From aad20e400cd1e585686fdd83794d8f7d048ef946 Mon Sep 17 00:00:00 2001 From: OllieJW <71931263+OllieJW@users.noreply.github.com> Date: Fri, 8 Oct 2021 15:34:28 +0100 Subject: [PATCH] Add files via upload --- pom.xml | 2 +- .../java/me/olliejw/oremarket/OreMarket.java | 7 -- .../oremarket/listeners/InventoryEvents.java | 84 +++++++++++++++++-- 3 files changed, 79 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index cea30d2..c7f192d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.olliejw OreMarket - 2.2.5 + 2.2.6 jar OreMarket diff --git a/src/main/java/me/olliejw/oremarket/OreMarket.java b/src/main/java/me/olliejw/oremarket/OreMarket.java index 22bb2bd..9751aa3 100644 --- a/src/main/java/me/olliejw/oremarket/OreMarket.java +++ b/src/main/java/me/olliejw/oremarket/OreMarket.java @@ -154,13 +154,6 @@ private void createMsgConfig() { e.printStackTrace(); } } - public void reloadMsgConfig() { - try { - msgConfig.load(msgFile); - } catch (IOException | InvalidConfigurationException e) { - e.printStackTrace(); - } - } public static OreMarket main(){ return instance; diff --git a/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java b/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java index 010e8dd..c75cac3 100644 --- a/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java +++ b/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java @@ -51,6 +51,29 @@ private void changePlayerBalance(double Money, HumanEntity player, boolean opera private double balance (HumanEntity Player) { return OreMarket.getEconomy().getBalance((OfflinePlayer) Player); } + /*SPOILER! private int getItemAmount (HumanEntity player, ItemStack item) { + if (item == null) { + return 0; + } + int amount = 0; + for (int i = 0; i < 36; i++) { + ItemStack slot = player.getInventory().getItem(i); + if (slot == null || !slot.isSimilar(item)) { + continue; + } + amount += slot.getAmount(); + } + return amount; + } + private void removeItemAmount (HumanEntity player, ItemStack item) { + for (int i = 0; i < 36; i++) { + ItemStack slot = player.getInventory().getItem(i); + if (slot == null || !slot.equals(item)) { + continue; + } + slot.setAmount(0); + } + }*/ String title = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(OreMarket.main().getGuiConfig().getString("gui.title"))); Placeholders plh = new Placeholders(); @@ -112,11 +135,15 @@ else if (toSend.contains("[msg]")) { int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock"); if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) { - // Take any type of the clicked item (e.g. custom name) - playerInventory.removeItem(event.getCurrentItem()); - } - else { // Take the EXACT item (e.g. exact custom name) + if (!(playerInventory.containsAtLeast(event.getCurrentItem(), 1))) { + String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + return; + } + playerInventory.removeItem(event.getCurrentItem()); + } else { + // Take any type of the clicked item (e.g. custom name) playerInventory.removeItem(clickedItem); } @@ -127,6 +154,45 @@ else if (toSend.contains("[msg]")) { String message = OreMarket.main().getMsgConfig().getString("messages.successfully-sold", "&aYou have successfully sold this item!"); player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } + /* SPOILER!: if ((event.getClick() == ClickType.SHIFT_LEFT)) { // Sell ALL Mode + if (OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly")) { + // You cannot sell this, Buy only item + String message = OreMarket.main().getMsgConfig().getString("messages.buy-only", "&cThis item can only be bought"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + return; + } + + if (!(playerInventory.containsAtLeast(clickedItem, 1))) { + String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + return; + } + + double itemValue = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value"); + int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock"); + int itemAmount = getItemAmount(player, clickedItem); + + if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) { + // Take the EXACT item and amount (e.g. exact custom name) + if (!(playerInventory.containsAtLeast(event.getCurrentItem(), 1))) { + String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + return; + } + removeItemAmount(player, event.getCurrentItem()); + } + else { + // Take any type of the clicked item (e.g. custom name) + removeItemAmount(player, clickedItem); + } + + changePlayerBalance(itemValue*itemAmount, player, false, slot); + OreMarket.main().getGuiConfig().set("items." + slot + ".stock", itemStock+itemAmount); + OreMarket.main().saveGuiConfig(); + + String message = OreMarket.main().getMsgConfig().getString("messages.successfully-sold", "&aYou have successfully sold this item!"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + }*/ if ((event.getClick() == ClickType.RIGHT)) { // Buy Mode if (OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".sellonly")) { // You cannot buy this, Sell only item @@ -138,7 +204,13 @@ else if (toSend.contains("[msg]")) { double itemValue = OreMarket.main().getGuiConfig().getDouble("items." + slot + ".value"); int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock"); + if (itemStock > 0) { + // Is there any stock? + return; + } + if (balance(player) < itemValue) { + // Player has enough money? String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-balance", "&cYou don't have enough money to buy this item!"); player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); return; @@ -147,8 +219,7 @@ else if (toSend.contains("[msg]")) { if (OreMarket.main().getGuiConfig().getBoolean("items." + slot + ".copymeta")) { // Take any type of the clicked item (e.g. custom name) playerInventory.addItem(event.getCurrentItem()); - } - else { + } else { // Take the EXACT item (e.g. exact custom name) playerInventory.addItem(clickedItem); } @@ -160,6 +231,7 @@ else if (toSend.contains("[msg]")) { String message = OreMarket.main().getMsgConfig().getString("messages.successfully-bought", "&aYou have successfully bought the item!"); player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } + mainGUI.createGUI((Player) player); // Reload GUI } }