From 134f4a5a08b0ac40046e9473ddb47b2a5825573f Mon Sep 17 00:00:00 2001 From: Ryder Belserion <52214219+RyderBelserion@users.noreply.github.com> Date: Tue, 11 Oct 2022 16:46:27 -0400 Subject: [PATCH] Remove old code --- .../com/badbones69/crazyauctions/Main.java | 477 --------- .../badbones69/crazyauctions/api/Version.java | 128 --- .../crazyauctions/controllers/GUI.java | 950 ------------------ .../crazyauctions/controllers/Metrics.java | 727 -------------- .../currency/CurrencyManager.java | 119 --- 5 files changed, 2401 deletions(-) delete mode 100644 src/main/java/com/badbones69/crazyauctions/Main.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/api/Version.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/controllers/GUI.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/controllers/Metrics.java delete mode 100644 src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java diff --git a/src/main/java/com/badbones69/crazyauctions/Main.java b/src/main/java/com/badbones69/crazyauctions/Main.java deleted file mode 100644 index ee546ee..0000000 --- a/src/main/java/com/badbones69/crazyauctions/Main.java +++ /dev/null @@ -1,477 +0,0 @@ -package com.badbones69.crazyauctions; - -import com.badbones69.crazyauctions.api.*; -import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.events.AuctionListEvent; -import com.badbones69.crazyauctions.controllers.GUI; -import com.badbones69.crazyauctions.controllers.Metrics; -import com.badbones69.crazyauctions.currency.Vault; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import org.bukkit.permissions.PermissionAttachmentInfo; -import org.bukkit.plugin.java.JavaPlugin; -import org.yaml.snakeyaml.error.YAMLException; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Random; - -public class Main extends JavaPlugin implements Listener { - - public static FileManager fileManager = FileManager.getInstance(); - public static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); - - @Override - public void onEnable() { - fileManager.logInfo(true).setup(this); - crazyAuctions.loadCrazyAuctions(); - Bukkit.getServer().getPluginManager().registerEvents(this, this); - Bukkit.getServer().getPluginManager().registerEvents(new GUI(), this); - Methods.updateAuction(); - startCheck(); - - if (!Vault.setupEconomy()) { saveDefaultConfig(); } - - Messages.addMissingMessages(); - new Metrics(this, 4624); //Starts up bStats - } - - @Override - public void onDisable() { - int file = 0; - Bukkit.getScheduler().cancelTask(file); - Files.DATA.saveFile(true); - } - - public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args) { - if (commandLable.equalsIgnoreCase("CrazyAuctions") || commandLable.equalsIgnoreCase("CrazyAuction") || commandLable.equalsIgnoreCase("CA") || commandLable.equalsIgnoreCase("AH") || commandLable.equalsIgnoreCase("HDV")) { - if (args.length == 0) { - if (!Methods.hasPermission(sender, "Access")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - Player player = (Player) sender; - if (Files.CONFIG.getFile().contains("Settings.Category-Page-Opens-First")) { - if (Files.CONFIG.getFile().getBoolean("Settings.Category-Page-Opens-First")) { - GUI.openCategories(player, ShopType.SELL); - return true; - } - } - if (crazyAuctions.isSellingEnabled()) { - GUI.openShop(player, ShopType.SELL, Category.NONE, 1); - } else if (crazyAuctions.isBiddingEnabled()) { - GUI.openShop(player, ShopType.BID, Category.NONE, 1); - } else { - player.sendMessage(Methods.getPrefix() + Methods.color("&cThe bidding and selling options are both disabled. Please contact the admin about this.")); - } - return true; - } - if (args.length >= 1) { - if (args[0].equalsIgnoreCase("Help")) {// CA Help - if (!Methods.hasPermission(sender, "Access")) return true; - sender.sendMessage(Messages.HELP.getMessage()); - return true; - } - if (args[0].equalsIgnoreCase("test")) {// CA test [times] - if (!Methods.hasPermission(sender, "test")) return true; - int times = 1; - if (args.length >= 2) { - if (!Methods.isInt(args[1])) { - HashMap placeholders = new HashMap<>(); - placeholders.put("%Arg%", args[1]); - placeholders.put("%arg%", args[1]); - sender.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); - return true; - } - times = Integer.parseInt(args[1]); - } - int price = 10; - int amount = 1; - ItemStack item = Methods.getItemInHand((Player) sender); - if (item != null && item.getType() != Material.AIR) { - // For testing as another player - String seller = "Test-Account"; - for (int it = 1; it <= times; it++) { - int num = 1; - Random r = new Random(); - for (; Files.DATA.getFile().contains("Items." + num); num++) ; - Files.DATA.getFile().set("Items." + num + ".Price", price); - Files.DATA.getFile().set("Items." + num + ".Seller", seller); - if (args[0].equalsIgnoreCase("Bid")) { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Bid-Time"))); - } else { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Sell-Time"))); - } - Files.DATA.getFile().set("Items." + num + ".Full-Time", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Full-Expire-Time"))); - int id = r.nextInt(Integer.MAX_VALUE); - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - Files.DATA.getFile().set("Items." + num + ".StoreID", id); - ShopType type = ShopType.SELL; - Files.DATA.getFile().set("Items." + num + ".Biddable", args[0].equalsIgnoreCase("Bid")); - Files.DATA.getFile().set("Items." + num + ".TopBidder", "None"); - ItemStack I = item.clone(); - I.setAmount(amount); - Files.DATA.getFile().set("Items." + num + ".Item", I); - } - Files.DATA.saveFile(); - HashMap placeholders = new HashMap<>(); - placeholders.put("%Price%", price + ""); - placeholders.put("%price%", price + ""); - sender.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); - if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { - Methods.setItemInHand((Player) sender, new ItemStack(Material.AIR)); - } else { - item.setAmount(item.getAmount() - amount); - } - } else { - sender.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage()); - } - return true; - } - if (args[0].equalsIgnoreCase("Reload")) {// CA Reload - if (!Methods.hasPermission(sender, "Admin")) return true; - fileManager.logInfo(true).setup(this); - crazyAuctions.loadCrazyAuctions(); - sender.sendMessage(Messages.RELOAD.getMessage()); - return true; - } - if (args[0].equalsIgnoreCase("View")) {// CA View - if (!Methods.hasPermission(sender, "View")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - if (args.length >= 2) { - Player player = (Player) sender; - GUI.openViewer(player, args[1], 1); - return true; - } - sender.sendMessage(Messages.CRAZYAUCTIONS_VIEW.getMessage()); - return true; - } - if (args[0].equalsIgnoreCase("Expired") || args[0].equalsIgnoreCase("Collect")) {// CA Expired - if (!Methods.hasPermission(sender, "Access")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - Player player = (Player) sender; - GUI.openPlayersExpiredList(player, 1); - return true; - } - if (args[0].equalsIgnoreCase("Listed")) {// CA Listed - if (!Methods.hasPermission(sender, "Access")) return true; - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - Player player = (Player) sender; - GUI.openPlayersCurrentList(player, 1); - return true; - } - if (args[0].equalsIgnoreCase("Sell") || args[0].equalsIgnoreCase("Bid")) {// /CA Sell/Bid [Amount of Items] - if (!(sender instanceof Player)) { - sender.sendMessage(Messages.PLAYERS_ONLY.getMessage()); - return true; - } - if (args.length >= 2) { - Player player = (Player) sender; - if (args[0].equalsIgnoreCase("Sell")) { - if (!crazyAuctions.isSellingEnabled()) { - player.sendMessage(Messages.SELLING_DISABLED.getMessage()); - return true; - } - if (!Methods.hasPermission(player, "Sell")) return true; - } - if (args[0].equalsIgnoreCase("Bid")) { - if (!crazyAuctions.isBiddingEnabled()) { - player.sendMessage(Messages.BIDDING_DISABLED.getMessage()); - return true; - } - if (!Methods.hasPermission(player, "Bid")) return true; - } - ItemStack item = Methods.getItemInHand(player); - int amount = item.getAmount(); - if (args.length >= 3) { - if (!Methods.isInt(args[2])) { - HashMap placeholders = new HashMap<>(); - placeholders.put("%Arg%", args[2]); - placeholders.put("%arg%", args[2]); - player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); - return true; - } - amount = Integer.parseInt(args[2]); - if (amount <= 0) amount = 1; - if (amount > item.getAmount()) amount = item.getAmount(); - } - if (!Methods.isLong(args[1])) { - HashMap placeholders = new HashMap<>(); - placeholders.put("%Arg%", args[1]); - placeholders.put("%arg%", args[1]); - player.sendMessage(Messages.NOT_A_NUMBER.getMessage(placeholders)); - return true; - } - if (Methods.getItemInHand(player).getType() == Material.AIR) { - player.sendMessage(Messages.DOSENT_HAVE_ITEM_IN_HAND.getMessage()); - return false; - } - long price = Long.parseLong(args[1]); - if (args[0].equalsIgnoreCase("Bid")) { - if (price < Files.CONFIG.getFile().getLong("Settings.Minimum-Bid-Price")) { - player.sendMessage(Messages.BID_PRICE_TO_LOW.getMessage()); - return true; - } - if (price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Bid-Price")) { - player.sendMessage(Messages.BID_PRICE_TO_HIGH.getMessage()); - return true; - } - } else { - if (price < Files.CONFIG.getFile().getLong("Settings.Minimum-Sell-Price")) { - player.sendMessage(Messages.SELL_PRICE_TO_LOW.getMessage()); - return true; - } - if (price > Files.CONFIG.getFile().getLong("Settings.Max-Beginning-Sell-Price")) { - player.sendMessage(Messages.SELL_PRICE_TO_HIGH.getMessage()); - return true; - } - } - if (!player.hasPermission("crazyauctions.bypass")) { - int SellLimit = 0; - int BidLimit = 0; - for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) { - String perm = permission.getPermission(); - if (perm.startsWith("crazyauctions.sell.")) { - perm = perm.replace("crazyauctions.sell.", ""); - if (Methods.isInt(perm)) { - if (Integer.parseInt(perm) > SellLimit) { - SellLimit = Integer.parseInt(perm); - } - } - } - if (perm.startsWith("crazyauctions.bid.")) { - perm = perm.replace("crazyauctions.bid.", ""); - if (Methods.isInt(perm)) { - if (Integer.parseInt(perm) > BidLimit) { - BidLimit = Integer.parseInt(perm); - } - } - } - } - for (int i = 1; i < 100; i++) { - if (SellLimit < i) { - if (player.hasPermission("crazyauctions.sell." + i)) { - SellLimit = i; - } - } - if (BidLimit < i) { - if (player.hasPermission("crazyauctions.bid." + i)) { - BidLimit = i; - } - } - } - if (args[0].equalsIgnoreCase("Sell")) { - if (crazyAuctions.getItems(player, ShopType.SELL).size() >= SellLimit) { - player.sendMessage(Messages.MAX_ITEMS.getMessage()); - return true; - } - } - if (args[0].equalsIgnoreCase("Bid")) { - if (crazyAuctions.getItems(player, ShopType.BID).size() >= BidLimit) { - player.sendMessage(Messages.MAX_ITEMS.getMessage()); - return true; - } - } - } - for (String id : Files.CONFIG.getFile().getStringList("Settings.BlackList")) { - if (item.getType() == Methods.makeItem(id, 1).getType()) { - player.sendMessage(Messages.ITEM_BLACKLISTED.getMessage()); - return true; - } - } - if (!Files.CONFIG.getFile().getBoolean("Settings.Allow-Damaged-Items")) { - for (Material i : getDamageableItems()) { - if (item.getType() == i) { - if (item.getDurability() > 0) { - player.sendMessage(Messages.ITEM_DAMAGED.getMessage()); - return true; - } - } - } - } - if (!allowBook(item)) { - player.sendMessage(Messages.BOOK_NOT_ALLOWED.getMessage()); - return true; - } - String seller = player.getName(); - // For testing as another player - //String seller = "Test-Account"; - int num = 1; - Random r = new Random(); - for (; Files.DATA.getFile().contains("Items." + num); num++) ; - Files.DATA.getFile().set("Items." + num + ".Price", price); - Files.DATA.getFile().set("Items." + num + ".Seller", seller); - if (args[0].equalsIgnoreCase("Bid")) { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Bid-Time"))); - } else { - Files.DATA.getFile().set("Items." + num + ".Time-Till-Expire", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Sell-Time"))); - } - Files.DATA.getFile().set("Items." + num + ".Full-Time", Methods.convertToMill(Files.CONFIG.getFile().getString("Settings.Full-Expire-Time"))); - int id = r.nextInt(999999); - // Runs 3x to check for same ID. - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - for (String i : Files.DATA.getFile().getConfigurationSection("Items").getKeys(false)) - if (Files.DATA.getFile().getInt("Items." + i + ".StoreID") == id) id = r.nextInt(Integer.MAX_VALUE); - Files.DATA.getFile().set("Items." + num + ".StoreID", id); - ShopType type = ShopType.SELL; - if (args[0].equalsIgnoreCase("Bid")) { - Files.DATA.getFile().set("Items." + num + ".Biddable", true); - type = ShopType.BID; - } else { - Files.DATA.getFile().set("Items." + num + ".Biddable", false); - } - Files.DATA.getFile().set("Items." + num + ".TopBidder", "None"); - ItemStack I = item.clone(); - I.setAmount(amount); - Files.DATA.getFile().set("Items." + num + ".Item", I); - Files.DATA.saveFile(); - Bukkit.getPluginManager().callEvent(new AuctionListEvent(player, type, I, price)); - HashMap placeholders = new HashMap<>(); - placeholders.put("%Price%", price + ""); - placeholders.put("%price%", price + ""); - player.sendMessage(Messages.ADDED_ITEM_TO_AUCTION.getMessage(placeholders)); - if (item.getAmount() <= 1 || (item.getAmount() - amount) <= 0) { - Methods.setItemInHand(player, new ItemStack(Material.AIR)); - } else { - item.setAmount(item.getAmount() - amount); - } - return false; - } - sender.sendMessage(Messages.CRAZYAUCTIONS_SELL_BID.getMessage()); - return true; - } - } - } - sender.sendMessage(Messages.CRAZYAUCTIONS_HELP.getMessage()); - return false; - } - - @EventHandler - public void onJoin(PlayerJoinEvent e) { - final Player player = e.getPlayer(); - if (player.getName().equalsIgnoreCase("BadBones69")) { - Bukkit.getScheduler().runTaskLater(this, () -> player.sendMessage(Methods.getPrefix() + Methods.color("&7This server is running your Crazy Auctions Plugin. " + "&7It is running version &av" + Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions").getDescription().getVersion() + "&7.")), 40); - } - } - - private void startCheck() { - Bukkit.getScheduler().runTaskTimer(this, Methods :: updateAuction, 20, 5 * 20); - } - - private ArrayList getDamageableItems() { - ArrayList ma = new ArrayList<>(); - if (Version.isNewer(Version.v1_12_R1)) { - ma.add(Material.matchMaterial("GOLDEN_HELMET")); - ma.add(Material.matchMaterial("GOLDEN_CHESTPLATE")); - ma.add(Material.matchMaterial("GOLDEN_LEGGINGS")); - ma.add(Material.matchMaterial("GOLDEN_BOOTS")); - ma.add(Material.matchMaterial("WOODEN_SWORD")); - ma.add(Material.matchMaterial("WOODEN_AXE")); - ma.add(Material.matchMaterial("WOODEN_PICKAXE")); - ma.add(Material.matchMaterial("WOODEN_AXE")); - ma.add(Material.matchMaterial("WOODEN_SHOVEL")); - ma.add(Material.matchMaterial("STONE_SHOVEL")); - ma.add(Material.matchMaterial("IRON_SHOVEL")); - ma.add(Material.matchMaterial("DIAMOND_SHOVEL")); - ma.add(Material.matchMaterial("WOODEN_HOE")); - ma.add(Material.matchMaterial("GOLDEN_HOE")); - ma.add(Material.matchMaterial("CROSSBOW")); - ma.add(Material.matchMaterial("TRIDENT")); - ma.add(Material.matchMaterial("TURTLE_HELMET")); - } else { - ma.add(Material.matchMaterial("GOLD_HELMET")); - ma.add(Material.matchMaterial("GOLD_CHESTPLATE")); - ma.add(Material.matchMaterial("GOLD_LEGGINGS")); - ma.add(Material.matchMaterial("GOLD_BOOTS")); - ma.add(Material.matchMaterial("WOOD_SWORD")); - ma.add(Material.matchMaterial("WOOD_AXE")); - ma.add(Material.matchMaterial("WOOD_PICKAXE")); - ma.add(Material.matchMaterial("WOOD_AXE")); - ma.add(Material.matchMaterial("WOOD_SPADE")); - ma.add(Material.matchMaterial("STONE_SPADE")); - ma.add(Material.matchMaterial("IRON_SPADE")); - ma.add(Material.matchMaterial("DIAMOND_SPADE")); - ma.add(Material.matchMaterial("WOOD_HOE")); - ma.add(Material.matchMaterial("GOLD_HOE")); - } - ma.add(Material.DIAMOND_HELMET); - ma.add(Material.DIAMOND_CHESTPLATE); - ma.add(Material.DIAMOND_LEGGINGS); - ma.add(Material.DIAMOND_BOOTS); - ma.add(Material.CHAINMAIL_HELMET); - ma.add(Material.CHAINMAIL_CHESTPLATE); - ma.add(Material.CHAINMAIL_LEGGINGS); - ma.add(Material.CHAINMAIL_BOOTS); - ma.add(Material.IRON_HELMET); - ma.add(Material.IRON_CHESTPLATE); - ma.add(Material.IRON_LEGGINGS); - ma.add(Material.IRON_BOOTS); - ma.add(Material.LEATHER_HELMET); - ma.add(Material.LEATHER_CHESTPLATE); - ma.add(Material.LEATHER_LEGGINGS); - ma.add(Material.LEATHER_BOOTS); - ma.add(Material.BOW); - ma.add(Material.STONE_SWORD); - ma.add(Material.IRON_SWORD); - ma.add(Material.DIAMOND_SWORD); - ma.add(Material.STONE_AXE); - ma.add(Material.IRON_AXE); - ma.add(Material.DIAMOND_AXE); - ma.add(Material.STONE_PICKAXE); - ma.add(Material.IRON_PICKAXE); - ma.add(Material.DIAMOND_PICKAXE); - ma.add(Material.STONE_AXE); - ma.add(Material.IRON_AXE); - ma.add(Material.DIAMOND_AXE); - ma.add(Material.STONE_HOE); - ma.add(Material.IRON_HOE); - ma.add(Material.DIAMOND_HOE); - ma.add(Material.FLINT_AND_STEEL); - ma.add(Material.ANVIL); - ma.add(Material.FISHING_ROD); - return ma; - } - - private boolean allowBook(ItemStack item) { - if (item != null && item.hasItemMeta() && item.getItemMeta() instanceof BookMeta) { - System.out.println("[Crazy Auctions] Checking " + item.getType() + " for illegal unicode."); - try { - Files.TEST_FILE.getFile().set("Test", item); - Files.TEST_FILE.saveFile(); - System.out.println("[Crazy Auctions] " + item.getType() + " has passed unicode checks."); - } catch (YAMLException e) { - System.out.println("[Crazy Auctions] " + item.getType() + " has failed unicode checks and has been denied."); - return false; - } - return ((BookMeta) item.getItemMeta()).getPages().stream().mapToInt(String :: length).sum() < 2000; - } - return true; - } - - public Material getMaterial(String newMaterial, String oldMaterial) { - return Material.matchMaterial(Version.isNewer(Version.v1_12_R1) ? newMaterial : oldMaterial); - } - -} diff --git a/src/main/java/com/badbones69/crazyauctions/api/Version.java b/src/main/java/com/badbones69/crazyauctions/api/Version.java deleted file mode 100644 index 7b57a9d..0000000 --- a/src/main/java/com/badbones69/crazyauctions/api/Version.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.badbones69.crazyauctions.api; - -import org.bukkit.Bukkit; - -public enum Version { - - TOO_OLD(-1), - v1_7_R1(171), v1_7_R2(172), v1_7_R3(173), v1_7_R4(174), - v1_8_R1(181), v1_8_R2(182), v1_8_R3(183), - v1_9_R1(191), v1_9_R2(192), - v1_10_R1(1101), - v1_11_R1(1111), - v1_12_R1(1121), - v1_13_R2(1132), - v1_14_R1(1141), - v1_15_R1(1151), - v1_16_R1(1161), v1_16_R2(1162), v1_16_R3(1163), - TOO_NEW(-2); - - private static Version currentVersion; - private static Version latest; - private final int versionInteger; - - private Version(int versionInteger) { - this.versionInteger = versionInteger; - } - - /** - * - * @return Get the server's Minecraft version. - */ - public static Version getCurrentVersion() { - if (currentVersion == null) { - String ver = Bukkit.getServer().getClass().getPackage().getName(); - int v = Integer.parseInt(ver.substring(ver.lastIndexOf('.') + 1).replace("_", "").replace("R", "").replace("v", "")); - for (Version version : values()) { - if (version.getVersionInteger() == v) { - currentVersion = version; - break; - } - } - if (v > Version.getLatestVersion().getVersionInteger()) { - currentVersion = Version.getLatestVersion(); - } - if (currentVersion == null) { - currentVersion = Version.TOO_NEW; - } - } - return currentVersion; - } - - /** - * Get the latest version allowed by the Version class. - * @return The latest version. - */ - public static Version getLatestVersion() { - if (latest == null) { - Version v = Version.TOO_OLD; - for (Version version : values()) { - if (version.comparedTo(v) == 1) { - v = version; - } - } - return v; - } else { - return latest; - - } - } - - /** - * - * @return The server's minecraft version as an integer. - */ - public int getVersionInteger() { - return this.versionInteger; - } - - /** - * This checks if the current version is older, newer, or is the checked version. - * @param version The version you are checking. - * @return -1 if older, 0 if the same, and 1 if newer. - */ - public int comparedTo(Version version) { - int result = -1; - int current = this.getVersionInteger(); - int check = version.getVersionInteger(); - if (current > check || check == -2) {// check is newer then current - result = 1; - } else if (current == check) {// check is the same as current - result = 0; - } else if (check == -1) {// check is older then current - result = -1; - } - return result; - } - - /** - * Checks to see if the current version is newer then the checked version. - * @param version The version you are checking. - * @return True if newer then the checked version and false if the same or older. - */ - public static boolean isNewer(Version version) { - if (currentVersion == null) getCurrentVersion(); - return currentVersion.versionInteger > version.versionInteger || currentVersion.versionInteger == -2; - } - - /** - * Checks to see if the current version is the same as the checked version. - * @param version The version you are checking. - * @return True if both the current and checked version is the same and false if otherwise. - */ - public static boolean isSame(Version version) { - if (currentVersion == null) getCurrentVersion(); - return currentVersion.versionInteger == version.versionInteger; - } - - /** - * Checks to see if the current version is older than the checked version. - * @param version The version you are checking. - * @return True if older than the checked version and false if the same or newer. - */ - public static boolean isOlder(Version version) { - if (currentVersion == null) getCurrentVersion(); - return currentVersion.versionInteger < version.versionInteger || currentVersion.versionInteger == -1; - } - -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java b/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java deleted file mode 100644 index bfd2d9c..0000000 --- a/src/main/java/com/badbones69/crazyauctions/controllers/GUI.java +++ /dev/null @@ -1,950 +0,0 @@ -package com.badbones69.crazyauctions.controllers; - -import com.badbones69.crazyauctions.Methods; -import com.badbones69.crazyauctions.api.*; -import com.badbones69.crazyauctions.api.FileManager.Files; -import com.badbones69.crazyauctions.api.enums.CancelledReason; -import com.badbones69.crazyauctions.api.events.AuctionBuyEvent; -import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent; -import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent; -import com.badbones69.crazyauctions.currency.CurrencyManager; -import org.bukkit.Bukkit; -import org.bukkit.Sound; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryAction; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.logging.Level; - -public class GUI implements Listener { - - private static HashMap bidding = new HashMap<>(); - private static HashMap biddingID = new HashMap<>(); - private static HashMap shopType = new HashMap<>(); // Shop Type - private static HashMap shopCategory = new HashMap<>(); // Category Type - private static HashMap> List = new HashMap<>(); - private static HashMap IDs = new HashMap<>(); - private static CrazyAuctions crazyAuctions = CrazyAuctions.getInstance(); - private static Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("CrazyAuctions"); - - public static void openShop(Player player, ShopType sell, Category cat, int page) { - Methods.updateAuction(); - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - List items = new ArrayList<>(); - List ID = new ArrayList<>(); - if (!data.contains("Items")) { - data.set("Items.Clear", null); - Files.DATA.saveFile(); - } - if (cat != null) { - shopCategory.put(player, cat); - } else { - shopCategory.put(player, Category.NONE); - } - if (data.contains("Items")) { - for (String i : data.getConfigurationSection("Items").getKeys(false)) { - List lore = new ArrayList<>(); - if (data.getItemStack("Items." + i + ".Item") != null && (cat.getItems().contains(data.getItemStack("Items." + i + ".Item").getType()) || cat == Category.NONE)) { - if (data.getBoolean("Items." + i + ".Biddable")) { - if (sell == ShopType.BID) { - String seller = data.getString("Items." + i + ".Seller"); - String topbidder = data.getString("Items." + i + ".TopBidder"); - for (String l : config.getStringList("Settings.GUISettings.Bidding")) { - lore.add(l.replace("%TopBid%", Methods.getPrice(i, false)).replace("%topbid%", Methods.getPrice(i, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); - } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); - ID.add(data.getInt("Items." + i + ".StoreID")); - } - } else { - if (sell == ShopType.SELL) { - for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { - lore.add(l.replace("%Price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%price%", String.format(Locale.ENGLISH, "%,d", Long.parseLong(Methods.getPrice(i, false)))).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); - } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); - ID.add(data.getInt("Items." + i + ".StoreID")); - } - } - } - } - } - int maxPage = Methods.getMaxPage(items); - for (; page > maxPage; page--) ; - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); - List options = new ArrayList<>(); - options.add("SellingItems"); - options.add("Cancelled/ExpiredItems"); - options.add("PreviousPage"); - options.add("Refesh"); - options.add("NextPage"); - options.add("Category1"); - options.add("Category2"); - if (sell == ShopType.SELL) { - shopType.put(player, ShopType.SELL); - if (crazyAuctions.isBiddingEnabled()) { - options.add("Bidding/Selling.Selling"); - } - options.add("WhatIsThis.SellingShop"); - } - if (sell == ShopType.BID) { - shopType.put(player, ShopType.BID); - if (crazyAuctions.isSellingEnabled()) { - options.add("Bidding/Selling.Bidding"); - } - options.add("WhatIsThis.BiddingShop"); - } - for (String o : options) { - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - continue; - } - } - String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); - String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); - List lore = new ArrayList<>(); - int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); - String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + shopCategory.get(player).getName() + ".Name")); - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - for (String l : config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - lore.add(l.replace("%Category%", cName).replace("%category%", cName)); - } - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, lore)); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); - } - } - for (ItemStack item : Methods.getPage(items, page)) { - int slot = inv.firstEmpty(); - inv.setItem(slot, item); - } - List Id = new ArrayList<>(Methods.getPageInts(ID, page)); - List.put(player, Id); - player.openInventory(inv); - } - - public static void openCategories(Player player, ShopType shop) { - Methods.updateAuction(); - FileConfiguration config = Files.CONFIG.getFile(); - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Categories"))); - List options = new ArrayList<>(); - options.add("OtherSettings.Back"); - options.add("OtherSettings.WhatIsThis.Categories"); - options.add("Category-Settings.Armor"); - options.add("Category-Settings.Weapons"); - options.add("Category-Settings.Tools"); - options.add("Category-Settings.Food"); - options.add("Category-Settings.Potions"); - options.add("Category-Settings.Blocks"); - options.add("Category-Settings.Other"); - options.add("Category-Settings.None"); - for (String o : options) { - if (config.contains("Settings.GUISettings." + o + ".Toggle")) { - if (!config.getBoolean("Settings.GUISettings." + o + ".Toggle")) { - continue; - } - } - String id = config.getString("Settings.GUISettings." + o + ".Item"); - String name = config.getString("Settings.GUISettings." + o + ".Name"); - int slot = config.getInt("Settings.GUISettings." + o + ".Slot"); - if (config.contains("Settings.GUISettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); - } - } - shopType.put(player, shop); - player.openInventory(inv); - } - - public static void openPlayersCurrentList(Player player, int page) { - Methods.updateAuction(); - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - List items = new ArrayList<>(); - List ID = new ArrayList<>(); - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items"))); - List options = new ArrayList<>(); - options.add("Back"); - options.add("WhatIsThis.CurrentItems"); - for (String o : options) { - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - continue; - } - } - String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); - String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); - int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); - } - } - if (data.contains("Items")) { - for (String i : data.getConfigurationSection("Items").getKeys(false)) { - if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { - List lore = new ArrayList<>(); - for (String l : config.getStringList("Settings.GUISettings.CurrentLore")) { - lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); - } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); - ID.add(data.getInt("Items." + i + ".StoreID")); - } - } - } - for (ItemStack item : Methods.getPage(items, page)) { - int slot = inv.firstEmpty(); - inv.setItem(slot, item); - } - List Id = new ArrayList<>(Methods.getPageInts(ID, page)); - List.put(player, Id); - player.openInventory(inv); - } - - public static void openPlayersExpiredList(Player player, int page) { - Methods.updateAuction(); - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - List items = new ArrayList<>(); - List ID = new ArrayList<>(); - if (data.contains("OutOfTime/Cancelled")) { - for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { - if (data.getString("OutOfTime/Cancelled." + i + ".Seller") != null) { - if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) { - List lore = new ArrayList<>(); - for (String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) { - lore.add(l.replace("%Price%", Methods.getPrice(i, true)).replace("%price%", Methods.getPrice(i, true)).replace("%Time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"))).replace("%time%", Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time")))); - } - items.add(Methods.addLore(data.getItemStack("OutOfTime/Cancelled." + i + ".Item").clone(), lore)); - ID.add(data.getInt("OutOfTime/Cancelled." + i + ".StoreID")); - } - } - } - } - int maxPage = Methods.getMaxPage(items); - for (; page > maxPage; page--) ; - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page)); - List options = new ArrayList<>(); - options.add("Back"); - options.add("PreviousPage"); - options.add("Return"); - options.add("NextPage"); - options.add("WhatIsThis.Cancelled/ExpiredItems"); - for (String o : options) { - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - continue; - } - } - String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); - String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); - int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); - } - } - for (ItemStack item : Methods.getPage(items, page)) { - int slot = inv.firstEmpty(); - inv.setItem(slot, item); - } - List Id = new ArrayList<>(Methods.getPageInts(ID, page)); - List.put(player, Id); - player.openInventory(inv); - } - - public static void openBuying(Player player, String ID) { - Methods.updateAuction(); - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - if (!data.contains("Items." + ID)) { - openShop(player, ShopType.SELL, shopCategory.get(player), 1); - player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); - return; - } - Inventory inv = Bukkit.createInventory(null, 9, Methods.color(config.getString("Settings.Buying-Item"))); - List options = new ArrayList<>(); - options.add("Confirm"); - options.add("Cancel"); - for (String o : options) { - String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); - String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); - ItemStack item; - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - item = Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")); - } else { - item = Methods.makeItem(id, 1, name); - } - if (o.equals("Confirm")) { - inv.setItem(0, item); - inv.setItem(1, item); - inv.setItem(2, item); - inv.setItem(3, item); - } - if (o.equals("Cancel")) { - inv.setItem(5, item); - inv.setItem(6, item); - inv.setItem(7, item); - inv.setItem(8, item); - } - } - ItemStack item = data.getItemStack("Items." + ID + ".Item"); - List lore = new ArrayList<>(); - for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { - lore.add(l.replace("%Price%", Methods.getPrice(ID, false)).replace("%price%", Methods.getPrice(ID, false)).replace("%Seller%", data.getString("Items." + ID + ".Seller")).replace("%seller%", data.getString("Items." + ID + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + l + ".Time-Till-Expire")))); - } - inv.setItem(4, Methods.addLore(item.clone(), lore)); - IDs.put(player, ID); - player.openInventory(inv); - } - - public static void openBidding(Player player, String ID) { - Methods.updateAuction(); - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - if (!data.contains("Items." + ID)) { - openShop(player, ShopType.BID, shopCategory.get(player), 1); - player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); - return; - } - Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); - if (!bidding.containsKey(player)) bidding.put(player, 0); - if (Version.isNewer(Version.v1_12_R1)) { - inv.setItem(9, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1")); - inv.setItem(10, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+10")); - inv.setItem(11, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+100")); - inv.setItem(12, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1000")); - inv.setItem(14, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1000")); - inv.setItem(15, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-100")); - inv.setItem(16, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-10")); - inv.setItem(17, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1")); - } else { - inv.setItem(9, Methods.makeItem("160:5", 1, "&a+1")); - inv.setItem(10, Methods.makeItem("160:5", 1, "&a+10")); - inv.setItem(11, Methods.makeItem("160:5", 1, "&a+100")); - inv.setItem(12, Methods.makeItem("160:5", 1, "&a+1000")); - inv.setItem(14, Methods.makeItem("160:14", 1, "&c-1000")); - inv.setItem(15, Methods.makeItem("160:14", 1, "&c-100")); - inv.setItem(16, Methods.makeItem("160:14", 1, "&c-10")); - inv.setItem(17, Methods.makeItem("160:14", 1, "&c-1")); - } - inv.setItem(13, getBiddingGlass(player, ID)); - inv.setItem(22, Methods.makeItem(config.getString("Settings.GUISettings.OtherSettings.Bid.Item"), 1, config.getString("Settings.GUISettings.OtherSettings.Bid.Name"), config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore"))); - - inv.setItem(4, getBiddingItem(player, ID)); - player.openInventory(inv); - } - - public static void openViewer(Player player, String other, int page) { - Methods.updateAuction(); - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - List items = new ArrayList<>(); - List ID = new ArrayList<>(); - if (!data.contains("Items")) { - data.set("Items.Clear", null); - Files.DATA.saveFile(); - } - if (data.contains("Items")) { - for (String i : data.getConfigurationSection("Items").getKeys(false)) { - if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(other)) { - List lore = new ArrayList<>(); - if (data.getBoolean("Items." + i + ".Biddable")) { - String seller = data.getString("Items." + i + ".Seller"); - String topbidder = data.getString("Items." + i + ".TopBidder"); - for (String l : config.getStringList("Settings.GUISettings.Bidding")) { - lore.add(l.replace("%TopBid%", Methods.getPrice(i, false)).replace("%topbid%", Methods.getPrice(i, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); - } - } else { - for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) { - lore.add(l.replace("%Price%", Methods.getPrice(i, false)).replace("%price%", Methods.getPrice(i, false)).replace("%Seller%", data.getString("Items." + i + ".Seller")).replace("%seller%", data.getString("Items." + i + ".Seller")).replace("%Time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire")))); - } - } - items.add(Methods.addLore(data.getItemStack("Items." + i + ".Item").clone(), lore)); - ID.add(data.getInt("Items." + i + ".StoreID")); - } - } - } - int maxPage = Methods.getMaxPage(items); - for (; page > maxPage; page--) ; - Inventory inv = Bukkit.createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page)); - List options = new ArrayList<>(); - options.add("WhatIsThis.Viewing"); - for (String o : options) { - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) { - continue; - } - } - String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item"); - String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name"); - int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot"); - if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name, config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"))); - } else { - inv.setItem(slot - 1, Methods.makeItem(id, 1, name)); - } - } - for (ItemStack item : Methods.getPage(items, page)) { - int slot = inv.firstEmpty(); - inv.setItem(slot, item); - } - List.put(player, new ArrayList<>(Methods.getPageInts(ID, page))); - player.openInventory(inv); - } - - public static ItemStack getBiddingGlass(Player player, String ID) { - FileConfiguration config = Files.CONFIG.getFile(); - String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item"); - String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name"); - ItemStack item; - int bid = bidding.get(player); - if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) { - List lore = new ArrayList<>(); - for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) { - lore.add(l.replace("%Bid%", bid + "").replace("%bid%", bid + "").replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false))); - } - item = Methods.makeItem(id, 1, name, lore); - } else { - item = Methods.makeItem(id, 1, name); - } - return item; - } - - public static ItemStack getBiddingItem(Player player, String ID) { - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - String seller = data.getString("Items." + ID + ".Seller"); - String topbidder = data.getString("Items." + ID + ".TopBidder"); - ItemStack item = data.getItemStack("Items." + ID + ".Item"); - List lore = new ArrayList<>(); - for (String l : config.getStringList("Settings.GUISettings.Bidding")) { - lore.add(l.replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false)).replace("%Seller%", seller).replace("%seller%", seller).replace("%TopBidder%", topbidder).replace("%topbidder%", topbidder).replace("%Time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire"))).replace("%time%", Methods.convertToTime(data.getLong("Items." + ID + ".Time-Till-Expire")))); - } - return Methods.addLore(item.clone(), lore); - } - - private static void playClick(Player player) { - if (Files.CONFIG.getFile().contains("Settings.Sounds.Toggle")) { - if (Files.CONFIG.getFile().getBoolean("Settings.Sounds.Toggle")) { - String sound = Files.CONFIG.getFile().getString("Settings.Sounds.Sound"); - try { - player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1); - } catch (Exception e) { - if (Methods.getVersion() >= 191) { - player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1); - } else { - player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1); - } - Bukkit.getLogger().log(Level.WARNING, "[Crazy Auctions]>> You set the sound to " + sound + " and this is not a sound for your minecraft version. " + "Please go to the config and set a correct sound or turn the sound off in the toggle setting."); - } - } - } else { - if (Methods.getVersion() >= 191) { - player.playSound(player.getLocation(), Sound.valueOf("UI_BUTTON_CLICK"), 1, 1); - } else { - player.playSound(player.getLocation(), Sound.valueOf("CLICK"), 1, 1); - } - } - } - - @EventHandler - public void onInvClose(InventoryCloseEvent e) { - FileConfiguration config = Files.CONFIG.getFile(); - Inventory inv = e.getInventory(); - Player player = (Player) e.getPlayer(); - if (inv != null) { - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) { - bidding.remove(player); - } - } - } - - @EventHandler - public void onInvClick(InventoryClickEvent e) { - FileConfiguration config = Files.CONFIG.getFile(); - FileConfiguration data = Files.DATA.getFile(); - Player player = (Player) e.getWhoClicked(); - final Inventory inv = e.getInventory(); - if (inv != null) { - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Categories")))) { - e.setCancelled(true); - int slot = e.getRawSlot(); - if (slot <= inv.getSize()) { - if (e.getCurrentItem() != null) { - ItemStack item = e.getCurrentItem(); - if (item.hasItemMeta()) { - if (item.getItemMeta().hasDisplayName()) { - for (Category cat : Category.values()) { - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) { - openShop(player, shopType.get(player), cat, 1); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { - openShop(player, shopType.get(player), shopCategory.get(player), 1); - playClick(player); - return; - } - } - } - } - } - } - } - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) { - e.setCancelled(true); - int slot = e.getRawSlot(); - if (slot <= inv.getSize()) { - if (e.getCurrentItem() != null) { - ItemStack item = e.getCurrentItem(); - if (item.hasItemMeta()) { - if (item.getItemMeta().hasDisplayName()) { - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))) { - String ID = biddingID.get(player); - int bid = bidding.get(player); - String topBidder = data.getString("Items." + ID + ".TopBidder"); - if (CurrencyManager.getMoney(player) < bid) { - HashMap placeholders = new HashMap<>(); - placeholders.put("%Money_Needed%", (bid - CurrencyManager.getMoney(player)) + ""); - placeholders.put("%money_needed%", (bid - CurrencyManager.getMoney(player)) + ""); - player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); - return; - } - if (data.getLong("Items." + ID + ".Price") > bid) { - player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); - return; - } - if (data.getLong("Items." + ID + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) { - player.sendMessage(Messages.BID_MORE_MONEY.getMessage()); - return; - } - Bukkit.getPluginManager().callEvent(new AuctionNewBidEvent(player, data.getItemStack("Items." + ID + ".Item"), bid)); - data.set("Items." + ID + ".Price", bid); - data.set("Items." + ID + ".TopBidder", player.getName()); - HashMap placeholders = new HashMap<>(); - placeholders.put("%Bid%", bid + ""); - player.sendMessage(Messages.BID_MESSAGE.getMessage(placeholders)); - Files.DATA.saveFile(); - bidding.put(player, 0); - player.closeInventory(); - playClick(player); - return; - } - HashMap priceEdits = new HashMap<>(); - priceEdits.put("&a+1", 1); - priceEdits.put("&a+10", 10); - priceEdits.put("&a+100", 100); - priceEdits.put("&a+1000", 1000); - priceEdits.put("&c-1", -1); - priceEdits.put("&c-10", -10); - priceEdits.put("&c-100", -100); - priceEdits.put("&c-1000", -1000); - for (String price : priceEdits.keySet()) { - if (item.getItemMeta().getDisplayName().equals(Methods.color(price))) { - try { - bidding.put(player, (bidding.get(player) + priceEdits.get(price))); - inv.setItem(4, getBiddingItem(player, biddingID.get(player))); - inv.setItem(13, getBiddingGlass(player, biddingID.get(player))); - playClick(player); - return; - } catch (Exception ex) { - player.closeInventory(); - player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); - return; - } - } - } - } - } - } - } - } - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.GUIName")))) { - e.setCancelled(true); - final int slot = e.getRawSlot(); - if (slot <= inv.getSize()) { - if (e.getCurrentItem() != null) { - final ItemStack item = e.getCurrentItem(); - if (item.hasItemMeta()) { - if (item.getItemMeta().hasDisplayName()) { - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { - Methods.updateAuction(); - int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - openShop(player, shopType.get(player), shopCategory.get(player), page + 1); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { - Methods.updateAuction(); - int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - if (page == 1) page++; - openShop(player, shopType.get(player), shopCategory.get(player), page - 1); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name")))) { - Methods.updateAuction(); - int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - openShop(player, shopType.get(player), shopCategory.get(player), page); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name")))) { - openShop(player, ShopType.BID, shopCategory.get(player), 1); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name")))) { - openShop(player, ShopType.SELL, shopCategory.get(player), 1); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name")))) { - openPlayersExpiredList(player, 1); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name")))) { - openPlayersCurrentList(player, 1); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category1.Name")))) { - openCategories(player, shopType.get(player)); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Category2.Name")))) { - openCategories(player, shopType.get(player)); - playClick(player); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name")))) { - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name")))) { - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name")))) { - return; - } - } - if (List.containsKey(player)) { - if (List.get(player).size() >= slot) { - int id = List.get(player).get(slot); - boolean T = false; - if (data.contains("Items")) { - for (String i : data.getConfigurationSection("Items").getKeys(false)) { - int ID = data.getInt("Items." + i + ".StoreID"); - if (id == ID) { - if (player.hasPermission("crazyAuctions.admin") || player.hasPermission("crazyauctions.force-end")) { - if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { - int num = 1; - for (; data.contains("OutOfTime/Cancelled." + num); num++) ; - String seller = data.getString("Items." + i + ".Seller"); - Player sellerPlayer = Methods.getPlayer(seller); - if (Methods.isOnline(seller) && sellerPlayer != null) { - sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage()); - } - AuctionCancelledEvent event = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Bukkit.getOfflinePlayer(seller)), data.getItemStack("Items." + i + ".Item"), CancelledReason.ADMIN_FORCE_CANCEL); - Bukkit.getPluginManager().callEvent(event); - data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); - data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time")); - data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); - data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); - data.set("Items." + i, null); - Files.DATA.saveFile(); - player.sendMessage(Messages.ADMIN_FORCE_CENCELLED.getMessage()); - playClick(player); - int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - openShop(player, shopType.get(player), shopCategory.get(player), page); - return; - } - } - final Runnable runnable = () -> inv.setItem(slot, item); - if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getName())) { - String it = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item"); - String name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name"); - ItemStack I; - if (config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")) { - I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore")); - } else { - I = Methods.makeItem(it, 1, name); - } - inv.setItem(slot, I); - playClick(player); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); - return; - } - long cost = data.getLong("Items." + i + ".Price"); - if (CurrencyManager.getMoney(player) < cost) { - String it = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item"); - String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name"); - ItemStack I; - if (config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")) { - I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")); - } else { - I = Methods.makeItem(it, 1, name); - } - inv.setItem(slot, I); - playClick(player); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); - return; - } - if (data.getBoolean("Items." + i + ".Biddable")) { - if (player.getName().equalsIgnoreCase(data.getString("Items." + i + ".TopBidder"))) { - String it = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item"); - String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name"); - ItemStack I; - if (config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")) { - I = Methods.makeItem(it, 1, name, config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")); - } else { - I = Methods.makeItem(it, 1, name); - } - inv.setItem(slot, I); - playClick(player); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, runnable, 3 * 20); - return; - } - playClick(player); - openBidding(player, i); - biddingID.put(player, i); - } else { - playClick(player); - openBuying(player, i); - } - return; - } - } - } - if (!T) { - playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); - player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); - return; - } - } - } - } - } - } - } - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Buying-Item")))) { - e.setCancelled(true); - int slot = e.getRawSlot(); - if (slot <= inv.getSize()) { - if (e.getCurrentItem() != null) { - ItemStack item = e.getCurrentItem(); - if (item.hasItemMeta()) { - if (item.getItemMeta().hasDisplayName()) { - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))) { - String ID = IDs.get(player); - long cost = data.getLong("Items." + ID + ".Price"); - String seller = data.getString("Items." + ID + ".Seller"); - if (!data.contains("Items." + ID)) { - playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); - player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); - return; - } - if (Methods.isInvFull(player)) { - playClick(player); - player.closeInventory(); - player.sendMessage(Messages.INVENTORY_FULL.getMessage()); - return; - } - if (CurrencyManager.getMoney(player) < cost) { - playClick(player); - player.closeInventory(); - HashMap placeholders = new HashMap<>(); - placeholders.put("%Money_Needed%", (cost - CurrencyManager.getMoney(player)) + ""); - placeholders.put("%money_needed%", (cost - CurrencyManager.getMoney(player)) + ""); - player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(placeholders)); - return; - } - ItemStack i = data.getItemStack("Items." + ID + ".Item"); - Bukkit.getPluginManager().callEvent(new AuctionBuyEvent(player, i, cost)); - CurrencyManager.removeMoney(player, cost); - CurrencyManager.addMoney(Methods.getOfflinePlayer(seller), cost); - HashMap placeholders = new HashMap<>(); - placeholders.put("%Price%", Methods.getPrice(ID, false)); - placeholders.put("%price%", Methods.getPrice(ID, false)); - placeholders.put("%Player%", player.getName()); - placeholders.put("%player%", player.getName()); - player.sendMessage(Messages.BOUGHT_ITEM.getMessage(placeholders)); - if (Methods.isOnline(seller) && Methods.getPlayer(seller) != null) { - Player sell = Methods.getPlayer(seller); - sell.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(placeholders)); - } - player.getInventory().addItem(i); - data.set("Items." + ID, null); - Files.DATA.saveFile(); - playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))) { - openShop(player, shopType.get(player), shopCategory.get(player), 1); - playClick(player); - return; - } - } - } - } - } - } - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Players-Current-Items")))) { - e.setCancelled(true); - int slot = e.getRawSlot(); - if (slot <= inv.getSize()) { - if (e.getCurrentItem() != null) { - ItemStack item = e.getCurrentItem(); - if (item.hasItemMeta()) { - if (item.getItemMeta().hasDisplayName()) { - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { - openShop(player, shopType.get(player), shopCategory.get(player), 1); - playClick(player); - return; - } - } - if (List.containsKey(player)) { - if (List.get(player).size() >= slot) { - int id = List.get(player).get(slot); - boolean T = false; - if (data.contains("Items")) { - for (String i : data.getConfigurationSection("Items").getKeys(false)) { - int ID = data.getInt("Items." + i + ".StoreID"); - if (id == ID) { - player.sendMessage(Messages.CANCELLED_ITEM.getMessage()); - AuctionCancelledEvent event = new AuctionCancelledEvent(player, data.getItemStack("Items." + i + ".Item"), CancelledReason.PLAYER_FORCE_CANCEL); - Bukkit.getPluginManager().callEvent(event); - int num = 1; - for (; data.contains("OutOfTime/Cancelled." + num); num++) ; - data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller")); - data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time")); - data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID")); - data.set("OutOfTime/Cancelled." + num + ".Item", data.getItemStack("Items." + i + ".Item")); - data.set("Items." + i, null); - Files.DATA.saveFile(); - playClick(player); - openPlayersCurrentList(player, 1); - return; - } - } - } - if (!T) { - playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); - player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); - return; - } - } - } - } - } - } - } - if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))) { - e.setCancelled(true); - final int slot = e.getRawSlot(); - if (slot <= inv.getSize()) { - if (e.getCurrentItem() != null) { - final ItemStack item = e.getCurrentItem(); - if (item.hasItemMeta()) { - if (item.getItemMeta().hasDisplayName()) { - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) { - Methods.updateAuction(); - playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) { - Methods.updateAuction(); - int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - if (page == 1) page++; - playClick(player); - openPlayersExpiredList(player, (page - 1)); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) { - Methods.updateAuction(); - int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - if (data.contains("OutOfTime/Cancelled")) { - for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { - if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getName())) { - if (Methods.isInvFull(player)) { - player.sendMessage(Messages.INVENTORY_FULL.getMessage()); - break; - } else { - player.getInventory().addItem(data.getItemStack("OutOfTime/Cancelled." + i + ".Item")); - data.set("OutOfTime/Cancelled." + i, null); - } - } - } - } - player.sendMessage(Messages.GOT_ITEM_BACK.getMessage()); - Files.DATA.saveFile(); - playClick(player); - openPlayersExpiredList(player, page); - return; - } - if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) { - Methods.updateAuction(); - int page = Integer.parseInt(e.getView().getTitle().split("#")[1]); - playClick(player); - openPlayersExpiredList(player, (page + 1)); - return; - } - } - if (List.containsKey(player)) { - if (List.get(player).size() >= slot) { - int id = List.get(player).get(slot); - boolean T = false; - if (data.contains("OutOfTime/Cancelled")) { - for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) { - int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID"); - if (id == ID) { - if (!Methods.isInvFull(player)) { - player.sendMessage(Messages.GOT_ITEM_BACK.getMessage()); - ItemStack IT = data.getItemStack("OutOfTime/Cancelled." + i + ".Item"); - player.getInventory().addItem(IT); - data.set("OutOfTime/Cancelled." + i, null); - Files.DATA.saveFile(); - playClick(player); - openPlayersExpiredList(player, 1); - } else { - player.sendMessage(Messages.INVENTORY_FULL.getMessage()); - } - return; - } - } - } - if (!T) { - playClick(player); - openShop(player, shopType.get(player), shopCategory.get(player), 1); - player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); - } - } - } - } - } - } - } - } - } - -} diff --git a/src/main/java/com/badbones69/crazyauctions/controllers/Metrics.java b/src/main/java/com/badbones69/crazyauctions/controllers/Metrics.java deleted file mode 100644 index 4a908a0..0000000 --- a/src/main/java/com/badbones69/crazyauctions/controllers/Metrics.java +++ /dev/null @@ -1,727 +0,0 @@ -package com.badbones69.crazyauctions.controllers; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.ServicePriority; - -import javax.net.ssl.HttpsURLConnection; -import java.io.*; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.concurrent.Callable; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; - -/** - * bStats collects some data for plugin authors. - *

- * Check out https://bStats.org/ to learn more about bStats! - */ -public class Metrics { - - static { - // You can use the property to disable the check in your test environment - if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) { - // Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D - final String defaultPackage = new String( - new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'}); - final String examplePackage = new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); - // We want to make sure nobody just copy & pastes the example and use the wrong package names - if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) { - throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); - } - } - } - - // The version of this bStats class - public static final int B_STATS_VERSION = 1; - - // The url to which the data is sent - private static final String URL = "https://bStats.org/submitData/bukkit"; - - // Is bStats enabled on this server? - private boolean enabled; - - // Should failed requests be logged? - private static boolean logFailedRequests; - - // Should the sent data be logged? - private static boolean logSentData; - - // Should the response text be logged? - private static boolean logResponseStatusText; - - // The uuid of the server - private static String serverUUID; - - // The plugin - private final Plugin plugin; - - // The plugin id - private final int pluginId; - - // A list with all custom charts - private final List charts = new ArrayList<>(); - - /** - * Class constructor. - * - * @param plugin The plugin which stats should be submitted. - * @param pluginId The id of the plugin. - * It can be found at What is my plugin id? - */ - public Metrics(Plugin plugin, int pluginId) { - if (plugin == null) { - throw new IllegalArgumentException("Plugin cannot be null!"); - } - this.plugin = plugin; - this.pluginId = pluginId; - - // Get the config file - File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); - File configFile = new File(bStatsFolder, "config.yml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); - - // Check if the config file exists - if (!config.isSet("serverUuid")) { - - // Add default values - config.addDefault("enabled", true); - // Every server gets it's unique random id. - config.addDefault("serverUuid", UUID.randomUUID().toString()); - // Should failed request be logged? - config.addDefault("logFailedRequests", false); - // Should the sent data be logged? - config.addDefault("logSentData", false); - // Should the response text be logged? - config.addDefault("logResponseStatusText", false); - - // Inform the server owners about bStats - config.options().header( - "bStats collects some data for plugin authors like how many servers are using their plugins.\n" + - "To honor their work, you should not disable it.\n" + - "This has nearly no effect on the server performance!\n" + - "Check out https://bStats.org/ to learn more :)" - ).copyDefaults(true); - try { - config.save(configFile); - } catch (IOException ignored) { - } - } - - // Load the data - enabled = config.getBoolean("enabled", true); - serverUUID = config.getString("serverUuid"); - logFailedRequests = config.getBoolean("logFailedRequests", false); - logSentData = config.getBoolean("logSentData", false); - logResponseStatusText = config.getBoolean("logResponseStatusText", false); - - if (enabled) { - boolean found = false; - // Search for all other bStats Metrics classes to see if we are the first one - for (Class service : Bukkit.getServicesManager().getKnownServices()) { - try { - service.getField("B_STATS_VERSION"); // Our identifier :) - found = true; // We aren't the first - break; - } catch (NoSuchFieldException ignored) { - } - } - // Register our service - Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); - if (!found) { - // We are the first! - startSubmitting(); - } - } - } - - /** - * Checks if bStats is enabled. - * - * @return Whether bStats is enabled or not. - */ - public boolean isEnabled() { - return enabled; - } - - /** - * Adds a custom chart. - * - * @param chart The chart to add. - */ - public void addCustomChart(CustomChart chart) { - if (chart == null) { - throw new IllegalArgumentException("Chart cannot be null!"); - } - charts.add(chart); - } - - /** - * Starts the Scheduler which submits our data every 30 minutes. - */ - private void startSubmitting() { - final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - if (!plugin.isEnabled()) { // Plugin was disabled - timer.cancel(); - return; - } - // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler - // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, () -> submitData()); - } - }, 1000 * 60 * 5, 1000 * 60 * 30); - // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start - // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! - // WARNING: Just don't do it! - } - - /** - * Gets the plugin specific data. - * This method is called using Reflection. - * - * @return The plugin specific data. - */ - public JsonObject getPluginData() { - JsonObject data = new JsonObject(); - - String pluginName = plugin.getDescription().getName(); - String pluginVersion = plugin.getDescription().getVersion(); - - data.addProperty("pluginName", pluginName); // Append the name of the plugin - data.addProperty("id", pluginId); // Append the id of the plugin - data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin - JsonArray customCharts = new JsonArray(); - for (CustomChart customChart : charts) { - // Add the data of the custom charts - JsonObject chart = customChart.getRequestJsonObject(); - if (chart == null) { // If the chart is null, we skip it - continue; - } - customCharts.add(chart); - } - data.add("customCharts", customCharts); - - return data; - } - - /** - * Gets the server specific data. - * - * @return The server specific data. - */ - private JsonObject getServerData() { - // Minecraft specific data - int playerAmount; - try { - // Around MC 1.8 the return type was changed to a collection from an array, - // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); - playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) - ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() - : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; - } catch (Exception e) { - playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed - } - int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; - String bukkitVersion = Bukkit.getVersion(); - String bukkitName = Bukkit.getName(); - - // OS/Java specific data - String javaVersion = System.getProperty("java.version"); - String osName = System.getProperty("os.name"); - String osArch = System.getProperty("os.arch"); - String osVersion = System.getProperty("os.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - JsonObject data = new JsonObject(); - - data.addProperty("serverUUID", serverUUID); - - data.addProperty("playerAmount", playerAmount); - data.addProperty("onlineMode", onlineMode); - data.addProperty("bukkitVersion", bukkitVersion); - data.addProperty("bukkitName", bukkitName); - - data.addProperty("javaVersion", javaVersion); - data.addProperty("osName", osName); - data.addProperty("osArch", osArch); - data.addProperty("osVersion", osVersion); - data.addProperty("coreCount", coreCount); - - return data; - } - - /** - * Collects the data and sends it afterwards. - */ - private void submitData() { - final JsonObject data = getServerData(); - - JsonArray pluginData = new JsonArray(); - // Search for all other bStats Metrics classes to get their plugin data - for (Class service : Bukkit.getServicesManager().getKnownServices()) { - try { - service.getField("B_STATS_VERSION"); // Our identifier :) - - for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { - try { - Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider()); - if (plugin instanceof JsonObject) { - pluginData.add((JsonObject) plugin); - } else { // old bstats version compatibility - try { - Class jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject"); - if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) { - Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString"); - jsonStringGetter.setAccessible(true); - String jsonString = (String) jsonStringGetter.invoke(plugin); - JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); - pluginData.add(object); - } - } catch (ClassNotFoundException e) { - // minecraft version 1.14+ - if (logFailedRequests) { - this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e); - } - } - } - } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { - } - } - } catch (NoSuchFieldException ignored) { - } - } - - data.add("plugins", pluginData); - - // Create a new thread for the connection to the bStats server - new Thread(() -> { - try { - // Send the data - sendData(plugin, data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); - } - } - }).start(); - } - - /** - * Sends the data to the bStats server. - * - * @param plugin Any plugin. It's just used to get a logger instance. - * @param data The data to send. - * @throws Exception If the request failed. - */ - private static void sendData(Plugin plugin, JsonObject data) throws Exception { - if (data == null) { - throw new IllegalArgumentException("Data cannot be null!"); - } - if (Bukkit.isPrimaryThread()) { - throw new IllegalAccessException("This method must not be called from the main thread!"); - } - if (logSentData) { - plugin.getLogger().info("Sending data to bStats: " + data); - } - HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); - - // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); - - // Add headers - connection.setRequestMethod("POST"); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request - connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length)); - connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format - connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION); - - // Send data - connection.setDoOutput(true); - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { - outputStream.write(compressedData); - } - - StringBuilder builder = new StringBuilder(); - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { - String line; - while ((line = bufferedReader.readLine()) != null) { - builder.append(line); - } - } - - if (logResponseStatusText) { - plugin.getLogger().info("Sent data to bStats and received response: " + builder); - } - } - - /** - * Gzips the given String. - * - * @param str The string to gzip. - * @return The gzipped String. - * @throws IOException If the compression failed. - */ - private static byte[] compress(final String str) throws IOException { - if (str == null) { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - } - return outputStream.toByteArray(); - } - - /** - * Represents a custom chart. - */ - public static abstract class CustomChart { - - // The id of the chart - final String chartId; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - */ - CustomChart(String chartId) { - if (chartId == null || chartId.isEmpty()) { - throw new IllegalArgumentException("ChartId cannot be null or empty!"); - } - this.chartId = chartId; - } - - private JsonObject getRequestJsonObject() { - JsonObject chart = new JsonObject(); - chart.addProperty("chartId", chartId); - try { - JsonObject data = getChartData(); - if (data == null) { - // If the data is null we don't send the chart. - return null; - } - chart.add("data", data); - } catch (Throwable t) { - if (logFailedRequests) { - Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); - } - return null; - } - return chart; - } - - protected abstract JsonObject getChartData() throws Exception; - - } - - /** - * Represents a custom simple pie. - */ - public static class SimplePie extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimplePie(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - String value = callable.call(); - if (value == null || value.isEmpty()) { - // Null = skip the chart - return null; - } - data.addProperty("value", value); - return data; - } - - } - - /** - * Represents a custom advanced pie. - */ - public static class AdvancedPie extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedPie(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.addProperty(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom drilldown pie. - */ - public static class DrilldownPie extends CustomChart { - - private final Callable>> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public DrilldownPie(String chartId, Callable>> callable) { - super(chartId); - this.callable = callable; - } - - @Override - public JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map> map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { - JsonObject value = new JsonObject(); - boolean allSkipped = true; - for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { - value.addProperty(valueEntry.getKey(), valueEntry.getValue()); - allSkipped = false; - } - if (!allSkipped) { - reallyAllSkipped = false; - values.add(entryValues.getKey(), value); - } - } - if (reallyAllSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom single line chart. - */ - public static class SingleLineChart extends CustomChart { - - private final Callable callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SingleLineChart(String chartId, Callable callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - int value = callable.call(); - if (value == 0) { - // Null = skip the chart - return null; - } - data.addProperty("value", value); - return data; - } - - } - - /** - * Represents a custom multi line chart. - */ - public static class MultiLineChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public MultiLineChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.addProperty(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom simple bar chart. - */ - public static class SimpleBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimpleBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - for (Map.Entry entry : map.entrySet()) { - JsonArray categoryValues = new JsonArray(); - categoryValues.add(new JsonPrimitive(entry.getValue())); - values.add(entry.getKey(), categoryValues); - } - data.add("values", values); - return data; - } - - } - - /** - * Represents a custom advanced bar chart. - */ - public static class AdvancedBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue().length == 0) { - continue; // Skip this invalid - } - allSkipped = false; - JsonArray categoryValues = new JsonArray(); - for (int categoryValue : entry.getValue()) { - categoryValues.add(new JsonPrimitive(categoryValue)); - } - values.add(entry.getKey(), categoryValues); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.add("values", values); - return data; - } - - } - -} \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java b/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java deleted file mode 100644 index 1347974..0000000 --- a/src/main/java/com/badbones69/crazyauctions/currency/CurrencyManager.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.badbones69.crazyauctions.currency; - -import com.badbones69.crazyauctions.api.FileManager.Files; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -public enum CurrencyManager { // Currency Manager - - VAULT("Vault", "Money"); - - private final String pluginName; - private final String name; - - /** - * @param pluginname - * name of the Plugin. - * @param name - * name of the Currency. - */ - private CurrencyManager(String pluginname, String name) { - this.pluginName = pluginname; - this.name = name; - } - - /** - * @param name - * name of the Type you want. - * @return Returns the Currency as a Enum. - */ - public static CurrencyManager getFromName(String name) { - for (CurrencyManager type : CurrencyManager.values()) { - if (type.getPluginName().equalsIgnoreCase(name)) { - return type; - } - } - return null; - } - - /** - * - * @param player - * Player you want the currency from. - * @return Returns the amount they have of the currency - */ - public static Long getMoney(Player player) { - return Vault.getMoney(player); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to take. - */ - public static void removeMoney(Player player, Long amount) { - Vault.removeMoney(player, amount); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to take. - */ - public static void removeMoney(OfflinePlayer player, Long amount) { - Vault.removeMoney(player, amount); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to add. - */ - public static void addMoney(Player player, Long amount) { - Vault.addMoney(player, amount); - } - - /** - * - * @param player - * Player you want the currency from. - * @param amount - * The amount you want to add. - */ - public static void addMoney(OfflinePlayer player, Long amount) { - Vault.addMoney(player, amount); - } - - /** - * @return Returns the Currency name as a string. - */ - public String getName() { - return name; - } - - /** - * @return Returns the Currency name as a string. - */ - public String getPluginName() { - return pluginName; - } - - /** - * - * @return Returns true if the server has the plugin. - */ - public Boolean hasPlugin() { - if (Bukkit.getServer().getPluginManager().getPlugin(pluginName) != null) { - return Files.CONFIG.getFile().getBoolean("Settings.Currencies." + pluginName + ".Enabled"); - } - return false; - } - -} \ No newline at end of file