This commit is contained in:
2021-12-23 22:52:13 +01:00
parent 5d7467e062
commit 1feff9e412
7 changed files with 27 additions and 21 deletions
@@ -25,10 +25,10 @@ public class BuyGUI extends GUIMerchant {
private static final MiniMessage miniMessage = MiniMessage.get();
public BuyGUI(VillagerType villagerType) {
public BuyGUI(VillagerType villagerType, EconUser econUser) {
super(MiniMessage.get().parse(Config.BUY_WINDOW,
Template.of("trader", villagerType.getDisplayName()),
Template.of("percentage", "100")), villagerType); //TODO get percentage from player somehow
Template.of("points", String.valueOf(Objects.requireNonNullElse(econUser.getPointsMap().get(villagerType.getName()), 0)))), villagerType);
for (ItemStack itemStack : villagerType.getBuying()) {
Price price = Utilities.getPrice(itemStack);
if (price == null)
@@ -47,7 +47,7 @@ public class BuyGUI extends GUIMerchant {
int trans_pts = (int) (Math.floor(price.getPrice(amount)/ WorthConfig.POINT_MOD) * amount);
EconUser econUser = EconUser.getUser(player.getUniqueId());
int oldPoints = Objects.requireNonNullElse(econUser.getPointsMap().get(villagerType.getName()), 0);
double cost = price.calculatePriceThing(oldPoints, trans_pts);
double cost = price.calculatePriceThing(oldPoints, trans_pts, true);
if (balance < cost) {
player.sendMessage(MiniMessage.get().parse(Config.NOT_ENOUGH_MONEY,
@@ -3,6 +3,7 @@ package com.alttd.GUI.windows;
import com.alttd.GUI.GUIInventory;
import com.alttd.VillagerUI;
import com.alttd.config.Config;
import com.alttd.objects.EconUser;
import com.alttd.objects.VillagerType;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
@@ -12,6 +13,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Objects;
public class OpenGUI extends GUIInventory {
private static final ItemStack BUY = new ItemStack(Material.GOLD_INGOT);
@@ -32,14 +35,14 @@ public class OpenGUI extends GUIInventory {
}
}
public OpenGUI(VillagerType villagerType) {
public OpenGUI(VillagerType villagerType, EconUser econUser) {
super(InventoryType.HOPPER, MiniMessage.get().parse(Config.INITIAL_VILLAGER_WINDOW,
Template.of("trader", villagerType.getDisplayName()),
Template.of("percentage", "100"))); //TODO get percentage from player somehow
Template.of("points", String.valueOf(Objects.requireNonNullElse(econUser.getPointsMap().get(villagerType.getName()), 0)))));
setItem(1, BUY, player -> new BukkitRunnable() {
@Override
public void run() {
BuyGUI buyGUI = new BuyGUI(villagerType);
BuyGUI buyGUI = new BuyGUI(villagerType, econUser);
new BukkitRunnable() {
@Override
public void run() {
@@ -51,7 +54,7 @@ public class OpenGUI extends GUIInventory {
setItem(3, SELL, player -> new BukkitRunnable() {
@Override
public void run() {
SellGUI sellGUI = new SellGUI(villagerType);
SellGUI sellGUI = new SellGUI(villagerType, econUser);
new BukkitRunnable() {
@Override
public void run() {
@@ -28,10 +28,10 @@ public class SellGUI extends GUIMerchant {
private static final MiniMessage miniMessage = MiniMessage.get();
public SellGUI(VillagerType villagerType) {
public SellGUI(VillagerType villagerType, EconUser econUser) {
super(MiniMessage.get().parse(Config.SELL_WINDOW,
Template.of("trader", villagerType.getDisplayName()),
Template.of("percentage", "100")), villagerType); //TODO get percentage from player somehow
Template.of("points", String.valueOf(Objects.requireNonNullElse(econUser.getPointsMap().get(villagerType.getName()), 0)))), villagerType);
for (ItemStack itemStack : villagerType.getSelling()) {
Price price = Utilities.getPrice(itemStack);
if (price == null)
@@ -47,11 +47,10 @@ public class SellGUI extends GUIMerchant {
private void sell(VillagerType villagerType, Player player, Material material, int amount, Price price) {
PlayerInventory inventory = player.getInventory();
if (!inventory.containsAtLeast(new ItemStack(material), amount))
{
if (!inventory.containsAtLeast(new ItemStack(material), amount)) {
player.sendMessage(miniMessage.parse(Config.NOT_ENOUGH_ITEMS,
Template.of("type", material.name()),
Template.of("amount",String.valueOf(amount))));
Template.of("amount", String.valueOf(amount))));
return;
}
@@ -59,7 +58,7 @@ public class SellGUI extends GUIMerchant {
EconUser econUser = EconUser.getUser(player.getUniqueId());
int oldPoints = Objects.requireNonNullElse(econUser.getPointsMap().get(villagerType.getName()), 0);
int trans_pts = (int) ((Math.floor(price.getPrice(amount) / WorthConfig.POINT_MOD) + 1) * amount);
double cost = price.calculatePriceThing(oldPoints, trans_pts);
double cost = price.calculatePriceThing(oldPoints, trans_pts, false);
econ.depositPlayer(player, cost);
econUser.addPoints(villagerType.getName(), -price.getPoints());
@@ -88,8 +87,7 @@ public class SellGUI extends GUIMerchant {
.forEach(itemStack -> {
if (ref.tmpAmount == 0)
return;
if (itemStack.getAmount() > ref.tmpAmount)
{
if (itemStack.getAmount() > ref.tmpAmount) {
itemStack.setAmount(itemStack.getAmount() - ref.tmpAmount);
ref.tmpAmount = 0;
} else {