Advertisement
Guest User

ColourCommand.java

a guest
Jul 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. public class ColourCommand implements CommandExecutor
  2. {
  3.     @Override
  4.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  5.     {
  6.         //Say for example we are making a command like this /colour <type>
  7.  
  8.         //First we check if the sender is a player (sender can also be the server console or a command block).
  9.         if (!(sender instanceof Player))
  10.             return false;
  11.  
  12.         //You have to make sure you checking there are the right number of arguments. In this case we are only looking for one, "<type>".
  13.         if (args.length == 1)
  14.         {
  15.             switch (args[0].toLowerCase())
  16.             {
  17.                 case "blue":
  18.                     //The command must be /colour blue
  19.                     break;
  20.                 case "red":
  21.                     //The command must be /colour red
  22.                     break;
  23.                 default:
  24.                     //The first argument is not a colour
  25.                     return false;
  26.             }
  27.         }
  28.  
  29.         //Return true for successful commands, and vice versa.
  30.         return true;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement