mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Only initialise EconHandler when economy is enabled and stop accessing the static instance directly.
This commit is contained in:
parent
efab6e92f7
commit
f64026af1a
@ -155,8 +155,8 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean hasPermission(final String permission) {
|
@Override public boolean hasPermission(final String permission) {
|
||||||
if (this.offline && EconHandler.manager != null) {
|
if (this.offline && EconHandler.getEconHandler() != null) {
|
||||||
return EconHandler.manager.hasPermission(getName(), permission);
|
return EconHandler.getEconHandler().hasPermission(getName(), permission);
|
||||||
}
|
}
|
||||||
return this.player.hasPermission(permission);
|
return this.player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
@ -48,28 +48,26 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
return this.econ != null && this.perms != null;
|
return this.econ != null && this.perms != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupPermissions() {
|
private void setupPermissions() {
|
||||||
RegisteredServiceProvider<Permission> permissionProvider =
|
RegisteredServiceProvider<Permission> permissionProvider =
|
||||||
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
if (permissionProvider != null) {
|
if (permissionProvider != null) {
|
||||||
this.perms = permissionProvider.getProvider();
|
this.perms = permissionProvider.getProvider();
|
||||||
}
|
}
|
||||||
return this.perms != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupEconomy() {
|
private void setupEconomy() {
|
||||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
RegisteredServiceProvider<Economy> economyProvider =
|
RegisteredServiceProvider<Economy> economyProvider =
|
||||||
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
this.econ = economyProvider.getProvider();
|
this.econ = economyProvider.getProvider();
|
||||||
}
|
}
|
||||||
return this.econ != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public double getMoney(PlotPlayer player) {
|
@Override public double getMoney(PlotPlayer<?> player) {
|
||||||
double bal = super.getMoney(player);
|
double bal = super.getMoney(player);
|
||||||
if (Double.isNaN(bal)) {
|
if (Double.isNaN(bal)) {
|
||||||
return this.econ.getBalance(((BukkitPlayer) player).player);
|
return this.econ.getBalance(((BukkitPlayer) player).player);
|
||||||
@ -77,11 +75,11 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
return bal;
|
return bal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void withdrawMoney(PlotPlayer player, double amount) {
|
@Override public void withdrawMoney(PlotPlayer<?> player, double amount) {
|
||||||
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void depositMoney(PlotPlayer player, double amount) {
|
@Override public void depositMoney(PlotPlayer<?> player, double amount) {
|
||||||
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,11 +91,11 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public double getBalance(PlotPlayer player) {
|
@Override public double getBalance(PlotPlayer<?> player) {
|
||||||
return this.econ.getBalance(player.getName());
|
return this.econ.getBalance(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermission(String world, String player, String perm, boolean value) {
|
@Deprecated public void setPermission(String world, String player, String perm, boolean value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.perms.playerAdd(world, player, perm);
|
this.perms.playerAdd(world, player, perm);
|
||||||
} else {
|
} else {
|
||||||
|
@ -304,8 +304,7 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
// Economy
|
// Economy
|
||||||
if (Settings.Enabled_Components.ECONOMY) {
|
if (Settings.Enabled_Components.ECONOMY) {
|
||||||
TaskManager
|
TaskManager.runTask(() -> EconHandler.initializeEconHandler());
|
||||||
.runTask(() -> EconHandler.manager = PlotSquared.this.IMP.getEconomyHandler());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
|
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
|
||||||
|
@ -157,9 +157,9 @@ public class Auto extends SubCommand {
|
|||||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||||
PlotArea plotarea = player.getApplicablePlotArea();
|
PlotArea plotarea = player.getApplicablePlotArea();
|
||||||
if (plotarea == null) {
|
if (plotarea == null) {
|
||||||
if (EconHandler.manager != null) {
|
if (EconHandler.getEconHandler() != null) {
|
||||||
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
|
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
|
||||||
if (EconHandler.manager
|
if (EconHandler.getEconHandler()
|
||||||
.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
|
.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
|
||||||
if (plotarea != null) {
|
if (plotarea != null) {
|
||||||
plotarea = null;
|
plotarea = null;
|
||||||
@ -253,18 +253,18 @@ public class Auto extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (EconHandler.manager != null && plotarea.useEconomy()) {
|
if (EconHandler.getEconHandler() != null && plotarea.useEconomy()) {
|
||||||
Expression<Double> costExp = plotarea.getPrices().get("claim");
|
Expression<Double> costExp = plotarea.getPrices().get("claim");
|
||||||
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ?
|
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ?
|
||||||
player.getPlotCount() :
|
player.getPlotCount() :
|
||||||
player.getPlotCount(plotarea.getWorldName())));
|
player.getPlotCount(plotarea.getWorldName())));
|
||||||
cost = (size_x * size_z) * cost;
|
cost = (size_x * size_z) * cost;
|
||||||
if (cost > 0d) {
|
if (cost > 0d) {
|
||||||
if (!force && EconHandler.manager.getMoney(player) < cost) {
|
if (!force && EconHandler.getEconHandler().getMoney(player) < cost) {
|
||||||
sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
|
sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
EconHandler.manager.withdrawMoney(player, cost);
|
EconHandler.getEconHandler().withdrawMoney(player, cost);
|
||||||
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
|
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class Buy extends Command {
|
|||||||
RunnableVal3<Command, Runnable, Runnable> confirm,
|
RunnableVal3<Command, Runnable, Runnable> confirm,
|
||||||
final RunnableVal2<Command, CommandResult> whenDone) {
|
final RunnableVal2<Command, CommandResult> whenDone) {
|
||||||
|
|
||||||
check(EconHandler.manager, Captions.ECON_DISABLED);
|
check(EconHandler.getEconHandler(), Captions.ECON_DISABLED);
|
||||||
final Plot plot;
|
final Plot plot;
|
||||||
if (args.length != 0) {
|
if (args.length != 0) {
|
||||||
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
|
||||||
@ -82,7 +82,7 @@ public class Buy extends Command {
|
|||||||
confirm.run(this, () -> {
|
confirm.run(this, () -> {
|
||||||
Captions.REMOVED_BALANCE.send(player, price);
|
Captions.REMOVED_BALANCE.send(player, price);
|
||||||
|
|
||||||
EconHandler.manager.depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
|
EconHandler.getEconHandler().depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
|
||||||
|
|
||||||
PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
|
PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
|
@ -105,14 +105,14 @@ public class Claim extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((EconHandler.manager != null) && area.useEconomy() && !force) {
|
if ((EconHandler.getEconHandler() != null) && area.useEconomy() && !force) {
|
||||||
Expression<Double> costExr = area.getPrices().get("claim");
|
Expression<Double> costExr = area.getPrices().get("claim");
|
||||||
double cost = costExr.evaluate((double) currentPlots);
|
double cost = costExr.evaluate((double) currentPlots);
|
||||||
if (cost > 0d) {
|
if (cost > 0d) {
|
||||||
if (EconHandler.manager.getMoney(player) < cost) {
|
if (EconHandler.getEconHandler().getMoney(player) < cost) {
|
||||||
return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
|
return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
|
||||||
}
|
}
|
||||||
EconHandler.manager.withdrawMoney(player, cost);
|
EconHandler.getEconHandler().withdrawMoney(player, cost);
|
||||||
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
|
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ public class DebugExec extends SubCommand {
|
|||||||
this.scope.put("BlockManager", WorldUtil.IMP);
|
this.scope.put("BlockManager", WorldUtil.IMP);
|
||||||
this.scope.put("SetupUtils", SetupUtils.manager);
|
this.scope.put("SetupUtils", SetupUtils.manager);
|
||||||
this.scope.put("EventUtil", PlotSquared.get().getEventDispatcher());
|
this.scope.put("EventUtil", PlotSquared.get().getEventDispatcher());
|
||||||
this.scope.put("EconHandler", EconHandler.manager);
|
this.scope.put("EconHandler", EconHandler.getEconHandler());
|
||||||
this.scope.put("DBFunc", DBFunc.dbManager);
|
this.scope.put("DBFunc", DBFunc.dbManager);
|
||||||
this.scope.put("HybridUtils", HybridUtils.manager);
|
this.scope.put("HybridUtils", HybridUtils.manager);
|
||||||
this.scope.put("IMP", PlotSquared.get().IMP);
|
this.scope.put("IMP", PlotSquared.get().IMP);
|
||||||
|
@ -86,11 +86,11 @@ public class Delete extends SubCommand {
|
|||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
boolean result = plot.deletePlot(() -> {
|
boolean result = plot.deletePlot(() -> {
|
||||||
plot.removeRunning();
|
plot.removeRunning();
|
||||||
if ((EconHandler.manager != null) && plotArea.useEconomy()) {
|
if ((EconHandler.getEconHandler() != null) && plotArea.useEconomy()) {
|
||||||
Expression<Double> valueExr = plotArea.getPrices().get("sell");
|
Expression<Double> valueExr = plotArea.getPrices().get("sell");
|
||||||
double value = plots.size() * valueExr.evaluate((double) currentPlots);
|
double value = plots.size() * valueExr.evaluate((double) currentPlots);
|
||||||
if (value > 0d) {
|
if (value > 0d) {
|
||||||
EconHandler.manager.depositMoney(player, value);
|
EconHandler.getEconHandler().depositMoney(player, value);
|
||||||
sendMessage(player, Captions.ADDED_BALANCE, String.valueOf(value));
|
sendMessage(player, Captions.ADDED_BALANCE, String.valueOf(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ public class ListCmd extends SubCommand {
|
|||||||
|
|
||||||
private String[] getArgumentList(PlotPlayer player) {
|
private String[] getArgumentList(PlotPlayer player) {
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
if (EconHandler.manager != null && Permissions
|
if (EconHandler.getEconHandler() != null && Permissions
|
||||||
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
||||||
args.add("forsale");
|
args.add("forsale");
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ public class ListCmd extends SubCommand {
|
|||||||
Captions.PERMISSION_LIST_FOR_SALE);
|
Captions.PERMISSION_LIST_FOR_SALE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (EconHandler.manager == null) {
|
if (EconHandler.getEconHandler() == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getFlag(PriceFlag.class) > 0));
|
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getFlag(PriceFlag.class) > 0));
|
||||||
@ -404,7 +404,7 @@ public class ListCmd extends SubCommand {
|
|||||||
|
|
||||||
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
|
||||||
final List<String> completions = new LinkedList<>();
|
final List<String> completions = new LinkedList<>();
|
||||||
if (EconHandler.manager != null && Permissions
|
if (EconHandler.getEconHandler() != null && Permissions
|
||||||
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
|
||||||
completions.add("forsale");
|
completions.add("forsale");
|
||||||
}
|
}
|
||||||
|
@ -164,14 +164,14 @@ public class MainCommand extends Command {
|
|||||||
public void run(final Command cmd, final Runnable success, final Runnable failure) {
|
public void run(final Command cmd, final Runnable success, final Runnable failure) {
|
||||||
if (cmd.hasConfirmation(player)) {
|
if (cmd.hasConfirmation(player)) {
|
||||||
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
|
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
|
||||||
if (EconHandler.manager != null) {
|
if (EconHandler.getEconHandler() != null) {
|
||||||
PlotArea area = player.getApplicablePlotArea();
|
PlotArea area = player.getApplicablePlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
Expression<Double> priceEval =
|
Expression<Double> priceEval =
|
||||||
area.getPrices().get(cmd.getFullId());
|
area.getPrices().get(cmd.getFullId());
|
||||||
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||||
if (price != null
|
if (price != null
|
||||||
&& EconHandler.manager.getMoney(player) < price) {
|
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
||||||
if (failure != null) {
|
if (failure != null) {
|
||||||
failure.run();
|
failure.run();
|
||||||
}
|
}
|
||||||
@ -185,12 +185,12 @@ public class MainCommand extends Command {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (EconHandler.manager != null) {
|
if (EconHandler.getEconHandler() != null) {
|
||||||
PlotArea area = player.getApplicablePlotArea();
|
PlotArea area = player.getApplicablePlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
Expression<Double> priceEval = area.getPrices().get(cmd.getFullId());
|
Expression<Double> priceEval = area.getPrices().get(cmd.getFullId());
|
||||||
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||||
if (price != 0d && EconHandler.manager.getMoney(player) < price) {
|
if (price != 0d && EconHandler.getEconHandler().getMoney(player) < price) {
|
||||||
if (failure != null) {
|
if (failure != null) {
|
||||||
failure.run();
|
failure.run();
|
||||||
}
|
}
|
||||||
@ -252,14 +252,14 @@ public class MainCommand extends Command {
|
|||||||
if ("f".equals(args[0].substring(1))) {
|
if ("f".equals(args[0].substring(1))) {
|
||||||
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
|
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
|
||||||
@Override public void run(Command cmd, Runnable success, Runnable failure) {
|
@Override public void run(Command cmd, Runnable success, Runnable failure) {
|
||||||
if (EconHandler.manager != null) {
|
if (EconHandler.getEconHandler() != null) {
|
||||||
PlotArea area = player.getApplicablePlotArea();
|
PlotArea area = player.getApplicablePlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
Expression<Double> priceEval =
|
Expression<Double> priceEval =
|
||||||
area.getPrices().get(cmd.getFullId());
|
area.getPrices().get(cmd.getFullId());
|
||||||
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
||||||
if (price != 0d
|
if (price != 0d
|
||||||
&& EconHandler.manager.getMoney(player) < price) {
|
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
||||||
if (failure != null) {
|
if (failure != null) {
|
||||||
failure.run();
|
failure.run();
|
||||||
}
|
}
|
||||||
|
@ -156,8 +156,8 @@ public class Merge extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (plot.autoMerge(Direction.ALL, maxSize, uuid, terrain)) {
|
if (plot.autoMerge(Direction.ALL, maxSize, uuid, terrain)) {
|
||||||
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
|
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
|
||||||
EconHandler.manager.withdrawMoney(player, price);
|
EconHandler.getEconHandler().withdrawMoney(player, price);
|
||||||
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
||||||
@ -174,8 +174,8 @@ public class Merge extends SubCommand {
|
|||||||
uuid = plot.getOwnerAbs();
|
uuid = plot.getOwnerAbs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!force && EconHandler.manager != null && plotArea.useEconomy() && price > 0d
|
if (!force && EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d
|
||||||
&& EconHandler.manager.getMoney(player) < price) {
|
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
||||||
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
|
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -192,8 +192,8 @@ public class Merge extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) {
|
if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) {
|
||||||
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
|
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
|
||||||
EconHandler.manager.withdrawMoney(player, price);
|
EconHandler.getEconHandler().withdrawMoney(player, price);
|
||||||
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
||||||
@ -226,12 +226,12 @@ public class Merge extends SubCommand {
|
|||||||
sendMessage(accepter, Captions.MERGE_NOT_VALID);
|
sendMessage(accepter, Captions.MERGE_NOT_VALID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
|
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
|
||||||
if (!force && EconHandler.manager.getMoney(player) < price) {
|
if (!force && EconHandler.getEconHandler().getMoney(player) < price) {
|
||||||
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
|
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EconHandler.manager.withdrawMoney(player, price);
|
EconHandler.getEconHandler().withdrawMoney(player, price);
|
||||||
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
|
||||||
|
@ -170,12 +170,12 @@ public class ComponentPresetManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (componentPreset.getCost() > 0.0D && EconHandler.manager != null && plot.getArea().useEconomy()) {
|
if (componentPreset.getCost() > 0.0D && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()) {
|
||||||
if (EconHandler.manager.getMoney(player) < componentPreset.getCost()) {
|
if (EconHandler.getEconHandler().getMoney(player) < componentPreset.getCost()) {
|
||||||
Captions.PRESET_CANNOT_AFFORD.send(player);
|
Captions.PRESET_CANNOT_AFFORD.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
EconHandler.manager.withdrawMoney(player, componentPreset.getCost());
|
EconHandler.getEconHandler().withdrawMoney(player, componentPreset.getCost());
|
||||||
Captions.REMOVED_BALANCE.send(player, componentPreset.getCost() + "");
|
Captions.REMOVED_BALANCE.send(player, componentPreset.getCost() + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ public class ComponentPresetManager {
|
|||||||
for (int i = 0; i < allowedPresets.size(); i++) {
|
for (int i = 0; i < allowedPresets.size(); i++) {
|
||||||
final ComponentPreset preset = allowedPresets.get(i);
|
final ComponentPreset preset = allowedPresets.get(i);
|
||||||
final List<String> lore = new ArrayList<>();
|
final List<String> lore = new ArrayList<>();
|
||||||
if (preset.getCost() > 0 && EconHandler.manager != null && plot.getArea().useEconomy()){
|
if (preset.getCost() > 0 && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()){
|
||||||
lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%",
|
lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%",
|
||||||
String.format("%.2f", preset.getCost())));
|
String.format("%.2f", preset.getCost())));
|
||||||
}
|
}
|
||||||
|
@ -756,18 +756,18 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
|
|||||||
* The amount of money this Player has.
|
* The amount of money this Player has.
|
||||||
*/
|
*/
|
||||||
public double getMoney() {
|
public double getMoney() {
|
||||||
return EconHandler.manager == null ? 0 : EconHandler.manager.getMoney(this);
|
return EconHandler.getEconHandler() == null ? 0 : EconHandler.getEconHandler().getMoney(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void withdraw(double amount) {
|
public void withdraw(double amount) {
|
||||||
if (EconHandler.manager != null) {
|
if (EconHandler.getEconHandler() != null) {
|
||||||
EconHandler.manager.withdrawMoney(this, amount);
|
EconHandler.getEconHandler().withdrawMoney(this, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deposit(double amount) {
|
public void deposit(double amount) {
|
||||||
if (EconHandler.manager != null) {
|
if (EconHandler.getEconHandler() != null) {
|
||||||
EconHandler.manager.depositMoney(this, amount);
|
EconHandler.getEconHandler().depositMoney(this, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,36 +25,52 @@
|
|||||||
*/
|
*/
|
||||||
package com.plotsquared.core.util;
|
package com.plotsquared.core.util;
|
||||||
|
|
||||||
|
import com.plotsquared.core.IPlotMain;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.player.ConsolePlayer;
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class EconHandler {
|
public abstract class EconHandler {
|
||||||
|
|
||||||
public static EconHandler manager;
|
/**
|
||||||
private static boolean initialized;
|
* @deprecated This will be made private in the future
|
||||||
|
*/
|
||||||
|
@Deprecated public static EconHandler manager;
|
||||||
|
|
||||||
public static EconHandler getEconHandler() {
|
/**
|
||||||
if (initialized) {
|
* Initialize the economy handler using
|
||||||
return manager;
|
* {@link IPlotMain#getEconomyHandler()}
|
||||||
|
*/
|
||||||
|
public static void initializeEconHandler() {
|
||||||
|
if (manager != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
initialized = true;
|
manager = PlotSquared.get().IMP.getEconomyHandler();
|
||||||
return manager = PlotSquared.get().IMP.getEconomyHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMoney(PlotPlayer player) {
|
/**
|
||||||
|
* Return the econ handler instance, if one exists
|
||||||
|
*
|
||||||
|
* @return Economy handler instance
|
||||||
|
*/
|
||||||
|
@Nullable public static EconHandler getEconHandler() {
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMoney(PlotPlayer<?> player) {
|
||||||
if (player instanceof ConsolePlayer) {
|
if (player instanceof ConsolePlayer) {
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
}
|
}
|
||||||
return getBalance(player);
|
return getBalance(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract double getBalance(PlotPlayer player);
|
public abstract double getBalance(PlotPlayer<?> player);
|
||||||
|
|
||||||
public abstract void withdrawMoney(PlotPlayer player, double amount);
|
public abstract void withdrawMoney(PlotPlayer<?> player, double amount);
|
||||||
|
|
||||||
public abstract void depositMoney(PlotPlayer player, double amount);
|
public abstract void depositMoney(PlotPlayer<?> player, double amount);
|
||||||
|
|
||||||
public abstract void depositMoney(OfflinePlotPlayer player, double amount);
|
public abstract void depositMoney(OfflinePlotPlayer player, double amount);
|
||||||
|
|
||||||
|
@ -76,6 +76,8 @@ subprojects {
|
|||||||
delete("../target")
|
delete("../target")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
javadoc.options.encoding = 'UTF-8'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile group: 'org.json', name: 'json', version: '20200518'
|
compile group: 'org.json', name: 'json', version: '20200518'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user