2011-06-29 02:18:20 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2011-06-30 01:11:03 +02:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2011-06-29 02:18:20 +02:00
|
|
|
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;
|
|
|
|
|
2011-06-30 00:24:59 +02:00
|
|
|
import com.nijiko.permissions.Group;
|
2011-06-29 02:18:20 +02:00
|
|
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
|
|
|
|
|
|
|
public class Permission_Permissions implements Permission {
|
2011-06-30 01:11:03 +02:00
|
|
|
private static final Logger log = Logger.getLogger("Minecraft");
|
|
|
|
|
2011-06-30 16:37:26 +02:00
|
|
|
private String name = "Permissions (Yetti)";
|
2011-06-29 02:18:20 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2011-07-05 20:37:51 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean has(Player player, String permission) {
|
|
|
|
return playerHas(player, permission);
|
|
|
|
}
|
2011-06-29 02:18:20 +02:00
|
|
|
|
|
|
|
@Override
|
2011-07-05 20:37:51 +02:00
|
|
|
public boolean playerHas(Player player, String permission) {
|
2011-06-29 02:18:20 +02:00
|
|
|
return this.permission.getHandler().has(player, permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public boolean playerInGroup(String worldName, String playerName, String groupName) {
|
2011-06-29 02:18:20 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
|
2011-06-30 17:01:39 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
|
|
|
|
if(s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return Integer.parseInt(s);
|
|
|
|
} catch(NumberFormatException e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 02:18:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
|
2011-06-30 17:01:39 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
|
|
|
|
if(s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return Double.parseDouble(s);
|
|
|
|
} catch(NumberFormatException e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 02:18:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
|
2011-06-30 17:01:39 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
|
|
|
|
if (s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
return Boolean.parseBoolean(s);
|
|
|
|
}
|
2011-06-29 02:18:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
|
2011-06-30 17:01:39 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
|
|
|
|
if(s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
return s;
|
|
|
|
}
|
2011-06-29 02:18:20 +02:00
|
|
|
}
|
|
|
|
|
2011-06-29 23:44:42 +02:00
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public boolean playerAddGroup(String worldName, String playerName, String groupName) {
|
2011-06-29 23:44:42 +02:00
|
|
|
// Not certain if this is possible in P3
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public boolean playerRemoveGroup(String worldName, String playerName, String groupName) {
|
2011-06-29 23:44:42 +02:00
|
|
|
// Not certain if this is possible in P3
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-07-05 20:37:51 +02:00
|
|
|
public boolean playerAdd(String worldName, String playerName, String permission) {
|
2011-06-29 23:44:42 +02:00
|
|
|
this.permission.getHandler().addUserPermission(worldName, playerName, permission);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-07-05 20:37:51 +02:00
|
|
|
public boolean playerRemove(String worldName, String playerName, String permission) {
|
2011-06-29 23:44:42 +02:00
|
|
|
this.permission.getHandler().removeUserPermission(worldName, playerName, permission);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-07-05 20:37:51 +02:00
|
|
|
public boolean groupAdd(String worldName, String groupName, String permission) {
|
2011-06-29 23:44:42 +02:00
|
|
|
this.permission.getHandler().addGroupPermission(worldName, groupName, permission);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-07-05 20:37:51 +02:00
|
|
|
public boolean groupRemove(String worldName, String groupName, String permission) {
|
2011-06-29 23:44:42 +02:00
|
|
|
this.permission.getHandler().removeGroupPermission(worldName, groupName, permission);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
|
2011-06-29 23:44:42 +02:00
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 02:18:20 +02:00
|
|
|
|
2011-06-29 23:44:42 +02:00
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
|
2011-06-29 23:44:42 +02:00
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
|
2011-06-29 23:44:42 +02:00
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-06-30 00:24:59 +02:00
|
|
|
public void setPlayerInfoString(String world, String playerName, String node, String value) {
|
2011-06-29 23:44:42 +02:00
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
|
2011-06-30 16:55:09 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
|
|
|
|
if(s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return Integer.parseInt(s);
|
|
|
|
} catch(NumberFormatException e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 23:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setGroupInfoInteger(String world, String groupName, String node, int value) {
|
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
|
2011-06-30 16:55:09 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
|
|
|
|
if(s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
return Double.parseDouble(s);
|
|
|
|
} catch(NumberFormatException e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 23:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setGroupInfoDouble(String world, String groupName, String node, double value) {
|
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
|
2011-06-30 16:55:09 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
|
|
|
|
if(s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
return Boolean.parseBoolean(s);
|
|
|
|
}
|
2011-06-29 23:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
|
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
|
2011-06-30 16:55:09 +02:00
|
|
|
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
|
|
|
|
if(s == null) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
return s;
|
|
|
|
}
|
2011-06-29 23:44:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setGroupInfoString(String world, String groupName, String node, String value) {
|
|
|
|
try {
|
|
|
|
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
|
|
|
|
} catch(Exception e) {
|
|
|
|
// lolwut?
|
|
|
|
}
|
|
|
|
}
|
2011-06-30 00:24:59 +02:00
|
|
|
|
|
|
|
@Override
|
2011-07-05 20:37:51 +02:00
|
|
|
public boolean groupHas(String worldName, String groupName, String permission) {
|
2011-06-30 00:24:59 +02:00
|
|
|
try {
|
|
|
|
Group group = this.permission.getHandler().safeGetGroup(worldName, groupName);
|
|
|
|
return group.hasPermission(permission);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// lowut?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 23:44:42 +02:00
|
|
|
}
|