Skip to content

Commit

Permalink
Merge branch 'TownyAdvanced:master' into fork
Browse files Browse the repository at this point in the history
  • Loading branch information
CorruptedGreed authored Feb 23, 2024
2 parents e3907c6 + ee8c779 commit 8a0f457
Show file tree
Hide file tree
Showing 94 changed files with 2,568 additions and 1,528 deletions.
1,032 changes: 516 additions & 516 deletions Towny/pom.xml

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,17 @@ public enum ConfigNodes {
NWS_PLOT_MANAGEMENT_WILD_REVERT_BLOCK_WHITELIST(
"new_world_settings.plot_management.wild_revert_on_explosion_block_whitelist",
"",
"# The list of blocks to regenerate. (if empty all blocks will regenerate)"),

"# This section is applied to new worlds as default settings when new worlds are detected.",
"# The list of blocks to regenerate for block and entity explosions. (if empty all blocks will regenerate)"),
NWS_PLOT_MANAGEMENT_WILD_REVERT_BLOCKS_TO_NOT_OVERWRITE(
"new_world_settings.plot_management.wild_revert_explosions_blocks_to_not_replace",
"",
"# This section is applied to new worlds as default settings when new worlds are detected.",
"# This is the list of blocks that should not be overwritten by wilderness explosion reverts. (if empty all ",
"# blocks placed into regenerating explosions will be overwritten with the original pre-explosion blocks.)",
"# This list is useful if you have a death chest plugin which could put a player's inventory inside chest",
"# that is inside of a regenerating creeper explosion pit. For Example: By putting CHEST here you can ",
"# prevent the chest from being overwritten by the dirt block that used to be there."),

GTOWN_SETTINGS(
"global_town_settings",
Expand Down Expand Up @@ -1462,14 +1471,6 @@ public enum ConfigNodes {
"plugin.interfacing.tekkit.fake_residents",
"[IndustrialCraft],[BuildCraft],[Redpower],[Forestry],[Turtle]",
"# Add any fake players for client/server mods (aka Tekkit) here"),
PLUGIN_USING_ECONOMY(
"plugin.interfacing.using_economy",
"true",
"",
"# This enables/disables all the economy functions of Towny.",
"# This will first attempt to use Vault or Reserve to bridge your economy plugin with Towny.",
"# If Reserve/Vault is not present it will attempt to find a supported economy plugin.",
"# If neither Vault/Reserve or supported economy are present it will not be possible to create towns or do any operations that require money."),

PLUGIN_LUCKPERMS_ROOT("plugin.interfacing.luckperms","",""),
PLUGIN_LUCKPERMS_CONTEXTS(
Expand Down Expand Up @@ -2319,6 +2320,14 @@ public enum ConfigNodes {
"# +------------------------------------------------------+ #",
"############################################################",
""),
ECO_USING_ECONOMY(
"economy.using_economy",
"true",
"",
"# This enables/disables all the economy functions of Towny.",
"# This will first attempt to use Vault or Reserve to bridge your economy plugin with Towny.",
"# If Reserve/Vault is not present it will attempt to find a supported economy plugin.",
"# If neither Vault/Reserve or supported economy are present it will not be possible to create towns or do any operations that require money."),
ECO_USE_ASYNC(
"economy.use_async",
"true",
Expand Down
10 changes: 4 additions & 6 deletions Towny/src/main/java/com/palmergames/bukkit/towny/Towny.java
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,10 @@ public static BukkitAudiences getAdventure() {
// https://www.spigotmc.org/threads/small-easy-register-command-without-plugin-yml.38036/
private void registerSpecialCommands() {
List<Command> commands = new ArrayList<>(4);
commands.add(new AcceptCommand(TownySettings.getAcceptCommand()));
commands.add(new DenyCommand(TownySettings.getDenyCommand()));
commands.add(new ConfirmCommand(TownySettings.getConfirmCommand()));
commands.add(new CancelCommand(TownySettings.getCancelCommand()));
commands.add(new AcceptCommand(this, TownySettings.getAcceptCommand()));
commands.add(new DenyCommand(this, TownySettings.getDenyCommand()));
commands.add(new ConfirmCommand(this, TownySettings.getConfirmCommand()));
commands.add(new CancelCommand(this, TownySettings.getCancelCommand()));

try {
BukkitTools.getCommandMap().registerAll("towny", commands);
Expand Down Expand Up @@ -838,8 +838,6 @@ else if (getServer().getName().equalsIgnoreCase("craftbukkit"))
metrics.addCustomChart(new SimplePie("town_block_size", () -> String.valueOf(TownySettings.getTownBlockSize())));

metrics.addCustomChart(new SimplePie("closed_economy_enabled", () -> String.valueOf(TownySettings.isEcoClosedEconomyEnabled())));

metrics.addCustomChart(new SimplePie("resident_uuids_stored", TownySettings::getUUIDPercent));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public record NationLevel(

private static CommentedConfiguration config;
private static CommentedConfiguration newConfig;
private static int uuidCount;
private static boolean areLevelTypeLimitsConfigured;

private static final SortedMap<Integer, TownLevel> configTownLevel = Collections.synchronizedSortedMap(new TreeMap<>(Collections.reverseOrder()));
Expand Down Expand Up @@ -1358,7 +1357,7 @@ public static boolean isFriendlyFireEnabled() {

public static boolean isUsingEconomy() {

return getBoolean(ConfigNodes.PLUGIN_USING_ECONOMY);
return getBoolean(ConfigNodes.ECO_USING_ECONOMY);
}

public static boolean isFakeResident(String name) {
Expand Down Expand Up @@ -1517,7 +1516,11 @@ public static List<String> getWildExplosionProtectionEntities() {
public static List<String> getWildExplosionRevertBlockWhitelist() {
return getStrArr(ConfigNodes.NWS_PLOT_MANAGEMENT_WILD_REVERT_BLOCK_WHITELIST);
}


public static List<String> getWildExplosionRevertMaterialsToNotOverwrite() {
return getStrArr(ConfigNodes.NWS_PLOT_MANAGEMENT_WILD_REVERT_BLOCKS_TO_NOT_OVERWRITE);
}

public static List<String> getWildExplosionProtectionBlocks() {
return getStrArr(ConfigNodes.NWS_PLOT_MANAGEMENT_WILD_BLOCK_REVERT_LIST);
}
Expand Down Expand Up @@ -3377,41 +3380,6 @@ public static Map<String,String> getTownColorsMap() {
}
return townColorsMap;
}

public static String getUUIDPercent() {
double fraction = (double) uuidCount / TownyUniverse.getInstance().getNumResidents();

if (fraction == 1.00)
return "100%";
if (fraction > 0.98)
return "99%";
if (fraction > 0.95)
return "95%+";
if (fraction > 0.89)
return "90%+";
if (fraction > 0.79)
return "80%+";
if (fraction > 0.69)
return "70%+";
if (fraction > 0.59)
return "60%+";
if (fraction > 0.49)
return "50%+";

return "<50%";
}

public static int getUUIDCount() {
return uuidCount;
}

public static void setUUIDCount(int hasUUID) {
uuidCount = hasUUID;
}

public static void incrementUUIDCount() {
uuidCount++;
}

public static boolean isTownBankruptcyEnabled() {
return getBoolean(ConfigNodes.ECO_BANKRUPTCY_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.palmergames.bukkit.towny;

import com.palmergames.bukkit.towny.object.SpawnPoint;
import com.palmergames.bukkit.towny.scheduling.ScheduledTask;
import com.palmergames.bukkit.towny.tasks.CooldownTimerTask;
import com.palmergames.bukkit.towny.tasks.DrawSmokeTask;
Expand Down Expand Up @@ -58,7 +59,7 @@ public static void toggleTownyRepeatingTimer(boolean on) {

public static void toggleMobRemoval(boolean on) {

if (on && !isMobRemovalRunning()) {
if (on && !isMobRemovalRunning() && !plugin.isFolia()) {
mobRemoveTask = plugin.getScheduler().runRepeating(new MobRemovalTimerTask(plugin), 1, TimeTools.convertToTicks(TownySettings.getMobRemovalSpeed()));
} else if (!on && isMobRemovalRunning()) {
mobRemoveTask.cancel();
Expand Down Expand Up @@ -136,7 +137,7 @@ public static void toggleDrawSmokeTask(boolean on) {
public static void toggleDrawSpointsTask(boolean on) {
if (on && !isDrawSpawnPointsTaskRunning()) {
// This is given a delay because it was causing ConcurrentModificationExceptions on startup on one server.
drawSpawnPointsTask = plugin.getScheduler().runAsyncRepeating(new DrawSpawnPointsTask(plugin), 40, 52);
drawSpawnPointsTask = plugin.getScheduler().runAsyncRepeating(new DrawSpawnPointsTask(plugin), 40, SpawnPoint.RING_POINT_COUNT * SpawnPoint.RING_DELAY_TICKS);
} else if (!on && isDrawSpawnPointsTaskRunning()) {
drawSpawnPointsTask.cancel();
drawSpawnPointsTask = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ private boolean loadDatabase(String loadDbType) {

long time = System.currentTimeMillis() - startTime;
towny.getLogger().info("Database: Loaded in " + time + "ms.");
towny.getLogger().info("Database: " + TownySettings.getUUIDPercent() + " of residents have stored UUIDs."); // TODO: remove this when we're using UUIDs directly in the database.

// Throw Event.
BukkitTools.fireEvent(new TownyLoadedDatabaseEvent());
Expand Down Expand Up @@ -476,7 +475,7 @@ public boolean hasTown(@NotNull String townName) {

String formattedName;
try {
formattedName = NameValidation.checkAndFilterName(townName).toLowerCase(Locale.ROOT);
formattedName = NameValidation.checkAndFilterTownNameOrThrow(townName).toLowerCase(Locale.ROOT);
} catch (InvalidNameException e) {
return false;
}
Expand All @@ -500,7 +499,7 @@ public Town getTown(@NotNull String townName) {

String formattedName;
try {
formattedName = NameValidation.checkAndFilterName(townName).toLowerCase(Locale.ROOT);
formattedName = NameValidation.checkAndFilterTownNameOrThrow(townName).toLowerCase(Locale.ROOT);
} catch (InvalidNameException e) {
return null;
}
Expand Down Expand Up @@ -541,7 +540,7 @@ public void newTown(@NotNull String name) throws AlreadyRegisteredException, Inv
}

private void newTown(String name, boolean assignUUID) throws AlreadyRegisteredException, InvalidNameException {
String filteredName = NameValidation.checkAndFilterName(name);
String filteredName = NameValidation.checkAndFilterTownNameOrThrow(name);

Town town = new Town(filteredName, assignUUID ? UUID.randomUUID() : null);
registerTown(town);
Expand Down Expand Up @@ -621,7 +620,7 @@ public boolean hasNation(@NotNull String nationName) {

String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(nationName).toLowerCase(Locale.ROOT);
filteredName = NameValidation.checkAndFilterNationNameOrThrow(nationName).toLowerCase(Locale.ROOT);
} catch (InvalidNameException ignored) {
return false;
}
Expand Down Expand Up @@ -657,7 +656,7 @@ public Nation getNation(@NotNull String nationName) {

String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(nationName).toLowerCase(Locale.ROOT);
filteredName = NameValidation.checkAndFilterNationNameOrThrow(nationName).toLowerCase(Locale.ROOT);
} catch (InvalidNameException ignored) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,8 @@ protected MenuBuilder load() {
.add("pvp", Translatable.of("plot_group_toggle_help_0"))
.add("explosion", Translatable.of("plot_group_toggle_help_1"))
.add("fire", Translatable.of("plot_group_toggle_help_2"))
.add("mobs", Translatable.of("plot_group_toggle_help_3"));
.add("mobs", Translatable.of("plot_group_toggle_help_3"))
.add("taxed", Translatable.of("plot_group_toggle_help_4"));
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.palmergames.bukkit.towny.event.NationAcceptAllyRequestEvent;
import com.palmergames.bukkit.towny.event.nation.NationKingChangeEvent;
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
import com.palmergames.bukkit.towny.exceptions.InvalidNameException;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.invites.Invite;
Expand Down Expand Up @@ -868,6 +867,9 @@ private void newNation(Player player, String[] split) throws TownyException {
throw new TownyException(Translatable.of("msg_specify_nation_name"));

String nationName = String.join("_", split);
if (TownySettings.getTownAutomaticCapitalisationEnabled())
nationName = StringMgmt.capitalizeStrings(nationName);

Town town = getTownForNationCapital(player);
boolean noCharge = TownySettings.getNewNationPrice() == 0.0 || !TownyEconomyHandler.isActive();
newNation((CommandSender) player, nationName, town, noCharge);
Expand Down Expand Up @@ -900,7 +902,9 @@ public static void newNation(CommandSender sender, String name, Town capitalTown
if (capitalTown.hasNation())
throw new TownyException(Translatable.of("msg_err_already_nation"));

final String filteredName = validateNationNameOrThrow(name);
String filteredName = NameValidation.checkAndFilterNationNameOrThrow(name);
if (TownyUniverse.getInstance().hasNation(filteredName))
throw new TownyException(Translatable.of("msg_err_name_validation_name_already_in_use", filteredName));

BukkitTools.ifCancelledThenThrow(new PreNewNationEvent(capitalTown, filteredName));

Expand Down Expand Up @@ -931,24 +935,6 @@ public static void newNation(CommandSender sender, String name, Town capitalTown
.sendTo(sender);
}

private static String validateNationNameOrThrow(String name) throws TownyException {
if (TownySettings.getTownAutomaticCapitalisationEnabled())
name = StringMgmt.capitalizeStrings(name);

// Check the name is valid and doesn't already exist.
String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(name);
} catch (InvalidNameException e) {
filteredName = null;
}

if (filteredName == null || TownyUniverse.getInstance().hasNation(filteredName) || (!TownySettings.areNumbersAllowedInNationNames() && NameValidation.containsNumbers(filteredName)))
throw new TownyException(Translatable.of("msg_err_invalid_name", name));

return filteredName;
}

public static Nation newNation(String name, Town town) throws AlreadyRegisteredException, NotRegisteredException {
TownyUniverse townyUniverse = TownyUniverse.getInstance();

Expand Down Expand Up @@ -2021,7 +2007,7 @@ private static void nationSetBoard(CommandSender sender, Nation nation, String[]
String line = StringMgmt.join(StringMgmt.remFirstArg(split), " ");

if (!line.equals("none")) {
if (!NameValidation.isValidString(line)) {
if (!NameValidation.isValidBoardString(line)) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_invalid_string_nationboard_not_set"));
return;
}
Expand All @@ -2048,17 +2034,7 @@ private static void nationSetSurname(CommandSender sender, Nation nation, Reside
return;
}

String surname = StringMgmt.join(NameValidation.checkAndFilterArray(StringMgmt.remArgs(split, 2)));
if (surname.length() > TownySettings.getMaxTitleLength()) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_input_too_long"));
return;
}

if (NameValidation.isConfigBlacklistedName(surname)) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_invalid_name"));
return;
}

String surname = NameValidation.checkAndFilterTitlesSurnameOrThrow(StringMgmt.remArgs(split, 2));
resident.setSurname(surname);
resident.save();

Expand Down Expand Up @@ -2087,17 +2063,7 @@ private static void nationSetTitle(CommandSender sender, Nation nation, Resident
return;
}

String title = StringMgmt.join(NameValidation.checkAndFilterArray(StringMgmt.remArgs(split, 2)));
if (title.length() > TownySettings.getMaxTitleLength()) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_err_input_too_long"));
return;
}

if (NameValidation.isConfigBlacklistedName(title)) {
TownyMessaging.sendErrorMsg(sender, Translatable.of("msg_invalid_name"));
return;
}

String title = NameValidation.checkAndFilterTitlesSurnameOrThrow(StringMgmt.remArgs(split, 2));
resident.setTitle(title);
resident.save();

Expand All @@ -2121,10 +2087,8 @@ else if (split[1].equalsIgnoreCase("clear")) {
nation.setTag(" ");
TownyMessaging.sendPrefixedNationMessage(nation, Translatable.of("msg_reset_nation_tag", name));
} else {
if (split[1].length() > TownySettings.getMaxTagLength())
throw new TownyException(Translatable.of("msg_err_tag_too_long"));

nation.setTag(NameValidation.checkAndFilterName(split[1]));
String tag = NameValidation.checkAndFilterTagOrThrow(split[1]);
nation.setTag(tag);
TownyMessaging.sendPrefixedNationMessage(nation, Translatable.of("msg_set_nation_tag", name, nation.getTag()));
if (admin)
TownyMessaging.sendMsg(sender, Translatable.of("msg_set_nation_tag", name, nation.getTag()));
Expand All @@ -2140,10 +2104,12 @@ private static void nationSetName(CommandSender sender, Nation nation, String[]
else {

String name = String.join("_", StringMgmt.remFirstArg(split));

if (NameValidation.isBlacklistName(name) || TownyUniverse.getInstance().hasNation(name) || (!TownySettings.areNumbersAllowedInNationNames() && NameValidation.containsNumbers(name)))
throw new TownyException(Translatable.of("msg_invalid_name"));


name = NameValidation.checkAndFilterGovernmentNameOrThrow(name, nation);
if (TownyUniverse.getInstance().hasNation(name))
throw new TownyException(Translatable.of("msg_err_name_validation_name_already_in_use", name));


if (TownySettings.getTownAutomaticCapitalisationEnabled())
name = StringMgmt.capitalizeStrings(name);

Expand Down
Loading

0 comments on commit 8a0f457

Please sign in to comment.