1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

Fix for issue with server account determination and usage causing

payments to be stopped
This commit is contained in:
Zrips 2023-11-16 17:56:53 +02:00
parent c5863bb121
commit ffd4309de7
2 changed files with 157 additions and 147 deletions

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>Jobs</groupId> <groupId>Jobs</groupId>
<artifactId>jobs</artifactId> <artifactId>jobs</artifactId>
<version>5.2.1.2</version> <version>5.2.2.0</version>
<name>Jobs</name> <name>Jobs</name>
<url>http://maven.apache.org</url> <url>http://maven.apache.org</url>

View File

@ -51,16 +51,16 @@ public class BufferedEconomy {
private OfflinePlayer serverTaxesAccount; private OfflinePlayer serverTaxesAccount;
public BufferedEconomy(Jobs plugin, Economy economy) { public BufferedEconomy(Jobs plugin, Economy economy) {
this.plugin = plugin; this.plugin = plugin;
this.economy = economy; this.economy = economy;
} }
public Jobs getPlugin() { public Jobs getPlugin() {
return plugin; return plugin;
} }
public Economy getEconomy() { public Economy getEconomy() {
return economy; return economy;
} }
/** /**
@ -69,7 +69,7 @@ public class BufferedEconomy {
* @param payments the payments map that contains currency type and amount * @param payments the payments map that contains currency type and amount
*/ */
public void pay(JobsPlayer player, Map<CurrencyType, Double> payments) { public void pay(JobsPlayer player, Map<CurrencyType, Double> payments) {
pay(new BufferedPayment(player.getPlayer(), payments)); pay(new BufferedPayment(player.getPlayer(), payments));
} }
/** /**
@ -77,153 +77,163 @@ public class BufferedEconomy {
* @param payment - payment to be paid * @param payment - payment to be paid
*/ */
public void pay(BufferedPayment payment) { public void pay(BufferedPayment payment) {
payments.add(payment); payments.add(payment);
} }
public String format(double money) { public String format(double money) {
return economy.format(money); return economy.format(money);
} }
/** /**
* Payout all players the amount they are going to be paid * Payout all players the amount they are going to be paid
*/ */
@SuppressWarnings("deprecation")
public void payAll() { public void payAll() {
if (payments.isEmpty() || !plugin.isEnabled()) if (payments.isEmpty() || !plugin.isEnabled())
return; return;
synchronized (paymentCache) { synchronized (paymentCache) {
double totalAmount = 0.0, taxesAmount = 0.0; double totalAmount = 0.0, taxesAmount = 0.0;
// combine all payments using paymentCache // combine all payments using paymentCache
while (!payments.isEmpty()) { while (!payments.isEmpty()) {
BufferedPayment payment = payments.remove(); BufferedPayment payment = payments.remove();
double money = payment.get(CurrencyType.MONEY); double money = payment.get(CurrencyType.MONEY);
totalAmount += money; totalAmount += money;
if (Jobs.getGCManager().UseTaxes) { if (Jobs.getGCManager().UseTaxes) {
taxesAmount += money * (Jobs.getGCManager().TaxesAmount / 100.0); taxesAmount += money * (Jobs.getGCManager().TaxesAmount / 100.0);
} }
OfflinePlayer offPlayer = payment.getOfflinePlayer(); OfflinePlayer offPlayer = payment.getOfflinePlayer();
if (offPlayer == null) if (offPlayer == null)
continue; continue;
BufferedPayment existing = paymentCache.get(offPlayer.getUniqueId()); BufferedPayment existing = paymentCache.get(offPlayer.getUniqueId());
if (existing != null) { if (existing != null) {
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())) { ((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId()); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId());
double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false); double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false);
if (moneyTaxAmount == 0D) { if (moneyTaxAmount == 0D) {
moneyTaxAmount = Jobs.getGCManager().TaxesAmount; moneyTaxAmount = Jobs.getGCManager().TaxesAmount;
} }
double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false); double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false);
if (pointsTaxAmount == 0D) { if (pointsTaxAmount == 0D) {
pointsTaxAmount = Jobs.getGCManager().TaxesAmount; pointsTaxAmount = Jobs.getGCManager().TaxesAmount;
} }
money = money - (money * (moneyTaxAmount / 100.0)); money = money - (money * (moneyTaxAmount / 100.0));
points = points - (points * (pointsTaxAmount / 100.0)); points = points - (points * (pointsTaxAmount / 100.0));
} }
existing.set(CurrencyType.MONEY, existing.get(CurrencyType.MONEY) + money); existing.set(CurrencyType.MONEY, existing.get(CurrencyType.MONEY) + money);
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 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())) { ((offPlayer.isOnline() && !offPlayer.getPlayer().hasPermission("jobs.tax.bypass")) || !offPlayer.isOnline())) {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId()); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId());
double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false); double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false);
if (moneyTaxAmount == 0D) { if (moneyTaxAmount == 0D) {
moneyTaxAmount = Jobs.getGCManager().TaxesAmount; moneyTaxAmount = Jobs.getGCManager().TaxesAmount;
} }
double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false); double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false);
if (pointsTaxAmount == 0D) { if (pointsTaxAmount == 0D) {
pointsTaxAmount = Jobs.getGCManager().TaxesAmount; pointsTaxAmount = Jobs.getGCManager().TaxesAmount;
} }
money = money - (money * (moneyTaxAmount / 100.0)); money = money - (money * (moneyTaxAmount / 100.0));
points = points - (points * (pointsTaxAmount / 100.0)); points = points - (points * (pointsTaxAmount / 100.0));
payment.set(CurrencyType.MONEY, money); payment.set(CurrencyType.MONEY, money);
payment.set(CurrencyType.POINTS, points); payment.set(CurrencyType.POINTS, points);
} }
paymentCache.put(offPlayer.getUniqueId(), payment); paymentCache.put(offPlayer.getUniqueId(), payment);
} }
} }
String serverAccountName = Jobs.getGCManager().ServerAccountName; boolean hasMoney = false;
if (Jobs.getGCManager().UseServerAccount) {
try {
String serverAccountName = Jobs.getGCManager().ServerAccountName;
if (serverTaxesAccount == null) if (serverTaxesAccount == null)
serverTaxesAccount = Bukkit.getOfflinePlayer(Jobs.getGCManager().ServertaxesAccountName); serverTaxesAccount = Bukkit.getOfflinePlayer(Jobs.getGCManager().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) {
economy.depositPlayer(serverTaxesAccount, taxesAmount); economy.depositPlayer(serverTaxesAccount, taxesAmount);
} }
if (Jobs.getGCManager().ActionBarsMessageByDefault && serverTaxesAccount.isOnline()) { if (Jobs.getGCManager().ActionBarsMessageByDefault && serverTaxesAccount.isOnline()) {
CMIActionBar.send(Bukkit.getPlayer(serverAccountName), CMIActionBar.send(Bukkit.getPlayer(serverAccountName),
Jobs.getLanguage().getMessage("message.taxes", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), totalAmount))); Jobs.getLanguage().getMessage("message.taxes", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), totalAmount)));
} }
} }
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); }
} } catch (Throwable e) {
e.printStackTrace();
}
}
// Schedule all payments // Schedule all payments
int i = 0; int i = 0;
for (BufferedPayment payment : paymentCache.values()) { for (BufferedPayment payment : paymentCache.values()) {
i++; i++;
if (payment.getOfflinePlayer() == null) try {
continue; if (payment.getOfflinePlayer() == null)
continue;
// JobsPayment event // JobsPayment event
JobsPaymentEvent jobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getPayment()); JobsPaymentEvent jobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getPayment());
Bukkit.getServer().getPluginManager().callEvent(jobsPaymentEvent); Bukkit.getServer().getPluginManager().callEvent(jobsPaymentEvent);
// If event is canceled, dont do anything // If event is canceled, dont do anything
if (jobsPaymentEvent.isCancelled()) if (jobsPaymentEvent.isCancelled())
continue; continue;
// Do we need this? // Do we need this?
payment.getPayment().putAll(jobsPaymentEvent.getPayment()); payment.getPayment().putAll(jobsPaymentEvent.getPayment());
if (Jobs.getGCManager().UseServerAccount && !hasMoney) { if (Jobs.getGCManager().UseServerAccount && !hasMoney) {
CMIActionBar.send(payment.getOfflinePlayer().getPlayer(), Jobs.getLanguage().getMessage("economy.error.nomoney")); CMIActionBar.send(payment.getOfflinePlayer().getPlayer(), Jobs.getLanguage().getMessage("economy.error.nomoney"));
continue; continue;
} }
if (Jobs.getGCManager().isEconomyAsync()) if (Jobs.getGCManager().isEconomyAsync())
CMIScheduler.get().runLaterAsync(new BufferedPaymentTask(this, economy, payment), i); CMIScheduler.get().runLaterAsync(new BufferedPaymentTask(this, economy, payment), i);
else else
CMIScheduler.get().runTaskLater(new BufferedPaymentTask(this, economy, payment), i); CMIScheduler.get().runTaskLater(new BufferedPaymentTask(this, economy, payment), i);
// Show players payment stuff // Show players payment stuff
showPayment(payment); showPayment(payment);
if (Version.getCurrent().isHigher(Version.v1_8_R3) && payment.getOfflinePlayer().isOnline()) { if (Version.getCurrent().isHigher(Version.v1_8_R3) && payment.getOfflinePlayer().isOnline()) {
Jobs.getBBManager().ShowJobProgression(Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId())); Jobs.getBBManager().ShowJobProgression(Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId()));
} }
} } catch (Throwable e) {
e.printStackTrace();
}
}
// empty payment cache // empty payment cache
paymentCache.clear(); paymentCache.clear();
} }
} }
/** /**
@ -232,7 +242,7 @@ public class BufferedEconomy {
*/ */
@Deprecated @Deprecated
public void showActionBar(BufferedPayment payment) { public void showActionBar(BufferedPayment payment) {
showPayment(payment); showPayment(payment);
} }
/** /**
@ -241,42 +251,42 @@ public class BufferedEconomy {
* @param payment {@link BufferedPayment} * @param payment {@link BufferedPayment}
*/ */
public void showPayment(BufferedPayment payment) { public void showPayment(BufferedPayment payment) {
if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline() if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline()
|| !payment.containsPayment()) || !payment.containsPayment())
return; return;
UUID playerUUID = payment.getOfflinePlayer().getUniqueId(); UUID playerUUID = payment.getOfflinePlayer().getUniqueId();
Player abp = Bukkit.getPlayer(playerUUID); Player abp = Bukkit.getPlayer(playerUUID);
if (abp == null) { if (abp == null) {
return; return;
} }
String message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main"); String message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");
double money = payment.get(CurrencyType.MONEY); double money = payment.get(CurrencyType.MONEY);
if (money != 0D) { if (money != 0D) {
message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(),
money)); money));
} }
double points = payment.get(CurrencyType.POINTS); double points = payment.get(CurrencyType.POINTS);
if (points != 0D) { if (points != 0D) {
message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(),
points)); points));
} }
double exp = payment.get(CurrencyType.EXP); double exp = payment.get(CurrencyType.EXP);
if (exp != 0D) { if (exp != 0D) {
message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(),
exp)); exp));
} }
// Whether or not to show this on player actionbar or on chat // Whether or not to show this on player actionbar or on chat
boolean showInActionbar = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID.toString(), boolean showInActionbar = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID.toString(),
Jobs.getGCManager().ActionBarsMessageByDefault); Jobs.getGCManager().ActionBarsMessageByDefault);
if (showInActionbar) { if (showInActionbar) {
CMIActionBar.send(abp, message); CMIActionBar.send(abp, message);
} else if (!Jobs.getGCManager().aBarSilentMode) { } else if (!Jobs.getGCManager().aBarSilentMode) {
abp.sendMessage(message); abp.sendMessage(message);
} }
} }
} }