Skip to content

Commit

Permalink
Vault offline player support
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr committed Jul 27, 2024
1 parent 0f06d68 commit be898fe
Show file tree
Hide file tree
Showing 27 changed files with 865 additions and 317 deletions.
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 @@ -2924,6 +2924,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",
"2",
"",
"# 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.",
"# Set to -1 to disable 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

0 comments on commit be898fe

Please sign in to comment.