From 1540d80ab129dd7bf6ea0e49dada886bf4f79b5e Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Tue, 18 Jun 2019 15:59:52 +0800 Subject: [PATCH] Main class methods clean up Former-commit-id: 2660db29bca5a0cef48fa518e275e84849f68f2b [formerly 1dc50307bcb5cb813f937d2e53d49d6e4125c5dc] Former-commit-id: 92639827c262ce97c43f0a0e70193263c61f14a9 --- .../org/maxgamer/quickshop/Command/QS.java | 16 +++++----- .../org/maxgamer/quickshop/QuickShop.java | 24 +------------- .../quickshop/Shop/ContainerShop.java | 2 +- .../maxgamer/quickshop/Shop/ShopManager.java | 32 +++++++++---------- .../org/maxgamer/quickshop/Util/Paste.java | 2 +- .../quickshop/Util/SentryErrorReporter.java | 4 +-- .../org/maxgamer/quickshop/Util/Util.java | 2 +- 7 files changed, 30 insertions(+), 52 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Command/QS.java b/src/main/java/org/maxgamer/quickshop/Command/QS.java index e48b53081..45e5db9a5 100644 --- a/src/main/java/org/maxgamer/quickshop/Command/QS.java +++ b/src/main/java/org/maxgamer/quickshop/Command/QS.java @@ -492,9 +492,9 @@ public class QS implements CommandExecutor { double fee = 0; if (plugin.isPriceChangeRequiresFee()) { fee = plugin.getConfig().getDouble("shop.fee-for-price-change"); - if (fee > 0 && plugin.getEcon().getBalance(p.getUniqueId()) < fee) { + if (fee > 0 && plugin.getEconomy().getBalance(p.getUniqueId()) < fee) { sender.sendMessage( - MsgUtil.getMessage("you-cant-afford-to-change-price", plugin.getEcon().format(fee))); + MsgUtil.getMessage("you-cant-afford-to-change-price", plugin.getEconomy().format(fee))); return; } } @@ -511,15 +511,15 @@ public class QS implements CommandExecutor { return; } if (fee > 0) { - if (!plugin.getEcon().withdraw(p.getUniqueId(), fee)) { + if (!plugin.getEconomy().withdraw(p.getUniqueId(), fee)) { sender.sendMessage(MsgUtil.getMessage("you-cant-afford-to-change-price", - plugin.getEcon().format(fee))); + plugin.getEconomy().format(fee))); return; } sender.sendMessage( - MsgUtil.getMessage("fee-charged-for-price-change", plugin.getEcon().format(fee))); + MsgUtil.getMessage("fee-charged-for-price-change", plugin.getEconomy().format(fee))); try { - plugin.getEcon().deposit(Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax-account")) + plugin.getEconomy().deposit(Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax-account")) .getUniqueId(), fee); } catch (Exception e) { e.getMessage(); @@ -532,7 +532,7 @@ public class QS implements CommandExecutor { shop.setPrice(price); //shop.setSignText(); shop.update(); - sender.sendMessage(MsgUtil.getMessage("price-is-now", plugin.getEcon().format(shop.getPrice()))); + sender.sendMessage(MsgUtil.getMessage("price-is-now", plugin.getEconomy().format(shop.getPrice()))); // Chest shops can be double shops. if (shop instanceof ContainerShop) { ContainerShop cs = (ContainerShop) shop; @@ -875,7 +875,7 @@ public class QS implements CommandExecutor { } } sender.sendMessage(ChatColor.RED + "QuickShop Statistics..."); - sender.sendMessage(ChatColor.GREEN + "Server UniqueID: " + QuickShop.getUniqueID().toString()); + sender.sendMessage(ChatColor.GREEN + "Server UniqueID: " + plugin.getServerUniqueID()); sender.sendMessage(ChatColor.GREEN + "" + (buying + selling) + " shops in " + chunks + " chunks spread over " + worlds + " worlds."); sender.sendMessage(ChatColor.GREEN + "" + doubles + " double shops. "); diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 3639e1583..6f8b92691 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -107,7 +107,7 @@ public class QuickShop extends JavaPlugin { /** A util to call to check some actions permission **/ private PermissionChecker permissionChecker; /** The server UniqueID, use to the ErrorReporter **/ - private static UUID serverUniqueID; + private UUID serverUniqueID; /** The error reporter to help devs report errors to Sentry.io **/ private SentryErrorReporter sentryErrorReporter; @@ -823,15 +823,6 @@ public class QuickShop extends JavaPlugin { Util.debugLog("All shutdown work is finished."); } - /** - * Returns the economy for moving currency around - * - * @return The economy for moving currency around - */ - public EconomyCore getEcon() { - return economy; - } - /** * Logs the given string to qs.log, if QuickShop is configured to do so. * @@ -845,16 +836,6 @@ public class QuickShop extends JavaPlugin { this.logWatcher.add("[" + time.toString() + "] " + s); } - /** - * Returns the ShopManager. This is used for fetching, adding and removing - * shops. - * - * @return The ShopManager. - */ - public ShopManager getShopManager() { - return this.shopManager; - } - /** * Returns QS version, this method only exist on QSRR forks If running other * QSRR forks,, result may not is "Reremake x.x.x" If running QS offical, Will @@ -873,7 +854,4 @@ public class QuickShop extends JavaPlugin { */ public String getFork() { return "Reremake"; } - public static UUID getUniqueID() { - return QuickShop.serverUniqueID; - } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 7df60f14e..e81596106 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -667,7 +667,7 @@ public class ContainerShop implements Shop { String world = this.getLocation().getWorld().getName(); // Refund if necessary if (plugin.getConfig().getBoolean("shop.refund")) { - plugin.getEcon().deposit(this.getOwner(), plugin.getConfig().getDouble("shop.cost")); + plugin.getEconomy().deposit(this.getOwner(), plugin.getConfig().getDouble("shop.cost")); } if (fromMemory) { // Delete it from memory diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java index c5fa71b3f..9ccc7a947 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ShopManager.java @@ -440,26 +440,26 @@ public class ShopManager { if (!shop.isUnlimited() || plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) { // Tries to check their balance nicely to see if // they can afford it. - if (plugin.getEcon().getBalance(shop.getOwner()) < amount * shop.getPrice()) { + if (plugin.getEconomy().getBalance(shop.getOwner()) < amount * shop.getPrice()) { p.sendMessage(MsgUtil .getMessage("the-owner-cant-afford-to-buy-from-you", format(amount * shop.getPrice()), format(plugin - .getEcon().getBalance(shop.getOwner())))); + .getEconomy().getBalance(shop.getOwner())))); return; } // Check for plugins faking econ.has(amount) - if (!plugin.getEcon().withdraw(shop.getOwner(), total)) { + if (!plugin.getEconomy().withdraw(shop.getOwner(), total)) { p.sendMessage(MsgUtil .getMessage("the-owner-cant-afford-to-buy-from-you", format(amount * shop.getPrice()), format(plugin - .getEcon().getBalance(shop.getOwner())))); + .getEconomy().getBalance(shop.getOwner())))); return; } if (tax != 0) { - plugin.getEcon().deposit(Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax-account")) + plugin.getEconomy().deposit(Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax-account")) .getUniqueId(), total * tax); } } // Give them the money after we know we succeeded - plugin.getEcon().deposit(p.getUniqueId(), total * (1 - tax)); + plugin.getEconomy().deposit(p.getUniqueId(), total * (1 - tax)); // Notify the owner of the purchase. String msg = MsgUtil.getMessage("player-sold-to-your-store", p.getName(), "" + amount, Util .getItemStackName(shop.getItem())); @@ -520,9 +520,9 @@ public class ShopManager { if (!p.getUniqueId().equals(shop.getOwner())) { // Check their balance. Works with *most* economy // plugins* - if (plugin.getEcon().getBalance(p.getUniqueId()) < amount * shop.getPrice()) { + if (plugin.getEconomy().getBalance(p.getUniqueId()) < amount * shop.getPrice()) { p.sendMessage(MsgUtil - .getMessage("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEcon() + .getMessage("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEconomy() .getBalance(p.getUniqueId())))); return; } @@ -532,16 +532,16 @@ public class ShopManager { if (shop.getOwner().equals(p.getUniqueId())) { tax = 0; } - if (!plugin.getEcon().withdraw(p.getUniqueId(), total)) { + if (!plugin.getEconomy().withdraw(p.getUniqueId(), total)) { p.sendMessage(MsgUtil - .getMessage("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEcon() + .getMessage("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEconomy() .getBalance(p.getUniqueId())))); return; } if (!shop.isUnlimited() || plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) { - plugin.getEcon().deposit(shop.getOwner(), total * (1 - tax)); + plugin.getEconomy().deposit(shop.getOwner(), total * (1 - tax)); if (tax != 0) { - plugin.getEcon().deposit(Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax-account")) + plugin.getEconomy().deposit(Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax-account")) .getUniqueId(), total * tax); } } @@ -659,7 +659,7 @@ public class ShopManager { double createCost = plugin.getConfig().getDouble("shop.cost"); // Tax refers to the cost to create a shop. Not actual // tax, that would be silly - if (createCost != 0 && plugin.getEcon().getBalance(p.getUniqueId()) < createCost) { + if (createCost != 0 && plugin.getEconomy().getBalance(p.getUniqueId()) < createCost) { p.sendMessage(MsgUtil.getMessage("you-cant-afford-a-new-shop", format(createCost))); return; } @@ -678,13 +678,13 @@ public class ShopManager { // Else, if the event is cancelled, they won't get their // money back. if (createCost != 0) { - if (!plugin.getEcon().withdraw(p.getUniqueId(), createCost)) { + if (!plugin.getEconomy().withdraw(p.getUniqueId(), createCost)) { p.sendMessage(MsgUtil.getMessage("you-cant-afford-a-new-shop", format(createCost))); shop.onUnload(); return; } try { - plugin.getEcon().deposit( + plugin.getEconomy().deposit( Bukkit.getOfflinePlayer(plugin.getConfig().getString("tax-account")).getUniqueId(), createCost); } catch (Exception e2) { e2.printStackTrace(); @@ -744,7 +744,7 @@ public class ShopManager { * @return formated price */ public String format(@NotNull double d) { - return plugin.getEcon().format(d); + return plugin.getEconomy().format(d); } public class ShopIterator implements Iterator { diff --git a/src/main/java/org/maxgamer/quickshop/Util/Paste.java b/src/main/java/org/maxgamer/quickshop/Util/Paste.java index b4c8a18bf..4c1f013a9 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Paste.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Paste.java @@ -42,7 +42,7 @@ public class Paste { finalReport.append("QuickShop:\n"); finalReport.append("\tVersion: " + QuickShop.getVersion() + "\n"); finalReport.append("\tFork: " + plugin.getFork() + "\n"); - finalReport.append("\tServer ID: " + QuickShop.getUniqueID().toString() + "\n"); + finalReport.append("\tServer ID: " + plugin.getServerUniqueID().toString() + "\n"); finalReport.append("\tOpenInv Hook: " + (plugin.getOpenInvPlugin() == null ? "Disabled" : "Enabled") + "\n"); //finalReport.append("Fork: "+plugin.+"\n"); finalReport.append("================================================\n"); diff --git a/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java b/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java index 986bfb91f..95e6b68a7 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java +++ b/src/main/java/org/maxgamer/quickshop/Util/SentryErrorReporter.java @@ -54,7 +54,7 @@ public class SentryErrorReporter { context.addTag("server_onlinemode", String.valueOf(serverData.get("onlineMode"))); context.addTag("server_bukkitversion", String.valueOf(serverData.get("bukkitVersion"))); context.addTag("server_plugins", getPluginInfo()); - context.setUser(new UserBuilder().setId(QuickShop.getUniqueID().toString()).build()); + context.setUser(new UserBuilder().setId(plugin.getServerUniqueID().toString()).build()); sentryClient.setServerName(Bukkit.getServer().getName() + " @ " + Bukkit.getServer().getVersion()); sentryClient.setRelease(QuickShop.getVersion()); sentryClient.setEnvironment(Util.isDevEdition() ? "Development" : "Production"); @@ -141,7 +141,7 @@ public class SentryErrorReporter { plugin.getLogger().warning("====QuickShop Error Report BEGIN==="); plugin.getLogger().warning("Description: " + throwable.getMessage()); plugin.getLogger().warning("Event ID: " + this.context.getLastEventId().toString()); - plugin.getLogger().warning("Server ID: " + QuickShop.getUniqueID().toString()); + plugin.getLogger().warning("Server ID: " + plugin.getServerUniqueID().toString()); plugin.getLogger().warning("====QuickShop Error Report E N D==="); return this.context.getLastEventId(); } diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index c15a37996..05dc4ac59 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -419,7 +419,7 @@ public class Util { return plugin.getConfig().getString("shop.alternate-currency-symbol") + n; } try { - String formated = plugin.getEcon().format(n); + String formated = plugin.getEconomy().format(n); if (formated == null || formated.isEmpty()) { Util.debugLog("Use alternate-currency-symbol to formatting, Cause economy plugin returned null"); return plugin.getConfig().getString("shop.alternate-currency-symbol") + n;