From fd2d2456b94dadc91d864a12e88c6228f63e928e Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 13 Jun 2011 15:05:11 +0200 Subject: Renamed the Charge class to Trade --- Essentials/src/com/earth2me/essentials/Charge.java | 95 ---------------------- .../essentials/EssentialsPlayerListener.java | 16 ++-- Essentials/src/com/earth2me/essentials/Trade.java | 95 ++++++++++++++++++++++ .../earth2me/essentials/commands/Commandback.java | 4 +- .../earth2me/essentials/commands/Commandhome.java | 4 +- .../earth2me/essentials/commands/Commandjump.java | 4 +- .../earth2me/essentials/commands/Commandkit.java | 4 +- .../earth2me/essentials/commands/Commandtop.java | 4 +- .../earth2me/essentials/commands/Commandtp.java | 4 +- .../essentials/commands/Commandtpaccept.java | 4 +- .../essentials/commands/Commandtphere.java | 4 +- .../earth2me/essentials/commands/Commandtppos.java | 4 +- .../earth2me/essentials/commands/Commandwarp.java | 4 +- .../earth2me/essentials/commands/Commandworld.java | 4 +- .../essentials/commands/EssentialsCommand.java | 4 +- .../earth2me/essentials/spawn/Commandspawn.java | 4 +- 16 files changed, 129 insertions(+), 129 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/Charge.java create mode 100644 Essentials/src/com/earth2me/essentials/Trade.java diff --git a/Essentials/src/com/earth2me/essentials/Charge.java b/Essentials/src/com/earth2me/essentials/Charge.java deleted file mode 100644 index a84bfa918..000000000 --- a/Essentials/src/com/earth2me/essentials/Charge.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.earth2me.essentials; - -import org.bukkit.inventory.ItemStack; - - -public class Charge -{ - private final transient String command; - private final transient Double costs; - private final transient ItemStack items; - private final transient IEssentials ess; - - public Charge(final String command, final IEssentials ess) - { - this(command, null, null, ess); - } - - public Charge(final double money, final IEssentials ess) - { - this(null, money, null, ess); - } - - public Charge(final ItemStack items, final IEssentials ess) - { - this(null, null, items, ess); - } - - private Charge(final String command, final Double money, final ItemStack item, final IEssentials ess) - { - this.command = command; - this.costs = money; - this.items = item; - this.ess = ess; - } - - public void isAffordableFor(final IUser user) throws ChargeException - { - final double mon = user.getMoney(); - if (costs != null - && mon < costs - && !user.isAuthorized("essentials.eco.loan")) - { - throw new ChargeException(Util.i18n("notEnoughMoney")); - } - - if (items != null - && !InventoryWorkaround.containsItem(user.getInventory(), true, items)) - { - throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " "))); - } - - if (command != null && !command.isEmpty() - && !user.isAuthorized("essentials.nocommandcost.all") - && !user.isAuthorized("essentials.nocommandcost." + command) - && mon < ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command) - && !user.isAuthorized("essentials.eco.loan")) - { - throw new ChargeException(Util.i18n("notEnoughMoney")); - } - } - - public void charge(final IUser user) throws ChargeException - { - if (costs != null) - { - final double mon = user.getMoney(); - if (mon < costs && !user.isAuthorized("essentials.eco.loan")) - { - throw new ChargeException(Util.i18n("notEnoughMoney")); - } - user.takeMoney(costs); - } - if (items != null) - { - if (!InventoryWorkaround.containsItem(user.getInventory(), true, items)) - { - throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " "))); - } - InventoryWorkaround.removeItem(user.getInventory(), true, items); - user.updateInventory(); - } - if (command != null && !command.isEmpty() - && !user.isAuthorized("essentials.nocommandcost.all") - && !user.isAuthorized("essentials.nocommandcost." + command)) - { - final double mon = user.getMoney(); - final double cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command); - if (mon < cost && !user.isAuthorized("essentials.eco.loan")) - { - throw new ChargeException(Util.i18n("notEnoughMoney")); - } - user.takeMoney(cost); - } - } -} diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index bc63eff52..ace790c09 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -181,7 +181,7 @@ public class EssentialsPlayerListener extends PlayerListener event.setTo(loc); try { - user.getTeleport().now(loc, new Charge("portal", ess)); + user.getTeleport().now(loc, new Trade("portal", ess)); } catch (Exception ex) { @@ -474,13 +474,13 @@ public class EssentialsPlayerListener extends PlayerListener { if (sign.getLine(2).equals("ยง2Everyone")) { - Charge charge = chargeUserForWarp(sign, user); + Trade charge = chargeUserForWarp(sign, user); user.getTeleport().warp(sign.getLine(1), charge); return; } if (user.inGroup(sign.getLine(2))) { - Charge charge = chargeUserForWarp(sign, user); + Trade charge = chargeUserForWarp(sign, user); user.getTeleport().warp(sign.getLine(1), charge); return; } @@ -488,7 +488,7 @@ public class EssentialsPlayerListener extends PlayerListener if (user.isAuthorized("essentials.signs.warp.use") && (!ess.getSettings().getPerWarpPermission() || user.isAuthorized("essentials.warp." + sign.getLine(1)))) { - Charge charge = chargeUserForWarp(sign, user); + Trade charge = chargeUserForWarp(sign, user); user.getTeleport().warp(sign.getLine(1), charge); } return; @@ -520,7 +520,7 @@ public class EssentialsPlayerListener extends PlayerListener } } - private Charge chargeUserForWarp(Sign sign, User user) throws Exception + private Trade chargeUserForWarp(Sign sign, User user) throws Exception { if (!sign.getLine(3).isEmpty()) { @@ -533,15 +533,15 @@ public class EssentialsPlayerListener extends PlayerListener } if (m1) { - return new Charge(q1, ess); + return new Trade(q1, ess); } else { ItemStack i = ItemDb.get(l1[1], (int)q1); - return new Charge(i, ess); + return new Trade(i, ess); } } - return new Charge("warpsign", ess); + return new Trade("warpsign", ess); } @Override diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java new file mode 100644 index 000000000..a84bfa918 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/Trade.java @@ -0,0 +1,95 @@ +package com.earth2me.essentials; + +import org.bukkit.inventory.ItemStack; + + +public class Charge +{ + private final transient String command; + private final transient Double costs; + private final transient ItemStack items; + private final transient IEssentials ess; + + public Charge(final String command, final IEssentials ess) + { + this(command, null, null, ess); + } + + public Charge(final double money, final IEssentials ess) + { + this(null, money, null, ess); + } + + public Charge(final ItemStack items, final IEssentials ess) + { + this(null, null, items, ess); + } + + private Charge(final String command, final Double money, final ItemStack item, final IEssentials ess) + { + this.command = command; + this.costs = money; + this.items = item; + this.ess = ess; + } + + public void isAffordableFor(final IUser user) throws ChargeException + { + final double mon = user.getMoney(); + if (costs != null + && mon < costs + && !user.isAuthorized("essentials.eco.loan")) + { + throw new ChargeException(Util.i18n("notEnoughMoney")); + } + + if (items != null + && !InventoryWorkaround.containsItem(user.getInventory(), true, items)) + { + throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " "))); + } + + if (command != null && !command.isEmpty() + && !user.isAuthorized("essentials.nocommandcost.all") + && !user.isAuthorized("essentials.nocommandcost." + command) + && mon < ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command) + && !user.isAuthorized("essentials.eco.loan")) + { + throw new ChargeException(Util.i18n("notEnoughMoney")); + } + } + + public void charge(final IUser user) throws ChargeException + { + if (costs != null) + { + final double mon = user.getMoney(); + if (mon < costs && !user.isAuthorized("essentials.eco.loan")) + { + throw new ChargeException(Util.i18n("notEnoughMoney")); + } + user.takeMoney(costs); + } + if (items != null) + { + if (!InventoryWorkaround.containsItem(user.getInventory(), true, items)) + { + throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " "))); + } + InventoryWorkaround.removeItem(user.getInventory(), true, items); + user.updateInventory(); + } + if (command != null && !command.isEmpty() + && !user.isAuthorized("essentials.nocommandcost.all") + && !user.isAuthorized("essentials.nocommandcost." + command)) + { + final double mon = user.getMoney(); + final double cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command); + if (mon < cost && !user.isAuthorized("essentials.eco.loan")) + { + throw new ChargeException(Util.i18n("notEnoughMoney")); + } + user.takeMoney(cost); + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandback.java b/Essentials/src/com/earth2me/essentials/commands/Commandback.java index c852a7f99..26456a5d7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandback.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandback.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import org.bukkit.Server; @@ -16,7 +16,7 @@ public class Commandback extends EssentialsCommand @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.sendMessage(Util.i18n("backUsageMsg")); 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 c71ba4b0e..2649a9cb0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -16,7 +16,7 @@ public class Commandhome extends EssentialsCommand @Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); if(args.length > 0 && user.isAuthorized("essentials.home.others")) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java index 42ef0d424..5cdcbb2f2 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Location; import org.bukkit.Server; import com.earth2me.essentials.TargetBlock; @@ -36,7 +36,7 @@ public class Commandjump extends EssentialsCommand throw new Exception(Util.i18n("jumpError"), ex); } - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); 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 e02a6d766..849ec2398 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import java.util.Calendar; import java.util.HashMap; import java.util.List; @@ -109,7 +109,7 @@ public class Commandkit extends EssentialsCommand items = (List)kit; } - Charge charge = new Charge("kit-" + kitName, ess); + Trade charge = new Trade("kit-" + kitName, ess); try { charge.isAffordableFor(user); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java index 9704d4a59..8c0c687d0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Location; import org.bukkit.Server; import com.earth2me.essentials.User; @@ -21,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()), new Charge(this.getName(), ess)); + user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Trade(this.getName(), ess)); 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 64f7f8d08..a8b805e8d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import com.earth2me.essentials.Console; import org.bukkit.Server; import com.earth2me.essentials.User; @@ -30,7 +30,7 @@ public class Commandtp extends EssentialsCommand throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } user.sendMessage(Util.i18n("teleporting")); - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.getTeleport().teleport(p, charge); break; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index 1aab32cdf..0cba80020 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -23,7 +23,7 @@ public class Commandtpaccept extends EssentialsCommand throw new Exception(Util.i18n("noPendingRequest")); } - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); if (user.isTeleportRequestHere()) { charge.isAffordableFor(user); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java index 3710b121b..036c4be27 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -21,7 +21,7 @@ public class Commandtphere extends EssentialsCommand { throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } - p.getTeleport().teleport(user, new Charge(this.getName(), ess)); + p.getTeleport().teleport(user, new Trade(this.getName(), ess)); 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 05f95bc40..805aefaca 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Location; import org.bukkit.Server; import com.earth2me.essentials.User; @@ -26,7 +26,7 @@ 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); - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.sendMessage(Util.i18n("teleporting")); user.getTeleport().teleport(l, charge); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index f4e710aaf..50a8ff0cf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; @@ -73,7 +73,7 @@ public class Commandwarp extends EssentialsCommand private void warpUser(User user, String name) throws Exception { - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); if (ess.getSettings().getPerWarpPermission()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java index bdbe83798..0a315b1d4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import java.util.List; import org.bukkit.Location; import org.bukkit.Server; @@ -68,7 +68,7 @@ public class Commandworld extends EssentialsCommand Location loc = user.getLocation(); loc = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5); - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.getTeleport().teleport(loc, charge); } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 12c9258c0..d4f509aa0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import java.util.List; import org.bukkit.Server; import org.bukkit.command.Command; @@ -89,7 +89,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand { if (sender instanceof Player) { - Charge charge = new Charge(this.getName(), ess); + Trade charge = new Trade(this.getName(), ess); charge.charge(ess.getUser((Player)sender)); } } diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index 88a7c477b..5660c3778 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.spawn; -import com.earth2me.essentials.Charge; +import com.earth2me.essentials.Trade; import org.bukkit.Server; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.IEssentials; @@ -19,7 +19,7 @@ public class Commandspawn extends EssentialsCommand public void run(Server server, User user, String commandLabel, String[] args) throws Exception { final IEssentials ess = Essentials.getStatic(); - final Charge charge = new Charge(this.getName(), ess); + final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.getTeleport().respawn(ess.getSpawn(), charge); } -- cgit v1.2.3