From b1c15f1256f25c8ec2d989e37e9b8c4134bbc820 Mon Sep 17 00:00:00 2001 From: Terry <68700354+teraprath@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:49:28 +0100 Subject: [PATCH] Update Physical Currency --- build.gradle | 2 +- .../virtualplayground/bank/VirtualBanks.java | 9 ++- .../bank/currency/Currency.java | 32 +++++++++++ .../bank/gui/BankMainGui.java | 4 +- .../bank/gui/DepositGui.java | 55 +++++++------------ .../virtualplayground/bank/gui/PayOutGui.java | 52 ++++++------------ src/main/resources/paper-plugin.yml | 2 +- 7 files changed, 74 insertions(+), 82 deletions(-) create mode 100644 src/main/java/de/virtualplayground/bank/currency/Currency.java diff --git a/build.gradle b/build.gradle index cbd23b3..34ab763 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'de.virtualplayground' -version = '1.0.0' +version = '1.0.1' repositories { mavenCentral() diff --git a/src/main/java/de/virtualplayground/bank/VirtualBanks.java b/src/main/java/de/virtualplayground/bank/VirtualBanks.java index cc5dc52..1d0a16c 100644 --- a/src/main/java/de/virtualplayground/bank/VirtualBanks.java +++ b/src/main/java/de/virtualplayground/bank/VirtualBanks.java @@ -4,11 +4,11 @@ import de.virtualplayground.api.item.CustomItemManager; import de.virtualplayground.bank.command.BankCommand; import de.virtualplayground.bank.config.MainConfig; +import de.virtualplayground.bank.currency.Currency; import de.virtualplayground.bank.listener.NpcListener; import de.virtualplayground.lib.item.CustomItem; import de.virtualplayground.lib.item.ItemBuilder; import de.virtualplayground.lib.lang.Lang; -import org.bukkit.Material; import org.bukkit.plugin.java.JavaPlugin; public final class VirtualBanks extends JavaPlugin { @@ -32,10 +32,9 @@ public void onEnable() { } private void createItems(CustomItemManager itemManager) { - itemManager.register(new CustomItem("coins_1", new ItemBuilder(Material.IRON_BLOCK).setName(Lang.parse("VP Coins")).setLore(Lang.parse("Wert: 1")))); - itemManager.register(new CustomItem("coins_10", new ItemBuilder(Material.GOLD_BLOCK).setName(Lang.parse("VP Coins")).setLore(Lang.parse("Wert: 10")))); - itemManager.register(new CustomItem("coins_50", new ItemBuilder(Material.EMERALD_BLOCK).setName(Lang.parse("VP Coins")).setLore(Lang.parse("Wert: 50")))); - itemManager.register(new CustomItem("coins_100", new ItemBuilder(Material.DIAMOND_BLOCK).setName(Lang.parse("VP Coins")).setLore(Lang.parse("Wert: 100")))); + for (Currency.Item item : Currency.Item.values()) { + itemManager.register(new CustomItem("coins_" + item.getValue(), new ItemBuilder(item.getType()).setName(Lang.parse("VP Coins")).setLore(Lang.parse("Wert: " + item.getValue())))); + } } public MainConfig getMainConfig() { diff --git a/src/main/java/de/virtualplayground/bank/currency/Currency.java b/src/main/java/de/virtualplayground/bank/currency/Currency.java new file mode 100644 index 0000000..4d87882 --- /dev/null +++ b/src/main/java/de/virtualplayground/bank/currency/Currency.java @@ -0,0 +1,32 @@ +package de.virtualplayground.bank.currency; + +import org.bukkit.Material; + +public class Currency { + + public enum Item { + + FIVE(5, Material.IRON_BLOCK), + TEN(10, Material.GOLD_BLOCK), + HUNDRED(100, Material.EMERALD_BLOCK), + THOUSAND(1000, Material.DIAMOND_BLOCK), + TEN_THOUSAND(10000, Material.NETHERITE_BLOCK); + + final int value; + final Material type; + + private Item(int v, Material t) { + value = v; + type = t; + } + + public int getValue() { + return value; + } + + public Material getType() { + return type; + } + } + +} diff --git a/src/main/java/de/virtualplayground/bank/gui/BankMainGui.java b/src/main/java/de/virtualplayground/bank/gui/BankMainGui.java index e87ee8f..3cd7e24 100644 --- a/src/main/java/de/virtualplayground/bank/gui/BankMainGui.java +++ b/src/main/java/de/virtualplayground/bank/gui/BankMainGui.java @@ -24,9 +24,7 @@ public void onOpen(InventoryOpenEvent event) { Player player = (Player) event.getPlayer(); - for (int slot = 0; slot < getInventory().getSize(); slot++) { - setItem(slot, new GuiIcon(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setName(Component.text("")))); - } + fill(new GuiIcon(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).setName(Component.text("")))); setItem(11, new GuiIcon(new ItemBuilder(Material.YELLOW_WOOL) .setName(Lang.parse("Einzahlen")) diff --git a/src/main/java/de/virtualplayground/bank/gui/DepositGui.java b/src/main/java/de/virtualplayground/bank/gui/DepositGui.java index 36d3304..8aaf960 100644 --- a/src/main/java/de/virtualplayground/bank/gui/DepositGui.java +++ b/src/main/java/de/virtualplayground/bank/gui/DepositGui.java @@ -3,22 +3,27 @@ import de.virtualplayground.api.VirtualAPI; import de.virtualplayground.api.item.CustomItemManager; import de.virtualplayground.api.player.VirtualPlayer; +import de.virtualplayground.bank.currency.Currency; import de.virtualplayground.lib.gui.Gui; import de.virtualplayground.lib.gui.GuiIcon; +import de.virtualplayground.lib.item.CustomItem; import de.virtualplayground.lib.item.ItemBuilder; import de.virtualplayground.lib.lang.Lang; import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; +import java.util.HashSet; public class DepositGui extends Gui { private final BankMainGui bankMainGui; public DepositGui(@Nonnull BankMainGui bankMainGui) { + super(Component.text("Bank > Einzahlen"), 5); this.bankMainGui = bankMainGui; } @@ -41,45 +46,23 @@ public void onOpen(InventoryOpenEvent event) { bankMainGui.open(player); })); - setItem(19, new GuiIcon(new ItemBuilder(Material.IRON_BLOCK) - .setName(Lang.parse("1")) - ).onClick(e -> { - if (player.getInventory().containsAtLeast(itemManager.getItem("coins_1").build(), 1)) { - player.getInventory().removeItem(itemManager.getItem("coins_1").build()); - virtualPlayer.addCoins(1); - updateBalance(virtualPlayer); - } - })); + int slot = 20; + for (Currency.Item item : Currency.Item.values()) { - setItem(21, new GuiIcon(new ItemBuilder(Material.GOLD_BLOCK) - .setName(Lang.parse("10")) - ).onClick(e -> { - if (player.getInventory().containsAtLeast(itemManager.getItem("coins_10").build(), 1)) { - player.getInventory().removeItem(itemManager.getItem("coins_10").build()); - virtualPlayer.addCoins(10); - updateBalance(virtualPlayer); - } - })); + ItemStack itemStack = itemManager.getItem("coins_" + item.getValue()).build(); - setItem(23, new GuiIcon(new ItemBuilder(Material.EMERALD_BLOCK) - .setName(Lang.parse("50")) - ).onClick(e -> { - if (player.getInventory().containsAtLeast(itemManager.getItem("coins_50").build(), 1)) { - player.getInventory().removeItem(itemManager.getItem("coins_50").build()); - virtualPlayer.addCoins(50); - updateBalance(virtualPlayer); - } - })); + setItem(slot, new GuiIcon(new ItemBuilder(item.getType()) + .setName(Lang.parse("" + item.getValue())) + ).onClick(e -> { + if (player.getInventory().containsAtLeast(itemStack, 1)) { + player.getInventory().removeItem(itemStack); + virtualPlayer.addCoins(item.getValue()); + updateBalance(virtualPlayer); + } + })); - setItem(25, new GuiIcon(new ItemBuilder(Material.DIAMOND_BLOCK) - .setName(Lang.parse("100")) - ).onClick(e -> { - if (player.getInventory().containsAtLeast(itemManager.getItem("coins_100").build(), 1)) { - player.getInventory().removeItem(itemManager.getItem("coins_100").build()); - virtualPlayer.addCoins(100); - updateBalance(virtualPlayer); - } - })); + slot++; + } updateBalance(virtualPlayer); } diff --git a/src/main/java/de/virtualplayground/bank/gui/PayOutGui.java b/src/main/java/de/virtualplayground/bank/gui/PayOutGui.java index acce48b..cef30e9 100644 --- a/src/main/java/de/virtualplayground/bank/gui/PayOutGui.java +++ b/src/main/java/de/virtualplayground/bank/gui/PayOutGui.java @@ -3,6 +3,7 @@ import de.virtualplayground.api.VirtualAPI; import de.virtualplayground.api.item.CustomItemManager; import de.virtualplayground.api.player.VirtualPlayer; +import de.virtualplayground.bank.currency.Currency; import de.virtualplayground.lib.gui.Gui; import de.virtualplayground.lib.gui.GuiIcon; import de.virtualplayground.lib.item.ItemBuilder; @@ -11,6 +12,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; @@ -41,45 +43,23 @@ public void onOpen(InventoryOpenEvent event) { bankMainGui.open(player); })); - setItem(19, new GuiIcon(new ItemBuilder(Material.IRON_BLOCK) - .setName(Lang.parse("1")) - ).onClick(e -> { - if (virtualPlayer.getCoins() >= 1) { - player.getInventory().addItem(itemManager.getItem("coins_1").build()); - virtualPlayer.removeCoins(1); - updateBalance(virtualPlayer); - } - })); + int slot = 20; + for (Currency.Item item : Currency.Item.values()) { - setItem(21, new GuiIcon(new ItemBuilder(Material.GOLD_BLOCK) - .setName(Lang.parse("10")) - ).onClick(e -> { - if (virtualPlayer.getCoins() >= 10) { - player.getInventory().addItem(itemManager.getItem("coins_10").build()); - virtualPlayer.removeCoins(10); - updateBalance(virtualPlayer); - } - })); + ItemStack itemStack = itemManager.getItem("coins_" + item.getValue()).build(); - setItem(23, new GuiIcon(new ItemBuilder(Material.EMERALD_BLOCK) - .setName(Lang.parse("50")) - ).onClick(e -> { - if (virtualPlayer.getCoins() >= 50) { - player.getInventory().addItem(itemManager.getItem("coins_50").build()); - virtualPlayer.removeCoins(50); - updateBalance(virtualPlayer); - } - })); + setItem(slot, new GuiIcon(new ItemBuilder(item.getType()) + .setName(Lang.parse("" + item.getValue())) + ).onClick(e -> { + if (virtualPlayer.getCoins() >= item.getValue()) { + player.getInventory().addItem(itemStack); + virtualPlayer.removeCoins(item.getValue()); + updateBalance(virtualPlayer); + } + })); - setItem(25, new GuiIcon(new ItemBuilder(Material.DIAMOND_BLOCK) - .setName(Lang.parse("100")) - ).onClick(e -> { - if (virtualPlayer.getCoins() >= 100) { - player.getInventory().addItem(itemManager.getItem("coins_100").build()); - virtualPlayer.removeCoins(100); - updateBalance(virtualPlayer); - } - })); + slot++; + } updateBalance(virtualPlayer); } diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml index 3fae869..ac51abd 100644 --- a/src/main/resources/paper-plugin.yml +++ b/src/main/resources/paper-plugin.yml @@ -1,5 +1,5 @@ name: VirtualBanks -version: '1.0.0' +version: '1.0.1' main: de.virtualplayground.bank.VirtualBanks api-version: '1.21' authors: [ MrMending ]