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