Removed Managers (they were silly)

This commit is contained in:
Morgan 2011-06-30 10:37:26 -04:00
parent 9dd74441ab
commit 0ca8ccb710
5 changed files with 52 additions and 367 deletions

View File

@ -59,6 +59,10 @@ public class Vault extends JavaPlugin {
log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
/**
* Gets current active Economy implementation
* @return Economy class
*/
public Economy getEconomy() {
if (activeEconomy == null) {
Iterator<Economy> it = econs.values().iterator();
@ -74,6 +78,10 @@ public class Vault extends JavaPlugin {
}
}
/**
* Gets current active Permission implementation
* @return Permission class
*/
public Permission getPermission() {
if(activePermission == null) {
Iterator<Permission> it = perms.values().iterator();
@ -89,6 +97,9 @@ public class Vault extends JavaPlugin {
}
}
/**
* Attempts to load Economy Addons
*/
private void loadEconomy() {
// Try to load 3co
if(packageExists(new String[] { "me.ic3d.eco.ECO" })) {
@ -136,6 +147,9 @@ public class Vault extends JavaPlugin {
}
}
/**
* Attempts to load Permission Addons
*/
private void loadPermission() {
// Try to load PermissionsEx
if(packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) {
@ -150,24 +164,53 @@ public class Vault extends JavaPlugin {
if (packageExists(new String[] { "com.nijikokun.bukkit.Permissions.Permissions" })) {
Permission nPerms = new Permission_Permissions(this);
perms.put(9, nPerms);
log.info(String.format("[%s][Permission] Permissions (Phoenix) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
log.info(String.format("[%s][Permission] Permissions (Yetti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] Permissions (Phoenix) not found.", getDescription().getName()));
log.info(String.format("[%s][Permission] Permissions (Yetti) not found.", getDescription().getName()));
}
}
private void reload() {
econs.clear();
activeEconomy = null;
loadEconomy();
perms.clear();
activePermission = null;
loadPermission();
}
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if(command.getLabel().equals("vault")) {
// do stuff!
sender.sendMessage(String.format("[%s] Vault v%s Information", getDescription().getName(), getDescription().getVersion()));
sender.sendMessage(String.format("[%s] Economy: %s", getDescription().getName(), getEconomy().getName()));
sender.sendMessage(String.format("[%s] Permission: %s", getDescription().getName(), getPermission().getName()));
return true;
if(args.length > 0) {
if(args[0].equalsIgnoreCase("info")) {
sender.sendMessage(String.format("[%s] Vault v%s Information", getDescription().getName(), getDescription().getVersion()));
sender.sendMessage(String.format("[%s] Economy: %s", getDescription().getName(), getEconomy().getName()));
sender.sendMessage(String.format("[%s] Permission: %s", getDescription().getName(), getPermission().getName()));
return true;
} else if(args[0].equalsIgnoreCase("reload")) {
reload();
sender.sendMessage(String.format("[%s] Reloaded Addons", getDescription().getName()));
return true;
}
}
}
return false;
// Show help
sender.sendMessage("Vault Commands:");
sender.sendMessage(" /vault info - Displays information about Vault");
sender.sendMessage(" /vault reload - Reloads Addons");
return true;
}
/**
* Determines if all packages in a String array are within the Classpath
* This is the best way to determine if a specific plugin exists and will be loaded.
* If the plugin package isn't loaded, we shouldn't bother waiting for it!
* @param packages String Array of package names to check
* @return Success or Failure
*/
private boolean packageExists(String[] packages) {
try {
for (String pkg : packages) {

View File

@ -1,165 +0,0 @@
/**
* 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

@ -19,8 +19,6 @@
package net.milkbowl.vault.permission;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
public interface Permission {

View File

@ -1,191 +0,0 @@
/**
* 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.playerHasPermission(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.playerInGroup(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.getPlayerInfoInteger(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.getPlayerInfoDouble(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.getPlayerInfoBoolean(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.getPlayerInfoString(world, playerName, node, defaultValue);
} else {
return defaultValue;
}
}
}

View File

@ -40,7 +40,7 @@ import com.nijikokun.bukkit.Permissions.Permissions;
public class Permission_Permissions implements Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "Permissions (Phoenix)";
private String name = "Permissions (Yetti)";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private Permissions permission = null;