diff --git a/.gitignore b/.gitignore index c50cbf0..e9522e4 100644 --- a/.gitignore +++ b/.gitignore @@ -234,3 +234,5 @@ target/classes/com/songoda/ultimatestacker/utils/Metrics\$SimpleBarChart\.class target/classes/com/songoda/ultimatestacker/utils/Metrics\$SimplePie\.class target/classes/com/songoda/ultimatestacker/utils/Metrics\$SingleLineChart\.class + +target/classes/META-INF/UltimateStacker\.kotlin_module diff --git a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java index 2d421fc..23e3483 100644 --- a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java @@ -10,7 +10,6 @@ import com.songoda.ultimatestacker.hologram.HologramHolographicDisplays; import com.songoda.ultimatestacker.spawner.SpawnerStack; import com.songoda.ultimatestacker.spawner.SpawnerStackManager; import com.songoda.ultimatestacker.storage.Storage; -import com.songoda.ultimatestacker.storage.StorageItem; import com.songoda.ultimatestacker.storage.StorageRow; import com.songoda.ultimatestacker.storage.types.StorageMysql; import com.songoda.ultimatestacker.storage.types.StorageYaml; @@ -19,7 +18,6 @@ import com.songoda.ultimatestacker.utils.*; import org.apache.commons.lang.ArrayUtils; import org.bukkit.*; import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -31,6 +29,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; public class UltimateStacker extends JavaPlugin { @@ -114,9 +114,9 @@ public class UltimateStacker extends JavaPlugin { mobFile.saveConfig(); for (Material value : Material.values()) { - 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)); + 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)); } itemFile.getConfig().options().copyDefaults(true); itemFile.saveConfig(); @@ -153,11 +153,11 @@ public class UltimateStacker extends JavaPlugin { if (storage.containsGroup("entities")) { for (StorageRow row : storage.getRowsByGroup("entities")) { try { - EntityStack stack = new EntityStack( - UUID.fromString(row.getKey()), - row.get("amount").asInt()); + EntityStack stack = new EntityStack( + UUID.fromString(row.getKey()), + row.get("amount").asInt()); - this.entityStackManager.addStack(stack); + this.entityStackManager.addStack(stack); } catch (Exception e) { console.sendMessage("Failed to load entity."); e.printStackTrace(); diff --git a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java index 5ebe43b..889110e 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java +++ b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java @@ -33,7 +33,7 @@ public class CommandGive extends AbstractCommand { } if (type == null) { - sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getReferences().getPrefix() + "&7The entity Type &6" + args[2] + " &7does not exist. Try one of these:")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getReferences().getPrefix() + "&7The entity StackType &6" + args[2] + " &7does not exist. Try one of these:")); StringBuilder list = new StringBuilder(); for (EntityType types : EntityType.values()) { diff --git a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandSettings.java b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandSettings.java index 38de5f1..ca76eed 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandSettings.java +++ b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandSettings.java @@ -8,7 +8,7 @@ import org.bukkit.entity.Player; public class CommandSettings extends AbstractCommand { public CommandSettings(AbstractCommand parent) { - super("settings", parent, true); + super("Settings", parent, true); } @Override @@ -24,7 +24,7 @@ public class CommandSettings extends AbstractCommand { @Override public String getSyntax() { - return "/us settings"; + return "/us Settings"; } @Override diff --git a/src/main/java/com/songoda/ultimatestacker/events/BlockListeners.java b/src/main/java/com/songoda/ultimatestacker/events/BlockListeners.java index 5b2b80a..0383bbc 100644 --- a/src/main/java/com/songoda/ultimatestacker/events/BlockListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/events/BlockListeners.java @@ -1,11 +1,14 @@ package com.songoda.ultimatestacker.events; import com.songoda.ultimatestacker.UltimateStacker; +import com.songoda.ultimatestacker.entity.EntityStackManager; import com.songoda.ultimatestacker.spawner.SpawnerStack; import com.songoda.ultimatestacker.utils.Methods; +import com.songoda.ultimatestacker.utils.SettingsManager; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.CreatureSpawner; import org.bukkit.enchantments.Enchantment; @@ -21,6 +24,8 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; +import java.util.List; + public class BlockListeners implements Listener { private final UltimateStacker instance; @@ -37,6 +42,9 @@ public class BlockListeners implements Listener { if (block == null || item == null || block.getType() != Material.MOB_SPAWNER || item.getType() != Material.MOB_SPAWNER || event.getAction() == Action.LEFT_CLICK_BLOCK) return; + List disabledWorlds = SettingsManager.Settings.DISABLED_WORLDS.getStringList(); + if (disabledWorlds.stream().anyMatch(worldStr -> event.getPlayer().getWorld().getName().equalsIgnoreCase(worldStr))) return; + if (!instance.spawnersEnabled()) return; BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta(); diff --git a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java index e0c3fb6..ad44dc6 100644 --- a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java +++ b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java @@ -4,6 +4,7 @@ import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.entity.EntityStack; import com.songoda.ultimatestacker.entity.EntityStackManager; import com.songoda.ultimatestacker.utils.Methods; +import com.songoda.ultimatestacker.utils.SettingsManager; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; @@ -50,12 +51,15 @@ public class StackingTask extends BukkitRunnable { @Override public void run() { - int maxItemStackSize = instance.getConfig().getInt("Item.Max Stack Size"); - int maxEntityStackSize = instance.getConfig().getInt("Entity.Max Stack Size"); - int minEntityStackAmount = instance.getConfig().getInt("Entity.Min Stack Amount"); + int maxItemStackSize = SettingsManager.Settings.MAX_STACK_ITEMS.getInt(); + int maxEntityStackSize = SettingsManager.Settings.MAX_STACK_ENTITIES.getInt(); + int minEntityStackAmount = SettingsManager.Settings.MIN_STACK_ENTITIES.getInt(); + + List disabledWorlds = SettingsManager.Settings.DISABLED_WORLDS.getStringList(); EntityStackManager stackManager = instance.getEntityStackManager(); for (World world : Bukkit.getWorlds()) { + if (disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr))) continue; List entities = world.getEntities(); Collections.reverse(entities); @@ -66,7 +70,7 @@ public class StackingTask extends BukkitRunnable { for (Entity entityO : entities) { if (entityO == null || entityO instanceof Player || !entityO.isValid()) continue; - if (entityO instanceof Item && instance.getConfig().getBoolean("Main.Stack Items")) { + if (entityO instanceof Item && SettingsManager.Settings.STACK_ITEMS.getBoolean()) { ItemStack item = ((Item) entityO).getItemStack(); if (entityO.hasMetadata("grabbed") @@ -95,7 +99,7 @@ public class StackingTask extends BukkitRunnable { continue; } - if (!(entityO instanceof LivingEntity) || !instance.getConfig().getBoolean("Main.Stack Entities")) + if (!(entityO instanceof LivingEntity) || !SettingsManager.Settings.STACK_ENTITIES.getBoolean()) continue; LivingEntity initalEntity = (LivingEntity) entityO; diff --git a/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java b/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java index 769c941..5cd7d58 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java @@ -172,21 +172,22 @@ public class SettingsManager implements Listener { public void updateSettings() { - for (settings s : settings.values()) { + for (Settings s : Settings.values()) { instance.getConfig().addDefault(s.setting, s.option); } } - public enum settings { - o1("Main.Stack Items", true), - o2("Main.Stack Entities", true), - o22("Main.Stack Spawners", true), + public enum Settings { + STACK_ITEMS("Main.Stack Items", true), + STACK_ENTITIES("Main.Stack Entities", true), + STACK_SPAWNERS("Main.Stack Spawners", true), o3("Main.Stack Search Tick Speed", 5), - o4("Entity.Max Stack Size", 15), - oo("Entity.Min Stack Amount", 5), + DISABLED_WORLDS("Main.DISABLED Worlds", Arrays.asList("World1", "World2", "World3")), + MAX_STACK_ENTITIES("Entity.Max Stack Size", 15), + MIN_STACK_ENTITIES("Entity.Min Stack Amount", 5), o5("Entity.Kill Whole Stack On Death", false), o52("Entity.Kill Whole Stack On Special Death Cause", true), - o53("Entity.Special Death Cause", Arrays.asList("FALL", "DROWNING", "LAVA", "VOID")), + SPECIAL_DEATH_CAUSE("Entity.Special Death Cause", Arrays.asList("FALL", "DROWNING", "LAVA", "VOID")), NAME_FORMAT_ENTITY("Entity.Name Format", "&f{TYPE} &6{AMT}x"), o6("Item.Max Stack Size", 120), NAME_FORMAT_ITEM("Item.Name Format", "&f{TYPE} &6{AMT}x"), @@ -208,10 +209,27 @@ public class SettingsManager implements Listener { private String setting; private Object option; - settings(String setting, Object option) { + Settings(String setting, Object option) { this.setting = setting; this.option = option; } + + public List getStringList() { + return UltimateStacker.getInstance().getConfig().getStringList(setting); + } + + public boolean getBoolean() { + return UltimateStacker.getInstance().getConfig().getBoolean(setting); + } + + public int getInt() { + return UltimateStacker.getInstance().getConfig().getInt(setting); + } + + public String getString() { + return UltimateStacker.getInstance().getConfig().getString(setting); + } + } } \ No newline at end of file