mirror of
https://github.com/garbagemule/MobArena.git
synced 2025-01-24 09:11:19 +01:00
Add support for minor economy values.
This commit is contained in:
parent
029a976dc7
commit
48686aafcb
@ -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:
|
||||
|
@ -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.
|
||||
|
@ -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();
|
||||
|
@ -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!");
|
||||
|
@ -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(", ");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user