From d9f21c9ef7b9dd21dbeb9099fa3d4db54a7b740b Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Thu, 10 Jan 2019 15:27:01 -0500 Subject: [PATCH] Removed Arconix as a hard dependency. --- .../ultimatestacker/UltimateStacker.java | 35 +++--- .../command/CommandManager.java | 8 +- .../command/commands/CommandGive.java | 9 +- .../command/commands/CommandReload.java | 4 +- .../command/commands/CommandRemoveAll.java | 8 +- .../commands/CommandUltimateStacker.java | 6 +- .../ultimatestacker/storage/Storage.java | 2 +- .../ultimatestacker/tasks/StackingTask.java | 5 +- .../ultimatestacker/utils/ConfigWrapper.java | 67 +++++++++++ .../ultimatestacker/utils/Methods.java | 107 ++++++++++++++++-- .../ultimatestacker/utils/Reflection.java | 2 - .../utils/SettingsManager.java | 22 ++-- src/main/resources/plugin.yml | 2 +- .../events/InteractListeners$1.class | Bin 0 -> 1077 bytes .../events/InventoryListeners.class | Bin 2089 -> 2674 bytes .../ultimatestacker/utils/ConfigWrapper.class | Bin 0 -> 2889 bytes 16 files changed, 210 insertions(+), 67 deletions(-) create mode 100644 src/main/java/com/songoda/ultimatestacker/utils/ConfigWrapper.java create mode 100644 target/classes/com/songoda/ultimatestacker/events/InteractListeners$1.class create mode 100644 target/classes/com/songoda/ultimatestacker/utils/ConfigWrapper.class diff --git a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java index 03dd4d3..2326949 100644 --- a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java @@ -1,8 +1,5 @@ package com.songoda.ultimatestacker; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.arconix.api.methods.serialize.Serialize; -import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.ultimatestacker.command.CommandManager; import com.songoda.ultimatestacker.entity.EntityStack; import com.songoda.ultimatestacker.entity.EntityStackManager; @@ -16,6 +13,8 @@ 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; +import com.songoda.ultimatestacker.utils.ConfigWrapper; +import com.songoda.ultimatestacker.utils.Methods; import com.songoda.ultimatestacker.utils.ServerVersion; import com.songoda.ultimatestacker.utils.SettingsManager; import org.apache.commons.lang.ArrayUtils; @@ -63,10 +62,10 @@ public class UltimateStacker extends JavaPlugin { this.storage.closeConnection(); ConsoleCommandSender console = Bukkit.getConsoleSender(); - console.sendMessage(TextComponent.formatText("&a=============================")); - console.sendMessage(TextComponent.formatText("&7UltimateStacker " + this.getDescription().getVersion() + " by &5Brianna <3!")); - console.sendMessage(TextComponent.formatText("&7Action: &cDisabling&7...")); - console.sendMessage(TextComponent.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7UltimateStacker " + this.getDescription().getVersion() + " by &5Brianna <3!")); + console.sendMessage(Methods.formatText("&7Action: &cDisabling&7...")); + console.sendMessage(Methods.formatText("&a=============================")); } private boolean checkVersion() { @@ -93,9 +92,9 @@ public class UltimateStacker extends JavaPlugin { if (!checkVersion()) return; ConsoleCommandSender console = Bukkit.getConsoleSender(); - console.sendMessage(TextComponent.formatText("&a=============================")); - console.sendMessage(TextComponent.formatText("&7UltimateStacker " + this.getDescription().getVersion() + " by &5Brianna <3&7!")); - console.sendMessage(TextComponent.formatText("&7Action: &aEnabling&7...")); + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7UltimateStacker " + this.getDescription().getVersion() + " by &5Brianna <3&7!")); + console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); this.settingsManager = new SettingsManager(this); this.commandManager = new CommandManager(this); @@ -114,7 +113,7 @@ public class UltimateStacker extends JavaPlugin { 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", TextComponent.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.saveConfig(); @@ -122,7 +121,7 @@ public class UltimateStacker extends JavaPlugin { for (EntityType value : EntityType.values()) { if (value.isSpawnable() && value.isAlive() && !value.toString().contains("ARMOR")) { spawnerFile.getConfig().addDefault("Spawners." + value.name() + ".Max Stack Size", -1); - spawnerFile.getConfig().addDefault("Spawners." + value.name() + ".Display Name", TextComponent.formatText(value.name().toLowerCase().replace("_", " "), true)); + spawnerFile.getConfig().addDefault("Spawners." + value.name() + ".Display Name", Methods.formatText(value.name().toLowerCase().replace("_", " "), true)); } } spawnerFile.getConfig().options().copyDefaults(true); @@ -166,7 +165,7 @@ public class UltimateStacker extends JavaPlugin { if (storage.containsGroup("spawners")) { for (StorageRow row : storage.getRowsByGroup("spawners")) { try { - Location location = Serialize.getInstance().unserializeLocation(row.getKey()); + Location location = Methods.unserializeLocation(row.getKey()); if (location.getWorld() == null || !location.getBlock().getType().name().contains("SPAWNER")) { if (location.getWorld() != null && !location.getBlock().getType().name().contains("SPAWNER")) { @@ -187,12 +186,14 @@ public class UltimateStacker extends JavaPlugin { } for (SpawnerStack stack : spawnerStackManager.getStacks()) { - storage.prepareSaveItem("spawners", new StorageItem("location", Serialize.getInstance().serializeLocation(stack.getLocation())), + storage.prepareSaveItem("spawners", new StorageItem("location", Methods.serializeLocation(stack.getLocation())), new StorageItem("amount", stack.getAmount())); } // Save data initially so that if the person reloads again fast they don't lose all their data. this.saveToFile(); - this.hologramHandler = new HologramHandler(this); + if (Bukkit.getPluginManager().isPluginEnabled("Arconix")) { + this.hologramHandler = new HologramHandler(this); + } }, 10); Bukkit.getPluginManager().registerEvents(new SpawnerListeners(this), this); @@ -206,7 +207,7 @@ public class UltimateStacker extends JavaPlugin { Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000); - console.sendMessage(TextComponent.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&a=============================")); } private void update() { @@ -260,7 +261,7 @@ public class UltimateStacker extends JavaPlugin { } for (SpawnerStack stack : spawnerStackManager.getStacks()) { - storage.prepareSaveItem("spawners", new StorageItem("location", Serialize.getInstance().serializeLocation(stack.getLocation())), + storage.prepareSaveItem("spawners", new StorageItem("location", Methods.serializeLocation(stack.getLocation())), new StorageItem("amount", stack.getAmount())); } diff --git a/src/main/java/com/songoda/ultimatestacker/command/CommandManager.java b/src/main/java/com/songoda/ultimatestacker/command/CommandManager.java index cdf0e37..ae25223 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/CommandManager.java +++ b/src/main/java/com/songoda/ultimatestacker/command/CommandManager.java @@ -1,8 +1,8 @@ package com.songoda.ultimatestacker.command; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.command.commands.*; +import com.songoda.ultimatestacker.utils.Methods; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -51,7 +51,7 @@ public class CommandManager implements CommandExecutor { } } } - commandSender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&7The command you entered does not exist or is spelt incorrectly.")); + commandSender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The command you entered does not exist or is spelt incorrectly.")); return true; } @@ -63,8 +63,8 @@ public class CommandManager implements CommandExecutor { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { AbstractCommand.ReturnType returnType = command.runCommand(instance, sender, strings); if (returnType == AbstractCommand.ReturnType.SYNTAX_ERROR) { - sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&cInvalid Syntax!")); - sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cInvalid Syntax!")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&7The valid syntax is: &6" + command.getSyntax() + "&7.")); } return; } 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 a8d839d..5ebe43b 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java +++ b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java @@ -1,6 +1,5 @@ package com.songoda.ultimatestacker.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.command.AbstractCommand; import com.songoda.ultimatestacker.utils.Methods; @@ -34,13 +33,13 @@ public class CommandGive extends AbstractCommand { } if (type == null) { - sender.sendMessage(instance.getReferences().getPrefix() + TextComponent.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 Type &6" + args[2] + " &7does not exist. Try one of these:")); StringBuilder list = new StringBuilder(); for (EntityType types : EntityType.values()) { list.append(types.name().toUpperCase().replace(" ", "_")).append("&7, &6"); } - sender.sendMessage(TextComponent.formatText("&6" + list)); + sender.sendMessage(Methods.formatText("&6" + list)); } else { int amt = Integer.parseInt(args[3]); @@ -48,11 +47,11 @@ public class CommandGive extends AbstractCommand { if (!args[1].trim().toLowerCase().equals("all")) { Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer(); player.getInventory().addItem(itemStack); - player.sendMessage(TextComponent.formatText(instance.getLocale().getMessage("command.give.success", Methods.compileSpawnerName(type, amt)))); + player.sendMessage(Methods.formatText(instance.getLocale().getMessage("command.give.success", Methods.compileSpawnerName(type, amt)))); } else { for (Player player : Bukkit.getOnlinePlayers()) { player.getInventory().addItem(itemStack); - player.sendMessage(TextComponent.formatText(instance.getLocale().getMessage("command.give.success", Methods.compileSpawnerName(type, amt)))); + player.sendMessage(Methods.formatText(instance.getLocale().getMessage("command.give.success", Methods.compileSpawnerName(type, amt)))); } } } diff --git a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandReload.java b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandReload.java index 513faf2..591e619 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandReload.java +++ b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandReload.java @@ -1,8 +1,8 @@ package com.songoda.ultimatestacker.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.command.AbstractCommand; +import com.songoda.ultimatestacker.utils.Methods; import org.bukkit.command.CommandSender; public class CommandReload extends AbstractCommand { @@ -14,7 +14,7 @@ public class CommandReload extends AbstractCommand { @Override protected ReturnType runCommand(UltimateStacker instance, CommandSender sender, String... args) { instance.reload(); - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded.")); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Configuration and Language files reloaded.")); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandRemoveAll.java b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandRemoveAll.java index 218328f..3a26e91 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandRemoveAll.java +++ b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandRemoveAll.java @@ -1,9 +1,9 @@ package com.songoda.ultimatestacker.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.command.AbstractCommand; import com.songoda.ultimatestacker.entity.EntityStackManager; +import com.songoda.ultimatestacker.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -42,7 +42,7 @@ public class CommandRemoveAll extends AbstractCommand { amountRemoved ++; } else if (entityO.getType() == EntityType.DROPPED_ITEM && type.equalsIgnoreCase("items")) { ItemStack item = ((Item) entityO).getItemStack(); - if (entityO.isCustomNameVisible() && !entityO.getCustomName().contains(TextComponent.convertToInvisibleString("IS")) || item.hasItemMeta() && item.getItemMeta().hasDisplayName()) + if (entityO.isCustomNameVisible() && !entityO.getCustomName().contains(Methods.convertToInvisibleString("IS")) || item.hasItemMeta() && item.getItemMeta().hasDisplayName()) continue; entityO.remove(); amountRemoved ++; @@ -55,9 +55,9 @@ public class CommandRemoveAll extends AbstractCommand { if (type.equalsIgnoreCase("items") && amountRemoved == 1) type = "Item"; if (amountRemoved == 0) { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7No stacked " + type + " exist that could be removed.")); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7No stacked " + type + " exist that could be removed.")); } else { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Removed &6" + amountRemoved + " stacked " + TextComponent.formatText(type.toLowerCase(), true) + " &7Successfully.")); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Removed &6" + amountRemoved + " stacked " + Methods.formatText(type.toLowerCase(), true) + " &7Successfully.")); } return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandUltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandUltimateStacker.java index 9d3c1e6..24e5c52 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandUltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandUltimateStacker.java @@ -1,8 +1,8 @@ package com.songoda.ultimatestacker.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.command.AbstractCommand; +import com.songoda.ultimatestacker.utils.Methods; import org.bukkit.command.CommandSender; public class CommandUltimateStacker extends AbstractCommand { @@ -14,11 +14,11 @@ public class CommandUltimateStacker extends AbstractCommand { @Override protected ReturnType runCommand(UltimateStacker instance, CommandSender sender, String... args) { sender.sendMessage(""); - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna")); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oBrianna")); for (AbstractCommand command : instance.getCommandManager().getCommands()) { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { - sender.sendMessage(TextComponent.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); + sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); } } sender.sendMessage(""); diff --git a/src/main/java/com/songoda/ultimatestacker/storage/Storage.java b/src/main/java/com/songoda/ultimatestacker/storage/Storage.java index 2253009..b7ad5dd 100644 --- a/src/main/java/com/songoda/ultimatestacker/storage/Storage.java +++ b/src/main/java/com/songoda/ultimatestacker/storage/Storage.java @@ -1,7 +1,7 @@ package com.songoda.ultimatestacker.storage; -import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.ultimatestacker.UltimateStacker; +import com.songoda.ultimatestacker.utils.ConfigWrapper; import java.util.List; diff --git a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java index e0999f9..3e70611 100644 --- a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java +++ b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java @@ -1,6 +1,5 @@ package com.songoda.ultimatestacker.tasks; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.entity.EntityStack; import com.songoda.ultimatestacker.entity.EntityStackManager; @@ -62,7 +61,7 @@ public class StackingTask extends BukkitRunnable { if (entityO.hasMetadata("grabbed") || item == null - || entityO.isCustomNameVisible() && !entityO.getCustomName().contains(TextComponent.convertToInvisibleString("IS")) + || entityO.isCustomNameVisible() && !entityO.getCustomName().contains(Methods.convertToInvisibleString("IS")) || item.hasItemMeta() && item.getItemMeta().hasDisplayName()) continue; @@ -76,7 +75,7 @@ public class StackingTask extends BukkitRunnable { int size = item.getAmount(); - String name = TextComponent.convertToInvisibleString("IS") + Methods.compileItemName(item.getType(), size); + String name = Methods.convertToInvisibleString("IS") + Methods.compileItemName(item.getType(), size); if (instance.getItemFile().getConfig().getBoolean("Items." + item.getType().name() + ".Has Hologram")) { entityO.setCustomName(name); diff --git a/src/main/java/com/songoda/ultimatestacker/utils/ConfigWrapper.java b/src/main/java/com/songoda/ultimatestacker/utils/ConfigWrapper.java new file mode 100644 index 0000000..b188659 --- /dev/null +++ b/src/main/java/com/songoda/ultimatestacker/utils/ConfigWrapper.java @@ -0,0 +1,67 @@ +package com.songoda.ultimatestacker.utils; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; + +/** + * ConfigWrapper made by @clip + */ +public class ConfigWrapper { + + private final JavaPlugin plugin; + private final String folderName, fileName; + private FileConfiguration config; + private File configFile; + + public ConfigWrapper(final JavaPlugin instance, final String folderName, final String fileName) { + this.plugin = instance; + this.folderName = folderName; + this.fileName = fileName; + } + + public void createNewFile(final String message, final String header) { + reloadConfig(); + saveConfig(); + loadConfig(header); + + if (message != null) { + plugin.getLogger().info(message); + } + } + + public FileConfiguration getConfig() { + if (config == null) { + reloadConfig(); + } + return config; + } + + public void loadConfig(final String header) { + config.options().header(header); + config.options().copyDefaults(true); + saveConfig(); + } + + public void reloadConfig() { + if (configFile == null) { + configFile = new File(plugin.getDataFolder() + folderName, fileName); + } + config = YamlConfiguration.loadConfiguration(configFile); + } + + public void saveConfig() { + if (config == null || configFile == null) { + return; + } + try { + getConfig().save(configFile); + } catch (final IOException ex) { + plugin.getLogger().log(Level.SEVERE, "Could not save config to " + configFile, ex); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java index 8b72148..69e965f 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java @@ -1,16 +1,18 @@ package com.songoda.ultimatestacker.utils; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.ultimatestacker.UltimateStacker; -import org.bukkit.GameMode; -import org.bukkit.Material; +import org.bukkit.*; +import org.bukkit.block.Block; import org.bukkit.block.CreatureSpawner; import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.ItemMeta; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class Methods { @@ -51,37 +53,37 @@ public class Methods { public static String compileSpawnerName(EntityType entityType, int amount) { String nameFormat = UltimateStacker.getInstance().getConfig().getString("Spawners.Name Format"); - String displayName = TextComponent.formatText(UltimateStacker.getInstance().getSpawnerFile().getConfig().getString("Spawners." + entityType.name() + ".Display Name")); + String displayName = Methods.formatText(UltimateStacker.getInstance().getSpawnerFile().getConfig().getString("Spawners." + entityType.name() + ".Display Name")); nameFormat = nameFormat.replace("{TYPE}", displayName); nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount)); - String info = TextComponent.convertToInvisibleString(amount + ":"); - return info + TextComponent.formatText(nameFormat).trim(); + String info = Methods.convertToInvisibleString(amount + ":"); + return info + Methods.formatText(nameFormat).trim(); } public static String compileItemName(Material type, int amount) { String nameFormat = UltimateStacker.getInstance().getConfig().getString("Item.Name Format"); - String displayName = TextComponent.formatText(UltimateStacker.getInstance().getItemFile().getConfig().getString("Items." + type.name() + ".Display Name")); + String displayName = Methods.formatText(UltimateStacker.getInstance().getItemFile().getConfig().getString("Items." + type.name() + ".Display Name")); nameFormat = nameFormat.replace("{TYPE}", displayName); nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount)); - String info = TextComponent.convertToInvisibleString(amount + ":"); + String info = Methods.convertToInvisibleString(amount + ":"); - return info + TextComponent.formatText(nameFormat).trim(); + return info + Methods.formatText(nameFormat).trim(); } public static String compileEntityName(Entity entity, int amount) { String nameFormat = UltimateStacker.getInstance().getConfig().getString("Entity.Name Format"); - String displayName = TextComponent.formatText(entity.getType().name().toLowerCase().replace("_", " "), true); + String displayName = Methods.formatText(entity.getType().name().toLowerCase().replace("_", " "), true); nameFormat = nameFormat.replace("{TYPE}", displayName); nameFormat = nameFormat.replace("{AMT}", Integer.toString(amount)); - String info = TextComponent.convertToInvisibleString(amount + ":"); + String info = Methods.convertToInvisibleString(amount + ":"); - return info + TextComponent.formatText(nameFormat).trim(); + return info + Methods.formatText(nameFormat).trim(); } public static void takeItem(Player player, int amount) { @@ -107,4 +109,85 @@ public class Methods { return item; } + /** + * Serializes the location of the block specified. + * + * @param b The block whose location is to be saved. + * @return The serialized data. + */ + public static String serializeLocation(Block b) { + if (b == null) + return ""; + return serializeLocation(b.getLocation()); + } + + /** + * Serializes the location specified. + * + * @param location The location that is to be saved. + * @return The serialized data. + */ + public static String serializeLocation(Location location) { + if (location == null) + return ""; + String w = location.getWorld().getName(); + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + String str = w + ":" + x + ":" + y + ":" + z; + str = str.replace(".0", "").replace("/", ""); + return str; + } + + private static Map serializeCache = new HashMap<>(); + + /** + * Deserializes a location from the string. + * + * @param str The string to parse. + * @return The location that was serialized in the string. + */ + public static Location unserializeLocation(String str) { + if (str == null || str.equals("")) + return null; + if (serializeCache.containsKey(str)) { + return serializeCache.get(str).clone(); + } + String cacheKey = str; + str = str.replace("y:", ":").replace("z:", ":").replace("w:", "").replace("x:", ":").replace("/", "."); + List args = Arrays.asList(str.split("\\s*:\\s*")); + + World world = Bukkit.getWorld(args.get(0)); + double x = Double.parseDouble(args.get(1)), y = Double.parseDouble(args.get(2)), z = Double.parseDouble(args.get(3)); + Location location = new Location(world, x, y, z, 0, 0); + serializeCache.put(cacheKey, location.clone()); + return location; + } + + + public static String convertToInvisibleString(String s) { + if (s == null || s.equals("")) + return ""; + StringBuilder hidden = new StringBuilder(); + for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR + "").append(c); + return hidden.toString(); + } + + + public static String formatText(String text) { + if (text == null || text.equals("")) + return ""; + return formatText(text, false); + } + + public static String formatText(String text, boolean cap) { + if (text == null || text.equals("")) + return ""; + if (cap) + text = text.substring(0, 1).toUpperCase() + text.substring(1); + return ChatColor.translateAlternateColorCodes('&', text); + } + + + } diff --git a/src/main/java/com/songoda/ultimatestacker/utils/Reflection.java b/src/main/java/com/songoda/ultimatestacker/utils/Reflection.java index af329fd..885aa9a 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/Reflection.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/Reflection.java @@ -1,7 +1,5 @@ package com.songoda.ultimatestacker.utils; -import com.songoda.arconix.api.ArconixAPI; -import com.songoda.arconix.plugin.Arconix; import org.bukkit.Bukkit; import org.bukkit.block.CreatureSpawner; diff --git a/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java b/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java index eb99a38..9cfca3c 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/SettingsManager.java @@ -1,8 +1,5 @@ package com.songoda.ultimatestacker.utils; -import com.songoda.arconix.api.methods.GUI; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.ultimatestacker.UltimateStacker; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -106,23 +103,22 @@ public class SettingsManager implements Listener { player.closeInventory(); player.sendMessage(""); - player.sendMessage(TextComponent.formatText("&7Please enter a value for &6" + current + "&7.")); + player.sendMessage(Methods.formatText("&7Please enter a value for &6" + current + "&7.")); if (instance.getConfig().isInt(current) || instance.getConfig().isDouble(current)) { - player.sendMessage(TextComponent.formatText("&cUse only numbers.")); + player.sendMessage(Methods.formatText("&cUse only numbers.")); } player.sendMessage(""); } public void openSettingsManager(Player player) { Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager"); - GUI.fillGlass(inventory, 7); int slot = 10; for (String key : instance.getConfig().getDefaultSection().getKeys(false)) { ItemStack item = new ItemStack(Material.WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to. ItemMeta meta = item.getItemMeta(); - meta.setLore(Collections.singletonList(TextComponent.formatText("&6Click To Edit This Category."))); - meta.setDisplayName(TextComponent.formatText("&f&l" + key)); + meta.setLore(Collections.singletonList(Methods.formatText("&6Click To Edit This Category."))); + meta.setDisplayName(Methods.formatText("&f&l" + key)); item.setItemMeta(meta); inventory.setItem(slot, item); slot++; @@ -140,18 +136,18 @@ public class SettingsManager implements Listener { String fKey = cat.get(player) + "." + key; ItemStack item = new ItemStack(Material.DIAMOND_HELMET); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(TextComponent.formatText("&6" + key)); + meta.setDisplayName(Methods.formatText("&6" + key)); List lore = new ArrayList<>(); if (config.isBoolean(fKey)) { item.setType(Material.LEVER); - lore.add(TextComponent.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse")); + lore.add(Methods.formatText(config.getBoolean(fKey) ? "&atrue" : "&cfalse")); } else if (config.isString(fKey)) { item.setType(Material.PAPER); - lore.add(TextComponent.formatText("&9" + config.getString(fKey))); + lore.add(Methods.formatText("&9" + config.getString(fKey))); } else if (config.isInt(fKey)) { item.setType(Material.WATCH); - lore.add(TextComponent.formatText("&5" + config.getInt(fKey))); + lore.add(Methods.formatText("&5" + config.getInt(fKey))); } if (defs.getConfig().contains(fKey)) { @@ -160,7 +156,7 @@ public class SettingsManager implements Listener { Matcher m = SETTINGS_PATTERN.matcher(text); while (m.find()) { if (m.end() != text.length() || m.group().length() != 0) - lore.add(TextComponent.formatText("&7" + m.group())); + lore.add(Methods.formatText("&7" + m.group())); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f870d8f..aa80958 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: UltimateStacker description: UltimateStacker version: maven-version-number -depend: [Arconix] +soft-depend: [Arconix] main: com.songoda.ultimatestacker.UltimateStacker author: songoda commands: diff --git a/target/classes/com/songoda/ultimatestacker/events/InteractListeners$1.class b/target/classes/com/songoda/ultimatestacker/events/InteractListeners$1.class new file mode 100644 index 0000000000000000000000000000000000000000..9681dd9d6ec46ca35e8d25dd7e8987cdad3ef074 GIT binary patch literal 1077 zcmbV~ZBNrs6vzLUJ#?D|CL$mrf>a)Spz`PgNHS(83*AcS0xx)D*WHXlX-V5*cxR#? zz{L0&e61$N7{dqfLmAI4CR@~KV%q!vpWp4dr?)-#+xIVL02Z;9!!?X%(Sz$*ipB(v zOSmCmLWm;drjSV?Q$nVN%m}$9;kJak3{#5v+==Y{igm2`K~t%>4iBA3;a=oKr-~L^ z?ev&4bnTTHGOM=hcuus&keHs?VMrGJ20iT69gkOAM|B?5th!4xeY$U3?v52Wf`3kS zn~`N7(z{}&?K0#{zZKZLy{6x=)Rr4LM^?l`v3nk<{Dl5bsQ$KDWsX5Ed$jMOYlR^X8S?GT z81(~gM+}SqQ<`Cf+M}MgM?G(k+S#7;iRHG$8^@<-_VmByu2Aoa#xBF?ztSW>XgHqb z#?7Ygr_2pa+alU3KV^`L8|C7rR;Bq3W82i|Fzgz7i6LziHQlIDuw7VRFH?}x^+KhP zAEV>iOUIYxheXpvgbey{iM*d+9tnzox1YhzzUDrn>w~xxpO8!%?~vS#F-@3iqePf) zV}?*_W0o+}#vEb3Bm08jj&xaYM}D{9Y`p$GvUK%h5Gf2{0+ZxZbnKSMmr=kIat&KB z$!mB9o4kQzgya!k;3fGhyv7^y1TNEOrsI$07@)X|#vlz9eY+CXulzx(V(u5AQdi>T U!?;SG#0cpf8aXQ7Lymmr2OmQ3rT_o{ literal 0 HcmV?d00001 diff --git a/target/classes/com/songoda/ultimatestacker/events/InventoryListeners.class b/target/classes/com/songoda/ultimatestacker/events/InventoryListeners.class index a9e1e9d3d5e6798b8051294f057d93b1ea71e0f0..04e5eb4833c92267f8b6dbc4176b596a68c98146 100644 GIT binary patch literal 2674 zcmcJR+fx)r6vn@1XBk*VAs9d)2xwxKiwww30f{IgtGjpsAxex6yOU*PcZS-XC16!v z@?u`{>_dEzN~-c~RRU#F$sdrn{6D#UJ?yTt+{A|zMelU?Ip68?>(f2+$3MUP4qyPw zA)G*8C2Da#gnkUD7z{zdkZgu!b0LI_7ztq%W3qcmHsiASMA~1j!UV2_a21nPxP~eD zbX~=?iinCE0u`2>bqzai3Y?3^owS~H?4*-0^jyld(uQktHojtJ^n3aK>`s4FpnS}- zEq7d?H~dbX9rFUpRVTra)lthfXL9K!Gc#u_r8rU>b>c>9-pE+8pC44*Wh*N%d}tVR z&9vRD9CY*f3ns6Bg+An;tP3*;rnjfRT0uL_{EvHr54>dFnA^)q}z^ z5NN!cv$;#=yp^>`Yr?i2*KjSzCal)IvAt}j4LgxCGhAhbV^756<|?CHI2xAQR(vJ5 zS_)=xZyX<#0@~f40-;$amx-HGmfZD*y}Q=)#8@*lG~lL&I@GI(YKUP*;FNCzeUS?I zHQd5&>32uNUCgSO({K;-Di$<+iu)QKU{=E-K9e>NHGGaoDjsVvu%sd`VI7t>})>F!G z<*d@K!!Yf-J$6()3Cm8-8QB$q^IXhf5-zQ>y5EQE?0Gj2-UL~1^#YS68SY0a^56(C zD@kJ_?eH85R8qU}tb`*H)|t0PkyghkGRd3Pvc1zQaPU4BN`Sc^a1aU>+-M__*r|)5 z@Z#I*q9f{+YtFS&`m~W<=0(F8{YNRsU58tsskE+mhg$B2E|)^ddcWkG83BzHq>Z=5 z`EDT@wDSdc0s`;zzgAudd^raA+<=p88`+ye8UKJ#=Qc!V*Uu<>#acyew~!3`i)*OqxligKT=3#{hey%yNR6O`#1@(wxU> zJj91s#Yf2DEY=am*Yx-XUHA^&9-(Qdv}>hDJ2gq6$m#{X&yZ9Q&#BQ)T0O9-be1dO zCksC2lR~|wylv)OjBKbuh`OPBvO_J{+u27MDf06vfBKc=~$+sOyUMK%D^!^8OS-R=~ delta 752 zcmZvZNl#Qk6otQfLqB*FlhQx~EzO`ztq4t{ptd-G41ypkB4~_?y22r7qKRQ?T$o78 z#4SVQZ1!OoF&=+th;PBGbujaBd zV4kS7N}HQb+I&|ns?#($eddePR2k)nW-Da@M>YKn1RT>0GGyu^F*EMvWi-Q#Xrdg~ zj4~E*LNm@pz)8&{r!=P-)0|<-a?Wa|ITtXandQ79z4WHWymH4?%G`2Nrq$DCBhv5I zH@BFHNaF3Z_f!??YjX=j^LOXw7jE3XXEyyu3F^dwQWRTqOKvCbIFd&xmsnxigX+af z`B#K1u@FzPe2R(5sa%*4Qbo1wHna6gz8d0!Re-uEW<>;BY0KiS<0(cz;7=#BMAith zZi%d~3#E%T`38P7DiqM!lep x^qCj6M!8B4*F~?9ZchZO{uJ+!@?yMA5&=y=s8uTLkZy>{iWb?G^tDge_8V%DZ#Mt{ diff --git a/target/classes/com/songoda/ultimatestacker/utils/ConfigWrapper.class b/target/classes/com/songoda/ultimatestacker/utils/ConfigWrapper.class new file mode 100644 index 0000000000000000000000000000000000000000..ecee18197eddbf446600ea7256986d80fefbc580 GIT binary patch literal 2889 zcmb7G{a4dw6n;W0ffx!FLEWg<>9iCveod#iH$zyJC3F94_TlZJg5>&9LbMO+av zu2EbS@xF);G+e`V4L4Ad-J2RFFsb1dJ`{0VbWnp%-^G ze1cB}@SY%irsDH%d;zlybAnw~QBh$j=xjKxs$ExbpyYa0W3IKhX!}N}H13;Arg5F( zR$x?6pv}8Z#quW18qcOnfq`SztHzY?+4U+dy5?=i3imt9ZhhXaDmWg;4wWs>^li6p zh_!K*q8QjlYVj1>$(Djt=*e~iQ|@-2x9hh5o`UPSIQDCJZ{)dAGd!&zS#&G()?2dc z)KeDmS?nl z+i4nMa5J9SXjq;k$*$9&UM6%;*|TUrVLb>#J)GOfZKFomsx_E{2b?_#6=|xr`jZt!|RcV?bHb#IVy=pkr@+KSME_-$N z>-KnG?E1V*)-i|wr>)q!ZcuyPo^xC8%E|C7sh!@UXVCO207%&kxsr{^3bHdvkO&SF|)<(q(-Q_5b)etvJ-v(GRNy?QX{L4@r zMd8(6-`>`e<#2LNjZcr?9_Q73)fEsMA}4q!6ci)ijWC7qY&;TU-+!Ah8P1S{c^p!PUU zM4p$qli*$^-^MonI`c=`P)D92mH!Jh6WFN!U9PtiO36n(Q#u!Ab*GTlZ$SBW-uwlTm}@(Bi4 zm}xoj2X?JMTg!Av#d4kI_wY1k+|A3XafJ7jl@`Y z%esv{zaUrQQVRSV-i%nLhsZ26=qEwuD)X3-y{vkMzpw-Lk`Wkoitc*x9`%>Gdy&0x l31j?|!brOI@>_m^`;wAkjBPiPDcn?X@gTP@akB%L{{@9|(iZ># literal 0 HcmV?d00001