From 406ae58391fac100a51e876710a10fc97bb43e72 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 21 Feb 2015 23:09:20 +1100 Subject: [PATCH] econ --- .../com/intellectualcrafters/plot/PlotSquared.java | 2 +- .../com/intellectualcrafters/plot/commands/Auto.java | 2 +- .../com/intellectualcrafters/plot/commands/Buy.java | 7 ++++--- .../com/intellectualcrafters/plot/commands/Claim.java | 2 +- .../com/intellectualcrafters/plot/commands/Merge.java | 2 +- .../intellectualcrafters/plot/object/PlotWorld.java | 2 +- .../intellectualcrafters/plot/util/EconHandler.java | 10 ++++++++++ .../plot/util/bukkit/BukkitPlayerFunctions.java | 2 +- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index 732961cce..3b1a61ee7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -381,6 +381,7 @@ public class PlotSquared { THIS = this; IMP = imp_class; VERSION = IMP.getVersion(); + economy = IMP.getEconomy(); C.setupTranslations(); C.saveTranslations(); if (getJavaVersion() < 1.7) { @@ -428,7 +429,6 @@ public class PlotSquared { if (Settings.AUTO_CLEAR) { ExpireManager.runTask(); } - economy = IMP.getEconomy(); } public void disable() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 4f0280435..0f30da926 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -138,7 +138,7 @@ public class Auto extends SubCommand { sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); return true; } - economy.withdrawPlayer(plr.getName(), cost); + EconHandler.withdrawPlayer(plr.getName(), cost); sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index d6ed4426f..5d0841bb2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -32,6 +32,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -92,12 +93,12 @@ public class Buy extends SubCommand { price += plotworld.PLOT_PRICE * size; initPrice += plotworld.SELL_PRICE * size; } - if (price > 0d) { + if (PlotSquared.economy != null && price > 0d) { final Economy economy = PlotSquared.economy; - if (economy.getBalance(plr) < price) { + if (EconHandler.getBalance(plr) < price) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); } - economy.withdrawPlayer(plr, price); + EconHandler.withdrawPlayer(plr, price); sendMessage(plr, C.REMOVED_BALANCE, price + ""); economy.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice); final Player owner = UUIDHandler.uuidWrapper.getPlayer(plot.owner); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 58385f02c..e9f74ba69 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -104,7 +104,7 @@ public class Claim extends SubCommand { if (economy.getBalance(plr) < cost) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); } - economy.withdrawPlayer(plr, cost); + EconHandler.withdrawPlayer(plr, cost); sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index b413fbef9..4f8941dfb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -151,7 +151,7 @@ public class Merge extends SubCommand { sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + ""); return false; } - economy.withdrawPlayer(plr, cost); + EconHandler.withdrawPlayer(plr, cost); sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index cf6ffd07e..af9070eec 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -115,7 +115,7 @@ public abstract class PlotWorld { this.SCHEMATIC_FILE = config.getString("schematic.file"); this.SCHEMATIC_CLAIM_SPECIFY = config.getBoolean("schematic.specify_on_claim"); this.SCHEMATICS = config.getStringList("schematic.schematics"); - this.USE_ECONOMY = config.getBoolean("economy.use"); + this.USE_ECONOMY = config.getBoolean("economy.use") && PlotSquared.economy != null; this.PLOT_PRICE = config.getDouble("economy.prices.claim"); this.MERGE_PRICE = config.getDouble("economy.prices.merge"); this.SELL_PRICE = config.getDouble("economy.prices.sell"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java index bae9074f9..8cca6b826 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EconHandler.java @@ -1,5 +1,15 @@ package com.intellectualcrafters.plot.util; +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.PlotPlayer; + public class EconHandler { // TODO economy shit + public static double getBalance(PlotPlayer player) { + return PlotSquared.economy.getBalance(player.getName()); + } + + public static void withdrawPlayer(PlotPlayer player, double amount) { + EconHandler.withdrawPlayer(player.getName(), amount); + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java index 24641c2cd..1f6f2d31d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/BukkitPlayerFunctions.java @@ -88,7 +88,7 @@ public class BukkitPlayerFunctions { MainUtil.sendMessage(BukkitUtil.getPlayer(plr), C.CANNOT_AFFORD_MERGE, "" + cost); return false; } - economy.withdrawPlayer(plr, cost); + EconHandler.withdrawPlayer(plr, cost); MainUtil.sendMessage(BukkitUtil.getPlayer(plr), C.REMOVED_BALANCE, cost + ""); } }