diff --git a/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java b/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java index 0e8b5e4b92..6b7f526eb1 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java +++ b/Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java @@ -3521,16 +3521,23 @@ public enum ConfigNodes { "false", "", "# When this is true, players who have no town can also reclaim the ruin. While false, only residents of the Town can reclaim the ruin."), - TOWN_RUINING_TOWN_DEPOSITS_BANK_TO_NATION( - "town_ruining.town_ruins.town_bank_is_sent_to_nation", - "false", - "", - "# If this is true, when a town becomes a ruin, and they are a member of a nation, any money in the town bank will be deposited to the nation bank."), - TOWN_RUINING_TOWN_PLOTS_PERMISSIONS_OPEN_UP_PROGRESSIVELY( - "town_ruining.town_ruins.do_plots_permissions_change_to_allow_all", - "false", - "", - "# If this is true, when a town becomes a ruin, every hour more and more of their plots will have their permissions turned to allow", + TOWN_RUINING_TOWN_DEPOSITS_BANK_TO_NATION( + "town_ruining.town_ruins.town_bank_is_sent_to_nation", + "false", + "", + "# If this is true, when a town becomes a ruin, and they are a member of a nation, any money in the town bank will be deposited to the nation bank."), + TOWN_RUINING_PERMISSIONS_ALLOW_ALL( + "town_ruining.town_ruins.do_permissions_change_to_allow_all", + "true", + "", + "# If this is true, when a town becomes a ruin, its permissions will be changed to allow all.", + "# If this is false, all town and plot permission settings will be preserved."), + TOWN_RUINING_TOWN_PLOTS_PERMISSIONS_OPEN_UP_PROGRESSIVELY( + "town_ruining.town_ruins.do_plots_permissions_change_to_allow_all", + "false", + "", + "# This setting has no effect when do_permissions_change_to_allow_all is false.", + "# If this is true, when a town becomes a ruin, every hour more and more of their plots will have their permissions turned to allow", "# build, destroy, switch, itemuse to on. This will affect the newest claims first and progress until the first claims made are opened up", "# right before the max_duration_hours have passed. When a town has more claims than max_duration_hours, multiple plots will be opened up", "# each hour, ie: 500 claims and 72 max hours = 7 claims per hour.", diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java b/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java index 1eeba92233..43c56bc789 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/TownySettings.java @@ -3933,6 +3933,10 @@ public static boolean areRuinedTownsBanksPaidToNation() { return getBoolean(ConfigNodes.TOWN_RUINING_TOWN_DEPOSITS_BANK_TO_NATION); } + public static boolean doRuinsPermissionsAllowAll() { + return getBoolean(ConfigNodes.TOWN_RUINING_PERMISSIONS_ALLOW_ALL); + } + public static boolean doRuinsPlotPermissionsProgressivelyAllowAll() { return getBoolean(ConfigNodes.TOWN_RUINING_TOWN_PLOTS_PERMISSIONS_OPEN_UP_PROGRESSIVELY); } diff --git a/Towny/src/main/java/com/palmergames/bukkit/towny/utils/TownRuinUtil.java b/Towny/src/main/java/com/palmergames/bukkit/towny/utils/TownRuinUtil.java index cb19afdb82..d495614184 100644 --- a/Towny/src/main/java/com/palmergames/bukkit/towny/utils/TownRuinUtil.java +++ b/Towny/src/main/java/com/palmergames/bukkit/towny/utils/TownRuinUtil.java @@ -112,41 +112,50 @@ public static void putTownIntoRuinedState(Town town) { town.setRuinedTime(System.currentTimeMillis()); town.setPublic(TownySettings.areRuinsMadePublic()); town.setOpen(TownySettings.areRuinsMadeOpen()); - town.getPermissions().setAll(true); + // Get the config setting for if all permissions should be allowed in ruined towns + final boolean setPermissionsAllowAll = TownySettings.doRuinsPermissionsAllowAll(); + if (setPermissionsAllowAll) + town.getPermissions().setAll(true); //Return town blocks to the basic, unowned, type for(TownBlock townBlock: town.getTownBlocks()) { - if (townBlock.hasResident()) - townBlock.removeResident(); // Removes any personal ownership. - townBlock.setType(TownBlockType.RESIDENTIAL); // Sets the townblock's perm line to the Town's perm line set above. - townBlock.setPlotPrice(-1); // Makes the plot not for sale. - townBlock.removePlotObjectGroup(); // Removes plotgroup if it were present. - townBlock.removeDistrict(); // Removes district if it were present. - townBlock.setPermissionOverrides(null); // Removes all permission overrides from the plot. - townBlock.setTrustedResidents(null); // Removes all trusted residents. + // Don't change townblock if config specifies not to + if (setPermissionsAllowAll) { + if (townBlock.hasResident()) + townBlock.removeResident(); // Removes any personal ownership. + townBlock.setType(TownBlockType.RESIDENTIAL); // Sets the townblock's perm line to the Town's perm line set above. + townBlock.removePlotObjectGroup(); // Removes plotgroup if it were present. + townBlock.removeDistrict(); // Removes district if it were present. + townBlock.setPermissionOverrides(null); // Removes all permission overrides from the plot. + townBlock.setTrustedResidents(null); // Removes all trusted residents. + } + townBlock.setPlotPrice(-1); // Makes the plot not for sale. townBlock.save(); } - // Unregister the now empty plotgroups. - if (town.getPlotGroups() != null) { - for (PlotGroup group : new ArrayList<>(town.getPlotGroups())) { - new PlotGroupDeletedEvent(group, null, PlotGroupDeletedEvent.Cause.TOWN_DELETED).callEvent(); - TownyUniverse.getInstance().getDataSource().removePlotGroup(group); + // Perform ruin cleanup if we are setting permissions to AllowAll + if (setPermissionsAllowAll) { + // Unregister the now empty plotgroups. + if (town.getPlotGroups() != null) { + for (PlotGroup group : new ArrayList<>(town.getPlotGroups())) { + new PlotGroupDeletedEvent(group, null, PlotGroupDeletedEvent.Cause.TOWN_DELETED).callEvent(); + TownyUniverse.getInstance().getDataSource().removePlotGroup(group); + } } - } - // Unregister the now empty districts. - if (town.getDistricts() != null) { - for (District district : new ArrayList<>(town.getDistricts())) { - new DistrictDeletedEvent(district, null, DistrictDeletedEvent.Cause.TOWN_DELETED).callEvent(); - TownyUniverse.getInstance().getDataSource().removeDistrict(district); + // Unregister the now empty districts. + if (town.getDistricts() != null) { + for (District district : new ArrayList<>(town.getDistricts())) { + new DistrictDeletedEvent(district, null, DistrictDeletedEvent.Cause.TOWN_DELETED).callEvent(); + TownyUniverse.getInstance().getDataSource().removeDistrict(district); + } } + + // Check if Town has more residents than it should be allowed (if it were the capital of a nation.) + if (TownySettings.getMaxResidentsPerTown() > 0) + ResidentUtil.reduceResidentCountToFitTownMaxPop(town); } - - // Check if Town has more residents than it should be allowed (if it were the capital of a nation.) - if (TownySettings.getMaxResidentsPerTown() > 0) - ResidentUtil.reduceResidentCountToFitTownMaxPop(town); - + town.setForSale(false); town.save(); @@ -228,12 +237,15 @@ public static void reclaimTown(@NotNull Resident resident, @NotNull Town town) { if (!resident.equals(town.getMayor())) setMayor(town, resident); //Set player as mayor (and remove npc) - // Set permission line to the config's default settings. - town.getPermissions().loadDefault(town); - for (TownBlock townBlock : town.getTownBlocks()) { - townBlock.getPermissions().loadDefault(town); - townBlock.setChanged(false); - townBlock.save(); + // Don't reset plot permissions if they were never changed + if (TownySettings.doRuinsPermissionsAllowAll()) { + // Set permission line to the config's default settings. + town.getPermissions().loadDefault(town); + for (TownBlock townBlock : town.getTownBlocks()) { + townBlock.getPermissions().loadDefault(town); + townBlock.setChanged(false); + townBlock.save(); + } } town.save(); @@ -284,7 +296,7 @@ public static void evaluateRuinedTownRemovals() { continue; } - if (TownySettings.doRuinsPlotPermissionsProgressivelyAllowAll()) { + if (TownySettings.doRuinsPermissionsAllowAll() && TownySettings.doRuinsPlotPermissionsProgressivelyAllowAll()) { final Town finalTown = town; // We are configured to slowly open up plots' permissions while a town is ruined. Towny.getPlugin().getScheduler().runAsync(() -> allowPermissionsOnRuinedTownBlocks(finalTown));