Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OfflinePlayer and UUID support to Economy backend #7425

Merged
merged 25 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4ea4ba7
Vault offline player support
Warriorrrr Feb 6, 2024
1e05a33
Add deprecated since javadocs.
LlmDl Oct 22, 2024
f6fe74b
Update config-migration version number.
LlmDl Oct 22, 2024
9bc28b8
Flip ternary right way around.
LlmDl Oct 22, 2024
08ad6f8
Remove the legacy debt account conversion.
LlmDl Oct 22, 2024
5e2bb7c
Update admin command permission nodes to follow command structure->node
LlmDl Oct 22, 2024
af9eefe
Remove old comment that no longer applied.
LlmDl Oct 22, 2024
c4fd646
Make economy provider sealed and fix trailing spaces
Warriorrrr Oct 22, 2024
55cb2d0
Change default npc uuid version
Warriorrrr Oct 22, 2024
e9908d2
Fix TownyServerAccount initialization throwing NPE.
LlmDl Oct 22, 2024
e9a328f
Add /ta eco info command.
LlmDl Oct 22, 2024
c7a8785
Add translations for convert command feedback
Warriorrrr Oct 23, 2024
07674be
Set UUID in deprecated methods when available
Warriorrrr Oct 23, 2024
4033e81
Use economy executor for new command
Warriorrrr Oct 23, 2024
c6b2c7c
Update default npc uuid version again
Warriorrrr Oct 23, 2024
824f8f7
Re-modify npc uuids when converting
Warriorrrr Oct 23, 2024
e806be7
Don't endlessly suggest modern
Warriorrrr Oct 23, 2024
5e6b6e8
Add help menu entry
Warriorrrr Oct 23, 2024
803fe3f
Skip accounts with no balance during conversion
Warriorrrr Oct 23, 2024
c73856c
Deprecated unused Account#getBukkitWorld
LlmDl Oct 23, 2024
949cf01
Add debug messages to eco conversion
Warriorrrr Oct 23, 2024
e3af8b6
Cache constructed offline players
Warriorrrr Oct 23, 2024
5b4705d
Fix config-migration.json
LlmDl Oct 23, 2024
553b688
Add conversion progress messages.
LlmDl Oct 23, 2024
1c88785
Add online player warning before conversion.
LlmDl Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Towny/src/main/java/com/palmergames/bukkit/config/ConfigNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -2970,6 +2970,21 @@ public enum ConfigNodes {
"false",
"",
"# Does a conquered town which cannot pay the nation tax get deleted?"),

ECO_ADVANCED_MODERN(
"economy.advanced.modern",
"true",
"",
"# When enabled, Towny will use UUIDs when communicating with your economy plugin.",
"# Most users will never have to touch this, but for existing servers this option will automatically be set to false.",
"# If this option is disabled and you wish to avoid losing data, use the `/townyadmin eco convert modern` command to convert."),

ECO_ADVANCED_NPC_UUID_VERSION(
"economy.advanced.npc_uuid_version",
"-1",
"",
"# The UUID version to use for non-player accounts. This is used so that economy plugins can more easily differentiate between player and NPC accounts.",
"# The default is -1, which disables modifying npc uuids."),

BANKHISTORY(
"bank_history",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.palmergames.bukkit.config.migration;

import com.palmergames.bukkit.config.CommentedConfiguration;
import com.palmergames.bukkit.config.ConfigNodes;
import com.palmergames.bukkit.towny.Towny;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.util.BukkitTools;
import com.palmergames.util.StringMgmt;
Expand All @@ -9,6 +11,8 @@
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -18,17 +22,29 @@
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.logging.Level;

@SuppressWarnings("FieldCanBeLocal")
@SuppressWarnings({"unused", "unchecked"})
public class RunnableMigrations {
private final Map<String, Consumer<CommentedConfiguration>> BY_NAME = new HashMap<>();

public RunnableMigrations() {
BY_NAME.put("migrate_notifications", MIGRATE_NOTIFICATIONS);
BY_NAME.put("add_townblocktype_limits", ADD_TOWNBLOCKTYPE_LIMITS);
BY_NAME.put("convert_entity_class_names", CONVERT_ENTITY_CLASS_NAMES);
BY_NAME.put("add_milkable_animals_to_farm_plot", ADD_MILKABLE_ANIMALS);
BY_NAME.put("update_farm_blocks", UPDATE_FARM_BLOCKS);
try {
for (final Field field : this.getClass().getDeclaredFields()) {
if (!Modifier.isStatic(field.getModifiers()))
continue;

field.setAccessible(true);
Object value = field.get(null);

if (!(value instanceof Consumer))
continue;

BY_NAME.put(field.getName().toLowerCase(Locale.ROOT), (Consumer<CommentedConfiguration>) value);
}
} catch (ReflectiveOperationException e) {
Towny.getPlugin().getLogger().log(Level.WARNING, "Exception occurred when getting runnable migrations", e);
}
}

@Nullable
Expand All @@ -40,7 +56,7 @@ public boolean addMigration(String name, Consumer<CommentedConfiguration> migrat
return BY_NAME.putIfAbsent(name.toLowerCase(Locale.ROOT), migration) == null;
}

private final Consumer<CommentedConfiguration> MIGRATE_NOTIFICATIONS = config -> {
private static final Consumer<CommentedConfiguration> MIGRATE_NOTIFICATIONS = config -> {
if (Boolean.parseBoolean(config.getString("notification.notifications_appear_in_action_bar", "true")))
config.set("notification.notifications_appear_as", "action_bar");
else if (Boolean.parseBoolean(config.getString("notification.notifications_appear_on_bossbar", "false")))
Expand All @@ -49,13 +65,12 @@ else if (Boolean.parseBoolean(config.getString("notification.notifications_appea
config.set("notification.notifications_appear_as", "chat");
};

@SuppressWarnings("unchecked")
private final Consumer<CommentedConfiguration> ADD_TOWNBLOCKTYPE_LIMITS = config -> {
private static final Consumer<CommentedConfiguration> ADD_TOWNBLOCKTYPE_LIMITS = config -> {
for (Map<?, ?> level : config.getMapList("levels.town_level"))
((Map<String, Object>) level).put("townBlockTypeLimits", new HashMap<>());
};

private final Consumer<CommentedConfiguration> CONVERT_ENTITY_CLASS_NAMES = config -> {
private static final Consumer<CommentedConfiguration> CONVERT_ENTITY_CLASS_NAMES = config -> {
List<String> entities = new ArrayList<>(Arrays.asList(config.getString("new_world_settings.plot_management.wild_revert_on_mob_explosion.entities", "").split(",")));

ListIterator<String> iterator = entities.listIterator();
Expand All @@ -79,8 +94,7 @@ else if (Boolean.parseBoolean(config.getString("notification.notifications_appea
config.set("new_world_settings.plot_management.wild_revert_on_mob_explosion.entities", String.join(",", entities));
};

@SuppressWarnings("unchecked")
private final Consumer<CommentedConfiguration> ADD_MILKABLE_ANIMALS = config -> {
private static final Consumer<CommentedConfiguration> ADD_MILKABLE_ANIMALS_TO_FARM_PLOT = config -> {
for (Map<?, ?> plotType : config.getMapList("townblocktypes.types")) {
if (plotType.get("name").equals("farm")) {
String allowedBlocks = (String) plotType.get("allowedBlocks");
Expand All @@ -93,8 +107,7 @@ else if (Boolean.parseBoolean(config.getString("notification.notifications_appea
* 0.100.2.10 included a change which revamped the ItemLists used to construct the farm blocks, resulting in a more comprehensive list.
* This runnable will add any blocks that older configs may have had which were missing from older configs.
*/
@SuppressWarnings("unchecked")
private final Consumer<CommentedConfiguration> UPDATE_FARM_BLOCKS = config -> {
private static final Consumer<CommentedConfiguration> UPDATE_FARM_BLOCKS = config -> {
for (Map<?, ?> plotType : config.getMapList("townblocktypes.types")) {
if (!plotType.get("name").equals("farm"))
continue;
Expand All @@ -106,4 +119,8 @@ else if (Boolean.parseBoolean(config.getString("notification.notifications_appea
((Map<String, Object>) plotType).replace("allowedBlocks", rawBlocks + "," + StringMgmt.join(missingBlocks, ","));
}
};

private static final Consumer<CommentedConfiguration> DISABLE_MODERN_ECO = config -> {
config.set(ConfigNodes.ECO_ADVANCED_MODERN.getRoot(), "false");
};
}
Loading
Loading