Add additional nodes and change Permission to abstract instead of interface

This commit is contained in:
Morgan 2011-07-20 20:43:46 -04:00
parent a8d30e5a03
commit 987aa76b25
3 changed files with 234 additions and 47 deletions

View File

@ -19,21 +19,22 @@
package net.milkbowl.vault.permission;
import org.bukkit.World;
import org.bukkit.entity.Player;
public interface Permission {
public abstract class Permission {
/**
* Gets name of permission method
* @return Name of Permission Method
*/
public String getName();
abstract public String getName();
/**
* Checks if permission method is enabled.
* @return Success or Failure
*/
public boolean isEnabled();
abstract public boolean isEnabled();
/**
* Checks if player has a permission node. (Short for playerHas(...)
@ -41,7 +42,15 @@ public interface Permission {
* @param permission Permission node
* @return Success or Failure
*/
public boolean has(Player player, String permission);
public boolean has(String worldName, String playerName, String permission) {
return playerHas(worldName, playerName, permission);
}
public boolean has(World world, String playerName, String permission) {
return playerHas(world.getName(), playerName, permission);
}
public boolean has(Player player, String permission) {
return playerHas(player.getWorld().getName(), player.getName(), permission);
}
/**
* Checks if player has a permission node.
@ -49,7 +58,13 @@ public interface Permission {
* @param permission Permission node
* @return Success or Failure
*/
public boolean playerHas(Player player, String permission);
abstract public boolean playerHas(String worldName, String playerName, String permission);
public boolean playerHas(World world, String playerName, String permission) {
return playerHas(world.getName(), playerName, permission);
}
public boolean playerHas(Player player, String permission) {
return playerHas(player.getWorld().getName(), player.getName(), permission);
}
/**
* Add permission to a player.
@ -58,7 +73,13 @@ public interface Permission {
* @param permission Permission node
* @return Success or Failure
*/
public boolean playerAdd(String worldName, String playerName, String permission);
abstract public boolean playerAdd(String worldName, String playerName, String permission);
public boolean playerAdd(World world, String playerName, String permission) {
return playerAdd(world.getName(), playerName, permission);
}
public boolean playerAdd(Player player, String permission) {
return playerAdd(player.getWorld().getName(), player.getName(), permission);
}
/**
* Remove permission from a player.
@ -67,7 +88,13 @@ public interface Permission {
* @param permission Permission node
* @return Success or Failure
*/
public boolean playerRemove(String worldName, String playerName, String permission);
abstract public boolean playerRemove(String worldName, String playerName, String permission);
public boolean playerRemove(World world, String playerName, String permission) {
return playerRemove(world.getName(), playerName, permission);
}
public boolean playerRemove(Player player, String permission) {
return playerRemove(player.getWorld().getName(), player.getName(), permission);
}
/**
* Checks if group has a permission node.
@ -76,7 +103,10 @@ public interface Permission {
* @param permission Permission node
* @return Success or Failure
*/
public boolean groupHas(String worldName, String groupName, String permission);
abstract public boolean groupHas(String worldName, String groupName, String permission);
public boolean groupHas(World world, String groupName, String permission) {
return groupHas(world.getName(), groupName, permission);
}
/**
* Add permission to a group.
@ -85,7 +115,10 @@ public interface Permission {
* @param permission Permission node
* @return Success or Failure
*/
public boolean groupAdd(String worldName, String groupName, String permission);
abstract public boolean groupAdd(String worldName, String groupName, String permission);
public boolean groupAdd(World world, String groupName, String permission) {
return groupAdd(world.getName(), groupName, permission);
}
/**
* Remove permission from a group.
@ -94,7 +127,10 @@ public interface Permission {
* @param permission Permission node
* @return Success or Failure
*/
public boolean groupRemove(String worldName, String groupName, String permission);
abstract public boolean groupRemove(String worldName, String groupName, String permission);
public boolean groupRemove(World world, String groupName, String permission) {
return groupRemove(world.getName(), groupName, permission);
}
/**
* Check if player is member of a group.
@ -103,7 +139,13 @@ public interface Permission {
* @param groupName Name of Group
* @return Success or Failure
*/
public boolean playerInGroup(String worldName, String playerName, String groupName);
abstract public boolean playerInGroup(String worldName, String playerName, String groupName);
public boolean playerInGroup(World world, String playerName, String groupName) {
return playerInGroup(world.getName(), playerName, groupName);
}
public boolean playerInGroup(Player player, String groupName) {
return playerInGroup(player.getWorld().getName(), player.getName(), groupName);
}
/**
* Add player to a group.
@ -112,7 +154,13 @@ public interface Permission {
* @param groupName Name of Group
* @return Success or Failure
*/
public boolean playerAddGroup(String worldName, String playerName, String groupName);
abstract public boolean playerAddGroup(String worldName, String playerName, String groupName);
public boolean playerAddGroup(World world, String playerName, String groupName) {
return playerAddGroup(world.getName(), playerName, groupName);
}
public boolean playerAddGroup(Player player, String groupName) {
return playerAddGroup(player.getWorld().getName(), player.getName(), groupName);
}
/**
* Remove player from a group.
@ -121,7 +169,13 @@ public interface Permission {
* @param groupName Name of Group
* @return Success or Failure
*/
public boolean playerRemoveGroup(String worldName, String playerName, String groupName);
abstract public boolean playerRemoveGroup(String worldName, String playerName, String groupName);
public boolean playerRemoveGroup(World world, String playerName, String groupName) {
return playerRemoveGroup(world.getName(), playerName, groupName);
}
public boolean playerRemoveGroup(Player player, String groupName) {
return playerRemoveGroup(player.getWorld().getName(), player.getName(), groupName);
}
/**
* Get a players informational node (Integer) value
@ -131,7 +185,13 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue);
abstract public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue);
public int getPlayerInfoInteger(World world, String playerName, String node, int defaultValue) {
return getPlayerInfoInteger(world.getName(), playerName, node, defaultValue);
}
public int getPlayerInfoInteger(Player player, String node, int defaultValue) {
return getPlayerInfoInteger(player.getWorld().getName(), player.getName(), node, defaultValue);
}
/**
* Set a players informational node (Integer) value
@ -140,7 +200,13 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setPlayerInfoInteger(String world, String playerName, String node, int value);
abstract public void setPlayerInfoInteger(String world, String playerName, String node, int value);
public void setPlayerInfoInteger(World world, String playerName, String node, int value) {
setPlayerInfoInteger(world.getName(), playerName, node, value);
}
public void setPlayerInfoInteger(Player player, String node, int value) {
setPlayerInfoInteger(player.getWorld().getName(), player.getName(), node, value);
}
/**
* Get a groups informational node (Integer) value
@ -150,8 +216,10 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue);
abstract public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue);
public int getGroupInfoInteger(World world, String groupName, String node, int defaultValue) {
return getGroupInfoInteger(world.getName(), groupName, node, defaultValue);
}
/**
* Set a groups informational node (Integer) value
@ -160,7 +228,10 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setGroupInfoInteger(String world, String groupName, String node, int value);
abstract public void setGroupInfoInteger(String world, String groupName, String node, int value);
public void setGroupInfoInteger(World world, String groupName, String node, int value) {
setGroupInfoInteger(world.getName(), groupName, node, value);
}
/**
* Get a players informational node (Double) value
@ -170,7 +241,13 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue);
abstract public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue);
public double getPlayerInfoDouble(World world, String playerName, String node, double defaultValue) {
return getPlayerInfoDouble(world.getName(), playerName, node, defaultValue);
}
public double getPlayerInfoDouble(Player player, String node, double defaultValue) {
return getPlayerInfoDouble(player.getWorld().getName(), player.getName(), node, defaultValue);
}
/**
* Set a players informational node (Double) value
@ -179,7 +256,13 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setPlayerInfoDouble(String world, String playerName, String node, double value);
abstract public void setPlayerInfoDouble(String world, String playerName, String node, double value);
public void setPlayerInfoDouble(World world, String playerName, String node, double value) {
setPlayerInfoDouble(world.getName(), playerName, node, value);
}
public void setPlayerInfoDouble(Player player, String node, double value) {
setPlayerInfoDouble(player.getWorld().getName(), player.getName(), node, value);
}
/**
* Get a groups informational node (Double) value
@ -189,7 +272,10 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue);
abstract public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue);
public double getGroupInfoDouble(World world, String groupName, String node, double defaultValue) {
return getGroupInfoDouble(world.getName(), groupName, node, defaultValue);
}
/**
* Set a groups informational node (Double) value
@ -198,7 +284,10 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setGroupInfoDouble(String world, String groupName, String node, double value);
abstract public void setGroupInfoDouble(String world, String groupName, String node, double value);
public void setGroupInfoDouble(World world, String groupName, String node, double value) {
setGroupInfoDouble(world.getName(), groupName, node, value);
}
/**
* Get a players informational node (Boolean) value
@ -208,7 +297,13 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue);
abstract public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue);
public boolean getPlayerInfoBoolean(World world, String playerName, String node, boolean defaultValue) {
return getPlayerInfoBoolean(world.getName(), playerName, node, defaultValue);
}
public boolean getPlayerInfoBoolean(Player player, String node, boolean defaultValue) {
return getPlayerInfoBoolean(player.getWorld().getName(), player.getName(), node, defaultValue);
}
/**
* Set a players informational node (Boolean) value
@ -217,7 +312,13 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value);
abstract public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value);
public void setPlayerInfoBoolean(World world, String playerName, String node, boolean value) {
setPlayerInfoBoolean(world.getName(), playerName, node, value);
}
public void setPlayerInfoBoolean(Player player, String node, boolean value) {
setPlayerInfoBoolean(player.getWorld().getName(), player.getName(), node, value);
}
/**
* Get a groups informational node (Boolean) value
@ -227,7 +328,10 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue);
abstract public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue);
public boolean getGroupInfoBoolean(World world, String groupName, String node, boolean defaultValue) {
return getGroupInfoBoolean(world.getName(), groupName, node, defaultValue);
}
/**
* Set a groups informational node (Boolean) value
@ -236,7 +340,10 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value);
abstract public void setGroupInfoBoolean(String world, String groupName, String node, boolean value);
public void setGroupInfoBoolean(World world, String groupName, String node, boolean value) {
setGroupInfoBoolean(world.getName(), groupName, node, value);
}
/**
* Get a players informational node (String) value
@ -246,7 +353,13 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue);
abstract public String getPlayerInfoString(String world, String playerName, String node, String defaultValue);
public String getPlayerInfoString(World world, String playerName, String node, String defaultValue) {
return getPlayerInfoString(world.getName(), playerName, node, defaultValue);
}
public String getPlayerInfoString(Player player, String node, String defaultValue) {
return getPlayerInfoString(player.getWorld().getName(), player.getName(), node, defaultValue);
}
/**
* Set a players informational node (String) value
@ -255,7 +368,13 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setPlayerInfoString(String world, String playerName, String node, String value);
abstract public void setPlayerInfoString(String world, String playerName, String node, String value);
public void setPlayerInfoString(World world, String playerName, String node, String value) {
setPlayerInfoString(world.getName(), playerName, node, value);
}
public void setPlayerInfoString(Player player, String node, String value) {
setPlayerInfoString(player.getWorld().getName(), player.getName(), node, value);
}
/**
* Get a groups informational node (String) value
@ -265,7 +384,10 @@ public interface Permission {
* @param defaultValue Default value (if node is not defined)
* @return Value
*/
public String getGroupInfoString(String world, String groupName, String node, String defaultValue);
abstract public String getGroupInfoString(String world, String groupName, String node, String defaultValue);
public String getGroupInfoString(World world, String groupName, String node, String defaultValue) {
return getGroupInfoString(world.getName(), groupName, node, defaultValue);
}
/**
* Set a groups informational node (String) value
@ -274,7 +396,10 @@ public interface Permission {
* @param node Permission node
* @param value Value to set
*/
public void setGroupInfoString(String world, String groupName, String node, String value);
abstract public void setGroupInfoString(String world, String groupName, String node, String value);
public void setGroupInfoString(World world, String groupName, String node, String value) {
setGroupInfoString(world.getName(), groupName, node, value);
}
/**
* Gets the list of groups that this player has
@ -282,7 +407,13 @@ public interface Permission {
* @param playerName Name of Player
* @return Array of groups
*/
public String[] getPlayerGroups(String world, String playerName);
abstract public String[] getPlayerGroups(String world, String playerName);
public String[] getPlayerGroups(World world, String playerName) {
return getPlayerGroups(world.getName(), playerName);
}
public String[] getPlayerGroups(Player player) {
return getPlayerGroups(player.getWorld().getName(), player.getName());
}
/**
* Gets users primary group
@ -290,5 +421,27 @@ public interface Permission {
* @param playerName
* @return Players primary group
*/
public String getPrimaryGroup(String world, String playerName);
}
abstract public String getPrimaryGroup(String world, String playerName);
public String getPrimaryGroup(World world, String playerName) {
return getPrimaryGroup(world.getName(), playerName);
}
public String getPrimaryGroup(Player player) {
return getPrimaryGroup(player.getWorld().getName(), player.getName());
}
abstract public String getPlayerPrefix(String world, String playerName);
public String getPlayerPrefix(World world, String playerName) {
return getPlayerPrefix(world.getName(), playerName);
}
public String getPlayerPrefix(Player player) {
return getPlayerPrefix(player.getWorld().getName(), player.getName());
}
abstract public String getPlayerSuffix(String world, String playerName);
public String getPlayerSuffix(World world, String playerName) {
return getPlayerSuffix(world.getName(), playerName);
}
public String getPlayerSuffix(Player player) {
return getPlayerSuffix(player.getWorld().getName(), player.getName());
}
}

View File

@ -35,7 +35,7 @@ import org.bukkit.plugin.PluginManager;
import com.nijiko.permissions.Group;
import com.nijikokun.bukkit.Permissions.Permissions;
public class Permission_Permissions implements Permission {
public class Permission_Permissions extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "Permissions (Yetti)";
@ -74,16 +74,6 @@ public class Permission_Permissions implements Permission {
}
}
@Override
public boolean has(Player player, String permission) {
return playerHas(player, permission);
}
@Override
public boolean playerHas(Player player, String permission) {
return this.permission.getHandler().has(player, permission);
}
@Override
public boolean playerInGroup(String worldName, String playerName, String groupName) {
return this.permission.getHandler().inGroup(worldName, playerName, groupName);
@ -347,4 +337,19 @@ public class Permission_Permissions implements Permission {
public String getPrimaryGroup(String world, String playerName) {
return this.permission.getHandler().getPrimaryGroup(world, playerName);
}
@Override
public boolean playerHas(String worldName, String playerName, String permission) {
return this.permission.getHandler().has(worldName, playerName, permission);
}
@Override
public String getPlayerPrefix(String world, String playerName) {
return this.permission.getHandler().getUserPrefix(world, playerName);
}
@Override
public String getPlayerSuffix(String world, String playerName) {
return this.permission.getHandler().getUserSuffix(world, playerName);
}
}

View File

@ -32,12 +32,11 @@ import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import ru.tehkode.permissions.PermissionGroup;
import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx;
public class Permission_PermissionsEx implements Permission {
public class Permission_PermissionsEx extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "PermissionsEx";
@ -360,4 +359,34 @@ public class Permission_PermissionsEx implements Permission {
else
return null;
}
}
@Override
public boolean playerHas(String worldName, String playerName, String permission) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
return user.has(permission, worldName);
} else {
return false;
}
}
@Override
public String getPlayerPrefix(String world, String playerName) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
return user.getPrefix();
} else {
return null;
}
}
@Override
public String getPlayerSuffix(String world, String playerName) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
return user.getSuffix();
} else {
return null;
}
}
}