mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-27 04:25:21 +01:00
Added ability to disable worlds.
This commit is contained in:
parent
17450fe62a
commit
84c4a9fe34
2
.gitignore
vendored
2
.gitignore
vendored
@ -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\$SimplePie\.class
|
||||||
|
|
||||||
target/classes/com/songoda/ultimatestacker/utils/Metrics\$SingleLineChart\.class
|
target/classes/com/songoda/ultimatestacker/utils/Metrics\$SingleLineChart\.class
|
||||||
|
|
||||||
|
target/classes/META-INF/UltimateStacker\.kotlin_module
|
||||||
|
@ -10,7 +10,6 @@ import com.songoda.ultimatestacker.hologram.HologramHolographicDisplays;
|
|||||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||||
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
|
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
|
||||||
import com.songoda.ultimatestacker.storage.Storage;
|
import com.songoda.ultimatestacker.storage.Storage;
|
||||||
import com.songoda.ultimatestacker.storage.StorageItem;
|
|
||||||
import com.songoda.ultimatestacker.storage.StorageRow;
|
import com.songoda.ultimatestacker.storage.StorageRow;
|
||||||
import com.songoda.ultimatestacker.storage.types.StorageMysql;
|
import com.songoda.ultimatestacker.storage.types.StorageMysql;
|
||||||
import com.songoda.ultimatestacker.storage.types.StorageYaml;
|
import com.songoda.ultimatestacker.storage.types.StorageYaml;
|
||||||
@ -19,7 +18,6 @@ import com.songoda.ultimatestacker.utils.*;
|
|||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -31,6 +29,8 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class UltimateStacker extends JavaPlugin {
|
public class UltimateStacker extends JavaPlugin {
|
||||||
@ -114,9 +114,9 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
mobFile.saveConfig();
|
mobFile.saveConfig();
|
||||||
|
|
||||||
for (Material value : Material.values()) {
|
for (Material value : Material.values()) {
|
||||||
itemFile.getConfig().addDefault("Items." + value.name() + ".Has Hologram", 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() + ".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() + ".Display Name", Methods.formatText(value.name().toLowerCase().replace("_", " "), true));
|
||||||
}
|
}
|
||||||
itemFile.getConfig().options().copyDefaults(true);
|
itemFile.getConfig().options().copyDefaults(true);
|
||||||
itemFile.saveConfig();
|
itemFile.saveConfig();
|
||||||
@ -153,11 +153,11 @@ public class UltimateStacker extends JavaPlugin {
|
|||||||
if (storage.containsGroup("entities")) {
|
if (storage.containsGroup("entities")) {
|
||||||
for (StorageRow row : storage.getRowsByGroup("entities")) {
|
for (StorageRow row : storage.getRowsByGroup("entities")) {
|
||||||
try {
|
try {
|
||||||
EntityStack stack = new EntityStack(
|
EntityStack stack = new EntityStack(
|
||||||
UUID.fromString(row.getKey()),
|
UUID.fromString(row.getKey()),
|
||||||
row.get("amount").asInt());
|
row.get("amount").asInt());
|
||||||
|
|
||||||
this.entityStackManager.addStack(stack);
|
this.entityStackManager.addStack(stack);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
console.sendMessage("Failed to load entity.");
|
console.sendMessage("Failed to load entity.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -33,7 +33,7 @@ public class CommandGive extends AbstractCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type == null) {
|
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();
|
StringBuilder list = new StringBuilder();
|
||||||
|
|
||||||
for (EntityType types : EntityType.values()) {
|
for (EntityType types : EntityType.values()) {
|
||||||
|
@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class CommandSettings extends AbstractCommand {
|
public class CommandSettings extends AbstractCommand {
|
||||||
|
|
||||||
public CommandSettings(AbstractCommand parent) {
|
public CommandSettings(AbstractCommand parent) {
|
||||||
super("settings", parent, true);
|
super("Settings", parent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -24,7 +24,7 @@ public class CommandSettings extends AbstractCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSyntax() {
|
public String getSyntax() {
|
||||||
return "/us settings";
|
return "/us Settings";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package com.songoda.ultimatestacker.events;
|
package com.songoda.ultimatestacker.events;
|
||||||
|
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
|
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
|
import com.songoda.ultimatestacker.utils.SettingsManager;
|
||||||
import org.apache.commons.lang.math.NumberUtils;
|
import org.apache.commons.lang.math.NumberUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -21,6 +24,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BlockListeners implements Listener {
|
public class BlockListeners implements Listener {
|
||||||
|
|
||||||
private final UltimateStacker instance;
|
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;
|
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;
|
if (!instance.spawnersEnabled()) return;
|
||||||
|
|
||||||
BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
|
BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
|
||||||
|
@ -4,6 +4,7 @@ import com.songoda.ultimatestacker.UltimateStacker;
|
|||||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||||
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
|
import com.songoda.ultimatestacker.utils.SettingsManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -50,12 +51,15 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
int maxItemStackSize = instance.getConfig().getInt("Item.Max Stack Size");
|
int maxItemStackSize = SettingsManager.Settings.MAX_STACK_ITEMS.getInt();
|
||||||
int maxEntityStackSize = instance.getConfig().getInt("Entity.Max Stack Size");
|
int maxEntityStackSize = SettingsManager.Settings.MAX_STACK_ENTITIES.getInt();
|
||||||
int minEntityStackAmount = instance.getConfig().getInt("Entity.Min Stack Amount");
|
int minEntityStackAmount = SettingsManager.Settings.MIN_STACK_ENTITIES.getInt();
|
||||||
|
|
||||||
|
List<String> disabledWorlds = SettingsManager.Settings.DISABLED_WORLDS.getStringList();
|
||||||
|
|
||||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
if (disabledWorlds.stream().anyMatch(worldStr -> world.getName().equalsIgnoreCase(worldStr))) continue;
|
||||||
|
|
||||||
List<Entity> entities = world.getEntities();
|
List<Entity> entities = world.getEntities();
|
||||||
Collections.reverse(entities);
|
Collections.reverse(entities);
|
||||||
@ -66,7 +70,7 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
for (Entity entityO : entities) {
|
for (Entity entityO : entities) {
|
||||||
if (entityO == null || entityO instanceof Player || !entityO.isValid()) continue;
|
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();
|
ItemStack item = ((Item) entityO).getItemStack();
|
||||||
|
|
||||||
if (entityO.hasMetadata("grabbed")
|
if (entityO.hasMetadata("grabbed")
|
||||||
@ -95,7 +99,7 @@ public class StackingTask extends BukkitRunnable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(entityO instanceof LivingEntity) || !instance.getConfig().getBoolean("Main.Stack Entities"))
|
if (!(entityO instanceof LivingEntity) || !SettingsManager.Settings.STACK_ENTITIES.getBoolean())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LivingEntity initalEntity = (LivingEntity) entityO;
|
LivingEntity initalEntity = (LivingEntity) entityO;
|
||||||
|
@ -172,21 +172,22 @@ public class SettingsManager implements Listener {
|
|||||||
|
|
||||||
|
|
||||||
public void updateSettings() {
|
public void updateSettings() {
|
||||||
for (settings s : settings.values()) {
|
for (Settings s : Settings.values()) {
|
||||||
instance.getConfig().addDefault(s.setting, s.option);
|
instance.getConfig().addDefault(s.setting, s.option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum settings {
|
public enum Settings {
|
||||||
o1("Main.Stack Items", true),
|
STACK_ITEMS("Main.Stack Items", true),
|
||||||
o2("Main.Stack Entities", true),
|
STACK_ENTITIES("Main.Stack Entities", true),
|
||||||
o22("Main.Stack Spawners", true),
|
STACK_SPAWNERS("Main.Stack Spawners", true),
|
||||||
o3("Main.Stack Search Tick Speed", 5),
|
o3("Main.Stack Search Tick Speed", 5),
|
||||||
o4("Entity.Max Stack Size", 15),
|
DISABLED_WORLDS("Main.DISABLED Worlds", Arrays.asList("World1", "World2", "World3")),
|
||||||
oo("Entity.Min Stack Amount", 5),
|
MAX_STACK_ENTITIES("Entity.Max Stack Size", 15),
|
||||||
|
MIN_STACK_ENTITIES("Entity.Min Stack Amount", 5),
|
||||||
o5("Entity.Kill Whole Stack On Death", false),
|
o5("Entity.Kill Whole Stack On Death", false),
|
||||||
o52("Entity.Kill Whole Stack On Special Death Cause", true),
|
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"),
|
NAME_FORMAT_ENTITY("Entity.Name Format", "&f{TYPE} &6{AMT}x"),
|
||||||
o6("Item.Max Stack Size", 120),
|
o6("Item.Max Stack Size", 120),
|
||||||
NAME_FORMAT_ITEM("Item.Name Format", "&f{TYPE} &6{AMT}x"),
|
NAME_FORMAT_ITEM("Item.Name Format", "&f{TYPE} &6{AMT}x"),
|
||||||
@ -208,10 +209,27 @@ public class SettingsManager implements Listener {
|
|||||||
private String setting;
|
private String setting;
|
||||||
private Object option;
|
private Object option;
|
||||||
|
|
||||||
settings(String setting, Object option) {
|
Settings(String setting, Object option) {
|
||||||
this.setting = setting;
|
this.setting = setting;
|
||||||
this.option = option;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user