mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-24 18:17:53 +01:00
Added ability to reload BentoBox's configuration using /bbox reload
#370
This commit is contained in:
parent
ca2bb18a56
commit
281d16c175
@ -101,14 +101,13 @@ public class BentoBox extends JavaPlugin {
|
||||
// Load Flags
|
||||
flagsManager = new FlagsManager(this);
|
||||
|
||||
// Load settings from config.yml. This will check if there are any issues with it too.
|
||||
settings = new Config<>(this, Settings.class).loadConfigObject("");
|
||||
if (settings == null) {
|
||||
// Settings did no load correctly. Disable plugin.
|
||||
logError("Settings did not load correctly - disabling plugin - please check config.yml");
|
||||
getPluginLoader().disablePlugin(this);
|
||||
if (!loadSettings()) {
|
||||
// We're aborting the load.
|
||||
return;
|
||||
}
|
||||
// Saving the config now.
|
||||
new Config<>(this, Settings.class).saveConfigObject(settings);
|
||||
|
||||
// Start Database managers
|
||||
playersManager = new PlayersManager(this);
|
||||
// Check if this plugin is now disabled (due to bad database handling)
|
||||
@ -223,10 +222,6 @@ public class BentoBox extends JavaPlugin {
|
||||
if (islandsManager != null) {
|
||||
islandsManager.shutdown();
|
||||
}
|
||||
// Save settings - ensures admins always have the latest config file
|
||||
if (settings != null) {
|
||||
new Config<>(this, Settings.class).saveConfigObject(settings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,6 +297,25 @@ public class BentoBox extends JavaPlugin {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the settings from the config file.
|
||||
* If it fails, it can shut the plugin down.
|
||||
* @return {@code true} if it loaded successfully.
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public boolean loadSettings() {
|
||||
log("Loading Settings from config.yml...");
|
||||
// Load settings from config.yml. This will check if there are any issues with it too.
|
||||
settings = new Config<>(this, Settings.class).loadConfigObject();
|
||||
if (settings == null) {
|
||||
// Settings did not load correctly. Disable plugin.
|
||||
logError("Settings did not load correctly - disabling plugin - please check config.yml");
|
||||
getPluginLoader().disablePlugin(this);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the notifier
|
||||
*/
|
||||
@ -387,6 +401,8 @@ public class BentoBox extends JavaPlugin {
|
||||
return Optional.ofNullable(metrics);
|
||||
}
|
||||
|
||||
// Overriding default JavaPlugin methods
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#getDefaultWorldGenerator(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@ -394,4 +410,12 @@ public class BentoBox extends JavaPlugin {
|
||||
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||
return addonsManager.getDefaultWorldGenerator(worldName, id);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#reloadConfig()
|
||||
*/
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
loadSettings();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||
@ -55,6 +56,7 @@ public class Config<T> {
|
||||
* @param uniqueId - unique id of the object
|
||||
* @return the object or null if it cannot be loaded
|
||||
*/
|
||||
@Nullable
|
||||
public T loadConfigObject(String uniqueId) {
|
||||
try {
|
||||
return handler.loadObject(uniqueId);
|
||||
@ -71,6 +73,7 @@ public class Config<T> {
|
||||
* Loads a config object
|
||||
* @return the object or null if it cannot be loaded
|
||||
*/
|
||||
@Nullable
|
||||
public T loadConfigObject() {
|
||||
return loadConfigObject("");
|
||||
}
|
||||
|
@ -7,15 +7,15 @@ import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* Reloads addons and localization.
|
||||
* Reloads settings, addons and localization.
|
||||
*
|
||||
* @author tastybento
|
||||
*/
|
||||
public class BentoBoxReloadCommand extends ConfirmableCommand {
|
||||
|
||||
/**
|
||||
* Reloads locales command
|
||||
* @param parent - command parent
|
||||
* Reloads settings, addons and localization command
|
||||
* @param parent command parent
|
||||
*/
|
||||
public BentoBoxReloadCommand(CompositeCommand parent) {
|
||||
super(parent, "reload");
|
||||
@ -30,6 +30,10 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
this.askConfirmation(user, () -> {
|
||||
// Reload settings
|
||||
getPlugin().loadSettings();
|
||||
user.sendMessage("commands.bentobox.reload.settings-reloaded");
|
||||
|
||||
// Reload addons
|
||||
getPlugin().getAddonsManager().reloadAddons();
|
||||
user.sendMessage("commands.bentobox.reload.addons-reloaded");
|
||||
@ -38,6 +42,6 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
|
||||
getPlugin().getLocalesManager().reloadLanguages();
|
||||
user.sendMessage("commands.bentobox.reload.locales-reloaded");
|
||||
});
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -222,9 +222,10 @@ commands:
|
||||
about:
|
||||
description: "display copyright and license info"
|
||||
reload:
|
||||
description: "reloads addons (if supported) and locale files"
|
||||
description: "reloads settings, addons (if supported) and locales"
|
||||
locales-reloaded: "&2Languages reloaded."
|
||||
addons-reloaded: "&2Addons reloaded."
|
||||
settings-reloaded: "&2Settings reloaded."
|
||||
version:
|
||||
plugin-version: "&2BentoBox version: &3[version]"
|
||||
description: "display info"
|
||||
|
Loading…
Reference in New Issue
Block a user