mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-09-21 02:01:10 +02:00
142 lines
5.2 KiB
Java
142 lines
5.2 KiB
Java
|
/**
|
||
|
* 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);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|