mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-04 23:37:49 +01:00
parent
aebcd6bffc
commit
f5d4302717
@ -790,10 +790,8 @@ public class Jobs extends JavaPlugin {
|
|||||||
getPermissionHandler().registerPermissions();
|
getPermissionHandler().registerPermissions();
|
||||||
|
|
||||||
// set the system to auto save
|
// set the system to auto save
|
||||||
if (getGCManager().getSavePeriod() > 0) {
|
saveTask = new DatabaseSaveThread(getGCManager().getSavePeriod());
|
||||||
saveTask = new DatabaseSaveThread(getGCManager().getSavePeriod());
|
saveTask.start();
|
||||||
saveTask.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// schedule payouts to buffered payments
|
// schedule payouts to buffered payments
|
||||||
paymentThread = new BufferedPaymentThread(getGCManager().getEconomyBatchDelay());
|
paymentThread = new BufferedPaymentThread(getGCManager().getEconomyBatchDelay());
|
||||||
|
@ -601,7 +601,7 @@ public class GeneralConfigManager {
|
|||||||
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");
|
||||||
c.addComment("Economy.Taxes.Amount", "Amount in percentage");
|
c.addComment("Economy.Taxes.Amount", "Amount in percentage. You can grant money and points permissions (jobs.tax.money.amount, jobs.tax.points.amount) for taxes.");
|
||||||
TaxesAmount = c.get("Economy.Taxes.Amount", 15.0);
|
TaxesAmount = c.get("Economy.Taxes.Amount", 15.0);
|
||||||
c.addComment("Economy.Taxes.TransferToServerAccount", "Do you want to transfer taxes to server account?");
|
c.addComment("Economy.Taxes.TransferToServerAccount", "Do you want to transfer taxes to server account?");
|
||||||
TransferToServerAccount = c.get("Economy.Taxes.TransferToServerAccount", true);
|
TransferToServerAccount = c.get("Economy.Taxes.TransferToServerAccount", true);
|
||||||
|
@ -37,12 +37,14 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
public class BufferedEconomy {
|
public class BufferedEconomy {
|
||||||
|
|
||||||
private Jobs plugin;
|
private Jobs plugin;
|
||||||
private Economy economy;
|
private Economy economy;
|
||||||
|
|
||||||
private final LinkedBlockingQueue<BufferedPayment> payments = new LinkedBlockingQueue<>();
|
private final 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 ServerTaxesAccount = null;
|
private OfflinePlayer serverTaxesAccount;
|
||||||
|
|
||||||
public BufferedEconomy(Jobs plugin, Economy economy) {
|
public BufferedEconomy(Jobs plugin, Economy economy) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -94,17 +96,17 @@ public class BufferedEconomy {
|
|||||||
|
|
||||||
synchronized (paymentCache) {
|
synchronized (paymentCache) {
|
||||||
|
|
||||||
Double TotalAmount = 0.0, TotalPoints = 0.0, TaxesAmount = 0.0, TaxesPoints = 0.0;
|
Double totalAmount = 0.0, totalPoints = 0.0, taxesAmount = 0.0, taxesPoints = 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();
|
||||||
TotalAmount += payment.get(CurrencyType.MONEY);
|
totalAmount += payment.get(CurrencyType.MONEY);
|
||||||
TotalPoints += payment.get(CurrencyType.POINTS);
|
totalPoints += payment.get(CurrencyType.POINTS);
|
||||||
|
|
||||||
if (Jobs.getGCManager().UseTaxes) {
|
if (Jobs.getGCManager().UseTaxes) {
|
||||||
TaxesAmount += payment.get(CurrencyType.MONEY) * (Jobs.getGCManager().TaxesAmount / 100.0);
|
taxesAmount += payment.get(CurrencyType.MONEY) * (Jobs.getGCManager().TaxesAmount / 100.0);
|
||||||
TaxesPoints += payment.get(CurrencyType.POINTS) * (Jobs.getGCManager().TaxesAmount / 100.0);
|
taxesPoints += payment.get(CurrencyType.POINTS) * (Jobs.getGCManager().TaxesAmount / 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflinePlayer offPlayer = payment.getOfflinePlayer();
|
OfflinePlayer offPlayer = payment.getOfflinePlayer();
|
||||||
@ -121,8 +123,19 @@ public class BufferedEconomy {
|
|||||||
|
|
||||||
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())) {
|
||||||
money = money - (money * (Jobs.getGCManager().TaxesAmount / 100.0));
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId());
|
||||||
points = points - (points * (Jobs.getGCManager().TaxesAmount / 100.0));
|
double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false, true);
|
||||||
|
if (moneyTaxAmount == 0D) {
|
||||||
|
moneyTaxAmount = Jobs.getGCManager().TaxesAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false, true);
|
||||||
|
if (pointsTaxAmount == 0D) {
|
||||||
|
pointsTaxAmount = Jobs.getGCManager().TaxesAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
money = money - (money * (moneyTaxAmount / 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);
|
||||||
@ -134,35 +147,49 @@ public class BufferedEconomy {
|
|||||||
|
|
||||||
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())) {
|
||||||
payment.set(CurrencyType.MONEY, money - (money * (Jobs.getGCManager().TaxesAmount / 100.0)));
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(offPlayer.getUniqueId());
|
||||||
payment.set(CurrencyType.POINTS, points - (points * (Jobs.getGCManager().TaxesAmount / 100.0)));
|
double moneyTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.money", false, false, true);
|
||||||
|
if (moneyTaxAmount == 0D) {
|
||||||
|
moneyTaxAmount = Jobs.getGCManager().TaxesAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
double pointsTaxAmount = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.tax.points", false, false, true);
|
||||||
|
if (pointsTaxAmount == 0D) {
|
||||||
|
pointsTaxAmount = Jobs.getGCManager().TaxesAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
money = money - (money * (moneyTaxAmount / 100.0));
|
||||||
|
points = points - (points * (pointsTaxAmount / 100.0));
|
||||||
|
|
||||||
|
payment.set(CurrencyType.MONEY, money);
|
||||||
|
payment.set(CurrencyType.POINTS, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
paymentCache.put(uuid, payment);
|
paymentCache.put(uuid, payment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String ServerAccountname = Jobs.getGCManager().ServerAccountName;
|
String serverAccountName = Jobs.getGCManager().ServerAccountName;
|
||||||
String ServerTaxesAccountname = Jobs.getGCManager().ServertaxesAccountName;
|
String serverTaxesAccountName = Jobs.getGCManager().ServertaxesAccountName;
|
||||||
|
|
||||||
if (ServerTaxesAccount == null)
|
if (serverTaxesAccount == null)
|
||||||
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) {
|
||||||
economy.depositPlayer(ServerTaxesAccount, TaxesAmount);
|
economy.depositPlayer(serverTaxesAccount, taxesAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ServerTaxesAccount.isOnline() && Jobs.getGCManager().ActionBarsMessageByDefault) {
|
if (serverTaxesAccount.isOnline() && Jobs.getGCManager().ActionBarsMessageByDefault) {
|
||||||
ActionBarManager.send(Bukkit.getPlayer(ServerAccountname),
|
ActionBarManager.send(Bukkit.getPlayer(serverAccountName),
|
||||||
Jobs.getLanguage().getMessage("message.taxes", "[amount]", (int) (TotalAmount * 100) / 100.0));
|
Jobs.getLanguage().getMessage("message.taxes", "[amount]", (int) (totalAmount * 100) / 100.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasMoney = false;
|
boolean hasMoney = false;
|
||||||
if (Jobs.getGCManager().UseServerAccount && 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
|
||||||
@ -174,14 +201,14 @@ public class BufferedEconomy {
|
|||||||
continue;
|
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) {
|
||||||
ActionBarManager.send(payment.getOfflinePlayer().getPlayer(), Jobs.getLanguage().getMessage("economy.error.nomoney"));
|
ActionBarManager.send(payment.getOfflinePlayer().getPlayer(), Jobs.getLanguage().getMessage("economy.error.nomoney"));
|
||||||
@ -194,7 +221,8 @@ public class BufferedEconomy {
|
|||||||
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
||||||
|
|
||||||
// Action bar stuff
|
// Action bar stuff
|
||||||
ShowActionBar(payment);
|
showActionBar(payment);
|
||||||
|
|
||||||
if (payment.getOfflinePlayer().isOnline() && Version.getCurrent().isHigher(Version.v1_8_R3)) {
|
if (payment.getOfflinePlayer().isOnline() && Version.getCurrent().isHigher(Version.v1_8_R3)) {
|
||||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId());
|
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId());
|
||||||
Jobs.getBBManager().ShowJobProgression(jPlayer);
|
Jobs.getBBManager().ShowJobProgression(jPlayer);
|
||||||
@ -206,7 +234,7 @@ public class BufferedEconomy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowActionBar(BufferedPayment payment) {
|
public void showActionBar(BufferedPayment payment) {
|
||||||
if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline()
|
if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline()
|
||||||
|| !Jobs.getGCManager().ActionBarsMessageByDefault || !payment.containsPayment())
|
|| !Jobs.getGCManager().ActionBarsMessageByDefault || !payment.containsPayment())
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user