Initial Commit

This commit is contained in:
Morgan 2011-06-28 20:18:20 -04:00
commit 875e5f980c
30 changed files with 2143 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
*/**/.classpath
.classpath
*/**/.externalToolBuilders
.externalToolBuilders
*/**/.project
.project
*/**/.settings
.settings
Vault.jar

140
README.md Normal file
View File

@ -0,0 +1,140 @@
# Vault - Abstraction Library for Bukkit Plugins
## Installing
Installing Vault is as simple as copying the provided "Vault.jar" to your
"<bukkit-install-dir>/plugins" directory and the rest is automatic! If you
wish to perform configuration changes, this can be done via a configuration
file but should not be necessary in most cases. See the "Advanced
Configuration" section for more information.
## Permissions
None! Vault has no permission nodes itself.
## License
Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## Building
Vault comes with all libraries needed to build from the current branch and
also comes with an Apache Ant build file (build.xml).
## Dependencies
Because Vault provides a bridge to other plugins, their binaries will be
required to build from. To ease this, they have been included in the lib
folder and will be updated from time to time.
## Supported Plugins
Vault provides abstraction for the following categories and plugins. If you
have your own plugin that you believe should be supported, fork Vault or create
a patch with the necessary changes. Additionally you can create an issue on
Github and we'll get to it at our convenience.
* Economy
- BOSEconomy (http://forums.bukkit.org/threads/19025/)
- iConomy 4 & 5 (http://forums.bukkit.org/threads/40/)
- 3co (http://forums.bukkit.org/threads/22461/)
* Permissions
- Permissions 2 & 3 (http://forums.bukkit.org/threads/18430/)
- Permissions Ex (http://forums.bukkit.org/threads/18140/)
## Implementing Vault
Implementing Vault is quite simple through obtaining an instance through the
Bukkit PluginManager class by using the string "Vault". An example plugin with
limited functionality is located within the contrib folder.
Example:
```java
package com.example.plugin;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class ExamplePlugin extends JavaPlugin {
private static final Logger log = Logger.getLogger("Minecraft");
private Vault vault = null;
@Override
public void onDisable() {
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
@Override
public void onEnable() {
Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
if(x != null & x instanceof Vault) {
vault = (Vault) x;
log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion()));
} else {
/**
* Throw error & disable because we have Vault set as a dependency, you could give a download link
* or even download it for the user. This is all up to you as a developer to decide the best option
* for your users! For our example, we assume that our audience (developers) can find the Vault
* plugin and properly install it. It's usually a bad idea however.
*/
log.warning(String.format("[%s] Vault was _NOT_ found! Disabling plugin.", getDescription().getName()));
getPluginLoader().disablePlugin(this);
}
}
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if(!(sender instanceof Player)) {
log.info("Only players are supported for this Example Plugin, but you should not do this!!!");
return true;
}
Player player = (Player) sender;
if(command.getLabel().equals("test-economy")) {
// Lets give the player 1.05 currency (note that SOME economic plugins require rounding!
sender.sendMessage(String.format("You have %s", vault.getEconomy().format(vault.getEconomy().getBalance(player.getName()).amount)));
EconomyResponse r = vault.getEconomy().depositPlayer(player.getName(), 1.05);
if(r.transactionSuccess()) {
sender.sendMessage(String.format("You were given %s and now have %s", vault.getEconomy().format(r.amount), vault.getEconomy().format(r.balance)));
} else {
sender.sendMessage(String.format("An error occured: %s", r.errorMessage));
}
return true;
} else if(command.getLabel().equals("test-permission")) {
// Lets test if user has the node "example.plugin.awesome" to determine if they are awesome or just suck
if(vault.getPermission().hasPermission(player, "example.plugin.awesome", false)) {
sender.sendMessage("You are awesome!");
} else {
sender.sendMessage("You suck!");
}
return true;
} else {
return false;
}
}
}
```

36
build.xml Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" ?>
<project default="main">
<path id="classpath">
<fileset dir="lib" includes="**/*.jar"/>
</path>
<target name="main" depends="clean, compile, compress" description="Main target">
<echo>Building the .jar file.</echo>
</target>
<target name="clean" description="Cleans project">
<echo>Cleaning</echo>
<delete failonerror="false">
<fileset dir="bin" includes="**/*" />
</delete>
<delete file="Vault.jar" />
<mkdir dir="bin"/>
</target>
<target name="compile" description="Compilation target">
<echo>Compiling</echo>
<javac srcdir="." destdir="bin" debug="on" debuglevel="lines,vars,source" classpathref="classpath" />
<copy file="plugin.yml" tofile="bin/plugin.yml" />
</target>
<target name="compress" description="Compression target">
<echo>Compressing</echo>
<jar jarfile="Vault.jar" basedir="bin" includes="net/**/*, plugin.yml, props/*">
<manifest>
<attribute name="Built-By" value="${user.name}" />
</manifest>
</jar>
<delete dir="bin" />
</target>
</project>

BIN
contrib/Example.jar Normal file

Binary file not shown.

36
contrib/build.xml Normal file
View File

@ -0,0 +1,36 @@
<?xml version="1.0" ?>
<project default="main">
<path id="classpath">
<fileset dir="lib" includes="**/*.jar"/>
</path>
<target name="main" depends="clean, compile, compress" description="Main target">
<echo>Building the .jar file.</echo>
</target>
<target name="clean" description="Cleans project">
<echo>Cleaning</echo>
<delete failonerror="false">
<fileset dir="bin" includes="**/*" />
</delete>
<delete file="Example.jar" />
<mkdir dir="bin"/>
</target>
<target name="compile" description="Compilation target">
<echo>Compiling</echo>
<javac srcdir="." destdir="bin" debug="on" debuglevel="lines,vars,source" classpathref="classpath" />
<copy file="plugin.yml" tofile="bin/plugin.yml" />
</target>
<target name="compress" description="Compression target">
<echo>Compressing</echo>
<jar jarfile="Example.jar" basedir="bin" includes="com/**/*, plugin.yml, props/*">
<manifest>
<attribute name="Built-By" value="${user.name}" />
</manifest>
</jar>
<delete dir="bin" />
</target>
</project>

Binary file not shown.

12
contrib/plugin.yml Normal file
View File

@ -0,0 +1,12 @@
name: ExamplePlugin
main: com.example.plugin.ExamplePlugin
version: 0.0.0
author: ExampleAuthor
depend: [Vault]
description: >
Example Plugin demonstrating implementation of Vault.
commands:
test-economy:
description: Tests Economy
test-permission:
description: Tests Permission

View File

@ -0,0 +1,72 @@
package com.example.plugin;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class ExamplePlugin extends JavaPlugin {
private static final Logger log = Logger.getLogger("Minecraft");
private Vault vault = null;
@Override
public void onDisable() {
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
@Override
public void onEnable() {
Plugin x = this.getServer().getPluginManager().getPlugin("Vault");
if(x != null & x instanceof Vault) {
vault = (Vault) x;
log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion()));
} else {
/**
* Throw error & disable because we have Vault set as a dependency, you could give a download link
* or even download it for the user. This is all up to you as a developer to decide the best option
* for your users! For our example, we assume that our audience (developers) can find the Vault
* plugin and properly install it. It's usually a bad idea however.
*/
log.warning(String.format("[%s] Vault was _NOT_ found! Disabling plugin.", getDescription().getName()));
getPluginLoader().disablePlugin(this);
}
}
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if(!(sender instanceof Player)) {
log.info("Only players are supported for this Example Plugin, but you should not do this!!!");
return true;
}
Player player = (Player) sender;
if(command.getLabel().equals("test-economy")) {
// Lets give the player 1.05 currency (note that SOME economic plugins require rounding!
sender.sendMessage(String.format("You have %s", vault.getEconomy().format(vault.getEconomy().getBalance(player.getName()).amount)));
EconomyResponse r = vault.getEconomy().depositPlayer(player.getName(), 1.05);
if(r.transactionSuccess()) {
sender.sendMessage(String.format("You were given %s and now have %s", vault.getEconomy().format(r.amount), vault.getEconomy().format(r.balance)));
} else {
sender.sendMessage(String.format("An error occured: %s", r.errorMessage));
}
return true;
} else if(command.getLabel().equals("test-permission")) {
// Lets test if user has the node "example.plugin.awesome" to determine if they are awesome or just suck
if(vault.getPermission().hasPermission(player, "example.plugin.awesome", false)) {
sender.sendMessage("You are awesome!");
} else {
sender.sendMessage("You suck!");
}
return true;
} else {
return false;
}
}
}

BIN
lib/3co.jar Normal file

Binary file not shown.

BIN
lib/BOSEconomy.jar Normal file

Binary file not shown.

BIN
lib/Essentials.jar Normal file

Binary file not shown.

BIN
lib/Permissions.jar Normal file

Binary file not shown.

BIN
lib/PermissionsEx.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/iConomy4.jar Normal file

Binary file not shown.

BIN
lib/iConomy5.jar Normal file

Binary file not shown.

6
plugin.yml Normal file
View File

@ -0,0 +1,6 @@
name: Vault
main: net.milkbowl.vault.Vault
version: 1.0.0dev
author: Cereal
description: >
Abstraction Library for Bukkit Plugins

View File

@ -0,0 +1,57 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault;
import java.util.logging.Logger;
import net.milkbowl.vault.economy.EconomyManager;
import net.milkbowl.vault.permission.PermissionManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Vault extends JavaPlugin {
private static final Logger log = Logger.getLogger("Minecraft");
private static EconomyManager econManager = null;
private static PermissionManager permManager = null;
@Override
public void onDisable() {
econManager = null;
permManager = null;
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
@Override
public void onEnable() {
econManager = new EconomyManager(this);
permManager = new PermissionManager(this);
log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
public static EconomyManager getEconomy() {
return econManager;
}
public static PermissionManager getPermission() {
return permManager;
}
}

View File

@ -0,0 +1,34 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy;
import java.util.logging.Logger;
public interface Economy {
public static final Logger log = Logger.getLogger("Minecraft");
public boolean isEnabled();
public String getName();
public String format(double amount);
public EconomyResponse getBalance(String playerName);
public EconomyResponse withdrawPlayer(String playerName, double amount);
public EconomyResponse depositPlayer(String playerName, double amount);
}

View File

@ -0,0 +1,165 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.logging.Logger;
import net.milkbowl.vault.economy.plugins.Economy_3co;
import net.milkbowl.vault.economy.plugins.Economy_BOSE;
import net.milkbowl.vault.economy.plugins.Economy_Essentials;
import net.milkbowl.vault.economy.plugins.Economy_iConomy4;
import net.milkbowl.vault.economy.plugins.Economy_iConomy5;
import org.bukkit.plugin.java.JavaPlugin;
public class EconomyManager {
private JavaPlugin plugin = null;
private TreeMap<Integer, Economy> econs = new TreeMap<Integer, Economy>();
private Economy activeEconomy = null;
private static final Logger log = Logger.getLogger("Minecraft");
/**
* Constructs a new instance of EconomyManager provided an instance of a JavaPlugin
* @param plugin Your plugin (should be "this")
*/
public EconomyManager(JavaPlugin plugin) {
this.plugin = plugin;
// Try to load 3co
if(packageExists(new String[] { "me.ic3d.eco.ECO" })) {
Economy econ = new Economy_3co(plugin);
econs.put(11, econ);
log.info(String.format("[%s][Economy] 3co found: %s", plugin.getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] 3co not found.", plugin.getDescription().getName()));
}
// Try to load BOSEconomy
if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy" })) {
Economy bose = new Economy_BOSE(plugin);
econs.put(10, bose);
log.info(String.format("[%s][Economy] BOSEconomy found: %s", plugin.getDescription().getName(), bose.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] BOSEconomy not found.", plugin.getDescription().getName()));
}
// Try to load Essentials Economy
if (packageExists(new String[] { "com.earth2me.essentials.api.Economy", "com.earth2me.essentials.api.NoLoanPermittedException", "com.earth2me.essentials.api.UserDoesNotExistException" })) {
Economy essentials = new Economy_Essentials(plugin);
econs.put(9, essentials);
log.info(String.format("[%s][Economy] Essentials Economy found: %s", plugin.getDescription().getName(), essentials.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] Essentials Economy not found.", plugin.getDescription().getName()));
}
// Try to load iConomy 4
if (packageExists(new String[] { "com.nijiko.coelho.iConomy.iConomy", "com.nijiko.coelho.iConomy.system.Account" })) {
Economy icon4 = new Economy_iConomy4(plugin);
econs.put(8, icon4);
log.info(String.format("[%s][Economy] iConomy 4 found: ", plugin.getDescription().getName(), icon4.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] iConomy 4 not found.", plugin.getDescription().getName()));
}
// Try to load iConomy 5
if (packageExists(new String[] { "com.iConomy.iConomy", "com.iConomy.system.Account", "com.iConomy.system.Holdings" })) {
Economy icon5 = new Economy_iConomy5(plugin);
econs.put(7, icon5);
log.info(String.format("[%s][Economy] iConomy 5 found: %s", plugin.getDescription().getName(), icon5.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] iConomy 5 not found.", plugin.getDescription().getName()));
}
}
private boolean packageExists(String[] packages) {
try {
for (String pkg : packages) {
Class.forName(pkg);
}
return true;
} catch (Exception e) {
return false;
}
}
private Economy getEconomy() {
if (activeEconomy == null) {
Iterator<Economy> it = econs.values().iterator();
while (it.hasNext()) {
Economy e = it.next();
if (e.isEnabled()) {
return e;
}
}
return null;
} else {
return activeEconomy;
}
}
/**
* Accessor for Name of Economy
* @return Name of active Economy
*/
public String getName() {
return getEconomy().getName();
}
/**
* Formats value to human readable forms
* @param amount Value to format
* @return Human readable form of amount
*/
public String format(double amount) {
return getEconomy().format(amount);
}
/**
* Returns current player balance
* @param playerName Player name
* @return Response containing amount (balance) and other meta data
*/
public EconomyResponse getBalance(String playerName) {
return getEconomy().getBalance(playerName);
}
/**
* Withdraw amount from a player account
* @param playerName Player name
* @param amount Amount to withdraw
* @return Response containing amount removed, and new balance
*/
public EconomyResponse withdrawPlayer(String playerName, double amount) {
return getEconomy().withdrawPlayer(playerName, amount);
}
/**
* Deposit amount to a player account
* @param playerName Player name
* @param amount Amount to deposit
* @return Response containing amount added, and new balance
*/
public EconomyResponse depositPlayer(String playerName, double amount) {
return getEconomy().depositPlayer(playerName, amount);
}
}

View File

@ -0,0 +1,86 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy;
public class EconomyResponse {
/**
* Enum for types of Responses indicating the status of a method call.
*/
public static enum ResponseType {
SUCCESS(1),
FAILURE(2),
NOT_IMPLEMENTED(3);
private int id;
ResponseType(int id) {
this.id = id;
}
int getId() {
return id;
}
}
/**
* Amount modified by calling method
*/
public final double amount;
/**
* New balance of account
*/
public final double balance;
/**
* Success or failure of call.
* Using Enum of ResponseType to determine valid outcomes
*/
public final ResponseType type;
/**
* Error message if the variable 'type' is ResponseType.FAILURE
*/
public final String errorMessage;
/**
* Constructor for EconomyResponse
* @param amount Amount modified during operation
* @param balance New balance of account
* @param type Success or failure type of the operation
* @param errorMessage Error message if necessary (commonly null)
*/
public EconomyResponse(double amount, double balance, ResponseType type, String errorMessage) {
this.amount = amount;
this.balance = balance;
this.type = type;
this.errorMessage = errorMessage;
}
/**
* Checks if an operation was successful
* @return Value
*/
public boolean transactionSuccess() {
switch (type) {
case SUCCESS:
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,185 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy.plugins;
import me.ic3d.eco.ECO;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class Economy_3co implements Economy {
private String name = "3co";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private ECO economy = null;
private EconomyServerListener economyServerListener = null;
public Economy_3co(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
economyServerListener = new EconomyServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (economy == null) {
Plugin econ = plugin.getServer().getPluginManager().getPlugin("3co");
if (econ != null && econ.isEnabled()) {
economy = (ECO) econ;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
@Override
public String getName() {
return name;
}
@Override
public boolean isEnabled() {
if(economy == null) {
return false;
} else {
return economy.isEnabled();
}
}
@Override
public EconomyResponse getBalance(String playerName) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(balance, balance, type, errorMessage);
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if(amount < 0) {
errorMessage = "Cannot withdraw negative funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(balance, balance, type, errorMessage);
}
amount = Math.ceil(amount);
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
if(balance - amount < 0) {
errorMessage = "Insufficient funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(balance, balance, type, errorMessage);
}
economy.setMoney(plugin.getServer().getPlayer(playerName), (int) (balance - amount));
type = EconomyResponse.ResponseType.SUCCESS;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(amount, balance, type, errorMessage);
}
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if(amount < 0) {
errorMessage = "Cannot deposit negative funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(balance, balance, type, errorMessage);
}
amount = Math.ceil(amount);
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
economy.setMoney(plugin.getServer().getPlayer(playerName), (int) (balance + amount));
type = EconomyResponse.ResponseType.SUCCESS;
balance = (double) economy.getMoney(plugin.getServer().getPlayer(playerName));
return new EconomyResponse(amount, balance, type, errorMessage);
}
public String getMoneyNamePlural() {
return economy.getPluralCurrency();
}
public String getMoneyNameSingular() {
return economy.getSingularCurrency();
}
private class EconomyServerListener extends ServerListener {
Economy_3co economy = null;
public EconomyServerListener(Economy_3co economy) {
this.economy = economy;
}
public void onPluginEnable(PluginEnableEvent event) {
if (economy.economy == null) {
Plugin eco = plugin.getServer().getPluginManager().getPlugin("3co");
if (eco != null && eco.isEnabled()) {
economy.economy = (ECO) eco;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (economy.economy != null) {
if (event.getPlugin().getDescription().getName().equals("Essentials")) {
economy.economy = null;
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
}
}
}
}
@Override
public String format(double amount) {
if (amount == 1) {
return String.format("%f %s", amount, getMoneyNameSingular());
} else {
return String.format("%f %s", amount, getMoneyNamePlural());
}
}
}

View File

@ -0,0 +1,203 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy.plugins;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import cosine.boseconomy.BOSEconomy;
public class Economy_BOSE implements Economy {
private String name = "BOSEconomy";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private BOSEconomy economy = null;
private EconomyServerListener economyServerListener = null;
public Economy_BOSE(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
economyServerListener = new EconomyServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (economy == null) {
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
if (bose != null && bose.isEnabled()) {
economy = (BOSEconomy) bose;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
@Override
public String getName() {
return name;
}
@Override
public boolean isEnabled() {
if(economy == null) {
return false;
} else {
return economy.isEnabled();
}
}
@Override
public EconomyResponse getBalance(String playerName) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
balance = (double) economy.getPlayerMoney(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(balance, balance, type, errorMessage);
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if(amount < 0) {
errorMessage = "Cannot withdraw negative funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage);
}
amount = Math.ceil(amount);
balance = (double) economy.getPlayerMoney(playerName);
if(balance - amount < 0) {
errorMessage = "Insufficient funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage);
}
if(economy.setPlayerMoney(playerName, (int) (balance - amount), false)) {
type = EconomyResponse.ResponseType.SUCCESS;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
} else {
errorMessage = "Error withdrawing funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
}
}
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if(amount < 0) {
errorMessage = "Cannot deposit negative funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage);
}
amount = Math.ceil(amount);
balance = (double) economy.getPlayerMoney(playerName);
if(economy.setPlayerMoney(playerName, (int) (balance + amount), false)) {
type = EconomyResponse.ResponseType.SUCCESS;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
} else {
errorMessage = "Error withdrawing funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = (double) economy.getPlayerMoney(playerName);
return new EconomyResponse(balance, balance, type, errorMessage);
}
}
public String getMoneyNamePlural() {
return economy.getMoneyNamePlural();
}
public String getMoneyNameSingular() {
return economy.getMoneyName();
}
private class EconomyServerListener extends ServerListener {
Economy_BOSE economy = null;
public EconomyServerListener(Economy_BOSE economy) {
this.economy = economy;
}
public void onPluginEnable(PluginEnableEvent event) {
if (economy.economy == null) {
Plugin bose = plugin.getServer().getPluginManager().getPlugin("BOSEconomy");
if (bose != null && bose.isEnabled()) {
economy.economy = (BOSEconomy) bose;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (economy.economy != null) {
if (event.getPlugin().getDescription().getName().equals("Essentials")) {
economy.economy = null;
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
}
}
}
}
@Override
public String format(double amount) {
if (amount == 1) {
return String.format("%f %s", amount, getMoneyNameSingular());
} else {
return String.format("%f %s", amount, getMoneyNamePlural());
}
}
}

View File

@ -0,0 +1,215 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy.plugins;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.api.NoLoanPermittedException;
import com.earth2me.essentials.api.UserDoesNotExistException;
public class Economy_Essentials implements Economy {
private String name = "Essentials Economy";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private Essentials ess = null;
private EconomyServerListener economyServerListener = null;
public Economy_Essentials(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
economyServerListener = new EconomyServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (ess == null) {
Plugin essentials = plugin.getServer().getPluginManager().getPlugin("Essentials");
if (essentials != null && essentials.isEnabled()) {
ess = (Essentials) essentials;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
@Override
public boolean isEnabled() {
if(ess == null) {
return false;
} else {
return ess.isEnabled();
}
}
@Override
public String getName() {
return name;
}
@Override
public EconomyResponse getBalance(String playerName) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
try {
balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
} catch (UserDoesNotExistException e) {
if(createPlayerAccount(playerName)) {
balance = 0;
type = EconomyResponse.ResponseType.SUCCESS;
} else {
balance = 0;
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "User does not exist";
}
}
return new EconomyResponse(balance, balance, type, errorMessage);
}
private boolean createPlayerAccount(String playerName) {
try {
com.earth2me.essentials.api.Economy.add(playerName, 0);
return true;
} catch (UserDoesNotExistException e1) {
return false;
} catch (NoLoanPermittedException e1) {
return false;
}
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
try {
com.earth2me.essentials.api.Economy.subtract(playerName, amount);
balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
} catch (UserDoesNotExistException e) {
if (createPlayerAccount(playerName)) {
return withdrawPlayer(playerName, amount);
} else {
amount = 0;
balance = 0;
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "User does not exist";
}
} catch (NoLoanPermittedException e) {
try {
balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
amount = 0;
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "Loan was not permitted";
} catch (UserDoesNotExistException e1) {
amount = 0;
balance = 0;
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "User does not exist";
}
}
return new EconomyResponse(amount, balance, type, errorMessage);
}
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
try {
com.earth2me.essentials.api.Economy.add(playerName, amount);
balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
} catch (UserDoesNotExistException e) {
if(createPlayerAccount(playerName)) {
return depositPlayer(playerName, amount);
} else {
amount = 0;
balance = 0;
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "User does not exist";
}
} catch (NoLoanPermittedException e) {
try {
balance = com.earth2me.essentials.api.Economy.getMoney(playerName);
amount = 0;
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "Loan was not permitted";
} catch (UserDoesNotExistException e1) {
balance = 0;
amount = 0;
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "Loan was not permitted";
}
}
return new EconomyResponse(amount, balance, type, errorMessage);
}
private class EconomyServerListener extends ServerListener {
Economy_Essentials economy = null;
public EconomyServerListener(Economy_Essentials economy) {
this.economy = economy;
}
public void onPluginEnable(PluginEnableEvent event) {
if (economy.ess == null) {
Plugin essentials = plugin.getServer().getPluginManager().getPlugin("Essentials");
if (essentials != null && essentials.isEnabled()) {
economy.ess = (Essentials) essentials;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (economy.ess != null) {
if (event.getPlugin().getDescription().getName().equals("Essentials")) {
economy.ess = null;
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
}
}
}
}
@Override
public String format(double amount) {
return com.earth2me.essentials.api.Economy.format(amount);
}
}

View File

@ -0,0 +1,200 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy.plugins;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijiko.coelho.iConomy.iConomy;
import com.nijiko.coelho.iConomy.system.Account;
public class Economy_iConomy4 implements Economy {
private String name = "iConomy 4";
private Plugin plugin = null;
private PluginManager pluginManager = null;
protected iConomy economy = null;
private EconomyServerListener economyServerListener = null;
public Economy_iConomy4(Plugin plugin) {
this.plugin = plugin;
this.pluginManager = this.plugin.getServer().getPluginManager();
economyServerListener = new EconomyServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if(economy == null) {
Plugin ec = plugin.getServer().getPluginManager().getPlugin("iConomy");
if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy.class")) {
economy = (iConomy) ec;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
@Override
public boolean isEnabled() {
if(economy == null) {
return false;
} else {
return economy.isEnabled();
}
}
@Override
public String getName() {
return name;
}
@Override
public String format(double amount) {
return iConomy.getBank().format(amount);
}
public String getMoneyNamePlural() {
return iConomy.getBank().getCurrency() + "s";
}
public String getMoneyNameSingular() {
return iConomy.getBank().getCurrency();
}
@Override
public EconomyResponse getBalance(String playerName) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(balance, balance, type, errorMessage);
}
private double getAccountBalance(String playerName) {
Account account = iConomy.getBank().getAccount(playerName);
if (account == null) {
iConomy.getBank().addAccount(playerName);
account = iConomy.getBank().getAccount(playerName);
}
return account.getBalance();
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if(amount < 0) {
errorMessage = "Cannot withdraw negative funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = getAccountBalance(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
}
balance = getAccountBalance(playerName);
if(balance >= amount) {
Account account = iConomy.getBank().getAccount(playerName);
if(account == null) {
return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, "Could not find account");
}
account.subtract(amount);
type = EconomyResponse.ResponseType.SUCCESS;
balance = getAccountBalance(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
} else {
errorMessage = "Error withdrawing funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = getAccountBalance(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
}
}
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
if(amount < 0) {
errorMessage = "Cannot deposit negative funds";
type = EconomyResponse.ResponseType.FAILURE;
amount = 0;
balance = getAccountBalance(playerName);
return new EconomyResponse(amount, balance, type, errorMessage);
}
Account account = iConomy.getBank().getAccount(playerName);
if(account == null) {
iConomy.getBank().addAccount(playerName);
account = iConomy.getBank().getAccount(playerName);
}
account.add(amount);
balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(amount, balance, type, errorMessage);
}
private class EconomyServerListener extends ServerListener {
Economy_iConomy4 economy = null;
public EconomyServerListener(Economy_iConomy4 economy) {
this.economy = economy;
}
public void onPluginEnable(PluginEnableEvent event) {
if (economy.economy == null) {
Plugin iConomy = plugin.getServer().getPluginManager().getPlugin("iConomy");
if (iConomy != null && iConomy.isEnabled() && iConomy.getClass().getName().equals("com.nijiko.coelho.iConomy.iConomy")) {
economy.economy = (iConomy) iConomy;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (economy.economy != null) {
if (event.getPlugin().getDescription().getName().equals("iConomy")) {
economy.economy = null;
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
}
}
}
}
}

View File

@ -0,0 +1,163 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.economy.plugins;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.iConomy.iConomy;
import com.iConomy.system.Account;
import com.iConomy.system.Holdings;
public class Economy_iConomy5 implements Economy {
private String name = "iConomy 5";
private JavaPlugin plugin = null;
private PluginManager pluginManager = null;
protected iConomy economy = null;
private EconomyServerListener economyServerListener = null;
public Economy_iConomy5(JavaPlugin plugin) {
this.plugin = plugin;
this.pluginManager = this.plugin.getServer().getPluginManager();
economyServerListener = new EconomyServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, economyServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, economyServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (economy == null) {
Plugin ec = plugin.getServer().getPluginManager().getPlugin("iConomy");
if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.iConomy.iConomy")) {
economy = (iConomy) ec;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
@Override
public boolean isEnabled() {
if (economy == null) {
return false;
} else {
return economy.isEnabled();
}
}
@Override
public String getName() {
return name;
}
private double getAccountBalance(String playerName) {
return iConomy.getAccount(playerName).getHoldings().balance();
}
@Override
public EconomyResponse getBalance(String playerName) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(balance, balance, type, errorMessage);
}
@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
Account account = iConomy.getAccount(playerName);
Holdings holdings = account.getHoldings();
if (holdings.hasEnough(amount)) {
holdings.subtract(amount);
balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(balance, balance, type, errorMessage);
} else {
amount = 0;
balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.FAILURE;
errorMessage = "Insufficient funds";
return new EconomyResponse(balance, balance, type, errorMessage);
}
}
@Override
public EconomyResponse depositPlayer(String playerName, double amount) {
double balance;
EconomyResponse.ResponseType type;
String errorMessage = null;
Account account = iConomy.getAccount(playerName);
Holdings holdings = account.getHoldings();
holdings.add(amount);
balance = getAccountBalance(playerName);
type = EconomyResponse.ResponseType.SUCCESS;
return new EconomyResponse(amount, balance, type, errorMessage);
}
private class EconomyServerListener extends ServerListener {
Economy_iConomy5 economy = null;
public EconomyServerListener(Economy_iConomy5 economy) {
this.economy = economy;
}
public void onPluginEnable(PluginEnableEvent event) {
if (economy.economy == null) {
Plugin ec = plugin.getServer().getPluginManager().getPlugin("iConomy");
if (ec != null && ec.isEnabled() && ec.getClass().getName().equals("com.iConomy.iConomy")) {
economy.economy = (iConomy) ec;
log.info(String.format("[%s][Economy] %s hooked.", plugin.getDescription().getName(), economy.name));
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (economy.economy != null) {
if (event.getPlugin().getDescription().getName().equals("iConomy")) {
economy.economy = null;
log.info(String.format("[%s][Economy] %s unhooked.", plugin.getDescription().getName(), economy.name));
}
}
}
}
@Override
public String format(double amount) {
return iConomy.format(amount);
}
}

View File

@ -0,0 +1,38 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.permission;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
public interface Permission {
public static final Logger log = Logger.getLogger("Minecraft");
public String getName();
public boolean isEnabled();
public boolean hasPermission(Player player, String permission);
public boolean inGroup(String worldName, String playerName, String groupName);
public int getInfoInt(String world, String playerName, String node, int defaultValue);
public double getInfoDouble(String world, String playerName, String node, double defaultValue);
public boolean getInfoBoolean(String world, String playerName, String node, boolean defaultValue);
public String getInfoString(String world, String playerName, String node, String defaultValue);
}

View File

@ -0,0 +1,191 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.permission;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.logging.Logger;
import net.milkbowl.vault.permission.Permission;
import net.milkbowl.vault.permission.plugins.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class PermissionManager {
private JavaPlugin plugin = null;
private TreeMap<Integer,Permission> perms = new TreeMap<Integer,Permission>();
private Permission activePermission = null;
private static final Logger log = Logger.getLogger("Minecraft");
/**
* Constructs a new instance of PermissionManager provided an instance of a JavaPlugin
* @param plugin Your plugin (should be "this")
*/
public PermissionManager(JavaPlugin plugin) {
this.plugin = plugin;
// Try to load PermissionsEx
if(packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) {
Permission ePerms = new Permission_PermissionsEx(plugin);
perms.put(8, ePerms);
log.info(String.format("[%s][Permission] PermissionsEx found: %s", plugin.getDescription().getName(), ePerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] PermissionsEx not found.", plugin.getDescription().getName()));
}
// Try to load Permissions (Phoenix)
if (packageExists(new String[] { "com.nijikokun.bukkit.Permissions.Permissions" })) {
Permission nPerms = new Permission_Permissions(plugin);
perms.put(9, nPerms);
log.info(String.format("[%s][Permission] Permissions (Phoenix) found: %s", plugin.getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] Permissions (Phoenix) not found.", plugin.getDescription().getName()));
}
}
private boolean packageExists(String[] packages) {
try {
for (String pkg : packages) {
Class.forName(pkg);
}
return true;
} catch (Exception e) {
return false;
}
}
private Permission getPermission() {
if(activePermission == null) {
Iterator<Permission> it = perms.values().iterator();
while(it.hasNext()) {
Permission p = it.next();
if(p.isEnabled()) {
return p;
}
}
return null;
} else {
return activePermission;
}
}
/**
* Check if player has a permission node
* @param player Player name
* @param permission Permission node (ie: pluginname.function)
* @return Value
*/
public boolean hasPermission(Player player, String permission, boolean def) {
Permission p = getPermission();
if(p != null) {
return p.hasPermission(player, permission);
} else {
if(player.isOp()) {
return true;
} else {
return def;
}
}
}
/**
* Check if player is in a group
* @param worldName World name
* @param playerName Player name
* @param groupName Group name
* @return Value
*/
public boolean inGroup(String worldName, String playerName, String groupName) {
Permission p = getPermission();
if(p != null) {
return p.inGroup(worldName, playerName, groupName);
} else {
return false;
}
}
/**
* Get integer value from an info node
* @param world World name
* @param playerName Player name
* @param node Node name
* @return Value
*/
public int getInfoInt(String world, String playerName, String node, int defaultValue) {
Permission p = getPermission();
if(p != null) {
return p.getInfoInt(world, playerName, node, defaultValue);
} else {
return defaultValue;
}
}
/**
* Get double value from an info node
* @param world World name
* @param playerName Player name
* @param node Node name
* @return Value
*/
public double getInfoBoolean(String world, String playerName, String node, double defaultValue) {
Permission p = getPermission();
if(p != null) {
return p.getInfoDouble(world, playerName, node, defaultValue);
} else {
return defaultValue;
}
}
/**
* Get boolean value from an info node
* @param world World name
* @param playerName Player name
* @param node Node name
* @return Value
*/
public boolean getInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
Permission p = getPermission();
if(p != null) {
return p.getInfoBoolean(world, playerName, node, defaultValue);
} else {
return defaultValue;
}
}
/**
* Get boolean value from an info node
* @param world World name
* @param playerName Player name
* @param node Node name
* @return Value
*/
public String getInfoBoolean(String world, String playerName, String node, String defaultValue) {
Permission p = getPermission();
if(p != null) {
return p.getInfoString(world, playerName, node, defaultValue);
} else {
return defaultValue;
}
}
}

View File

@ -0,0 +1,141 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.permission.plugins;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijikokun.bukkit.Permissions.Permissions;
public class Permission_Permissions implements Permission {
private String name = "Permissions (Phoenix)";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private Permissions permission = null;
private PermissionServerListener permissionServerListener = null;
public Permission_Permissions(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
permissionServerListener = new PermissionServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Permissions");
if (perms != null) {
if (perms.isEnabled()) {
permission = (Permissions) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
}
@Override
public boolean isEnabled() {
if(permission == null) {
return false;
} else {
return permission.isEnabled();
}
}
@Override
public boolean hasPermission(Player player, String permission) {
return this.permission.getHandler().has(player, permission);
}
@Override
public boolean inGroup(String worldName, String playerName, String groupName) {
return this.permission.getHandler().inGroup(worldName, playerName, groupName);
}
private class PermissionServerListener extends ServerListener {
Permission_Permissions permission = null;
public PermissionServerListener(Permission_Permissions permission) {
this.permission = permission;
}
public void onPluginEnable(PluginEnableEvent event) {
if (permission.permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Permissions");
if (perms != null) {
if (perms.isEnabled()) {
permission.permission = (Permissions) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (permission.permission != null) {
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
permission.permission = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override
public String getName() {
return name;
}
/* (non-Javadoc)
* @see com.milkbukkit.localshops.modules.permission.Permission#numChestsAllowed(java.util.List, java.lang.String, java.lang.String)
*/
@Override
public int getInfoInt(String world, String playerName, String node, int defaultValue) {
return this.permission.getHandler().getPermissionInteger(world, playerName, node);
}
@Override
public double getInfoDouble(String world, String playerName, String node, double defaultValue) {
return this.permission.getHandler().getPermissionDouble(world, playerName, node);
}
@Override
public boolean getInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
return this.permission.getHandler().getPermissionBoolean(world, playerName, node);
}
@Override
public String getInfoString(String world, String playerName, String node, String defaultValue) {
return this.permission.getHandler().getPermissionString(world, playerName, node);
}
}

View File

@ -0,0 +1,154 @@
/**
* Copyright (C) 2011 Morgan Humes <morgan@lanaddict.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.milkbowl.vault.permission.plugins;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx;
public class Permission_PermissionsEx implements Permission {
private String name = "PermissionsEx";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private PermissionsEx permission = null;
private PermissionServerListener permissionServerListener = null;
public Permission_PermissionsEx(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
permissionServerListener = new PermissionServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
if (perms != null) {
if (perms.isEnabled()) {
permission = (PermissionsEx) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
}
@Override
public boolean isEnabled() {
if(permission == null) {
return false;
} else {
return permission.isEnabled();
}
}
@Override
public boolean hasPermission(Player player, String permission) {
return this.permission.has(player, permission);
}
@Override
public boolean inGroup(String worldName, String playerName, String groupName) {
//Try catch the check because we don't know if the objects will actually exist Good Job on the crap Permissions plugin, why do we support this again?
try {
PermissionUser[] userList = PermissionsEx.getPermissionManager().getGroup(groupName).getUsers();
for (PermissionUser user : userList) {
if (user.getName() == playerName)
return true;
else
return false;
}
} catch (Exception e) {
return false;
}
return false;
}
private class PermissionServerListener extends ServerListener {
Permission_PermissionsEx permission = null;
public PermissionServerListener(Permission_PermissionsEx permission) {
this.permission = permission;
}
public void onPluginEnable(PluginEnableEvent event) {
if (permission.permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
if (perms != null) {
if (perms.isEnabled()) {
permission.permission = (PermissionsEx) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (permission.permission != null) {
if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) {
permission.permission = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override
public String getName() {
return name;
}
/* (non-Javadoc)
* @see com.milkbukkit.localshops.modules.permission.Permission#numChestsAllowed(java.util.List, java.lang.String)
*/
@Override
public int getInfoInt(String world, String playerName, String node, int defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionInteger(node, world, defaultValue);
}
@Override
public double getInfoDouble(String world, String playerName, String node, double defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionDouble(node, world, defaultValue);
}
@Override
public boolean getInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionBoolean(node, world, defaultValue);
}
@Override
public String getInfoString(String world, String playerName, String node, String defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOption(node, world, defaultValue);
}
}