From ce144a4e0c44e7f0a81efe7127c3a24581d97162 Mon Sep 17 00:00:00 2001 From: HmmmQuestionMark Date: Fri, 21 Dec 2012 00:08:54 -0500 Subject: [PATCH] Added multigroup support with PEX. --- src/net/TheDgtl/iChat/VariableHandler.java | 76 ++++++++++++++-------- src/net/TheDgtl/iChat/iChatAPI.java | 20 ++++-- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/src/net/TheDgtl/iChat/VariableHandler.java b/src/net/TheDgtl/iChat/VariableHandler.java index 1a24560..491dd97 100644 --- a/src/net/TheDgtl/iChat/VariableHandler.java +++ b/src/net/TheDgtl/iChat/VariableHandler.java @@ -115,36 +115,60 @@ public void loadConfig() { public void addPlayer(Player player) { HashMap tmpList = new HashMap(); - String group = ichat.API.getGroup(player); - String world = player.getWorld().getName().toLowerCase(); - - // Check if the world the player is in has variables - HashMap wVars = worldVars.get(world); - if (wVars != null && !wVars.isEmpty()) { - tmpList.putAll(wVars); - } - - if (group != null && !group.isEmpty()) { - // Add the players cached group to the group list - playerGroups.put(player.getName().toLowerCase(), group); - - group = group.toLowerCase(); - HashMap gVars = groupVars.get(group); - if (gVars != null) - tmpList.putAll(gVars); - - // Check if this group has world-specific vars - HashMap> worlds = wGroupVars.get(world); - if (worlds != null) { - HashMap wgVars = worlds.get(group); - if (wgVars != null) - tmpList.putAll(wgVars); + if (ichat.pexPlug == null) { + String group = ichat.API.getGroup(player); + String world = player.getWorld().getName().toLowerCase(); + if (group != null && !group.isEmpty()) { + // Add the players cached group to the group list + playerGroups.put(player.getName().toLowerCase(), group); + + group = group.toLowerCase(); + HashMap gVars = groupVars.get(group); + if (gVars != null) + tmpList.putAll(gVars); + + // Check if this group has world-specific vars + HashMap> worlds = wGroupVars.get(world); + if (worlds != null) { + HashMap wgVars = worlds.get(group); + if (wgVars != null) + tmpList.putAll(wgVars); + } + } else { + // Remove players cached group + playerGroups.remove(player.getName().toLowerCase()); } } else { - // Remove players cached group - playerGroups.remove(player.getName().toLowerCase()); + String[] group = ichat.API.getPexGroup(player); + String world = player.getWorld().getName().toLowerCase(); + + for (String g : group) + { + if (g != null && !g.isEmpty()) { + // Add the players cached group to the group list + playerGroups.put(player.getName().toLowerCase(), g); + + g = g.toLowerCase(); + HashMap gVars = groupVars.get(g); + if (gVars != null) + tmpList.putAll(gVars); + + // Check if this group has world-specific vars + HashMap> worlds = wGroupVars.get(world); + if (worlds != null) { + HashMap wgVars = worlds.get(g); + if (wgVars != null) + tmpList.putAll(wgVars); + } + } else { + // Remove players cached group + playerGroups.remove(player.getName().toLowerCase()); + } + } } + String world = player.getWorld().getName().toLowerCase(); + HashMap uVars = userVars.get(player.getName().toLowerCase()); if (uVars != null) tmpList.putAll(uVars); diff --git a/src/net/TheDgtl/iChat/iChatAPI.java b/src/net/TheDgtl/iChat/iChatAPI.java index a4e7b10..b6a3550 100644 --- a/src/net/TheDgtl/iChat/iChatAPI.java +++ b/src/net/TheDgtl/iChat/iChatAPI.java @@ -158,9 +158,6 @@ public String getRawInfo(Player player, String info) { if (ichat.pbPlug != null) { return getPermBGroup(player); } - if (ichat.pexPlug != null) { - return getPexGroup(player); - } if (ichat.gMan != null) { return getGManGroup(player); } @@ -271,12 +268,21 @@ private String getPermBGroup(Player player) { return groups.get(0).getName(); } - private String getPexGroup(Player player) { + String[] getPexGroup(Player player) { PermissionUser user = PermissionsEx.getUser(player); - if (user == null) return ""; + if (user == null) return null; PermissionGroup[] groups = user.getGroups(player.getWorld().getName()); - if (groups.length == 0) return ""; - return groups[0].getName(); + if (groups.length == 0) return null; + + int count = 0; + String[] playerGroup = new String[groups.length]; + for (PermissionGroup g : groups) + { + playerGroup[count] = ChatColor.translateAlternateColorCodes('&', g.getName()); + count++; + } + + return playerGroup; } private String getGManGroup(Player player) {