Skip to content

Commit

Permalink
Update Physical Currency
Browse files Browse the repository at this point in the history
  • Loading branch information
teraprath committed Nov 15, 2024
1 parent 6d4d297 commit b1c15f1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 82 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'de.virtualplayground'
version = '1.0.0'
version = '1.0.1'

repositories {
mavenCentral()
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/de/virtualplayground/bank/VirtualBanks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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("<gold>VP Coins")).setLore(Lang.parse("<gray>Wert: <yellow>1"))));
itemManager.register(new CustomItem("coins_10", new ItemBuilder(Material.GOLD_BLOCK).setName(Lang.parse("<gold>VP Coins")).setLore(Lang.parse("<gray>Wert: <yellow>10"))));
itemManager.register(new CustomItem("coins_50", new ItemBuilder(Material.EMERALD_BLOCK).setName(Lang.parse("<gold>VP Coins")).setLore(Lang.parse("<gray>Wert: <yellow>50"))));
itemManager.register(new CustomItem("coins_100", new ItemBuilder(Material.DIAMOND_BLOCK).setName(Lang.parse("<gold>VP Coins")).setLore(Lang.parse("<gray>Wert: <yellow>100"))));
for (Currency.Item item : Currency.Item.values()) {
itemManager.register(new CustomItem("coins_" + item.getValue(), new ItemBuilder(item.getType()).setName(Lang.parse("<gold><bold>VP Coins")).setLore(Lang.parse("<gray>Wert: <yellow>" + item.getValue()))));
}
}

public MainConfig getMainConfig() {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/de/virtualplayground/bank/currency/Currency.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
4 changes: 1 addition & 3 deletions src/main/java/de/virtualplayground/bank/gui/BankMainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("<gold>Einzahlen"))
Expand Down
55 changes: 19 additions & 36 deletions src/main/java/de/virtualplayground/bank/gui/DepositGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -41,45 +46,23 @@ public void onOpen(InventoryOpenEvent event) {
bankMainGui.open(player);
}));

setItem(19, new GuiIcon(new ItemBuilder(Material.IRON_BLOCK)
.setName(Lang.parse("<yellow>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("<yellow>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("<yellow>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("<yellow>" + 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("<yellow>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);
}
Expand Down
52 changes: 16 additions & 36 deletions src/main/java/de/virtualplayground/bank/gui/PayOutGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -41,45 +43,23 @@ public void onOpen(InventoryOpenEvent event) {
bankMainGui.open(player);
}));

setItem(19, new GuiIcon(new ItemBuilder(Material.IRON_BLOCK)
.setName(Lang.parse("<yellow>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("<yellow>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("<yellow>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("<yellow>" + 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("<yellow>100"))
).onClick(e -> {
if (virtualPlayer.getCoins() >= 100) {
player.getInventory().addItem(itemManager.getItem("coins_100").build());
virtualPlayer.removeCoins(100);
updateBalance(virtualPlayer);
}
}));
slot++;
}

updateBalance(virtualPlayer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -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 ]
Expand Down

0 comments on commit b1c15f1

Please sign in to comment.