SNiPeRzCiinema

Untitled

Sep 12th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.gameriffy;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.plugin.java.JavaPlugin;
  9.  
  10. public class PrivateMessages extends JavaPlugin
  11. {
  12.  
  13.     public void onEnable()
  14.     {
  15.         System.out.println("ACTIVATED");
  16.  
  17.     }
  18.  
  19.  
  20.     public void onDisable()
  21.     {
  22.         System.out.println("DISABLED");
  23.  
  24.     }
  25.  
  26.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  27.     {
  28.         //Check command
  29.         if (cmd.getName().equalsIgnoreCase("pm"))
  30.         {
  31.             //Check if sender is a player
  32.             if (sender instanceof Player)
  33.             {
  34.                 Player p = (Player) sender;
  35.                 //If there were no args included
  36.                 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
  37.                     p.sendMessage(ChatColor.RED + "Syntax: /pm <To> <Message>");
  38.                 else
  39.                 {
  40.  
  41.                     @SuppressWarnings("deprecation")
  42.                     Player target = Bukkit.getPlayer(args[0]);
  43.                     //Check if the target was found online
  44.                     if (target != null)
  45.                     {
  46.                         //Combine all the args into one string
  47.                         String message = "";
  48.                         for (int i = 1; i != args.length; i++)
  49.                             message += args[1] + " "; //You don't want to always grab arg[1]
  50.  
  51.                         target.sendMessage(ChatColor.BLUE + sender.getName() + ChatColor.WHITE + " > " + ChatColor.BLUE + "YOU " + ChatColor.WHITE + ": " + ChatColor.GREEN + message);
  52.                     }
  53.                     else
  54.                         sender.sendMessage(ChatColor.RED + "ERROR: This player is not connected on the server!");
  55.  
  56.                 }
  57.  
  58.             }
  59.             //If the sender is not a player you'll want to tell them why they can't use the command
  60.             else
  61.                 sender.sendMessage("You're not a player");
  62.         }
  63.         return true;
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment