2018-11-06 04:33:10 +01:00
|
|
|
package com.songoda.ultimatestacker;
|
|
|
|
|
|
|
|
import com.songoda.ultimatestacker.command.CommandManager;
|
|
|
|
import com.songoda.ultimatestacker.entity.EntityStack;
|
2018-11-06 06:09:40 +01:00
|
|
|
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
2019-01-23 19:01:31 +01:00
|
|
|
import com.songoda.ultimatestacker.hologram.Hologram;
|
|
|
|
import com.songoda.ultimatestacker.hologram.HologramHolographicDisplays;
|
2019-06-10 02:47:29 +02:00
|
|
|
import com.songoda.ultimatestacker.hook.StackerHook;
|
|
|
|
import com.songoda.ultimatestacker.hook.hooks.JobsHook;
|
2019-06-07 19:48:17 +02:00
|
|
|
import com.songoda.ultimatestacker.listeners.*;
|
2019-07-23 16:55:49 +02:00
|
|
|
import com.songoda.ultimatestacker.lootables.LootablesManager;
|
2018-11-06 04:33:10 +01:00
|
|
|
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
|
|
|
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
|
|
|
|
import com.songoda.ultimatestacker.storage.Storage;
|
|
|
|
import com.songoda.ultimatestacker.storage.StorageRow;
|
|
|
|
import com.songoda.ultimatestacker.storage.types.StorageMysql;
|
|
|
|
import com.songoda.ultimatestacker.storage.types.StorageYaml;
|
|
|
|
import com.songoda.ultimatestacker.tasks.StackingTask;
|
2019-06-07 19:48:17 +02:00
|
|
|
import com.songoda.ultimatestacker.utils.ConfigWrapper;
|
|
|
|
import com.songoda.ultimatestacker.utils.Methods;
|
|
|
|
import com.songoda.ultimatestacker.utils.Metrics;
|
|
|
|
import com.songoda.ultimatestacker.utils.ServerVersion;
|
2019-07-19 04:19:33 +02:00
|
|
|
import com.songoda.ultimatestacker.utils.locale.Locale;
|
2019-06-07 19:48:17 +02:00
|
|
|
import com.songoda.ultimatestacker.utils.settings.Setting;
|
2019-05-23 22:15:04 +02:00
|
|
|
import com.songoda.ultimatestacker.utils.settings.SettingsManager;
|
2019-04-26 10:06:18 +02:00
|
|
|
import com.songoda.ultimatestacker.utils.updateModules.LocaleModule;
|
|
|
|
import com.songoda.update.Plugin;
|
|
|
|
import com.songoda.update.SongodaUpdate;
|
2019-06-07 19:48:17 +02:00
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2018-11-06 04:33:10 +01:00
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
|
|
import org.bukkit.entity.EntityType;
|
2019-06-10 02:47:29 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2019-01-23 19:01:31 +01:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
2018-11-06 04:33:10 +01:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
2019-04-28 01:20:33 +02:00
|
|
|
|
2019-06-10 02:47:29 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2018-11-06 04:33:10 +01:00
|
|
|
|
|
|
|
public class UltimateStacker extends JavaPlugin {
|
|
|
|
|
|
|
|
private static UltimateStacker INSTANCE;
|
|
|
|
|
|
|
|
private ConfigWrapper mobFile = new ConfigWrapper(this, "", "mobs.yml");
|
|
|
|
private ConfigWrapper itemFile = new ConfigWrapper(this, "", "items.yml");
|
|
|
|
private ConfigWrapper spawnerFile = new ConfigWrapper(this, "", "spawners.yml");
|
|
|
|
|
|
|
|
private Locale locale;
|
|
|
|
private SettingsManager settingsManager;
|
|
|
|
private EntityStackManager entityStackManager;
|
|
|
|
private SpawnerStackManager spawnerStackManager;
|
2019-07-23 16:55:49 +02:00
|
|
|
private LootablesManager lootablesManager;
|
2018-11-06 04:33:10 +01:00
|
|
|
private CommandManager commandManager;
|
|
|
|
private StackingTask stackingTask;
|
2019-01-23 19:01:31 +01:00
|
|
|
private Hologram hologram;
|
2018-11-06 05:41:58 +01:00
|
|
|
|
2019-06-10 02:47:29 +02:00
|
|
|
private List<StackerHook> stackerHooks = new ArrayList<>();
|
|
|
|
|
2018-11-06 05:41:58 +01:00
|
|
|
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
2018-11-06 04:33:10 +01:00
|
|
|
private Storage storage;
|
|
|
|
|
2018-11-06 06:09:40 +01:00
|
|
|
public static UltimateStacker getInstance() {
|
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
public void onDisable() {
|
|
|
|
this.saveToFile();
|
|
|
|
this.storage.closeConnection();
|
2019-01-23 19:01:31 +01:00
|
|
|
if (hologram != null)
|
|
|
|
this.hologram.unloadHolograms();
|
2018-11-06 04:33:10 +01:00
|
|
|
|
|
|
|
ConsoleCommandSender console = Bukkit.getConsoleSender();
|
2019-01-10 21:27:01 +01:00
|
|
|
console.sendMessage(Methods.formatText("&a============================="));
|
2019-01-15 08:29:27 +01:00
|
|
|
console.sendMessage(Methods.formatText("&7UltimateStacker " + this.getDescription().getVersion() + " by &5Songoda <3!"));
|
2019-01-10 21:27:01 +01:00
|
|
|
console.sendMessage(Methods.formatText("&7Action: &cDisabling&7..."));
|
|
|
|
console.sendMessage(Methods.formatText("&a============================="));
|
2018-11-06 04:33:10 +01:00
|
|
|
}
|
|
|
|
|
2018-11-09 05:11:49 +01:00
|
|
|
@Override
|
2018-11-06 04:33:10 +01:00
|
|
|
public void onEnable() {
|
|
|
|
INSTANCE = this;
|
2018-11-09 05:11:49 +01:00
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
ConsoleCommandSender console = Bukkit.getConsoleSender();
|
2019-01-10 21:27:01 +01:00
|
|
|
console.sendMessage(Methods.formatText("&a============================="));
|
2019-01-15 08:29:27 +01:00
|
|
|
console.sendMessage(Methods.formatText("&7UltimateStacker " + this.getDescription().getVersion() + " by &5Songoda <3&7!"));
|
2019-01-10 21:27:01 +01:00
|
|
|
console.sendMessage(Methods.formatText("&7Action: &aEnabling&7..."));
|
2018-11-06 04:33:10 +01:00
|
|
|
|
|
|
|
this.settingsManager = new SettingsManager(this);
|
2019-05-23 22:15:04 +02:00
|
|
|
this.settingsManager.setupConfig();
|
2018-11-06 04:33:10 +01:00
|
|
|
|
2019-05-23 22:15:04 +02:00
|
|
|
this.commandManager = new CommandManager(this);
|
2018-11-06 04:33:10 +01:00
|
|
|
|
2019-07-23 16:55:49 +02:00
|
|
|
this.lootablesManager = new LootablesManager();
|
|
|
|
this.lootablesManager.createDefaultLootables();
|
|
|
|
this.getLootablesManager().getLootManager().loadLootables();
|
2019-07-08 18:39:57 +02:00
|
|
|
|
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
for (EntityType value : EntityType.values()) {
|
2018-11-06 05:53:27 +01:00
|
|
|
if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) {
|
2018-11-06 04:33:10 +01:00
|
|
|
mobFile.getConfig().addDefault("Mobs." + value.name() + ".Enabled", true);
|
2019-04-03 19:31:23 +02:00
|
|
|
mobFile.getConfig().addDefault("Mobs." + value.name() + ".Display Name", Methods.formatText(value.name().toLowerCase().replace("_", " "), true));
|
2018-11-06 04:33:10 +01:00
|
|
|
mobFile.getConfig().addDefault("Mobs." + value.name() + ".Max Stack Size", -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mobFile.getConfig().options().copyDefaults(true);
|
|
|
|
mobFile.saveConfig();
|
|
|
|
|
|
|
|
for (Material value : Material.values()) {
|
2019-04-11 08:54:59 +02:00
|
|
|
itemFile.getConfig().addDefault("Items." + value.name() + ".Has Hologram", true);
|
|
|
|
itemFile.getConfig().addDefault("Items." + value.name() + ".Max Stack Size", -1);
|
|
|
|
itemFile.getConfig().addDefault("Items." + value.name() + ".Display Name", Methods.formatText(value.name().toLowerCase().replace("_", " "), true));
|
2018-11-06 04:33:10 +01:00
|
|
|
}
|
|
|
|
itemFile.getConfig().options().copyDefaults(true);
|
|
|
|
itemFile.saveConfig();
|
|
|
|
|
|
|
|
for (EntityType value : EntityType.values()) {
|
2018-11-06 05:53:27 +01:00
|
|
|
if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) {
|
2018-11-06 04:33:10 +01:00
|
|
|
spawnerFile.getConfig().addDefault("Spawners." + value.name() + ".Max Stack Size", -1);
|
2019-01-10 21:27:01 +01:00
|
|
|
spawnerFile.getConfig().addDefault("Spawners." + value.name() + ".Display Name", Methods.formatText(value.name().toLowerCase().replace("_", " "), true));
|
2018-11-06 04:33:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
spawnerFile.getConfig().options().copyDefaults(true);
|
|
|
|
spawnerFile.saveConfig();
|
|
|
|
|
2019-07-19 04:19:33 +02:00
|
|
|
new Locale(this, "en_US");
|
|
|
|
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
2018-11-06 04:33:10 +01:00
|
|
|
|
2019-04-26 10:06:18 +02:00
|
|
|
//Running Songoda Updater
|
|
|
|
Plugin plugin = new Plugin(this, 16);
|
|
|
|
plugin.addModule(new LocaleModule());
|
|
|
|
SongodaUpdate.load(plugin);
|
2018-11-06 04:33:10 +01:00
|
|
|
|
|
|
|
this.spawnerStackManager = new SpawnerStackManager();
|
|
|
|
this.entityStackManager = new EntityStackManager();
|
|
|
|
this.stackingTask = new StackingTask(this);
|
|
|
|
|
|
|
|
checkStorage();
|
|
|
|
|
|
|
|
Bukkit.getScheduler().runTaskLater(this, () -> {
|
|
|
|
if (storage.containsGroup("spawners")) {
|
|
|
|
for (StorageRow row : storage.getRowsByGroup("spawners")) {
|
|
|
|
try {
|
2019-01-10 21:27:01 +01:00
|
|
|
Location location = Methods.unserializeLocation(row.getKey());
|
2018-11-06 04:33:10 +01:00
|
|
|
|
|
|
|
SpawnerStack stack = new SpawnerStack(
|
|
|
|
location,
|
|
|
|
row.get("amount").asInt());
|
|
|
|
|
|
|
|
this.spawnerStackManager.addSpawner(stack);
|
|
|
|
} catch (Exception e) {
|
|
|
|
console.sendMessage("Failed to load spawner.");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save data initially so that if the person reloads again fast they don't lose all their data.
|
|
|
|
this.saveToFile();
|
2019-01-23 19:01:31 +01:00
|
|
|
if (hologram != null)
|
|
|
|
hologram.loadHolograms();
|
2018-11-06 04:33:10 +01:00
|
|
|
}, 10);
|
2019-01-23 19:01:31 +01:00
|
|
|
PluginManager pluginManager = Bukkit.getPluginManager();
|
2019-01-10 22:45:13 +01:00
|
|
|
if (isServerVersionAtLeast(ServerVersion.V1_10))
|
2019-06-07 19:48:17 +02:00
|
|
|
pluginManager.registerEvents(new BreedListeners(this), this);
|
|
|
|
pluginManager.registerEvents(new BlockListeners(this), this);
|
|
|
|
pluginManager.registerEvents(new DeathListeners(this), this);
|
|
|
|
pluginManager.registerEvents(new ShearListeners(this), this);
|
|
|
|
pluginManager.registerEvents(new InteractListeners(this), this);
|
|
|
|
pluginManager.registerEvents(new EntityListeners(this), this);
|
|
|
|
pluginManager.registerEvents(new ItemListeners(this), this);
|
|
|
|
pluginManager.registerEvents(new TameListeners(this), this);
|
2019-07-17 14:56:50 +02:00
|
|
|
pluginManager.registerEvents(new SpawnerListeners(this), this);
|
2019-06-07 19:48:17 +02:00
|
|
|
pluginManager.registerEvents(new SheepDyeListeners(this), this);
|
2018-11-06 04:33:10 +01:00
|
|
|
|
2019-06-20 09:33:29 +02:00
|
|
|
if (Setting.CLEAR_LAG.getBoolean() && pluginManager.isPluginEnabled("ClearLag"))
|
|
|
|
pluginManager.registerEvents(new ClearLagListeners(this), this);
|
|
|
|
|
2019-01-23 19:01:31 +01:00
|
|
|
// Register Hologram Plugin
|
2019-06-07 19:48:17 +02:00
|
|
|
if (Setting.SPAWNER_HOLOGRAMS.getBoolean()) {
|
2019-01-27 21:33:28 +01:00
|
|
|
if (pluginManager.isPluginEnabled("HolographicDisplays"))
|
|
|
|
hologram = new HologramHolographicDisplays(this);
|
|
|
|
}
|
2018-11-06 04:33:10 +01:00
|
|
|
|
2019-06-10 02:47:29 +02:00
|
|
|
// Register Hooks
|
|
|
|
if (pluginManager.isPluginEnabled("Jobs")) {
|
|
|
|
stackerHooks.add(new JobsHook());
|
|
|
|
}
|
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
|
|
|
|
2019-03-07 20:00:13 +01:00
|
|
|
// Starting Metrics
|
|
|
|
new Metrics(this);
|
|
|
|
|
2019-01-10 21:27:01 +01:00
|
|
|
console.sendMessage(Methods.formatText("&a============================="));
|
2018-11-06 04:33:10 +01:00
|
|
|
}
|
|
|
|
|
2019-06-10 02:47:29 +02:00
|
|
|
public void addExp(Player player, EntityStack stack) {
|
|
|
|
for (StackerHook stackerHook : stackerHooks) {
|
|
|
|
stackerHook.applyExperience(player, stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
private void checkStorage() {
|
|
|
|
if (getConfig().getBoolean("Database.Activate Mysql Support")) {
|
|
|
|
this.storage = new StorageMysql(this);
|
|
|
|
} else {
|
|
|
|
this.storage = new StorageYaml(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveToFile() {
|
|
|
|
this.storage.closeConnection();
|
|
|
|
checkStorage();
|
|
|
|
|
|
|
|
storage.doSave();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void reload() {
|
2019-07-19 04:19:33 +02:00
|
|
|
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
|
2018-11-06 04:33:10 +01:00
|
|
|
this.locale.reloadMessages();
|
|
|
|
this.mobFile = new ConfigWrapper(this, "", "mobs.yml");
|
|
|
|
this.itemFile = new ConfigWrapper(this, "", "items.yml");
|
|
|
|
this.spawnerFile = new ConfigWrapper(this, "", "spawners.yml");
|
2019-05-23 22:15:04 +02:00
|
|
|
this.settingsManager.reloadConfig();
|
2019-07-23 16:55:49 +02:00
|
|
|
this.getLootablesManager().getLootManager().loadLootables();
|
2018-11-06 04:33:10 +01:00
|
|
|
}
|
|
|
|
|
2018-11-08 04:26:38 +01:00
|
|
|
public boolean spawnersEnabled() {
|
2019-06-07 19:48:17 +02:00
|
|
|
return !this.getServer().getPluginManager().isPluginEnabled("EpicSpawners") && Setting.SPAWNERS_ENABLED.getBoolean();
|
2018-11-08 04:26:38 +01:00
|
|
|
}
|
|
|
|
|
2019-06-20 09:33:29 +02:00
|
|
|
public Hologram getHologram() {
|
|
|
|
return hologram;
|
|
|
|
}
|
|
|
|
|
2018-11-06 05:41:58 +01:00
|
|
|
public ServerVersion getServerVersion() {
|
|
|
|
return serverVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isServerVersion(ServerVersion version) {
|
|
|
|
return serverVersion == version;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isServerVersion(ServerVersion... versions) {
|
|
|
|
return ArrayUtils.contains(versions, serverVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isServerVersionAtLeast(ServerVersion version) {
|
|
|
|
return serverVersion.ordinal() >= version.ordinal();
|
|
|
|
}
|
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
public Locale getLocale() {
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CommandManager getCommandManager() {
|
|
|
|
return commandManager;
|
|
|
|
}
|
|
|
|
|
2019-07-23 16:55:49 +02:00
|
|
|
public LootablesManager getLootablesManager() {
|
|
|
|
return lootablesManager;
|
2019-07-08 18:39:57 +02:00
|
|
|
}
|
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
public EntityStackManager getEntityStackManager() {
|
|
|
|
return entityStackManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SpawnerStackManager getSpawnerStackManager() {
|
|
|
|
return spawnerStackManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public StackingTask getStackingTask() {
|
|
|
|
return stackingTask;
|
|
|
|
}
|
|
|
|
|
2018-11-09 22:26:23 +01:00
|
|
|
public SettingsManager getSettingsManager() {
|
|
|
|
return settingsManager;
|
|
|
|
}
|
|
|
|
|
2018-11-06 04:33:10 +01:00
|
|
|
public ConfigWrapper getMobFile() {
|
|
|
|
return mobFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ConfigWrapper getItemFile() {
|
|
|
|
return itemFile;
|
|
|
|
}
|
|
|
|
|
2018-11-06 05:53:27 +01:00
|
|
|
public ConfigWrapper getSpawnerFile() {
|
|
|
|
return spawnerFile;
|
|
|
|
}
|
2018-11-06 04:33:10 +01:00
|
|
|
}
|