From cd87b9baa94181530a28b13ab37f8eaf19750141 Mon Sep 17 00:00:00 2001 From: RandomHashTags Date: Sat, 29 Oct 2022 06:58:26 -0500 Subject: [PATCH] minor performance improvements --- .../tweetzy/auctionhouse/api/AuctionAPI.java | 28 +++++----- .../auctionhouse/api/DiscordWebhook.java | 3 +- .../auctionhouse/auction/AuctionPlayer.java | 19 ++++--- .../auction/AuctionStatistic.java | 5 +- .../auctionhouse/commands/CommandActive.java | 12 ++--- .../auctionhouse/commands/CommandAdmin.java | 45 ++++++++-------- .../commands/CommandAuctionHouse.java | 17 +++--- .../auctionhouse/commands/CommandBan.java | 23 ++++---- .../auctionhouse/commands/CommandExpired.java | 17 +++--- .../auctionhouse/commands/CommandFilter.java | 15 +++--- .../commands/CommandMarkChest.java | 7 +-- .../commands/CommandMiddleware.java | 7 +-- .../commands/CommandMinPrice.java | 19 +++---- .../auctionhouse/commands/CommandReload.java | 5 +- .../auctionhouse/commands/CommandSearch.java | 13 ++--- .../auctionhouse/commands/CommandSell.java | 51 +++++++++--------- .../auctionhouse/commands/CommandSellDev.java | 31 ++++++----- .../commands/CommandSettings.java | 3 +- .../auctionhouse/commands/CommandStats.java | 17 +++--- .../commands/CommandToggleListInfo.java | 16 +++--- .../commands/CommandTransactions.java | 7 +-- .../auctionhouse/commands/CommandUnban.java | 13 ++--- .../auctionhouse/commands/CommandUpload.java | 13 ++--- .../auctionhouse/database/DataManager.java | 7 +-- .../auctionhouse/guis/GUIMinItemPrices.java | 3 +- .../guis/statistics/GUIStatisticSelf.java | 13 ++--- .../guis/transaction/GUITransactionList.java | 7 +-- .../guis/transaction/GUITransactionType.java | 17 +++--- .../helpers/ConfigurationItemHelper.java | 2 +- .../helpers/MaterialCategorizer.java | 7 +-- .../listeners/AuctionListeners.java | 52 +++++++++++-------- .../listeners/PlayerListeners.java | 41 ++++++++------- .../managers/AuctionPlayerManager.java | 5 +- .../managers/AuctionStatisticManager.java | 16 +++--- .../auctionhouse/managers/SoundManager.java | 6 +-- .../auctionhouse/tasks/AutoSaveTask.java | 7 +-- .../auctionhouse/tasks/TickAuctionsTask.java | 41 ++++++++------- 37 files changed, 327 insertions(+), 283 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java index 3522bd7..e16c341 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java @@ -258,20 +258,20 @@ public class AuctionAPI { * @param isBid Is this auction a bid enabled auction, or a single sale auction? */ public void sendDiscordMessage(String webhook, OfflinePlayer seller, OfflinePlayer buyer, AuctionedItem auctionItem, AuctionSaleType saleType, boolean isNew, boolean isBid) { - DiscordWebhook hook = new DiscordWebhook(webhook); + final DiscordWebhook hook = new DiscordWebhook(webhook); hook.setUsername(Settings.DISCORD_MSG_USERNAME.getString()); hook.setAvatarUrl(Settings.DISCORD_MSG_PFP.getString()); - String color = isBid ? Settings.DISCORD_MSG_DEFAULT_COLOUR_BID.getString() : isNew ? Settings.DISCORD_MSG_DEFAULT_COLOUR.getString() : Settings.DISCORD_MSG_DEFAULT_COLOUR_SALE.getString(); + final String color = isBid ? Settings.DISCORD_MSG_DEFAULT_COLOUR_BID.getString() : isNew ? Settings.DISCORD_MSG_DEFAULT_COLOUR.getString() : Settings.DISCORD_MSG_DEFAULT_COLOUR_SALE.getString(); - String[] possibleColours = color.split("-"); - Color colour = Settings.DISCORD_MSG_USE_RANDOM_COLOUR.getBoolean() + final String[] possibleColours = color.split("-"); + final Color colour = Settings.DISCORD_MSG_USE_RANDOM_COLOUR.getBoolean() ? Color.getHSBColor(ThreadLocalRandom.current().nextFloat() * 360F, ThreadLocalRandom.current().nextFloat() * 101F, ThreadLocalRandom.current().nextFloat() * 101F) : Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100); - ItemStack itemStack = auctionItem.getItem(); - String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack)); - DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject(); + final ItemStack itemStack = auctionItem.getItem(); + final String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack)); + final DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject(); final String playerLost = AuctionHouse.getInstance().getLocale().getMessage("discord.player_lost").getMessage(); final String notSold = AuctionHouse.getInstance().getLocale().getMessage("discord.not_sold").getMessage(); @@ -311,19 +311,19 @@ public class AuctionAPI { */ public void sendDiscordBidMessage(String webhook, AuctionedItem auctionItem, double newBid) { // oh boy the code repetition is high with this one - DiscordWebhook hook = new DiscordWebhook(webhook); + final DiscordWebhook hook = new DiscordWebhook(webhook); hook.setUsername(Settings.DISCORD_MSG_USERNAME.getString()); hook.setAvatarUrl(Settings.DISCORD_MSG_PFP.getString()); - String[] possibleColours = Settings.DISCORD_MSG_DEFAULT_COLOUR_BID.getString().split("-"); - Color colour = Settings.DISCORD_MSG_USE_RANDOM_COLOUR.getBoolean() + final String[] possibleColours = Settings.DISCORD_MSG_DEFAULT_COLOUR_BID.getString().split("-"); + final Color colour = Settings.DISCORD_MSG_USE_RANDOM_COLOUR.getBoolean() ? Color.getHSBColor(ThreadLocalRandom.current().nextFloat() * 360F, ThreadLocalRandom.current().nextFloat() * 101F, ThreadLocalRandom.current().nextFloat() * 101F) : Color.getHSBColor(Float.parseFloat(possibleColours[0]) / 360, Float.parseFloat(possibleColours[1]) / 100, Float.parseFloat(possibleColours[2]) / 100); - ItemStack itemStack = auctionItem.getItem(); - String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack)); + final ItemStack itemStack = auctionItem.getItem(); + final String itemName = MMOItemsHook.isEnabled() ? MMOItemsHook.getItemType(itemStack) : ChatColor.stripColor(getItemName(itemStack)); - DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject(); + final DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject(); embedObject.setTitle(Settings.DISCORD_MSG_BID_TITLE.getString()); embedObject.setColor(colour); embedObject.addField(Settings.DISCORD_MSG_FIELD_BIDDER_NAME.getString(), Settings.DISCORD_MSG_FIELD_BIDDER_VALUE.getString().replace("%bidder%", auctionItem.getHighestBidderName() != null ? auctionItem.getHighestBidderName() : AuctionHouse.getInstance().getLocale().getMessage("discord.player_lost").getMessage()), Settings.DISCORD_MSG_FIELD_BIDDER_INLINE.getBoolean()); @@ -375,7 +375,7 @@ public class AuctionAPI { * @return a list of all the enchantment names */ public List getItemEnchantments(ItemStack stack) { - List enchantments = new ArrayList<>(); + final List enchantments = new ArrayList<>(); Objects.requireNonNull(stack, "Item Stack cannot be null when getting enchantments"); if (!stack.getEnchantments().isEmpty()) { stack.getEnchantments().forEach((k, i) -> { diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/DiscordWebhook.java b/src/main/java/ca/tweetzy/auctionhouse/api/DiscordWebhook.java index 6b73ff8..85ea184 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/DiscordWebhook.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/DiscordWebhook.java @@ -52,8 +52,7 @@ public class DiscordWebhook { throw new IllegalArgumentException("Set content or add at least one EmbedObject"); } - JSONObject json = new JSONObject(); - + final JSONObject json = new JSONObject(); json.put("content", this.content); json.put("username", this.username); json.put("avatar_url", this.avatarUrl); diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java index 781ffb9..dc80ff1 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java @@ -52,29 +52,28 @@ public class AuctionPlayer { if (Settings.LIST_ITEM_DELAY.getInt() == -1) { return true; } - + final AuctionHouse instance = AuctionHouse.getInstance(); if (this.lastListedItem == -1 || System.currentTimeMillis() >= this.lastListedItem) { this.lastListedItem = System.currentTimeMillis() + 1000L * Settings.LIST_ITEM_DELAY.getInt(); - AuctionHouse.getInstance().getDataManager().updateAuctionPlayer(this, (error, success) -> { + instance.getDataManager().updateAuctionPlayer(this, (error, success) -> { if (error == null && success) if (!Settings.DISABLE_PROFILE_UPDATE_MSG.getBoolean()) - AuctionHouse.getInstance().getLogger().info("Updating profile for player: " + player.getName()); + instance.getLogger().info("Updating profile for player: " + player.getName()); }); return true; } - AuctionHouse.getInstance().getLocale().getMessage("general.wait_to_list").processPlaceholder("time", (this.lastListedItem - System.currentTimeMillis()) / 1000).sendPrefixedMessage(this.player); - + instance.getLocale().getMessage("general.wait_to_list").processPlaceholder("time", (this.lastListedItem - System.currentTimeMillis()) / 1000).sendPrefixedMessage(this.player); return false; } public List getItems(boolean getExpired) { - List items = new ArrayList<>(); - - for (Map.Entry entry : AuctionHouse.getInstance().getAuctionItemManager().getItems().entrySet()) { - AuctionedItem auctionItem = entry.getValue(); - if (auctionItem.getOwner().equals(this.player.getUniqueId()) && auctionItem.isExpired() == getExpired && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getId())) { + final List items = new ArrayList<>(); + final AuctionHouse instance = AuctionHouse.getInstance(); + for (Map.Entry entry : instance.getAuctionItemManager().getItems().entrySet()) { + final AuctionedItem auctionItem = entry.getValue(); + if (auctionItem.getOwner().equals(this.player.getUniqueId()) && auctionItem.isExpired() == getExpired && !instance.getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getId())) { items.add(auctionItem); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionStatistic.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionStatistic.java index 50ae17e..f019bb4 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionStatistic.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionStatistic.java @@ -43,11 +43,12 @@ public final class AuctionStatistic implements Storeable { @Override public void store(Consumer stored) { - AuctionHouse.getInstance().getDataManager().insertStatistic(this, (error, statistic) -> { + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.getDataManager().insertStatistic(this, (error, statistic) -> { if (error != null) return; if (statistic != null) { - AuctionHouse.getInstance().getAuctionStatisticManager().addStatistic(statistic); + instance.getAuctionStatisticManager().addStatistic(statistic); if (stored != null) stored.accept(statistic); diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java index 3a1e192..3677c81 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java @@ -25,16 +25,16 @@ public class CommandActive extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + final AuctionHouse instance = AuctionHouse.getInstance(); + if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIActiveAuctions(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + instance.getGuiManager().showGUI(player, new GUIActiveAuctions(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()))); return ReturnType.SUCCESS; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAdmin.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAdmin.java index cdd0045..c405fb1 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAdmin.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAdmin.java @@ -41,16 +41,17 @@ public class CommandAdmin extends AbstractCommand { protected ReturnType runCommand(CommandSender sender, String... args) { if (args.length < 1) return ReturnType.FAILURE; if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE; - + + final AuctionHouse instance = AuctionHouse.getInstance(); switch (args[0].toLowerCase()) { case "logs": if (!(sender instanceof Player)) break; Player player = (Player) sender; if (!player.hasPermission("auctionhouse.cmd.admin.logs")) return ReturnType.FAILURE; - AuctionHouse.getInstance().getDataManager().getAdminLogs((error, logs) -> { + instance.getDataManager().getAdminLogs((error, logs) -> { if (error == null) - AuctionHouse.newChain().sync(() -> AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAdminLogs(player, logs))).execute(); + AuctionHouse.newChain().sync(() -> instance.getGuiManager().showGUI(player, new GUIAdminLogs(player, logs))).execute(); else error.printStackTrace(); }); @@ -73,36 +74,36 @@ public class CommandAdmin extends AbstractCommand { } if (target == null) { - AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[1]).sendPrefixedMessage(sender); + instance.getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[1]).sendPrefixedMessage(sender); return ReturnType.FAILURE; } - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAdminExpired(player, target)); + instance.getGuiManager().showGUI(player, new GUIAdminExpired(player, target)); break; case "endall": if (!sender.hasPermission("auctionhouse.cmd.admin.endall")) return ReturnType.FAILURE; - for (UUID id : AuctionHouse.getInstance().getAuctionItemManager().getItems().keySet()) { - AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).setExpired(true); + for (UUID id : instance.getAuctionItemManager().getItems().keySet()) { + instance.getAuctionItemManager().getItems().get(id).setExpired(true); } - AuctionHouse.getInstance().getLocale().getMessage("general.endedallauctions").sendPrefixedMessage(sender); + instance.getLocale().getMessage("general.endedallauctions").sendPrefixedMessage(sender); break; case "relistall": if (!sender.hasPermission("auctionhouse.cmd.admin.relistall")) return ReturnType.FAILURE; - for (UUID id : AuctionHouse.getInstance().getAuctionItemManager().getItems().keySet()) { - if (AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).isExpired()) { - int relistTime = args.length == 1 ? AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).isBidItem() ? Settings.DEFAULT_AUCTION_LISTING_TIME.getInt() : Settings.DEFAULT_BIN_LISTING_TIME.getInt() : Integer.parseInt(args[1]); + for (UUID id : instance.getAuctionItemManager().getItems().keySet()) { + if (instance.getAuctionItemManager().getItems().get(id).isExpired()) { + int relistTime = args.length == 1 ? instance.getAuctionItemManager().getItems().get(id).isBidItem() ? Settings.DEFAULT_AUCTION_LISTING_TIME.getInt() : Settings.DEFAULT_BIN_LISTING_TIME.getInt() : Integer.parseInt(args[1]); - AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).setExpiresAt(System.currentTimeMillis() + 1000L * relistTime); - AuctionHouse.getInstance().getAuctionItemManager().getItems().get(id).setExpired(false); + instance.getAuctionItemManager().getItems().get(id).setExpiresAt(System.currentTimeMillis() + 1000L * relistTime); + instance.getAuctionItemManager().getItems().get(id).setExpired(false); } } - AuctionHouse.getInstance().getLocale().getMessage("general.relisteditems").sendPrefixedMessage(sender); + instance.getLocale().getMessage("general.relisteditems").sendPrefixedMessage(sender); break; case "clearall": if (!sender.hasPermission("auctionhouse.cmd.admin.clearall")) return ReturnType.FAILURE; // Don't tell ppl that this exists - AuctionHouse.getInstance().getAuctionItemManager().getItems().clear(); + instance.getAuctionItemManager().getItems().clear(); case "opensell": if (args.length < 2) return ReturnType.FAILURE; if (!sender.hasPermission("auctionhouse.cmd.admin.opensell")) return ReturnType.FAILURE; @@ -113,11 +114,11 @@ public class CommandAdmin extends AbstractCommand { ItemStack itemToSell = PlayerHelper.getHeldItem(player).clone(); if (itemToSell.getType() == XMaterial.AIR.parseMaterial() && Settings.SELL_MENU_REQUIRES_USER_TO_HOLD_ITEM.getBoolean()) { - AuctionHouse.getInstance().getLocale().getMessage("general.air").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.air").sendPrefixedMessage(player); return ReturnType.FAILURE; } else { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellItem(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()), itemToSell)); - AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), itemToSell); + instance.getGuiManager().showGUI(player, new GUISellItem(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()), itemToSell)); + instance.getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), itemToSell); PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount()); } break; @@ -130,12 +131,12 @@ public class CommandAdmin extends AbstractCommand { if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()))); break; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java index 54019dc..f4aa716 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java @@ -31,20 +31,21 @@ public class CommandAuctionHouse extends AbstractCommand { Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + + final AuctionHouse instance = AuctionHouse.getInstance(); + if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } if (args.length == 0) { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()))); return ReturnType.SUCCESS; } - if (args.length == 1 && AuctionHouse.getInstance().getCommandManager().getSubCommands("auctionhouse").stream().noneMatch(cmd -> cmd.equalsIgnoreCase(StringUtils.join(args, ' ').trim()))) { + if (args.length == 1 && instance.getCommandManager().getSubCommands("auctionhouse").stream().noneMatch(cmd -> cmd.equalsIgnoreCase(StringUtils.join(args, ' ').trim()))) { if (args[0].equalsIgnoreCase("NaN")) return ReturnType.FAILURE; - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()), StringUtils.join(args, ' ').trim())); + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()), StringUtils.join(args, ' ').trim())); } } return ReturnType.SUCCESS; @@ -52,7 +53,7 @@ public class CommandAuctionHouse extends AbstractCommand { @Override protected List onTab(CommandSender sender, String... args) { - Player player = (Player) sender; + final Player player = (Player) sender; return AuctionHouse.getInstance().getCommandManager().getAllCommands().stream().filter(cmd -> cmd.getPermissionNode() == null || player.hasPermission(cmd.getPermissionNode())).map(AbstractCommand::getSyntax).collect(Collectors.toList()); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java index e00fa5c..3d4c8e9 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java @@ -34,10 +34,11 @@ public class CommandBan extends AbstractCommand { protected ReturnType runCommand(CommandSender sender, String... args) { Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - + + final AuctionHouse instance = AuctionHouse.getInstance(); if (args.length == 0) { // Open the bans menu - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIBans(player)); + instance.getGuiManager().showGUI(player, new GUIBans(player)); return ReturnType.SUCCESS; } @@ -45,7 +46,7 @@ public class CommandBan extends AbstractCommand { return ReturnType.SYNTAX_ERROR; } - Player target = PlayerUtils.findPlayer(args[0]); + final Player target = PlayerUtils.findPlayer(args[0]); String timeString = args[1]; StringBuilder reason = new StringBuilder(); for (int i = 2; i < args.length; i++) { @@ -59,7 +60,7 @@ public class CommandBan extends AbstractCommand { // try and look for an offline player offlinePlayer = Bukkit.getOfflinePlayer(args[0]); if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) { - AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(player); + instance.getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(player); return; } } @@ -67,17 +68,17 @@ public class CommandBan extends AbstractCommand { UUID toBan = target == null ? offlinePlayer.getUniqueId() : target.getUniqueId(); if (!AuctionAPI.getInstance().isValidTimeString(timeString)) { - AuctionHouse.getInstance().getLocale().getMessage("general.invalidtimestring").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.invalidtimestring").sendPrefixedMessage(player); return; } if (reason.toString().length() == 0) { - AuctionHouse.getInstance().getLocale().getMessage("bans.nobanreason").sendPrefixedMessage(player); + instance.getLocale().getMessage("bans.nobanreason").sendPrefixedMessage(player); return; } - if (AuctionHouse.getInstance().getAuctionBanManager().getBans().containsKey(toBan)) { - AuctionHouse.getInstance().getLocale().getMessage("bans.playeralreadybanned").processPlaceholder("player", args[0]).sendPrefixedMessage(player); + if (instance.getAuctionBanManager().getBans().containsKey(toBan)) { + instance.getLocale().getMessage("bans.playeralreadybanned").processPlaceholder("player", args[0]).sendPrefixedMessage(player); return; } @@ -88,11 +89,11 @@ public class CommandBan extends AbstractCommand { if (auctionBanPlayerEvent.isCancelled()) return; AuctionBan auctionBan = new AuctionBan(toBan, reason.toString().trim(), System.currentTimeMillis() + bannedSeconds * 1000); - AuctionHouse.getInstance().getAuctionBanManager().addBan(auctionBan); - AuctionHouse.getInstance().getLocale().getMessage("bans.bannedplayer").processPlaceholder("player", args[0]).processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(player); + instance.getAuctionBanManager().addBan(auctionBan); + instance.getLocale().getMessage("bans.bannedplayer").processPlaceholder("player", args[0]).processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(player); if (target != null) { - AuctionHouse.getInstance().getLocale().getMessage("bans.remainingtime").processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(target); + instance.getLocale().getMessage("bans.remainingtime").processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(target); } }).execute(); diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java index eb7994e..d2d1099 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java @@ -25,15 +25,16 @@ public class CommandExpired extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + + final AuctionHouse instance = AuctionHouse.getInstance(); + if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIExpiredItems(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + instance.getGuiManager().showGUI(player, new GUIExpiredItems(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()))); return ReturnType.SUCCESS; } @@ -44,12 +45,12 @@ public class CommandExpired extends AbstractCommand { @Override public String getSyntax() { - return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.expired").getMessage(); + return instance.getLocale().getMessage("commands.syntax.expired").getMessage(); } @Override public String getDescription() { - return AuctionHouse.getInstance().getLocale().getMessage("commands.description.expired").getMessage(); + return instance.getLocale().getMessage("commands.description.expired").getMessage(); } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandFilter.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandFilter.java index 9dcbabc..a141d1c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandFilter.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandFilter.java @@ -31,11 +31,12 @@ public class CommandFilter extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; + final AuctionHouse instance = AuctionHouse.getInstance(); if (args.length == 0) { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIFilterWhitelist(player)); + instance.getGuiManager().showGUI(player, new GUIFilterWhitelist(player)); return ReturnType.SUCCESS; } @@ -52,19 +53,19 @@ public class CommandFilter extends AbstractCommand { ItemStack held = PlayerHelper.getHeldItem(player); if (held.getType() == XMaterial.AIR.parseMaterial()) { - AuctionHouse.getInstance().getLocale().getMessage("general.filter air").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.filter air").sendPrefixedMessage(player); return ReturnType.FAILURE; } - if (AuctionHouse.getInstance().getFilterManager().getFilteredItem(held) != null && AuctionHouse.getInstance().getFilterManager().getFilteredItem(held).getCategory() == AuctionItemCategory.valueOf(args[1].toUpperCase())) { - AuctionHouse.getInstance().getLocale().getMessage("general.filteritemaddedalready").sendPrefixedMessage(player); + if (instance.getFilterManager().getFilteredItem(held) != null && instance.getFilterManager().getFilteredItem(held).getCategory() == AuctionItemCategory.valueOf(args[1].toUpperCase())) { + instance.getLocale().getMessage("general.filteritemaddedalready").sendPrefixedMessage(player); return ReturnType.FAILURE; } AuctionFilterItem filterItem = new AuctionFilterItem(held, AuctionItemCategory.valueOf(args[1].toUpperCase())); - AuctionHouse.getInstance().getFilterManager().addFilterItem(filterItem); - AuctionHouse.getInstance().getLocale().getMessage("general.addeditemtofilterwhitelist").processPlaceholder("item_name", AuctionAPI.getInstance().getItemName(held)).processPlaceholder("filter_category", args[1]).sendPrefixedMessage(player); + instance.getFilterManager().addFilterItem(filterItem); + instance.getLocale().getMessage("general.addeditemtofilterwhitelist").processPlaceholder("item_name", AuctionAPI.getInstance().getItemName(held)).processPlaceholder("filter_category", args[1]).sendPrefixedMessage(player); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMarkChest.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMarkChest.java index db937dc..694575b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMarkChest.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMarkChest.java @@ -36,16 +36,17 @@ public final class CommandMarkChest extends AbstractCommand { if (targetBlock.getType() != XMaterial.CHEST.parseMaterial()) return ReturnType.FAILURE; final Chest chest = (Chest) targetBlock.getState(); - final NamespacedKey key = new NamespacedKey(AuctionHouse.getInstance(), "AuctionHouseMarkedChest"); + final AuctionHouse instance = AuctionHouse.getInstance(); + final NamespacedKey key = new NamespacedKey(instance, "AuctionHouseMarkedChest"); if (chest.getPersistentDataContainer().has(key, PersistentDataType.BYTE)) { chest.getPersistentDataContainer().remove(key); chest.update(true); - AuctionHouse.getInstance().getLocale().getMessage("general.unmarked chest").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.unmarked chest").sendPrefixedMessage(player); } else { chest.getPersistentDataContainer().set(key, PersistentDataType.BYTE, (byte) 1); chest.update(true); - AuctionHouse.getInstance().getLocale().getMessage("general.marked chest").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.marked chest").sendPrefixedMessage(player); } return ReturnType.SUCCESS; diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMiddleware.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMiddleware.java index ede9554..75ba2fe 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMiddleware.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMiddleware.java @@ -21,17 +21,18 @@ public final class CommandMiddleware { public AbstractCommand.ReturnType handle(@NonNull final Player player) { if (AuctionAPI.tellMigrationStatus(player)) return AbstractCommand.ReturnType.FAILURE; + final AuctionHouse instance = AuctionHouse.getInstance(); if (Settings.BLOCKED_WORLDS.getStringList().contains(player.getWorld().getName())) { - AuctionHouse.getInstance().getLocale().getMessage("general.disabled in world").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.disabled in world").sendPrefixedMessage(player); return AbstractCommand.ReturnType.FAILURE; } if (Settings.USE_AUCTION_CHEST_MODE.getBoolean()) { - AuctionHouse.getInstance().getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.visit auction chest").sendPrefixedMessage(player); return AbstractCommand.ReturnType.FAILURE; } - if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { + if (instance.getAuctionBanManager().checkAndHandleBan(player)) { return AbstractCommand.ReturnType.FAILURE; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMinPrice.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMinPrice.java index e5511f5..01ef883 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMinPrice.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandMinPrice.java @@ -29,11 +29,12 @@ public class CommandMinPrice extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; + final AuctionHouse instance = AuctionHouse.getInstance(); if (args.length == 0) { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIMinItemPrices(player)); + instance.getGuiManager().showGUI(player, new GUIMinItemPrices(player)); return ReturnType.SUCCESS; } @@ -42,26 +43,26 @@ public class CommandMinPrice extends AbstractCommand { ItemStack held = PlayerHelper.getHeldItem(player); if (held.getType() == XMaterial.AIR.parseMaterial()) { - AuctionHouse.getInstance().getLocale().getMessage("general.min item price air").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.min item price air").sendPrefixedMessage(player); return ReturnType.FAILURE; } - if (AuctionHouse.getInstance().getMinItemPriceManager().getMinPrice(held.clone()) != null) { - AuctionHouse.getInstance().getLocale().getMessage("general.min price already added").sendPrefixedMessage(player); + if (instance.getMinItemPriceManager().getMinPrice(held.clone()) != null) { + instance.getLocale().getMessage("general.min price already added").sendPrefixedMessage(player); return ReturnType.FAILURE; } if (!NumberUtils.isNumeric(args[1])) { - AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.notanumber").sendPrefixedMessage(player); return ReturnType.FAILURE; } final double price = Double.parseDouble(args[1]); - AuctionHouse.getInstance().getDataManager().insertMinPriceAsync(new MinItemPrice(held.clone(), price), (error, inserted) -> { + instance.getDataManager().insertMinPriceAsync(new MinItemPrice(held.clone(), price), (error, inserted) -> { if (error == null) { - AuctionHouse.getInstance().getMinItemPriceManager().addItem(inserted); - AuctionHouse.getInstance().getLocale().getMessage("general.added min price") + instance.getMinItemPriceManager().addItem(inserted); + instance.getLocale().getMessage("general.added min price") .processPlaceholder("item", AuctionAPI.getInstance().getItemName(inserted.getItemStack())) .processPlaceholder("price", AuctionAPI.getInstance().formatNumber(inserted.getPrice())) .sendPrefixedMessage(player); diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java index fa40dd5..d860d1a 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java @@ -23,8 +23,9 @@ public class CommandReload extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE; - AuctionHouse.getInstance().reloadConfig(); - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aReloaded files")).sendPrefixedMessage(sender); + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.reloadConfig(); + instance.getLocale().newMessage(TextUtils.formatText("&aReloaded files")).sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java index 3a5f771..2c4eeae 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java @@ -26,21 +26,22 @@ public class CommandSearch extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { if (args.length <= 0) return ReturnType.SYNTAX_ERROR; - Player player = (Player) sender; + final Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - StringBuilder builder = new StringBuilder(); + final StringBuilder builder = new StringBuilder(); for (String arg : args) { builder.append(arg).append(" "); } - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + final AuctionHouse instance = AuctionHouse.getInstance(); + if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()), builder.toString().trim())); + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()), builder.toString().trim())); return ReturnType.SUCCESS; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 48a243e..bc47588 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -48,19 +48,20 @@ public final class CommandSell extends AbstractCommand { if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + final AuctionHouse instance = AuctionHouse.getInstance(); + if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()); + AuctionPlayer auctionPlayer = instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()); ItemStack originalItem = PlayerHelper.getHeldItem(player).clone(); ItemStack itemToSell = PlayerHelper.getHeldItem(player).clone(); // check if player is at their selling limit if (auctionPlayer.isAtSellLimit()) { - AuctionHouse.getInstance().getLocale().getMessage("general.sellinglimit").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.sellinglimit").sendPrefixedMessage(player); return ReturnType.FAILURE; } @@ -71,18 +72,18 @@ public final class CommandSell extends AbstractCommand { } if (itemToSell.getType() == XMaterial.AIR.parseMaterial() && Settings.SELL_MENU_REQUIRES_USER_TO_HOLD_ITEM.getBoolean()) { - AuctionHouse.getInstance().getLocale().getMessage("general.air").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.air").sendPrefixedMessage(player); return ReturnType.FAILURE; } else { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellItem(auctionPlayer, itemToSell)); - AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), itemToSell); + instance.getGuiManager().showGUI(player, new GUISellItem(auctionPlayer, itemToSell)); + instance.getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), itemToSell); PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount()); } return ReturnType.SUCCESS; } if (itemToSell.getType() == XMaterial.AIR.parseMaterial()) { - AuctionHouse.getInstance().getLocale().getMessage("general.air").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.air").sendPrefixedMessage(player); return ReturnType.FAILURE; } @@ -90,12 +91,12 @@ public final class CommandSell extends AbstractCommand { if (Settings.MAKE_BLOCKED_ITEMS_A_WHITELIST.getBoolean()) { if (!Settings.BLOCKED_ITEMS.getStringList().contains(itemToSell.getType().name())) { - AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemToSell.getType().name()).sendPrefixedMessage(player); + instance.getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemToSell.getType().name()).sendPrefixedMessage(player); return ReturnType.FAILURE; } } else { if (Settings.BLOCKED_ITEMS.getStringList().contains(itemToSell.getType().name())) { - AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemToSell.getType().name()).sendPrefixedMessage(player); + instance.getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemToSell.getType().name()).sendPrefixedMessage(player); return ReturnType.FAILURE; } } @@ -108,7 +109,7 @@ public final class CommandSell extends AbstractCommand { // Check for blocked names and lore for (String s : Settings.BLOCKED_ITEM_NAMES.getStringList()) { if (AuctionAPI.getInstance().match(s, itemName)) { - AuctionHouse.getInstance().getLocale().getMessage("general.blockedname").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.blockedname").sendPrefixedMessage(player); blocked = true; } } @@ -117,7 +118,7 @@ public final class CommandSell extends AbstractCommand { for (String s : Settings.BLOCKED_ITEM_LORES.getStringList()) { for (String line : itemLore) { if (AuctionAPI.getInstance().match(s, line)) { - AuctionHouse.getInstance().getLocale().getMessage("general.blockedlore").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.blockedlore").sendPrefixedMessage(player); blocked = true; } } @@ -194,7 +195,7 @@ public final class CommandSell extends AbstractCommand { } // check buy now price null if (buyNowPrice == null) { - AuctionHouse.getInstance().getLocale().getMessage("general.please_enter_at_least_one_number").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.please_enter_at_least_one_number").sendPrefixedMessage(player); return ReturnType.FAILURE; } @@ -204,7 +205,7 @@ public final class CommandSell extends AbstractCommand { if (!isBiddingItem /* && buyNowPrice != null */) { // min item price todo fix it broke if (!AuctionAPI.getInstance().meetsMinItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) { - AuctionHouse.getInstance().getLocale().getMessage("pricing.minitemprice").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getMinItemPriceManager().getMinPrice(originalItem).getPrice())).sendPrefixedMessage(player); + instance.getLocale().getMessage("pricing.minitemprice").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(instance.getMinItemPriceManager().getMinPrice(originalItem).getPrice())).sendPrefixedMessage(player); return ReturnType.FAILURE; } @@ -215,7 +216,7 @@ public final class CommandSell extends AbstractCommand { if (isBiddingItem && /* buyNowPrice != null && */ startingBid != null) { // min item price todo fix it broke if (!AuctionAPI.getInstance().meetsMinItemPrice(isBundle, isBiddingItem, originalItem, buyNowPrice, isBiddingItem ? startingBid : 0)) { - AuctionHouse.getInstance().getLocale().getMessage("pricing.minitemprice").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getMinItemPriceManager().getMinPrice(originalItem).getPrice())).sendPrefixedMessage(player); + instance.getLocale().getMessage("pricing.minitemprice").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(instance.getMinItemPriceManager().getMinPrice(originalItem).getPrice())).sendPrefixedMessage(player); return ReturnType.FAILURE; } @@ -223,24 +224,24 @@ public final class CommandSell extends AbstractCommand { // check the starting bid values if (startingBid < Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()) { - AuctionHouse.getInstance().getLocale().getMessage("pricing.minstartingprice").processPlaceholder("price", Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(player); + instance.getLocale().getMessage("pricing.minstartingprice").processPlaceholder("price", Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(player); return ReturnType.FAILURE; } if (startingBid > Settings.MAX_AUCTION_START_PRICE.getDouble()) { - AuctionHouse.getInstance().getLocale().getMessage("pricing.maxstartingprice").processPlaceholder("price", Settings.MAX_AUCTION_START_PRICE.getDouble()).sendPrefixedMessage(player); + instance.getLocale().getMessage("pricing.maxstartingprice").processPlaceholder("price", Settings.MAX_AUCTION_START_PRICE.getDouble()).sendPrefixedMessage(player); return ReturnType.FAILURE; } // if present check the bid increment pricing if (bidIncrement != null) { if (bidIncrement < Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()) { - AuctionHouse.getInstance().getLocale().getMessage("pricing.minbidincrementprice").processPlaceholder("price", Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(player); + instance.getLocale().getMessage("pricing.minbidincrementprice").processPlaceholder("price", Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(player); return ReturnType.FAILURE; } if (bidIncrement > Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble()) { - AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbidincrementprice").processPlaceholder("price", Settings.MAX_AUCTION_START_PRICE.getDouble()).sendPrefixedMessage(player); + instance.getLocale().getMessage("pricing.maxbidincrementprice").processPlaceholder("price", Settings.MAX_AUCTION_START_PRICE.getDouble()).sendPrefixedMessage(player); return ReturnType.FAILURE; } } else { @@ -249,7 +250,7 @@ public final class CommandSell extends AbstractCommand { // check if the starting bid is not higher than the buy now if (Settings.BASE_PRICE_MUST_BE_HIGHER_THAN_BID_START.getBoolean() && startingBid > buyNowPrice && !(buyNowPrice <= -1)) { - AuctionHouse.getInstance().getLocale().getMessage("pricing.basepricetoolow").sendPrefixedMessage(player); + instance.getLocale().getMessage("pricing.basepricetoolow").sendPrefixedMessage(player); return ReturnType.FAILURE; } } @@ -263,7 +264,7 @@ public final class CommandSell extends AbstractCommand { } else { if (isBundle) { if (NBTEditor.contains(itemToSell, "AuctionBundleItem")) { - AuctionHouse.getInstance().getLocale().getMessage("general.cannotsellbundleditem").sendPrefixedMessage(player); + instance.getLocale().getMessage("general.cannotsellbundleditem").sendPrefixedMessage(player); return ReturnType.FAILURE; } @@ -286,7 +287,7 @@ public final class CommandSell extends AbstractCommand { } if (isBundle) { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIBundleCreation( + instance.getGuiManager().showGUI(player, new GUIBundleCreation( auctionPlayer, allowedTime, buyNowAllow, @@ -332,7 +333,7 @@ public final class CommandSell extends AbstractCommand { boolean finalPartialBuy = partialBuy; boolean finalIsBundle = isBundle; - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIListingConfirm(player, auctionedItem, result -> { + instance.getGuiManager().showGUI(player, new GUIListingConfirm(player, auctionedItem, result -> { if (!result) { player.closeInventory(); return; @@ -356,7 +357,7 @@ public final class CommandSell extends AbstractCommand { player.closeInventory(); if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()))); } })); } else { diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSellDev.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSellDev.java index 983e45c..44a9598 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSellDev.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSellDev.java @@ -32,17 +32,18 @@ public final class CommandSellDev extends AbstractCommand { if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + final AuctionHouse instance = AuctionHouse.getInstance(); + if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()); + AuctionPlayer auctionPlayer = instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()); if (args.length == 0) - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellListingType(auctionPlayer, selected -> { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, selected)); + instance.getGuiManager().showGUI(player, new GUISellListingType(auctionPlayer, selected -> { + instance.getGuiManager().showGUI(player, new GUISellPlaceItem(auctionPlayer, GUISellPlaceItem.ViewMode.SINGLE_ITEM, selected)); })); if (args.length == 1) { @@ -68,13 +69,17 @@ public final class CommandSellDev extends AbstractCommand { @Override protected List onTab(CommandSender sender, String... args) { - if (args.length == 1) - return Arrays.asList(AuctionHouse.getInstance().getLocale().getMessage("commands.sell.args.suggestion one").getMessage().split(" ")); - if (args.length == 2) - return Arrays.asList(AuctionHouse.getInstance().getLocale().getMessage("commands.sell.args.suggestion two").getMessage().split(" ")); - if (args.length == 3) - return Arrays.asList(AuctionHouse.getInstance().getLocale().getMessage("commands.sell.args.suggestion three").getMessage().split(" ")); - return null; + final int length = args.length; + switch (length) { + case 1: + return Arrays.asList(AuctionHouse.getInstance().getLocale().getMessage("commands.sell.args.suggestion one").getMessage().split(" ")); + case 2: + return Arrays.asList(AuctionHouse.getInstance().getLocale().getMessage("commands.sell.args.suggestion two").getMessage().split(" ")); + case 3: + return Arrays.asList(AuctionHouse.getInstance().getLocale().getMessage("commands.sell.args.suggestion three").getMessage().split(" ")); + default: + return null; + } } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java index 1202df0..b5acc68 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java @@ -29,7 +29,8 @@ public class CommandSettings extends AbstractCommand { Player player = (Player) sender; if (AuctionAPI.tellMigrationStatus(player)) return ReturnType.FAILURE; - AuctionHouse.getInstance().getGuiManager().showGUI(player, new PluginConfigGui(AuctionHouse.getInstance(), AuctionHouse.getInstance().getLocale().getMessage("general.prefix").getMessage())); + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.getGuiManager().showGUI(player, new PluginConfigGui(instance, instance.getLocale().getMessage("general.prefix").getMessage())); return ReturnType.SUCCESS; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java index 8a8000f..3032ca4 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java @@ -26,31 +26,32 @@ public class CommandStats extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - final AuctionPlayer user = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()); + final AuctionHouse instance = AuctionHouse.getInstance(); + final AuctionPlayer user = instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()); if (user == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } if (args.length == 0) { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIStatisticViewSelect(user)); + instance.getGuiManager().showGUI(player, new GUIStatisticViewSelect(user)); return ReturnType.SUCCESS; } final Player target = Bukkit.getPlayerExact(args[0]); if (target == null) { - AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); + instance.getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); return ReturnType.FAILURE; } - final AuctionPlayer targetAuctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(target.getUniqueId()); - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIStatisticTarget(user, targetAuctionPlayer)); + final AuctionPlayer targetAuctionPlayer = instance.getAuctionPlayerManager().getPlayer(target.getUniqueId()); + instance.getGuiManager().showGUI(player, new GUIStatisticTarget(user, targetAuctionPlayer)); return ReturnType.SUCCESS; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandToggleListInfo.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandToggleListInfo.java index ab07748..373656c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandToggleListInfo.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandToggleListInfo.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.List; +import java.util.UUID; /** * The current file has been created by Kiran Hart @@ -25,16 +26,17 @@ public class CommandToggleListInfo extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player) sender; - - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + final Player player = (Player) sender; + final UUID playerUUID = player.getUniqueId(); + final AuctionHouse instance = AuctionHouse.getInstance(); + if (instance.getAuctionPlayerManager().getPlayer(playerUUID) == null) { + instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()); + final AuctionPlayer auctionPlayer = instance.getAuctionPlayerManager().getPlayer(playerUUID); auctionPlayer.setShowListingInfo(!auctionPlayer.isShowListingInfo()); - AuctionHouse.getInstance().getLocale().getMessage("general.toggled listing." + (auctionPlayer.isShowListingInfo() ? "on" : "off")).sendPrefixedMessage(player); + instance.getLocale().getMessage("general.toggled listing." + (auctionPlayer.isShowListingInfo() ? "on" : "off")).sendPrefixedMessage(player); return ReturnType.SUCCESS; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java index f5598f8..b7c4247 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java @@ -24,14 +24,15 @@ public class CommandTransactions extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - Player player = (Player) sender; + final Player player = (Player) sender; if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; + final AuctionHouse instance = AuctionHouse.getInstance(); if (Settings.RESTRICT_ALL_TRANSACTIONS_TO_PERM.getBoolean() && !player.hasPermission("auctionhouse.transactions.viewall")) { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUITransactionList(player, false)); + instance.getGuiManager().showGUI(player, new GUITransactionList(player, false)); } else { - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUITransactionType(player)); + instance.getGuiManager().showGUI(player, new GUITransactionType(player)); } return ReturnType.SUCCESS; diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUnban.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUnban.java index b29d3a9..d7af39d 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUnban.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUnban.java @@ -30,26 +30,27 @@ public class CommandUnban extends AbstractCommand { if (args.length != 1) return ReturnType.SYNTAX_ERROR; if (AuctionAPI.tellMigrationStatus(sender)) return ReturnType.FAILURE; - Player target = PlayerUtils.findPlayer(args[0]); + final Player target = PlayerUtils.findPlayer(args[0]); OfflinePlayer offlinePlayer = null; + final AuctionHouse instance = AuctionHouse.getInstance(); if (target == null) { offlinePlayer = Bukkit.getOfflinePlayer(args[0]); if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) { - AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); + instance.getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); return ReturnType.FAILURE; } } UUID toUnBan = target == null ? offlinePlayer.getUniqueId() : target.getUniqueId(); - if (!AuctionHouse.getInstance().getAuctionBanManager().getBans().containsKey(toUnBan)) { - AuctionHouse.getInstance().getLocale().getMessage("bans.playernotbanned").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); + if (!instance.getAuctionBanManager().getBans().containsKey(toUnBan)) { + instance.getLocale().getMessage("bans.playernotbanned").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); return ReturnType.FAILURE; } - AuctionHouse.getInstance().getAuctionBanManager().removeBan(toUnBan); - AuctionHouse.getInstance().getLocale().getMessage("bans.playerunbanned").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); + instance.getAuctionBanManager().removeBan(toUnBan); + instance.getLocale().getMessage("bans.playerunbanned").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); if (target != null) { AuctionHouse.getInstance().getLocale().getMessage("bans.unbanned").sendPrefixedMessage(target); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java index ed04b44..d3daee7 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java @@ -40,23 +40,24 @@ public final class CommandUpload extends AbstractCommand { } if (!args[0].equalsIgnoreCase("-confirm")) return ReturnType.FAILURE; - - DatabaseConnector databaseConnector = new SQLiteConnector(AuctionHouse.getInstance()); - DataManager manager = new DataManager(databaseConnector, AuctionHouse.getInstance(), null); + + final AuctionHouse instance = AuctionHouse.getInstance(); + final DatabaseConnector databaseConnector = new SQLiteConnector(instance); + final DataManager manager = new DataManager(databaseConnector, instance, null); manager.getItems((error, items) -> { if (error == null) - items.forEach(item -> AuctionHouse.getInstance().getDataManager().insertAuctionAsync(item, null)); + items.forEach(item -> instance.getDataManager().insertAuctionAsync(item, null)); }); manager.getAdminLogs((error, logs) -> { if (error == null) - logs.forEach(log -> AuctionHouse.getInstance().getDataManager().insertLogAsync(log)); + logs.forEach(log -> instance.getDataManager().insertLogAsync(log)); }); manager.getTransactions((error, transactions) -> { if (error == null) - transactions.forEach(transaction -> AuctionHouse.getInstance().getDataManager().insertTransactionAsync(transaction, null)); + transactions.forEach(transaction -> instance.getDataManager().insertTransactionAsync(transaction, null)); }); return ReturnType.SUCCESS; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java index 67f0cdb..8ffd826 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java @@ -306,6 +306,7 @@ public class DataManager extends DataManagerAbstract { public void insertAuction(AuctionedItem item, Callback callback) { this.databaseConnector.connect(connection -> { try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item, listed_world, infinite, allow_partial_buys) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) { + final AuctionAPI api = AuctionAPI.getInstance(); PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "auctions WHERE id = ?"); fetch.setString(1, item.getId().toString()); @@ -322,9 +323,9 @@ public class DataManager extends DataManagerAbstract { statement.setBoolean(11, item.isExpired()); statement.setLong(12, item.getExpiresAt()); statement.setString(13, item.getItem().getType().name()); - statement.setString(14, AuctionAPI.getInstance().getItemName(item.getItem())); - statement.setString(15, AuctionAPI.getInstance().serializeLines(AuctionAPI.getInstance().getItemLore(item.getItem()))); - statement.setString(16, AuctionAPI.getInstance().serializeLines(AuctionAPI.getInstance().getItemEnchantments(item.getItem()))); + statement.setString(14, api.getItemName(item.getItem())); + statement.setString(15, api.serializeLines(api.getItemLore(item.getItem()))); + statement.setString(16, api.serializeLines(api.getItemEnchantments(item.getItem()))); statement.setString(17, AuctionAPI.encodeItem(item.getItem())); statement.setString(18, item.getListedWorld()); statement.setBoolean(19, item.isInfinite()); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIMinItemPrices.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIMinItemPrices.java index 6b59e93..07393c5 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIMinItemPrices.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIMinItemPrices.java @@ -38,12 +38,13 @@ public final class GUIMinItemPrices extends AbstractPlaceholderGui { reset(); pages = (int) Math.max(1, Math.ceil(this.minPrices.size() / (double) 45)); + setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack()); setNextPage(5, 5, new TItemBuilder(Objects.requireNonNull(Settings.GUI_NEXT_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_NEXT_BTN_NAME.getString()).setLore(Settings.GUI_NEXT_BTN_LORE.getStringList()).toItemStack()); setOnPage(e -> draw()); int slot = 0; - List data = this.minPrices.stream().skip((page - 1) * 45L).limit(45).collect(Collectors.toList()); + final List data = this.minPrices.stream().skip((page - 1) * 45L).limit(45).collect(Collectors.toList()); for (MinItemPrice minItemPrice : data) { diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java index 7dc73d1..6d70d1b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java @@ -45,35 +45,36 @@ public final class GUIStatisticSelf extends AbstractPlaceholderGui { } private void draw() { + final AuctionHouse instance = AuctionHouse.getInstance(); // created auction setItem(1, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_LORE.getStringList(), new HashMap() {{ - put("%created_auctions%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.CREATED_AUCTION)); + put("%created_auctions%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.CREATED_AUCTION)); }})); // sold auction setItem(3, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_LORE.getStringList(), new HashMap() {{ - put("%sold_auctions%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.SOLD_AUCTION)); + put("%sold_auctions%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.SOLD_AUCTION)); }})); // created bin setItem(1, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_LORE.getStringList(), new HashMap() {{ - put("%created_bins%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.CREATED_BIN)); + put("%created_bins%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.CREATED_BIN)); }})); // sold bin setItem(3, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_LORE.getStringList(), new HashMap() {{ - put("%sold_bins%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.SOLD_BIN)); + put("%sold_bins%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.SOLD_BIN)); }})); // money earned setItem(1, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_LORE.getStringList(), new HashMap() {{ - put("%money_earned%", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_EARNED))); + put("%money_earned%", AuctionAPI.getInstance().formatNumber(instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_EARNED))); }})); // money spent setItem(3, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_LORE.getStringList(), new HashMap() {{ - put("%money_spent%", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_SPENT))); + put("%money_spent%", AuctionAPI.getInstance().formatNumber(instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_SPENT))); }})); setButton(5, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> { diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java index d04a265..dffd73a 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java @@ -34,12 +34,13 @@ public class GUITransactionList extends AbstractPlaceholderGui { public GUITransactionList(Player player, boolean showAll) { super(player); this.player = player; - this.auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(this.player.getUniqueId()); + final AuctionHouse instance = AuctionHouse.getInstance(); + this.auctionPlayer = instance.getAuctionPlayerManager().getPlayer(this.player.getUniqueId()); this.showAll = showAll; if (showAll) - this.transactions = new ArrayList<>(AuctionHouse.getInstance().getTransactionManager().getTransactions().values()); + this.transactions = new ArrayList<>(instance.getTransactionManager().getTransactions().values()); else - this.transactions = AuctionHouse.getInstance().getTransactionManager().getTransactions().values().stream().filter(transaction -> transaction.getSeller().equals(player.getUniqueId()) || transaction.getBuyer().equals(player.getUniqueId())).collect(Collectors.toList()); + this.transactions = instance.getTransactionManager().getTransactions().values().stream().filter(transaction -> transaction.getSeller().equals(player.getUniqueId()) || transaction.getBuyer().equals(player.getUniqueId())).collect(Collectors.toList()); setTitle(TextUtils.formatText(showAll ? Settings.GUI_TRANSACTIONS_TITLE_ALL.getString() : Settings.GUI_TRANSACTIONS_TITLE.getString())); setRows(6); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionType.java b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionType.java index 0958395..8e78dba 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionType.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionType.java @@ -39,10 +39,11 @@ public final class GUITransactionType extends AbstractPlaceholderGui { } private void draw() { + final AuctionHouse instance = AuctionHouse.getInstance(); // (player.hasPermission("auctionhouse.admin") || player.isOp()) setButton(11, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_TRANSACTIONS_TYPE_ITEMS_ALL_TRANSACTIONS_ITEM.getString(), Settings.GUI_TRANSACTIONS_TYPE_ITEMS_ALL_TRANSACTIONS_NAME.getString(), Settings.GUI_TRANSACTIONS_TYPE_ITEMS_ALL_TRANSACTIONS_LORE.getStringList(), null), e -> { if (Settings.RESTRICT_ALL_TRANSACTIONS_TO_PERM.getBoolean() && !e.player.hasPermission("auctionhouse.transactions.viewall")) { - AuctionHouse.getInstance().getLocale().getMessage("commands.no_permission").sendPrefixedMessage(e.player); + instance.getLocale().getMessage("commands.no_permission").sendPrefixedMessage(e.player); return; } @@ -56,7 +57,7 @@ public final class GUITransactionType extends AbstractPlaceholderGui { if (player.isOp() || player.hasPermission("auctionhouse.admin")) { setButton(3, 8, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_TRANSACTIONS_TYPE_ITEMS_DELETE_ITEM.getString(), Settings.GUI_TRANSACTIONS_TYPE_ITEMS_DELETE_NAME.getString(), Settings.GUI_TRANSACTIONS_TYPE_ITEMS_DELETE_LORE.getStringList(), null), e -> { e.gui.close(); - PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player); + PlayerChatInput.PlayerChatInputBuilder builder = new PlayerChatInput.PlayerChatInputBuilder<>(instance, e.player); builder.isValidInput((p, str) -> { String[] parts = ChatColor.stripColor(str).split(" "); if (parts.length == 2) { @@ -64,8 +65,8 @@ public final class GUITransactionType extends AbstractPlaceholderGui { } return false; }); - builder.sendValueMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter deletion range").getMessage())); - builder.invalidInputMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter valid deletion range").getMessage())); + builder.sendValueMessage(TextUtils.formatText(instance.getLocale().getMessage("prompts.enter deletion range").getMessage())); + builder.invalidInputMessage(TextUtils.formatText(instance.getLocale().getMessage("prompts.enter valid deletion range").getMessage())); builder.toCancel("cancel"); builder.onCancel(p -> e.manager.showGUI(e.player, new GUITransactionType(e.player))); builder.setValue((p, value) -> AuctionAPI.toTicks(ChatColor.stripColor(value))); @@ -73,10 +74,10 @@ public final class GUITransactionType extends AbstractPlaceholderGui { int seconds = value.intValue(); AuctionHouse.newChain().async(() -> { - AuctionHouse.getInstance().getLocale().getMessage("general.transaction delete begin").sendPrefixedMessage(e.player); + instance.getLocale().getMessage("general.transaction delete begin").sendPrefixedMessage(e.player); List toRemove = new ArrayList<>(); - Set> entrySet = AuctionHouse.getInstance().getTransactionManager().getTransactions().entrySet(); + Set> entrySet = instance.getTransactionManager().getTransactions().entrySet(); Iterator> entryIterator = entrySet.iterator(); while (entryIterator.hasNext()) { @@ -89,8 +90,8 @@ public final class GUITransactionType extends AbstractPlaceholderGui { } } - AuctionHouse.getInstance().getDataManager().deleteTransactions(toRemove); - AuctionHouse.getInstance().getLocale().getMessage("general.deleted transactions").processPlaceholder("deleted_transactions", toRemove.size()).sendPrefixedMessage(e.player); + instance.getDataManager().deleteTransactions(toRemove); + instance.getLocale().getMessage("general.deleted transactions").processPlaceholder("deleted_transactions", toRemove.size()).sendPrefixedMessage(e.player); }).execute(); }); diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java index 0dcef05..3c4703f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java @@ -21,7 +21,7 @@ import java.util.stream.Collectors; public class ConfigurationItemHelper { public static ItemStack createConfigurationItem(ItemStack stack, String title, List lore, HashMap replacements, String... nbtData) { - ItemMeta meta = stack.getItemMeta(); + final ItemMeta meta = stack.getItemMeta(); assert meta != null; meta.setDisplayName(TextUtils.formatText(title)); diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/MaterialCategorizer.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/MaterialCategorizer.java index 26c107b..53dca88 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/MaterialCategorizer.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/MaterialCategorizer.java @@ -23,16 +23,17 @@ public class MaterialCategorizer { if (material.isBlock()) return AuctionItemCategory.BLOCKS; if (material == XMaterial.ENCHANTED_BOOK.parseMaterial()) return AuctionItemCategory.ENCHANTS; + final String materialName = material.name(); // Armor filter - if (material.name().endsWith("_HELMET") || material.name().endsWith("_CHESTPLATE") || material.name().endsWith("_LEGGINGS") || material.name().endsWith("_BOOTS")) + if (materialName.endsWith("_HELMET") || materialName.endsWith("_CHESTPLATE") || materialName.endsWith("_LEGGINGS") || materialName.endsWith("_BOOTS")) return AuctionItemCategory.ARMOR; // Weapon Filter - if (material.name().endsWith("_SWORD") || material.name().equals("BOW") || material.name().equals("TRIDENT") || material.name().equals("CROSSBOW")) + if (materialName.endsWith("_SWORD") || materialName.equals("BOW") || materialName.equals("TRIDENT") || materialName.equals("CROSSBOW")) return AuctionItemCategory.WEAPONS; // Tool Filter - if (material.name().endsWith("_AXE") || material.name().endsWith("_PICKAXE") || material.name().endsWith("_HOE") || material.name().endsWith("SHOVEL")) + if (materialName.endsWith("_AXE") || materialName.endsWith("_PICKAXE") || materialName.endsWith("_HOE") || materialName.endsWith("SHOVEL")) return AuctionItemCategory.TOOLS; return AuctionItemCategory.MISC; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java index 66b7cc6..bdcd5b6 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java @@ -7,10 +7,12 @@ import ca.tweetzy.auctionhouse.api.events.AuctionBidEvent; import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent; import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent; import ca.tweetzy.auctionhouse.auction.AuctionStatistic; +import ca.tweetzy.auctionhouse.auction.AuctionedItem; import ca.tweetzy.auctionhouse.auction.enums.AuctionSaleType; import ca.tweetzy.auctionhouse.auction.enums.AuctionStatisticType; import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.transaction.Transaction; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -27,19 +29,22 @@ public class AuctionListeners implements Listener { @EventHandler public void onAuctionStart(AuctionStartEvent e) { // new stat system - new AuctionStatistic(e.getSeller().getUniqueId(), e.getAuctionItem().isBidItem() ? AuctionStatisticType.CREATED_AUCTION : AuctionStatisticType.CREATED_BIN, 1).store(null); + final Player seller = e.getSeller(); + final AuctionedItem auctionedItem = e.getAuctionedItem(); + new AuctionStatistic(seller.getUniqueId(), auctionedItem.isBidItem() ? AuctionStatisticType.CREATED_AUCTION : AuctionStatisticType.CREATED_BIN, 1).store(null); if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_START.getBoolean()) { AuctionHouse.newChain().async(() -> { + final AuctionAPI instance = AuctionAPI.getInstance(); Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> { - AuctionAPI.getInstance().sendDiscordMessage( + instance.sendDiscordMessage( hook, - e.getSeller(), - e.getSeller(), - e.getAuctionItem(), + seller, + seller, + auctionedItem, AuctionSaleType.USED_BIDDING_SYSTEM, true, - e.getAuctionItem().isBidItem() + auctionedItem.isBidItem() ); }); }).execute(); @@ -49,33 +54,36 @@ public class AuctionListeners implements Listener { @EventHandler public void onAuctionEnd(AuctionEndEvent e) { // new stat system - new AuctionStatistic(e.getOriginalOwner().getUniqueId(), e.getAuctionItem().isBidItem() ? AuctionStatisticType.SOLD_AUCTION : AuctionStatisticType.SOLD_BIN, 1).store(null); - new AuctionStatistic(e.getOriginalOwner().getUniqueId(), AuctionStatisticType.MONEY_EARNED, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? e.getAuctionItem().getCurrentPrice() : e.getAuctionItem().getBasePrice()).store(null); - new AuctionStatistic(e.getBuyer().getUniqueId(), AuctionStatisticType.MONEY_SPENT, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? e.getAuctionItem().getCurrentPrice() : e.getAuctionItem().getBasePrice()).store(null); + final Player originalOwner = e.getOriginalOwner(), buyer = e.getBuyer(); + final UUID originalOwnerUUID = originalOwner.getUniqueId(), buyerUUID = buyer.getUniqueId(); + final AuctionedItem auctionedItem = e.getAuctionedItem(); + new AuctionStatistic(originalOwnerUUID, auctionedItem.isBidItem() ? AuctionStatisticType.SOLD_AUCTION : AuctionStatisticType.SOLD_BIN, 1).store(null); + new AuctionStatistic(originalOwnerUUID, AuctionStatisticType.MONEY_EARNED, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionedItem.getCurrentPrice() : auctionedItem.getBasePrice()).store(null); + new AuctionStatistic(buyerUUID, AuctionStatisticType.MONEY_SPENT, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionedItem.getCurrentPrice() : auctionedItem.getBasePrice()).store(null); AuctionHouse.newChain().async(() -> { if (Settings.RECORD_TRANSACTIONS.getBoolean()) { - - AuctionHouse.getInstance().getDataManager().insertTransactionAsync(new Transaction( + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.getDataManager().insertTransactionAsync(new Transaction( UUID.randomUUID(), - e.getOriginalOwner().getUniqueId(), - e.getBuyer().getUniqueId(), - e.getAuctionItem().getOwnerName(), - e.getBuyer().getName(), + originalOwnerUUID, + buyerUUID, + auctionedItem.getOwnerName(), + buyer.getName(), System.currentTimeMillis(), - e.getAuctionItem().getItem(), + auctionedItem.getItem(), e.getSaleType(), - e.getAuctionItem().getCurrentPrice() + auctionedItem.getCurrentPrice() ), (error, transaction) -> { if (error == null) { - AuctionHouse.getInstance().getTransactionManager().addTransaction(transaction); + instance.getTransactionManager().addTransaction(transaction); } }); - } if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_FINISH.getBoolean()) { - Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> AuctionAPI.getInstance().sendDiscordMessage(hook, e.getOriginalOwner(), e.getBuyer(), e.getAuctionItem(), e.getSaleType(), false, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM)); + final AuctionAPI instance = AuctionAPI.getInstance(); + Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> instance.sendDiscordMessage(hook, originalOwner, buyer, auctionedItem, e.getSaleType(), false, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM)); } }).execute(); } @@ -84,7 +92,9 @@ public class AuctionListeners implements Listener { public void onAuctionBid(AuctionBidEvent e) { if (!Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_BID.getBoolean()) return; AuctionHouse.newChain().async(() -> { - Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> AuctionAPI.getInstance().sendDiscordBidMessage(hook, e.getAuctionedItem(), e.getNewBidAmount())); + final AuctionAPI instance = AuctionAPI.getInstance(); + final AuctionedItem auctionedItem = e.getAuctionedItem(); + Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> instance.sendDiscordBidMessage(hook, auctionedItem, e.getNewBidAmount())); }).execute(); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java index 9009033..ec1fdbd 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/PlayerListeners.java @@ -30,6 +30,8 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; @@ -47,7 +49,6 @@ public class PlayerListeners implements Listener { @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { final Player player = event.getEntity(); - final AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()); if (auctionPlayer != null) { // task id cancel @@ -57,39 +58,38 @@ public class PlayerListeners implements Listener { player.getLocation().getWorld().dropItemNaturally(player.getLocation(), auctionPlayer.getItemBeingListed()); } } - } @EventHandler(priority = EventPriority.HIGH) public void onPlayerJoin(PlayerJoinEvent e) { - Player player = e.getPlayer(); - - AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(player); + final Player player = e.getPlayer(); + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.getAuctionPlayerManager().addPlayer(player); Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> { - if (Settings.UPDATE_CHECKER.getBoolean() && AuctionHouse.getInstance().getStatus() == UpdateChecker.UpdateStatus.UNRELEASED_VERSION && player.isOp()) { - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText(String.format("&dYou're running an unreleased version of Auction House &f(&c%s&f)", AuctionHouse.getInstance().getDescription().getVersion()))).sendPrefixedMessage(player); + if (Settings.UPDATE_CHECKER.getBoolean() && instance.getStatus() == UpdateChecker.UpdateStatus.UNRELEASED_VERSION && player.isOp()) { + instance.getLocale().newMessage(TextUtils.formatText(String.format("&dYou're running an unreleased version of Auction House &f(&c%s&f)", instance.getDescription().getVersion()))).sendPrefixedMessage(player); } }, 20); } @EventHandler public void onPlayerQuit(PlayerQuitEvent e) { - Player player = e.getPlayer(); - - AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().remove(player.getUniqueId()); - AuctionHouse.getInstance().getLogger().info("Removing sell holding instance for user: " + player.getName()); + final Player player = e.getPlayer(); + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.getAuctionPlayerManager().getSellHolding().remove(player.getUniqueId()); + instance.getLogger().info("Removing sell holding instance for user: " + player.getName()); } @EventHandler public void onCraftWithBundle(PrepareItemCraftEvent event) { - final ItemStack[] craftingItems = event.getInventory().getMatrix(); - + final CraftingInventory inventory = event.getInventory(); + final ItemStack[] craftingItems = inventory.getMatrix(); for (ItemStack item : craftingItems) { if (item == null || item.getType() == XMaterial.AIR.parseMaterial()) continue; if (NBTEditor.contains(item, "AuctionBundleItem")) { - event.getInventory().setResult(XMaterial.AIR.parseItem()); + inventory.setResult(XMaterial.AIR.parseItem()); } } } @@ -104,23 +104,24 @@ public class PlayerListeners implements Listener { if (block == null || block.getType() != XMaterial.CHEST.parseMaterial()) return; final Chest chest = (Chest) block.getState(); - final NamespacedKey key = new NamespacedKey(AuctionHouse.getInstance(), "AuctionHouseMarkedChest"); + final AuctionHouse instance = AuctionHouse.getInstance(); + final NamespacedKey key = new NamespacedKey(instance, "AuctionHouseMarkedChest"); if (chest.getPersistentDataContainer().has(key, PersistentDataType.BYTE)) { e.setUseInteractedBlock(Event.Result.DENY); e.setCancelled(true); - if (AuctionHouse.getInstance().getAuctionBanManager().checkAndHandleBan(player)) { + if (instance.getAuctionBanManager().checkAndHandleBan(player)) { return; } - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()))); } } @EventHandler public void onBundleClick(PlayerInteractEvent e) { - Player player = e.getPlayer(); - ItemStack heldItem = PlayerHelper.getHeldItem(player); + final Player player = e.getPlayer(); + final ItemStack heldItem = PlayerHelper.getHeldItem(player); if (heldItem == null || (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)) return; @@ -128,7 +129,7 @@ public class PlayerListeners implements Listener { if (!NBTEditor.contains(heldItem, "AuctionBundleItem")) return; e.setCancelled(true); - List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (int i = 0; i < NBTEditor.getInt(heldItem, "AuctionBundleItem"); i++) { items.add(AuctionAPI.getInstance().deserializeItem(NBTEditor.getByteArray(heldItem, "AuctionBundleItem-" + i))); diff --git a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java index 7000589..c592bc4 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionPlayerManager.java @@ -111,12 +111,13 @@ public class AuctionPlayerManager { public void loadPlayers() { this.auctionPlayers.clear(); - AuctionHouse.getInstance().getDataManager().getAuctionPlayers((error, all) -> { + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.getDataManager().getAuctionPlayers((error, all) -> { if (error == null) { all.forEach(this::addPlayer); // add all online players - Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> Bukkit.getOnlinePlayers().forEach(this::addPlayer), 20 * 3); + Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(instance, () -> Bukkit.getOnlinePlayers().forEach(this::addPlayer), 20 * 3); } }); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionStatisticManager.java b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionStatisticManager.java index 77c4db7..61d8715 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionStatisticManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionStatisticManager.java @@ -45,25 +45,27 @@ public final class AuctionStatisticManager { synchronized (this.statistics) { if (this.statistics.contains(statistic)) return; this.statistics.add(statistic); - + + final UUID owner = statistic.getStatOwner(); + final double value = value; switch (statistic.getStatisticType()) { case CREATED_AUCTION: - this.createdAuctionCount.put(statistic.getStatOwner(), this.createdAuctionCount.getOrDefault(statistic.getStatOwner(), 0D) + statistic.getValue()); + this.createdAuctionCount.put(owner, this.createdAuctionCount.getOrDefault(owner, 0D) + value); break; case CREATED_BIN: - this.createdBinCount.put(statistic.getStatOwner(), this.createdBinCount.getOrDefault(statistic.getStatOwner(), 0D) + statistic.getValue()); + this.createdBinCount.put(owner, this.createdBinCount.getOrDefault(owner, 0D) + value); break; case SOLD_AUCTION: - this.soldAuctionCount.put(statistic.getStatOwner(), this.soldAuctionCount.getOrDefault(statistic.getStatOwner(), 0D) + statistic.getValue()); + this.soldAuctionCount.put(owner, this.soldAuctionCount.getOrDefault(owner, 0D) + value); break; case SOLD_BIN: - this.soldBinCount.put(statistic.getStatOwner(), this.soldBinCount.getOrDefault(statistic.getStatOwner(), 0D) + statistic.getValue()); + this.soldBinCount.put(owner, this.soldBinCount.getOrDefault(owner, 0D) + value); break; case MONEY_SPENT: - this.moneySpentCount.put(statistic.getStatOwner(), this.moneySpentCount.getOrDefault(statistic.getStatOwner(), 0D) + statistic.getValue()); + this.moneySpentCount.put(owner, this.moneySpentCount.getOrDefault(owner, 0D) + value); break; case MONEY_EARNED: - this.moneyEarnedCount.put(statistic.getStatOwner(), this.moneyEarnedCount.getOrDefault(statistic.getStatOwner(), 0D) + statistic.getValue()); + this.moneyEarnedCount.put(owner, this.moneyEarnedCount.getOrDefault(owner, 0D) + value); break; } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/managers/SoundManager.java b/src/main/java/ca/tweetzy/auctionhouse/managers/SoundManager.java index f1268f1..c0ff7ec 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/managers/SoundManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/managers/SoundManager.java @@ -3,6 +3,7 @@ package ca.tweetzy.auctionhouse.managers; import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.core.compatibility.XSound; import org.bukkit.Bukkit; +import org.bukkit.Sound; import org.bukkit.entity.Player; import java.util.Arrays; @@ -32,12 +33,11 @@ public class SoundManager { } public void playSound(Player[] players, String sound, float volume, float pitch) { - Arrays.stream(players).forEach(p -> p.playSound(p.getLocation(), XSound.matchXSound(sound).get().parseSound(), volume, pitch)); + final Sound xsound = XSound.matchXSound(sound).get().parseSound(); + Arrays.stream(players).forEach(p -> p.playSound(p.getLocation(), xsound, volume, pitch)); } public void playSound(Player player, String sound, float volume, float pitch, int delay) { Bukkit.getServer().getScheduler().runTaskLater(AuctionHouse.getInstance(), () -> playSound(player, sound, volume, pitch), delay); } - - } diff --git a/src/main/java/ca/tweetzy/auctionhouse/tasks/AutoSaveTask.java b/src/main/java/ca/tweetzy/auctionhouse/tasks/AutoSaveTask.java index dcbe8dc..077cd51 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/tasks/AutoSaveTask.java +++ b/src/main/java/ca/tweetzy/auctionhouse/tasks/AutoSaveTask.java @@ -26,10 +26,11 @@ public class AutoSaveTask extends BukkitRunnable { @Override public void run() { - AuctionHouse.getInstance().getDataManager().updateItems(AuctionHouse.getInstance().getAuctionItemManager().getItems().values(), null); - AuctionHouse.getInstance().getFilterManager().saveFilterWhitelist(true); + final AuctionHouse instance = AuctionHouse.getInstance(); + instance.getDataManager().updateItems(instance.getAuctionItemManager().getItems().values(), null); + instance.getFilterManager().saveFilterWhitelist(true); if (!Settings.DISABLE_AUTO_SAVE_MSG.getBoolean()) - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aAuto saved auction items & transactions")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getLocale().newMessage(TextUtils.formatText("&aAuto saved auction items & transactions")).sendPrefixedMessage(Bukkit.getConsoleSender()); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java b/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java index 38147fb..9f9aa10 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java +++ b/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java @@ -45,7 +45,8 @@ public class TickAuctionsTask extends BukkitRunnable { public void run() { clock += Settings.TICK_UPDATE_TIME.getInt(); - Set> entrySet = AuctionHouse.getInstance().getAuctionItemManager().getItems().entrySet(); + final AuctionHouse instance = AuctionHouse.getInstance(); + Set> entrySet = instance.getAuctionItemManager().getItems().entrySet(); Iterator> auctionItemIterator = entrySet.iterator(); @@ -54,26 +55,26 @@ public class TickAuctionsTask extends BukkitRunnable { AuctionedItem auctionItem = entry.getValue(); ItemStack itemStack = auctionItem.getItem(); - if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getId())) { - AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().remove(auctionItem.getId()); - AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().put(auctionItem.getId(), auctionItem); + if (instance.getAuctionItemManager().getGarbageBin().containsKey(auctionItem.getId())) { + instance.getAuctionItemManager().getGarbageBin().remove(auctionItem.getId()); + instance.getAuctionItemManager().getDeletedItems().put(auctionItem.getId(), auctionItem); auctionItemIterator.remove(); continue; } // begin the scuffed deletion - if (!AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().keySet().isEmpty()) { + if (!instance.getAuctionItemManager().getDeletedItems().keySet().isEmpty()) { if (Settings.GARBAGE_DELETION_TIMED_MODE.getBoolean() && clock % Settings.GARBAGE_DELETION_TIMED_DELAY.getInt() == 0) { - AuctionHouse.getInstance().getDataManager().deleteItemsAsync(AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().values().stream().map(AuctionedItem::getId).collect(Collectors.toList())); + instance.getDataManager().deleteItemsAsync(instance.getAuctionItemManager().getDeletedItems().values().stream().map(AuctionedItem::getId).collect(Collectors.toList())); if (!Settings.DISABLE_CLEANUP_MSG.getBoolean()) - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aCleaned a total of &e" + AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().size() + "&a items.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().clear(); + instance.getLocale().newMessage(TextUtils.formatText("&aCleaned a total of &e" + instance.getAuctionItemManager().getDeletedItems().size() + "&a items.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionItemManager().getDeletedItems().clear(); } else { - if (AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().size() >= Settings.GARBAGE_DELETION_MAX_ITEMS.getInt()) { - AuctionHouse.getInstance().getDataManager().deleteItemsAsync(AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().values().stream().map(AuctionedItem::getId).collect(Collectors.toList())); + if (instance.getAuctionItemManager().getDeletedItems().size() >= Settings.GARBAGE_DELETION_MAX_ITEMS.getInt()) { + instance.getDataManager().deleteItemsAsync(instance.getAuctionItemManager().getDeletedItems().values().stream().map(AuctionedItem::getId).collect(Collectors.toList())); if (!Settings.DISABLE_CLEANUP_MSG.getBoolean()) - AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&aCleaned a total of &e" + AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().size() + "&a items.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().clear(); + instance.getLocale().newMessage(TextUtils.formatText("&aCleaned a total of &e" + instance.getAuctionItemManager().getDeletedItems().size() + "&a items.")).sendPrefixedMessage(Bukkit.getConsoleSender()); + instance.getAuctionItemManager().getDeletedItems().clear(); } } } @@ -88,7 +89,7 @@ public class TickAuctionsTask extends BukkitRunnable { if (!auctionItem.isExpired()) { if (Settings.BROADCAST_AUCTION_ENDING.getBoolean()) { if (timeRemaining <= Settings.BROADCAST_AUCTION_ENDING_AT_TIME.getInt() && timeRemaining % 10 == 0 && timeRemaining != 0) { - Bukkit.getOnlinePlayers().forEach(player -> AuctionHouse.getInstance().getLocale().getMessage("auction.broadcast.ending") + Bukkit.getOnlinePlayers().forEach(player -> instance.getLocale().getMessage("auction.broadcast.ending") .processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack)) .processPlaceholder("seconds", timeRemaining) .sendPrefixedMessage(player)); @@ -117,7 +118,7 @@ public class TickAuctionsTask extends BukkitRunnable { AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(auctionItem.getOwner()), auctionWinner, auctionItem, AuctionSaleType.USED_BIDDING_SYSTEM, tax); - AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent); + instance.getServer().getPluginManager().callEvent(auctionEndEvent); if (auctionEndEvent.isCancelled()) continue; @@ -128,26 +129,26 @@ public class TickAuctionsTask extends BukkitRunnable { // alert seller and buyer if (Bukkit.getOfflinePlayer(auctionItem.getOwner()).isOnline()) { - AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold") + instance.getLocale().getMessage("auction.itemsold") .processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack)) .processPlaceholder("amount", itemStack.clone().getAmount()) .processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice : finalPrice - tax)) .processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(auctionItem.getHighestBidder()).getName()) .processPlaceholder("buyer_displayname", AuctionAPI.getInstance().getDisplayName(Bukkit.getOfflinePlayer(auctionItem.getHighestBidder()))) .sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer()); - AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(Bukkit.getOfflinePlayer(auctionItem.getOwner())))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice : finalPrice - tax)).sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer()); + instance.getLocale().getMessage("pricing.moneyadd").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(Bukkit.getOfflinePlayer(auctionItem.getOwner())))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice : finalPrice - tax)).sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer()); } if (auctionWinner.isOnline()) { assert auctionWinner.getPlayer() != null; - AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon") + instance.getLocale().getMessage("auction.bidwon") .processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemStack)) .processPlaceholder("amount", itemStack.getAmount()) .processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice + tax : finalPrice)) .sendPrefixedMessage(auctionWinner.getPlayer()); if (!Settings.BIDDING_TAKES_MONEY.getBoolean()) - AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(auctionWinner.getPlayer()))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice + tax : finalPrice)).sendPrefixedMessage(auctionWinner.getPlayer()); + instance.getLocale().getMessage("pricing.moneyremove").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(auctionWinner.getPlayer()))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice + tax : finalPrice)).sendPrefixedMessage(auctionWinner.getPlayer()); // handle full inventory if (auctionWinner.getPlayer().getInventory().firstEmpty() == -1) { @@ -157,7 +158,7 @@ public class TickAuctionsTask extends BukkitRunnable { else PlayerUtils.giveItem(auctionWinner.getPlayer(), itemStack); - AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem); + instance.getAuctionItemManager().sendToGarbage(auctionItem); continue; } } else { @@ -166,7 +167,7 @@ public class TickAuctionsTask extends BukkitRunnable { else PlayerUtils.giveItem(auctionWinner.getPlayer(), itemStack); - AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem); + instance.getAuctionItemManager().sendToGarbage(auctionItem); continue; } }