Allow setting prefix/suffix in GM

Use GM info interfaces
Standardize formatting
This commit is contained in:
KHobbits 2012-02-09 12:41:37 +00:00
parent 56444b162d
commit 1e8c1e3a22

View File

@ -19,316 +19,293 @@ import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
public class Chat_GroupManager extends Chat {
private static final Logger log = Logger.getLogger("Minecraft");
private final String name = "GroupManager - Chat";
private Plugin plugin = null;
private GroupManager groupManager;
private static final Logger log = Logger.getLogger("Minecraft");
private final String name = "GroupManager - Chat";
private Plugin plugin = null;
private GroupManager groupManager;
public Chat_GroupManager(Plugin plugin, Permission permissions) {
super(permissions);
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
public Chat_GroupManager(Plugin plugin, Permission permissions) {
super(permissions);
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
// Load Plugin in case it was loaded before
if (groupManager == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("GroupManager");
if (perms != null) {
if (perms.isEnabled()) {
groupManager = (GroupManager) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
}
public class PermissionServerListener implements Listener {
Chat_GroupManager chat = null;
public PermissionServerListener(Chat_GroupManager chat) {
this.chat = chat;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (chat.groupManager == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("GroupManager");
if (perms != null) {
if (perms.isEnabled()) {
chat.groupManager = (GroupManager) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), chat.name));
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if (chat.groupManager != null) {
if (event.getPlugin().getDescription().getName().equals("GroupManager")) {
chat.groupManager = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), chat.name));
}
}
}
}
@Override
public String getName() {
return this.name;
}
@Override
public boolean isEnabled() {
if (groupManager == null) {
return false;
} else {
return groupManager.isEnabled();
}
}
@Override
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
// Load Plugin in case it was loaded before
if (groupManager == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("GroupManager");
if (perms != null) {
if (perms.isEnabled()) {
groupManager = (GroupManager) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
if (owh == null) {
return defaultValue;
}
User user = owh.getUser(playerName);
if (user == null) {
return defaultValue;
}
Integer val = user.getVariables().getVarInteger(node);
return val != null ? val : defaultValue;
}
}
@Override
public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
setPlayerValue(world, playerName, node, value);
}
public class PermissionServerListener implements Listener {
@Override
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getDefaultWorld();
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
}
if (owh == null) {
return defaultValue;
}
Group group = owh.getGroup(groupName);
if (group == null) {
return defaultValue;
}
Integer val = group.getVariables().getVarInteger(node);
return val != null ? val : defaultValue;
}
Chat_GroupManager chat = null;
@Override
public void setGroupInfoInteger(String world, String groupName, String node, int value) {
setGroupValue(world, groupName, node, value);
}
public PermissionServerListener(Chat_GroupManager chat) {
this.chat = chat;
}
@Override
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
}
if (owh == null) {
return defaultValue;
}
User user = owh.getUser(playerName);
if (user == null) {
return defaultValue;
}
Double val = user.getVariables().getVarDouble(node);
return val != null ? val : defaultValue;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (chat.groupManager == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("GroupManager");
@Override
public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
setPlayerValue(world, playerName, node, value);
}
if (perms != null) {
if (perms.isEnabled()) {
chat.groupManager = (GroupManager) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), chat.name));
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if (chat.groupManager != null) {
if (event.getPlugin().getDescription().getName().equals("GroupManager")) {
chat.groupManager = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), chat.name));
}
}
}
}
@Override
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getDefaultWorld();
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
}
if (owh == null) {
return defaultValue;
}
Group group = owh.getGroup(groupName);
if (group == null) {
return defaultValue;
}
Double val = group.getVariables().getVarDouble(node);
return val != null ? val : defaultValue;
}
@Override
public void setGroupInfoDouble(String world, String groupName, String node, double value) {
setGroupValue(world, groupName, node, value);
}
@Override
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
}
if (owh == null) {
return defaultValue;
}
User user = owh.getUser(playerName);
if (user == null) {
return defaultValue;
}
Boolean val = user.getVariables().getVarBoolean(node);
return val != null ? val : defaultValue;
}
@Override
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
setPlayerValue(world, playerName, node, value);
}
@Override
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getDefaultWorld();
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
}
if (owh == null) {
return defaultValue;
}
Group group = owh.getGroup(groupName);
if (group == null) {
return defaultValue;
}
Boolean val = group.getVariables().getVarBoolean(node);
return val != null ? val : defaultValue;
}
@Override
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
setGroupValue(world, groupName, node, value);
}
@Override
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
}
if (owh == null) {
return defaultValue;
}
User user = owh.getUser(playerName);
if (user == null) {
return defaultValue;
}
String val = user.getVariables().getVarString(node);
return val != null ? val : defaultValue;
}
@Override
public void setPlayerInfoString(String world, String playerName, String node, String value) {
setPlayerValue(world, playerName, node, value);
}
@Override
public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
OverloadedWorldHolder owh;
if (world == null) {
owh = groupManager.getWorldsHolder().getDefaultWorld();
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
}
if (owh == null) {
return defaultValue;
}
Group group = owh.getGroup(groupName);
if (group == null) {
return defaultValue;
}
String val = group.getVariables().getVarString(node);
return val != null ? val : defaultValue;
}
@Override
public void setGroupInfoString(String world, String groupName, String node, String value) {
setGroupValue(world, groupName, node, value);
}
@Override
public String getPlayerPrefix(String world, String playerName) {
return getPlayerInfoString(world, playerName, "prefix", "");
}
@Override
public String getPlayerSuffix(String world, String playerName) {
return getPlayerInfoString(world, playerName, "suffix", "");
}
@Override
public void setPlayerSuffix(String world, String player, String suffix) {
throw new UnsupportedOperationException(getName() + " cannot modify permissions.");
}
@Override
public void setPlayerPrefix(String world, String player, String prefix) {
throw new UnsupportedOperationException(getName() + " cannot modify permissions.");
}
@Override
public String getGroupPrefix(String world, String group) {
return perms.getGroupPrefix(group);
}
@Override
public void setGroupPrefix(String world, String group, String prefix) {
throw new UnsupportedOperationException(getName() + " cannot modify permissions.");
}
@Override
public String getGroupSuffix(String world, String group) {
return perms.getGroupSuffix(group);
}
@Override
public void setGroupSuffix(String world, String group, String suffix) {
throw new UnsupportedOperationException(getName() + " cannot modify permissions.");
}
public String getPrimaryGroup(String world, String playerName) {
return perms.getGroup(playerName);
public String getName() {
return this.name;
}
private void setPlayerValue(String world, String playerName, String node, Object value) {
@Override
public boolean isEnabled() {
if (groupManager == null) {
return false;
} else {
return groupManager.isEnabled();
}
}
@Override
public int getPlayerInfoInteger(String worldName, String playerName, String node, int defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
Integer val = handler.getUserPermissionInteger(playerName, node);
return val != null ? val : defaultValue;
}
@Override
public void setPlayerInfoInteger(String worldName, String playerName, String node, int value) {
setPlayerValue(worldName, playerName, node, value);
}
@Override
public int getGroupInfoInteger(String worldName, String groupName, String node, int defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
Integer val = handler.getGroupPermissionInteger(groupName, node);
return val != null ? val : defaultValue;
}
@Override
public void setGroupInfoInteger(String worldName, String groupName, String node, int value) {
setGroupValue(worldName, groupName, node, value);
}
@Override
public double getPlayerInfoDouble(String worldName, String playerName, String node, double defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
Double val = handler.getUserPermissionDouble(playerName, node);
return val != null ? val : defaultValue;
}
@Override
public void setPlayerInfoDouble(String worldName, String playerName, String node, double value) {
setPlayerValue(worldName, playerName, node, value);
}
@Override
public double getGroupInfoDouble(String worldName, String groupName, String node, double defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
Double val = handler.getGroupPermissionDouble(groupName, node);
return val != null ? val : defaultValue;
}
@Override
public void setGroupInfoDouble(String worldName, String groupName, String node, double value) {
setGroupValue(worldName, groupName, node, value);
}
@Override
public boolean getPlayerInfoBoolean(String worldName, String playerName, String node, boolean defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
Boolean val = handler.getUserPermissionBoolean(playerName, node);
return val != null ? val : defaultValue;
}
@Override
public void setPlayerInfoBoolean(String worldName, String playerName, String node, boolean value) {
setPlayerValue(worldName, playerName, node, value);
}
@Override
public boolean getGroupInfoBoolean(String worldName, String groupName, String node, boolean defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
Boolean val = handler.getGroupPermissionBoolean(groupName, node);
return val != null ? val : defaultValue;
}
@Override
public void setGroupInfoBoolean(String worldName, String groupName, String node, boolean value) {
setGroupValue(worldName, groupName, node, value);
}
@Override
public String getPlayerInfoString(String worldName, String playerName, String node, String defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
String val = handler.getUserPermissionString(playerName, node);
return val != null ? val : defaultValue;
}
@Override
public void setPlayerInfoString(String worldName, String playerName, String node, String value) {
setPlayerValue(worldName, playerName, node, value);
}
@Override
public String getGroupInfoString(String worldName, String groupName, String node, String defaultValue) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getDefaultWorld().getPermissionsHandler();
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
if (handler == null) {
return defaultValue;
}
String val = handler.getGroupPermissionString(groupName, node);
return val != null ? val : defaultValue;
}
@Override
public void setGroupInfoString(String worldName, String groupName, String node, String value) {
setGroupValue(worldName, groupName, node, value);
}
@Override
public String getPlayerPrefix(String worldName, String playerName) {
return getPlayerInfoString(worldName, playerName, "prefix", "");
}
@Override
public String getPlayerSuffix(String worldName, String playerName) {
return getPlayerInfoString(worldName, playerName, "suffix", "");
}
@Override
public void setPlayerSuffix(String worldName, String player, String suffix) {
setPlayerInfoString(worldName, player, "suffix", suffix);
}
@Override
public void setPlayerPrefix(String worldName, String player, String prefix) {
setPlayerInfoString(worldName, player, "prefix", prefix);
}
@Override
public String getGroupPrefix(String worldName, String group) {
return getGroupInfoString(worldName, group, "prefix", "");
}
@Override
public void setGroupPrefix(String worldName, String group, String prefix) {
setGroupInfoString(worldName, group, "prefix", prefix);
}
@Override
public String getGroupSuffix(String worldName, String group) {
return getGroupInfoString(worldName, group, "suffix", "");
}
@Override
public void setGroupSuffix(String worldName, String group, String suffix) {
setGroupInfoString(worldName, group, "suffix", suffix);
}
@Override
public String getPrimaryGroup(String worldName, String playerName) {
AnjoPermissionsHandler handler;
if (worldName == null) {
handler = groupManager.getWorldsHolder().getWorldPermissionsByPlayerName(playerName);
} else {
handler = groupManager.getWorldsHolder().getWorldPermissions(worldName);
}
return handler.getGroup(playerName);
}
private void setPlayerValue(String worldName, String playerName, String node, Object value) {
OverloadedWorldHolder owh;
if (world == null) {
if (worldName == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) {
return;
@ -339,13 +316,13 @@ public class Chat_GroupManager extends Chat {
}
user.getVariables().addVar(node, value);
}
private void setGroupValue(String world, String groupName, String node, Object value) {
private void setGroupValue(String worldName, String groupName, String node, Object value) {
OverloadedWorldHolder owh;
if (world == null) {
if (worldName == null) {
owh = groupManager.getWorldsHolder().getDefaultWorld();
} else {
owh = groupManager.getWorldsHolder().getWorldData(world);
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) {
return;