From f3030afa332ecdddba20afc4e2d5ccbe478c5bfa Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:07:05 +0200 Subject: [PATCH] Work on TransactionListener.java --- .../playershops/config/ShopTypeConfig.java | 15 +++++++- .../listener/TransactionListener.java | 37 ++++++++++++++++--- .../alttd/playershops/shop/PlayerShop.java | 3 ++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/alttd/playershops/config/ShopTypeConfig.java b/src/main/java/com/alttd/playershops/config/ShopTypeConfig.java index 7cb7e37..6634811 100644 --- a/src/main/java/com/alttd/playershops/config/ShopTypeConfig.java +++ b/src/main/java/com/alttd/playershops/config/ShopTypeConfig.java @@ -45,10 +45,23 @@ public class ShopTypeConfig { public List activeSignLines = List.of("[Shop]", "", "", ""); public List inActiveSignLines = List.of("[Shop]", "right click", "to manage", ""); public List expiredSignLines = List.of("[Shop]", "expired", "", ""); - private void textSettings() { + private void signSettings() { activeSignLines = getStringList("sign.active-lines", activeSignLines); inActiveSignLines = getStringList("sign.inactive-lines", inActiveSignLines); expiredSignLines = getStringList("sign.expired-lines", expiredSignLines); } + public String playerInventoryFull = "You do not have enough space in your inventory to buy from this shop."; + public String playerNoFunds = "You do not have sufficient funds to trade with this shop."; + public String playerBought = "You bought (s) from for ."; + public String shopSold = " bought (s) from you for ."; + public String shopInventoryFull = "This shop does not have enough space in its inventory."; + public String shopNoStock = "This shop is out of stock."; + private void transactionMessages() { + playerInventoryFull = getString("transaction.player-inventory-full", playerInventoryFull); + playerNoFunds = getString("transaction.player-no-funds", playerNoFunds); + shopInventoryFull = getString("transaction.shop-inventory-full", shopInventoryFull); + shopNoStock = getString("transaction.shop-no-stock", shopNoStock); + } + } diff --git a/src/main/java/com/alttd/playershops/listener/TransactionListener.java b/src/main/java/com/alttd/playershops/listener/TransactionListener.java index 7470174..af4b39d 100644 --- a/src/main/java/com/alttd/playershops/listener/TransactionListener.java +++ b/src/main/java/com/alttd/playershops/listener/TransactionListener.java @@ -6,6 +6,9 @@ import com.alttd.playershops.handler.ShopHandler; import com.alttd.playershops.hook.WorldGuardHook; import com.alttd.playershops.shop.PlayerShop; import com.alttd.playershops.shop.TransactionError; +import com.alttd.playershops.utils.Util; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -60,6 +63,7 @@ public class TransactionListener extends EventListener { // Failsafe. If we have a shopsign but no block cancel the event, log error save and unload the shop if (!shopHandler.isShopMaterial(playerShop.getShopLocation().getBlock())) { event.setCancelled(true); + // TODO LOG THIS ERROR shopHandler.removeShop(playerShop); } @@ -82,16 +86,39 @@ public class TransactionListener extends EventListener { orders = shop.getItemStack().getMaxStackSize(); TransactionError transactionError = shop.executeTransaction(orders, player); + // TODO minimessage placeholders + if (transactionError != TransactionError.NONE) { switch (transactionError) { - case INVENTORY_FULL_PLAYER -> { - - } - case CANCELLED -> { - } case INSUFFICIENT_FUNDS_SHOP -> { + Player shopOwner = Bukkit.getPlayer(shop.getOwnerUUID()); + if (shopOwner != null && notifyOwner(shop)) { + // TODO notify shopowner in game if not on cooldown and once per day on discord if linked and enabled + shopOwner.sendActionBar(Util.parseMiniMessage(shop.getType().getShopTypeConfig().shopSold, null)); + } + player.sendMiniMessage(shop.getType().getShopTypeConfig().shopNoStock, null); + } + case INSUFFICIENT_FUNDS_PLAYER -> { + player.sendMiniMessage(shop.getType().getShopTypeConfig().playerNoFunds, null); + } + case INVENTORY_FULL_SHOP -> { + Player shopOwner = Bukkit.getPlayer(shop.getOwnerUUID()); + if (shopOwner != null && notifyOwner(shop)) { + // TODO notify shopowner in game if not on cooldown and once per day on discord if linked and enabled + } + player.sendMiniMessage(shop.getType().getShopTypeConfig().shopInventoryFull, null); + } + case INVENTORY_FULL_PLAYER -> { + player.sendMiniMessage(shop.getType().getShopTypeConfig().playerInventoryFull, null); } } + return; } + player.sendActionBar(Util.parseMiniMessage(shop.getType().getShopTypeConfig().playerBought, null)); + } + + private boolean notifyOwner(PlayerShop playerShop) { + // TODO notify shopowner in game if not on cooldown and once per day on discord if linked and enabled + return playerShop.isNotifiedOwner(); } } diff --git a/src/main/java/com/alttd/playershops/shop/PlayerShop.java b/src/main/java/com/alttd/playershops/shop/PlayerShop.java index 09830c5..8228f89 100644 --- a/src/main/java/com/alttd/playershops/shop/PlayerShop.java +++ b/src/main/java/com/alttd/playershops/shop/PlayerShop.java @@ -48,6 +48,9 @@ public class PlayerShop { private ItemStack itemStack; @Getter @Setter private long lastTransaction; + @Getter @Setter + private boolean notifiedOwner = false; + public PlayerShop(Location shopLocation, Location signLocation, Player player) { this(shopLocation, signLocation, player.getUniqueId(), player.getName());