1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-07 00:38:42 +01:00

Added bypass permission for taxes

This commit is contained in:
montlikadani 2020-03-21 12:57:16 +01:00
parent f9f745e63a
commit 42969fb8b3
5 changed files with 30 additions and 59 deletions

View File

@ -42,9 +42,6 @@ public class convert implements Cmd {
Jobs.ChangeDatabase(); Jobs.ChangeDatabase();
if (archivelist == null)
return;
try { try {
Jobs.getJobsDAO().truncateAllTables(); Jobs.getJobsDAO().truncateAllTables();
Jobs.getPlayerManager().convertChacheOfPlayers(true); Jobs.getPlayerManager().convertChacheOfPlayers(true);

View File

@ -669,7 +669,7 @@ public class GeneralConfigManager {
UseServerAccount = c.get("Economy.UseServerAccount", false); UseServerAccount = c.get("Economy.UseServerAccount", false);
c.addComment("Economy.AccountName", "Username should be with Correct capitalization"); c.addComment("Economy.AccountName", "Username should be with Correct capitalization");
ServerAccountName = c.get("Economy.AccountName", "Server"); 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); 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"); 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"); ServertaxesAccountName = c.get("Economy.Taxes.AccountName", "Server");

View File

@ -1457,11 +1457,11 @@ public abstract class JobsDAO {
* @throws SQLException * @throws SQLException
*/ */
public List<Convert> convertDatabase() throws SQLException { public List<Convert> convertDatabase() throws SQLException {
List<Convert> list = new ArrayList<>();
JobsConnection conn = getConnection(); JobsConnection conn = getConnection();
if (conn == null) if (conn == null)
return null; return list;
List<Convert> list = new ArrayList<>();
PreparedStatement prest = null; PreparedStatement prest = null;
ResultSet res = null; ResultSet res = null;
try { try {
@ -1472,6 +1472,7 @@ public abstract class JobsDAO {
PlayerInfo pi = Jobs.getPlayerManager().getPlayerInfo(id); PlayerInfo pi = Jobs.getPlayerManager().getPlayerInfo(id);
if (pi == null) if (pi == null)
continue; continue;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pi.getUuid()); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pi.getUuid());
if (jPlayer == null) if (jPlayer == null)
continue; 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()))); 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 { } finally {
close(res); close(res);
close(prest); close(prest);
} }
try { conn.closeConnection();
conn.closeConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return list; return list;
} }

View File

@ -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

View File

@ -41,7 +41,6 @@ public class BufferedEconomy {
private LinkedBlockingQueue<BufferedPayment> payments = new LinkedBlockingQueue<>(); private LinkedBlockingQueue<BufferedPayment> payments = new LinkedBlockingQueue<>();
private final Map<UUID, BufferedPayment> paymentCache = Collections.synchronizedMap(new HashMap<UUID, BufferedPayment>()); private final Map<UUID, BufferedPayment> paymentCache = Collections.synchronizedMap(new HashMap<UUID, BufferedPayment>());
private OfflinePlayer ServerAccount = null;
private OfflinePlayer ServerTaxesAccount = null; private OfflinePlayer ServerTaxesAccount = null;
public BufferedEconomy(Jobs plugin, Economy economy) { public BufferedEconomy(Jobs plugin, Economy economy) {
@ -112,10 +111,11 @@ public class BufferedEconomy {
TaxesPoints += payment.get(CurrencyType.POINTS) * (Jobs.getGCManager().TaxesAmount / 100.0); TaxesPoints += payment.get(CurrencyType.POINTS) * (Jobs.getGCManager().TaxesAmount / 100.0);
} }
if (payment.getOfflinePlayer() == null) OfflinePlayer offPlayer = payment.getOfflinePlayer();
if (offPlayer == null)
continue; continue;
UUID uuid = payment.getOfflinePlayer().getUniqueId(); UUID uuid = offPlayer.getUniqueId();
if (paymentCache.containsKey(uuid)) { if (paymentCache.containsKey(uuid)) {
BufferedPayment existing = paymentCache.get(uuid); BufferedPayment existing = paymentCache.get(uuid);
@ -123,7 +123,8 @@ public class BufferedEconomy {
double points = payment.get(CurrencyType.POINTS); double points = payment.get(CurrencyType.POINTS);
double exp = payment.get(CurrencyType.EXP); 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)); money = money - (money * (Jobs.getGCManager().TaxesAmount / 100.0));
points = points - (points * (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.POINTS, existing.get(CurrencyType.POINTS) + points);
existing.set(CurrencyType.EXP, existing.get(CurrencyType.EXP) + exp); existing.set(CurrencyType.EXP, existing.get(CurrencyType.EXP) + exp);
} else { } else {
double money = payment.get(CurrencyType.MONEY); double money = payment.get(CurrencyType.MONEY);
double points = payment.get(CurrencyType.POINTS); 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.MONEY, money - (money * (Jobs.getGCManager().TaxesAmount / 100.0)));
payment.set(CurrencyType.POINTS, points - (points * (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 ServerAccountname = Jobs.getGCManager().ServerAccountName;
String ServerTaxesAccountname = Jobs.getGCManager().ServertaxesAccountName; String ServerTaxesAccountname = Jobs.getGCManager().ServertaxesAccountName;
if (this.ServerAccount == null)
this.ServerAccount = Bukkit.getOfflinePlayer(ServerAccountname);
if (this.ServerTaxesAccount == null) if (ServerTaxesAccount == null)
this.ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerTaxesAccountname); ServerTaxesAccount = Bukkit.getOfflinePlayer(ServerTaxesAccountname);
if (Jobs.getGCManager().UseTaxes && Jobs.getGCManager().TransferToServerAccount && ServerTaxesAccount != null) { if (Jobs.getGCManager().UseTaxes && Jobs.getGCManager().TransferToServerAccount && ServerTaxesAccount != null) {
if (TaxesAmount > 0) if (TaxesAmount > 0)
@ -166,11 +164,10 @@ public class BufferedEconomy {
} }
} }
if (Jobs.getGCManager().UseServerAccount) { boolean hasMoney = false;
if (economy.hasMoney(ServerAccountname, TotalAmount)) { if (Jobs.getGCManager().UseServerAccount && economy.hasMoney(ServerAccountname, TotalAmount)) {
hasMoney = true; hasMoney = true;
economy.withdrawPlayer(ServerAccountname, TotalAmount); economy.withdrawPlayer(ServerAccountname, TotalAmount);
}
} }
// Schedule all payments // Schedule all payments
@ -196,30 +193,24 @@ public class BufferedEconomy {
Jobs.getActionBar().send(payment.getOfflinePlayer().getPlayer(), Jobs.getLanguage().getMessage("economy.error.nomoney")); Jobs.getActionBar().send(payment.getOfflinePlayer().getPlayer(), Jobs.getLanguage().getMessage("economy.error.nomoney"));
continue; 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 if (Jobs.getGCManager().isEconomyAsync())
ShowActionBar(payment); Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
if (payment.getOfflinePlayer().isOnline() && Jobs.getVersionCheckManager().getVersion().isHigher(Version.v1_8_R3)) { else
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId()); Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
Jobs.getBBManager().ShowJobProgression(jPlayer);
} // Action bar stuff
} catch (Throwable e) { 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 // empty payment cache
paymentCache.clear(); paymentCache.clear();
} }
} }
public void ShowActionBar(BufferedPayment payment) { public void ShowActionBar(BufferedPayment payment) {