public boolean execute() throws MissingOrIncorrectParametersException, InsufficientPermissionsException { errorCheck(); List<String> helpMsg = initializeHelp(); int page = -1; if (args.length < 2) page = 1; else if (args.length == 2) try { page = Integer.parseInt(args[1]); } catch (NumberFormatException nfe) { throw new MissingOrIncorrectParametersException(); } else throw new MissingOrIncorrectParametersException(); if (page < 1) page = 1; if (page > MTUtil.getNumPages(helpMsg)) { Messaging.send(cs, "`rNo such page."); page = 1; } String intro = "`a+-------------- MagicTorches Help (" + page + "/" + MTUtil.getNumPages(helpMsg) + ") --------------+"; // String intro = "`gMagicTorches Help (Page " + page + " of " + MTUtil.getNumPages(helpMsg) + // ")"; Messaging.send(cs, intro); Messaging.mlSend(cs, MTUtil.getListPage(helpMsg, page)); return true; }
public List<String> initializeHelp() { List<String> help = new ArrayList<String>(); boolean canCreate = MTUtil.hasPermission(cs, Properties.permCreateDelay) || MTUtil.hasPermission(cs, Properties.permCreateDirect) || MTUtil.hasPermission(cs, Properties.permCreateInverse) || MTUtil.hasPermission(cs, Properties.permCreateTimer) || MTUtil.hasPermission(cs, Properties.permCreateToggle); if (canCreate) { // help.add("`g/mt instructions `w- Show basic torch creation instructions."); help.add("`g/mt create `s<name> [next receiver type] `w- Creates a"); help.add("MagicTorch array named `s<name>`w. `s[next receiver type]`w can be"); List<String> types = new ArrayList<String>(); if (MTUtil.hasPermission(cs, Properties.permCreateDirect)) types.add("Direct"); if (MTUtil.hasPermission(cs, Properties.permCreateInverse)) types.add("Inverse"); if (MTUtil.hasPermission(cs, Properties.permCreateToggle)) types.add("Toggle"); if (MTUtil.hasPermission(cs, Properties.permCreateDelay)) types.add("Delay"); if (MTUtil.hasPermission(cs, Properties.permCreateTimer)) types.add("Timer"); StringBuilder sb = new StringBuilder(); String comma = ""; if (types.size() > 1) { for (int i = 0; i < (types.size() - 1); i++) { sb.append(comma).append(types.get(i)); comma = ", "; } sb.append(", or "); } sb.append(types.get(types.size() - 1)).append("."); help.add(sb.toString()); help.add("`g/mt edit `s<name> `w- Edits the named torch array."); help.add("`g/mt cancel `w- Cancels torch creating or editing."); help.add("`g/mt finish `w- Finishes torch creating or editing."); help.add("`g/mt delete `s<name> `w- Delete the named torch array."); help.add("`g/mt info `s<name> `w- Shows info for the named torch array."); } if (MTUtil.hasPermission(cs, Properties.permCreateDirect)) { help.add("`g/mt direct `w- Sets the next added receiver torches to be a"); help.add("direct receiver."); } if (MTUtil.hasPermission(cs, Properties.permCreateInverse)) { help.add("`g/mt inverse `w- Sets the next added receiver torches to be an"); help.add("inverse receiver."); } if (MTUtil.hasPermission(cs, Properties.permCreateToggle)) { help.add("`g/mt toggle `s[time] `w- Sets the next added receiver torches to"); help.add("be a toggle receiver. `s[time] `wis the amount of time to wait"); help.add( "before accepting another signal. Default is `a" + Properties.toggleDelay + " `wseconds."); } if (MTUtil.hasPermission(cs, Properties.permCreateDelay)) { help.add("`g/mt delay `s[time] `w- Sets the next added receiver torches to be"); help.add("a delay receiver. `s[time] `wis the amount of time to wait before"); help.add("processing the signals. Default is `a" + Properties.delayDelay + " `wseconds."); } if (MTUtil.hasPermission(cs, Properties.permCreateTimer)) { help.add("`g/mt timer `s[time] `w- Sets the next added receiver torches to be"); help.add("a timer receiver. `s[time] `wis the amount of time to wait before"); help.add( "switching back to the initial state. Default is `a" + Properties.timerDelay + " `wseconds."); } if (MTUtil.isAdmin(cs)) { help.add("`g/mt list `s[player] [page] `w- Lists the torch arrays for"); help.add("everyone, or a `s[player] `wyou specify."); } else help.add("`g/mt list `s[page] `w- Lists the torch arrays that you own."); if (Properties.useEconomy) { help.add("`g/mt price `w- Show the current price for the array you are"); help.add("creating or editing."); help.add("`g/mt rate `w- Show the current rates for creating or editing"); help.add("MagicTorch arrays."); } if (MTUtil.isAdmin(cs)) { help.add("`g/mt enable `w- Reenable all loaded MT Torch arrays, after they"); help.add("have been disabled."); help.add("`g/mt disable `w- Disable all loaded MT Torch arrays."); help.add("`g/mt prune `w- Delete all non-loaded torch arrays."); help.add("`g/mt reload `w- Reloads all torch arrays from db."); } return help; }
public boolean execute() throws MissingOrIncorrectParametersException, InsufficientPermissionsException { errorCheck(); // command: /mt list [name of player] [page in listing] int page = -1; String playerToList = null; // player name to search for boolean isAdmin = MTUtil.isAdmin(cs); if (args.length < 2) page = 1; else if (args.length == 2) try { page = Integer.parseInt(args[1]); } catch (NumberFormatException nfe) { playerToList = args[1]; // MagicTorches.spam("nfe (args == 2): " + playerToList); } else if (args.length == 3) { try { page = Integer.parseInt(args[2]); } catch (NumberFormatException nfe) { // MagicTorches.spam("nfe (args == 3): " + args[1] + ", " + args[2]); throw new MissingOrIncorrectParametersException(); } playerToList = args[1]; } else { // MagicTorches.spam("args.length = " + args.length); throw new MissingOrIncorrectParametersException(); } if (page < 1) page = 1; if (!isAdmin) playerToList = player.getName(); List<String> torchList = new ArrayList<String>(); HashMap<Location, TorchArray> allArrays = mt.mtHandler.getAllArrays(); for (Entry<Location, TorchArray> e : allArrays.entrySet()) { if (playerToList == null || e.getValue().getOwner().equalsIgnoreCase(playerToList)) { TorchArray ta = e.getValue(); StringBuilder sb = new StringBuilder(); sb.append("`Y").append(ta.getName()); if (isAdmin) sb.append(" `w(").append(ta.getOwner()).append(")"); sb.append(" `a["); sb.append(ta.getLocation().getWorld().getName()).append(": "); sb.append(ta.getLocation().getBlockX()).append(", "); sb.append(ta.getLocation().getBlockY()).append(", "); sb.append(ta.getLocation().getBlockZ()).append("]"); torchList.add(sb.toString()); } } if (torchList.isEmpty()) torchList.add("`YNo torches found."); if (page > MTUtil.getNumPages(torchList)) { Messaging.send(cs, "`rNo such page."); page = 1; } String intro = "`gMagicTorches For `w" + ((playerToList == null) ? "Everyone" : playerToList) + " `g(Page " + page + " of " + MTUtil.getNumPages(torchList) + ")"; Messaging.send(cs, intro); Messaging.mlSend(cs, MTUtil.getListPage(torchList, page)); return true; }