From 42969fb8b372476de4291b1ccb2be1765dceb51d Mon Sep 17 00:00:00 2001 From: montlikadani Date: Sat, 21 Mar 2020 12:57:16 +0100 Subject: [PATCH] Added bypass permission for taxes --- .../jobs/commands/list/convert.java | 3 - .../jobs/config/GeneralConfigManager.java | 2 +- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 13 ++-- .../com/gamingmesh/jobs/economy/.gitignore | 12 ---- .../jobs/economy/BufferedEconomy.java | 59 ++++++++----------- 5 files changed, 30 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/com/gamingmesh/jobs/economy/.gitignore diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/convert.java b/src/main/java/com/gamingmesh/jobs/commands/list/convert.java index 4d72e4f2..78a2838f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/convert.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/convert.java @@ -42,9 +42,6 @@ public class convert implements Cmd { Jobs.ChangeDatabase(); - if (archivelist == null) - return; - try { Jobs.getJobsDAO().truncateAllTables(); Jobs.getPlayerManager().convertChacheOfPlayers(true); diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index f17446a3..7c0c40bd 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -669,7 +669,7 @@ public class GeneralConfigManager { UseServerAccount = c.get("Economy.UseServerAccount", false); c.addComment("Economy.AccountName", "Username should be with Correct capitalization"); ServerAccountName = c.get("Economy.AccountName", "Server"); - c.addComment("Economy.Taxes.use", "Do you want to use taxes feature for jobs payment?"); + c.addComment("Economy.Taxes.use", "Do you want to use taxes feature for jobs payment?", "You can bypass taxes with permission jobs.tax.bypass"); UseTaxes = c.get("Economy.Taxes.use", false); c.addComment("Economy.Taxes.AccountName", "Username should be with Correct capitalization, it can be same as setup in server account before"); ServertaxesAccountName = c.get("Economy.Taxes.AccountName", "Server"); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 25e32b3b..aa6c50a7 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1457,11 +1457,11 @@ public abstract class JobsDAO { * @throws SQLException */ public List convertDatabase() throws SQLException { + List list = new ArrayList<>(); JobsConnection conn = getConnection(); if (conn == null) - return null; + return list; - List list = new ArrayList<>(); PreparedStatement prest = null; ResultSet res = null; try { @@ -1472,6 +1472,7 @@ public abstract class JobsDAO { PlayerInfo pi = Jobs.getPlayerManager().getPlayerInfo(id); if (pi == null) continue; + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pi.getUuid()); if (jPlayer == null) continue; @@ -1491,18 +1492,12 @@ public abstract class JobsDAO { list.add(new Convert(res.getInt("id"), jPlayer.getUniqueId(), job.getId(), res.getInt(ArchiveTableFields.level.getCollumn()), res.getInt(ArchiveTableFields.experience.getCollumn()))); } - } catch (SQLException e) { - e.printStackTrace(); } finally { close(res); close(prest); } - try { - conn.closeConnection(); - } catch (SQLException e) { - e.printStackTrace(); - } + conn.closeConnection(); return list; } diff --git a/src/main/java/com/gamingmesh/jobs/economy/.gitignore b/src/main/java/com/gamingmesh/jobs/economy/.gitignore deleted file mode 100644 index 98c8d3f7..00000000 --- a/src/main/java/com/gamingmesh/jobs/economy/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/BlackholeEconomy.class -/BufferedEconomy.class -/BufferedPayment.class -/Economy.class -/VaultEconomy.class -/PaymentData.class -/PointsData.class -/IConomy6Adapter.class -/IConomy7Adapter.class -/IConomyAdapter.class -/CraftConomy3Adapter.class -/SaneEconomyAdapter.class diff --git a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java index c89b7242..64841ea3 100644 --- a/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java +++ b/src/main/java/com/gamingmesh/jobs/economy/BufferedEconomy.java @@ -41,7 +41,6 @@ public class BufferedEconomy { private LinkedBlockingQueue payments = new LinkedBlockingQueue<>(); private final Map paymentCache = Collections.synchronizedMap(new HashMap()); - private OfflinePlayer ServerAccount = null; private OfflinePlayer ServerTaxesAccount = null; public BufferedEconomy(Jobs plugin, Economy economy) { @@ -112,10 +111,11 @@ public class BufferedEconomy { TaxesPoints += payment.get(CurrencyType.POINTS) * (Jobs.getGCManager().TaxesAmount / 100.0); } - if (payment.getOfflinePlayer() == null) + OfflinePlayer offPlayer = payment.getOfflinePlayer(); + if (offPlayer == null) continue; - UUID uuid = payment.getOfflinePlayer().getUniqueId(); + UUID uuid = offPlayer.getUniqueId(); if (paymentCache.containsKey(uuid)) { BufferedPayment existing = paymentCache.get(uuid); @@ -123,7 +123,8 @@ public class BufferedEconomy { double points = payment.get(CurrencyType.POINTS); double exp = payment.get(CurrencyType.EXP); - if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes) { + if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes && + ((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) { money = money - (money * (Jobs.getGCManager().TaxesAmount / 100.0)); points = points - (points * (Jobs.getGCManager().TaxesAmount / 100.0)); } @@ -132,11 +133,11 @@ public class BufferedEconomy { existing.set(CurrencyType.POINTS, existing.get(CurrencyType.POINTS) + points); existing.set(CurrencyType.EXP, existing.get(CurrencyType.EXP) + exp); } else { - double money = payment.get(CurrencyType.MONEY); double points = payment.get(CurrencyType.POINTS); - if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes) { + if (Jobs.getGCManager().TakeFromPlayersPayment && Jobs.getGCManager().UseTaxes && + ((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) { payment.set(CurrencyType.MONEY, money - (money * (Jobs.getGCManager().TaxesAmount / 100.0))); payment.set(CurrencyType.POINTS, points - (points * (Jobs.getGCManager().TaxesAmount / 100.0))); } @@ -145,14 +146,11 @@ public class BufferedEconomy { } } - boolean hasMoney = false; String ServerAccountname = Jobs.getGCManager().ServerAccountName; String ServerTaxesAccountname = Jobs.getGCManager().ServertaxesAccountName; - if (this.ServerAccount == null) - this.ServerAccount = Bukkit.getOfflinePlayer(ServerAccountname); - if (this.ServerTaxesAccount == null) - this.ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerTaxesAccountname); + if (ServerTaxesAccount == null) + ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerTaxesAccountname); if (Jobs.getGCManager().UseTaxes && Jobs.getGCManager().TransferToServerAccount && ServerTaxesAccount != null) { if (TaxesAmount > 0) @@ -166,11 +164,10 @@ public class BufferedEconomy { } } - if (Jobs.getGCManager().UseServerAccount) { - if (economy.hasMoney(ServerAccountname, TotalAmount)) { - hasMoney = true; - economy.withdrawPlayer(ServerAccountname, TotalAmount); - } + boolean hasMoney = false; + if (Jobs.getGCManager().UseServerAccount && economy.hasMoney(ServerAccountname, TotalAmount)) { + hasMoney = true; + economy.withdrawPlayer(ServerAccountname, TotalAmount); } // Schedule all payments @@ -196,30 +193,24 @@ public class BufferedEconomy { Jobs.getActionBar().send(payment.getOfflinePlayer().getPlayer(), Jobs.getLanguage().getMessage("economy.error.nomoney")); continue; } - if (Jobs.getGCManager().isEconomyAsync()) - Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i); - else - Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i); - } else { - if (Jobs.getGCManager().isEconomyAsync()) - Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i); - else - Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i); } - try { - // Action bar stuff - ShowActionBar(payment); - if (payment.getOfflinePlayer().isOnline() && Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_8_R3)) { - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId()); - Jobs.getBBManager().ShowJobProgression(jPlayer); - } - } catch (Throwable e) { + + if (Jobs.getGCManager().isEconomyAsync()) + Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i); + else + Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i); + + // Action bar stuff + ShowActionBar(payment); + if (payment.getOfflinePlayer().isOnline() && Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_8_R3)) { + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId()); + Jobs.getBBManager().ShowJobProgression(jPlayer); } } + // empty payment cache paymentCache.clear(); } - } public void ShowActionBar(BufferedPayment payment) {