This commit is contained in:
mung3r 2011-11-07 10:51:27 -08:00
commit 79c2dd39b4
10 changed files with 301 additions and 425 deletions

Binary file not shown.

View File

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

View File

@ -55,280 +55,249 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Vault extends JavaPlugin {
private static final Logger log = Logger.getLogger("Minecraft");
private static final Logger log = Logger.getLogger("Minecraft");
@Override
public void onDisable() {
// Remove all Service Registrations
getServer().getServicesManager().unregisterAll(this);
@Override
public void onDisable() {
// Remove all Service Registrations
getServer().getServicesManager().unregisterAll(this);
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
@Override
public void onEnable() {
// Load Vault Addons
loadEconomy();
loadPermission();
loadChat();
@Override
public void onEnable() {
// Load Vault Addons
loadEconomy();
loadPermission();
loadChat();
getCommand("vault-info").setExecutor(this);
getCommand("vault-reload").setExecutor(this);
log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
getCommand("vault-info").setExecutor(this);
getCommand("vault-reload").setExecutor(this);
log.info(String.format("[%s] Enabled Version %s", getDescription().getName(), getDescription().getVersion()));
}
/**
* Attempts to load Chat Addons
*/
private void loadChat() {
// Try to load PermissionsEx
if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) {
Chat eChat = new Chat_PermissionsEx(this);
getServer().getServicesManager().register(Chat.class, eChat, this, ServicePriority.Highest);
log.info(String.format("[%s][Chat] PermissionsEx found: %s", getDescription().getName(), eChat.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Chat] PermissionsEx not found.", getDescription().getName()));
}
//Try loading mChat
if (packageExists(new String[] {"net.D3GN.MiracleM4n.mChat"} )) {
Chat mChat = new Chat_mChat(this);
getServer().getServicesManager().register(Chat.class, mChat, this, ServicePriority.Highest);
log.info(String.format("[%s][Chat] mChat found: %s", getDescription().getName(), mChat.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Chat] mChat not found.", getDescription().getName()));
}
//try loading bPermissions
if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"})) {
Chat bPerms = new Chat_bPermissions(this);
getServer().getServicesManager().register(Chat.class, bPerms, this, ServicePriority.High);
log.info(String.format("[%s][Chat] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Chat] bPermissions not found.", getDescription().getName()));
}
// Try to load GroupManager
if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) {
Chat gPerms = new Chat_GroupManager(this);
getServer().getServicesManager().register(Chat.class, gPerms, this, ServicePriority.High);
log.info(String.format("[%s][Chat] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Chat] GroupManager not found.", getDescription().getName()));
}
/**
* Attempts to load Chat Addons
*/
private void loadChat() {
// Try to load Permissions 3 (Yeti)
if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) {
Chat nPerms = new Chat_Permissions3(this);
getServer().getServicesManager().register(Chat.class, nPerms, this, ServicePriority.High);
log.info(String.format("[%s][Chat] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Chat] Permissions 3 (Yeti) not found.", getDescription().getName()));
}
}
/**
* Attempts to load Economy Addons
*/
private void loadEconomy() {
// Try to load MultiCurrency
if (packageExists(new String[] { "me.ashtheking.currency.Currency", "me.ashtheking.currency.CurrencyList" })) {
Economy econ = new Economy_MultiCurrency(this);
getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] MultiCurrency found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] MultiCurrency not found.", getDescription().getName()));
}
// Try to load 3co
if (packageExists(new String[] { "me.ic3d.eco.ECO" })) {
Economy econ = new Economy_3co(this);
getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] 3co found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] 3co not found.", getDescription().getName()));
}
// Try to load PermissionsEx
if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) {
Chat eChat = new Chat_PermissionsEx(this);
getServer().getServicesManager().register(Chat.class, eChat, this, ServicePriority.Highest);
log.info(String.format("[%s][Chat] PermissionsEx found: %s", getDescription().getName(), eChat.isEnabled() ? "Loaded" : "Waiting"));
}
// Try to load BOSEconomy
if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandManager" })) {
Economy bose6 = new Economy_BOSE6(this);
getServer().getServicesManager().register(Economy.class, bose6, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] BOSEconomy6 found: %s", getDescription().getName(), bose6.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] BOSEconomy6 not found.", getDescription().getName()));
}
// Try to load BOSEconomy
if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandHandler" })) {
Economy bose7 = new Economy_BOSE7(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, bose7, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] BOSEconomy7 found: %s", getDescription().getName(), bose7.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] BOSEconomy7 not found.", 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(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, essentials, this, ServicePriority.Low);
log.info(String.format("[%s][Economy] Essentials Economy found: %s", getDescription().getName(), essentials.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] Essentials Economy not found.", getDescription().getName()));
}
//Try loading mChat
if (packageExists(new String[] {"net.D3GN.MiracleM4n.mChat"} )) {
Chat mChat = new Chat_mChat(this);
getServer().getServicesManager().register(Chat.class, mChat, this, ServicePriority.Highest);
log.info(String.format("[%s][Chat] mChat found: %s", getDescription().getName(), mChat.isEnabled() ? "Loaded" : "Waiting"));
}
// 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(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon4, this, ServicePriority.High);
log.info(String.format("[%s][Economy] iConomy 4 found: ", getDescription().getName(), icon4.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] iConomy 4 not found.", getDescription().getName()));
}
//try loading bPermissions
if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"})) {
Chat bPerms = new Chat_bPermissions(this);
getServer().getServicesManager().register(Chat.class, bPerms, this, ServicePriority.High);
log.info(String.format("[%s][Chat] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting"));
}
// 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(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon5, this, ServicePriority.High);
log.info(String.format("[%s][Economy] iConomy 5 found: %s", getDescription().getName(), icon5.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] iConomy 5 not found.", getDescription().getName()));
}
// Try to load GroupManager
if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) {
Chat gPerms = new Chat_GroupManager(this);
getServer().getServicesManager().register(Chat.class, gPerms, this, ServicePriority.High);
log.info(String.format("[%s][Chat] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting"));
}
// Try to load iConomy 6
if (packageExists(new String[] { "com.iCo6.iConomy" })) {
Economy icon6 = new Economy_iConomy6(this);
getServer().getServicesManager().register(Economy.class, icon6, this, ServicePriority.High);
log.info(String.format("[%s][Economy] iConomy 6 found: %s", getDescription().getName(), icon6.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Economy] iConomy 6 not found.", getDescription().getName()));
}
}
// Try to load Permissions 3 (Yeti)
if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) {
Chat nPerms = new Chat_Permissions3(this);
getServer().getServicesManager().register(Chat.class, nPerms, this, ServicePriority.High);
log.info(String.format("[%s][Chat] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
}
}
/**
* Attempts to load Permission Addons
*/
private void loadPermission() {
// Try to load PermissionsEx
if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) {
Permission ePerms = new Permission_PermissionsEx(this);
getServer().getServicesManager().register(Permission.class, ePerms, this, ServicePriority.Highest);
log.info(String.format("[%s][Permission] PermissionsEx found: %s", getDescription().getName(), ePerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] PermissionsEx not found.", getDescription().getName()));
}
//Try loading PermissionsBukkit
if (packageExists(new String[] {"com.platymuus.bukkit.permissions.PermissionsPlugin"} )) {
Permission pPerms = new Permission_PermissionsBukkit(this);
getServer().getServicesManager().register(Permission.class, pPerms, this, ServicePriority.Highest);
log.info(String.format("[%s][Permission] PermissionsBukkit found: %s", getDescription().getName(), pPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] PermissionsBukkit not found.", getDescription().getName()));
}
if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"} )) {
Permission bPerms = new Permission_bPermissions(this);
getServer().getServicesManager().register(Permission.class, bPerms, this, ServicePriority.Highest);
log.info(String.format("[%s][Permission] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] bPermissions not found.", getDescription().getName()));
}
// Try to load GroupManager
if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) {
Permission gPerms = new Permission_GroupManager(this);
getServer().getServicesManager().register(Permission.class, gPerms, this, ServicePriority.High);
log.info(String.format("[%s][Permission] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] GroupManager not found.", getDescription().getName()));
}
/**
* Attempts to load Economy Addons
*/
private void loadEconomy() {
// Try to load MultiCurrency
if (packageExists(new String[] { "me.ashtheking.currency.Currency", "me.ashtheking.currency.CurrencyList" })) {
Economy econ = new Economy_MultiCurrency(this);
getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] MultiCurrency found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting"));
}
// Try to load Permissions 3 (Yeti)
if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) {
Permission nPerms = new Permission_Permissions3(this);
getServer().getServicesManager().register(Permission.class, nPerms, this, ServicePriority.High);
log.info(String.format("[%s][Permission] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] Permissions 3 (Yeti) not found.", getDescription().getName()));
}
Permission perms = new Permission_SuperPerms(this);
getServer().getServicesManager().register(Permission.class, perms, this, ServicePriority.Lowest);
log.info(String.format("[%s][Permission] SuperPermissions loaded as backup permission system.", getDescription().getName()));
// Try to load 3co
if (packageExists(new String[] { "me.ic3d.eco.ECO" })) {
Economy econ = new Economy_3co(this);
getServer().getServicesManager().register(Economy.class, econ, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] 3co found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting"));
}
}
// Try to load BOSEconomy
if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandManager" })) {
Economy bose6 = new Economy_BOSE6(this);
getServer().getServicesManager().register(Economy.class, bose6, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] BOSEconomy6 found: %s", getDescription().getName(), bose6.isEnabled() ? "Loaded" : "Waiting"));
}
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if (sender instanceof Player) {
// Check if Player
// If so, ignore command if player is not Op
Player p = (Player) sender;
if (!p.isOp()) {
return true;
}
} else if (!(sender instanceof ConsoleCommandSender)) {
// Check if NOT console
// Ignore it if not originated from Console!
return true;
}
// Try to load BOSEconomy
if (packageExists(new String[] { "cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandHandler" })) {
Economy bose7 = new Economy_BOSE7(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, bose7, this, ServicePriority.Normal);
log.info(String.format("[%s][Economy] BOSEconomy7 found: %s", getDescription().getName(), bose7.isEnabled() ? "Loaded" : "Waiting"));
}
if (command.getLabel().equals("vault-info")) {
// 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(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, essentials, this, ServicePriority.Low);
log.info(String.format("[%s][Economy] Essentials Economy found: %s", getDescription().getName(), essentials.isEnabled() ? "Loaded" : "Waiting"));
}
// Get String of Registered Economy Services
String registeredEcons = null;
Collection<RegisteredServiceProvider<Economy>> econs = this.getServer().getServicesManager().getRegistrations(Economy.class);
for (RegisteredServiceProvider<Economy> econ : econs) {
Economy e = econ.getProvider();
if (registeredEcons == null) {
registeredEcons = e.getName();
} else {
registeredEcons += ", " + e.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(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon4, this, ServicePriority.High);
log.info(String.format("[%s][Economy] iConomy 4 found: ", getDescription().getName(), icon4.isEnabled() ? "Loaded" : "Waiting"));
}
// Get String of Registered Permission Services
String registeredPerms = null;
Collection<RegisteredServiceProvider<Permission>> perms = this.getServer().getServicesManager().getRegistrations(Permission.class);
for (RegisteredServiceProvider<Permission> perm : perms) {
Permission p = perm.getProvider();
if (registeredPerms == null) {
registeredPerms = p.getName();
} else {
registeredPerms += ", " + p.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(this);
getServer().getServicesManager().register(net.milkbowl.vault.economy.Economy.class, icon5, this, ServicePriority.High);
log.info(String.format("[%s][Economy] iConomy 5 found: %s", getDescription().getName(), icon5.isEnabled() ? "Loaded" : "Waiting"));
}
// Get Economy & Permission primary Services
Economy econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider();
Permission perm = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
// Try to load iConomy 6
if (packageExists(new String[] { "com.iCo6.iConomy" })) {
Economy icon6 = new Economy_iConomy6(this);
getServer().getServicesManager().register(Economy.class, icon6, this, ServicePriority.High);
log.info(String.format("[%s][Economy] iConomy 6 found: %s", getDescription().getName(), icon6.isEnabled() ? "Loaded" : "Waiting"));
}
}
// Send user some info!
sender.sendMessage(String.format("[%s] Vault v%s Information", getDescription().getName(), getDescription().getVersion()));
sender.sendMessage(String.format("[%s] Economy: %s [%s]", getDescription().getName(), econ.getName(), registeredEcons));
sender.sendMessage(String.format("[%s] Permission: %s [%s]", getDescription().getName(), perm.getName(), registeredPerms));
return true;
} else {
// Show help
sender.sendMessage("Vault Commands:");
sender.sendMessage(" /vault-info - Displays information about Vault");
return true;
}
}
/**
* Attempts to load Permission Addons
*/
private void loadPermission() {
// Try to load PermissionsEx
if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) {
Permission ePerms = new Permission_PermissionsEx(this);
getServer().getServicesManager().register(Permission.class, ePerms, this, ServicePriority.Highest);
log.info(String.format("[%s][Permission] PermissionsEx found: %s", getDescription().getName(), ePerms.isEnabled() ? "Loaded" : "Waiting"));
log.info(String.format("[%s] - Warning Using PEX can cause SuperPerms compatibility issues with non-Vault enabled plugins.", getDescription().getName()));
}
/**
* 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 static boolean packageExists(String[] packages) {
try {
for (String pkg : packages) {
Class.forName(pkg);
}
return true;
} catch (Exception e) {
return false;
}
}
//Try loading PermissionsBukkit
if (packageExists(new String[] {"com.platymuus.bukkit.permissions.PermissionsPlugin"} )) {
Permission pPerms = new Permission_PermissionsBukkit(this);
getServer().getServicesManager().register(Permission.class, pPerms, this, ServicePriority.Highest);
log.info(String.format("[%s][Permission] PermissionsBukkit found: %s", getDescription().getName(), pPerms.isEnabled() ? "Loaded" : "Waiting"));
}
//Try to load bPermissions
if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"} )) {
Permission bPerms = new Permission_bPermissions(this);
getServer().getServicesManager().register(Permission.class, bPerms, this, ServicePriority.Highest);
log.info(String.format("[%s][Permission] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting"));
}
// Try to load GroupManager
if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) {
Permission gPerms = new Permission_GroupManager(this);
getServer().getServicesManager().register(Permission.class, gPerms, this, ServicePriority.High);
log.info(String.format("[%s][Permission] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting"));
}
// Try to load Permissions 3 (Yeti)
if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) {
Permission nPerms = new Permission_Permissions3(this);
getServer().getServicesManager().register(Permission.class, nPerms, this, ServicePriority.High);
log.info(String.format("[%s][Permission] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
}
Permission perms = new Permission_SuperPerms(this);
getServer().getServicesManager().register(Permission.class, perms, this, ServicePriority.Lowest);
log.info(String.format("[%s][Permission] SuperPermissions loaded as backup permission system.", getDescription().getName()));
}
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
if (sender instanceof Player) {
// Check if Player
// If so, ignore command if player is not Op
Player p = (Player) sender;
if (!p.isOp()) {
return true;
}
} else if (!(sender instanceof ConsoleCommandSender)) {
// Check if NOT console
// Ignore it if not originated from Console!
return true;
}
if (command.getLabel().equals("vault-info")) {
// Get String of Registered Economy Services
String registeredEcons = null;
Collection<RegisteredServiceProvider<Economy>> econs = this.getServer().getServicesManager().getRegistrations(Economy.class);
for (RegisteredServiceProvider<Economy> econ : econs) {
Economy e = econ.getProvider();
if (registeredEcons == null) {
registeredEcons = e.getName();
} else {
registeredEcons += ", " + e.getName();
}
}
// Get String of Registered Permission Services
String registeredPerms = null;
Collection<RegisteredServiceProvider<Permission>> perms = this.getServer().getServicesManager().getRegistrations(Permission.class);
for (RegisteredServiceProvider<Permission> perm : perms) {
Permission p = perm.getProvider();
if (registeredPerms == null) {
registeredPerms = p.getName();
} else {
registeredPerms += ", " + p.getName();
}
}
// Get Economy & Permission primary Services
Economy econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider();
Permission perm = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
// Send user some info!
sender.sendMessage(String.format("[%s] Vault v%s Information", getDescription().getName(), getDescription().getVersion()));
sender.sendMessage(String.format("[%s] Economy: %s [%s]", getDescription().getName(), econ.getName(), registeredEcons));
sender.sendMessage(String.format("[%s] Permission: %s [%s]", getDescription().getName(), perm.getName(), registeredPerms));
return true;
} else {
// Show help
sender.sendMessage("Vault Commands:");
sender.sendMessage(" /vault-info - Displays information about Vault");
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 static boolean packageExists(String[] packages) {
try {
for (String pkg : packages) {
Class.forName(pkg);
}
return true;
} catch (Exception e) {
return false;
}
}
}

View File

@ -19,11 +19,20 @@
package net.milkbowl.vault.permission;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
public abstract class Permission {
protected static final Logger log = Logger.getLogger("Minecraft");
protected Vault plugin = null;
/**
* Gets name of permission method
* @return Name of Permission Method
@ -130,12 +139,34 @@ public abstract class Permission {
/**
* Add transient permission to a player.
* This implementation can be used by any subclass which implements a "pure" superperms plugin, i.e.
* one that only needs the built-in Bukkit API to add transient permissions to a player. Any subclass
* implementing a plugin which provides its own API for this needs to override this method.
* @param world World name
* @param player Player name
* @param permission Permission node
* @return Success or Failure
*/
abstract public boolean playerAddTransient(String world, String player, String permission);
public boolean playerAddTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true);
return true;
}
}
PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true);
return true;
}
/**
* Add transient permission to a player.
* @param world World Object
@ -187,14 +218,29 @@ public abstract class Permission {
}
/**
* Remove transient permission to a player.
* Remove transient permission from a player.
* This implementation can be used by any subclass which implements a "pure" superperms plugin, i.e.
* one that only needs the built-in Bukkit API to remove transient permissions from a player. Any subclass
* implementing a plugin which provides its own API for this needs to override this method.
* @param world World name
* @param player Player name
* @param permission Permission node
* @return Success or Failure
*/
abstract public boolean playerRemoveTransient(String world, String player, String permission);
public boolean playerRemoveTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null)
return false;
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment() != null && paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().unsetPermission(permission);
return true;
}
}
return false;
}
/**
* Remove transient permission from a player.
* @param world World name
@ -213,7 +259,7 @@ public abstract class Permission {
* @return Success or Failure
*/
public boolean playerRemoveTransient(Player player, String permission) {
return playerRemove(player.getWorld().getName(), player.getName(), permission);
return playerRemoveTransient(player.getWorld().getName(), player.getName(), permission);
}
/**

View File

@ -3,8 +3,8 @@ package net.milkbowl.vault.permission.plugins;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
import org.anjocaido.groupmanager.GroupManager;
@ -24,17 +24,15 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class Permission_GroupManager extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "GroupManager";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private GroupManager groupManager;
private AnjoPermissionsHandler perms;
private PermissionServerListener permissionServerListener = null;
@SuppressWarnings("deprecation")
public Permission_GroupManager(Plugin plugin) {
public Permission_GroupManager(Vault plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();

View File

@ -21,13 +21,10 @@ package net.milkbowl.vault.permission.plugins;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
@ -37,16 +34,13 @@ import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijiko.permissions.Group;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
public class Permission_Permissions3 extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "Permissions 3 (Yeti)";
private PermissionHandler perms;
private Vault plugin = null;
private PluginManager pluginManager = null;
private Permissions permission = null;
private PermissionServerListener permissionServerListener = null;

View File

@ -2,18 +2,14 @@ package net.milkbowl.vault.permission.plugins;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.craftbukkit.command.ColouredConsoleSender;
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.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@ -21,29 +17,28 @@ import com.platymuus.bukkit.permissions.Group;
import com.platymuus.bukkit.permissions.PermissionsPlugin;
import net.D3GN.MiracleM4n.mChat.mChatAPI;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
public class Permission_PermissionsBukkit extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private final String name = "PermissionsBukkit";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private PermissionsPlugin perms = null;
private mChatAPI mChat = null;
private PermissionServerListener permissionServerListener = null;
private ConsoleCommandSender ccs;
public Permission_PermissionsBukkit(Plugin plugin) {
public Permission_PermissionsBukkit(Vault plugin) {
this.plugin = plugin;
ccs = ColouredConsoleSender.getInstance();
ccs = Bukkit.getServer().getConsoleSender();
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 (perms == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
@ -52,7 +47,7 @@ public class Permission_PermissionsBukkit extends Permission {
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
if (mChat == null) {
Plugin chat = plugin.getServer().getPluginManager().getPlugin("mChat");
if (chat != null) {
@ -62,7 +57,6 @@ public class Permission_PermissionsBukkit extends Permission {
}
}
private class PermissionServerListener extends ServerListener {
Permission_PermissionsBukkit permission = null;
@ -133,27 +127,7 @@ public class Permission_PermissionsBukkit extends Permission {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(ccs, "permission player setperm " + player + " " + permission + " true");
}
@Override
public boolean playerAddTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true);
return true;
}
}
PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true);
return true;
return plugin.getServer().dispatchCommand(ccs, "permissions player setperm " + player + " " + permission + " true");
}
@Override
@ -161,23 +135,11 @@ public class Permission_PermissionsBukkit extends Permission {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(ccs, "permission player unsetperm " + player + " " + permission);
}
@Override
public boolean playerRemoveTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
}
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
return paInfo.getAttachment().getPermissions().remove(permission);
}
}
return false;
return plugin.getServer().dispatchCommand(ccs, "permissions player unsetperm " + player + " " + permission);
}
// use superclass implementation of playerAddTransient() and playerRemoveTransient()
@Override
public boolean groupHas(String world, String group, String permission) {
if (world != null && !world.isEmpty()) {
@ -197,7 +159,7 @@ public class Permission_PermissionsBukkit extends Permission {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(ccs, "permission group setperm " + group + " " + permission + " true");
return plugin.getServer().dispatchCommand(ccs, "permissions group setperm " + group + " " + permission + " true");
}
@Override
@ -205,7 +167,7 @@ public class Permission_PermissionsBukkit extends Permission {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(ccs, "permission group unsetperm " + group + " " + permission);
return plugin.getServer().dispatchCommand(ccs, "permissions group unsetperm " + group + " " + permission);
}
@Override
@ -226,7 +188,7 @@ public class Permission_PermissionsBukkit extends Permission {
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support world based groups.");
}
return plugin.getServer().dispatchCommand(ccs, "permission player addgroup " + group + " " + player);
return plugin.getServer().dispatchCommand(ccs, "permissions player addgroup " + group + " " + player);
}
@Override
@ -234,9 +196,9 @@ public class Permission_PermissionsBukkit extends Permission {
if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support world based groups.");
}
return plugin.getServer().dispatchCommand(ccs, "permission player removegroup " + group + " " + player);
return plugin.getServer().dispatchCommand(ccs, "permissions player removegroup " + group + " " + player);
}
@Override
public String[] getPlayerGroups(String world, String player) {
List<String> groupList = new ArrayList<String>();
@ -270,7 +232,7 @@ public class Permission_PermissionsBukkit extends Permission {
for (Group group : perms.getAllGroups()) {
groupNames.add(group.getName());
}
return groupNames.toArray(new String[0]);
}
}

View File

@ -19,8 +19,6 @@
package net.milkbowl.vault.permission.plugins;
import java.util.logging.Logger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
@ -38,10 +36,8 @@ import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx;
public class Permission_PermissionsEx extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private final String name = "PermissionsEx";
private Vault plugin = null;
private PluginManager pluginManager = null;
private PermissionsEx permission = null;
private PermissionServerListener permissionServerListener = null;
@ -88,21 +84,7 @@ public class Permission_PermissionsEx extends Permission {
@Override
public boolean playerInGroup(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;
return PermissionsEx.getPermissionManager().getUser(playerName).inGroup(groupName);
}
private class PermissionServerListener extends ServerListener {
@ -154,14 +136,8 @@ public class Permission_PermissionsEx extends Permission {
@Override
public boolean playerRemoveGroup(String worldName, String playerName, String groupName) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if (group == null || user == null) {
return false;
} else {
user.removeGroup(group);
return true;
}
PermissionsEx.getPermissionManager().getUser(playerName).removeGroup(groupName);
return true;
}
@Override

View File

@ -1,8 +1,6 @@
package net.milkbowl.vault.permission.plugins;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
@ -37,44 +35,13 @@ public class Permission_SuperPerms extends Permission {
return false;
}
@Override
public boolean playerAddTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null)
return false;
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true);
return true;
}
}
PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true);
return true;
}
// use superclass implementation of playerAddTransient() and playerRemoveTransient()
@Override
public boolean playerRemove(String world, String player, String permission) {
return false;
}
@Override
public boolean playerRemoveTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null)
return false;
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
return paInfo.getAttachment().getPermissions().remove(permission);
}
}
return false;
}
@Override
public boolean groupHas(String world, String group, String permission) {
throw new UnsupportedOperationException(getName() + " no group permissions.");

View File

@ -1,7 +1,6 @@
package net.milkbowl.vault.permission.plugins;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
@ -9,8 +8,6 @@ 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.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@ -22,10 +19,8 @@ import net.milkbowl.vault.Vault;
import net.milkbowl.vault.permission.Permission;
public class Permission_bPermissions extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "bPermissions";
private Vault plugin = null;
private PluginManager pluginManager = null;
private WorldPermissionsManager perms;
private PermissionServerListener permissionServerListener = null;
@ -95,44 +90,13 @@ public class Permission_bPermissions extends Permission {
throw new UnsupportedOperationException("Player specific permissions are not supported!");
}
@Override
public boolean playerAddTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null)
return false;
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true);
return true;
}
}
PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true);
return true;
}
@Override
public boolean playerRemove(String world, String player, String permission) {
throw new UnsupportedOperationException("Player specific permissions are not supported!");
}
@Override
public boolean playerRemoveTransient(String world, String player, String permission) {
Player p = plugin.getServer().getPlayer(player);
if (p == null)
return false;
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) {
return paInfo.getAttachment().getPermissions().remove(permission);
}
}
return false;
}
// use superclass implementation of playerAddTransient() and playerRemoveTransient()
@Override
public boolean groupHas(String world, String group, String permission) {
if (world == null)