diff options
28 files changed, 208 insertions, 117 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Charge.java b/Essentials/src/com/earth2me/essentials/Charge.java new file mode 100644 index 000000000..d1dbcebc0 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/Charge.java @@ -0,0 +1,104 @@ +package com.earth2me.essentials; + +import com.earth2me.essentials.commands.EssentialsCommand; +import org.bukkit.inventory.ItemStack; + + +public class Charge +{ + private String command = null; + private Double costs = null; + private ItemStack items = null; + private Essentials ess = Essentials.getStatic(); + + public Charge(String command) + { + this.command = command; + } + + public Charge(double money) + { + this.costs = money; + } + + public Charge(ItemStack items) + { + this.items = items; + } + + public Charge(EssentialsCommand command) + { + this.command = command.getName(); + } + + public void isAffordableFor(User user) throws Exception + { + double mon = user.getMoney(); + if (costs != null) + { + if (mon < costs && !user.isAuthorized("essentials.eco.loan")) + { + throw new Exception(Util.i18n("notEnoughMoney")); + } + } + if (items != null) + { + if (!InventoryWorkaround.containsItem(user.getInventory(), true, items)) + { + throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " "))); + } + } + if (command != null && !command.isEmpty()) + { + if (user.isAuthorized("essentials.nocommandcost.all") + || user.isAuthorized("essentials.nocommandcost." + command)) + { + return; + } + double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command); + if (mon < cost && !user.isAuthorized("essentials.eco.loan")) + { + throw new Exception(Util.i18n("notEnoughMoney")); + } + } + } + + public void charge(User user) throws Exception + { + double mon = user.getMoney(); + if (costs != null) + { + if (mon < costs && !user.isAuthorized("essentials.eco.loan")) + { + throw new Exception(Util.i18n("notEnoughMoney")); + } + user.takeMoney(costs); + user.sendMessage(Util.format("moneyTaken", Util.formatCurrency(costs))); + } + if (items != null) + { + if (!InventoryWorkaround.containsItem(user.getInventory(), true, items)) + { + throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " "))); + } + InventoryWorkaround.removeItem(user.getInventory(), true, items); + user.updateInventory(); + } + if (command != null && !command.isEmpty()) + { + if (user.isAuthorized("essentials.nocommandcost.all") + || user.isAuthorized("essentials.nocommandcost." + command)) + { + return; + } + + double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command); + if (mon < cost && !user.isAuthorized("essentials.eco.loan")) + { + throw new Exception(Util.i18n("notEnoughMoney")); + } + user.takeMoney(cost); + user.sendMessage(Util.format("moneyTaken", Util.formatCurrency(cost))); + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 35c607e02..f0b4941b7 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -2,7 +2,6 @@ package com.earth2me.essentials; import java.util.Iterator; import java.util.List; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import net.minecraft.server.InventoryPlayer; @@ -163,7 +162,7 @@ public class EssentialsPlayerListener extends PlayerListener event.setTo(loc); try { - user.getTeleport().teleport(loc, "portal"); + user.getTeleport().teleport(loc, new Charge("portal")); } catch (Exception ex) { @@ -456,22 +455,22 @@ public class EssentialsPlayerListener extends PlayerListener { if (sign.getLine(2).equals("§2Everyone")) { - chargeUserForWarp(sign, user); - user.getTeleport().warp(sign.getLine(1), "warpsign"); + Charge charge = chargeUserForWarp(sign, user); + user.getTeleport().warp(sign.getLine(1), charge); return; } if (user.inGroup(sign.getLine(2))) { - chargeUserForWarp(sign, user); - user.getTeleport().warp(sign.getLine(1), "warpsign"); + Charge charge = chargeUserForWarp(sign, user); + user.getTeleport().warp(sign.getLine(1), charge); return; } } if (user.isAuthorized("essentials.signs.warp.use") && (!ess.getSettings().getPerWarpPermission() || user.isAuthorized("essentials.warp." + sign.getLine(1)))) { - chargeUserForWarp(sign, user); - user.getTeleport().warp(sign.getLine(1), "warpsign"); + Charge charge = chargeUserForWarp(sign, user); + user.getTeleport().warp(sign.getLine(1), charge); } return; } @@ -482,7 +481,7 @@ public class EssentialsPlayerListener extends PlayerListener } } - private void chargeUserForWarp(Sign sign, User user) throws Exception + private Charge chargeUserForWarp(Sign sign, User user) throws Exception { if (!sign.getLine(3).isEmpty()) { @@ -495,24 +494,15 @@ public class EssentialsPlayerListener extends PlayerListener } if (m1) { - if (user.getMoney() < q1) - { - throw new Exception(Util.i18n("notEnoughMoney")); - } - user.takeMoney(q1); - user.sendMessage(Util.format("moneyTaken", Util.formatCurrency(q1))); + return new Charge(q1); } else { ItemStack i = ItemDb.get(l1[1], (int)q1); - if (!InventoryWorkaround.containsItem(user.getInventory(), true, i)) - { - throw new Exception(Util.format("missingItems", (int)q1, l1[1])); - } - InventoryWorkaround.removeItem(user.getInventory(), true, i); - user.updateInventory(); + return new Charge(i); } } + return new Charge("warpsign"); } @Override diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 9b16dd6b9..a618e3eab 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -44,10 +44,10 @@ public class Teleport implements Runnable private long initY; private long initZ; private Target teleportTarget; - private String chargeFor; + private Charge chargeFor; private Essentials ess; - private void initTimer(long delay, Target target, String chargeFor) + private void initTimer(long delay, Target target, Charge chargeFor) { this.started = System.currentTimeMillis(); this.delay = delay; @@ -91,7 +91,7 @@ public class Teleport implements Runnable now(teleportTarget); if (chargeFor != null) { - user.charge(chargeFor); + chargeFor.charge(user); } } catch (Throwable ex) @@ -113,12 +113,12 @@ public class Teleport implements Runnable this.ess = ess; } - public void respawn(Spawn spawn, String chargeFor) throws Exception + public void respawn(Spawn spawn, Charge chargeFor) throws Exception { teleport(new Target(spawn.getSpawn(user.getGroup())), chargeFor); } - public void warp(String warp, String chargeFor) throws Exception + public void warp(String warp, Charge chargeFor) throws Exception { Location loc = Essentials.getWarps().getWarp(warp); teleport(new Target(loc), chargeFor); @@ -172,27 +172,28 @@ public class Teleport implements Runnable cancel(false); } - public void teleport(Location loc, String name) throws Exception + public void teleport(Location loc, Charge chargeFor) throws Exception { - teleport(new Target(loc), name); + teleport(new Target(loc), chargeFor); } - public void teleport(Entity entity, String name) throws Exception + public void teleport(Entity entity, Charge chargeFor) throws Exception { - teleport(new Target(entity), name); + teleport(new Target(entity), chargeFor); } - private void teleport(Target target, String chargeFor) throws Exception + private void teleport(Target target, Charge chargeFor) throws Exception { double delay = ess.getSettings().getTeleportDelay(); + chargeFor.isAffordableFor(user); cooldown(true); if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) { now(target); if (chargeFor != null) { - user.charge(chargeFor); + chargeFor.charge(user); } return; } @@ -224,7 +225,7 @@ public class Teleport implements Runnable now(new Target(entity)); } - public void back(final String chargeFor) throws Exception + public void back(final Charge chargeFor) throws Exception { teleport(new Target(user.getLastLocation()), chargeFor); } @@ -234,12 +235,12 @@ public class Teleport implements Runnable back(null); } - public void home(String chargeFor) throws Exception + public void home(Charge chargeFor) throws Exception { home(user, chargeFor); } - public void home(User user, String chargeFor) throws Exception + public void home(User user, Charge chargeFor) throws Exception { Location loc = user.getHome(this.user.getLocation()); if (loc == null) diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 26279171f..c8ef473c0 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -117,32 +117,6 @@ public class User extends UserData implements Comparable<User>, IReplyTo sendMessage(Util.format("takenFromAccount", Util.formatCurrency(value))); } - public void charge(String cmd) throws Exception - { - if (isAuthorized("essentials.nocommandcost.all") - || isAuthorized("essentials.nocommandcost." + cmd)) - { - return; - } - double mon = getMoney(); - double cost = ess.getSettings().getCommandCost(cmd.startsWith("/") ? cmd.substring(1) : cmd); - if (mon < cost && !isAuthorized("essentials.eco.loan")) - { - throw new Exception(Util.i18n("notEnoughMoney")); - } - takeMoney(cost); - } - - public void canAfford(String cmd) throws Exception - { - double mon = getMoney(); - double cost = ess.getSettings().getCommandCost(cmd.startsWith("/") ? cmd.substring(1) : cmd); - if (mon < cost && !isAuthorized("essentials.eco.loan")) - { - throw new Exception(Util.i18n("notEnoughMoney")); - } - } - public boolean canAfford(double cost) { double mon = getMoney(); @@ -156,21 +130,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo } } - public void canAfford(IEssentialsCommand cmd) throws Exception - { - canAfford(cmd.getName()); - } - public void dispose() { this.base = new OfflinePlayer(getName()); } - public void charge(IEssentialsCommand cmd) throws Exception - { - charge(cmd.getName()); - } - public boolean getJustPortaled() { return justPortaled; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandback.java b/Essentials/src/com/earth2me/essentials/commands/Commandback.java index f9a45857b..a244a4e3a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandback.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandback.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import org.bukkit.Server; @@ -15,8 +16,9 @@ public class Commandback extends EssentialsCommand @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - user.canAfford(this); + Charge charge = new Charge(this); + charge.isAffordableFor(user); user.sendMessage(Util.i18n("backUsageMsg")); - user.getTeleport().back(this.getName()); + user.getTeleport().back(charge); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index f82b12421..a5cde8d3f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -15,7 +16,8 @@ public class Commandhome extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - user.canAfford(this); + Charge charge = new Charge(this); + charge.isAffordableFor(user); if(args.length > 0 && user.isAuthorized("essentials.home.others")) { User u; @@ -31,9 +33,9 @@ public class Commandhome extends EssentialsCommand { throw new Exception(Util.i18n("playerNotFound")); } - user.getTeleport().home(u, this.getName()); + user.getTeleport().home(u, charge); return; } - user.getTeleport().home(this.getName()); + user.getTeleport().home(charge); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java index cd1953ece..d1dd5c763 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import org.bukkit.Location; import org.bukkit.Server; import com.earth2me.essentials.TargetBlock; @@ -35,7 +36,8 @@ public class Commandjump extends EssentialsCommand throw new Exception(Util.i18n("jumpError"), ex); } - user.canAfford(this); - user.getTeleport().teleport(loc, this.getName()); + Charge charge = new Charge(this); + charge.isAffordableFor(user); + user.getTeleport().teleport(loc, charge); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java index 8065234ab..2badf51fc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import java.util.Calendar; import java.util.HashMap; import java.util.List; @@ -109,9 +110,10 @@ public class Commandkit extends EssentialsCommand items = (List<String>)kit; } + Charge charge = new Charge("kit-" + kitName); try { - user.canAfford("kit-" + kitName); + charge.isAffordableFor(user); } catch (Exception ex) { @@ -139,8 +141,8 @@ public class Commandkit extends EssentialsCommand } try { - user.charge(this); - user.charge("kit-" + kitName); + charge(user); + charge.charge(user); } catch (Exception ex) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java index 35d8ee755..794fd81f1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java @@ -28,7 +28,7 @@ public class Commandlightning extends EssentialsCommand if (args.length < 1 & user != null) { user.getWorld().strikeLightning(user.getTargetBlock(null, 600).getLocation()); - user.charge(this); + charge(user); return; } @@ -38,6 +38,10 @@ public class Commandlightning extends EssentialsCommand return; } + if (user != null) + { + charge(user); + } for (Player p : server.matchPlayer(args[0])) { sender.sendMessage(Util.format("lightningUse", p.getDisplayName())); @@ -48,7 +52,5 @@ public class Commandlightning extends EssentialsCommand p.sendMessage(Util.i18n("lightningSmited")); } } - if (user != null) - user.charge(this); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index e959157ec..e9431ddf3 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -2,7 +2,6 @@ package com.earth2me.essentials.commands; import org.bukkit.Server; import org.bukkit.command.CommandSender; -import com.earth2me.essentials.Essentials; import org.bukkit.entity.Player; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -67,7 +66,7 @@ public class Commandnick extends EssentialsCommand } } - user.charge(this); + charge(user); user.setDisplayName(ess.getConfiguration().getString("nickname-prefix", "~") + nick); user.setNickname(nick); user.sendMessage(Util.format("nickSet", user.getDisplayName() + "§7.")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index 99139ef6c..4d5ad8e9b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -21,7 +21,7 @@ public class Commandrealname extends EssentialsCommand throw new NotEnoughArgumentsException(); } String whois = args[0].toLowerCase(); - user.charge(this); + charge(user); for (Player p : server.getOnlinePlayers()) { User u = ess.getUser(p); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java index 59e9a1dd2..b1ffd3f7f 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandthunder.java @@ -22,7 +22,7 @@ public class Commandthunder extends EssentialsCommand throw new NotEnoughArgumentsException(); } - user.charge(this); + charge(user); World world = user.getWorld(); boolean setThunder = args[0].equalsIgnoreCase("true"); if (args.length > 1) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index 2cb2695b1..22360753c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import org.bukkit.Location; import org.bukkit.Server; import com.earth2me.essentials.User; @@ -20,7 +21,7 @@ public class Commandtop extends EssentialsCommand int topZ = user.getLocation().getBlockZ(); int topY = user.getWorld().getHighestBlockYAt(topX, topZ); charge(user); - user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), this.getName()); + user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Charge(this)); user.sendMessage(Util.i18n("teleportTop")); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java index f5393e7c9..52b868da4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import com.earth2me.essentials.Console; import org.bukkit.Server; import com.earth2me.essentials.User; @@ -29,8 +30,9 @@ public class Commandtp extends EssentialsCommand throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } user.sendMessage(Util.i18n("teleporting")); - user.canAfford(this); - user.getTeleport().teleport(p, this.getName()); + Charge charge = new Charge(this); + charge.isAffordableFor(user); + user.getTeleport().teleport(p, charge); break; case 2: diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index 77a510438..f3b7ae505 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -13,7 +13,7 @@ public class Commandtpa extends EssentialsCommand } @Override - public void run(Server server, User player, String commandLabel, String[] args) throws Exception + public void run(Server server, User user, String commandLabel, String[] args) throws Exception { if (args.length < 1) { @@ -25,14 +25,14 @@ public class Commandtpa extends EssentialsCommand { throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } - player.charge(this); - if (!p.isIgnoredPlayer(player.getName())) + charge(user); + if (!p.isIgnoredPlayer(user.getName())) { - p.requestTeleport(player, false); - p.sendMessage(Util.format("teleportRequest", player.getDisplayName())); + p.requestTeleport(user, false); + p.sendMessage(Util.format("teleportRequest", user.getDisplayName())); p.sendMessage(Util.i18n("typeTpaccept")); p.sendMessage(Util.i18n("typeTpdeny")); } - player.sendMessage(Util.format("requestSent", p.getDisplayName())); + user.sendMessage(Util.format("requestSent", p.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index 752ac7ac2..921b9bc89 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -22,17 +23,25 @@ public class Commandtpaccept extends EssentialsCommand throw new Exception(Util.i18n("noPendingRequest")); } - user.canAfford(this); + Charge charge = new Charge(this); + if (user.isTeleportRequestHere()) + { + charge.isAffordableFor(user); + } + else + { + charge.isAffordableFor(p); + } user.sendMessage(Util.i18n("requestAccepted")); p.sendMessage(Util.i18n("requestAccepted")); if (user.isTeleportRequestHere()) { - user.getTeleport().teleport(p, this.getName()); + user.getTeleport().teleport(p, charge); } else { - p.getTeleport().teleport(user, this.getName()); + p.getTeleport().teleport(user, charge); } user.requestTeleport(null, false); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java index 414a5b28f..2003bbf73 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpahere.java @@ -25,7 +25,7 @@ public class Commandtpahere extends EssentialsCommand { throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } - user.charge(this); + charge(user); p.requestTeleport(user, true); p.sendMessage(Util.format("teleportHereRequest", user.getDisplayName())); p.sendMessage(Util.i18n("typeTpaccept")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java index f5b7f5801..097ea1fdd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpdeny.java @@ -21,7 +21,7 @@ public class Commandtpdeny extends EssentialsCommand throw new Exception(Util.i18n("noPendingRequest")); } - user.charge(this); + charge(user); user.sendMessage(Util.i18n("requestDenied")); p.sendMessage(Util.i18n("requestDenied")); user.requestTeleport(null, false); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index f0c206ff3..d10ba4e78 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -20,7 +21,7 @@ public class Commandtphere extends EssentialsCommand { throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } - p.getTeleport().teleport(user, commandLabel); + p.getTeleport().teleport(user, new Charge(this)); user.sendMessage(Util.i18n("teleporting")); p.sendMessage(Util.i18n("teleporting")); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java index 2f32237a1..ee03479d1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import org.bukkit.Location; import org.bukkit.Server; import com.earth2me.essentials.User; @@ -25,8 +26,9 @@ public class Commandtppos extends EssentialsCommand int y = Integer.parseInt(args[1]); int z = Integer.parseInt(args[2]); Location l = new Location(user.getWorld(), x, y, z); - user.canAfford(this); + Charge charge = new Charge(this); + charge.isAffordableFor(user); user.sendMessage(Util.i18n("teleporting")); - user.getTeleport().teleport(l, this.getName()); + user.getTeleport().teleport(l, charge); } }
\ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java index 6c90a8b7f..8e3b567b4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtree.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtree.java @@ -66,7 +66,7 @@ public class Commandtree extends EssentialsCommand boolean success = user.getWorld().generateTree(safeLocation, (TreeType)tree); if (success) { - user.charge(this); + charge(user); user.sendMessage(Util.i18n("treeSpawned")); } else diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 6429892ff..6c3aef64d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -1,11 +1,11 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import org.bukkit.Server; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import com.earth2me.essentials.Warps; -import org.bukkit.command.CommandSender; public class Commandwarp extends EssentialsCommand @@ -74,16 +74,18 @@ public class Commandwarp extends EssentialsCommand private void warpUser(User user, String name) throws Exception { + Charge charge = new Charge(this); + charge.isAffordableFor(user); if (ess.getSettings().getPerWarpPermission()) { if (user.isAuthorized("essentials.warp." + name)) { - user.getTeleport().warp(name, this.getName()); + user.getTeleport().warp(name, charge); return; } user.sendMessage(Util.i18n("warpUsePermission")); return; } - user.getTeleport().warp(name, this.getName()); + user.getTeleport().warp(name, charge); } }
\ No newline at end of file diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java index 6e846dab9..eec1d9575 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandweather.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandweather.java @@ -23,7 +23,7 @@ public class Commandweather extends EssentialsCommand boolean isStorm = args[0].equalsIgnoreCase("storm"); World world = user.getWorld(); - user.charge(this); + charge(user); if (args.length > 1) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index a2f7d15d6..fbd53da05 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import java.util.List; import org.bukkit.Location; import org.bukkit.Server; @@ -68,7 +69,8 @@ public class Commandworld extends EssentialsCommand Location loc = user.getLocation(); loc = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5); - user.canAfford(this); - user.getTeleport().teleport(loc, this.getName()); + Charge charge = new Charge(this); + charge.isAffordableFor(user); + user.getTeleport().teleport(loc, charge); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java index af86e5bec..02f915bb1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java @@ -45,7 +45,7 @@ public class Commandworth extends EssentialsCommand throw new Exception(Util.i18n("itemCannotBeSold")); } - user.charge(this); + charge(user); user.sendMessage(is.getDurability() != 0 ? Util.format("worthMeta", is.getType().toString().toLowerCase().replace("_", ""), diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 3091e3fcb..d1c268c6d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Charge; import java.util.List; import org.bukkit.Server; import org.bukkit.command.Command; @@ -83,7 +84,8 @@ public abstract class EssentialsCommand implements IEssentialsCommand { if (sender instanceof Player) { - ess.getUser((Player)sender).charge(this); + Charge charge = new Charge(this); + charge.charge(ess.getUser((Player)sender)); } } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java index 6d2dfc467..a19fa3d9a 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java @@ -17,7 +17,7 @@ public class Commandsetspawn extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - user.charge(this); + charge(user); String group = args.length > 0 ? getFinalArg(args, 0) : "default"; Essentials.getSpawn().setSpawn(user.getLocation(), group); user.sendMessage(Util.format("spawnSet", group)); diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index 36af5740b..f36b284e3 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.spawn; +import com.earth2me.essentials.Charge; import org.bukkit.Server; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; @@ -16,7 +17,8 @@ public class Commandspawn extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - user.canAfford(this); - user.getTeleport().respawn(Essentials.getSpawn(), this.getName()); + Charge charge = new Charge(this); + charge.isAffordableFor(user); + user.getTeleport().respawn(Essentials.getSpawn(), charge); } } |