24.04.2016, 17:12
Here is the code for the commands:
Problem 2 solved, thank you!
Код:
public abstract class Commands{ private String help = ""; private static CommandGroup group; static EventManager event; public static void prepare(EventManager eventM, CommandGroup groupM){ event = eventM; group = groupM; } public void enableHelp(){ if(help.isEmpty()){ group.getCommands() .stream() .sorted((o1, o2) -> o1.getCommand().compareToIgnoreCase(o2.getCommand())) .forEach(commandEntry -> { if(commandEntry.getOrigin() == this.getClass()){ help = help+"{FF0000}/"+commandEntry.getCommand()+"{FFFFFF} - "+commandEntry.getHelpMessage()+"\n"; } }); } } void showHelpDialog(Player player){ MsgboxDialog.create(player, event) .caption("{91FF00}Dev commands") .message(help).buttonOk("Ok") .buttonCancel("") .build() .show(); } }
Код:
public class DevCmds extends Commands{ @BeforeCheck public boolean checkPremission(Player p, String cmd, String params){ SPlayer sPlayer = SPlayer.playerInfo[p.getId()]; if(!sPlayer.isAdmin(SPlayer.AdminType.DEVELOPER)){ p.sendMessage(Color.RED, "» You don't have permissions to use this command"); return false; } return true; } @Command @CommandHelp("Change the server time") public boolean changetime(Player player, int hour){ //Some stuff here return true; } //More commands @Command @CommandHelp("Help") public boolean devcmds(Player player){ showHelpDialog(player); return true; } }
Код:
PlayerCommandManager commandEvents = new PlayerCommandManager(event); CommandGroup group = new CommandGroup(); Commands.prepare(event, group); DevCmds devCmds= new DevCmds(); grupo.registerCommands(devCmds); devCmds.enableHelp();