mirror of
https://github.com/garbagemule/MobArena.git
synced 2025-01-24 17:21:20 +01:00
Add support for minor economy values.
This commit is contained in:
parent
029a976dc7
commit
48686aafcb
@ -1,7 +1,7 @@
|
|||||||
name: MobArena
|
name: MobArena
|
||||||
author: garbagemule
|
author: garbagemule
|
||||||
main: com.garbagemule.MobArena.MobArena
|
main: com.garbagemule.MobArena.MobArena
|
||||||
version: 0.95.5.9
|
version: 0.95.5.10
|
||||||
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
|
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
|
||||||
commands:
|
commands:
|
||||||
ma:
|
ma:
|
||||||
|
@ -1293,7 +1293,7 @@ public class ArenaImpl implements Arena
|
|||||||
for (ItemStack stack : entryFee) {
|
for (ItemStack stack : entryFee) {
|
||||||
// Economy money
|
// Economy money
|
||||||
if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
||||||
if (!plugin.hasEnough(p, stack.getAmount())) {
|
if (!plugin.hasEnough(p, stack)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1315,7 +1315,7 @@ public class ArenaImpl implements Arena
|
|||||||
|
|
||||||
// Take some economy money
|
// Take some economy money
|
||||||
for (ItemStack stack : InventoryUtils.extractAll(MobArena.ECONOMY_MONEY_ID, entryFee)) {
|
for (ItemStack stack : InventoryUtils.extractAll(MobArena.ECONOMY_MONEY_ID, entryFee)) {
|
||||||
plugin.takeMoney(p, stack.getAmount());
|
plugin.takeMoney(p, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take any other items
|
// Take any other items
|
||||||
@ -1334,7 +1334,7 @@ public class ArenaImpl implements Arena
|
|||||||
|
|
||||||
// Refund economy money
|
// Refund economy money
|
||||||
for (ItemStack stack : InventoryUtils.extractAll(MobArena.ECONOMY_MONEY_ID, entryFee)) {
|
for (ItemStack stack : InventoryUtils.extractAll(MobArena.ECONOMY_MONEY_ID, entryFee)) {
|
||||||
plugin.giveMoney(p, stack.getAmount());
|
plugin.giveMoney(p, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refund other items.
|
// Refund other items.
|
||||||
|
@ -475,8 +475,8 @@ public class ArenaListener
|
|||||||
if (reward != null) {
|
if (reward != null) {
|
||||||
String msg = p.getName() + " killed the boss and won: ";
|
String msg = p.getName() + " killed the boss and won: ";
|
||||||
if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
||||||
plugin.giveMoney(p, reward.getAmount());
|
plugin.giveMoney(p, reward);
|
||||||
msg += plugin.economyFormat(reward.getAmount());
|
msg += plugin.economyFormat(reward);
|
||||||
} else {
|
} else {
|
||||||
arena.getRewardManager().addReward((Player) damager, reward);
|
arena.getRewardManager().addReward((Player) damager, reward);
|
||||||
msg += MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount();
|
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!");
|
Messenger.warning("Could not add null reward. Please check the config-file!");
|
||||||
}
|
}
|
||||||
else if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
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
|
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.getAmount()));
|
Messenger.tellPlayer(p, Msg.WAVE_REWARD, plugin.economyFormat(reward));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Messenger.warning("Tried to add money, but no economy plugin detected!");
|
Messenger.warning("Tried to add money, but no economy plugin detected!");
|
||||||
|
@ -243,7 +243,7 @@ public class MAUtils
|
|||||||
for (E e : list) {
|
for (E e : list) {
|
||||||
stack = (ItemStack) e;
|
stack = (ItemStack) e;
|
||||||
if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
if (stack.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
||||||
String formatted = plugin.economyFormat(stack.getAmount());
|
String formatted = plugin.economyFormat(stack);
|
||||||
if (formatted != null) {
|
if (formatted != null) {
|
||||||
buffy.append(formatted);
|
buffy.append(formatted);
|
||||||
buffy.append(", ");
|
buffy.append(", ");
|
||||||
|
@ -12,6 +12,7 @@ import net.milkbowl.vault.economy.EconomyResponse.ResponseType;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
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) {
|
if (economy != null) {
|
||||||
EconomyResponse result = economy.depositPlayer(p.getName(), amount);
|
EconomyResponse result = economy.depositPlayer(p.getName(), getAmount(item));
|
||||||
return (result.type == ResponseType.SUCCESS);
|
return (result.type == ResponseType.SUCCESS);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean takeMoney(Player p, int amount) {
|
public boolean takeMoney(Player p, ItemStack item) {
|
||||||
if (economy != null) {
|
if (economy != null) {
|
||||||
EconomyResponse result = economy.withdrawPlayer(p.getName(), amount);
|
EconomyResponse result = economy.withdrawPlayer(p.getName(), getAmount(item));
|
||||||
return (result.type == ResponseType.SUCCESS);
|
return (result.type == ResponseType.SUCCESS);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEnough(Player p, double amount) {
|
public boolean hasEnough(Player p, ItemStack item) {
|
||||||
if (economy != null) {
|
if (economy != null) {
|
||||||
return (economy.getBalance(p.getName()) >= amount);
|
return (economy.getBalance(p.getName()) >= getAmount(item));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String economyFormat(double amount) {
|
public String economyFormat(ItemStack item) {
|
||||||
if (economy != null) {
|
if (economy != null) {
|
||||||
return economy.format(amount);
|
return economy.format(getAmount(item));
|
||||||
}
|
}
|
||||||
return null;
|
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) {
|
private static ItemStack singleItem(String item) {
|
||||||
if (item.matches("\\$[1-9][0-9]*")) {
|
if (item.matches("\\$([1-9]|([0-9].[0-9]))[0-9]*")) {
|
||||||
int amount = Integer.parseInt(item.substring(1));
|
double amount = Double.parseDouble(item.substring(1));
|
||||||
return new ItemStack(MobArena.ECONOMY_MONEY_ID, amount);
|
|
||||||
|
int major = (int) amount;
|
||||||
|
int minor = ((int) (amount * 100D)) % 100;
|
||||||
|
return new ItemStack(MobArena.ECONOMY_MONEY_ID, major, (short) minor);
|
||||||
}
|
}
|
||||||
int id = getTypeId(item);
|
int id = getTypeId(item);
|
||||||
return new ItemStack(id);
|
return new ItemStack(id);
|
||||||
|
Loading…
Reference in New Issue
Block a user