From 48686aafcbce504ff3987c9b53126a4d61872ebb Mon Sep 17 00:00:00 2001 From: garbagemule Date: Sat, 3 Aug 2013 04:16:31 +0200 Subject: [PATCH] Add support for minor economy values. --- resources/plugin.yml | 2 +- src/com/garbagemule/MobArena/ArenaImpl.java | 6 ++--- .../garbagemule/MobArena/ArenaListener.java | 4 ++-- .../garbagemule/MobArena/MASpawnThread.java | 4 ++-- src/com/garbagemule/MobArena/MAUtils.java | 2 +- src/com/garbagemule/MobArena/MobArena.java | 23 ++++++++++++------- .../garbagemule/MobArena/util/ItemParser.java | 9 +++++--- 7 files changed, 30 insertions(+), 20 deletions(-) diff --git a/resources/plugin.yml b/resources/plugin.yml index 686fa46..bb48596 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,7 +1,7 @@ name: MobArena author: garbagemule main: com.garbagemule.MobArena.MobArena -version: 0.95.5.9 +version: 0.95.5.10 softdepend: [Spout,Towny,Heroes,MagicSpells,Vault] commands: ma: diff --git a/src/com/garbagemule/MobArena/ArenaImpl.java b/src/com/garbagemule/MobArena/ArenaImpl.java index fa473cb..06221d2 100644 --- a/src/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/com/garbagemule/MobArena/ArenaImpl.java @@ -1293,7 +1293,7 @@ public class ArenaImpl implements Arena for (ItemStack stack : entryFee) { // Economy money if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) { - if (!plugin.hasEnough(p, stack.getAmount())) { + if (!plugin.hasEnough(p, stack)) { return false; } } @@ -1315,7 +1315,7 @@ public class ArenaImpl implements Arena // Take some economy money for (ItemStack stack : InventoryUtils.extractAll(MobArena.ECONOMY_MONEY_ID, entryFee)) { - plugin.takeMoney(p, stack.getAmount()); + plugin.takeMoney(p, stack); } // Take any other items @@ -1334,7 +1334,7 @@ public class ArenaImpl implements Arena // Refund economy money for (ItemStack stack : InventoryUtils.extractAll(MobArena.ECONOMY_MONEY_ID, entryFee)) { - plugin.giveMoney(p, stack.getAmount()); + plugin.giveMoney(p, stack); } // Refund other items. diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 5790c8f..c336f98 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -475,8 +475,8 @@ public class ArenaListener if (reward != null) { String msg = p.getName() + " killed the boss and won: "; if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) { - plugin.giveMoney(p, reward.getAmount()); - msg += plugin.economyFormat(reward.getAmount()); + plugin.giveMoney(p, reward); + msg += plugin.economyFormat(reward); } else { arena.getRewardManager().addReward((Player) damager, reward); msg += MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount(); diff --git a/src/com/garbagemule/MobArena/MASpawnThread.java b/src/com/garbagemule/MobArena/MASpawnThread.java index e8a1b4a..b0ad11f 100644 --- a/src/com/garbagemule/MobArena/MASpawnThread.java +++ b/src/com/garbagemule/MobArena/MASpawnThread.java @@ -321,8 +321,8 @@ public class MASpawnThread implements Runnable Messenger.warning("Could not add null reward. Please check the config-file!"); } else if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) { - if (plugin.giveMoney(p, reward.getAmount())) { // Money already awarded here, not needed at end of match as well - Messenger.tellPlayer(p, Msg.WAVE_REWARD, plugin.economyFormat(reward.getAmount())); + if (plugin.giveMoney(p, reward)) { // Money already awarded here, not needed at end of match as well + Messenger.tellPlayer(p, Msg.WAVE_REWARD, plugin.economyFormat(reward)); } else { Messenger.warning("Tried to add money, but no economy plugin detected!"); diff --git a/src/com/garbagemule/MobArena/MAUtils.java b/src/com/garbagemule/MobArena/MAUtils.java index 03ce880..fb88ebd 100644 --- a/src/com/garbagemule/MobArena/MAUtils.java +++ b/src/com/garbagemule/MobArena/MAUtils.java @@ -243,7 +243,7 @@ public class MAUtils for (E e : list) { stack = (ItemStack) e; if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) { - String formatted = plugin.economyFormat(stack.getAmount()); + String formatted = plugin.economyFormat(stack); if (formatted != null) { buffy.append(formatted); buffy.append(", "); diff --git a/src/com/garbagemule/MobArena/MobArena.java b/src/com/garbagemule/MobArena/MobArena.java index 6778a1d..8d7d382 100644 --- a/src/com/garbagemule/MobArena/MobArena.java +++ b/src/com/garbagemule/MobArena/MobArena.java @@ -12,6 +12,7 @@ import net.milkbowl.vault.economy.EconomyResponse.ResponseType; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.RegisteredServiceProvider; @@ -271,33 +272,39 @@ public class MobArena extends JavaPlugin } } - public boolean giveMoney(Player p, int amount) { + public boolean giveMoney(Player p, ItemStack item) { if (economy != null) { - EconomyResponse result = economy.depositPlayer(p.getName(), amount); + EconomyResponse result = economy.depositPlayer(p.getName(), getAmount(item)); return (result.type == ResponseType.SUCCESS); } return false; } - public boolean takeMoney(Player p, int amount) { + public boolean takeMoney(Player p, ItemStack item) { if (economy != null) { - EconomyResponse result = economy.withdrawPlayer(p.getName(), amount); + EconomyResponse result = economy.withdrawPlayer(p.getName(), getAmount(item)); return (result.type == ResponseType.SUCCESS); } return false; } - public boolean hasEnough(Player p, double amount) { + public boolean hasEnough(Player p, ItemStack item) { if (economy != null) { - return (economy.getBalance(p.getName()) >= amount); + return (economy.getBalance(p.getName()) >= getAmount(item)); } return true; } - public String economyFormat(double amount) { + public String economyFormat(ItemStack item) { if (economy != null) { - return economy.format(amount); + return economy.format(getAmount(item)); } return null; } + + private double getAmount(ItemStack item) { + double major = item.getAmount(); + double minor = item.getDurability() / 100D; + return major + minor; + } } \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/util/ItemParser.java b/src/com/garbagemule/MobArena/util/ItemParser.java index 0bc278b..7401c5f 100644 --- a/src/com/garbagemule/MobArena/util/ItemParser.java +++ b/src/com/garbagemule/MobArena/util/ItemParser.java @@ -151,9 +151,12 @@ public class ItemParser } private static ItemStack singleItem(String item) { - if (item.matches("\\$[1-9][0-9]*")) { - int amount = Integer.parseInt(item.substring(1)); - return new ItemStack(MobArena.ECONOMY_MONEY_ID, amount); + if (item.matches("\\$([1-9]|([0-9].[0-9]))[0-9]*")) { + double amount = Double.parseDouble(item.substring(1)); + + int major = (int) amount; + int minor = ((int) (amount * 100D)) % 100; + return new ItemStack(MobArena.ECONOMY_MONEY_ID, major, (short) minor); } int id = getTypeId(item); return new ItemStack(id);