Advertisement
Jaker232

Command 2.0 Tutorial Source

Dec 25th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. // onEnable calling method
  2. public void onEnable() {
  3.     getCommand("kick").setExecutor(new KickCommand(this)); // Creates new command
  4. }
  5.  
  6. // onCommand method
  7. public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) {
  8.     Player player = (Player) sender; // Player variable
  9.     if(cmd.getName().equalsIgnoreCase("kick")) { // Command checking
  10.         if(player.hasPermission("example.kick")) { // Permission checking
  11.             if(args.length == 1) { // 1 argument (player)
  12.                 Player toKick = Bukkit.getPlayer(args[0]); // Player to kick variable
  13.                 toKick.kickPlayer("kicked by " + player.getDisplayName()); // Kicks player
  14.                 player.sendMessage(toKick.toString() + " has been kicked."); // Tells kicked
  15.                 return true; // Returns true that operation is done sucessfully.
  16.             }
  17.             // BONUS!
  18.             if(args.length == 2) { // 2 argument (player) (reason)
  19.                 Player toKick = Bukkit.getPlayer(args[0]); // Player to kick variable
  20.                 String reason = (args[1]); // Reason variable
  21.                 toKick.kickPlayer(reason); // Kicks player for reason
  22.                 player.sendMessage(toKick.toString() + " has been kicked. (reason: " + reason + ")."); // Tells that player has been kicked for reason
  23.                 return true; // Returns true that the operation is done sucessfully
  24.             }
  25.         }
  26.     }
  27.     return false; // if command is unsuccessful, returns usage.
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement