From a6362a99724c480d8f330734b606e0fb7c2a9968 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 10 May 2021 16:41:58 -0400 Subject: [PATCH] 2.7.0, command syntax and description can be translated, added an inventory check full setting --- pom.xml | 4 +- .../auctionhouse/commands/CommandActive.java | 4 +- .../commands/CommandAuctionHouse.java | 4 +- .../auctionhouse/commands/CommandConvert.java | 48 ++++++++++--------- .../auctionhouse/commands/CommandExpired.java | 4 +- .../auctionhouse/commands/CommandReload.java | 4 +- .../auctionhouse/commands/CommandSearch.java | 4 +- .../auctionhouse/commands/CommandSell.java | 4 +- .../commands/CommandSettings.java | 4 +- .../commands/CommandTransactions.java | 4 +- .../auctionhouse/commands/CommandUpload.java | 4 +- .../auctionhouse/database/DataManager.java | 11 ++++- .../auctionhouse/guis/GUIConfirmPurchase.java | 5 ++ .../auctionhouse/settings/Settings.java | 1 + .../auctionhouse/tasks/TickAuctionsTask.java | 17 +++++-- src/main/resources/en_US.lang | 29 ++++++++++- 16 files changed, 102 insertions(+), 49 deletions(-) diff --git a/pom.xml b/pom.xml index cd3f5c4..cabc011 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ ca.tweetzy auctionhouse - 2.6.3 + 2.7.0 UTF-8 @@ -126,7 +126,7 @@ ca.tweetzy tweetycore - 2.0.0 + 2.1.1 com.github.MilkBowl diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java index d2ac484..ca3cabe 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandActive.java @@ -43,12 +43,12 @@ public class CommandActive extends AbstractCommand { @Override public String getSyntax() { - return "active"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.active").getMessage(); } @Override public String getDescription() { - return "View all your auction listings"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.active").getMessage(); } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java index d1c10af..999a96f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandAuctionHouse.java @@ -51,11 +51,11 @@ public class CommandAuctionHouse extends AbstractCommand { @Override public String getSyntax() { - return "/ah"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.auctionhouse").getMessage(); } @Override public String getDescription() { - return "Main command for the plugin, it opens the auction window."; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.auctionhouse").getMessage(); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandConvert.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandConvert.java index 30e5834..facf39e 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandConvert.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandConvert.java @@ -28,6 +28,32 @@ public class CommandConvert extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { + handleLegacyConversion(sender); + + return ReturnType.SUCCESS; + } + + @Override + public String getPermissionNode() { + return "auctionhouse.cmd.convert"; + } + + @Override + public String getSyntax() { + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.convert").getMessage(); + } + + @Override + public String getDescription() { + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.convert").getMessage(); + } + + @Override + protected List onTab(CommandSender sender, String... args) { + return null; + } + + private void handleLegacyConversion(CommandSender sender) { AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&4Beginning the ATTEMPTED conversion process, this may take some time.")).sendPrefixedMessage(sender); long start = System.currentTimeMillis(); Bukkit.getServer().getScheduler().runTaskLater(AuctionHouse.getInstance(), () -> { @@ -81,27 +107,5 @@ public class CommandConvert extends AbstractCommand { AuctionHouse.getInstance().getData().save(); }, 1L); - - return ReturnType.SUCCESS; - } - - @Override - public String getPermissionNode() { - return "auctionhouse.cmd.convert"; - } - - @Override - public String getSyntax() { - return "convert"; - } - - @Override - public String getDescription() { - return "Used to make an attempted conversion from < 2.0.0+"; - } - - @Override - protected List onTab(CommandSender sender, String... args) { - return null; } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java index cd9c524..886d17b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandExpired.java @@ -43,12 +43,12 @@ public class CommandExpired extends AbstractCommand { @Override public String getSyntax() { - return "expired"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.expired").getMessage(); } @Override public String getDescription() { - return "View all your expired/cancelled listings"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.expired").getMessage(); } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java index 358f1c4..574b257 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandReload.java @@ -38,11 +38,11 @@ public class CommandReload extends AbstractCommand { @Override public String getSyntax() { - return "reload"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.reload").getMessage(); } @Override public String getDescription() { - return "Reload plugin files"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.reload").getMessage(); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java index 982be9e..cdfa6c9 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSearch.java @@ -41,12 +41,12 @@ public class CommandSearch extends AbstractCommand { @Override public String getSyntax() { - return "search "; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.search").getMessage(); } @Override public String getDescription() { - return "Search for specific item(s) in the auction house"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.search").getMessage(); } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 9928f57..0a253c2 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -241,11 +241,11 @@ public class CommandSell extends AbstractCommand { @Override public String getSyntax() { - return "sell [bidStart] [bidIncr]"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.sell").getMessage(); } @Override public String getDescription() { - return "Used to put an item up for auction"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.sell").getMessage(); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java index 7dd31b1..2f1fc29 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSettings.java @@ -39,11 +39,11 @@ public class CommandSettings extends AbstractCommand { @Override public String getSyntax() { - return "settings"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.settings").getMessage(); } @Override public String getDescription() { - return "Open the in-game config editor"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.settings").getMessage(); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java index c7098ae..84d2738 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandTransactions.java @@ -34,12 +34,12 @@ public class CommandTransactions extends AbstractCommand { @Override public String getSyntax() { - return "transactions"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.transactions").getMessage(); } @Override public String getDescription() { - return "Used to open the transactions menu"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.transactions").getMessage(); } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java index 22a5fde..c6d2eb1 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java @@ -59,12 +59,12 @@ public class CommandUpload extends AbstractCommand { @Override public String getSyntax() { - return "upload"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.syntax.upload").getMessage(); } @Override public String getDescription() { - return "Used to upload flat file data to the database"; + return AuctionHouse.getInstance().getLocale().getMessage("commands.description.upload").getMessage(); } @Override diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java index 54f4d0b..c953fe8 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java @@ -1,18 +1,25 @@ package ca.tweetzy.auctionhouse.database; +import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionItem; +import ca.tweetzy.auctionhouse.auction.AuctionItemCategory; +import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer; import ca.tweetzy.auctionhouse.transaction.Transaction; +import ca.tweetzy.core.compatibility.XMaterial; +import ca.tweetzy.core.configuration.Config; import ca.tweetzy.core.database.DataManagerAbstract; import ca.tweetzy.core.database.DatabaseConnector; +import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.function.Consumer; /** diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmPurchase.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmPurchase.java index fa9f949..33b2526 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmPurchase.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmPurchase.java @@ -89,6 +89,11 @@ public class GUIConfirmPurchase extends Gui { if (auctionEndEvent.isCancelled()) return; + if (!Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean() && e.player.getInventory().firstEmpty() == -1) { + AuctionHouse.getInstance().getLocale().getMessage("general.noroom").sendPrefixedMessage(e.player); + return; + } + if (this.buyingSpecificQuantity) { ItemStack item = AuctionAPI.getInstance().deserializeItem(located.getRawItem()); // Bukkit.broadcastMessage(String.format("Total Item Qty: %d\nTotal Purchase Qty: %d\nAmount of purchase: %d", item.getAmount(), this.purchaseQuantity, item.getAmount() - this.purchaseQuantity)); diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index cb1c8be..c5f0c98 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -53,6 +53,7 @@ public class Settings { public static final ConfigSetting ALLOW_PURCHASE_OF_SPECIFIC_QUANTITIES = new ConfigSetting(config, "auction setting.allow purchase of specific quantities", false, "When a buy now item is right-clicked should it open a", "special gui to specify the quantity of items to buy from the stack?"); public static final ConfigSetting USE_REFRESH_COOL_DOWN = new ConfigSetting(config, "auction setting.use refresh cool down", true, "Should the refresh cooldown be enabled?"); public static final ConfigSetting REFRESH_COOL_DOWN = new ConfigSetting(config, "auction setting.refresh cool down", 2, "How many seconds should pass before the player can refresh the auction house again?"); + public static final ConfigSetting ALLOW_PURCHASE_IF_INVENTORY_FULL = new ConfigSetting(config, "auction setting.allow purchase with full inventory", true, "Should auction house allow players to buy items even if their", "inventory is full, if true, items will be dropped on the floor if there is no room."); /* =============================== * DATABASE OPTIONS diff --git a/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java b/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java index 7108505..f75abb1 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java +++ b/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java @@ -65,8 +65,6 @@ public class TickAuctionsTask extends BukkitRunnable { AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent); if (!auctionEndEvent.isCancelled()) { - // since they're online, try to add the item to their inventory - PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem())); // withdraw money and give to the owner AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice()); AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice()); @@ -87,7 +85,20 @@ public class TickAuctionsTask extends BukkitRunnable { AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer()); } - AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey()); + // since they're online, try to add the item to their inventory + // TODO CLEAN THIS UP A BIT + if (Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean()) { + PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem())); + AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey()); + } else { + if (offlinePlayer.getPlayer().getInventory().firstEmpty() == -1) { + item.setOwner(offlinePlayer.getUniqueId()); + item.setExpired(true); + } else { + PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem())); + AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey()); + } + } } } else { diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index 3bbfd70..97c57de 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -8,7 +8,8 @@ general: blockeditem: "&cYou are not allowed to auction that item. (%item%)" air: "&cSorry, but you cannot sell air o.O" blocked: "&cSorry, you are not allowed to sell &e%item%" - sellinglimit: "You cannot sell more items, please remove/sell current active items" + sellinglimit: "&cYou cannot sell more items, please remove/sell current active items" + noroom: "&cPlease clear room in your inventory to purchase that item." pricing: minbaseprice: "&cThe minimum base price must be &a$%price%" @@ -52,4 +53,28 @@ auction: nobid: "&e%player% listed &fx%amount% &6%item% &efor &a%base_price%" bidwon: "&eYou won the bid for&fx%amount% &6%item% &efor &a%price%" itemsold: "&eYou sold &6%item% &eto &6%buyer_name% &efor &a%price%" - itemnotavailable: "&cThat item is no longer available :(" \ No newline at end of file + itemnotavailable: "&cThat item is no longer available :(" + +commands: + syntax: + active: "active" + auctionhouse: "/ah" + convert: "convert" + expired: "expired" + reload: "reload" + search: "search " + sell: "sell [bidStart] [bidIncr]" + settings: "settings" + transactions: "transactions" + upload: "upload" + description: + active: "View all your auction listings" + auctionhouse: "Main command for the plugin, it opens the auction window." + convert: "Used to make an attempted conversion from < 2.0.0+" + expired: "View all your expired/cancelled listings" + reload: "Reload plugin files" + search: "Search for specific item(s) in the auction house" + sell: "Used to put an item up for auction" + settings: "Open the in-game config editor" + transactions: "Used to open the transactions menu" + upload: "Used to upload flat file data to the database" \ No newline at end of file