From bf5ba94b8914499817c81b8ef63fd38427a1be3d Mon Sep 17 00:00:00 2001 From: OllieJW <71931263+OllieJW@users.noreply.github.com> Date: Wed, 22 Sep 2021 18:41:55 +0100 Subject: [PATCH] Add files via upload --- pom.xml | 2 +- .../java/me/olliejw/oremarket/OreMarket.java | 32 +++++++++++++++++-- .../oremarket/commands/CrashMarket.java | 5 +++ .../oremarket/commands/OpenMarket.java | 5 +++ .../me/olliejw/oremarket/commands/Reload.java | 6 ++-- .../oremarket/commands/StatsCommands.java | 5 +++ .../olliejw/oremarket/events/MarketCrash.java | 2 +- .../oremarket/listeners/InventoryEvents.java | 17 +++++----- .../olliejw/oremarket/utils/Placeholders.java | 2 -- src/main/resources/gui.yml | 10 ------ src/main/resources/messages.yml | 15 +++++++++ src/main/resources/plugin.yml | 4 +-- 12 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 src/main/resources/messages.yml diff --git a/pom.xml b/pom.xml index 02bc115..cea30d2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.olliejw OreMarket - 2.2.3 + 2.2.5 jar OreMarket diff --git a/src/main/java/me/olliejw/oremarket/OreMarket.java b/src/main/java/me/olliejw/oremarket/OreMarket.java index a5cfe65..22bb2bd 100644 --- a/src/main/java/me/olliejw/oremarket/OreMarket.java +++ b/src/main/java/me/olliejw/oremarket/OreMarket.java @@ -10,6 +10,7 @@ import me.olliejw.oremarket.utils.Placeholders; import me.olliejw.oremarket.utils.Stats; import me.olliejw.oremarket.utils.Updates; +import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -38,7 +39,7 @@ public final class OreMarket extends JavaPlugin implements Listener { public void onEnable() { saveDefaultConfig(); createGuiConfig(); - + createMsgConfig(); instance = this; // Spigot and bStats @@ -46,7 +47,7 @@ public void onEnable() { if (this.getDescription().getVersion().equalsIgnoreCase(version)) { this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " ___ __ __ "); this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " / _ \\ | \\/ | " + ChatColor.GREEN +"OreMarket v"+this.getDescription().getVersion()); - this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " | (_) || |\\/| |"); + this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " | (_) || |\\/| | " + ChatColor.GREEN +"Up to date!"); this.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + " \\___/ |_| |_|"); this.getServer().getConsoleSender().sendMessage(""); } @@ -134,6 +135,33 @@ public void reloadGuiConfig() { } } + private File msgFile; + private FileConfiguration msgConfig; + public FileConfiguration getMsgConfig() { + return this.msgConfig; + } + private void createMsgConfig() { + msgFile = new File(getDataFolder(), "messages.yml"); + if (!msgFile.exists()) { + msgFile.getParentFile().mkdirs(); + saveResource("messages.yml", false); + } + + msgConfig = new YamlConfiguration(); + try { + msgConfig.load(msgFile); + } catch (IOException | InvalidConfigurationException e) { + 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/commands/CrashMarket.java b/src/main/java/me/olliejw/oremarket/commands/CrashMarket.java index b763c58..1746ae4 100644 --- a/src/main/java/me/olliejw/oremarket/commands/CrashMarket.java +++ b/src/main/java/me/olliejw/oremarket/commands/CrashMarket.java @@ -1,6 +1,8 @@ package me.olliejw.oremarket.commands; +import me.olliejw.oremarket.OreMarket; import me.olliejw.oremarket.events.MarketCrash; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -12,6 +14,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (command.getName().equalsIgnoreCase("om-crash")) { if (sender.hasPermission("oremarket.crashmarket")) { mkCrash.forceCrash(); + } else { + String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!"); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } } return true; diff --git a/src/main/java/me/olliejw/oremarket/commands/OpenMarket.java b/src/main/java/me/olliejw/oremarket/commands/OpenMarket.java index 58c27db..3231f8c 100644 --- a/src/main/java/me/olliejw/oremarket/commands/OpenMarket.java +++ b/src/main/java/me/olliejw/oremarket/commands/OpenMarket.java @@ -1,6 +1,8 @@ package me.olliejw.oremarket.commands; +import me.olliejw.oremarket.OreMarket; import me.olliejw.oremarket.menus.MainGUI; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -13,6 +15,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (command.getName().equalsIgnoreCase("openmarket")) { if (sender.hasPermission("oremarket.open")) { mainGUI.createGUI((Player) sender); + } else { + String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!"); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } } return true; diff --git a/src/main/java/me/olliejw/oremarket/commands/Reload.java b/src/main/java/me/olliejw/oremarket/commands/Reload.java index a3ddb00..babe56d 100644 --- a/src/main/java/me/olliejw/oremarket/commands/Reload.java +++ b/src/main/java/me/olliejw/oremarket/commands/Reload.java @@ -13,9 +13,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (sender.hasPermission("oremarket.reload")) { OreMarket.main().reloadConfig(); OreMarket.main().reloadGuiConfig(); - sender.sendMessage(ChatColor.GREEN + "Reloaded successfully. Some options may require a restart to take place."); + String message = OreMarket.main().getMsgConfig().getString("messages.reload", "&aReloaded successfully. Some options may require a restart to take place."); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } else { - sender.sendMessage(ChatColor.RED + "You do not have permission to do this!"); + String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!"); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } return true; } diff --git a/src/main/java/me/olliejw/oremarket/commands/StatsCommands.java b/src/main/java/me/olliejw/oremarket/commands/StatsCommands.java index 47f067a..5a0ad09 100644 --- a/src/main/java/me/olliejw/oremarket/commands/StatsCommands.java +++ b/src/main/java/me/olliejw/oremarket/commands/StatsCommands.java @@ -1,6 +1,8 @@ package me.olliejw.oremarket.commands; +import me.olliejw.oremarket.OreMarket; import me.olliejw.oremarket.utils.Stats; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -14,6 +16,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St sender.sendMessage("Total Items: " + stats.totalItems()); sender.sendMessage("Total Value: " + stats.totalValues()); sender.sendMessage("https://bstats.org/plugin/bukkit/OreMarket/10961"); + } else { + String message = OreMarket.main().getMsgConfig().getString("messages.insufficient-permission", "&cYou do not have permission to do this!"); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); } } return true; diff --git a/src/main/java/me/olliejw/oremarket/events/MarketCrash.java b/src/main/java/me/olliejw/oremarket/events/MarketCrash.java index e84804c..faebeb2 100644 --- a/src/main/java/me/olliejw/oremarket/events/MarketCrash.java +++ b/src/main/java/me/olliejw/oremarket/events/MarketCrash.java @@ -13,7 +13,7 @@ public class MarketCrash implements Listener { public void forceCrash() { // Notification - String notification = OreMarket.main().getConfig().getString("marketcrash.message"); + String notification = OreMarket.main().getMsgConfig().getString("messages.market-crash"); for (Player player: Bukkit.getOnlinePlayers()) { assert notification != null; String message = ChatColor.translateAlternateColorCodes('&', notification).replace("[amount]", Objects.requireNonNull(OreMarket.main().getConfig().getString("marketcrash.amount"))); diff --git a/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java b/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java index 47a7b4b..010e8dd 100644 --- a/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java +++ b/src/main/java/me/olliejw/oremarket/listeners/InventoryEvents.java @@ -29,9 +29,9 @@ private double calculateTotalWithTax(double price, boolean operation) { total = price; } else { if (operation) { - total = (price + (price/tax)); + total = (price + (price * (tax/100))); } else { - total = (price - (price/tax)); + total = (price - (price * (tax/100))); } } return total; @@ -76,7 +76,6 @@ public void clickEvent (InventoryClickEvent event) { int slot = event.getSlot(); if (OreMarket.main().getGuiConfig().contains("items." + event.getSlot() + ".commands")) { - for (String command : Objects.requireNonNull(OreMarket.main().getGuiConfig().getStringList("items." + event.getSlot() + ".commands"))) { if (command != null) { assert keySection != null; @@ -98,13 +97,13 @@ else if (toSend.contains("[msg]")) { if ((event.getClick() == ClickType.LEFT)) { // Sell Mode if (OreMarket.main().getGuiConfig().getBoolean("items." + event.getSlot() + ".buyonly")) { // You cannot sell this, Buy only item - String message = OreMarket.main().getGuiConfig().getString("messages.buy-only", "&cThis item can only be bought"); + 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().getGuiConfig().getString("messages.no-item", "&cYou don't have that item!"); + String message = OreMarket.main().getMsgConfig().getString("messages.no-item", "&cYou don't have that item!"); player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); return; } @@ -125,13 +124,13 @@ else if (toSend.contains("[msg]")) { OreMarket.main().getGuiConfig().set("items." + slot + ".stock", itemStock+1); OreMarket.main().saveGuiConfig(); - String message = OreMarket.main().getGuiConfig().getString("messages.successfully-bought", "&aYou have successfully bought this item!"); + 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 - String message = OreMarket.main().getGuiConfig().getString("messages.sell-only", "&cThis item can only be sold"); + String message = OreMarket.main().getMsgConfig().getString("messages.sell-only", "&cThis item can only be sold"); player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); return; } @@ -140,7 +139,7 @@ else if (toSend.contains("[msg]")) { int itemStock = OreMarket.main().getGuiConfig().getInt("items." + slot + ".stock"); if (balance(player) < itemValue) { - String message = OreMarket.main().getGuiConfig().getString("insufficient-balance", "&cYou don't have enough money to buy this item!"); + 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; } @@ -158,7 +157,7 @@ else if (toSend.contains("[msg]")) { OreMarket.main().getGuiConfig().set("items." + slot + ".stock", itemStock-1); OreMarket.main().saveGuiConfig(); - String message = OreMarket.main().getGuiConfig().getString("messages.successfully-sold", "&aYou have successfully bought the item!"); + 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 diff --git a/src/main/java/me/olliejw/oremarket/utils/Placeholders.java b/src/main/java/me/olliejw/oremarket/utils/Placeholders.java index c848a18..4ef0230 100644 --- a/src/main/java/me/olliejw/oremarket/utils/Placeholders.java +++ b/src/main/java/me/olliejw/oremarket/utils/Placeholders.java @@ -40,9 +40,7 @@ public String format(String string, HumanEntity player, ConfigurationSection con return PlaceholderAPI.setPlaceholders(playerObj, formatted); } - // Placeholder API - @Override public boolean canRegister() { return true; diff --git a/src/main/resources/gui.yml b/src/main/resources/gui.yml index bdcfa80..8aee281 100644 --- a/src/main/resources/gui.yml +++ b/src/main/resources/gui.yml @@ -4,16 +4,6 @@ gui: title: '&4OreMarket' rows: 3 -messages: - sell-only: "&cThis item can only be sold!" - buy-only: "&cThis item can only be bought" - no-item: "&cYou don't have that item!" - insufficient-balance: "&cYou don't have enough money to buy this item!" - price-too-low: "&cPrice of item is too low for buying!" - no-stocks: "&cMarket is run out of item stocks!" - successfully-bought: "&aYou have successfully bought the item!" - successfully-sold: "&aYou have successfully sold the item!" - items: 0: item: DIAMOND diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml new file mode 100644 index 0000000..026c207 --- /dev/null +++ b/src/main/resources/messages.yml @@ -0,0 +1,15 @@ +messages: + # GUI + sell-only: "&cThis item can only be sold!" + buy-only: "&cThis item can only be bought" + no-item: "&cYou don't have that item!" + insufficient-balance: "&cYou don't have enough money to buy this item!" + price-too-low: "&cPrice of item is too low for buying!" + no-stocks: "&cMarket is run out of item stocks!" + successfully-bought: "&aYou have successfully bought the item!" + successfully-sold: "&aYou have successfully sold the item!" + # Market Crash + market-crash: "&4&lMARKET CRASH! ORE VALUES DECREASED BY UP TO [amount]%" + # Commands + insufficient-permission: "&cYou do not have permission to do this!" + reload: "&aReloaded successfully. Some options may require a restart to take place." \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b739340..ea5a8ff 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -28,6 +28,6 @@ permissions: oremarket.reload: default: op oremarket.open: - default: not op + default: true oremarket.stats: - default: not op \ No newline at end of file + default: true \ No newline at end of file