Added messages/placeholders for failed transactions

This commit is contained in:
Teriuihi 2022-08-28 20:50:29 +02:00
parent fe82ccfa43
commit 09c3349048
2 changed files with 17 additions and 4 deletions

View File

@ -59,11 +59,15 @@ public class ShopTypeConfig {
public String shopSold = "<white><user> bought <amount> <item>(s) from you for <price>."; public String shopSold = "<white><user> bought <amount> <item>(s) from you for <price>.";
public String shopInventoryFull = "<red>This shop does not have enough space in its inventory."; public String shopInventoryFull = "<red>This shop does not have enough space in its inventory.";
public String shopNoStock = "<red>This shop is out of stock."; public String shopNoStock = "<red>This shop is out of stock.";
public String yourShopNoFunds = "<red>Your <item> shop at <location> is out of funds";
public String yourShopNoStock = "<red>Your <item> shop at <location> is out of stock";
private void transactionMessages() { private void transactionMessages() {
playerInventoryFull = getString("transaction.player-inventory-full", playerInventoryFull); playerInventoryFull = getString("transaction.player-inventory-full", playerInventoryFull);
playerNoFunds = getString("transaction.player-no-funds", playerNoFunds); playerNoFunds = getString("transaction.player-no-funds", playerNoFunds);
shopInventoryFull = getString("transaction.shop-inventory-full", shopInventoryFull); shopInventoryFull = getString("transaction.shop-inventory-full", shopInventoryFull);
shopNoStock = getString("transaction.shop-no-stock", shopNoStock); shopNoStock = getString("transaction.shop-no-stock", shopNoStock);
yourShopNoFunds = getString("transaction.your-shop-no-funds", yourShopNoFunds);
yourShopNoStock = getString("transaction.your-shop-no-stock", yourShopNoStock);
} }
} }

View File

@ -6,14 +6,13 @@ import com.alttd.playershops.handler.ShopHandler;
import com.alttd.playershops.hook.WorldGuardHook; import com.alttd.playershops.hook.WorldGuardHook;
import com.alttd.playershops.shop.PlayerShop; import com.alttd.playershops.shop.PlayerShop;
import com.alttd.playershops.shop.TransactionError; import com.alttd.playershops.shop.TransactionError;
import com.alttd.playershops.storage.database.DatabaseHelper;
import com.alttd.playershops.utils.Logger; import com.alttd.playershops.utils.Logger;
import com.alttd.playershops.utils.ShopUtil; import com.alttd.playershops.utils.ShopUtil;
import com.alttd.playershops.utils.Util; import com.alttd.playershops.utils.Util;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.Location;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -106,7 +105,9 @@ public class TransactionListener extends EventListener {
TagResolver placeholders = TagResolver.resolver( TagResolver placeholders = TagResolver.resolver(
Placeholder.unparsed("ownername", shop.getOwnerName()), Placeholder.unparsed("ownername", shop.getOwnerName()),
Placeholder.unparsed("price", shop.getPrice() + ""), Placeholder.unparsed("price", shop.getPrice() + ""),
Placeholder.unparsed("amount", shop.getAmount() + "") Placeholder.unparsed("amount", shop.getAmount() + ""),
Placeholder.unparsed("item", Util.capitalize(shop.getItemStack().getType().toString())),
Placeholder.unparsed("location", formatLocation(shop.getShopLocation()))
); );
if (transactionError != TransactionError.NONE) { if (transactionError != TransactionError.NONE) {
switch (transactionError) { switch (transactionError) {
@ -114,7 +115,7 @@ public class TransactionListener extends EventListener {
Player shopOwner = Bukkit.getPlayer(shop.getOwnerUUID()); Player shopOwner = Bukkit.getPlayer(shop.getOwnerUUID());
if (shopOwner != null && notifyOwner(shop)) { if (shopOwner != null && notifyOwner(shop)) {
// TODO notify shopowner in game if not on cooldown and once per day on discord if linked and enabled // 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)); shopOwner.sendActionBar(Util.parseMiniMessage(shop.getType().getShopTypeConfig().yourShopNoFunds, placeholders));
} }
player.sendMiniMessage(shop.getType().getShopTypeConfig().shopNoStock, placeholders); player.sendMiniMessage(shop.getType().getShopTypeConfig().shopNoStock, placeholders);
} }
@ -124,6 +125,7 @@ public class TransactionListener extends EventListener {
case INVENTORY_FULL_SHOP -> { case INVENTORY_FULL_SHOP -> {
Player shopOwner = Bukkit.getPlayer(shop.getOwnerUUID()); Player shopOwner = Bukkit.getPlayer(shop.getOwnerUUID());
if (shopOwner != null && notifyOwner(shop)) { if (shopOwner != null && notifyOwner(shop)) {
shopOwner.sendActionBar(Util.parseMiniMessage(shop.getType().getShopTypeConfig().yourShopNoStock, placeholders));
// TODO notify shopowner in game if not on cooldown and once per day on discord if linked and enabled // 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, placeholders); player.sendMiniMessage(shop.getType().getShopTypeConfig().shopInventoryFull, placeholders);
@ -138,6 +140,13 @@ public class TransactionListener extends EventListener {
plugin.getDatabaseHelper().logTransaction(player, shop, orders); plugin.getDatabaseHelper().logTransaction(player, shop, orders);
} }
private String formatLocation(Location location) {
return Util.capitalize(location.getWorld().getName()) + ": " +
" " + (int) location.getX() +
", " + (int) location.getY() +
", " + (int) location.getZ();
}
private boolean notifyOwner(PlayerShop playerShop) { private boolean notifyOwner(PlayerShop playerShop) {
// TODO notify shopowner in game if not on cooldown and once per day on discord if linked and enabled // TODO notify shopowner in game if not on cooldown and once per day on discord if linked and enabled
return playerShop.isNotifiedOwner(); return playerShop.isNotifiedOwner();