diff --git a/pom.xml b/pom.xml index 68857f9..0b380fa 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.olliejw OreMarket - 2.3.2 + 2.5.0 jar OreMarket diff --git a/src/main/java/me/olliejw/oremarket/OreMarket.java b/src/main/java/me/olliejw/oremarket/OreMarket.java index 8760801..29998ee 100644 --- a/src/main/java/me/olliejw/oremarket/OreMarket.java +++ b/src/main/java/me/olliejw/oremarket/OreMarket.java @@ -181,27 +181,28 @@ public static Economy getEconomy() { } public void logToFile(String string) { - try { - File dataFolder = getDataFolder(); - if(!dataFolder.exists()) { - dataFolder.mkdir(); - } - File logsFile = new File(getDataFolder(), "logs.txt"); - if (!logsFile.exists()) { - logsFile.createNewFile(); + if (getConfig().getBoolean("logs.enabled")) + try { + File dataFolder = getDataFolder(); + if(!dataFolder.exists()) { + dataFolder.mkdir(); + } + File logsFile = new File(getDataFolder(), "logs.txt"); + if (!logsFile.exists()) { + logsFile.createNewFile(); + } + + SimpleDateFormat formatter = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]: "); + Date date = new Date(System.currentTimeMillis()); + + FileWriter fw = new FileWriter(logsFile, true); + PrintWriter pw = new PrintWriter(fw); + pw.println(formatter.format(date) + ChatColor.stripColor(string.replaceAll("&", "§"))); + pw.flush(); + pw.close(); + } catch (IOException e) { + e.printStackTrace(); } - - SimpleDateFormat formatter = new SimpleDateFormat("[dd/MM/yyyy HH:mm:ss]: "); - Date date = new Date(System.currentTimeMillis()); - - FileWriter fw = new FileWriter(logsFile, true); - PrintWriter pw = new PrintWriter(fw); - pw.println(formatter.format(date) + ChatColor.stripColor(string.replaceAll("&", "§"))); - pw.flush(); - pw.close(); - } catch (IOException e) { - e.printStackTrace(); - } } } diff --git a/src/main/java/me/olliejw/oremarket/chat/ValueUpdates.java b/src/main/java/me/olliejw/oremarket/chat/ValueUpdates.java index 769a6ce..d6bb290 100644 --- a/src/main/java/me/olliejw/oremarket/chat/ValueUpdates.java +++ b/src/main/java/me/olliejw/oremarket/chat/ValueUpdates.java @@ -22,7 +22,7 @@ public void announceValue() { assert message != null; for (Player player: Bukkit.getOnlinePlayers()) { - if (keySection.getBoolean("hide")) { + if (keySection.getBoolean(".flags.hide")) { return; } player.sendMessage(plh.format(message, player, keySection)); diff --git a/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java b/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java index e17e55d..62dfef2 100644 --- a/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java +++ b/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java @@ -19,30 +19,37 @@ import java.util.Objects; public class InventoryEvents implements Listener { - private double calculateTotalWithTax(double price, boolean operation) { + private double calculateTotalWithTax(double price) { double tax = OreMarket.main().getConfig().getDouble("tax", 0.0); - double total; - if (tax == 0.0) { - total = price; - } else { - if (operation) { - total = (price + (price * (tax/100))); - } else { - total = (price - (price * (tax/100))); - } - } - return total; + return price - (tax/100); } - private void changePlayerBalance(double Money, HumanEntity player, boolean operation, int Slot) { // Buy - double total = calculateTotalWithTax(Money, operation); - if (Money > 0) { - if (operation) { // true is take, false is give - OreMarket.getEconomy().withdrawPlayer((OfflinePlayer) player, total); + private void changePlayerBalance(double previous, HumanEntity player, boolean operation, int Slot) { // Buy + /** + @param previous = Ore Value before any changes + @param player = Player whose balance will be changes + @param operation = T=Add F=Remove money + @param slot = Slot's ore that's value will be affected + */ + + double total = calculateTotalWithTax(previous); + + if (previous > 0) { + if (operation) { + OreMarket.getEconomy().withdrawPlayer((OfflinePlayer) player, previous-(total*OreMarket.main().getConfig().getDouble("multiplier"))); + OreMarket.main().getGuiConfig().set("items." + Slot + ".value", + previous+(total*OreMarket.main().getConfig().getDouble("multiplier"))); + // 1000 + (120 x 0.01) + // 1000 + 1.12 + // 1000 -> 1001.12 } else { - OreMarket.getEconomy().depositPlayer((OfflinePlayer) player, total); + OreMarket.getEconomy().depositPlayer((OfflinePlayer) player, previous-(total*OreMarket.main().getConfig().getDouble("multiplier"))); + OreMarket.main().getGuiConfig().set("items." + Slot + ".value", + previous-(total*OreMarket.main().getConfig().getDouble("multiplier"))); + // 1000 - (80 x 0.01) + // 1000 - 0.08 + // 1000 -> 999.92 } } - OreMarket.main().getGuiConfig().set("items." + Slot + ".value", total+(total*(OreMarket.main().getConfig().getDouble("multiplier", 0.01)))); OreMarket.main().saveGuiConfig(); } private double balance (HumanEntity Player) { diff --git a/src/main/java/me/olliejw/oremarket/menus/MainGUI.java b/src/main/java/me/olliejw/oremarket/menus/MainGUI.java index 6c94153..12c00f4 100644 --- a/src/main/java/me/olliejw/oremarket/menus/MainGUI.java +++ b/src/main/java/me/olliejw/oremarket/menus/MainGUI.java @@ -44,7 +44,11 @@ public void createGUI (Player player) { } // Set values - assert name != null; + if (name == null) { + // If a name is not given, we will make it blank + name = " "; + } + meta.setDisplayName(plh.format(name, player, keySection)); meta.setLore(lore); item.setItemMeta(meta); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 60944c1..1a9f72c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,6 +4,10 @@ prefix: '&bOreMarket ' +# Logs.txt settings. More soon +logs: + enabled: true + valuemessage: enabled: true # Time (in minutes) to send this message diff --git a/src/main/resources/gui.yml b/src/main/resources/gui.yml index e51d589..e3fac55 100644 --- a/src/main/resources/gui.yml +++ b/src/main/resources/gui.yml @@ -5,7 +5,9 @@ gui: rows: 3 items: - 0: + + # Buyable items + '11': item: DIAMOND name: '&bDiamond Ore' lore: @@ -17,11 +19,11 @@ items: - '&7Left-Click to sell' cost: 1000 value: 1000 - stock: 100 + stock: 25 flags: buy-sound: BLOCK_ANVIL_PLACE sell-sound: BLOCK_CHEST_OPEN - 1: + '12': item: GOLD_INGOT name: '&6Gold Ingot' lore: @@ -33,9 +35,8 @@ items: - '&7Left-Click to sell' cost: 500 value: 500 - stock: 100 - - 2: + stock: 50 + '13': item: IRON_INGOT name: '&7Iron Ore' lore: @@ -48,8 +49,44 @@ items: cost: 250 value: 250 stock: 100 + '14': + item: NETHERITE_INGOT + name: '&dNetherite Ore' + lore: + - '&aValue: $[value]' + - '&aOriginal: $[cost]' + - '&aStock: [stock]' + - '&aChange: [percent]%' + - '&7Right-Click to buy' + - '&7Left-Click to sell' + cost: 2500 + value: 2500 + stock: 10 + '15': + item: EMERALD + name: '&aEmerald' + lore: + - '&aValue: $[value]' + - '&aOriginal: $[cost]' + - '&aStock: [stock]' + - '&aChange: [percent]%' + - '&7Right-Click to buy' + - '&7Left-Click to sell' + cost: 1250 + value: 1250 + stock: 15 - 5: + # Command Items + '18': + item: PAPER + name: '&aBalance' + lore: + - '&a$[balance]' + commands: + - '[msg] Your balance: [balance]' + flags: + hide: true + '26': item: BARRIER name: '&cClose' lore: @@ -59,12 +96,104 @@ items: flags: hide: true - 6: - item: PAPER - name: '&aBalance' - lore: - - '&a$[balance]' - commands: - - '[msg] Your balance: [balance]' + # Style items + '9': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '0': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '1': + item: RED_STAINED_GLASS_PANE + name: ' ' flags: - hide: true \ No newline at end of file + hide: true + '2': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '3': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '4': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '5': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '6': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '7': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '8': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '17': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '19': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '20': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '21': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '22': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '23': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '24': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '25': + item: RED_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '10': + item: GREEN_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true + '16': + item: GREEN_STAINED_GLASS_PANE + name: ' ' + flags: + hide: true