mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-12-10 15:03:30 +01:00
Refactor main plugin class
This commit is contained in:
parent
014cc02609
commit
2e2801f3a7
@ -64,7 +64,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPluginExtended
|
|||||||
@Getter private static Minepacks instance = null;
|
@Getter private static Minepacks instance = null;
|
||||||
|
|
||||||
private ManagedUpdater updater = null;
|
private ManagedUpdater updater = null;
|
||||||
private Config config;
|
@Getter private Config configuration;
|
||||||
@Getter private BackpacksConfig backpacksConfig;
|
@Getter private BackpacksConfig backpacksConfig;
|
||||||
@Getter private Language language;
|
@Getter private Language language;
|
||||||
@Getter private Database database;
|
@Getter private Database database;
|
||||||
@ -102,9 +102,9 @@ public void onEnable()
|
|||||||
|
|
||||||
updater = new ManagedUpdater(this);
|
updater = new ManagedUpdater(this);
|
||||||
instance = this;
|
instance = this;
|
||||||
config = new Config(this);
|
configuration = new Config(this);
|
||||||
updater.setChannel(config.getUpdateChannel());
|
updater.setChannel(configuration.getUpdateChannel());
|
||||||
if(config.useUpdater()) updater.update();
|
if(configuration.useUpdater()) updater.update();
|
||||||
|
|
||||||
if(!checkMcVersion()) return;
|
if(!checkMcVersion()) return;
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ private boolean checkMcVersion()
|
|||||||
{
|
{
|
||||||
getLogger().warning(ConsoleColor.RED + "################################" + ConsoleColor.RESET);
|
getLogger().warning(ConsoleColor.RED + "################################" + ConsoleColor.RESET);
|
||||||
getLogger().warning(ConsoleColor.RED + String.format("Your server version (%1$s) is currently not compatible with your current version (%2$s) of the plugin. " +
|
getLogger().warning(ConsoleColor.RED + String.format("Your server version (%1$s) is currently not compatible with your current version (%2$s) of the plugin. " +
|
||||||
"Please check for updates!" + ConsoleColor.RESET, Bukkit.getVersion(), getDescription().getVersion()));
|
"Please check for updates!", Bukkit.getVersion(), getDescription().getVersion()) + ConsoleColor.RESET);
|
||||||
getLogger().warning(ConsoleColor.RED + "################################" + ConsoleColor.RESET);
|
getLogger().warning(ConsoleColor.RED + "################################" + ConsoleColor.RESET);
|
||||||
Utils.blockThread(5);
|
Utils.blockThread(5);
|
||||||
this.setEnabled(false);
|
this.setEnabled(false);
|
||||||
@ -167,8 +167,8 @@ private void checkOldDataFolder()
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
if(config == null) return;
|
if(configuration == null) return;
|
||||||
if(config.useUpdater()) updater.update();
|
if(configuration.useUpdater()) updater.update();
|
||||||
unload();
|
unload();
|
||||||
updater.waitForAsyncOperation(); // Wait for an update to finish
|
updater.waitForAsyncOperation(); // Wait for an update to finish
|
||||||
getLogger().info(StringUtils.getPluginDisabledMessage(getDescription().getName()));
|
getLogger().info(StringUtils.getPluginDisabledMessage(getDescription().getName()));
|
||||||
@ -182,8 +182,8 @@ public void update(final @Nullable UpdateResponseCallback updateResponseCallback
|
|||||||
|
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
updater.setChannel(config.getUpdateChannel());
|
updater.setChannel(configuration.getUpdateChannel());
|
||||||
language.load(config);
|
language.load(configuration);
|
||||||
backpacksConfig.loadData();
|
backpacksConfig.loadData();
|
||||||
database = new Database(this);
|
database = new Database(this);
|
||||||
if(!database.available())
|
if(!database.available())
|
||||||
@ -191,9 +191,9 @@ private void load()
|
|||||||
new NoDatabaseWorker(this);
|
new NoDatabaseWorker(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
maxSize = config.getBackpackMaxSize();
|
maxSize = configuration.getBackpackMaxSize();
|
||||||
at.pcgamingfreaks.Minepacks.Bukkit.Backpack.setShrinkApproach(config.getShrinkApproach());
|
at.pcgamingfreaks.Minepacks.Bukkit.Backpack.setShrinkApproach(configuration.getShrinkApproach());
|
||||||
at.pcgamingfreaks.Minepacks.Bukkit.Backpack.setTitle(config.getBPTitle(), config.getBPTitleOther());
|
at.pcgamingfreaks.Minepacks.Bukkit.Backpack.setTitle(configuration.getBPTitle(), configuration.getBPTitleOther());
|
||||||
messageNotFromConsole = language.getMessage("NotFromConsole");
|
messageNotFromConsole = language.getMessage("NotFromConsole");
|
||||||
messageNoPermission = language.getMessage("Ingame.NoPermission");
|
messageNoPermission = language.getMessage("Ingame.NoPermission");
|
||||||
messageInvalidBackpack = language.getMessage("Ingame.InvalidBackpack");
|
messageInvalidBackpack = language.getMessage("Ingame.InvalidBackpack");
|
||||||
@ -201,19 +201,19 @@ private void load()
|
|||||||
messageNotANumber = language.getMessage("Ingame.NaN");
|
messageNotANumber = language.getMessage("Ingame.NaN");
|
||||||
|
|
||||||
commandManager = new CommandManager(this);
|
commandManager = new CommandManager(this);
|
||||||
if(config.isInventoryManagementClearCommandEnabled()) inventoryClearCommand = new InventoryClearCommand(this);
|
if(configuration.isInventoryManagementClearCommandEnabled()) inventoryClearCommand = new InventoryClearCommand(this);
|
||||||
|
|
||||||
//region register events
|
//region register events
|
||||||
PluginManager pluginManager = getServer().getPluginManager();
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
pluginManager.registerEvents(new BackpackEventListener(this), this);
|
pluginManager.registerEvents(new BackpackEventListener(this), this);
|
||||||
if(config.getDropOnDeath()) pluginManager.registerEvents(new DropOnDeath(this), this);
|
if(configuration.getDropOnDeath()) pluginManager.registerEvents(new DropOnDeath(this), this);
|
||||||
if(config.isItemFilterEnabled())
|
if(configuration.isItemFilterEnabled())
|
||||||
{
|
{
|
||||||
itemFilter = new ItemFilter(this);
|
itemFilter = new ItemFilter(this);
|
||||||
pluginManager.registerEvents(itemFilter, this);
|
pluginManager.registerEvents(itemFilter, this);
|
||||||
}
|
}
|
||||||
if(config.isShulkerboxesDisable()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
|
if(configuration.isShulkerboxesDisable()) pluginManager.registerEvents(new DisableShulkerboxes(this), this);
|
||||||
if(config.isItemShortcutEnabled() && backpacksConfig.isAllowItemShortcut())
|
if(configuration.isItemShortcutEnabled() && backpacksConfig.isAllowItemShortcut())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -228,16 +228,16 @@ private void load()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else shortcut = null;
|
else shortcut = null;
|
||||||
if(config.isWorldWhitelistMode()) pluginManager.registerEvents(new WorldBlacklistUpdater(this), this);
|
if(configuration.isWorldWhitelistMode()) pluginManager.registerEvents(new WorldBlacklistUpdater(this), this);
|
||||||
//endregion
|
//endregion
|
||||||
if(config.getFullInvCollect()) collector = new ItemsCollector(this);
|
if(configuration.getFullInvCollect()) collector = new ItemsCollector(this);
|
||||||
worldBlacklist = config.getWorldBlacklist();
|
worldBlacklist = configuration.getWorldBlacklist();
|
||||||
worldBlacklistMode = (worldBlacklist.size() == 0) ? WorldBlacklistMode.None : config.getWorldBlockMode();
|
worldBlacklistMode = (worldBlacklist.size() == 0) ? WorldBlacklistMode.None : configuration.getWorldBlockMode();
|
||||||
|
|
||||||
gameModes = config.getAllowedGameModes();
|
gameModes = configuration.getAllowedGameModes();
|
||||||
if(config.getCommandCooldown() > 0) cooldownManager = new CooldownManager(this);
|
if(configuration.getCommandCooldown() > 0) cooldownManager = new CooldownManager(this);
|
||||||
|
|
||||||
openSound = config.getOpenSound();
|
openSound = configuration.getOpenSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unload()
|
private void unload()
|
||||||
@ -261,16 +261,11 @@ private void unload()
|
|||||||
public void reload()
|
public void reload()
|
||||||
{
|
{
|
||||||
unload();
|
unload();
|
||||||
config.reload();
|
configuration.reload();
|
||||||
backpacksConfig.reload();
|
backpacksConfig.reload();
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config getConfiguration()
|
|
||||||
{
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openBackpack(@NotNull final Player opener, @NotNull final OfflinePlayer owner, final boolean editable)
|
public void openBackpack(@NotNull final Player opener, @NotNull final OfflinePlayer owner, final boolean editable)
|
||||||
{
|
{
|
||||||
@ -286,17 +281,7 @@ public void openBackpack(@NotNull final Player opener, @Nullable final Backpack
|
|||||||
@Override
|
@Override
|
||||||
public void openBackpack(final @NotNull Player opener, final @NotNull OfflinePlayer owner, final boolean editable, final @Nullable String title)
|
public void openBackpack(final @NotNull Player opener, final @NotNull OfflinePlayer owner, final boolean editable, final @Nullable String title)
|
||||||
{
|
{
|
||||||
database.getBackpack(owner, new Callback<Backpack>()
|
database.getBackpack(owner, backpack -> openBackpack(opener, backpack, editable, title));
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void onResult(Backpack backpack)
|
|
||||||
{
|
|
||||||
openBackpack(opener, backpack, editable, title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFail() {}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user