SHOW:
|
|
- or go back to the newest paste.
| 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{
|
| 10 | + | public class PrivateMessages extends JavaPlugin |
| 11 | {
| |
| 12 | - | public void onEnable(){
|
| 12 | + | |
| 13 | - | System.out.println("ACTIVATED");
|
| 13 | + | public void onEnable() |
| 14 | {
| |
| 15 | - | } |
| 15 | + | System.out.println("ACTIVATED");
|
| 16 | - | |
| 16 | + | |
| 17 | } | |
| 18 | - | public void onDisable(){
|
| 18 | + | |
| 19 | - | System.out.println("DISABLED");
|
| 19 | + | |
| 20 | - | |
| 20 | + | public void onDisable() |
| 21 | - | } |
| 21 | + | {
|
| 22 | - | |
| 22 | + | System.out.println("DISABLED");
|
| 23 | - | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
|
| 23 | + | |
| 24 | - | if (cmd.getName().equalsIgnoreCase("pm"))
|
| 24 | + | } |
| 25 | - | if(sender instanceof Player){
|
| 25 | + | |
| 26 | - | Player p = (Player) sender; |
| 26 | + | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) |
| 27 | - | if(args.length == 0){
|
| 27 | + | {
|
| 28 | - | p.sendMessage(ChatColor.RED+"Syntax: /pm <To> <Message>"); |
| 28 | + | //Check command |
| 29 | - | |
| 29 | + | if (cmd.getName().equalsIgnoreCase("pm"))
|
| 30 | - | } |
| 30 | + | {
|
| 31 | - | } |
| 31 | + | //Check if sender is a player |
| 32 | - | {
|
| 32 | + | if (sender instanceof Player) |
| 33 | - | |
| 33 | + | {
|
| 34 | - | @SuppressWarnings("deprecation")
|
| 34 | + | Player p = (Player) sender; |
| 35 | - | Player target = Bukkit.getPlayer(args[0]); |
| 35 | + | //If there were no args included |
| 36 | - | |
| 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 | - | if(target != null) |
| 37 | + | p.sendMessage(ChatColor.RED + "Syntax: /pm <To> <Message>"); |
| 38 | - | {
|
| 38 | + | else |
| 39 | - | |
| 39 | + | {
|
| 40 | - | String message = ""; |
| 40 | + | |
| 41 | - | for(int i = 1; i != args.length; i++) |
| 41 | + | @SuppressWarnings("deprecation")
|
| 42 | - | message += args[1] + " "; |
| 42 | + | Player target = Bukkit.getPlayer(args[0]); |
| 43 | - | |
| 43 | + | //Check if the target was found online |
| 44 | - | target.sendMessage(ChatColor.BLUE+sender.getName()+ChatColor.WHITE+" > "+ChatColor.BLUE+"YOU "+ChatColor.WHITE+": " + ChatColor.GREEN + message); |
| 44 | + | if (target != null) |
| 45 | - | }else |
| 45 | + | {
|
| 46 | - | sender.sendMessage(ChatColor.RED+"ERROR: This player is not connected on the server!"); |
| 46 | + | //Combine all the args into one string |
| 47 | - | |
| 47 | + | String message = ""; |
| 48 | - | } |
| 48 | + | for (int i = 1; i != args.length; i++) |
| 49 | - | |
| 49 | + | message += args[1] + " "; //You don't want to always grab arg[1] |
| 50 | - | return true; |
| 50 | + | |
| 51 | - | |
| 51 | + | target.sendMessage(ChatColor.BLUE + sender.getName() + ChatColor.WHITE + " > " + ChatColor.BLUE + "YOU " + ChatColor.WHITE + ": " + ChatColor.GREEN + message); |
| 52 | - | } |
| 52 | + | } |
| 53 | - | |
| 53 | + | else |
| 54 | - | } |
| 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 | } |