From 97542eedb1fe55281670a9afec70eaf9a18cabef Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Sun, 3 Feb 2019 22:18:55 -0500 Subject: [PATCH] Removed Arconix. --- .gitlab-ci.yml | 2 +- EpicFarming-Plugin/pom.xml | 10 +- .../epicfarming/EpicFarmingPlugin.java | 27 ++- .../epicfarming/command/CommandManager.java | 8 +- .../command/commands/CommandBoost.java | 13 +- .../command/commands/CommandEpicFarming.java | 6 +- .../command/commands/CommandGiveFarmItem.java | 8 +- .../songoda/epicfarming/farming/EFarm.java | 10 +- .../songoda/epicfarming/storage/Storage.java | 2 +- .../epicfarming/utils/ConfigWrapper.java | 67 ++++++++ .../songoda/epicfarming/utils/Methods.java | 162 ++++++++++++++++-- .../epicfarming/utils/SettingsManager.java | 18 +- .../src/main/resources/plugin.yml | 1 - .../target/classes/SettingDefinitions.yml | 1 + EpicFarming-Plugin/target/classes/en_US.lang | 33 ++++ EpicFarming-Plugin/target/classes/plugin.yml | 13 ++ 16 files changed, 304 insertions(+), 77 deletions(-) create mode 100644 EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/ConfigWrapper.java create mode 100644 EpicFarming-Plugin/target/classes/SettingDefinitions.yml create mode 100644 EpicFarming-Plugin/target/classes/en_US.lang create mode 100644 EpicFarming-Plugin/target/classes/plugin.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 35c8795..e9440c3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ stages: variables: name: "EpicFarming" path: "/builds/Songoda/$name" - version: "2.0.20" + version: "2.1" build: stage: build diff --git a/EpicFarming-Plugin/pom.xml b/EpicFarming-Plugin/pom.xml index dd399b1..80e329b 100644 --- a/EpicFarming-Plugin/pom.xml +++ b/EpicFarming-Plugin/pom.xml @@ -13,7 +13,7 @@ private - http://repo.songoda.com/repository/private + http://repo.songoda.com/artifactory/private @@ -28,12 +28,6 @@ liquidtanks LATEST - - com.songoda - arconix - LATEST - provided - org kingdoms @@ -43,7 +37,7 @@ net.milkbowl vault - LATEST + 1.7.1 provided diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java index 34bd34f..b33d1e2 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/EpicFarmingPlugin.java @@ -1,9 +1,6 @@ package com.songoda.epicfarming; import com.google.common.base.Preconditions; -import com.songoda.arconix.api.methods.serialize.Serialize; -import com.songoda.arconix.api.utils.ConfigWrapper; -import com.songoda.arconix.plugin.Arconix; import com.songoda.epicfarming.api.EpicFarming; import com.songoda.epicfarming.api.farming.Farm; import com.songoda.epicfarming.api.farming.Level; @@ -30,6 +27,7 @@ import com.songoda.epicfarming.tasks.EntityTask; import com.songoda.epicfarming.tasks.FarmTask; import com.songoda.epicfarming.tasks.GrowthTask; import com.songoda.epicfarming.tasks.HopperTask; +import com.songoda.epicfarming.utils.ConfigWrapper; import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Methods; import com.songoda.epicfarming.utils.SettingsManager; @@ -112,12 +110,11 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { if (!checkVersion()) return; checkStorage(); INSTANCE = this; - Arconix.pl().hook(this); CommandSender console = Bukkit.getConsoleSender(); - console.sendMessage(Arconix.pl().getApi().format().formatText("&a=============================")); - console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3&7!")); - console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &aEnabling&7...")); + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3&7!")); + console.sendMessage(Methods.formatText("&7Action: &aEnabling&7...")); String langMode = getConfig().getString("System.Language Mode"); Locale.init(this); @@ -147,7 +144,7 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { Bukkit.getScheduler().runTaskLater(this, () -> { if (storage.containsGroup("farms")) { for (StorageRow row : storage.getRowsByGroup("farms")) { - Location location = Serialize.getInstance().unserializeLocation(row.getKey()); + Location location = Methods.unserializeLocation(row.getKey()); if (location == null || location.getBlock() == null) return; int level = row.get("level").asInt(); @@ -205,7 +202,7 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::saveToFile, 6000, 6000); - console.sendMessage(Arconix.pl().getApi().format().formatText("&a=============================")); + console.sendMessage(Methods.formatText("&a=============================")); } private void checkStorage() { @@ -224,10 +221,10 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { playerData.getPlayer().closeInventory(); } CommandSender console = Bukkit.getConsoleSender(); - console.sendMessage(Arconix.pl().getApi().format().formatText("&a=============================")); - console.sendMessage(Arconix.pl().getApi().format().formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3!")); - console.sendMessage(Arconix.pl().getApi().format().formatText("&7Action: &cDisabling&7...")); - console.sendMessage(Arconix.pl().getApi().format().formatText("&a=============================")); + console.sendMessage(Methods.formatText("&a=============================")); + console.sendMessage(Methods.formatText("&7EpicFarming " + this.getDescription().getVersion() + " by &5Brianna <3!")); + console.sendMessage(Methods.formatText("&7Action: &cDisabling&7...")); + console.sendMessage(Methods.formatText("&a=============================")); } private void loadLevelManager() { @@ -264,7 +261,7 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { for (Farm farm : farmManager.getFarms().values()) { if (farm.getLocation() == null || farm.getLocation().getWorld() == null) continue; - String locstr = Arconix.pl().getApi().serialize().serializeLocation(farm.getLocation()); + String locstr = Methods.serializeLocation(farm.getLocation()); storage.prepareSaveItem("farms",new StorageItem("location",locstr), new StorageItem("level",farm.getLevel().getLevel()), new StorageItem("placedby",farm.getPlacedBy().toString()), @@ -442,7 +439,7 @@ public class EpicFarmingPlugin extends JavaPlugin implements EpicFarming { public ItemStack makeFarmItem(Level level) { ItemStack item = new ItemStack(Material.valueOf(EpicFarmingPlugin.getInstance().getConfig().getString("Main.Farm Block Material")), 1); ItemMeta meta = item.getItemMeta(); - meta.setDisplayName(Arconix.pl().getApi().format().formatText(Methods.formatName(level.getLevel(), true))); + meta.setDisplayName(Methods.formatText(Methods.formatName(level.getLevel(), true))); String line = getLocale().getMessage("general.nametag.lore"); if (!line.equals("")) meta.setLore(Arrays.asList(line)); item.setItemMeta(meta); diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/CommandManager.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/CommandManager.java index be24d0f..b1edbcc 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/CommandManager.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/CommandManager.java @@ -1,8 +1,8 @@ package com.songoda.epicfarming.command; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.epicfarming.EpicFarmingPlugin; import com.songoda.epicfarming.command.commands.*; +import com.songoda.epicfarming.utils.Methods; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -52,7 +52,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; } @@ -64,8 +64,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/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandBoost.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandBoost.java index 2a83836..69b5ec5 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandBoost.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandBoost.java @@ -1,10 +1,9 @@ package com.songoda.epicfarming.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.arconix.api.methods.math.AMath; import com.songoda.epicfarming.EpicFarmingPlugin; import com.songoda.epicfarming.boost.BoostData; import com.songoda.epicfarming.command.AbstractCommand; +import com.songoda.epicfarming.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -23,10 +22,10 @@ public class CommandBoost extends AbstractCommand { return ReturnType.SYNTAX_ERROR; } if (Bukkit.getPlayer(args[1]) == null) { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&cThat player does not exist...")); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&cThat player does not exist...")); return ReturnType.FAILURE; - } else if (!AMath.isInt(args[2])) { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&6" + args[2] + " &7is not a number...")); + } else if (!Methods.isInt(args[2])) { + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&6" + args[2] + " &7is not a number...")); return ReturnType.FAILURE; } else { Calendar c = Calendar.getInstance(); @@ -53,7 +52,7 @@ public class CommandBoost extends AbstractCommand { c.add(Calendar.YEAR, Integer.parseInt(arr2[1])); time = " &7for &6" + arr2[1] + " years&7."; } else { - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7" + args[3] + " &7is invalid.")); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7" + args[3] + " &7is invalid.")); return ReturnType.SUCCESS; } } else { @@ -62,7 +61,7 @@ public class CommandBoost extends AbstractCommand { BoostData boostData = new BoostData(Integer.parseInt(args[2]), c.getTime().getTime(), Bukkit.getPlayer(args[1]).getUniqueId()); instance.getBoostManager().addBoostToPlayer(boostData); - sender.sendMessage(TextComponent.formatText(instance.getReferences().getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7farms yield rates by &6" + args[2] + "x" + time)); + sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Successfully boosted &6" + Bukkit.getPlayer(args[1]).getName() + "'s &7farms yield rates by &6" + args[2] + "x" + time)); } return ReturnType.FAILURE; } diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandEpicFarming.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandEpicFarming.java index 40150de..0c82352 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandEpicFarming.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandEpicFarming.java @@ -1,8 +1,8 @@ package com.songoda.epicfarming.command.commands; -import com.songoda.arconix.api.methods.formatting.TextComponent; import com.songoda.epicfarming.EpicFarmingPlugin; import com.songoda.epicfarming.command.AbstractCommand; +import com.songoda.epicfarming.utils.Methods; import org.bukkit.command.CommandSender; public class CommandEpicFarming extends AbstractCommand { @@ -14,11 +14,11 @@ public class CommandEpicFarming extends AbstractCommand { @Override protected ReturnType runCommand(EpicFarmingPlugin 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/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandGiveFarmItem.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandGiveFarmItem.java index 2ad986b..5cafc30 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandGiveFarmItem.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/command/commands/CommandGiveFarmItem.java @@ -1,9 +1,9 @@ package com.songoda.epicfarming.command.commands; -import com.songoda.arconix.plugin.Arconix; import com.songoda.epicfarming.EpicFarmingPlugin; import com.songoda.epicfarming.command.AbstractCommand; import com.songoda.epicfarming.farming.ELevel; +import com.songoda.epicfarming.utils.Methods; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -21,11 +21,11 @@ public class CommandGiveFarmItem extends AbstractCommand { ELevel level = instance.getLevelManager().getLowestLevel(); Player player; if (args.length != 1 && Bukkit.getPlayer(args[1]) == null) { - sender.sendMessage(instance.getReferences().getPrefix() + Arconix.pl().getApi().format().formatText("&cThat player does not exist or is currently offline.")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cThat player does not exist or is currently offline.")); return ReturnType.FAILURE; } else if (args.length == 1) { if (!(sender instanceof Player)) { - sender.sendMessage(instance.getReferences().getPrefix() + Arconix.pl().getApi().format().formatText("&cYou need to be a player to give a farm item to yourself.")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cYou need to be a player to give a farm item to yourself.")); return ReturnType.FAILURE; } player = (Player)sender; @@ -35,7 +35,7 @@ public class CommandGiveFarmItem extends AbstractCommand { if (args.length >= 3 && !instance.getLevelManager().isLevel(Integer.parseInt(args[2]))) { - sender.sendMessage(instance.getReferences().getPrefix() + Arconix.pl().getApi().format().formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c.")); + sender.sendMessage(instance.getReferences().getPrefix() + Methods.formatText("&cNot a valid level... The current valid levels are: &4" + instance.getLevelManager().getLowestLevel().getLevel() + "-" + instance.getLevelManager().getHighestLevel().getLevel() + "&c.")); return ReturnType.FAILURE; } else if (args.length != 1){ diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java index 29f7b12..ffb6c0b 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/farming/EFarm.java @@ -1,8 +1,5 @@ package com.songoda.epicfarming.farming; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.arconix.api.methods.formatting.TimeComponent; -import com.songoda.arconix.plugin.Arconix; import com.songoda.epicfarming.EpicFarmingPlugin; import com.songoda.epicfarming.api.farming.Farm; import com.songoda.epicfarming.api.farming.Level; @@ -11,7 +8,6 @@ import com.songoda.epicfarming.boost.BoostData; import com.songoda.epicfarming.player.PlayerData; import com.songoda.epicfarming.utils.Debugger; import com.songoda.epicfarming.utils.Methods; -import com.songoda.epicfarming.api.farming.Farm; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -87,10 +83,10 @@ public class EFarm implements Farm { BoostData boostData = instance.getBoostManager().getBoost(placedBy); if (boostData != null) { - String[] parts = instance.getLocale().getMessage("interface.button.boostedstats", Integer.toString(boostData.getMultiplier()), TimeComponent.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|"); + String[] parts = instance.getLocale().getMessage("interface.button.boostedstats", Integer.toString(boostData.getMultiplier()), Methods.makeReadable(boostData.getEndTime() - System.currentTimeMillis())).split("\\|"); lore.add(""); for (String line : parts) - lore.add(TextComponent.formatText(line)); + lore.add(Methods.formatText(line)); } itemmeta.setLore(lore); @@ -112,7 +108,7 @@ public class EFarm implements Farm { itemmetaECO.setDisplayName(instance.getLocale().getMessage("interface.button.upgradewitheconomy")); ArrayList loreECO = new ArrayList<>(); if (nextLevel != null) - loreECO.add(instance.getLocale().getMessage("interface.button.upgradewitheconomylore", Arconix.pl().getApi().format().formatEconomy(nextLevel.getCostEconomy()))); + loreECO.add(instance.getLocale().getMessage("interface.button.upgradewitheconomylore", Methods.formatEconomy(nextLevel.getCostEconomy()))); else loreECO.add(instance.getLocale().getMessage("event.upgrade.maxed")); itemmetaECO.setLore(loreECO); diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/storage/Storage.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/storage/Storage.java index 3839c8c..9f8cb73 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/storage/Storage.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/storage/Storage.java @@ -1,8 +1,8 @@ package com.songoda.epicfarming.storage; -import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.epicfarming.EpicFarmingPlugin; import com.songoda.epicfarming.api.EpicFarming; +import com.songoda.epicfarming.utils.ConfigWrapper; import java.util.List; diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/ConfigWrapper.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/ConfigWrapper.java new file mode 100644 index 0000000..2c57a39 --- /dev/null +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/ConfigWrapper.java @@ -0,0 +1,67 @@ +package com.songoda.epicfarming.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/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Methods.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Methods.java index 753e806..13e3961 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Methods.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/Methods.java @@ -1,58 +1,78 @@ package com.songoda.epicfarming.utils; -import com.songoda.arconix.plugin.Arconix; import com.songoda.epicfarming.EpicFarmingPlugin; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; +import java.text.DecimalFormat; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + public class Methods { + private static Map serializeCache = new HashMap<>(); + public static ItemStack getGlass() { try { - EpicFarmingPlugin plugin = EpicFarmingPlugin.getInstance(); - return Arconix.pl().getApi().getGUI().getGlass(plugin.getConfig().getBoolean("settings.Rainbow-Glass"), plugin.getConfig().getInt("Interfaces.Glass Type 1")); - } catch (Exception ex) { - Debugger.runReport(ex); + EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance(); + return getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1")); + } catch (Exception e) { + Debugger.runReport(e); } return null; } public static ItemStack getBackgroundGlass(boolean type) { try { - EpicFarmingPlugin plugin = EpicFarmingPlugin.getInstance(); + EpicFarmingPlugin instance = EpicFarmingPlugin.getInstance(); if (type) - return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 2")); + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2")); else - return Arconix.pl().getApi().getGUI().getGlass(false, plugin.getConfig().getInt("Interfaces.Glass Type 3")); - } catch (Exception ex) { - Debugger.runReport(ex); + return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3")); + } catch (Exception e) { + Debugger.runReport(e); } return null; } + private static ItemStack getGlass(Boolean rainbow, int type) { + int randomNum = 1 + (int) (Math.random() * 6); + ItemStack glass; + if (rainbow) { + glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) randomNum); + } else { + glass = new ItemStack(Material.LEGACY_STAINED_GLASS_PANE, 1, (short) type); + } + ItemMeta glassmeta = glass.getItemMeta(); + glassmeta.setDisplayName("§l"); + glass.setItemMeta(glassmeta); + return glass; + } + public static String formatName(int level, boolean full) { try { String name = EpicFarmingPlugin.getInstance().getLocale().getMessage("general.nametag.farm", level); String info = ""; if (full) { - info += Arconix.pl().getApi().format().convertToInvisibleString(level + ":"); + info += Methods.convertToInvisibleString(level + ":"); } - return info + Arconix.pl().getApi().format().formatText(name); + return info + Methods.formatText(name); } catch (Exception ex) { Debugger.runReport(ex); } return null; } - public static void animate(Location location, Material mat) { try { if (!EpicFarmingPlugin.getInstance().getConfig().getBoolean("Main.Animate")) return; @@ -74,4 +94,114 @@ public class Methods { Debugger.runReport(ex); } } + + 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); + } + + 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(); + } + + /** + * 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; + } + + /** + * 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; + } + + /** + * Makes the specified Unix Epoch time human readable as per the format settings in the Arconix config. + * + * @param time The time to convert. + * @return A human readable string representing to specified time. + */ + public static String makeReadable(Long time) { + if (time == null) + return ""; + return String.format("%d hour(s), %d min(s), %d sec(s)", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))); + } + + /** + * Formats the specified double into the Economy format specified in the Arconix config. + * + * @param amt The double to format. + * @return The economy formatted double. + */ + public static String formatEconomy(double amt) { + DecimalFormat formatter = new DecimalFormat("#,###.00"); + return formatter.format(amt); + } + + public static boolean isInt(String number) { + if (number == null || number.equals("")) + return false; + try { + Integer.parseInt(number); + } catch (NumberFormatException e) { + return false; + } + return true; + } + } \ No newline at end of file diff --git a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java index 4eb1ed2..e909c14 100644 --- a/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java +++ b/EpicFarming-Plugin/src/main/java/com/songoda/epicfarming/utils/SettingsManager.java @@ -1,7 +1,5 @@ package com.songoda.epicfarming.utils; -import com.songoda.arconix.api.methods.formatting.TextComponent; -import com.songoda.arconix.api.utils.ConfigWrapper; import com.songoda.epicfarming.EpicFarmingPlugin; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -105,9 +103,9 @@ 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(""); } @@ -123,8 +121,8 @@ public class SettingsManager implements Listener { for (String key : instance.getConfig().getDefaultSection().getKeys(false)) { ItemStack item = new ItemStack(Material.WHITE_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++; @@ -142,18 +140,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.CLOCK); - lore.add(TextComponent.formatText("&5" + config.getInt(fKey))); + lore.add(Methods.formatText("&5" + config.getInt(fKey))); } meta.setLore(lore); diff --git a/EpicFarming-Plugin/src/main/resources/plugin.yml b/EpicFarming-Plugin/src/main/resources/plugin.yml index bd50272..d5495f5 100644 --- a/EpicFarming-Plugin/src/main/resources/plugin.yml +++ b/EpicFarming-Plugin/src/main/resources/plugin.yml @@ -2,7 +2,6 @@ name: EpicFarming description: EpicFarming main: com.songoda.epicfarming.EpicFarmingPlugin version: maven-version-number -depend: [Arconix] soft-depend: [Multiverse-Core] author: Songoda api-version: 1.13 diff --git a/EpicFarming-Plugin/target/classes/SettingDefinitions.yml b/EpicFarming-Plugin/target/classes/SettingDefinitions.yml new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/EpicFarming-Plugin/target/classes/SettingDefinitions.yml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/EpicFarming-Plugin/target/classes/en_US.lang b/EpicFarming-Plugin/target/classes/en_US.lang new file mode 100644 index 0000000..b4749ab --- /dev/null +++ b/EpicFarming-Plugin/target/classes/en_US.lang @@ -0,0 +1,33 @@ +#General Messages + +general.nametag.prefix = "&8[&6EpicFarming&8]" +general.nametag.farm = "&eLevel %level% &fFarm" +general.nametag.lore = "" + +#Interface Messages + +interface.button.upgradewithxp = "&aUpgrade with XP" +interface.button.upgradewithxplore = "&7Cost: &a%cost% Levels" +interface.button.upgradewitheconomy = "&aUpgrade with ECO" +interface.button.upgradewitheconomylore = "&7Cost: &a$%cost%" +interface.button.level = "&6Next Level &7%level%" +interface.button.radius = "&7Radius: &6%speed%" +interface.button.speed = "&7Speed: &6%speed%x" +interface.button.autoharvest = "&7Auto Harvest: &6%status%" +interface.button.autoreplant = "&7Auto Replant: &6%status%" +interface.button.autobreeding = "&7Auto Breeding: &6%status%" +interface.button.boostedstats = "&a&lCurrently boosted!|&7Yeild rate multiplied by &6%amount%x&7.|&7Expires in &6%time%&7." + + +#Command Messages + +command.give.success = "&7You have been given a &6level %level% &7farm item." + +#Event Messages + +event.general.nopermission = "&cYou do not have permission to do that." +event.upgrade.cannotafford = "&cYou cannot afford this upgrade." +event.upgrade.success = "&7You successfully upgraded this farm to &6level %level%&7!" +event.upgrade.maxed = "&6This farm is maxed out." +event.upgrade.successmaxed = "&7You maxed out this farm at &6%level%x&7." +event.limit.hit = "&7You can only have &6%limit% &7farms at a single time." \ No newline at end of file diff --git a/EpicFarming-Plugin/target/classes/plugin.yml b/EpicFarming-Plugin/target/classes/plugin.yml new file mode 100644 index 0000000..d5495f5 --- /dev/null +++ b/EpicFarming-Plugin/target/classes/plugin.yml @@ -0,0 +1,13 @@ +name: EpicFarming +description: EpicFarming +main: com.songoda.epicfarming.EpicFarmingPlugin +version: maven-version-number +soft-depend: [Multiverse-Core] +author: Songoda +api-version: 1.13 +commands: + EpicFarming: + description: View information on this plugin. + default: true + aliases: [efa] + usage: /efa \ No newline at end of file