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")); } }
/** * Remove residents who havn't logged in for X amount of days. * * @param split */ public void purge(String[] split) { if (split.length == 0) { // command was '/townyadmin purge' player.sendMessage(ChatTools.formatTitle("/townyadmin purge")); player.sendMessage(ChatTools.formatCommand("", "/townyadmin purge", "[number of days]", "")); player.sendMessage( ChatTools.formatCommand( "", "", "Removes offline residents not seen for this duration.", "")); return; } int days = 1; try { days = Integer.parseInt(split[0]); } catch (NumberFormatException e) { TownyMessaging.sendErrorMsg( getSender(), TownySettings.getLangString("msg_error_must_be_int")); return; } // Use questioner to confirm. Plugin test = BukkitTools.getServer().getPluginManager().getPlugin("Questioner"); if (this.sender instanceof Player && TownySettings.isUsingQuestioner() && test != null && test instanceof Questioner && test.isEnabled()) { Questioner questioner = (Questioner) test; questioner.loadClasses(); List<Option> options = new ArrayList<Option>(); options.add( new Option( TownySettings.questionerAccept(), new PurgeQuestionTask(plugin, this.sender, TimeTools.getMillis(days + "d")))); options.add( new Option( TownySettings.questionerDeny(), new PurgeQuestionTask(plugin, this.sender, TimeTools.getMillis(days + "d")) { @Override public void run() { TownyMessaging.sendMessage(getSender(), "Purge Aborted!"); } })); Question question = new Question(this.sender.getName(), "Do you really want to perform this purge", options); try { plugin.appendQuestion(questioner, question); } catch (Exception e) { System.out.println(e.getMessage()); } } else { // Run a purge in it's own thread new ResidentPurge(plugin, this.sender, TimeTools.getMillis(days + "d")).start(); } }
public void adminSet(String[] split) throws TownyException { if (split.length == 0) { sender.sendMessage(ChatTools.formatTitle("/townyadmin set")); // TODO: player.sendMessage(ChatTools.formatCommand("", // "/townyadmin set", "king [nation] [king]", "")); sender.sendMessage( ChatTools.formatCommand( "", "/townyadmin set", "mayor [town] " + TownySettings.getLangString("town_help_2"), "")); sender.sendMessage(ChatTools.formatCommand("", "/townyadmin set", "mayor [town] npc", "")); // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set", // "debugmode [on/off]", "")); // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set", // "devmode [on/off]", "")); return; } if (!TownyUniverse.getPermissionSource() .testPermission( player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_SET.getNode(split[0].toLowerCase()))) throw new TownyException(TownySettings.getLangString("msg_err_command_disable")); if (split[0].equalsIgnoreCase("mayor")) { if (split.length < 3) { sender.sendMessage(ChatTools.formatTitle("/townyadmin set mayor")); sender.sendMessage( ChatTools.formatCommand( "Eg", "/townyadmin set mayor", "[town] " + TownySettings.getLangString("town_help_2"), "")); sender.sendMessage( ChatTools.formatCommand("Eg", "/townyadmin set mayor", "[town] npc", "")); } else try { Resident newMayor = null; Town town = TownyUniverse.getDataSource().getTown(split[1]); if (split[2].equalsIgnoreCase("npc")) { String name = nextNpcName(); TownyUniverse.getDataSource().newResident(name); newMayor = TownyUniverse.getDataSource().getResident(name); newMayor.setRegistered(System.currentTimeMillis()); newMayor.setLastOnline(0); newMayor.setNPC(true); TownyUniverse.getDataSource().saveResident(newMayor); TownyUniverse.getDataSource().saveResidentList(); // set for no upkeep as an NPC mayor is assigned town.setHasUpkeep(false); } else { newMayor = TownyUniverse.getDataSource().getResident(split[2]); // set upkeep again town.setHasUpkeep(true); } if (!town.hasResident(newMayor)) TownCommand.townAddResident(town, newMayor); // Delete the resident if the old mayor was an NPC. Resident oldMayor = town.getMayor(); town.setMayor(newMayor); if (oldMayor.isNPC()) { try { town.removeResident(oldMayor); TownyUniverse.getDataSource().removeResident(oldMayor); TownyUniverse.getDataSource().removeResidentList(oldMayor); } catch (EmptyTownException e) { // Should never reach here as we are setting a new // mayor before removing the old one. e.printStackTrace(); } } TownyUniverse.getDataSource().saveTown(town); String[] msg = TownySettings.getNewMayorMsg(newMayor.getName()); TownyMessaging.sendTownMessage(town, msg); // TownyMessaging.sendMessage(player, msg); } catch (TownyException e) { TownyMessaging.sendErrorMsg(getSender(), e.getMessage()); } } else if (split[0].equalsIgnoreCase("capital")) { if (split.length < 2) { sender.sendMessage(ChatTools.formatTitle("/townyadmin set capital")); sender.sendMessage(ChatTools.formatCommand("Eg", "/ta set capital", "[town name]", "")); } else { try { Town newCapital = TownyUniverse.getDataSource().getTown(split[1]); Nation nation = newCapital.getNation(); nation.setCapital(newCapital); plugin.resetCache(); TownyMessaging.sendNationMessage( nation, TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName())); TownyUniverse.getDataSource().saveNation(nation); TownyUniverse.getDataSource().saveNationList(); } catch (TownyException e) { TownyMessaging.sendErrorMsg(player, e.getMessage()); } } } else { TownyMessaging.sendErrorMsg( getSender(), String.format(TownySettings.getLangString("msg_err_invalid_property"), "administrative")); return; } }
private static void initializePlugin( String name, Plugin plugin) { // Really messy, right? But it's short and fast :) Dependency dependency; try { dependency = Dependency.valueOf(name); } catch (IllegalArgumentException exception) { return; } Listener listener = null; switch (dependency) { // Protection plugins case LWC: listener = new LightweightChestProtection(); break; case Lockette: listener = new Lockette(); break; case Deadbolt: listener = new Deadbolt(); break; case SimpleChestLock: listener = SimpleChestLock.getSimpleChestLock(plugin); break; case Residence: listener = new ResidenceChestProtection(); break; // Terrain protection plugins case Towny: Towny towny = Towny.getTowny(); if (towny == null || !Properties.TOWNY_INTEGRATION) { return; } listener = towny; break; case WorldGuard: WorldGuardPlugin worldGuard = (WorldGuardPlugin) plugin; boolean inUse = Properties.WORLDGUARD_USE_PROTECTION || Properties.WORLDGUARD_INTEGRATION; if (!inUse) { return; } if (Properties.WORLDGUARD_USE_PROTECTION) { ChestShop.registerListener(new WorldGuardProtection(worldGuard)); } if (Properties.WORLDGUARD_INTEGRATION) { listener = new WorldGuardBuilding(worldGuard); } break; // Other plugins case Heroes: Heroes heroes = Heroes.getHeroes(plugin); if (heroes == null) { return; } listener = heroes; break; case OddItem: MaterialUtil.Odd.initialize(); break; } if (listener != null) { ChestShop.registerListener(listener); } PluginDescriptionFile description = plugin.getDescription(); ChestShop.getBukkitLogger() .info(description.getName() + " version " + description.getVersion() + " loaded."); }