private void giveBonus(String[] split) throws TownyException { Town town; try { if (split.length != 2) throw new TownyException( String.format( TownySettings.getLangString("msg_err_invalid_input"), "Eg: givebonus [town/player] [n]")); try { town = TownyUniverse.getDataSource().getTown(split[0]); } catch (NotRegisteredException e) { town = TownyUniverse.getDataSource().getResident(split[0]).getTown(); } try { town.setBonusBlocks(town.getBonusBlocks() + Integer.parseInt(split[1].trim())); TownyMessaging.sendMsg( getSender(), String.format( TownySettings.getLangString("msg_give_total"), town.getName(), split[1], town.getBonusBlocks())); } catch (NumberFormatException nfe) { throw new TownyException(TownySettings.getLangString("msg_error_must_be_int")); } TownyUniverse.getDataSource().saveTown(town); } catch (TownyException e) { throw new TownyException(e.getMessage()); } }
public void reloadTowny(Boolean reset) { if (reset) { TownyUniverse.getDataSource().deleteFile(plugin.getConfigPath()); } TownyLogger.shutDown(); if (plugin.load()) { // Register all child permissions for ranks TownyPerms.registerPermissionNodes(); // Update permissions for all online players TownyPerms.updateOnlinePerms(); } TownyMessaging.sendMsg(sender, TownySettings.getLangString("msg_reloaded")); // TownyMessaging.sendMsg(TownySettings.getLangString("msg_reloaded")); }
public void parseToggleCommand(String[] split) throws TownyException { boolean choice; if (split.length == 0) { // command was '/townyadmin toggle' player.sendMessage(ChatTools.formatTitle("/townyadmin toggle")); player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "war", "")); player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "neutral", "")); player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "devmode", "")); player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "debug", "")); player.sendMessage( ChatTools.formatCommand("", "/townyadmin toggle", "townwithdraw/nationwithdraw", "")); player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle npc", "[resident]", "")); return; } if (!TownyUniverse.getPermissionSource() .testPermission( player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOGGLE.getNode(split[0].toLowerCase()))) throw new TownyException(TownySettings.getLangString("msg_err_command_disable")); if (split[0].equalsIgnoreCase("war")) { choice = TownyUniverse.isWarTime(); if (!choice) { plugin.getTownyUniverse().startWarEvent(); TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("msg_war_started")); } else { plugin.getTownyUniverse().endWarEvent(); TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("msg_war_ended")); } } else if (split[0].equalsIgnoreCase("neutral")) { try { choice = !TownySettings.isDeclaringNeutral(); TownySettings.setDeclaringNeutral(choice); TownyMessaging.sendMsg( getSender(), String.format( TownySettings.getLangString("msg_nation_allow_neutral"), choice ? "Enabled" : "Disabled")); } catch (Exception e) { TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_err_invalid_choice")); return; } } else if (split[0].equalsIgnoreCase("devmode")) { try { choice = !TownySettings.isDevMode(); TownySettings.setDevMode(choice); TownyMessaging.sendMsg( getSender(), "Dev Mode " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled")); } catch (Exception e) { TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_err_invalid_choice")); } } else if (split[0].equalsIgnoreCase("debug")) { try { choice = !TownySettings.getDebug(); TownySettings.setDebug(choice); TownyMessaging.sendMsg( getSender(), "Debug Mode " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled")); } catch (Exception e) { TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_err_invalid_choice")); } } else if (split[0].equalsIgnoreCase("townwithdraw")) { try { choice = !TownySettings.getTownBankAllowWithdrawls(); TownySettings.SetTownBankAllowWithdrawls(choice); TownyMessaging.sendMsg( getSender(), "Town Withdrawls " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled")); } catch (Exception e) { TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_err_invalid_choice")); } } else if (split[0].equalsIgnoreCase("nationwithdraw")) { try { choice = !TownySettings.geNationBankAllowWithdrawls(); TownySettings.SetNationBankAllowWithdrawls(choice); TownyMessaging.sendMsg( getSender(), "Nation Withdrawls " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled")); } catch (Exception e) { TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_err_invalid_choice")); } } else if (split[0].equalsIgnoreCase("npc")) { if (split.length != 2) throw new TownyException( String.format( TownySettings.getLangString("msg_err_invalid_input"), "Eg: toggle npc [resident]")); try { Resident resident = TownyUniverse.getDataSource().getResident(split[1]); resident.setNPC(!resident.isNPC()); TownyUniverse.getDataSource().saveResident(resident); TownyMessaging.sendMessage( sender, String.format( TownySettings.getLangString("msg_npc_flag"), resident.isNPC(), resident.getName())); } catch (NotRegisteredException x) { throw new TownyException( String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[1])); } } else { // parameter error message // neutral/war/townmobs/worldmobs TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_err_invalid_choice")); } }
public boolean parseTownyAdminCommand(String[] split) throws TownyException { if (split.length == 0) { buildTAPanel(); for (String line : ta_panel) { sender.sendMessage(line); } } else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help")) { for (String line : ta_help) { sender.sendMessage(line); } } else { if (split[0].equalsIgnoreCase("set")) { adminSet(StringMgmt.remFirstArg(split)); return true; } else if (split[0].equalsIgnoreCase("town")) { parseAdminTownCommand(StringMgmt.remFirstArg(split)); return true; } else if (split[0].equalsIgnoreCase("nation")) { parseAdminNationCommand(StringMgmt.remFirstArg(split)); return true; } else if (split[0].equalsIgnoreCase("toggle")) { parseToggleCommand(StringMgmt.remFirstArg(split)); return true; } if ((!isConsole) && (!TownyUniverse.getPermissionSource() .testPermission( player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN.getNode(split[0].toLowerCase())))) throw new TownyException(TownySettings.getLangString("msg_err_command_disable")); if (split[0].equalsIgnoreCase("givebonus")) { giveBonus(StringMgmt.remFirstArg(split)); } else if (split[0].equalsIgnoreCase("reload")) { reloadTowny(false); } else if (split[0].equalsIgnoreCase("reset")) { reloadTowny(true); } else if (split[0].equalsIgnoreCase("backup")) { try { TownyUniverse.getDataSource().backup(); TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("mag_backup_success")); } catch (IOException e) { TownyMessaging.sendErrorMsg(getSender(), "Error: " + e.getMessage()); } } else if (split[0].equalsIgnoreCase("newday")) { TownyTimerHandler.newDay(); } else if (split[0].equalsIgnoreCase("purge")) { purge(StringMgmt.remFirstArg(split)); } else if (split[0].equalsIgnoreCase("delete")) { String[] newSplit = StringMgmt.remFirstArg(split); residentDelete(player, newSplit); } else if (split[0].equalsIgnoreCase("unclaim")) { parseAdminUnclaimCommand(StringMgmt.remFirstArg(split)); /* * else if (split[0].equalsIgnoreCase("seed") && * TownySettings.getDebug()) seedTowny(); else if * (split[0].equalsIgnoreCase("warseed") && * TownySettings.getDebug()) warSeed(player); */ } else { TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_err_invalid_sub")); return false; } } return true; }