Refactor PlayerShops to use Dialogs.
This commit is contained in:
@@ -12,7 +12,12 @@ import java.util.UUID;
|
||||
public class PlayerSettings {
|
||||
public enum Option {
|
||||
SALE_OWNER_NOTIFICATIONS, SALE_USER_NOTIFICATIONS,
|
||||
STOCK_NOTIFICATIONS, DISCORD_STOCK_NOTIFICATIONS
|
||||
STOCK_NOTIFICATIONS, DISCORD_STOCK_NOTIFICATIONS;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name().toLowerCase().replace("_", " ");
|
||||
}
|
||||
}
|
||||
|
||||
private final UUID uuid;
|
||||
|
||||
@@ -3,19 +3,25 @@ package com.alttd.playershops.shop;
|
||||
import com.alttd.playershops.PlayerShops;
|
||||
import com.alttd.playershops.events.*;
|
||||
import com.alttd.playershops.utils.*;
|
||||
import com.alttd.playershops.utils.sprite.MaterialSprites;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
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.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.sign.Side;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.*;
|
||||
@@ -31,8 +37,8 @@ public class PlayerShop {
|
||||
private final Location signLocation;
|
||||
private final Location shopLocation;
|
||||
private String server;
|
||||
private double price;
|
||||
private int amount;
|
||||
private double price = 0;
|
||||
private int amount = 1;
|
||||
private double balance;
|
||||
private ItemStack itemStack;
|
||||
@Setter
|
||||
@@ -148,7 +154,7 @@ public class PlayerShop {
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return type != ShopType.NONE;
|
||||
return type != ShopType.NONE && itemStack != null;
|
||||
}
|
||||
|
||||
public void updateSign() {
|
||||
@@ -172,11 +178,12 @@ public class PlayerShop {
|
||||
public void run() {
|
||||
if (!(signLocation.getBlock().getState() instanceof Sign signBlock)) return;
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
Component itemComponent = getItemStack() == null ? ShopUtil.trimmedItemNameComponent(getItemStack()): MaterialSprites.get(getItemStack().getType()).append(Component.space()).append(ShopUtil.trimmedItemNameComponent(getItemStack()));
|
||||
TagResolver tagResolver = TagResolver.resolver(
|
||||
Placeholder.unparsed("ownername", getOwnerName()),
|
||||
Placeholder.unparsed("price", trimPrice(String.valueOf(ShopUtil.round(getPrice())))),
|
||||
Placeholder.unparsed("amount", String.valueOf(getAmount())),
|
||||
Placeholder.component("itemname", ShopUtil.trimmedItemNameComponent(getItemStack()))
|
||||
Placeholder.component("itemname", itemComponent)
|
||||
);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
signBlock.getSide(Side.FRONT).line(i, miniMessage.deserialize(signLines.get(i), tagResolver));
|
||||
@@ -452,4 +459,25 @@ public class PlayerShop {
|
||||
+ " balance :" + this.balance
|
||||
+ " lastTransaction :" + this.lastTransaction;
|
||||
}
|
||||
|
||||
public Component getHoverComponent(Player player) {
|
||||
Component component = ShopUtil.itemNameComponent(getItemStack())
|
||||
.append(Component.newline())
|
||||
.append(Component.newline())
|
||||
.append(Component.text("ShopType: " + type))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("Price: " + price))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("ShopType: " + amount))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("World: " + shopLocation.getWorld().getName()))
|
||||
.append(Component.newline())
|
||||
.append(Component.text("Coordinates: " + shopLocation.getBlockX() + ", " + shopLocation.getBlockY() + ", " + shopLocation.getBlockZ()))
|
||||
;
|
||||
if (getOwnerUUID().equals(player.getUniqueId())) {
|
||||
component = component.append(Component.newline()).append(Component.text("Balance: " + balance));
|
||||
}
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user