Merge pull request #8 from MilkBowl/master

sync
This commit is contained in:
Rodney Ramos 2013-01-30 07:52:59 -08:00
commit 41c9c6d008
6 changed files with 286 additions and 202 deletions

Binary file not shown.

View File

@ -11,7 +11,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.4.5-R0.3-SNAPSHOT</version>
<version>1.4.7-R0.1</version>
</dependency>
<dependency>
<groupId>de.hydrox.bukkit.DroxPerms</groupId>

View File

@ -239,4 +239,4 @@ public class Economy_MineConomy implements Economy {
public int fractionalDigits() {
return 2;
}
}
}

View File

@ -31,24 +31,31 @@ import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import com.gmail.mirelatrue.xpbank.API;
import com.gmail.mirelatrue.xpbank.Account;
import com.gmail.mirelatrue.xpbank.GroupBank;
import com.gmail.mirelatrue.xpbank.XPBank;
public class Economy_XPBank implements Economy {
private static final Logger log = Logger.getLogger("Minecraft");
private final String name = "XPBank";
private Plugin plugin = null;
private XPBank XPB = null;
private API api = null;
public Economy_XPBank(Plugin plugin) {
public Economy_XPBank (Plugin plugin) {
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new EconomyServerListener(this), plugin);
// Load Plugin in case it was loaded before
if (XPB == null) {
Plugin economy = plugin.getServer().getPluginManager().getPlugin("XPBank");
if (economy != null && economy.isEnabled()) {
XPB = (XPBank) economy;
api = XPB.getAPI();
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
@ -57,25 +64,25 @@ public class Economy_XPBank implements Economy {
public class EconomyServerListener implements Listener {
Economy_XPBank economy = null;
public EconomyServerListener(Economy_XPBank economy_XPBank) {
public EconomyServerListener (Economy_XPBank economy_XPBank) {
this.economy = economy_XPBank;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
@EventHandler (priority = EventPriority.MONITOR)
public void onPluginEnable (PluginEnableEvent event) {
if (economy.XPB == null) {
Plugin eco = plugin.getServer().getPluginManager().getPlugin("XPBank");
if (eco != null && eco.isEnabled()) {
economy.XPB = (XPBank) eco;
api = XPB.getAPI();
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
@EventHandler (priority = EventPriority.MONITOR)
public void onPluginDisable (PluginDisableEvent event) {
if (economy.XPB != null) {
if (event.getPlugin().getDescription().getName().equals("XPBank")) {
economy.XPB = null;
@ -86,209 +93,267 @@ public class Economy_XPBank implements Economy {
}
@Override
public boolean isEnabled() {
public boolean isEnabled () {
return this.XPB != null;
}
@Override
public String getName() {
public String getName () {
return name;
}
@Override
public String format(double amount) {
return String.format("%d %s", (int) amount, XPBank.currencyName);
}
@Override
public String currencyNamePlural() {
return XPBank.currencyName;
}
@Override
public String currencyNameSingular() {
return XPBank.currencyName;
}
@Override
public double getBalance(String playerName) {
return XPB.getBalance(playerName);
}
@Override
public boolean has(String playerName, double amount) {
if (XPB.getBalance(playerName) >= (int) amount) { return true; }
return false;
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
if (!XPB.playerExists(playerName)) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player doesn't exist");
}
int value = (int) amount;
int balance = XPB.getBalance(playerName);
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Amount must be greater than zero");
}
if (value > balance) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format("Insufficient %s", XPBank.currencyName));
}
XPB.addToBalance(playerName, -value);
return new EconomyResponse(value, balance - value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
if (!XPB.playerExists(playerName)) {
// Stupid plugins that use fake players without creating them first...
// return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player doesn't exist");
this.createPlayerAccount(playerName);
}
int value = (int) amount;
int balance = XPB.getBalance(playerName);
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Amount must be greater than zero");
}
XPB.addToBalance(playerName, value);
return new EconomyResponse(value, balance + value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse createBank(String name, String player) {
if (XPB.bankExists(name)) {
return new EconomyResponse(0, XPB.getBankBalance(name), ResponseType.FAILURE, "That account already exists");
}
Boolean created = XPB.addBank(name);
if (!created) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There was an error creating the account");
}
return new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse deleteBank(String name) {
if (!XPB.bankExists(name)) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no account with that name");
}
Boolean deleted = XPB.deleteBank(name);
if (!deleted) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There was an error deleting the account");
}
return new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse bankHas(String name, double amount) {
if (!XPB.bankExists(name)) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no account with that name");
}
int balance = XPB.getBankBalance(name);
if (balance >= (int) amount) {
return new EconomyResponse(0, balance, ResponseType.SUCCESS, null);
}
return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format("The account does not have that much %s", XPBank.currencyName));
}
@Override
public EconomyResponse bankWithdraw(String name, double amount) {
if (!XPB.bankExists(name)) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no account with that name");
}
int value = (int) amount;
int balance = XPB.getBankBalance(name);
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Amount must be greater than zero");
}
if (value > balance) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format("Insufficient %s", XPBank.currencyName));
}
XPB.addToBankBalance(name, -value);
return new EconomyResponse(value, balance - value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse bankDeposit(String name, double amount) {
if (!XPB.bankExists(name)) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no account with that name");
}
int value = (int) amount;
int balance = XPB.getBankBalance(name);
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, "Amount must be greater than zero");
}
XPB.addToBankBalance(name, value);
return new EconomyResponse(value, balance + value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse isBankOwner(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "XPBank does not support assigning bank owners");
}
@Override
public EconomyResponse isBankMember(String name, String playerName) {
return new EconomyResponse(0, 0, ResponseType.NOT_IMPLEMENTED, "XPBank does not support assigning bank members");
}
@Override
public EconomyResponse bankBalance(String name) {
if (!XPB.bankExists(name)) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, "There is no account with that name");
}
return new EconomyResponse(0, XPB.getBankBalance(name), ResponseType.SUCCESS, null);
}
@Override
public List<String> getBanks() {
return XPB.getBanks();
}
@Override
public boolean hasBankSupport() {
public boolean hasBankSupport () {
return true;
}
@Override
public boolean hasAccount(String playerName) {
return XPB.playerExists(playerName);
}
@Override
public boolean createPlayerAccount(String playerName) {
return XPB.addPlayer(playerName);
public int fractionalDigits () {
return 0;
}
@Override
public int fractionalDigits() {
return 0;
}
}
@Override
public String format (double amount) {
return String.format("%d %s", (int) amount, api.currencyName((int) amount));
}
@Override
public String currencyNamePlural () {
return api.getMsg("CurrencyNamePlural");
}
@Override
public String currencyNameSingular () {
return api.getMsg("currencyName");
}
@Override
public boolean hasAccount (String playerName) {
Account account = api.getAccount(playerName);
if (account != null) {
return true;
}
return false;
}
@Override
public double getBalance (String playerName) {
Account account = api.getAccount(playerName);
return account.getBalance();
}
@Override
public boolean has (String playerName, double amount) {
Account account = api.getAccount(playerName);
if (account.getBalance() >= (int) amount) {
return true;
}
return false;
}
@Override
public EconomyResponse withdrawPlayer (String playerName, double amount) {
Account account = api.getAccount(playerName);
if (account == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("Player doesn't exist."));
}
int value = (int) amount;
int balance = account.getBalance();
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero"));
}
if (value > balance) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format(api.getMsg("InsufficientXP"), api.currencyName(value)));
}
account.modifyBalance(-value);
return new EconomyResponse(value, balance - value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse depositPlayer (String playerName, double amount) {
Account account = api.getAccount(playerName);
if (account == null) {
// Stupid plugins that use fake players without creating them first...
// return new EconomyResponse(0, 0, ResponseType.FAILURE, "Player doesn't exist");
this.createPlayerAccount(playerName);
}
int value = (int) amount;
int balance = account.getBalance();
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero"));
}
account.addTaxableIncome(value);
return new EconomyResponse(value, balance + value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse createBank (String name, String player) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank != null) {
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, String.format(api.getMsg("GroupBankExists"), name));
}
Account account = api.getAccount(player);
groupBank = api.createGroupBank(name, account);
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse deleteBank (String name) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists"));
}
api.deleteGroupBank(groupBank, String.format(api.getMsg("Disbanded"), groupBank.getName()));
return new EconomyResponse(0, 0, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse bankBalance (String name) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists"));
}
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse bankHas (String name, double amount) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists"));
}
int value = (int) amount;
int balance = groupBank.getBalance();
if (balance >= value) {
return new EconomyResponse(0, balance, ResponseType.SUCCESS, null);
}
return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format(api.getMsg("InsufficientXP"), api.currencyName(value)));
}
@Override
public EconomyResponse bankWithdraw (String name, double amount) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists"));
}
int value = (int) amount;
int balance = groupBank.getBalance();
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero"));
}
if (value > balance) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, String.format(api.getMsg("InsufficientXP"), api.currencyName(value)));
}
groupBank.modifyBalance(-value);
return new EconomyResponse(value, balance - value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse bankDeposit (String name, double amount) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists"));
}
int value = (int) amount;
int balance = groupBank.getBalance();
if (value < 1) {
return new EconomyResponse(0, balance, ResponseType.FAILURE, api.getMsg("LessThanZero"));
}
groupBank.modifyBalance(value);
return new EconomyResponse(value, balance + value, ResponseType.SUCCESS, null);
}
@Override
public EconomyResponse isBankOwner (String name, String playerName) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists"));
}
Account account = api.getAccount(name);
if (account == null) {
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, api.getMsg("PlayerNotExist"));
}
if (groupBank.getOwner().equalsIgnoreCase(name)) {
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null);
}
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, String.format(api.getMsg("PlayerNotOwner"), account.getName(), groupBank.getName()));
}
@Override
public EconomyResponse isBankMember (String name, String playerName) {
GroupBank groupBank = api.getGroupBank(name);
if (groupBank == null) {
return new EconomyResponse(0, 0, ResponseType.FAILURE, api.getMsg("GroupBankNotExists"));
}
Account account = api.getAccount(name);
if (account == null) {
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, api.getMsg("PlayerNotExist"));
}
if (groupBank.groupMembers.getMembers().containsKey(playerName)) {
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.SUCCESS, null);
}
return new EconomyResponse(0, groupBank.getBalance(), ResponseType.FAILURE, String.format(api.getMsg("NotAMemberOf"), groupBank.getName(), account.getName()));
}
@Override
public List<String> getBanks () {
return api.getAllGroupBanks();
}
@Override
public boolean createPlayerAccount (String playerName) {
api.createAccount(playerName);
return true;
}
}

View File

@ -462,7 +462,26 @@ public class Items {
items.add(new ItemInfo("Potion of Invisibility (Extended)", new String[][] {{"pot", "invi", "ext"}}, Material.POTION, (short) 8270));
items.add(new ItemInfo("Potion of Night Vision", new String[][] {{"pot", "nigh", "visi"}, {"pot", "visio"}}, Material.POTION, (short) 8198));
items.add(new ItemInfo("Potion of Night Vision (Extended)", new String[][] {{"pot", "nigh", "visi", "ext"}, {"pot", "visio", "ext"}}, Material.POTION, (short) 8262));
items.add(new ItemInfo("Enchanted Book", new String[][]{{"ench", "boo"}}, Material.ENCHANTED_BOOK));
items.add(new ItemInfo("Nether Star", new String[][]{{"star", "neth"}}, Material.NETHER_STAR));
items.add(new ItemInfo("Firework Star", new String[][]{{"fire", "star"}}, Material.FIREWORK_CHARGE));
items.add(new ItemInfo("Firework Rocket", new String[][]{{"rocket"}, {"firework"}}, Material.FIREWORK));
items.add(new ItemInfo("White Firework Star", new String[][]{{"whi", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 1));
items.add(new ItemInfo("Orange Firework Star", new String[][]{{"ora", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 2));
items.add(new ItemInfo("Magenta Firework Star", new String[][]{{"mag", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 3));
items.add(new ItemInfo("Light Blue Firework Star", new String[][]{{"blu", "lig", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 4));
items.add(new ItemInfo("Yellow Firework Star", new String[][]{{"yell", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 5));
items.add(new ItemInfo("Lime Firework Star", new String[][]{{"lim", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 6));
items.add(new ItemInfo("Pink Firework Star", new String[][]{{"pin", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 7));
items.add(new ItemInfo("Gray Firework Star", new String[][]{{"gra", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 8));
items.add(new ItemInfo("Light Gray Firework Star", new String[][]{{"lig", "gra", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 9));
items.add(new ItemInfo("Cyan Firework Star", new String[][]{{"cya", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 10));
items.add(new ItemInfo("Purple Firework Star", new String[][]{{"pur", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 11));
items.add(new ItemInfo("Blue Firework Star", new String[][]{{"blue", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 12));
items.add(new ItemInfo("Brown Firework Star", new String[][]{{"bro", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 13));
items.add(new ItemInfo("Green Firework Star", new String[][]{{"gre", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 14));
items.add(new ItemInfo("Red Firework Star", new String[][]{{"red", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 15));
items.add(new ItemInfo("Block Firework Star", new String[][]{{"bla", "fire", "star"}}, Material.FIREWORK_CHARGE, (short) 16));
}
public static ItemInfo itemById(int typeId) {