public static void help( CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) { final CommandsManager<LocalPlayer> commandsManager = we.getCommandsManager(); if (args.argsLength() == 0) { SortedSet<String> commands = new TreeSet<String>( new Comparator<String>() { @Override public int compare(String o1, String o2) { final int ret = o1.replaceAll("/", "").compareToIgnoreCase(o2.replaceAll("/", "")); if (ret == 0) { return o1.compareToIgnoreCase(o2); } return ret; } }); commands.addAll(commandsManager.getCommands().keySet()); StringBuilder sb = new StringBuilder(); boolean first = true; for (String command : commands) { if (!first) { sb.append(", "); } sb.append('/'); sb.append(command); first = false; } player.print(sb.toString()); return; } String command = args.getJoinedStrings(0).replaceAll("/", ""); String helpMessage = commandsManager.getHelpMessages().get(command); if (helpMessage == null) { player.printError("Unknown command '" + command + "'."); return; } player.print(helpMessage); }
public boolean handleCommand(Player player, String[] split) { try { split[0] = split[0].substring(1); // Quick script shortcut if (split[0].matches("^[^/].*\\.js$")) { String[] newSplit = new String[split.length + 1]; System.arraycopy(split, 0, newSplit, 1, split.length); newSplit[0] = "cs"; newSplit[1] = newSplit[1]; split = newSplit; } // No command found! if (!commandMap.hasCommand(split[0])) { return false; } try { commandMap.execute(split, player, this, player); } catch (CommandPermissionsException e) { player.sendMessage("You don't have permission to do this."); } catch (MissingNestedCommandException e) { player.sendMessage(e.getUsage()); } catch (CommandUsageException e) { player.sendMessage(e.getMessage()); player.sendMessage(e.getUsage()); } catch (WrappedCommandException e) { throw e.getCause(); } catch (UnhandledCommandException e) { return false; } finally { } } catch (Throwable excp) { player.sendMessage("Please report this error:"); player.sendMessage(excp.getMessage()); } return true; }
public void onEnable() { // TODO: Place any custom enable code here including the registration of any events // Setup Plugin Member Variables server = getServer(); log = server.getLogger(); commandMap = new CommandsManager<Player>() { @Override public boolean hasPermission(Player player, String perm) { // TODO: Implement Permissions return true; } }; dungeons = new HashMap<String, Dungeon>(); editSessions = new HashMap<Player, EditSession>(); PluginManager pm = getServer().getPluginManager(); try { // Register our events pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_EXPLODE, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Normal, this); } catch (Exception e) { log.info("Exception while registering events."); log.info(e.getMessage()); } try { // Setup PlayerListener class to preprocess command events pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this); // Register Commands to the command map commandMap.register(LairDungeonCommand.class); } catch (Exception e) { log.info("Exception Registering Commands: "); log.info(e.getMessage()); } // Say Hello log.info("Legends.Lair Hello!"); }