From ffbc2f9611ba6160c738d87397c09b656855971b Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 5 Jun 2015 22:39:48 +1000 Subject: [PATCH] Fixed errors --- .../plot/commands/Auto.java | 7 ++--- .../plot/commands/Buy.java | 10 +++---- .../plot/commands/Claim.java | 6 ++-- .../plot/commands/Delete.java | 4 +-- .../plot/commands/Merge.java | 12 ++++---- .../plot/commands/Unclaim.java | 4 +-- .../plot/commands/list.java | 5 ++-- .../plot/object/BukkitPlayer.java | 25 +++++++++++++++++ .../plot/object/PlotWorld.java | 3 +- .../plot/util/MainUtil.java | 25 +++++++++++++++++ .../util/bukkit/BukkitPlayerFunctions.java | 28 ++----------------- 11 files changed, 78 insertions(+), 51 deletions(-) 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 c217057c1..61923ed8d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -130,16 +130,15 @@ public class Auto extends SubCommand { return false; } final PlotWorld pWorld = PlotSquared.getPlotWorld(world); - if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY) { + if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { double cost = pWorld.PLOT_PRICE; cost = (size_x * size_z) * cost; if (cost > 0d) { - final Economy economy = PlotSquared.economy; - if (economy.getBalance(plr.getName()) < cost) { + if (EconHandler.manager.getMoney(plr) < cost) { sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); return true; } - EconHandler.withdrawPlayer(plr, cost); + EconHandler.manager.withdrawMoney(plr, 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 e1ef9ae5d..51bf5ff35 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -46,7 +46,7 @@ public class Buy extends SubCommand { @Override public boolean execute(final PlotPlayer plr, final String... args) { - if (PlotSquared.economy == null) { + if (EconHandler.manager == null) { return sendMessage(plr, C.ECON_DISABLED); } final Location loc = plr.getLocation(); @@ -93,13 +93,13 @@ public class Buy extends SubCommand { price += plotworld.PLOT_PRICE * size; initPrice += plotworld.SELL_PRICE * size; } - if ((PlotSquared.economy != null) && (price > 0d)) { - if (EconHandler.getBalance(plr) < price) { + if ((EconHandler.manager != null) && (price > 0d)) { + if (EconHandler.manager.getMoney(plr) < price) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); } - EconHandler.withdrawPlayer(plr, price); + EconHandler.manager.withdrawMoney(plr, price); sendMessage(plr, C.REMOVED_BALANCE, price + ""); - EconHandler.depositPlayer(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice); + EconHandler.manager.depositMoney(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice); final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner); if (owner != null) { sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + ""); 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 970ba937a..ef1f75809 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -98,13 +98,13 @@ public class Claim extends SubCommand { return sendMessage(plr, C.PLOT_IS_CLAIMED); } final PlotWorld world = PlotSquared.getPlotWorld(plot.world); - if ((PlotSquared.economy != null) && world.USE_ECONOMY) { + if ((EconHandler.manager != null) && world.USE_ECONOMY) { final double cost = world.PLOT_PRICE; if (cost > 0d) { - if (EconHandler.getBalance(plr) < cost) { + if (EconHandler.manager.getMoney(plr) < cost) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); } - EconHandler.withdrawPlayer(plr, cost); + EconHandler.manager.withdrawMoney(plr, cost); sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index 541d5ee5a..fb416dde1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -62,10 +62,10 @@ public class Delete extends SubCommand { Runnable runnable = new Runnable() { @Override public void run() { - if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) { + if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) { final double c = pWorld.SELL_PRICE; if (c > 0d) { - EconHandler.depositPlayer(plr, c); + EconHandler.manager.depositMoney(plr, c); sendMessage(plr, C.ADDED_BALANCE, c + ""); } } 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 d330383c8..948e271dc 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -173,15 +173,15 @@ public class Merge extends SubCommand { return; } final PlotWorld plotWorld = PlotSquared.getPlotWorld(world); - if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) { + if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) { double cost = plotWorld.MERGE_PRICE; cost = plots.size() * cost; if (cost > 0d) { - if (EconHandler.getBalance(plr) < cost) { + if (EconHandler.manager.getMoney(plr) < cost) { sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + ""); return; } - EconHandler.withdrawPlayer(plr, cost); + EconHandler.manager.withdrawMoney(plr, cost); sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } @@ -202,15 +202,15 @@ public class Merge extends SubCommand { return true; } final PlotWorld plotWorld = PlotSquared.getPlotWorld(world); - if ((PlotSquared.economy != null) && plotWorld.USE_ECONOMY) { + if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) { double cost = plotWorld.MERGE_PRICE; cost = plots.size() * cost; if (cost > 0d) { - if (EconHandler.getBalance(plr) < cost) { + if (EconHandler.manager.getMoney(plr) < cost) { sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + ""); return false; } - EconHandler.withdrawPlayer(plr, cost); + EconHandler.manager.withdrawMoney(plr, cost); sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java index a296887dd..63f60a66d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unclaim.java @@ -51,10 +51,10 @@ public class Unclaim extends SubCommand { } assert plot != null; final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world); - if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY) { + if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { final double c = pWorld.SELL_PRICE; if (c > 0d) { - EconHandler.depositPlayer(plr, c); + EconHandler.manager.depositMoney(plr, c); sendMessage(plr, C.ADDED_BALANCE, c + ""); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java index 9e85e0004..d0a203b9a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -32,6 +32,7 @@ import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringComparison; @@ -60,7 +61,7 @@ public class list extends SubCommand { final StringBuilder builder = new StringBuilder(); builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s()); if (plr != null) { - if (PlotSquared.economy != null) { + if (EconHandler.manager != null) { builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "unowned", "unknown", "forsale", "", ""})); } else { @@ -161,7 +162,7 @@ public class list extends SubCommand { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.forsale"); return false; } - if (PlotSquared.economy == null) { + if (EconHandler.manager == null) { break; } plots = new HashSet<>(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index 7509c106d..6adc1fbc1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -4,9 +4,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; @@ -149,4 +153,25 @@ public class BukkitPlayer implements PlotPlayer { public String toString() { return getName(); } + + @Override + public void setAttribute(String key) { + Permission perm = Bukkit.getServer().getPluginManager().getPermission(key); + if (perm == null) { + perm = new Permission(key, PermissionDefault.FALSE); + Bukkit.getServer().getPluginManager().addPermission(perm); + Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm); + } + EconHandler.manager.setPermission(this, key, true); + } + + @Override + public boolean getAttribute(String key) { + return player.hasPermission(key); + } + + @Override + public void removeAttribute(String key) { + EconHandler.manager.setPermission(this, key, false); + } } 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 a5305e1ee..c8defbc13 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.util.EconHandler; /** * @author Jesse Boyd @@ -139,7 +140,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") && (PlotSquared.economy != null); + this.USE_ECONOMY = config.getBoolean("economy.use") && (EconHandler.manager != 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/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index af82a0d42..80d99afd7 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -67,6 +67,31 @@ public class MainUtil { return true; } + /** + * Merges all plots in the arraylist (with cost) + * + * @param plr + * @param world + * @param plotIds + * + * @return boolean + */ + public static boolean mergePlots(final PlotPlayer player, final String world, final ArrayList plotIds) { + final PlotWorld plotworld = PlotSquared.getPlotWorld(world); + if ((EconHandler.manager != null) && plotworld.USE_ECONOMY) { + final double cost = plotIds.size() * plotworld.MERGE_PRICE; + if (cost > 0d) { + if (EconHandler.manager.getMoney(player) < cost) { + MainUtil.sendMessage(player, C.CANNOT_AFFORD_MERGE, "" + cost); + return false; + } + EconHandler.manager.withdrawMoney(player, cost); + MainUtil.sendMessage(player, C.REMOVED_BALANCE, cost + ""); + } + } + return MainUtil.mergePlots(world, plotIds, true); + } + public static boolean unlinkPlot(final Plot plot) { final String world = plot.world; final PlotId pos1 = MainUtil.getBottomPlot(plot).id; 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 c45e5c4f9..122faa8f1 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 @@ -27,12 +27,14 @@ import java.util.UUID; import net.milkbowl.vault.economy.Economy; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; 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; @@ -69,32 +71,6 @@ public class BukkitPlayerFunctions { } } - /** - * Merges all plots in the arraylist (with cost) - * - * @param plr - * @param world - * @param plotIds - * - * @return boolean - */ - public static boolean mergePlots(final Player plr, final String world, final ArrayList plotIds) { - final PlotWorld plotworld = PlotSquared.getPlotWorld(world); - if ((PlotSquared.economy != null) && plotworld.USE_ECONOMY) { - final double cost = plotIds.size() * plotworld.MERGE_PRICE; - if (cost > 0d) { - final Economy economy = PlotSquared.economy; - if (economy.getBalance(plr) < cost) { - MainUtil.sendMessage(BukkitUtil.getPlayer(plr), C.CANNOT_AFFORD_MERGE, "" + cost); - return false; - } - EconHandler.withdrawPlayer(BukkitUtil.getPlayer(plr), cost); - MainUtil.sendMessage(BukkitUtil.getPlayer(plr), C.REMOVED_BALANCE, cost + ""); - } - } - return MainUtil.mergePlots(world, plotIds, true); - } - public static String getPlayerName(final UUID uuid) { if (uuid == null) { return "unknown";