mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-26 19:17:40 +01:00
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:
parent
49fa079f13
commit
935704d7dd
@ -1,5 +1,7 @@
|
|||||||
package world.bentobox.bentobox;
|
package world.bentobox.bentobox;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.plugin.PluginManager;
|
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.managers.SchemsManager;
|
||||||
import world.bentobox.bentobox.util.heads.HeadGetter;
|
import world.bentobox.bentobox.util.heads.HeadGetter;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main BentoBox class
|
* Main BentoBox class
|
||||||
* @author tastybento, Poslovitch
|
* @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.
|
// Load settings from config.yml. This will check if there are any issues with it too.
|
||||||
settings = new Config<>(this, Settings.class).loadConfigObject("");
|
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
|
// Start Database managers
|
||||||
playersManager = new PlayersManager(this);
|
playersManager = new PlayersManager(this);
|
||||||
// Check if this plugin is now disabled (due to bad database handling)
|
// Check if this plugin is now disabled (due to bad database handling)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package world.bentobox.bentobox.database;
|
package world.bentobox.bentobox.database;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.database.yaml.YamlDatabase;
|
|
||||||
import world.bentobox.bentobox.database.json.JSONDatabase;
|
import world.bentobox.bentobox.database.json.JSONDatabase;
|
||||||
import world.bentobox.bentobox.database.mongodb.MongoDBDatabase;
|
import world.bentobox.bentobox.database.mongodb.MongoDBDatabase;
|
||||||
import world.bentobox.bentobox.database.mysql.MySQLDatabase;
|
import world.bentobox.bentobox.database.mysql.MySQLDatabase;
|
||||||
|
import world.bentobox.bentobox.database.yaml.YamlDatabase;
|
||||||
|
|
||||||
public interface DatabaseSetup {
|
public interface DatabaseSetup {
|
||||||
|
|
||||||
@ -15,8 +15,9 @@ public interface DatabaseSetup {
|
|||||||
* @return Database type
|
* @return Database type
|
||||||
*/
|
*/
|
||||||
static DatabaseSetup getDatabase() {
|
static DatabaseSetup getDatabase() {
|
||||||
|
BentoBox plugin = BentoBox.getInstance();
|
||||||
for(DatabaseType type : DatabaseType.values()){
|
for(DatabaseType type : DatabaseType.values()){
|
||||||
if(type == BentoBox.getInstance().getSettings().getDatabaseType()) {
|
if(type == plugin.getSettings().getDatabaseType()) {
|
||||||
return type.database;
|
return type.database;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user