mirror of
https://github.com/tomasff/BeesPlus.git
synced 2024-11-22 18:16:20 +01:00
Split the enable method into other functions
This commit is contained in:
parent
b85876c8b3
commit
1f079051fa
@ -31,51 +31,19 @@ public class BeesPlus extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
|
||||||
String locale = getConfig().getString("locale", Locale.ENGLISH.toLanguageTag());
|
|
||||||
|
|
||||||
localizationWrapper = new LocalizationWrapper(this, "locale");
|
|
||||||
|
|
||||||
try {
|
|
||||||
YamlConfiguration localeYamlFile = localizationWrapper.getLocale(locale);
|
|
||||||
Localization.load(localeYamlFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
getLogger().severe("Invalid locale! Please choose a valid locale.");
|
|
||||||
disablePlugin();
|
|
||||||
|
|
||||||
return;
|
|
||||||
} catch (InvalidConfigurationException e) {
|
|
||||||
getLogger().severe(e.getMessage());
|
|
||||||
getLogger().severe("Locale file corrupted or malformed! Please check your locale file.");
|
|
||||||
disablePlugin();
|
|
||||||
|
|
||||||
return;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
getLogger().severe(e.getMessage());
|
|
||||||
getLogger().severe("Error in the locale file! Please check your locale file.");
|
|
||||||
getLogger().severe("Maybe caused by a typo");
|
|
||||||
disablePlugin();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
guiManager = new GuiManager();
|
guiManager = new GuiManager();
|
||||||
|
customItemManager = new CustomItemManager(this);
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new GuiHandler(this), this);
|
getServer().getPluginManager().registerEvents(new GuiHandler(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new RightClickHandler(this), this);
|
getServer().getPluginManager().registerEvents(new RightClickHandler(this), this);
|
||||||
|
|
||||||
boolean isProtectionSuitEnabled = getConfig().getBoolean("beeprotectionsuit.enabled", true);
|
if (!loadLocale()) {
|
||||||
|
getServer().getPluginManager().disablePlugin(this);
|
||||||
if (isProtectionSuitEnabled) {
|
return;
|
||||||
customItemManager = new CustomItemManager(this);
|
|
||||||
|
|
||||||
customItemManager.registerCustomItem("protection_boots", new BeeProtectionBoots());
|
|
||||||
customItemManager.registerCustomItem("protection_leggings", new BeeProtectionLeggings());
|
|
||||||
customItemManager.registerCustomItem("protection_chestplate", new BeeProtectionChestplate());
|
|
||||||
customItemManager.registerCustomItem("protection_helmet", new BeeProtectionHelmet());
|
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new DamageHandler(this), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerItems();
|
||||||
|
|
||||||
Metrics metrics = new Metrics(this, 7065);
|
Metrics metrics = new Metrics(this, 7065);
|
||||||
|
|
||||||
new UpdateChecker(this, 77224).getVersion(version -> {
|
new UpdateChecker(this, 77224).getVersion(version -> {
|
||||||
@ -85,8 +53,38 @@ public class BeesPlus extends JavaPlugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disablePlugin() {
|
private boolean loadLocale() {
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
String locale = getConfig().getString("locale", Locale.ENGLISH.toLanguageTag());
|
||||||
|
localizationWrapper = new LocalizationWrapper(this, "locale");
|
||||||
|
|
||||||
|
try {
|
||||||
|
YamlConfiguration localeYamlFile = localizationWrapper.getLocale(locale);
|
||||||
|
Localization.load(localeYamlFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
getLogger().severe("Invalid locale! Please choose a valid locale.");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} catch (InvalidConfigurationException | IllegalArgumentException e) {
|
||||||
|
getLogger().severe(e.getMessage());
|
||||||
|
|
||||||
|
getLogger().severe("Locale file corrupted or malformed! Please check your locale file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerItems() {
|
||||||
|
boolean isProtectionSuitEnabled = getConfig().getBoolean("beeprotectionsuit.enabled", true);
|
||||||
|
|
||||||
|
if(isProtectionSuitEnabled) {
|
||||||
|
customItemManager.registerCustomItem("protection_boots", new BeeProtectionBoots());
|
||||||
|
customItemManager.registerCustomItem("protection_leggings", new BeeProtectionLeggings());
|
||||||
|
customItemManager.registerCustomItem("protection_chestplate", new BeeProtectionChestplate());
|
||||||
|
customItemManager.registerCustomItem("protection_helmet", new BeeProtectionHelmet());
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new DamageHandler(this), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiManager getGuiManager() {
|
public GuiManager getGuiManager() {
|
||||||
|
Loading…
Reference in New Issue
Block a user