Commit b281f67a authored by Giant's avatar Giant
Browse files

Add prefix support to permission engines.

parent 3ec40ad4
......@@ -151,6 +151,51 @@ public class bpEngine implements Permission {
return this.getGroups(p.getName());
}
@Override
public void setPrefix(Player p, String prefix) {
this.setPrefix(p.getName(), prefix, p.getWorld().getName());
}
@Override
public void setPrefix(String p, String prefix, String world) {
plugin.getLogger().log(Level.WARNING, "bPermissions does not support player prefixes!");
}
@Override
public void setPrefix(Player p, String prefix, String world) {
this.setPrefix(p.getName(), prefix, world);
}
@Override
public String getPrefix(Player p) {
return this.getPrefix(p.getName(), p.getWorld().getName());
}
@Override
public String getPrefix(String p, String world) {
return "";
}
@Override
public String getPrefix(Player p, String world) {
return this.getPrefix(p.getName(), world);
}
@Override
public String getGroupPrefix(Player p) {
return this.getGroupPrefix(p, p.getWorld().getName());
}
@Override
public String getGroupPrefix(Player p, String world) {
return this.getGroupPrefix(p.getName(), this.getGroup(p), world);
}
@Override
public String getGroupPrefix(String p, String g, String world) {
return "";
}
@Override
public boolean isEnabled() {
return permission;
......
......@@ -18,65 +18,73 @@ import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import java.util.logging.Level;
import org.anjocaido.groupmanager.data.User;
public class gmEngine implements Permission {
private GiantCore plugin;
private GroupManager permission;
private Boolean opHasPerms;
public gmEngine(GiantCore plugin, Boolean opHasPerms) {
this.plugin = plugin;
this.opHasPerms = opHasPerms;
Plugin perms = plugin.getServer().getPluginManager().getPlugin("GroupManager");
if (perms != null && perms.isEnabled()) {
permission = (GroupManager) perms;
if(perms != null && perms.isEnabled()) {
permission = (GroupManager)perms;
plugin.getLogger().log(Level.INFO, "Successfully hooked into GroupManager");
}else{
//It's not enabled yet, let's set up a listener!
plugin.getServer().getPluginManager().registerEvents(new PluginListener(), plugin);
}
}else{
//It's not enabled yet, let's set up a listener!
plugin.getServer().getPluginManager().registerEvents(new PluginListener(), plugin);
}
}
@Override
public boolean has(String p, String perm) {
Player player = plugin.getServer().getPlayer(p);
if(player != null)
if(player != null) {
return this.has(player, perm);
}
return false;
}
@Override
public boolean has(Player p, String perm) {
if(opHasPerms && p.isOp())
if(opHasPerms && p.isOp()) {
return true;
}
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissionsByPlayerName(p.getName());
if(h != null)
if(h != null) {
return h.has(p, perm);
}
return false;
}
@Override
public boolean has(String p, String perm, String world) {
Player player = plugin.getServer().getPlayer(p);
if(player != null)
if(player != null) {
return this.has(player, perm, world);
}
return false;
}
@Override
public boolean has(Player p, String perm, String world) {
if(opHasPerms && p.isOp())
if(opHasPerms && p.isOp()) {
return true;
}
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissions(world);
if(h != null)
if(h != null) {
return h.has(p, perm);
}
return false;
}
......@@ -85,31 +93,34 @@ public class gmEngine implements Permission {
OverloadedWorldHolder h = permission.getWorldsHolder().getDefaultWorld();
if(h != null) {
Group g = h.getGroup(group);
if(g != null)
if(g != null) {
g.hasSamePermissionNode(perm);
}
}
return false;
}
@Override
public boolean groupHasPerm(String group, String perm, String world) {
OverloadedWorldHolder h = permission.getWorldsHolder().getWorldData(world);
if(h != null) {
Group g = h.getGroup(group);
if(g != null)
if(g != null) {
g.hasSamePermissionNode(perm);
}
}
return false;
}
@Override
public boolean inGroup(String p, String group) {
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissionsByPlayerName(p);
if(h != null)
if(h != null) {
return h.inGroup(p, group);
}
return false;
}
......@@ -121,9 +132,10 @@ public class gmEngine implements Permission {
@Override
public boolean inGroup(String p, String group, String world) {
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissions(p);
if(h != null)
if(h != null) {
return h.inGroup(p, group);
}
return false;
}
......@@ -135,9 +147,10 @@ public class gmEngine implements Permission {
@Override
public String getGroup(String p) {
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissionsByPlayerName(p);
if(h != null)
if(h != null) {
return h.getGroup(p);
}
return null;
}
......@@ -149,9 +162,10 @@ public class gmEngine implements Permission {
@Override
public String getGroup(String p, String world) {
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissions(world);
if(h != null)
if(h != null) {
return h.getGroup(p);
}
return null;
}
......@@ -163,9 +177,10 @@ public class gmEngine implements Permission {
@Override
public String[] getGroups(String p) {
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissionsByPlayerName(p);
if(h != null)
if(h != null) {
return h.getGroups(p);
}
return null;
}
......@@ -177,9 +192,10 @@ public class gmEngine implements Permission {
@Override
public String[] getGroups(String p, String world) {
AnjoPermissionsHandler h = permission.getWorldsHolder().getWorldPermissions(world);
if(h != null)
if(h != null) {
return h.getGroups(p);
}
return null;
}
......@@ -187,27 +203,110 @@ public class gmEngine implements Permission {
public String[] getGroups(Player p, String world) {
return this.getGroups(p.getName(), world);
}
@Override
public void setPrefix(Player p, String prefix) {
this.setPrefix(p.getName(), prefix, p.getWorld().getName());
}
@Override
public void setPrefix(String p, String prefix, String world) {
OverloadedWorldHolder owh;
if(world == null) {
owh = permission.getWorldsHolder().getWorldDataByPlayerName(world);
}else{
owh = permission.getWorldsHolder().getWorldData(world);
}
if(owh == null) {
return;
}
User user = owh.getUser(p);
if(user == null) {
return;
}
user.getVariables().addVar("prefix", prefix);
}
@Override
public void setPrefix(Player p, String prefix, String world) {
this.setPrefix(p.getName(), prefix, world);
}
@Override
public String getPrefix(Player p) {
return this.getPrefix(p.getName(), p.getWorld().getName());
}
@Override
public String getPrefix(String p, String world) {
AnjoPermissionsHandler h;
if(world == null) {
h = permission.getWorldsHolder().getWorldPermissionsByPlayerName(p);
}else{
h = permission.getWorldsHolder().getWorldPermissions(world);
}
if(h == null) {
return "";
}
return h.getUserPrefix(p);
}
@Override
public String getPrefix(Player p, String world) {
return this.getPrefix(p.getName(), world);
}
@Override
public String getGroupPrefix(Player p) {
return this.getGroupPrefix(p, p.getWorld().getName());
}
@Override
public String getGroupPrefix(Player p, String world) {
return this.getGroupPrefix(p.getName(), this.getGroup(p), world);
}
@Override
public String getGroupPrefix(String p, String g, String world) {
AnjoPermissionsHandler h;
if(world == null) {
h = permission.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
}else{
h = permission.getWorldsHolder().getWorldPermissions(world);
}
if(h == null) {
return "";
}
return h.getGroupPrefix(g);
}
@Override
public boolean isEnabled() {
return permission.isEnabled();
}
private class PluginListener implements Listener {
public PluginListener() {}
public PluginListener() {
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPluginEnable(PluginEnableEvent event) {
if(permission == null) {
Plugin p = event.getPlugin();
if(p instanceof GroupManager) {
permission = (GroupManager) p;
permission = (GroupManager)p;
plugin.getLogger().log(Level.INFO, "Successfully hooked into GroupManager");
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPluginDisable(PluginDisableEvent event) {
if(permission != null) {
......
......@@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
import java.util.logging.Level;
public class npEngine implements Permission {
private GiantCore plugin;
......@@ -128,6 +129,59 @@ public class npEngine implements Permission {
return this.getGroups(p.getName(), world);
}
@Override
public void setPrefix(Player p, String prefix) {
this.setPrefix(p, prefix, p.getWorld().getName());
}
@Override
public void setPrefix(String p, String prefix, String world) {
Player pl = plugin.getServer().getPlayer(p);
if(pl != null) {
this.setPrefix(pl, prefix, world);
}
}
@Override
public void setPrefix(Player p, String prefix, String world) {
p.setDisplayName(prefix + p.getName());
}
@Override
public String getPrefix(Player p) {
return p.getDisplayName().substring(0, p.getDisplayName().length() - p.getName().length());
}
@Override
public String getPrefix(String p, String world) {
Player pl = plugin.getServer().getPlayer(p);
if(pl != null) {
return this.getPrefix(pl, world);
}
return "";
}
@Override
public String getPrefix(Player p, String world) {
return this.getPrefix(p.getName(), world);
}
@Override
public String getGroupPrefix(Player p) {
return this.getGroupPrefix(p, p.getWorld().getName());
}
@Override
public String getGroupPrefix(Player p, String world) {
return this.getGroupPrefix(p.getName(), this.getGroup(p), world);
}
@Override
public String getGroupPrefix(String p, String g, String world) {
return "";
}
@Override
public boolean isEnabled() {
return true;
......
......@@ -72,7 +72,7 @@ public class pexEngine implements Permission {
@Override
public boolean groupHasPerm(String group, String perm) {
PermissionGroup g = permission.getPermissionManager().getGroup(group);
PermissionGroup g = PermissionsEx.getPermissionManager().getGroup(group);
if(g != null)
return g.has(perm);
......@@ -81,7 +81,7 @@ public class pexEngine implements Permission {
@Override
public boolean groupHasPerm(String group, String perm, String world) {
PermissionGroup g = permission.getPermissionManager().getGroup(group);
PermissionGroup g = PermissionsEx.getPermissionManager().getGroup(group);
if(g != null)
return g.has(perm, world);
......@@ -90,7 +90,7 @@ public class pexEngine implements Permission {
@Override
public boolean inGroup(String p, String group) {
return permission.getPermissionManager().getUser(p).inGroup(group);
return PermissionsEx.getPermissionManager().getUser(p).inGroup(group);
}
@Override
......@@ -100,7 +100,7 @@ public class pexEngine implements Permission {
@Override
public boolean inGroup(String p, String group, String world) {
return permission.getPermissionManager().getUser(p).inGroup(group, world);
return PermissionsEx.getPermissionManager().getUser(p).inGroup(group, world);
}
@Override
......@@ -110,7 +110,7 @@ public class pexEngine implements Permission {
@Override
public String getGroup(String p) {
String[] groups = permission.getPermissionManager().getUser(p).getGroupsNames();
String[] groups = PermissionsEx.getPermissionManager().getUser(p).getGroupsNames();
if(groups.length > 0)
return groups[0];
......@@ -124,7 +124,7 @@ public class pexEngine implements Permission {
@Override
public String getGroup(String p, String world) {
String[] groups = permission.getPermissionManager().getUser(p).getGroupsNames(world);
String[] groups = PermissionsEx.getPermissionManager().getUser(p).getGroupsNames(world);
if(groups.length > 0)
return groups[0];
......@@ -138,7 +138,7 @@ public class pexEngine implements Permission {
@Override
public String[] getGroups(String p) {
return permission.getPermissionManager().getUser(p).getGroupsNames();
return PermissionsEx.getPermissionManager().getUser(p).getGroupsNames();
}
@Override
......@@ -148,7 +148,7 @@ public class pexEngine implements Permission {
@Override
public String[] getGroups(String p, String world) {
return permission.getPermissionManager().getUser(p).getGroupsNames(world);
return PermissionsEx.getPermissionManager().getUser(p).getGroupsNames(world);
}
@Override
......@@ -156,6 +156,51 @@ public class pexEngine implements Permission {
return this.getGroups(p.getName(), world);
}
@Override
public void setPrefix(Player p, String prefix) {
this.setPrefix(p.getName(), prefix, p.getWorld().getName());
}
@Override
public void setPrefix(String p, String prefix, String world) {
PermissionsEx.getPermissionManager().getUser(p).setPrefix(prefix, world);
}
@Override
public void setPrefix(Player p, String prefix, String world) {
this.setPrefix(p.getName(), prefix, world);
}
@Override
public String getPrefix(Player p) {
return this.getPrefix(p.getName(), p.getWorld().getName());
}
@Override
public String getPrefix(String p, String world) {
return PermissionsEx.getPermissionManager().getUser(p).getPrefix(world);
}
@Override
public String getPrefix(Player p, String world) {
return this.getPrefix(p.getName(), world);
}
@Override
public String getGroupPrefix(Player p) {
return this.getGroupPrefix(p, p.getWorld().getName());
}
@Override
public String getGroupPrefix(Player p, String world) {
return this.getGroupPrefix(p.getName(), this.getGroup(p), world);
}
@Override
public String getGroupPrefix(String p, String g, String world) {
return PermissionsEx.getPermissionManager().getGroup(g).getPrefix(world);
}
@Override
public boolean isEnabled() {
return permission.isEnabled();
......
......@@ -11,46 +11,50 @@ public class spermEngine implements Permission {
private GiantCore plugin;
private Boolean opHasPerms;
public spermEngine(GiantCore plugin, Boolean opHasPerms) {
this.plugin = plugin;
this.opHasPerms = opHasPerms;
plugin.getLogger().log(Level.INFO, "Now using Bukkit SuperPerms!");
plugin.getLogger().log(Level.WARNING, "Superperms does not support groups!");
}
@Override
public boolean has(String p, String perm) {
Player player = plugin.getServer().getPlayer(p);
if(player != null)
if(player != null) {
return this.has(player, perm);
}
return false;