Work on TransactionListener.java
This commit is contained in:
parent
3aa8414c5b
commit
f3030afa33
|
|
@ -45,10 +45,23 @@ public class ShopTypeConfig {
|
|||
public List<String> activeSignLines = List.of("<green>[Shop]", "", "", "");
|
||||
public List<String> inActiveSignLines = List.of("<green>[Shop]", "right click", "to manage", "<ownername>");
|
||||
public List<String> expiredSignLines = List.of("[Shop]", "expired", "", "<ownername>");
|
||||
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 = "<red>You do not have enough space in your inventory to buy from this shop.";
|
||||
public String playerNoFunds = "<red>You do not have sufficient funds to trade with this shop.";
|
||||
public String playerBought = "<white>You bought <amount> <item>(s) from <shopownername> 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 shopNoStock = "<red>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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user