Merge pull request #381 from Sebc722/master

Update for Xperms v2.0
This commit is contained in:
Nick Minkler 2013-03-19 07:03:27 -07:00
commit 343fa70880

View File

@ -19,7 +19,7 @@ import java.util.ArrayList;
import net.milkbowl.vault.permission.Permission;
import com.github.sebc722.Xperms.Xmain;
import com.github.sebc722.xperms.core.Main;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
@ -32,154 +32,148 @@ import org.bukkit.plugin.Plugin;
public class Permission_Xperms extends Permission {
private final String name = "Xperms";
private Xmain perms = null;
private Main permission = null;
public Permission_Xperms(Plugin plugin) {
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
if(perms == null){
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Xperms");
if(perms != null){
if(perms.isEnabled()){
try{
if(Double.valueOf(perms.getDescription().getVersion()) < 1.1){
log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", plugin.getDescription().getName(), name));
}
} catch(NumberFormatException e){
// version is first release, numbered 1.0.0
log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", plugin.getDescription().getName(), name));
}
}
perms = (Xmain) perms;
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin)
if(permission == null){
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Xperms");
if(perms != null){
if(perms.isEnabled()){
try{
if(Double.valueOf(perms.getDescription().getVersion()) < 1.1){
log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", plugin.getDescription().getName(), name));
}
} catch(NumberFormatException e){
// version is first release, numbered 1.0.0
log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", plugin.getDescription().getName(), name);
}
}
permission = (Main) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
}
}
public class PermissionServerListener implements Listener {
Permission_Xperms permission = null;
public PermissionServerListener(Permission_Xperms permission) {
this.permission = permission;
}
Main permission = null;
public PermissionServerListener(Permission_Xperms permission){
this.permission = permission;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (event.getPlugin().getDescription().getName().equals("Xperms")) {
Plugin perms = event.getPlugin();
try {
if(Double.valueOf(perms.getDescription().getVersion()) < 1.1){
log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", plugin.getDescription().getName(), name));
}
} catch(NumberFormatException e){
// version is first release, numbered 1.0.0
log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", plugin.getDescription().getName(), name));
}
permission.perms = (Xmain) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(), plugin)
if(permission == null){
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Xperms");
if(perms != null){
try{
if(Double.valueOf(perms.getDescription().getVersion()) < 1.1){
log.info(String.format("[%s] [Permission] %s Current version is not compatible with vault! Please Update!", plugin.getDescription().getName(), name));
}
} catch(NumberFormatException e){
// version is first release, numbered 1.0.0
log.info(String.format("[%s] [Permission] %s Current version is not compatibe with vault! Please Update!", plugin.getDescription().getName(), name);
}
permission.permission = (Main) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if(permission.perms != null){
if(event.getPlugin().getName().equals("Xperms")){
permission.perms = null;
if(permission.permission != null){
if(event.getPlugin().getName().equals("Xperms")){
permission.permission = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
}
}
@Override
public String getName() {
return name;
return name;
}
@Override
public boolean isEnabled() {
return perms.isEnabled();
return permission.isEnabled();
}
@Override
public boolean hasSuperPermsCompat() {
return true;
return true;
}
@Override
public boolean playerHas(String world, String player, String permission) {
return perms.getXplayer().hasPermission(player, permission);
return permission.getXplayer().hasPerm(world, player, permission);
}
@Override
public boolean playerAdd(String world, String player, String permission) {
return perms.getXplayer().addPermission(player, permission);
return permission.getXplayer().addNode(world, player, permission);
}
@Override
public boolean playerRemove(String world, String player, String permission) {
return perms.getXplayer().removePermission(player, permission);
return permission.getXplayer().removeNode(world, player, permission);
}
@Override
public boolean groupHas(String world, String group, String permission) {
return perms.getXgroup().hasPermission(group, permission);
return permission.getXgroup().hasPerm(group, permission);
}
@Override
public boolean groupAdd(String world, String group, String permission) {
return perms.getXgroup().addPermission(group, permission);
permission.getXgroup().addNode(group, permission);
return true;
}
@Override
public boolean groupRemove(String world, String group, String permission) {
return perms.getXgroup().removePermission(group, permission);
return permission.getXgroup().removeNode(group, permission)
}
@Override
public boolean playerInGroup(String world, String player, String group) {
String userGroup = perms.getXusers().getUserGroup(player);
if(userGroup == group){
return true;
}
else{
return false;
}
String groupForWorld = permission.getXplayer().getGroupForWorld(player, world);
if(groupForWorld.equals(group)){
return true;
}
return false;
}
@Override
public boolean playerAddGroup(String world, String player, String group) {
return perms.getXplayer().setGroup(player, group);
return permission.getXplayer().setPlayerGroup(world, player, group);
}
@Override
public boolean playerRemoveGroup(String world, String player, String group) {
return perms.getXplayer().setGroup(player, "def");
return permission.getXplayer().setPlayerDefault(world, player);
}
@Override
public String[] getPlayerGroups(String world, String player) {
ArrayList<String> playerGroup = new ArrayList<String>();
playerGroup.add(perms.getXusers().getUserGroup(player));
String[] playerGroupArray = playerGroup.toArray(new String[0]);
return playerGroupArray;
return permission.getXplayer().getPlayerGroups(player);
}
@Override
public String getPrimaryGroup(String world, String player) {
return perms.getXusers().getUserGroup(player);
return permission.getXplayer().getGroupForWorld(player, world);
}
@Override
public String[] getGroups() {
return perms.getXperms().getGroups();
}
@Override
public boolean hasGroupSupport() {
return true;
return permission.getXgroup().getGroups();
}
}