Added ability to disable worlds.

This commit is contained in:
Brianna 2019-04-11 02:54:59 -04:00
parent 17450fe62a
commit 84c4a9fe34
7 changed files with 58 additions and 26 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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();

View File

@ -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()) {

View File

@ -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

View File

@ -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<String> 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();

View File

@ -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<String> 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<Entity> 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;

View File

@ -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<String> 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);
}
}
}