Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FirstLogin extends JavaPlugin {
- private Map<String, CommandHandler> handlers = new HashMap<>();
- //register command handlers at start
- public void onEnable() {
- FirstHelpCommandHandler firstHelp = new FirstHelpCommandHandler();
- handlers.put(firstHelp.getName(), firstHelp);
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- boolean isCommand = false; //to avoid tons of return statements
- if (sender instanceof Player) {
- if(handlers.containsKey(cmd.getName())) {
- isCommand = true;
- handlers.get(cmd.getName()).process((Player) sender, cmd, commandLabel, args);
- }
- }
- return isCommand;
- }
- }
- //the "contract" for each command
- interface CommandHandler {
- void process(Player player, Command cmd, String cmdLabel, String[] args);
- String getName();
- }
- //handle specific command
- class FirstHelpCommandHandler implements CommandHandler {
- public void process(Player player, Command cmd, String cmdLabel, String[] args) {
- player.sendMessage("/listp: Lists the number of players joined to date.");
- player.sendMessage("/pnames: Lists all the names off players that joined the server.");
- player.sendMessage("/owner: Shows the owner of the servers name.");
- player.sendMessage("/onlinep: Shows how many players are currently online.");
- player.sendMessage("/firsthelp: Shows this to the player.");
- }
- public String getName() {
- return "firsthelp";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement