Skip to content

Commit 458d957

Browse files
committed
Add function to keep config up to date over different versions (#19)
1 parent 943cf81 commit 458d957

File tree

2 files changed

+159
-1
lines changed

2 files changed

+159
-1
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package com.dev7ex.multiworld.api.bukkit;
2+
3+
import com.dev7ex.common.bukkit.plugin.configuration.DefaultPluginConfiguration;
4+
import com.dev7ex.multiworld.api.MultiWorldApiConfiguration;
5+
import lombok.AccessLevel;
6+
import lombok.Getter;
7+
import org.bukkit.plugin.Plugin;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.util.Collections;
11+
12+
/**
13+
* @author Dev7ex
14+
* @since 16.08.2023
15+
*/
16+
public abstract class MultiWorldBukkitApiConfiguration extends DefaultPluginConfiguration implements MultiWorldApiConfiguration {
17+
18+
public MultiWorldBukkitApiConfiguration(@NotNull final Plugin plugin) {
19+
super(plugin);
20+
}
21+
22+
@Getter(AccessLevel.PUBLIC)
23+
public enum Entry {
24+
25+
PREFIX("prefix", "§8[§bMultiWorld§8]§r"),
26+
NO_PERMISSION("no-permission",
27+
"§cIm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that is in error."),
28+
PLAYER_NOT_FOUND("player-not-found", "%prefix% §cThis player could not be found"),
29+
ONLY_PLAYER_COMMAND("only-player-command", "%prefix% §cThis command can only performed by a player"),
30+
31+
SETTINGS_AUTO_LOAD("settings.auto-load", Collections.emptyList()),
32+
SETTINGS_RECEIVE_UPDATE_MESSAGE("settings.receive-update-message", true),
33+
SETTINGS_AUTO_GAMEMODE_ENABLED("settings.auto-game-mode-enabled", true),
34+
SETTINGS_ACCESS_NETHER_WORLD_VIA_COMMAND("settings.access-nether-world-via-command", true),
35+
SETTINGS_ACCESS_END_WORLD_VIA_COMMAND("settings.access-end-world-via-command", true),
36+
SETTINGS_WORLD_LINK_ENABLED("settings.world-link-enabled", true),
37+
38+
SETTINGS_DEFAULTS_NORMAL_WORLD("settings.defaults.normal-world", "world"),
39+
SETTINGS_DEFAULTS_END_WORLD("settings.defaults.end-world", "end-world"),
40+
SETTINGS_DEFAULTS_NETHER_WORLD("settings.defaults.nether_world", "nether_world"),
41+
SETTINGS_DEFAULTS_DIFFICULTY("settings.defaults.difficulty", "PEACEFUL"),
42+
SETTINGS_DEFAULTS_GAME_MODE("settings.defaults.game-mode", "SURVIVAL"),
43+
SETTINGS_DEFAULTS_PVP_ENABLED("settings.defaults.pvp-enabled", true),
44+
SETTINGS_DEFAULTS_SPAWN_ANIMALS("settings.defaults.spawn-animals", true),
45+
SETTINGS_DEFAULTS_SPAWN_MONSTERS("settings.defaults.spawn-monsters", true),
46+
SETTINGS_DEFAULTS_END_PORTAL_ACCESSIBLE("settings.defaults.end-portal-accessible", true),
47+
SETTINGS_DEFAULTS_NETHER_PORTAL_ACCESSIBLE("defaults.nether-portal-accessible", true),
48+
SETTINGS_DEFAULTS_WHITELIST_ENABLED("settings.defaults.whitelist-enabled", false),
49+
50+
MESSAGES_GENERAL_UPDATE_MESSAGE_PLAYER("messages.general.update-message-player", "%prefix% §7There is a new update available. §8[§bhttps://www.spigotmc.org/resources/multiworld.92559§8]"),
51+
MESSAGES_GENERAL_UPDATE_MESSAGE_VERSION_PLAYER("messages.general.update-message-version-player", "%prefix% §7Current Version: §b%current_version% §7New Version §b%new_version%"),
52+
MESSAGES_GENERAL_WORLD_NOT_EXISTS("messages.general.world-not-exists", "%prefix% §cThe specified world does not exist!"),
53+
MESSAGES_GENERAL_WORLD_NOT_LOADED("messages.general.world-not-loaded", "%prefix% §cThe specified world is not loaded!"),
54+
MESSAGES_GENERAL_WORLD_ALREADY_EXISTS("messages.general.world-already-exists", "%prefix% §cThe specified world already exists!"),
55+
MESSAGES_GENERAL_WORLD_TYPE_NOT_EXISTS("messages.general.world-type-not-exists", "%prefix% §cThe specified WorldType does not exist"),
56+
MESSAGES_GENERAL_WORLD_FOLDER_NOT_EXISTS("messages.general.world-folder-not-exists", "%prefix% §cNo world folder could be found!"),
57+
MESSAGES_GENERAL_WORLD_WHITELIST_BLOCK_TRESPASSING("messages.general.world-whitelist-block-trespassing", "%prefix% §7You are not on the whitelist of this world!"),
58+
59+
MESSAGES_COMMANDS_BACK_USAGE("messages.commands.back.usage", "%prefix% §cUsage: /world back"),
60+
MESSAGES_COMMANDS_BACK_WORLD_NOT_EXISTS("messages.commands.back.world-not-exists", "%prefix% §cThere is no world you can go!"),
61+
MESSAGES_COMMANDS_BACK_SENDER_ALREADY_THERE("messages.commands.back.sender-already-there", "%prefix% §cYou are already in the world §b%world_name%"),
62+
63+
MESSAGES_COMMANDS_BACKUP_USAGE("messages.commands.backup.usage", "%prefix% §cUsage: /world backup <World>"),
64+
MESSAGES_COMMANDS_BACKUP_STARTING("messages.commands.backup.starting", "%prefix% §7A backup of the world §b%world_name% is created..."),
65+
MESSAGES_COMMANDS_BACKUP_FINISHED("messages.commands.backup.finished", "%prefix% §7The backup of the world §b%world_name% §7has been successfully created!"),
66+
67+
MESSAGES_COMMANDS_CLONE_USAGE("messages.commands.clone.usage", "%prefix% §cUsage: /world clone <World> <Name>"),
68+
MESSAGES_COMMANDS_CLONE_STARTING("messages.commands.clone.starting", "%prefix% §7The world §b%world_name% §7will be copied..."),
69+
MESSAGES_COMMANDS_CLONE_FINISHED("messages.commands.clone.finished", "%prefix% §7The world §b%world_name% §7has been successfully copied!"),
70+
71+
MESSAGES_COMMANDS_CREATE_USAGE("messages.commands.create.usage", "%prefix% §cUsage: /world create <Name> <Generator | Seed | WorldType>"),
72+
MESSAGES_COMMANDS_CREATE_STARTING("messages.commands.create.starting", "%prefix% §7The world §b%world_name% §7will be created..."),
73+
MESSAGES_COMMANDS_CREATE_FINISHED("messages.commands.create.finished", "%prefix% §7The world §b%world_name% §7was created successfully!"),
74+
75+
MESSAGES_COMMANDS_DELETE_USAGE("messages.commands.delete.usage", "%prefix% §cUsage: /world delete <World>"),
76+
MESSAGES_COMMANDS_DELETE_WORLD_CANNOT_DELETED("messages.commands.delete.world-cannot-deleted", "%prefix% §cThe specified world may not be deleted!"),
77+
MESSAGES_COMMANDS_DELETE_STARTING("messages.commands.delete.starting", "%prefix% §7The world §b%world_name% §7will be deleted..."),
78+
MESSAGES_COMMANDS_DELETE_FINISHED("messages.commands.delete.finished", "%prefix% §7The world §b%world_name% §7has been successfully deleted!"),
79+
80+
MESSAGES_COMMANDS_FLAG_USAGE("messages.commands.flag.usage", "%prefix% §cUsage: /world flag <World> <Flag> <Value>"),
81+
MESSAGES_COMMANDS_FLAG_NOT_EXISTING("messages.commands.flag.not-existing", "%prefix% §cThis flag does not exist"),
82+
MESSAGES_COMMANDS_FLAG_VALUE_NOT_EXISTING("messages.commands.flag.value-not-existing", "%prefix% §cThis value does not exist for the flag §b%flag%"),
83+
MESSAGES_COMMANDS_FLAG_SUCCESSFULLY_SET("messages.commands.flag.successfully-set", "%prefix% §7The flag §b%flag% §7was set to §b%value% §7!"),
84+
85+
MESSAGES_COMMANDS_HELP_MESSAGE("messages.commands.help.message", "DELETE YOUR CONFIG.YML AND RELOAD"),
86+
87+
MESSAGES_COMMANDS_IMPORT_USAGE("messages.commands.import.usage", "%prefix% §cUsage: /world import <Name> <WorldType | Generator>"),
88+
MESSAGES_COMMANDS_IMPORT_WORLD_ALREADY_IMPORTED("messages.commands.import.world-already-imported", "%prefix% §7The world §b%world_name% §7is already imported!"),
89+
MESSAGES_COMMANDS_IMPORT_STARTING("messages.commands.import.starting", "%prefix% §7The world §b%world_name% §7will import..."),
90+
MESSAGES_COMMANDS_IMPORT_FINISHED("messages.commands.import.finished", "%prefix% §7The world §b%world_name% §7was successfully imported!"),
91+
92+
MESSAGES_COMMANDS_INFO_USAGE("messages.commands.info.usage", "'%prefix% §cUsage: /world info <World>'"),
93+
MESSAGES_COMMANDS_INFO_MESSAGE("messages.commands.info.message", "DELETE YOUR CONFIG.YML AND RELOAD"),
94+
95+
MESSAGES_COMMANDS_LIST_USAGE("messages.commands.list.usage", "%prefix% §cUsage: /world list"),
96+
MESSAGES_COMMANDS_LIST_MESSAGE("messages.commands.list.message", "%prefix% §aWorlds: %world_names%"),
97+
98+
MESSAGES_COMMANDS_LINK_USAGE("messages.commands.link.usage", "%prefix% §cUsage: /world link <World> <End | Nether> <World>"),
99+
MESSAGES_COMMANDS_LINK_ENVIRONMENT_NOT_EXISTS("messages.commands.link.environment-not-exists", "%prefix% §cThe specified environment does not exist!"),
100+
MESSAGES_COMMANDS_LINK_SUCCESSFULLY_SET("messages.commands.link.successfully-set", "%prefix% §7You have connected the portal of the environment §b%environment_name% §7in the world §b%world_name% §7with the world §b%target_world_name%"),
101+
102+
MESSAGES_COMMANDS_LOAD_USAGE("messages.commands.load.usage", "%prefix% §cUsage: /world load <Name>"),
103+
MESSAGES_COMMANDS_LOAD_WORLD_ALREADY_LOADED("messages.commands.load.world-already-loaded", "%prefix% §7The world §bworld_name% §7is already loaded!"),
104+
MESSAGES_COMMANDS_LOAD_STARTING("messages.commands.load.starting", "%prefix% §7The world §b%world_name% §7will loaded..."),
105+
MESSAGES_COMMANDS_LOAD_FINISHED("messages.commands.load.finished", "%prefix% §7The world §b%world_name% §7was successfully loaded!"),
106+
107+
MESSAGES_COMMANDS_RELOAD_USAGE("messages.commands.reload.usage", "%prefix% §cUsage: /world reload"),
108+
MESSAGES_COMMANDS_RELOAD_MESSAGE("messages.commands.reload.message", "%prefix% §7The configurations has been reloaded!"),
109+
110+
MESSAGES_COMMANDS_TELEPORT_USAGE("messages.commands.teleport.usage", "%prefix% §cUsage: /world teleport <Player> <World>"),
111+
MESSAGES_COMMANDS_TELEPORT_MESSAGE("messages.commands.teleport.message", "%prefix% §a%player_name% §7is teleported to the world §b%world_name% §7!"),
112+
MESSAGES_COMMANDS_TELEPORT_SENDER_ALREADY_THERE("messages.commands.teleport.sender-already-there", "%prefix% §7You are already in the world §b%world_name%"),
113+
MESSAGES_COMMANDS_TARGET_ALREADY_THERE("messages.commands.teleport.target-already-there", "%prefix% §7The player §a%player_name% §7is already in the world §b%world_name%"),
114+
MESSAGES_COMMANDS_TELEPORT_NETHER_NOT_ACCESSIBLE("messages.commands.teleport.nether-not-accessible", "%prefix% §cYou cant enter the Nether via the command!"),
115+
MESSAGES_COMMANDS_TELEPORT_END_NOT_ACCESSIBLE("messages.commands.teleport.end-not-accessible", "%prefix% §cYou cant enter the end via the command!"),
116+
117+
MESSAGES_COMMANDS_UNLOAD_USAGE("messages.commands.unload.usage", "%prefix% §cUsage: /world unload <World>"),
118+
MESSAGES_COMMANDS_UNLOAD_WORLD_CANNOT_UNLOADED("messages.commands.unload.world-cannot-unloaded", "%prefix% §cThe specified world must not be unloaded!"),
119+
MESSAGES_COMMANDS_UNLOAD_STARTING("messages.commands.unload.starting", "%prefix% §7The world §b%world_name% §7will be unloaded..."),
120+
MESSAGES_COMMANDS_UNLOAD_FINISHED("messages.commands.unload.finished", "%prefix% §7The world §b%world_name% §7was successfully unloaded!"),
121+
MESSAGES_COMMANDS_UNLOAD_CHUNK_STARTING("messages.commands.unload.chunk-starting", "%prefix% §7The chunks in §b%world_name% §7are unloaded..."),
122+
MESSAGES_COMMANDS_UNLOAD_CHUNK_FINISHED("messages.commands.unload.chunk-finished", "%prefix% §7The chunks in §b%world_name% §7were successfully unloaded!"),
123+
MESSAGES_COMMANDS_UNLOAD_CHUNK_TELEPORT("messages.commands.unload.chunk-teleport", "%prefix% §7The world you were in will be unloaded. You will be teleported!"),
124+
125+
MESSAGES_COMMANDS_WHITELIST_USAGE("messages.commands.whitelist.usage", "%prefix% §cUsage: /world whitelist <World> <On | Off | Add | List | Remove> <Player>"),
126+
MESSAGES_COMMANDS_WHITELIST_ADD_ALREADY_ADDED("messages.commands.whitelist.add.already-added", "%prefix% §The player %player_name% §7is already §7on the whitelist!"),
127+
MESSAGES_COMMANDS_WHITELIST_SUCCESSFULLY_ADDED("messages.commands.whitelist.add.successfully-added", "%prefix% §7You have added %player_name% §7to the whitelist of world §b%world_name%"),
128+
MESSAGES_COMMANDS_WHITELIST_LIST_EMPTY("messages.commands.whitelist.list.empty", "%prefix% §7The whitelist for world §b%world_name% §7is empty"),
129+
MESSAGES_COMMANDS_WHITELIST_LIST_MESSAGE("messages.commands.whitelist.list.message", "%prefix% §7Whitelist: %player_names%"),
130+
MESSAGES_COMMANDS_WHITELIST_DISABLE_ALREADY_DISABLED("messages.commands.whitelist.disable.already-disabled", "%prefix% §7World whitelist §b%world_name% §7is already disabled!"),
131+
MESSAGES_COMMANDS_WHITELIST_SUCCESSFULLY_DISABLED("messages.commands.whitelist.disable.successfully-disabled", "%prefix% §7You have disabled the whitelist in the world §b%world_name%§7!"),
132+
MESSAGES_COMMANDS_WHITELIST_ALREADY_ENABLED("messages.commands.whitelist.enable.already-enabled", "%prefix% §7The world whitelist §b%world_name% §7is already activated!"),
133+
MESSAGES_COMMANDS_WHITELIST_SUCCESSFULLY_ENABLED("messages.commands.whitelist.enable.successfully-enabled", "%prefix% §7You have activated the whitelist in the world §b%world_name% §7!"),
134+
MESSAGES_COMMANDS_WHITELIST_ALREADY_REMOVED("messages.commands.whitelist.remove.already-removed", "%prefix% §7The player %player_name% §7is §not §7on the whitelist!"),
135+
MESSAGES_COMMANDS_WHITELIST_SUCCESSFULLY_REMOVED("messages.commands.whitelist.remove.successfully-removed", "%prefix% §7You have %player_name% §7removed from the §b%world_name% §7whitelist");
136+
137+
138+
private final String path;
139+
private final Object defaultValue;
140+
141+
Entry(@NotNull final String path, @NotNull final Object defaultValue) {
142+
this.path = path;
143+
this.defaultValue = defaultValue;
144+
}
145+
}
146+
147+
}

multiworld-bukkit/src/main/java/com/dev7ex/multiworld/MultiWorldConfiguration.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import com.dev7ex.common.bukkit.plugin.configuration.DefaultPluginConfiguration;
55
import com.dev7ex.common.map.ParsedMap;
66
import com.dev7ex.multiworld.api.MultiWorldApiConfiguration;
7+
import com.dev7ex.multiworld.api.bukkit.MultiWorldBukkitApiConfiguration;
78
import com.dev7ex.multiworld.api.world.WorldDefaultProperty;
89
import lombok.AccessLevel;
910
import lombok.Getter;
1011
import org.bukkit.plugin.Plugin;
1112
import org.jetbrains.annotations.NotNull;
1213

14+
import java.util.Collections;
1315
import java.util.List;
1416

1517
/**
@@ -18,7 +20,7 @@
1820
*/
1921
@Getter(AccessLevel.PUBLIC)
2022
@ConfigurationProperties(fileName = "config.yml")
21-
public final class MultiWorldConfiguration extends DefaultPluginConfiguration implements MultiWorldApiConfiguration {
23+
public final class MultiWorldConfiguration extends MultiWorldBukkitApiConfiguration implements MultiWorldApiConfiguration {
2224

2325
private final ParsedMap<WorldDefaultProperty, Object> defaultProperties = new ParsedMap<>();
2426

@@ -30,9 +32,18 @@ public MultiWorldConfiguration(@NotNull final Plugin plugin) {
3032
public void load() {
3133
super.load();
3234

35+
for (final MultiWorldBukkitApiConfiguration.Entry entry : MultiWorldBukkitApiConfiguration.Entry.values()) {
36+
if (super.getFileConfiguration().contains(entry.getPath())) {
37+
continue;
38+
}
39+
super.getPlugin().getLogger().info("Adding Missing Config Entry: " + entry.getPath());
40+
super.getFileConfiguration().set(entry.getPath(), entry.getDefaultValue());
41+
}
42+
3343
super.getFileConfiguration().getConfigurationSection("settings.defaults").getKeys(false)
3444
.stream()
3545
.forEach(entry -> this.defaultProperties.put(WorldDefaultProperty.valueOf(entry.replaceAll("-", "_").toUpperCase()), super.getFileConfiguration().get("settings.defaults." + entry)));
46+
super.saveFile();
3647

3748
}
3849

0 commit comments

Comments
 (0)