mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-07 08:58:10 +01:00
Better economy handling
This commit is contained in:
parent
4c8ea6b001
commit
56e9189193
@ -5,6 +5,7 @@ import net.citizensnpcs.api.event.PlayerCreateNPCEvent;
|
|||||||
import net.citizensnpcs.util.Messages;
|
import net.citizensnpcs.util.Messages;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -26,14 +27,13 @@ public class PaymentListener implements Listener {
|
|||||||
if (!hasAccount || event.getCreator().hasPermission("citizens.npc.ignore-cost"))
|
if (!hasAccount || event.getCreator().hasPermission("citizens.npc.ignore-cost"))
|
||||||
return;
|
return;
|
||||||
double cost = Setting.NPC_COST.asDouble();
|
double cost = Setting.NPC_COST.asDouble();
|
||||||
boolean hasEnough = provider.has(name, cost);
|
EconomyResponse response = provider.withdrawPlayer(name, cost);
|
||||||
String formattedCost = provider.format(cost);
|
if (!response.transactionSuccess()) {
|
||||||
if (!hasEnough) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.setCancelReason(Messaging.tr(Messages.MINIMUM_COST_REQUIRED, formattedCost));
|
event.setCancelReason(response.errorMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
provider.withdrawPlayer(name, cost);
|
String formattedCost = provider.format(cost);
|
||||||
Messaging.sendTr(event.getCreator(), Messages.MONEY_WITHDRAWN, formattedCost);
|
Messaging.sendTr(event.getCreator(), Messages.MONEY_WITHDRAWN, formattedCost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user