mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-15 15:15:38 +01:00
refactor: Remove use of MVCoreConfigProvider
This commit is contained in:
parent
a8c8ef7a6b
commit
9f1ddcc81e
@ -23,7 +23,7 @@ import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
|
||||
import com.onarandombox.MultiverseCore.economy.MVEconomist;
|
||||
import com.onarandombox.MultiverseCore.inject.InjectableListener;
|
||||
@ -55,7 +55,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
|
||||
private ServiceLocator serviceLocator;
|
||||
@Inject
|
||||
private MVCoreConfigProvider configProvider;
|
||||
private MVCoreConfig config;
|
||||
@Inject
|
||||
private Provider<MVWorldManager> worldManagerProvider;
|
||||
@Inject
|
||||
@ -100,8 +100,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
initializeDependencyInjection();
|
||||
|
||||
// Load our configs first as we need them for everything else.
|
||||
this.loadConfigs();
|
||||
if (!getConfigProvider().isConfigLoaded()) {
|
||||
if (config == null || !config.isLoaded()) {
|
||||
Logging.severe("Your configs were not loaded.");
|
||||
Logging.severe("Please check your configs and restart the server.");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
@ -112,15 +111,16 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
|
||||
var worldManager = worldManagerProvider.get();
|
||||
|
||||
worldManager.loadWorldsConfig();
|
||||
worldManager.getDefaultWorldGenerators();
|
||||
worldManager.loadDefaultWorlds();
|
||||
worldManager.loadWorlds(true);
|
||||
|
||||
// Now set the firstspawnworld (after the worlds are loaded):
|
||||
worldManager.setFirstSpawnWorld(getConfigProvider().getConfig().getFirstSpawnLocation());
|
||||
worldManager.setFirstSpawnWorld(config.getFirstSpawnLocation());
|
||||
MVWorld firstSpawnWorld = worldManager.getFirstSpawnWorld();
|
||||
if (firstSpawnWorld != null) {
|
||||
getConfigProvider().getConfig().setFirstSpawnLocation(firstSpawnWorld.getName());
|
||||
config.setFirstSpawnLocation(firstSpawnWorld.getName());
|
||||
}
|
||||
|
||||
//Setup economy here so vault is loaded
|
||||
@ -134,7 +134,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
this.registerDestinations();
|
||||
this.setupMetrics();
|
||||
this.loadPlaceholderAPIIntegration();
|
||||
this.saveMVConfig();
|
||||
this.saveAllConfigs();
|
||||
this.logEnableMessage();
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
}
|
||||
|
||||
private boolean shouldShowConfig() {
|
||||
return !getConfigProvider().getConfig().getSilentStart();
|
||||
return !config.getSilentStart();
|
||||
}
|
||||
|
||||
private void loadEconomist() {
|
||||
@ -251,24 +251,20 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
private void logEnableMessage() {
|
||||
Logging.config("Version %s (API v%s) Enabled - By %s", this.getDescription().getVersion(), PROTOCOL, getAuthors());
|
||||
|
||||
if (getConfigProvider().getConfig().isShowingDonateMessage()) {
|
||||
if (config.isShowingDonateMessage()) {
|
||||
Logging.config("Help dumptruckman keep this project alive. Become a patron! https://www.patreon.com/dumptruckman");
|
||||
Logging.config("One time donations are also appreciated: https://www.paypal.me/dumptruckman");
|
||||
}
|
||||
}
|
||||
|
||||
private void loadPlaceholderAPIIntegration() {
|
||||
if (getConfigProvider().getConfig().isRegisterPapiHook()
|
||||
if (config.isRegisterPapiHook()
|
||||
&& getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
Try.run(() -> serviceLocator.createAndInitialize(MultiverseCorePlaceholders.class))
|
||||
.onFailure(e -> Logging.severe("Failed to load PlaceholderAPI integration.", e));
|
||||
}
|
||||
}
|
||||
|
||||
private MVCoreConfigProvider getConfigProvider() {
|
||||
return configProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -339,34 +335,14 @@ public class MultiverseCore extends JavaPlugin implements MVCore {
|
||||
this.pluginCount -= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void loadConfigs() {
|
||||
getConfigProvider().loadConfigs();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean saveMVConfig() {
|
||||
return getConfigProvider().saveConfig()
|
||||
.map(v -> true)
|
||||
.recover(e -> {
|
||||
Logging.severe(e.getMessage(), e);
|
||||
return false;
|
||||
})
|
||||
.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean saveAllConfigs() {
|
||||
return this.saveMVConfig() && worldManagerProvider.get().saveWorldsConfig();
|
||||
return config.save()
|
||||
&& worldManagerProvider.get().saveWorldsConfig()
|
||||
&& anchorManagerProvider.get().saveAnchors();
|
||||
}
|
||||
|
||||
//TODO: REMOVE THIS STATIC CRAP - START
|
||||
|
@ -10,7 +10,7 @@ package com.onarandombox.MultiverseCore.anchor;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.LocationManipulation;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -38,17 +38,17 @@ public class AnchorManager {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final LocationManipulation locationManipulation;
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
|
||||
@Inject
|
||||
public AnchorManager(
|
||||
MultiverseCore plugin,
|
||||
LocationManipulation locationManipulation,
|
||||
MVCoreConfigProvider configProvider
|
||||
MVCoreConfig config
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.locationManipulation = locationManipulation;
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
|
||||
this.anchors = new HashMap<String, Location>();
|
||||
}
|
||||
@ -160,8 +160,8 @@ public class AnchorManager {
|
||||
// Add to the list if we're not enforcing access
|
||||
// OR
|
||||
// We are enforcing access and the user has the permission.
|
||||
if (!this.configProvider.getConfig().getEnforceAccess() ||
|
||||
(this.configProvider.getConfig().getEnforceAccess() && p.hasPermission(worldPerm))) {
|
||||
if (!config.getEnforceAccess() ||
|
||||
(config.getEnforceAccess() && p.hasPermission(worldPerm))) {
|
||||
myAnchors.add(anchor);
|
||||
} else {
|
||||
Logging.finer(String.format("Not adding anchor %s to the list, user %s doesn't have the %s " +
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.onarandombox.MultiverseCore.configuration.node.NodeGroup;
|
||||
import com.onarandombox.MultiverseCore.placeholders.MultiverseCorePlaceholders;
|
||||
import org.jvnet.hk2.annotations.Contract;
|
||||
|
||||
@Contract
|
||||
public interface MVConfig {
|
||||
|
||||
/**
|
||||
@ -13,10 +13,16 @@ public interface MVConfig {
|
||||
*/
|
||||
boolean load();
|
||||
|
||||
/**
|
||||
* Whether the config has been loaded.
|
||||
* @return True if the config has been loaded.
|
||||
*/
|
||||
boolean isLoaded();
|
||||
|
||||
/**
|
||||
* Saves the config to disk.
|
||||
*/
|
||||
void save();
|
||||
boolean save();
|
||||
|
||||
/**
|
||||
* Gets the nodes for the config.
|
||||
|
@ -14,19 +14,6 @@ package com.onarandombox.MultiverseCore.api;
|
||||
*/
|
||||
public interface MVCore extends MVPlugin {
|
||||
|
||||
/**
|
||||
* Reloads the Multiverse Configuration files:
|
||||
* worlds.yml and config.yml.
|
||||
*/
|
||||
void loadConfigs();
|
||||
|
||||
/**
|
||||
* Saves the Multiverse-Config.
|
||||
*
|
||||
* @return Whether the Multiverse-Config was successfully saved
|
||||
*/
|
||||
boolean saveMVConfig();
|
||||
|
||||
/**
|
||||
* Saves all configs.
|
||||
*
|
||||
|
@ -7,11 +7,9 @@
|
||||
|
||||
package com.onarandombox.MultiverseCore.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.onarandombox.MultiverseCore.world.SimpleWorldPurger;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.WorldType;
|
||||
@ -246,10 +244,9 @@ public interface MVWorldManager {
|
||||
/**
|
||||
* Load the config from a file.
|
||||
*
|
||||
* @param file The file to load.
|
||||
* @return A loaded configuration.
|
||||
*/
|
||||
FileConfiguration loadWorldConfig(File file);
|
||||
FileConfiguration loadWorldsConfig();
|
||||
|
||||
/**
|
||||
* Saves the world config to disk.
|
||||
|
@ -13,7 +13,7 @@ import com.onarandombox.MultiverseCore.api.MVConfig;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.MVConfigValue;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
@ -22,16 +22,12 @@ import org.jvnet.hk2.annotations.Service;
|
||||
@CommandAlias("mv")
|
||||
public class ConfigCommand extends MultiverseCommand {
|
||||
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
|
||||
@Inject
|
||||
public ConfigCommand(@NotNull MVCommandManager commandManager, @NotNull MVCoreConfigProvider configProvider) {
|
||||
public ConfigCommand(@NotNull MVCommandManager commandManager, @NotNull MVCoreConfig config) {
|
||||
super(commandManager);
|
||||
this.configProvider = configProvider;
|
||||
}
|
||||
|
||||
private MVConfig getConfig() {
|
||||
return configProvider.getConfig();
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Subcommand("config")
|
||||
@ -59,20 +55,20 @@ public class ConfigCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
private void showConfigValue(BukkitCommandIssuer issuer, String name) {
|
||||
Object currentValue = getConfig().getProperty(name);
|
||||
Object currentValue = config.getProperty(name);
|
||||
if (currentValue == null) {
|
||||
issuer.sendMessage("No such config option: " + name);
|
||||
return;
|
||||
}
|
||||
issuer.sendMessage(name + "is currently set to " + getConfig().getProperty(name));
|
||||
issuer.sendMessage(name + "is currently set to " + config.getProperty(name));
|
||||
}
|
||||
|
||||
private void updateConfigValue(BukkitCommandIssuer issuer, String name, Object value) {
|
||||
if (!getConfig().setProperty(name, value)) {
|
||||
if (!config.setProperty(name, value)) {
|
||||
issuer.sendMessage("Unable to set " + name + " to " + value);
|
||||
return;
|
||||
}
|
||||
getConfig().save();
|
||||
config.save();
|
||||
issuer.sendMessage("Successfully set " + name + " to " + value);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -21,17 +21,17 @@ import org.jvnet.hk2.annotations.Service;
|
||||
@CommandAlias("mv")
|
||||
public class DebugCommand extends MultiverseCommand {
|
||||
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final MultiverseCore plugin;
|
||||
|
||||
@Inject
|
||||
public DebugCommand(
|
||||
@NotNull MVCommandManager commandManager,
|
||||
@NotNull MVCoreConfigProvider configProvider,
|
||||
@NotNull MVCoreConfig config,
|
||||
@NotNull MultiverseCore plugin
|
||||
) {
|
||||
super(commandManager);
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -53,13 +53,13 @@ public class DebugCommand extends MultiverseCommand {
|
||||
@Description("{@@mv-core.debug.change.level.description}")
|
||||
int level) {
|
||||
|
||||
this.configProvider.getConfig().setGlobalDebug(level);
|
||||
this.plugin.saveAllConfigs();
|
||||
config.setGlobalDebug(level);
|
||||
config.save();
|
||||
this.displayDebugMode(issuer);
|
||||
}
|
||||
|
||||
private void displayDebugMode(BukkitCommandIssuer issuer) {
|
||||
final int debugLevel = this.configProvider.getConfig().getGlobalDebug();
|
||||
final int debugLevel = config.getGlobalDebug();
|
||||
if (debugLevel == 0) {
|
||||
issuer.sendInfo(MVCorei18n.DEBUG_INFO_OFF);
|
||||
return;
|
||||
|
@ -8,11 +8,13 @@ import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.anchor.AnchorManager;
|
||||
import com.onarandombox.MultiverseCore.api.MVCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent;
|
||||
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
|
||||
import jakarta.inject.Inject;
|
||||
@ -24,7 +26,7 @@ import org.jvnet.hk2.annotations.Service;
|
||||
@CommandAlias("mv")
|
||||
public class ReloadCommand extends MultiverseCommand {
|
||||
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final AnchorManager anchorManager;
|
||||
private final MVWorldManager worldManager;
|
||||
private final PluginManager pluginManager;
|
||||
@ -32,13 +34,13 @@ public class ReloadCommand extends MultiverseCommand {
|
||||
@Inject
|
||||
public ReloadCommand(
|
||||
@NotNull MVCommandManager commandManager,
|
||||
@NotNull MVCoreConfigProvider configProvider,
|
||||
@NotNull MVCoreConfig config,
|
||||
@NotNull AnchorManager anchorManager,
|
||||
@NotNull MVWorldManager worldManager,
|
||||
@NotNull PluginManager pluginManager
|
||||
) {
|
||||
super(commandManager);
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.anchorManager = anchorManager;
|
||||
this.worldManager = worldManager;
|
||||
this.pluginManager = pluginManager;
|
||||
@ -49,9 +51,10 @@ public class ReloadCommand extends MultiverseCommand {
|
||||
@Description("{@@mv-core.reload.description}")
|
||||
public void onReloadCommand(@NotNull BukkitCommandIssuer issuer) {
|
||||
issuer.sendInfo(MVCorei18n.RELOAD_RELOADING);
|
||||
this.configProvider.loadConfigs();
|
||||
this.anchorManager.loadAnchors();
|
||||
this.config.load();
|
||||
this.worldManager.loadWorldsConfig();
|
||||
this.worldManager.loadWorlds(true);
|
||||
this.anchorManager.loadAnchors();
|
||||
|
||||
List<String> configsLoaded = new ArrayList<>();
|
||||
configsLoaded.add("Multiverse-Core - config.yml");
|
||||
|
@ -18,7 +18,7 @@ import co.aikar.commands.RootCommand;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import jakarta.inject.Inject;
|
||||
@ -38,7 +38,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
@NotNull MVCommandManager mvCommandManager,
|
||||
@NotNull MVWorldManager worldManager,
|
||||
@NotNull DestinationsProvider destinationsProvider,
|
||||
@NotNull MVCoreConfigProvider configProvider
|
||||
@NotNull MVCoreConfig config
|
||||
) {
|
||||
super(mvCommandManager);
|
||||
this.commandManager = mvCommandManager;
|
||||
@ -49,7 +49,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
registerAsyncCompletion("destinations", this::suggestDestinations);
|
||||
registerAsyncCompletion("flags", this::suggestFlags);
|
||||
registerStaticCompletion("gamerules", this::suggestGamerules);
|
||||
registerStaticCompletion("mvconfigs", configProvider.getConfig().getNodes().getNames());
|
||||
registerStaticCompletion("mvconfigs", config.getNodes().getNames());
|
||||
registerAsyncCompletion("mvworlds", this::suggestMVWorlds);
|
||||
|
||||
setDefaultCompletion("destinations", ParsedDestination.class);
|
||||
|
@ -14,7 +14,7 @@ import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.GameRuleValue;
|
||||
import com.onarandombox.MultiverseCore.commandtools.context.MVConfigValue;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import com.onarandombox.MultiverseCore.display.filters.ContentFilter;
|
||||
@ -33,19 +33,19 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
|
||||
private final DestinationsProvider destinationsProvider;
|
||||
private final MVWorldManager worldManager;
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
|
||||
@Inject
|
||||
public MVCommandContexts(
|
||||
MVCommandManager mvCommandManager,
|
||||
DestinationsProvider destinationsProvider,
|
||||
MVWorldManager worldManager,
|
||||
MVCoreConfigProvider configProvider
|
||||
MVCoreConfig config
|
||||
) {
|
||||
super(mvCommandManager);
|
||||
this.destinationsProvider = destinationsProvider;
|
||||
this.worldManager = worldManager;
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
|
||||
registerIssuerOnlyContext(BukkitCommandIssuer.class, BukkitCommandExecutionContext::getIssuer);
|
||||
registerOptionalContext(ContentFilter.class, this::parseContentFilter);
|
||||
@ -123,7 +123,7 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
if (Strings.isNullOrEmpty(configName)) {
|
||||
throw new InvalidCommandArgument("No config name specified.");
|
||||
}
|
||||
Optional<CommentedNode> node = configProvider.getConfig().getNodes().findNode(configName);
|
||||
Optional<CommentedNode> node = config.getNodes().findNode(configName);
|
||||
if (node.isEmpty()) {
|
||||
throw new InvalidCommandArgument("The config " + configName + " is not valid.");
|
||||
}
|
||||
|
@ -15,33 +15,28 @@ import com.onarandombox.MultiverseCore.configuration.migration.InvertBoolMigrato
|
||||
import com.onarandombox.MultiverseCore.configuration.migration.MoveMigratorAction;
|
||||
import com.onarandombox.MultiverseCore.configuration.migration.VersionMigrator;
|
||||
import com.onarandombox.MultiverseCore.configuration.node.NodeGroup;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
@Service
|
||||
public class MVCoreConfig implements MVConfig {
|
||||
public static final String CONFIG_FILENAME = "config.yml";
|
||||
public static final double CONFIG_VERSION = 5.0;
|
||||
|
||||
/**
|
||||
* Creates a new DefaultMVConfig instance and loads the configuration automatically.
|
||||
*
|
||||
* @param core The MultiverseCore instance.
|
||||
* @return The new DefaultMVConfig instance.
|
||||
*/
|
||||
public static MVCoreConfig init(MultiverseCore core) {
|
||||
var config = new MVCoreConfig(core);
|
||||
config.load();
|
||||
config.save();
|
||||
return config;
|
||||
}
|
||||
|
||||
private final Path configPath;
|
||||
private final MVCoreConfigNodes configNodes;
|
||||
private final ConfigHandle configHandle;
|
||||
|
||||
public MVCoreConfig(MultiverseCore core) {
|
||||
configPath = Path.of(core.getDataFolder().getPath(), CONFIG_FILENAME);
|
||||
configNodes = new MVCoreConfigNodes(core.getService(PluginManager.class));
|
||||
configHandle = ConfigHandle.builder(configPath)
|
||||
@Inject
|
||||
MVCoreConfig(
|
||||
@NotNull MultiverseCore core,
|
||||
@NotNull PluginManager pluginManager
|
||||
) {
|
||||
this.configPath = Path.of(core.getDataFolder().getPath(), CONFIG_FILENAME);
|
||||
this.configNodes = new MVCoreConfigNodes(pluginManager);
|
||||
this.configHandle = ConfigHandle.builder(configPath)
|
||||
.logger(Logging.getLogger())
|
||||
.nodes(configNodes.getNodes())
|
||||
.migrator(ConfigMigrator.builder(configNodes.VERSION)
|
||||
@ -76,6 +71,8 @@ public class MVCoreConfig implements MVConfig {
|
||||
.build();
|
||||
|
||||
migrateFromOldConfigFile();
|
||||
load();
|
||||
save();
|
||||
}
|
||||
|
||||
private void migrateFromOldConfigFile() {
|
||||
@ -100,8 +97,14 @@ public class MVCoreConfig implements MVConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
public boolean isLoaded() {
|
||||
return configHandle.isLoaded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save() {
|
||||
configHandle.save();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,13 +4,16 @@ import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.configuration.node.MVCommentedNode;
|
||||
import com.onarandombox.MultiverseCore.configuration.node.MVValueNode;
|
||||
import com.onarandombox.MultiverseCore.configuration.node.NodeGroup;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import io.github.townyadvanced.commentedconfiguration.setting.CommentedNode;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
class MVCoreConfigNodes {
|
||||
|
||||
private final NodeGroup nodes = new NodeGroup();
|
||||
private final PluginManager pluginManager;
|
||||
private PluginManager pluginManager;
|
||||
|
||||
MVCoreConfigNodes(PluginManager pluginManager) {
|
||||
this.pluginManager = pluginManager;
|
||||
@ -173,7 +176,13 @@ class MVCoreConfigNodes {
|
||||
.defaultValue(0)
|
||||
.name("global-debug")
|
||||
.validator(value -> value >= 0 && value <= 3)
|
||||
.onSetValue((oldValue, newValue) -> Logging.setDebugLevel(newValue)) //TODO Debug event
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
int level = Logging.getDebugLevel();
|
||||
Logging.setDebugLevel(newValue);
|
||||
if (level != Logging.getDebugLevel()) {
|
||||
pluginManager.callEvent(new MVDebugModeEvent(level));
|
||||
}
|
||||
})
|
||||
.build());
|
||||
|
||||
public final MVValueNode<Boolean> SILENT_START = node(MVValueNode.builder("misc.silent-start", Boolean.class)
|
||||
|
@ -1,89 +0,0 @@
|
||||
package com.onarandombox.MultiverseCore.config;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVConfig;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import io.vavr.control.Try;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Provider;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Service
|
||||
public final class MVCoreConfigProvider {
|
||||
|
||||
private static final String WORLDS_CONFIG_FILE = "worlds.yml";
|
||||
|
||||
private volatile MVCoreConfig config;
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final PluginManager pluginManager;
|
||||
|
||||
private final Provider<MVWorldManager> worldManagerProvider; // TODO remove this dependency
|
||||
|
||||
@Inject
|
||||
MVCoreConfigProvider(
|
||||
MultiverseCore plugin,
|
||||
PluginManager pluginManager,
|
||||
Provider<MVWorldManager> worldManagerProvider
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.pluginManager = pluginManager;
|
||||
this.worldManagerProvider = worldManagerProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the config is loaded.
|
||||
*
|
||||
* @return True if the config is loaded, false otherwise
|
||||
*/
|
||||
public boolean isConfigLoaded() {
|
||||
return config != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Core configuration instance. If the config has not been loaded yet, it will first be loaded.
|
||||
*
|
||||
* @return The config
|
||||
*/
|
||||
@NotNull
|
||||
public MVConfig getConfig() {
|
||||
if (config == null) {
|
||||
loadConfigs();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public void loadConfigs() {
|
||||
config = MVCoreConfig.init(plugin);
|
||||
|
||||
loadWorldConfigs();
|
||||
|
||||
setDebugLevelFromConfig(config);
|
||||
}
|
||||
|
||||
private void loadWorldConfigs() {
|
||||
worldManagerProvider.get().loadWorldConfig(new File(plugin.getDataFolder(), WORLDS_CONFIG_FILE));
|
||||
}
|
||||
|
||||
private void setDebugLevelFromConfig(@NotNull MVConfig config) {
|
||||
int level = Logging.getDebugLevel();
|
||||
Logging.setDebugLevel(config.getGlobalDebug());
|
||||
if (level != Logging.getDebugLevel()) {
|
||||
pluginManager.callEvent(new MVDebugModeEvent(level));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Try<Void> saveConfig() {
|
||||
if (config != null) {
|
||||
return Try.run(() -> config.save());
|
||||
}
|
||||
return Try.failure(new IllegalStateException("Config not loaded yet"));
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package com.onarandombox.MultiverseCore.listeners;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.inject.InjectableListener;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -16,17 +16,17 @@ import org.jvnet.hk2.annotations.Service;
|
||||
*/
|
||||
@Service
|
||||
public class MVChatListener implements InjectableListener {
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final MVWorldManager worldManager;
|
||||
private final MVPlayerListener playerListener;
|
||||
|
||||
@Inject
|
||||
public MVChatListener(
|
||||
MVCoreConfigProvider configProvider,
|
||||
MVCoreConfig config,
|
||||
MVWorldManager worldManager,
|
||||
MVPlayerListener playerListener
|
||||
) {
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.worldManager = worldManager;
|
||||
this.playerListener = playerListener;
|
||||
}
|
||||
@ -42,7 +42,7 @@ public class MVChatListener implements InjectableListener {
|
||||
}
|
||||
// Check whether the Server is set to prefix the chat with the World name.
|
||||
// If not we do nothing, if so we need to check if the World has an Alias.
|
||||
if (configProvider.getConfig().isEnablePrefixChat()) {
|
||||
if (config.isEnablePrefixChat()) {
|
||||
String world = playerListener.getPlayerWorld().get(event.getPlayer().getName());
|
||||
if (world == null) {
|
||||
world = event.getPlayer().getWorld().getName();
|
||||
@ -60,7 +60,7 @@ public class MVChatListener implements InjectableListener {
|
||||
prefix = mvworld.getColoredWorldString();
|
||||
String chat = event.getFormat();
|
||||
|
||||
String prefixChatFormat = configProvider.getConfig().getPrefixChatFormat();
|
||||
String prefixChatFormat = config.getPrefixChatFormat();
|
||||
prefixChatFormat = prefixChatFormat.replace("%world%", prefix).replace("%chat%", chat);
|
||||
prefixChatFormat = ChatColor.translateAlternateColorCodes('&', prefixChatFormat);
|
||||
|
||||
|
@ -11,7 +11,7 @@ import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.inject.InjectableListener;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.World;
|
||||
@ -33,17 +33,17 @@ import org.jvnet.hk2.annotations.Service;
|
||||
*/
|
||||
@Service
|
||||
public class MVEntityListener implements InjectableListener {
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final MVWorldManager worldManager;
|
||||
private final WorldPurger worldPurger;
|
||||
|
||||
@Inject
|
||||
public MVEntityListener(
|
||||
@NotNull MVCoreConfigProvider configProvider,
|
||||
@NotNull MVCoreConfig config,
|
||||
@NotNull MVWorldManager worldManager,
|
||||
@NotNull WorldPurger worldPurger
|
||||
) {
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.worldManager = worldManager;
|
||||
this.worldPurger = worldPurger;
|
||||
}
|
||||
@ -128,8 +128,8 @@ public class MVEntityListener implements InjectableListener {
|
||||
if (event.isCancelled() || event.getTo() == null) {
|
||||
return;
|
||||
}
|
||||
if (!this.configProvider.getConfig().isUsingCustomPortalSearch()) {
|
||||
event.setSearchRadius(this.configProvider.getConfig().getCustomPortalSearchRadius());
|
||||
if (!config.isUsingCustomPortalSearch()) {
|
||||
event.setSearchRadius(config.getCustomPortalSearchRadius());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
|
||||
import com.onarandombox.MultiverseCore.inject.InjectableListener;
|
||||
import com.onarandombox.MultiverseCore.utils.MVPermissions;
|
||||
@ -45,7 +45,7 @@ import org.jvnet.hk2.annotations.Service;
|
||||
@Service
|
||||
public class MVPlayerListener implements InjectableListener {
|
||||
private final Plugin plugin;
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final Provider<MVWorldManager> worldManagerProvider;
|
||||
private final PermissionTools pt;
|
||||
private final Provider<MVPermissions> mvPermsProvider;
|
||||
@ -57,7 +57,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
@Inject
|
||||
public MVPlayerListener(
|
||||
MultiverseCore plugin,
|
||||
MVCoreConfigProvider configProvider,
|
||||
MVCoreConfig config,
|
||||
Provider<MVWorldManager> worldManagerProvider,
|
||||
PermissionTools permissionTools,
|
||||
Provider<MVPermissions> mvPermsProvider,
|
||||
@ -65,7 +65,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
Server server
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.worldManagerProvider = worldManagerProvider;
|
||||
this.pt = permissionTools;
|
||||
this.mvPermsProvider = mvPermsProvider;
|
||||
@ -142,7 +142,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
Player p = event.getPlayer();
|
||||
if (!p.hasPlayedBefore()) {
|
||||
Logging.finer("Player joined for the FIRST time!");
|
||||
if (configProvider.getConfig().getFirstSpawnOverride()) {
|
||||
if (config.getFirstSpawnOverride()) {
|
||||
Logging.fine("Moving NEW player to(firstspawnoverride): "
|
||||
+ getWorldManager().getFirstSpawnWorld().getSpawnLocation());
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
@ -150,7 +150,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
return;
|
||||
} else {
|
||||
Logging.finer("Player joined AGAIN!");
|
||||
if (this.configProvider.getConfig().getEnforceAccess() // check this only if we're enforcing access!
|
||||
if (config.getEnforceAccess() // check this only if we're enforcing access!
|
||||
&& !this.getMVPerms().hasPermission(p, "multiverse.access." + p.getWorld().getName(), false)) {
|
||||
p.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
@ -222,7 +222,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
}
|
||||
|
||||
// Check if player is allowed to enter the world if we're enforcing permissions
|
||||
if (configProvider.getConfig().getEnforceAccess()) {
|
||||
if (config.getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
Logging.fine("Player '" + teleportee.getName()
|
||||
@ -314,7 +314,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
+ "' because they don't have the FUNDS required to enter.");
|
||||
return;
|
||||
}
|
||||
if (configProvider.getConfig().getEnforceAccess()) {
|
||||
if (config.getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, event.getPlayer(), event.getPlayer()));
|
||||
if (event.isCancelled()) {
|
||||
Logging.fine("Player '" + event.getPlayer().getName()
|
||||
@ -326,8 +326,8 @@ public class MVPlayerListener implements InjectableListener {
|
||||
+ "' was allowed to go to '" + event.getTo().getWorld().getName()
|
||||
+ "' because enforceaccess is off.");
|
||||
}
|
||||
if (!this.configProvider.getConfig().isUsingCustomPortalSearch()) {
|
||||
event.setSearchRadius(this.configProvider.getConfig().getCustomPortalSearchRadius());
|
||||
if (!config.isUsingCustomPortalSearch()) {
|
||||
event.setSearchRadius(config.getCustomPortalSearchRadius());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.MVDestination;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -31,17 +31,17 @@ import org.jvnet.hk2.annotations.Service;
|
||||
public class MVPermissions {
|
||||
|
||||
private final PluginManager pluginManager;
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final MVWorldManager worldMgr;
|
||||
|
||||
@Inject
|
||||
public MVPermissions(
|
||||
PluginManager pluginManager,
|
||||
MVCoreConfigProvider configProvider,
|
||||
MVCoreConfig config,
|
||||
MVWorldManager worldManager
|
||||
) {
|
||||
this.pluginManager = pluginManager;
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.worldMgr = worldManager;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ public class MVPermissions {
|
||||
*/
|
||||
public boolean canEnterWorld(Player p, MVWorld w) {
|
||||
// If we're not enforcing access, anyone can enter.
|
||||
if (!configProvider.getConfig().getEnforceAccess()) {
|
||||
if (!config.getEnforceAccess()) {
|
||||
Logging.finest("EnforceAccess is OFF. Player was allowed in " + w.getAlias());
|
||||
return true;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.economy.MVEconomist;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Provider;
|
||||
@ -27,19 +27,19 @@ import org.jvnet.hk2.annotations.Service;
|
||||
@Service
|
||||
public class PermissionTools {
|
||||
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final PluginManager pluginManager;
|
||||
private final Provider<MVPermissions> mvPermsProvider;
|
||||
private final MVEconomist economist;
|
||||
|
||||
@Inject
|
||||
public PermissionTools(
|
||||
MVCoreConfigProvider configProvider,
|
||||
MVCoreConfig config,
|
||||
PluginManager pluginManager,
|
||||
Provider<MVPermissions> mvPermsProvider,
|
||||
MVEconomist economist)
|
||||
{
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.pluginManager = pluginManager;
|
||||
this.mvPermsProvider = mvPermsProvider;
|
||||
this.economist = economist;
|
||||
@ -123,7 +123,7 @@ public class PermissionTools {
|
||||
*/
|
||||
public boolean playerHasMoneyToEnter(MVWorld fromWorld, MVWorld toWorld, CommandSender teleporter, Player teleportee, boolean pay) {
|
||||
Player teleporterPlayer;
|
||||
if (configProvider.getConfig().getTeleportIntercept()) {
|
||||
if (config.getTeleportIntercept()) {
|
||||
if (teleporter instanceof ConsoleCommandSender) {
|
||||
return true;
|
||||
}
|
||||
@ -219,7 +219,7 @@ public class PermissionTools {
|
||||
Logging.finest("Checking '" + teleporter + "' can send '" + teleportee + "' somewhere");
|
||||
|
||||
Player teleporterPlayer;
|
||||
if (configProvider.getConfig().getTeleportIntercept()) {
|
||||
if (config.getTeleportIntercept()) {
|
||||
// The console can send anyone anywhere
|
||||
if (teleporter instanceof ConsoleCommandSender) {
|
||||
return true;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.onarandombox.MultiverseCore.utils;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
@ -12,11 +12,11 @@ import java.util.concurrent.Callable;
|
||||
*/
|
||||
@Service
|
||||
public class UnsafeCallWrapper {
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
|
||||
@Inject
|
||||
public UnsafeCallWrapper(MVCoreConfigProvider configProvider) {
|
||||
this.configProvider = configProvider;
|
||||
public UnsafeCallWrapper(MVCoreConfig configProvider) {
|
||||
this.config = configProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +40,7 @@ public class UnsafeCallWrapper {
|
||||
actualFormatArgs[formatArgs.length] = t;
|
||||
Logging.warning(action, actualFormatArgs);
|
||||
Logging.warning("This is a bug in %s, NOT a bug in Multiverse!", plugin);
|
||||
if (configProvider.getConfig().getGlobalDebug() >= 1)
|
||||
if (config.getGlobalDebug() >= 1)
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType;
|
||||
@ -55,7 +55,7 @@ public class SimpleMVWorld implements MVWorld {
|
||||
private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16;
|
||||
|
||||
private final MVWorldManager worldManager;
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final WorldPurger worldPurger;
|
||||
private final MVPlayerListener playerListener;
|
||||
private final BlockSafety blockSafety;
|
||||
@ -68,7 +68,7 @@ public class SimpleMVWorld implements MVWorld {
|
||||
|
||||
public SimpleMVWorld(
|
||||
MVWorldManager worldManager,
|
||||
MVCoreConfigProvider configProvider,
|
||||
MVCoreConfig config,
|
||||
WorldPurger worldPurger,
|
||||
MVPlayerListener playerListener,
|
||||
BlockSafety blockSafety,
|
||||
@ -78,7 +78,7 @@ public class SimpleMVWorld implements MVWorld {
|
||||
World world,
|
||||
WorldProperties properties
|
||||
) {
|
||||
this(worldManager, configProvider, worldPurger, playerListener, blockSafety, safeTTeleporter,
|
||||
this(worldManager, config, worldPurger, playerListener, blockSafety, safeTTeleporter,
|
||||
locationManipulation, server, world, properties, true);
|
||||
}
|
||||
|
||||
@ -87,7 +87,7 @@ public class SimpleMVWorld implements MVWorld {
|
||||
*/
|
||||
public SimpleMVWorld(
|
||||
MVWorldManager worldManager,
|
||||
MVCoreConfigProvider configProvider,
|
||||
MVCoreConfig config,
|
||||
WorldPurger worldPurger,
|
||||
MVPlayerListener playerListener,
|
||||
BlockSafety blockSafety,
|
||||
@ -99,7 +99,7 @@ public class SimpleMVWorld implements MVWorld {
|
||||
boolean fixSpawn
|
||||
) {
|
||||
this.worldManager = worldManager;
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.worldPurger = worldPurger;
|
||||
this.playerListener = playerListener;
|
||||
this.blockSafety = blockSafety;
|
||||
@ -325,7 +325,7 @@ public class SimpleMVWorld implements MVWorld {
|
||||
}
|
||||
world.setSpawnFlags(allowMonsters, allowAnimals);
|
||||
}
|
||||
if (configProvider.getConfig().isAutoPurgeEntities()) {
|
||||
if (config.isAutoPurgeEntities()) {
|
||||
worldPurger.purgeWorld(SimpleMVWorld.this);
|
||||
}
|
||||
return super.validateChange(property, newValue, oldValue, object);
|
||||
|
@ -32,7 +32,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVPlayerListener;
|
||||
import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper;
|
||||
@ -61,8 +61,10 @@ import org.jvnet.hk2.annotations.Service;
|
||||
*/
|
||||
@Service
|
||||
public class SimpleMVWorldManager implements MVWorldManager {
|
||||
public static final String WORLD_CONFIG_FILE = "worlds.yml";
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
private final MVCoreConfigProvider configProvider;
|
||||
private final MVCoreConfig config;
|
||||
private final MVPlayerListener playerListener;
|
||||
private final BlockSafety blockSafety;
|
||||
private final SafeTTeleporter safeTTeleporter;
|
||||
@ -79,7 +81,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
@Inject
|
||||
public SimpleMVWorldManager(
|
||||
MultiverseCore plugin,
|
||||
MVCoreConfigProvider configProvider,
|
||||
MVCoreConfig config,
|
||||
MVPlayerListener playerListener,
|
||||
BlockSafety blockSafety,
|
||||
SafeTTeleporter safeTTeleporter,
|
||||
@ -89,7 +91,7 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
Server server
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.configProvider = configProvider;
|
||||
this.config = config;
|
||||
this.playerListener = playerListener;
|
||||
this.blockSafety = blockSafety;
|
||||
this.safeTTeleporter = safeTTeleporter;
|
||||
@ -515,9 +517,9 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
nullWorld(worldName);
|
||||
return false;
|
||||
}
|
||||
SimpleMVWorld world = new SimpleMVWorld(this, configProvider, worldPurger, playerListener, blockSafety,
|
||||
SimpleMVWorld world = new SimpleMVWorld(this, config, worldPurger, playerListener, blockSafety,
|
||||
safeTTeleporter, locationManipulation, server, cbworld, mvworld);
|
||||
if (configProvider.getConfig().isAutoPurgeEntities()) {
|
||||
if (config.isAutoPurgeEntities()) {
|
||||
this.worldPurger.purgeWorld(world);
|
||||
}
|
||||
this.worlds.put(worldName, world);
|
||||
@ -817,11 +819,12 @@ public class SimpleMVWorldManager implements MVWorldManager {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public FileConfiguration loadWorldConfig(File file) {
|
||||
public FileConfiguration loadWorldsConfig() {
|
||||
File file = new File(this.plugin.getDataFolder(), WORLD_CONFIG_FILE);
|
||||
this.configWorlds = YamlConfiguration.loadConfiguration(file);
|
||||
this.ensureConfigIsPrepared();
|
||||
try {
|
||||
this.configWorlds.save(new File(this.plugin.getDataFolder(), "worlds.yml"));
|
||||
this.configWorlds.save(file);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -9,7 +9,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfigProvider
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig
|
||||
import com.onarandombox.MultiverseCore.economy.MVEconomist
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener
|
||||
@ -112,8 +112,8 @@ class InjectionTest : TestWithMockBukkit() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MVCoreConfigProvider is available as a service`() {
|
||||
assertNotNull(multiverseCore.getService(MVCoreConfigProvider::class.java))
|
||||
fun `MVCoreConfig is available as a service`() {
|
||||
assertNotNull(multiverseCore.getService(MVCoreConfig::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -130,13 +130,6 @@ class InjectionTest : TestWithMockBukkit() {
|
||||
assertEquals(6, destinations.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MVConfig is not available as a service`() {
|
||||
// We need one test case for asking for non-services to make sure we don't accidentally make them available
|
||||
// and that the getService method doesn't throw an exception
|
||||
assertNull(multiverseCore.getService(MVConfig::class.java))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MetricsConfigurator is not available as a service`() {
|
||||
// Also making sure this is not loaded automatically since it's supposed to be disabled during tests
|
||||
|
Loading…
Reference in New Issue
Block a user