Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. class FirstLogin extends JavaPlugin {
  2.     private Map<String, CommandHandler> handlers = new HashMap<>();
  3.    
  4.         //register command handlers at start
  5.     public void onEnable() {
  6.         FirstHelpCommandHandler firstHelp = new FirstHelpCommandHandler();
  7.         handlers.put(firstHelp.getName(), firstHelp);
  8.     }
  9.  
  10.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  11.         boolean isCommand = false; //to avoid tons of return statements
  12.        
  13.         if (sender instanceof Player) {
  14.             if(handlers.containsKey(cmd.getName())) {
  15.                 isCommand = true;
  16.                 handlers.get(cmd.getName()).process((Player) sender, cmd, commandLabel, args);
  17.             }
  18.         }
  19.        
  20.         return isCommand;
  21.     }
  22. }
  23.  
  24. //the "contract" for each command
  25. interface CommandHandler {
  26.     void process(Player player, Command cmd, String cmdLabel, String[] args);
  27.     String getName();
  28. }
  29.  
  30. //handle specific command
  31. class FirstHelpCommandHandler implements CommandHandler {
  32.     public void process(Player player, Command cmd, String cmdLabel, String[] args) {
  33.         player.sendMessage("/listp: Lists the number of players joined to date.");
  34.         player.sendMessage("/pnames: Lists all the names off players that joined the server.");
  35.         player.sendMessage("/owner: Shows the owner of the servers name.");
  36.         player.sendMessage("/onlinep: Shows how many players are currently online.");
  37.         player.sendMessage("/firsthelp: Shows this to the player.");
  38.     }
  39.    
  40.     public String getName() {
  41.         return "firsthelp";
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement