mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 11:06:14 +01:00
Add per-class option 'price'.
This commit is contained in:
parent
97e5dd0b63
commit
619f07f11b
@ -1,7 +1,7 @@
|
||||
name: MobArena
|
||||
author: garbagemule
|
||||
main: com.garbagemule.MobArena.MobArena
|
||||
version: 0.96.2.4
|
||||
version: 0.96.2.5
|
||||
softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault]
|
||||
commands:
|
||||
ma:
|
||||
|
@ -18,13 +18,14 @@ public class ArenaClass
|
||||
private Map<String,Boolean> perms;
|
||||
private Map<String,Boolean> lobbyperms;
|
||||
private boolean unbreakableWeapons, unbreakableArmor;
|
||||
private double price;
|
||||
private Location classchest;
|
||||
|
||||
/**
|
||||
* Create a new, empty arena class with the given name.
|
||||
* @param name the class name as it appears in the config-file
|
||||
*/
|
||||
public ArenaClass(String name, boolean unbreakableWeapons, boolean unbreakableArmor) {
|
||||
public ArenaClass(String name, double price, boolean unbreakableWeapons, boolean unbreakableArmor) {
|
||||
this.configName = name;
|
||||
this.lowercaseName = name.toLowerCase();
|
||||
|
||||
@ -35,6 +36,8 @@ public class ArenaClass
|
||||
|
||||
this.unbreakableWeapons = unbreakableWeapons;
|
||||
this.unbreakableArmor = unbreakableArmor;
|
||||
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,6 +264,10 @@ public class ArenaClass
|
||||
return unbreakableArmor;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by isWeapon() to determine if an ItemStack is a weapon type.
|
||||
*/
|
||||
|
@ -437,6 +437,11 @@ public class ArenaImpl implements Arena
|
||||
assignClassPermissions(p);
|
||||
arenaPlayerMap.get(p).resetStats();
|
||||
|
||||
double price = arenaPlayerMap.get(p).getArenaClass().getPrice();
|
||||
if (price > 0D) {
|
||||
plugin.takeMoney(p, price);
|
||||
}
|
||||
|
||||
scoreboard.addPlayer(p);
|
||||
}
|
||||
|
||||
|
@ -927,12 +927,21 @@ public class ArenaListener
|
||||
return;
|
||||
}
|
||||
|
||||
// Check price, balance, and inform
|
||||
double price = newAC.getPrice();
|
||||
if (price > 0D) {
|
||||
if (!plugin.hasEnough(p, price)) {
|
||||
Messenger.tell(p, Msg.LOBBY_CLASS_TOO_EXPENSIVE, plugin.economyFormat(price));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, leave the old class, and pick the new!
|
||||
classLimits.playerLeftClass(oldAC, p);
|
||||
classLimits.playerPickedClass(newAC, p);
|
||||
|
||||
// Delay the inventory stuff to ensure that right-clicking works.
|
||||
delayAssignClass(p, className, sign);
|
||||
delayAssignClass(p, className, price, sign);
|
||||
}
|
||||
|
||||
/*private boolean cansPlayerJoinClass(ArenaClass ac, Player p) {
|
||||
@ -947,7 +956,7 @@ public class ArenaListener
|
||||
return true;
|
||||
}*/
|
||||
|
||||
private void delayAssignClass(final Player p, final String className, final Sign sign) {
|
||||
private void delayAssignClass(final Player p, final String className, final double price, final Sign sign) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,new Runnable() {
|
||||
public void run() {
|
||||
if (!className.equalsIgnoreCase("random")) {
|
||||
@ -996,12 +1005,18 @@ public class ArenaListener
|
||||
arena.assignClassGiveInv(p, className, contents);
|
||||
p.getInventory().setContents(contents);
|
||||
Messenger.tell(p, Msg.LOBBY_CLASS_PICKED, TextUtils.camelCase(className));
|
||||
if (price > 0D) {
|
||||
Messenger.tell(p, Msg.LOBBY_CLASS_PRICE, plugin.economyFormat(price));
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Otherwise just fall through and use the items from the config-file
|
||||
}
|
||||
arena.assignClass(p, className);
|
||||
Messenger.tell(p, Msg.LOBBY_CLASS_PICKED, TextUtils.camelCase(className));
|
||||
if (price > 0D) {
|
||||
Messenger.tell(p, Msg.LOBBY_CLASS_PRICE, plugin.economyFormat(price));
|
||||
}
|
||||
}
|
||||
else {
|
||||
arena.addRandomPlayer(p);
|
||||
|
@ -293,8 +293,21 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
boolean weps = section.getBoolean("unbreakable-weapons", true);
|
||||
boolean arms = section.getBoolean("unbreakable-armor", true);
|
||||
|
||||
// Grab the class price, if any
|
||||
double price = -1D;
|
||||
String priceString = section.getString("price", null);
|
||||
if (priceString != null) {
|
||||
ItemStack priceItem = ItemParser.parseItem(priceString);
|
||||
if (priceItem != null && priceItem.getTypeId() == MobArena.ECONOMY_MONEY_ID) {
|
||||
price = (priceItem.getAmount() + (priceItem.getDurability() / 100D));
|
||||
} else {
|
||||
Messenger.warning("The price for class '" + classname + "' could not be parsed!");
|
||||
Messenger.warning("- expected e.g. '$10', found '" + priceString + "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Create an ArenaClass with the config-file name.
|
||||
ArenaClass arenaClass = new ArenaClass(classname, weps, arms);
|
||||
ArenaClass arenaClass = new ArenaClass(classname, price, weps, arms);
|
||||
|
||||
// Parse the items-node
|
||||
List<String> items = section.getStringList("items");
|
||||
|
@ -251,25 +251,31 @@ public class MobArena extends JavaPlugin
|
||||
}
|
||||
|
||||
public boolean takeMoney(Player p, ItemStack item) {
|
||||
return takeMoney(p, getAmount(item));
|
||||
}
|
||||
|
||||
public boolean takeMoney(Player p, double amount) {
|
||||
if (economy != null) {
|
||||
EconomyResponse result = economy.withdrawPlayer(p.getName(), getAmount(item));
|
||||
EconomyResponse result = economy.withdrawPlayer(p.getName(), amount);
|
||||
return (result.type == ResponseType.SUCCESS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasEnough(Player p, ItemStack item) {
|
||||
if (economy != null) {
|
||||
return (economy.getBalance(p.getName()) >= getAmount(item));
|
||||
return hasEnough(p, getAmount(item));
|
||||
}
|
||||
return true;
|
||||
|
||||
public boolean hasEnough(Player p, double amount) {
|
||||
return economy == null || (economy.getBalance(p.getName()) >= amount);
|
||||
}
|
||||
|
||||
public String economyFormat(ItemStack item) {
|
||||
if (economy != null) {
|
||||
return economy.format(getAmount(item));
|
||||
return economyFormat(getAmount(item));
|
||||
}
|
||||
return null;
|
||||
|
||||
public String economyFormat(double amount) {
|
||||
return economy == null ? null : economy.format(amount);
|
||||
}
|
||||
|
||||
private double getAmount(ItemStack item) {
|
||||
|
@ -57,6 +57,8 @@ public enum Msg {
|
||||
LOBBY_CLASS_PICKED("You have chosen &e%&r as your class!"),
|
||||
LOBBY_CLASS_RANDOM("You will get a random class on arena start."),
|
||||
LOBBY_CLASS_PERMISSION("You don't have permission to use this class!"),
|
||||
LOBBY_CLASS_PRICE("This class costs &c%&r (paid on arena start)."),
|
||||
LOBBY_CLASS_TOO_EXPENSIVE("You can't afford that class (&c%&r)"),
|
||||
WARP_TO_ARENA("Warping to the arena not allowed!"),
|
||||
WARP_FROM_ARENA("Warping from the arena not allowed!"),
|
||||
WAVE_DEFAULT("Wave &b#%&r!"),
|
||||
|
Loading…
Reference in New Issue
Block a user