Add a way to display ShopTransaction.java
This commit is contained in:
parent
f898794b1a
commit
5e5d70bf53
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.alttd.playershops.gui;
|
||||||
|
|
||||||
|
import com.alttd.playershops.config.MessageConfig;
|
||||||
|
import com.alttd.playershops.shop.PlayerShop;
|
||||||
|
import com.alttd.playershops.shop.ShopTransaction;
|
||||||
|
import com.alttd.playershops.utils.ShopUtil;
|
||||||
|
import com.alttd.playershops.utils.Util;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ListTransactionsGui extends AbstractGui {
|
||||||
|
|
||||||
|
private final List<ShopTransaction> transactions;
|
||||||
|
public ListTransactionsGui(UUID uuid, PlayerShop shop) {
|
||||||
|
super(uuid);
|
||||||
|
this.transactions = shop.getTransactions();
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.unparsed("page", Integer.toString(pageIndex + 1)),
|
||||||
|
Placeholder.unparsed("pages", Integer.toString((int) Math.ceil(transactions.size() / 45)))
|
||||||
|
);
|
||||||
|
this.inventory = Bukkit.createInventory(this, INV_SIZE, Util.parseMiniMessage(MessageConfig.GUI_LIST_TRANSACTIONS_TITLE, placeholders));
|
||||||
|
initInvContents();
|
||||||
|
makeMenuBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void initInvContents() {
|
||||||
|
super.initInvContents();
|
||||||
|
|
||||||
|
int startIndex = pageIndex * 45;
|
||||||
|
ItemStack item;
|
||||||
|
for (int i = startIndex; i < transactions.size(); i++) {
|
||||||
|
item = ShopUtil.getShopTransactionItem(transactions.get(i));
|
||||||
|
|
||||||
|
if (!addItem(item)) {
|
||||||
|
addNextPageItem();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pageIndex > 0) {
|
||||||
|
addPrevPageItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -88,7 +88,9 @@ public class ShopManagementGui extends AbstractGui {
|
||||||
getPlayer().sendMiniMessage("<red>You can't widraw money from this shop", null);
|
getPlayer().sendMiniMessage("<red>You can't widraw money from this shop", null);
|
||||||
}
|
}
|
||||||
} else if (slot == GuiIcon.MANAGE_SHOP_SALES.getSlot() && GuiIcon.MANAGE_SHOP_SALES.getItemStack().equals(item)) {
|
} else if (slot == GuiIcon.MANAGE_SHOP_SALES.getSlot() && GuiIcon.MANAGE_SHOP_SALES.getItemStack().equals(item)) {
|
||||||
|
ListTransactionsGui listTransactionsGui = new ListTransactionsGui(uuid, shop);
|
||||||
|
listTransactionsGui.setLastGui(this);
|
||||||
|
listTransactionsGui.open();
|
||||||
} else if (slot == GuiIcon.MANAGE_SHOP_ITEM.getSlot() && GuiIcon.MANAGE_SHOP_ITEM.getItemStack().equals(item)) {
|
} else if (slot == GuiIcon.MANAGE_SHOP_ITEM.getSlot() && GuiIcon.MANAGE_SHOP_ITEM.getItemStack().equals(item)) {
|
||||||
openChangePrompt(ConversationType.CHANGE_ITEM);
|
openChangePrompt(ConversationType.CHANGE_ITEM);
|
||||||
} else if (slot == GuiIcon.MANAGE_SHOP_TYPE.getSlot() && GuiIcon.MANAGE_SHOP_TYPE.getItemStack().equals(item)) {
|
} else if (slot == GuiIcon.MANAGE_SHOP_TYPE.getSlot() && GuiIcon.MANAGE_SHOP_TYPE.getItemStack().equals(item)) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -50,6 +51,8 @@ public class PlayerShop {
|
||||||
private boolean notifiedOwner = false;
|
private boolean notifiedOwner = false;
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
private boolean dirty;
|
private boolean dirty;
|
||||||
|
@Getter
|
||||||
|
private List<ShopTransaction> transactions = new ArrayList<>();
|
||||||
|
|
||||||
public PlayerShop(Location shopLocation, Location signLocation, Player player) {
|
public PlayerShop(Location shopLocation, Location signLocation, Player player) {
|
||||||
this(shopLocation, signLocation, player.getUniqueId(), player.getName());
|
this(shopLocation, signLocation, player.getUniqueId(), player.getName());
|
||||||
|
|
@ -270,6 +273,7 @@ public class PlayerShop {
|
||||||
InventoryUtils.addItem(player.getInventory(), itemStack);
|
InventoryUtils.addItem(player.getInventory(), itemStack);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
|
||||||
|
addTransaction(new ShopTransaction(ShopAction.SELL, player.getName(), orders, price));
|
||||||
return TransactionError.NONE;
|
return TransactionError.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,6 +314,7 @@ public class PlayerShop {
|
||||||
InventoryUtils.addItem(getInventory(), itemStack);
|
InventoryUtils.addItem(getInventory(), itemStack);
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
|
|
||||||
|
addTransaction(new ShopTransaction(ShopAction.BUY, player.getName(), orders, price));
|
||||||
return TransactionError.NONE;
|
return TransactionError.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,6 +384,10 @@ public class PlayerShop {
|
||||||
updateSign();
|
updateSign();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addTransaction(ShopTransaction transaction) {
|
||||||
|
transactions.add(transaction);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Shop: " + this.getShopID()
|
return "Shop: " + this.getShopID()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
package com.alttd.playershops.shop;
|
||||||
|
|
||||||
|
public record ShopTransaction(ShopAction shopAction, String Name, int transactions, double value) {}
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
package com.alttd.playershops.utils;
|
package com.alttd.playershops.utils;
|
||||||
|
|
||||||
|
import com.alttd.playershops.gui.GuiIcon;
|
||||||
import com.alttd.playershops.shop.PlayerShop;
|
import com.alttd.playershops.shop.PlayerShop;
|
||||||
|
import com.alttd.playershops.shop.ShopTransaction;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
@ -12,8 +16,11 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -150,6 +157,27 @@ public class ShopUtil {
|
||||||
return skull;
|
return skull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ItemStack getShopTransactionItem(ShopTransaction shopTransaction) {
|
||||||
|
ItemStack itemStack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||||
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
|
List<Component> lore = new ArrayList<>();
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.unparsed("name", shopTransaction.Name()),
|
||||||
|
Placeholder.unparsed("amount", shopTransaction.transactions() + ""),
|
||||||
|
Placeholder.unparsed("value", shopTransaction.value() + ""),
|
||||||
|
Placeholder.unparsed("action", shopTransaction.shopAction().name() + "")
|
||||||
|
);
|
||||||
|
lore.add(Util.parseMiniMessage("PlayerName: <name>", placeholders));
|
||||||
|
lore.add(Util.parseMiniMessage("Amount: <amount>", placeholders));
|
||||||
|
lore.add(Util.parseMiniMessage("Value: <value>", placeholders));
|
||||||
|
lore.add(Util.parseMiniMessage("Action: <action>", placeholders));
|
||||||
|
|
||||||
|
meta.lore(lore);
|
||||||
|
itemStack.setItemMeta(meta);
|
||||||
|
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO upgrade this to an util method check if owner/trusted and open management interface
|
// TODO upgrade this to an util method check if owner/trusted and open management interface
|
||||||
public static boolean canManageShop(Player player, PlayerShop playerShop) {
|
public static boolean canManageShop(Player player, PlayerShop playerShop) {
|
||||||
if (playerShop.getOwnerUUID().equals(player.getUniqueId())) {
|
if (playerShop.getOwnerUUID().equals(player.getUniqueId())) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user