Added safety checking to config.yml

If there is an enum setting, e.g. FLATFILE instead of YAML in a config,
the config will not load and the resulting object will be null. This
adds a check to the main config.yml load and disables the plugin if
there is a problem.
This commit is contained in:
tastybento 2018-10-30 15:16:13 -07:00
parent 49fa079f13
commit 935704d7dd
3 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,7 @@
package world.bentobox.bentobox;
import java.util.Optional;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.plugin.PluginManager;
@ -30,8 +32,6 @@ import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.SchemsManager;
import world.bentobox.bentobox.util.heads.HeadGetter;
import java.util.Optional;
/**
* Main BentoBox class
* @author tastybento, Poslovitch
@ -78,6 +78,12 @@ public class BentoBox extends JavaPlugin {
// 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);
return;
}
// Start Database managers
playersManager = new PlayersManager(this);
// Check if this plugin is now disabled (due to bad database handling)

View File

@ -1,10 +1,10 @@
package world.bentobox.bentobox.database;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.yaml.YamlDatabase;
import world.bentobox.bentobox.database.json.JSONDatabase;
import world.bentobox.bentobox.database.mongodb.MongoDBDatabase;
import world.bentobox.bentobox.database.mysql.MySQLDatabase;
import world.bentobox.bentobox.database.yaml.YamlDatabase;
public interface DatabaseSetup {
@ -15,8 +15,9 @@ public interface DatabaseSetup {
* @return Database type
*/
static DatabaseSetup getDatabase() {
BentoBox plugin = BentoBox.getInstance();
for(DatabaseType type : DatabaseType.values()){
if(type == BentoBox.getInstance().getSettings().getDatabaseType()) {
if(type == plugin.getSettings().getDatabaseType()) {
return type.database;
}
}