Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.gameriffy;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- public class PrivateMessages extends JavaPlugin
- {
- public void onEnable()
- {
- System.out.println("ACTIVATED");
- }
- public void onDisable()
- {
- System.out.println("DISABLED");
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- //Check command
- if (cmd.getName().equalsIgnoreCase("pm"))
- {
- //Check if sender is a player
- if (sender instanceof Player)
- {
- Player p = (Player) sender;
- //If there were no args included
- if (args.length == 0) //You may want to check if the length is less than 1. They may just use "/pm Name" then there would be no message
- p.sendMessage(ChatColor.RED + "Syntax: /pm <To> <Message>");
- else
- {
- @SuppressWarnings("deprecation")
- Player target = Bukkit.getPlayer(args[0]);
- //Check if the target was found online
- if (target != null)
- {
- //Combine all the args into one string
- String message = "";
- for (int i = 1; i != args.length; i++)
- message += args[1] + " "; //You don't want to always grab arg[1]
- target.sendMessage(ChatColor.BLUE + sender.getName() + ChatColor.WHITE + " > " + ChatColor.BLUE + "YOU " + ChatColor.WHITE + ": " + ChatColor.GREEN + message);
- }
- else
- sender.sendMessage(ChatColor.RED + "ERROR: This player is not connected on the server!");
- }
- }
- //If the sender is not a player you'll want to tell them why they can't use the command
- else
- sender.sendMessage("You're not a player");
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment