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