summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager/src/org/anjocaido
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido')
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java65
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java2
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java118
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java50
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java106
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java538
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java332
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEvent.java22
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java8
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java64
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java123
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java2
12 files changed, 803 insertions, 627 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
index 2d46e74c8..8134a1c23 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
@@ -161,7 +161,7 @@ public class GroupManager extends JavaPlugin {
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
// Register as a service
- this.getServer().getServicesManager().register(AnjoPermissionsHandler.class, this.permissionHandler, this, ServicePriority.Normal);
+ this.getServer().getServicesManager().register(AnjoPermissionsHandler.class, this.permissionHandler, this, ServicePriority.Lowest);
}
public static boolean isLoaded() {
@@ -415,7 +415,7 @@ public class GroupManager extends JavaPlugin {
// PARECE OK
auxUser.setGroup(auxGroup);
- if (!sender.hasPermission("groupmanager.notify.other"))
+ if (!sender.hasPermission("groupmanager.notify.other") || (isConsole))
sender.sendMessage(ChatColor.YELLOW + "You changed player '" + auxUser.getName() + "' group to '" + auxGroup.getName() + "'.");
targetPlayer = this.getServer().getPlayer(auxUser.getName());
@@ -787,29 +787,29 @@ public class GroupManager extends JavaPlugin {
}
targetPlayer = this.getServer().getPlayer(auxUser.getName());
// VALIDANDO PERMISSAO
- permissionResult = permissionHandler.checkFullUserPermission(auxUser, args[1]);
+ permissionResult = permissionHandler.checkFullGMPermission(auxUser, args[1], false);
+
if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
+ //No permissions found in GM so fall through and check Bukkit.
sender.sendMessage(ChatColor.RED + "The player doesn't have access to that permission");
- sender.sendMessage(ChatColor.YELLOW + "SuperPerms reports Node: " + targetPlayer.hasPermission(args[1]));
- return false;
- }
- // PARECE OK
- // auxString =
- // permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
- if (permissionResult.owner instanceof User) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- sender.sendMessage(ChatColor.RED + "The user has directly a negation node for that permission.");
- } else {
- sender.sendMessage(ChatColor.YELLOW + "The user has directly this permission.");
- }
- sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
- } else if (permissionResult.owner instanceof Group) {
- if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
- sender.sendMessage(ChatColor.RED + "The user inherits the a negation permission from group: " + permissionResult.owner.getName());
- } else {
- sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName());
+
+ } else {
+ // This permission was found in groupmanager.
+ if (permissionResult.owner instanceof User) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ sender.sendMessage(ChatColor.RED + "The user has directly a negation node for that permission.");
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "The user has directly this permission.");
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
+ } else if (permissionResult.owner instanceof Group) {
+ if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
+ sender.sendMessage(ChatColor.RED + "The user inherits a negation permission from group: " + permissionResult.owner.getName());
+ } else {
+ sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName());
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
}
- sender.sendMessage(ChatColor.YELLOW + "Permission Node: " + permissionResult.accessLevel);
}
// superperms
@@ -948,7 +948,7 @@ public class GroupManager extends JavaPlugin {
}
} else {
- sender.sendMessage(ChatColor.YELLOW + "The grpup '" + auxGroup.getName() + "' has no specific permissions.");
+ sender.sendMessage(ChatColor.YELLOW + "The group '" + auxGroup.getName() + "' has no specific permissions.");
auxString = "";
for (String grp : auxGroup.getInherits()) {
auxString += grp + ", ";
@@ -1504,7 +1504,9 @@ public class GroupManager extends JavaPlugin {
isLoaded = false; // Disable Bukkit Perms update
+ globalGroups.load();
worldsHolder.loadWorld(auxString);
+
sender.sendMessage("The request to world '" + auxString + "' was sent.");
isLoaded = true;
@@ -1520,7 +1522,8 @@ public class GroupManager extends JavaPlugin {
}
// WORKING
config.load();
-
+ worldsHolder.mirrorSetUp();
+
isLoaded = false;
if (args.length > 0) {
@@ -1537,7 +1540,6 @@ public class GroupManager extends JavaPlugin {
worldsHolder.reloadAll();
sender.sendMessage(ChatColor.YELLOW + " The current world was reloaded.");
}
- worldsHolder.mirrorSetUp();
isLoaded = true;
@@ -1610,7 +1612,7 @@ public class GroupManager extends JavaPlugin {
}
// PARECE OK
auxUser.setGroup(auxGroup);
- if (!sender.hasPermission("groupmanager.notify.other"))
+ if (!sender.hasPermission("groupmanager.notify.other") || (isConsole))
sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
targetPlayer = this.getServer().getPlayer(auxUser.getName());
@@ -1666,7 +1668,7 @@ public class GroupManager extends JavaPlugin {
}
// PARECE OK
auxUser.setGroup(auxGroup);
- if (!sender.hasPermission("groupmanager.notify.other"))
+ if (!sender.hasPermission("groupmanager.notify.other") || (isConsole))
sender.sendMessage(ChatColor.YELLOW + "You changed " + auxUser.getName() + " group to " + auxGroup.getName() + ".");
targetPlayer = this.getServer().getPlayer(auxUser.getName());
@@ -1837,15 +1839,6 @@ public class GroupManager extends JavaPlugin {
return match;
}
-
- /**
- * Triggers all GroupManager events for other plugins to see.
- *
- * @param event
- */
- public static void callEvent(GroupManagerEvent event) {
- Bukkit.getServer().getPluginManager().callEvent(event);
- }
/**
* @return the config
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java
index f4b805c35..8788fc83b 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java
@@ -18,7 +18,7 @@ public class BukkitPermsUpdateTask implements Runnable {
public void run() {
// Signal loaded and update BukkitPermissions.
GroupManager.setLoaded(true);
- GroupManager.BukkitPermissions.collectPermissions();
+ //GroupManager.BukkitPermissions.collectPermissions();
GroupManager.BukkitPermissions.updateAllPlayers();
GroupManager.logger.info("Bukkit Permissions Updated!");
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java
new file mode 100644
index 000000000..4fc819245
--- /dev/null
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java
@@ -0,0 +1,118 @@
+package org.anjocaido.groupmanager.dataholder;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.anjocaido.groupmanager.data.Group;
+
+
+
+/**
+ * @author ElgarL
+ *
+ */
+public class GroupsDataHolder {
+
+ /**
+ * Root World name this set of groups is associated with.
+ */
+ private String name;
+ private Group defaultGroup = null;
+ private File groupsFile;
+ private boolean haveGroupsChanged = false;
+ private long timeStampGroups = 0;
+
+ /**
+ * The actual groups holder
+ */
+ private Map<String, Group> groups = new HashMap<String, Group>();
+
+ /**
+ * Constructor
+ */
+ protected GroupsDataHolder() {
+ }
+
+ protected void setWorldName(String worldName) {
+ name = worldName;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getWorldName() {
+ return name;
+ }
+
+ /**
+ * @return the defaultGroup
+ */
+ public Group getDefaultGroup() {
+ return defaultGroup;
+ }
+
+ /**
+ * @param defaultGroup the defaultGroup to set
+ */
+ public void setDefaultGroup(Group defaultGroup) {
+ this.defaultGroup = defaultGroup;
+ }
+
+ /**
+ * @return the groups
+ */
+ public Map<String, Group> getGroups() {
+ return groups;
+ }
+
+ /**
+ * @param groups the groups to set
+ */
+ public void setGroups(Map<String, Group> groups) {
+ this.groups = groups;
+ }
+
+ /**
+ * @return the groupsFile
+ */
+ public File getGroupsFile() {
+ return groupsFile;
+ }
+
+ /**
+ * @param groupsFile the groupsFile to set
+ */
+ public void setGroupsFile(File groupsFile) {
+ this.groupsFile = groupsFile;
+ }
+
+ /**
+ * @return the haveGroupsChanged
+ */
+ public boolean HaveGroupsChanged() {
+ return haveGroupsChanged;
+ }
+
+ /**
+ * @param haveGroupsChanged the haveGroupsChanged to set
+ */
+ public void setGroupsChanged(boolean haveGroupsChanged) {
+ this.haveGroupsChanged = haveGroupsChanged;
+ }
+
+ /**
+ * @return the timeStampGroups
+ */
+ public long getTimeStampGroups() {
+ return timeStampGroups;
+ }
+
+ /**
+ * @param timeStampGroups the timeStampGroups to set
+ */
+ public void setTimeStampGroups(long timeStampGroups) {
+ this.timeStampGroups = timeStampGroups;
+ }
+
+} \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
index 8e2df5d10..b37c55e51 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
@@ -25,13 +25,11 @@ public class OverloadedWorldHolder extends WorldDataHolder {
*
* @param ph
*/
- @SuppressWarnings("deprecation")
public OverloadedWorldHolder(WorldDataHolder ph) {
super(ph.getName());
- this.f = ph.f;
- this.groupsFile = ph.groupsFile;
- this.usersFile = ph.usersFile;
- this.defaultGroup = ph.defaultGroup;
+ this.setGroupsFile(ph.getGroupsFile());
+ this.setUsersFile(ph.getUsersFile());
+ //this.setDefaultGroup(ph.getDefaultGroup());
this.groups = ph.groups;
this.users = ph.users;
}
@@ -49,11 +47,11 @@ public class OverloadedWorldHolder extends WorldDataHolder {
return overloadedUsers.get(userNameLowered);
}
//END CODE
- if (users.containsKey(userNameLowered)) {
- return users.get(userNameLowered);
+ if (getUsers().containsKey(userNameLowered)) {
+ return getUsers().get(userNameLowered);
}
User newUser = createUser(userName);
- haveUsersChanged = true;
+ setUsersChanged(true);
return newUser;
}
@@ -69,8 +67,8 @@ public class OverloadedWorldHolder extends WorldDataHolder {
if (theUser == null) {
return;
}
- if ((theUser.getGroup() == null) || (!groups.containsKey(theUser.getGroupName().toLowerCase()))) {
- theUser.setGroup(defaultGroup);
+ if ((theUser.getGroup() == null) || (!getGroups().containsKey(theUser.getGroupName().toLowerCase()))) {
+ theUser.setGroup(getDefaultGroup());
}
//OVERLOADED CODE
if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) {
@@ -80,8 +78,8 @@ public class OverloadedWorldHolder extends WorldDataHolder {
}
//END CODE
removeUser(theUser.getName());
- users.put(theUser.getName().toLowerCase(), theUser);
- haveUsersChanged = true;
+ getUsers().put(theUser.getName().toLowerCase(), theUser);
+ setUsersChanged(true);
}
/**
@@ -97,9 +95,9 @@ public class OverloadedWorldHolder extends WorldDataHolder {
return true;
}
//END CODE
- if (users.containsKey(userName.toLowerCase())) {
- users.remove(userName.toLowerCase());
- haveUsersChanged = true;
+ if (getUsers().containsKey(userName.toLowerCase())) {
+ getUsers().remove(userName.toLowerCase());
+ setUsersChanged(true);
return true;
}
return false;
@@ -107,16 +105,16 @@ public class OverloadedWorldHolder extends WorldDataHolder {
@Override
public boolean removeGroup(String groupName) {
- if (groupName.equals(defaultGroup)) {
+ if (groupName.equals(getDefaultGroup())) {
return false;
}
- for (String key : groups.keySet()) {
+ for (String key : getGroups().keySet()) {
if (groupName.equalsIgnoreCase(key)) {
- groups.remove(key);
- for (String userKey : users.keySet()) {
- User user = users.get(userKey);
+ getGroups().remove(key);
+ for (String userKey : getUsers().keySet()) {
+ User user = getUsers().get(userKey);
if (user.getGroupName().equalsIgnoreCase(key)) {
- user.setGroup(defaultGroup);
+ user.setGroup(getDefaultGroup());
}
}
@@ -124,12 +122,12 @@ public class OverloadedWorldHolder extends WorldDataHolder {
for (String userKey : overloadedUsers.keySet()) {
User user = overloadedUsers.get(userKey);
if (user.getGroupName().equalsIgnoreCase(key)) {
- user.setGroup(defaultGroup);
+ user.setGroup(getDefaultGroup());
}
}
//END OVERLOAD
- haveGroupsChanged = true;
+ setGroupsChanged(true);
return true;
}
}
@@ -143,7 +141,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
@Override
public Collection<User> getUserList() {
Collection<User> overloadedList = new ArrayList<User>();
- Collection<User> normalList = users.values();
+ Collection<User> normalList = getUsers().values();
for (User u : normalList) {
if (overloadedUsers.containsKey(u.getName().toLowerCase())) {
overloadedList.add(overloadedUsers.get(u.getName().toLowerCase()));
@@ -198,8 +196,8 @@ public class OverloadedWorldHolder extends WorldDataHolder {
if (!isOverloaded(userName)) {
return getUser(userName);
}
- if (users.containsKey(userName.toLowerCase())) {
- return users.get(userName.toLowerCase());
+ if (getUsers().containsKey(userName.toLowerCase())) {
+ return getUsers().get(userName.toLowerCase());
}
User newUser = createUser(userName);
return newUser;
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java
new file mode 100644
index 000000000..37e1c4b43
--- /dev/null
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java
@@ -0,0 +1,106 @@
+package org.anjocaido.groupmanager.dataholder;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.anjocaido.groupmanager.data.User;
+
+
+
+/**
+ * @author ElgarL
+ *
+ */
+public class UsersDataHolder {
+
+ /**
+ * Root World name this set of groups is associated with.
+ */
+ private String name;
+ private File usersFile;
+ private boolean haveUsersChanged = false;
+ private long timeStampUsers = 0;
+
+ /**
+ * The actual groups holder
+ */
+ private Map<String, User> users = new HashMap<String, User>();
+
+ /**
+ * Constructor
+ */
+ protected UsersDataHolder() {
+ }
+
+ /**
+ * @param worldName
+ */
+ public void setWorldName(String worldName) {
+ this.name = worldName;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getWorldName() {
+ return this.name;
+ }
+
+ /**
+ * @return the users
+ */
+ public Map<String, User> getUsers() {
+ return users;
+ }
+
+ /**
+ * @param users the users to set
+ */
+ public void setUsers(Map<String, User> users) {
+ this.users = users;
+ }
+
+ /**
+ * @return the usersFile
+ */
+ public File getUsersFile() {
+ return usersFile;
+ }
+
+ /**
+ * @param usersFile the usersFile to set
+ */
+ public void setUsersFile(File usersFile) {
+ this.usersFile = usersFile;
+ }
+
+ /**
+ * @return the haveUsersChanged
+ */
+ public boolean HaveUsersChanged() {
+ return haveUsersChanged;
+ }
+
+ /**
+ * @param haveUsersChanged the haveUsersChanged to set
+ */
+ public void setUsersChanged(boolean haveUsersChanged) {
+ this.haveUsersChanged = haveUsersChanged;
+ }
+
+ /**
+ * @return the timeStampUsers
+ */
+ public long getTimeStampUsers() {
+ return timeStampUsers;
+ }
+
+ /**
+ * @param timeStampUsers the timeStampUsers to set
+ */
+ public void setTimeStampUsers(long timeStampUsers) {
+ this.timeStampUsers = timeStampUsers;
+ }
+
+} \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
index 2a944856b..c9c1d2b64 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
@@ -8,7 +8,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
@@ -49,72 +48,37 @@ public class WorldDataHolder {
/**
* The actual groups holder
*/
- protected Map<String, Group> groups = new HashMap<String, Group>();
+ protected GroupsDataHolder groups = new GroupsDataHolder();
/**
* The actual users holder
*/
- protected Map<String, User> users = new HashMap<String, User>();
-
- /**
- * Points to the default group
- */
- protected Group defaultGroup = null;
-
- /**
- * The file, which this class loads/save data from/to
- * @deprecated
- */
- @Deprecated
- protected File f;
-
+ protected UsersDataHolder users = new UsersDataHolder();
/**
*
*/
protected AnjoPermissionsHandler permissionsHandler;
- /**
- *
- */
- protected File usersFile;
- /**
- *
- */
- protected File groupsFile;
- /**
- *
- */
- protected boolean haveUsersChanged = false;
- /**
- *
- */
- protected boolean haveGroupsChanged = false;
- /**
- *
- */
- protected long timeStampGroups = 0;
- /**
- *
- */
- protected long timeStampUsers = 0;
/**
* Prevent direct instantiation
* @param worldName
*/
- protected WorldDataHolder(String worldName) {
+ public WorldDataHolder(String worldName) {
name = worldName;
}
/**
* The main constructor for a new WorldDataHolder
- * Please don't set the default group as null
* @param worldName
- * @param defaultGroup the default group. its good to start with one
+ * @param groups
+ * @param users
*/
- public WorldDataHolder(String worldName, Group defaultGroup) {
+ public WorldDataHolder(String worldName, GroupsDataHolder groups, UsersDataHolder users) {
this.name = worldName;
- groups.put(defaultGroup.getName().toLowerCase(), defaultGroup);
- this.defaultGroup = defaultGroup;
+ this.groups = groups;
+ this.users = users;
+
+ //this.defaultGroup = defaultGroup;
}
/**
@@ -125,8 +89,8 @@ public class WorldDataHolder {
* @return class that manage that user permission
*/
public User getUser(String userName) {
- if (users.containsKey(userName.toLowerCase())) {
- return users.get(userName.toLowerCase());
+ if (getUsers().containsKey(userName.toLowerCase())) {
+ return getUsers().get(userName.toLowerCase());
}
User newUser = createUser(userName);
return newUser;
@@ -144,11 +108,11 @@ public class WorldDataHolder {
return;
}
if ((theUser.getGroup() == null)) {
- theUser.setGroup(defaultGroup);
+ theUser.setGroup(groups.getDefaultGroup());
}
removeUser(theUser.getName());
- users.put(theUser.getName().toLowerCase(), theUser);
- haveUsersChanged = true;
+ getUsers().put(theUser.getName().toLowerCase(), theUser);
+ setUsersChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(theUser, Action.USER_ADDED);
}
@@ -159,9 +123,9 @@ public class WorldDataHolder {
* @return true if it had something to remove
*/
public boolean removeUser(String userName) {
- if (users.containsKey(userName.toLowerCase())) {
- users.remove(userName.toLowerCase());
- haveUsersChanged = true;
+ if (getUsers().containsKey(userName.toLowerCase())) {
+ getUsers().remove(userName.toLowerCase());
+ setUsersChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(userName, GMUserEvent.Action.USER_REMOVED);
return true;
@@ -175,7 +139,7 @@ public class WorldDataHolder {
* @return true if we have data for this player.
*/
public boolean isUserDeclared(String userName) {
- return users.containsKey(userName.toLowerCase());
+ return getUsers().containsKey(userName.toLowerCase());
}
/**
@@ -183,11 +147,11 @@ public class WorldDataHolder {
* @param group the group you want make default.
*/
public void setDefaultGroup(Group group) {
- if (!groups.containsKey(group.getName().toLowerCase()) || (group.getDataSource() != this)) {
+ if (!getGroups().containsKey(group.getName().toLowerCase()) || (group.getDataSource() != this)) {
addGroup(group);
}
- defaultGroup = this.getGroup(group.getName());
- haveGroupsChanged = true;
+ groups.setDefaultGroup(getGroup(group.getName()));
+ setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.DEFAULT_GROUP_CHANGED);
}
@@ -197,7 +161,7 @@ public class WorldDataHolder {
* @return the default group
*/
public Group getDefaultGroup() {
- return defaultGroup;
+ return groups.getDefaultGroup();
}
/**
@@ -209,7 +173,7 @@ public class WorldDataHolder {
if (groupName.toLowerCase().startsWith("g:"))
return GroupManager.getGlobalGroups().getGroup(groupName);
else
- return groups.get(groupName.toLowerCase());
+ return getGroups().get(groupName.toLowerCase());
}
/**
@@ -222,7 +186,7 @@ public class WorldDataHolder {
if (groupName.toLowerCase().startsWith("g:"))
return GroupManager.getGlobalGroups().hasGroup(groupName);
else
- return groups.containsKey(groupName.toLowerCase());
+ return getGroups().containsKey(groupName.toLowerCase());
}
/**
@@ -240,8 +204,8 @@ public class WorldDataHolder {
groupToAdd = groupToAdd.clone(this);
}
removeGroup(groupToAdd.getName());
- groups.put(groupToAdd.getName().toLowerCase(), groupToAdd);
- haveGroupsChanged = true;
+ getGroups().put(groupToAdd.getName().toLowerCase(), groupToAdd);
+ setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
}
@@ -256,12 +220,12 @@ public class WorldDataHolder {
return GroupManager.getGlobalGroups().removeGroup(groupName);
}
- if (defaultGroup != null && groupName.equalsIgnoreCase(defaultGroup.getName())) {
+ if (getDefaultGroup() != null && groupName.equalsIgnoreCase(getDefaultGroup().getName())) {
return false;
}
- if (groups.containsKey(groupName.toLowerCase())) {
- groups.remove(groupName.toLowerCase());
- haveGroupsChanged = true;
+ if (getGroups().containsKey(groupName.toLowerCase())) {
+ getGroups().remove(groupName.toLowerCase());
+ setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
return true;
@@ -277,13 +241,13 @@ public class WorldDataHolder {
* @return null if user already exists. or new User
*/
public User createUser(String userName) {
- if (this.users.containsKey(userName.toLowerCase())) {
+ if (getUsers().containsKey(userName.toLowerCase())) {
return null;
}
User newUser = new User(this, userName);
- newUser.setGroup(defaultGroup);
- this.addUser(newUser);
- haveUsersChanged = true;
+ newUser.setGroup(groups.getDefaultGroup());
+ addUser(newUser);
+ setUsersChanged(true);
return newUser;
}
@@ -299,13 +263,13 @@ public class WorldDataHolder {
return GroupManager.getGlobalGroups().newGroup(newGroup);
}
- if (this.groups.containsKey(groupName.toLowerCase())) {
+ if (getGroups().containsKey(groupName.toLowerCase())) {
return null;
}
Group newGroup = new Group(this, groupName);
- this.addGroup(newGroup);
- haveGroupsChanged = true;
+ addGroup(newGroup);
+ setGroupsChanged(true);
return newGroup;
}
@@ -314,7 +278,7 @@ public class WorldDataHolder {
* @return a collection of the groups
*/
public Collection<Group> getGroupList() {
- return groups.values();
+ return getGroups().values();
}
/**
@@ -322,7 +286,7 @@ public class WorldDataHolder {
* @return a collection of the users
*/
public Collection<User> getUserList() {
- return users.values();
+ return getUsers().values();
}
/**
@@ -352,9 +316,9 @@ public class WorldDataHolder {
for (Group tempGroup : ph.getGroupList()) {
tempGroup.clone(this);
}
- this.setDefaultGroup(this.getGroup(ph.getDefaultGroup().getName()));
+ this.setDefaultGroup(getGroup(ph.getDefaultGroup().getName()));
this.removeGroupsChangedFlag();
- this.timeStampGroups = getGroupsFile().lastModified();
+ this.setTimeStampGroups(getGroupsFile().lastModified());
ph = null;
} catch (Exception ex) {
@@ -377,7 +341,7 @@ public class WorldDataHolder {
tempGroup.clone(ph);
}
// setup the default group before loading user data.
- ph.setDefaultGroup(ph.getGroup(this.getDefaultGroup().getName()));
+ ph.setDefaultGroup(ph.getGroup(getDefaultGroup().getName()));
loadUsers(ph, getUsersFile());
// transfer new data
resetUsers();
@@ -385,7 +349,7 @@ public class WorldDataHolder {
tempUser.clone(this);
}
this.removeUsersChangedFlag();
- this.timeStampUsers = getUsersFile().lastModified();
+ this.setTimeStampUsers(getUsersFile().lastModified());
ph = null;
} catch (Exception ex) {
@@ -395,165 +359,39 @@ public class WorldDataHolder {
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED);
}
- /**
- * Save by yourself!
- * @deprecated
- */
- @Deprecated
- public void commit() {
- writeGroups(this, getGroupsFile());
- writeUsers(this, getUsersFile());
- }
-
- /**
- * Returns a data holder for the given file
- *
- * @param worldName
- * @param file
- * @return a new WorldDataHolder
- *
- * @throws Exception
- * @deprecated
- */
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Deprecated
- public static WorldDataHolder load(String worldName, File file) throws Exception {
- WorldDataHolder ph = new WorldDataHolder(worldName);
- ph.f = file;
- final Yaml yaml = new Yaml(new SafeConstructor());
- Map<String, Object> rootDataNode;
- if (!file.exists()) {
- throw new Exception("The file which should contain permissions does not exist!\n" + file.getPath());
- }
- FileInputStream rx = new FileInputStream(file);
- try {
- rootDataNode = (Map<String, Object>) yaml.load(new UnicodeReader(rx));
- if (rootDataNode == null) {
- throw new NullPointerException();
- }
- } catch (Exception ex) {
- throw new Exception("The following file couldn't pass on Parser.\n" + file.getPath(), ex);
- } finally {
- rx.close();
- }
- Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
- try {
- Map<String, Object> allGroupsNode = (Map<String, Object>) rootDataNode.get("groups");
- for (String groupKey : allGroupsNode.keySet()) {
- Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
- Group thisGrp = ph.createGroup(groupKey);
- if (thisGrp == null) {
- throw new IllegalArgumentException("I think this group was declared more than once: " + groupKey);
- }
- if (thisGroupNode.get("default") == null) {
- thisGroupNode.put("default", false);
- }
- if ((Boolean.parseBoolean(thisGroupNode.get("default").toString()))) {
- if (ph.getDefaultGroup() != null) {
- GroupManager.logger.warning("The group " + thisGrp.getName() + " is declaring be default where" + ph.getDefaultGroup().getName() + " already was.");
- GroupManager.logger.warning("Overriding first request.");
- }
- ph.setDefaultGroup(thisGrp);
- }
-
- //PERMISSIONS NODE
- if (thisGroupNode.get("permissions") == null) {
- thisGroupNode.put("permissions", new ArrayList<String>());
- }
- if (thisGroupNode.get("permissions") instanceof List) {
- for (Object o : ((List) thisGroupNode.get("permissions"))) {
- thisGrp.addPermission(o.toString());
- }
- } else if (thisGroupNode.get("permissions") instanceof String) {
- thisGrp.addPermission((String) thisGroupNode.get("permissions"));
- } else {
- throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>): " + thisGroupNode.get("permissions").getClass().getName());
- }
-
- //INFO NODE
- Map<String, Object> infoNode = (Map<String, Object>) thisGroupNode.get("info");
- if (infoNode != null) {
- thisGrp.setVariables(infoNode);
- }
-
- //END INFO NODE
-
- Object inheritNode = thisGroupNode.get("inheritance");
- if (inheritNode == null) {
- thisGroupNode.put("inheritance", new ArrayList<String>());
- } else if (inheritNode instanceof List) {
- List<String> groupsInh = (List<String>) inheritNode;
- for (String grp : groupsInh) {
- if (inheritance.get(groupKey) == null) {
- List<String> thisInherits = new ArrayList<String>();
- inheritance.put(groupKey, thisInherits);
- }
- inheritance.get(groupKey).add(grp);
-
- }
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new Exception("Your Permissions config file is invalid. See console for details.");
- }
- if (ph.defaultGroup == null) {
- throw new IllegalArgumentException("There was no Default Group declared.");
- }
- for (String groupKey : inheritance.keySet()) {
- List<String> inheritedList = inheritance.get(groupKey);
- Group thisGroup = ph.getGroup(groupKey);
- for (String inheritedKey : inheritedList) {
- Group inheritedGroup = ph.getGroup(inheritedKey);
- if (thisGroup != null && inheritedGroup != null) {
- thisGroup.addInherits(inheritedGroup);
- }
- }
- }
- // Process USERS
- Map<String, Object> allUsersNode = (Map<String, Object>) rootDataNode.get("users");
- for (String usersKey : allUsersNode.keySet()) {
- Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
- User thisUser = ph.createUser(usersKey);
- if (thisUser == null) {
- GroupManager.logger.warning("I think this user was declared more than once: " + usersKey);
- continue;
- }
- if (thisUserNode.get("permissions") == null) {
- thisUserNode.put("permissions", new ArrayList<String>());
- }
- if (thisUserNode.get("permissions") instanceof List) {
- for (Object o : ((List) thisUserNode.get("permissions"))) {
- thisUser.addPermission(o.toString());
- }
- } else if (thisUserNode.get("permissions") instanceof String) {
- thisUser.addPermission(thisUserNode.get("permissions").toString());
- }
+ public void loadGroups(File groupsFile) {
+ GroupManager.setLoaded(false);
+ try {
+ setGroupsFile(groupsFile);
+ loadGroups(this, groupsFile);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ throw new IllegalArgumentException("The file which should contain groups does not exist!\n" + groupsFile.getPath());
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new IllegalArgumentException("Error access the groups file!\n" + groupsFile.getPath());
+ }
- //USER INFO NODE - BETA
+ GroupManager.setLoaded(true);
+ }
+
+ public void loadUsers(File usersFile) {
- //INFO NODE
- Map<String, Object> infoNode = (Map<String, Object>) thisUserNode.get("info");
- if (infoNode != null) {
- thisUser.setVariables(infoNode);
- }
- //END INFO NODE - BETA
+ GroupManager.setLoaded(false);
+ try {
+ setUsersFile(usersFile);
+ loadUsers(this, usersFile);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ throw new IllegalArgumentException("The file which should contain users does not exist!\n" + usersFile.getPath());
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new IllegalArgumentException("Error access the users file!\n" + usersFile.getPath());
+ }
- if (thisUserNode.get("group") != null) {
- Group hisGroup = ph.getGroup(thisUserNode.get("group").toString());
- if (hisGroup == null) {
- GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName());
- thisUser.setGroup(ph.defaultGroup);
- }
- thisUser.setGroup(hisGroup);
- } else {
- thisUser.setGroup(ph.defaultGroup);
- }
- }
- return ph;
+ GroupManager.setLoaded(true);
}
-
/**
* Returns a NEW data holder containing data read from the files
*
@@ -568,8 +406,8 @@ public class WorldDataHolder {
WorldDataHolder ph = new WorldDataHolder(worldName);
GroupManager.setLoaded(false);
- loadGroups(ph, groupsFile);
- loadUsers(ph, usersFile);
+ if (groupsFile != null) loadGroups(ph, groupsFile);
+ if (usersFile != null) loadUsers(ph, usersFile);
GroupManager.setLoaded(true);
return ph;
@@ -632,7 +470,12 @@ public class WorldDataHolder {
}
if (thisGroupNode.get("permissions") instanceof List) {
for (Object o : ((List) thisGroupNode.get("permissions"))) {
- thisGrp.addPermission(o.toString());
+ try {
+ thisGrp.addPermission(o.toString());
+ } catch (NullPointerException e) {
+ // Ignore this entry as it's null.
+ //throw new IllegalArgumentException("Invalid permission node in group: " + thisGrp.getName() + " in file: " + groupsFile.getPath());
+ }
}
} else if (thisGroupNode.get("permissions") instanceof String) {
thisGrp.addPermission((String) thisGroupNode.get("permissions"));
@@ -673,7 +516,7 @@ public class WorldDataHolder {
// ex.printStackTrace();
// throw new IllegalArgumentException("Your Permissions config file is invalid. See console for details.");
//}
- if (ph.defaultGroup == null) {
+ if (ph.getDefaultGroup() == null) {
throw new IllegalArgumentException("There was no Default Group declared in file: " + groupsFile.getPath());
}
for (String groupKey : inheritance.keySet()) {
@@ -689,7 +532,7 @@ public class WorldDataHolder {
ph.removeGroupsChangedFlag();
// Update the LastModified time.
- ph.groupsFile = groupsFile;
+ ph.setGroupsFile(groupsFile);
ph.setTimeStampGroups(groupsFile.lastModified());
//return ph;
@@ -744,7 +587,12 @@ public class WorldDataHolder {
thisUser.addPermission(o.toString());
}
} else if (thisUserNode.get("permissions") instanceof String) {
- thisUser.addPermission(thisUserNode.get("permissions").toString());
+ try {
+ thisUser.addPermission(thisUserNode.get("permissions").toString());
+ } catch (NullPointerException e) {
+ // Ignore this entry as it's null.
+ //throw new IllegalArgumentException("Invalid permission node for user: " + thisUser.getName() + " in file: " + UserFile.getPath());
+ }
}
//SUBGROUPS LOADING
@@ -788,111 +636,24 @@ public class WorldDataHolder {
Group hisGroup = ph.getGroup(thisUserNode.get("group").toString());
if (hisGroup == null) {
GroupManager.logger.warning("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName() + ": Set to '" + ph.getDefaultGroup().getName() + "' for file: " + usersFile.getPath());
- hisGroup = ph.defaultGroup;
+ hisGroup = ph.getDefaultGroup();
//throw new IllegalArgumentException("There is no group " + thisUserNode.get("group").toString() + ", as stated for player " + thisUser.getName());
}
thisUser.setGroup(hisGroup);
} else {
- thisUser.setGroup(ph.defaultGroup);
+ thisUser.setGroup(ph.getDefaultGroup());
}
}
ph.removeUsersChangedFlag();
// Update the LastModified time.
- ph.usersFile = usersFile;
+ ph.setUsersFile(usersFile);
ph.setTimeStampUsers(usersFile.lastModified());
}
/**
* Write a dataHolder in a specified file
* @param ph
- * @param file
- * @deprecated
- */
- @Deprecated
- public static void write(WorldDataHolder ph, File file) {
- Map<String, Object> root = new HashMap<String, Object>();
-
- Map<String, Object> pluginMap = new HashMap<String, Object>();
- root.put("plugin", pluginMap);
-
- Map<String, Object> permissionsMap = new HashMap<String, Object>();
- pluginMap.put("permissions", permissionsMap);
-
- permissionsMap.put("system", "default");
-
- Map<String, Object> groupsMap = new HashMap<String, Object>();
- root.put("groups", groupsMap);
- for (String groupKey : ph.groups.keySet()) {
- Group group = ph.groups.get(groupKey);
-
- Map<String, Object> aGroupMap = new HashMap<String, Object>();
- groupsMap.put(group.getName(), aGroupMap);
-
- aGroupMap.put("default", group.equals(ph.defaultGroup));
-
- Map<String, Object> infoMap = new HashMap<String, Object>();
- aGroupMap.put("info", infoMap);
-
- for (String infoKey : group.getVariables().getVarKeyList()) {
- infoMap.put(infoKey, group.getVariables().getVarObject(infoKey));
- }
-
- aGroupMap.put("inheritance", group.getInherits());
-
- aGroupMap.put("permissions", group.getPermissionList());
- }
-
- Map<String, Object> usersMap = new HashMap<String, Object>();
- root.put("users", usersMap);
- for (String userKey : ph.users.keySet()) {
- User user = ph.users.get(userKey);
- if ((user.getGroup() == null || user.getGroup().equals(ph.defaultGroup)) && user.getPermissionList().isEmpty()) {
- continue;
- }
-
- Map<String, Object> aUserMap = new HashMap<String, Object>();
- usersMap.put(user.getName(), aUserMap);
-
- if (user.getGroup() == null) {
- aUserMap.put("group", ph.defaultGroup.getName());
- } else {
- aUserMap.put("group", user.getGroup().getName());
- }
- //USER INFO NODE - BETA
- if (user.getVariables().getSize() > 0) {
- Map<String, Object> infoMap = new HashMap<String, Object>();
- aUserMap.put("info", infoMap);
-
- for (String infoKey : user.getVariables().getVarKeyList()) {
- infoMap.put(infoKey, user.getVariables().getVarObject(infoKey));
- }
- }
- //END USER INFO NODE - BETA
-
- aUserMap.put("permissions", user.getPermissionList());
- }
- DumperOptions opt = new DumperOptions();
- opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- final Yaml yaml = new Yaml(opt);
-
- FileWriter tx = null;
- try {
- tx = new FileWriter(file, false);
- tx.write(yaml.dump(root));
- tx.flush();
- } catch (Exception e) {
- } finally {
- try {
- tx.close();
- } catch (IOException ex) {
- }
- }
- }
-
- /**
- * Write a dataHolder in a specified file
- * @param ph
* @param groupsFile
*/
public static void writeGroups(WorldDataHolder ph, File groupsFile) {
@@ -901,16 +662,16 @@ public class WorldDataHolder {
Map<String, Object> groupsMap = new HashMap<String, Object>();
root.put("groups", groupsMap);
- for (String groupKey : ph.groups.keySet()) {
- Group group = ph.groups.get(groupKey);
+ for (String groupKey : ph.getGroups().keySet()) {
+ Group group = ph.getGroups().get(groupKey);
Map<String, Object> aGroupMap = new HashMap<String, Object>();
groupsMap.put(group.getName(), aGroupMap);
- if (ph.defaultGroup == null) {
+ if (ph.getDefaultGroup() == null) {
GroupManager.logger.severe("There is no default group for world: " + ph.getName());
}
- aGroupMap.put("default", group.equals(ph.defaultGroup));
+ aGroupMap.put("default", group.equals(ph.getDefaultGroup()));
Map<String, Object> infoMap = new HashMap<String, Object>();
aGroupMap.put("info", infoMap);
@@ -951,7 +712,7 @@ public class WorldDataHolder {
}
// Update the LastModified time.
- ph.groupsFile = groupsFile;
+ ph.setGroupsFile(groupsFile);
ph.setTimeStampGroups(groupsFile.lastModified());
ph.removeGroupsChangedFlag();
@@ -982,9 +743,9 @@ public class WorldDataHolder {
Map<String, Object> usersMap = new HashMap<String, Object>();
root.put("users", usersMap);
- for (String userKey : ph.users.keySet()) {
- User user = ph.users.get(userKey);
- if ((user.getGroup() == null || user.getGroup().equals(ph.defaultGroup)) && user.getPermissionList().isEmpty() && user.getVariables().isEmpty() && user.isSubGroupsEmpty()) {
+ for (String userKey : ph.getUsers().keySet()) {
+ User user = ph.getUsers().get(userKey);
+ if ((user.getGroup() == null || user.getGroup().equals(ph.getDefaultGroup())) && user.getPermissionList().isEmpty() && user.getVariables().isEmpty() && user.isSubGroupsEmpty()) {
continue;
}
@@ -992,7 +753,7 @@ public class WorldDataHolder {
usersMap.put(user.getName(), aUserMap);
if (user.getGroup() == null) {
- aUserMap.put("group", ph.defaultGroup.getName());
+ aUserMap.put("group", ph.getDefaultGroup().getName());
} else {
aUserMap.put("group", user.getGroup().getName());
}
@@ -1027,7 +788,7 @@ public class WorldDataHolder {
}
// Update the LastModified time.
- ph.usersFile = usersFile;
+ ph.setUsersFile(usersFile);
ph.setTimeStampUsers(usersFile.lastModified());
ph.removeUsersChangedFlag();
@@ -1083,16 +844,23 @@ public class WorldDataHolder {
}
return permissionsHandler;
}
+
+ /**
+ * @param haveUsersChanged the haveUsersChanged to set
+ */
+ public void setUsersChanged(boolean haveUsersChanged) {
+ users.setUsersChanged(haveUsersChanged);
+ }
/**
*
* @return true if any user data has changed
*/
public boolean haveUsersChanged() {
- if (haveUsersChanged) {
+ if (users.HaveUsersChanged()) {
return true;
}
- for (User u : users.values()) {
+ for (User u : users.getUsers().values()) {
if (u.isChanged()) {
return true;
}
@@ -1101,14 +869,21 @@ public class WorldDataHolder {
}
/**
+ * @param setGroupsChanged the haveGroupsChanged to set
+ */
+ public void setGroupsChanged(boolean setGroupsChanged) {
+ groups.setGroupsChanged(setGroupsChanged);
+ }
+
+ /**
*
* @return true if any group data has changed.
*/
public boolean haveGroupsChanged() {
- if (haveGroupsChanged) {
+ if (groups.HaveGroupsChanged()) {
return true;
}
- for (Group g : groups.values()) {
+ for (Group g : groups.getGroups().values()) {
if (g.isChanged()) {
return true;
}
@@ -1120,8 +895,8 @@ public class WorldDataHolder {
*
*/
public void removeUsersChangedFlag() {
- haveUsersChanged = false;
- for (User u : users.values()) {
+ setUsersChanged(false);
+ for (User u : getUsers().values()) {
u.flagAsSaved();
}
}
@@ -1130,8 +905,8 @@ public class WorldDataHolder {
*
*/
public void removeGroupsChangedFlag() {
- haveGroupsChanged = false;
- for (Group g : groups.values()) {
+ setGroupsChanged(false);
+ for (Group g : getGroups().values()) {
g.flagAsSaved();
}
}
@@ -1140,14 +915,28 @@ public class WorldDataHolder {
* @return the usersFile
*/
public File getUsersFile() {
- return usersFile;
+ return users.getUsersFile();
+ }
+
+ /**
+ * @param file the usersFile to set
+ */
+ public void setUsersFile(File file) {
+ users.setUsersFile(file);
}
/**
* @return the groupsFile
*/
public File getGroupsFile() {
- return groupsFile;
+ return groups.getGroupsFile();
+ }
+
+ /**
+ * @param file the groupsFile to set
+ */
+ public void setGroupsFile(File file) {
+ groups.setGroupsFile(file);
}
/**
@@ -1161,60 +950,85 @@ public class WorldDataHolder {
* Resets Groups.
*/
public void resetGroups() {
- this.defaultGroup = null;
- this.groups = new HashMap<String, Group>();
+ //setDefaultGroup(null);
+ groups.setGroups(new HashMap<String, Group>());
}
/**
* Resets Users
*/
public void resetUsers() {
- this.users = new HashMap<String, User>();
+ users.setUsers(new HashMap<String, User>());
}
/**
* @return the groups
*/
public Map<String, Group> getGroups() {
- return groups;
+ return groups.getGroups();
}
/**
* @return the users
*/
public Map<String, User> getUsers() {
+ return users.getUsers();
+ }
+
+ /**
+ * @return the groups
+ */
+ public GroupsDataHolder getGroupsObject() {
+ return groups;
+ }
+ /**
+ * @param groupsDataHolder the GroupsDataHolder to set
+ */
+ public void setGroupsObject(GroupsDataHolder groupsDataHolder) {
+ groups = groupsDataHolder;
+ }
+ /**
+ * @return the users
+ */
+ public UsersDataHolder getUsersObject() {
return users;
}
+ /**
+ * @param usersDataHolder the UsersDataHolder to set
+ */
+ public void setUsersObject(UsersDataHolder usersDataHolder) {
+ users = usersDataHolder;
+ }
/**
* @return the timeStampGroups
*/
public long getTimeStampGroups() {
- return timeStampGroups;
+ return groups.getTimeStampGroups();
}
/**
* @return the timeStampUsers
*/
public long getTimeStampUsers() {
- return timeStampUsers;
+ return users.getTimeStampUsers();
}
/**
* @param timeStampGroups the timeStampGroups to set
*/
protected void setTimeStampGroups(long timeStampGroups) {
- this.timeStampGroups = timeStampGroups;
+ groups.setTimeStampGroups(timeStampGroups);
}
/**
* @param timeStampUsers the timeStampUsers to set
*/
protected void setTimeStampUsers(long timeStampUsers) {
- this.timeStampUsers = timeStampUsers;
+ users.setTimeStampUsers(timeStampUsers);
}
public void setTimeStamps() {
- if (groupsFile != null)
- setTimeStampGroups(groupsFile.lastModified());
- if (usersFile != null)
- setTimeStampUsers(usersFile.lastModified());
+ if (getGroupsFile() != null)
+ setTimeStampGroups(getGroupsFile().lastModified());
+ if (getUsersFile() != null)
+ setTimeStampUsers(getUsersFile().lastModified());
}
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
index 25eaf8526..1a765c7b4 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
@@ -6,7 +6,6 @@ package org.anjocaido.groupmanager.dataholder.worlds;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -22,6 +21,7 @@ import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.anjocaido.groupmanager.utils.Tasks;
import org.bukkit.World;
+import org.bukkit.configuration.MemorySection;
import org.bukkit.entity.Player;
/**
@@ -34,6 +34,7 @@ public class WorldsHolder {
* Map with instances of loaded worlds.
*/
private Map<String, OverloadedWorldHolder> worldsData = new HashMap<String, OverloadedWorldHolder>();
+
/**
* Map of mirrors: <nonExistingWorldName, existingAndLoadedWorldName>
* The key is the mirror.
@@ -41,7 +42,9 @@ public class WorldsHolder {
*
* Mirror shows the same data of mirrored.
*/
- private Map<String, String> mirrors = new HashMap<String, String>();
+ private Map<String, String> mirrorsGroup = new HashMap<String, String>();
+ private Map<String, String> mirrorsUser = new HashMap<String, String>();
+
private OverloadedWorldHolder defaultWorld;
private String serverDefaultWorldName;
private GroupManager plugin;
@@ -85,7 +88,7 @@ public class WorldsHolder {
*/
for (World world: plugin.getServer().getWorlds())
if ((!worldsData.containsKey(world.getName().toLowerCase()))
- && (!mirrors.containsKey(world.getName().toLowerCase())))
+ && ((!mirrorsGroup.containsKey(world.getName().toLowerCase())) || (!mirrorsUser.containsKey(world.getName().toLowerCase()))))
setupWorldFolder(world.getName());
/*
* Loop over all folders within the worlds folder
@@ -97,10 +100,11 @@ public class WorldsHolder {
/*
* don't load any worlds which are already loaded
- * or mirrored worlds that don't need data.
+ * or fully mirrored worlds that don't need data.
*/
if (!worldsData.containsKey(folder.getName().toLowerCase())
- && !mirrors.containsKey(folder.getName().toLowerCase())) {
+ && ((!mirrorsGroup.containsKey(folder.getName().toLowerCase()))
+ || (!mirrorsUser.containsKey(folder.getName().toLowerCase())))) {
loadWorld(folder.getName());
}
@@ -110,7 +114,8 @@ public class WorldsHolder {
@SuppressWarnings("rawtypes")
public void mirrorSetUp() {
- mirrors.clear();
+ mirrorsGroup.clear();
+ mirrorsUser.clear();
Map<String, Object> mirrorsMap = plugin.getGMConfig().getMirrorsMap();
if (mirrorsMap != null) {
for (String source : mirrorsMap.keySet()) {
@@ -122,16 +127,52 @@ public class WorldsHolder {
if (mirrorsMap.get(source) instanceof ArrayList) {
ArrayList mirrorList = (ArrayList) mirrorsMap.get(source);
+
+ // These worlds fully mirror their parent
for (Object o : mirrorList) {
try {
- mirrors.remove(o.toString().toLowerCase());
+ mirrorsGroup.remove(o.toString().toLowerCase());
+ mirrorsUser.remove(o.toString().toLowerCase());
} catch (Exception e) {
}
- mirrors.put(o.toString().toLowerCase(), getWorldData(source).getName());
+ mirrorsGroup.put(o.toString().toLowerCase(), getWorldData(source).getName());
+ mirrorsUser.put(o.toString().toLowerCase(), getWorldData(source).getName());
}
- } else if (mirrorsMap.get(source) instanceof Object) {
- String aMirror = mirrorsMap.get(source).toString();
- mirrors.put(aMirror.toLowerCase(), getWorldData(source).getName());
+ } else if (mirrorsMap.get(source) instanceof MemorySection) {
+ MemorySection subSection = (MemorySection) mirrorsMap.get(source);
+
+ for (String key : subSection.getKeys(true)) {
+ //System.out.print("Key - " + key);
+
+ if (subSection.get(key) instanceof ArrayList) {
+ ArrayList mirrorList = (ArrayList) subSection.get(key);
+
+ // These worlds have defined mirroring
+ for (Object o : mirrorList) {
+ String type = o.toString().toLowerCase();
+ try {
+ if (type.equals("groups"))
+ mirrorsGroup.remove(key.toLowerCase());
+
+ if (type.equals("users"))
+ mirrorsUser.remove(key.toLowerCase());
+
+ } catch (Exception e) {
+ }
+ if (type.equals("groups"))
+ mirrorsGroup.put(key.toLowerCase(), getWorldData(source).getName());
+
+ if (type.equals("users"))
+ mirrorsUser.put(key.toLowerCase(), getWorldData(source).getName());
+ }
+
+
+
+ } else {
+ throw new IllegalStateException("Unknown mirroring format for " + key);
+ }
+
+ }
}
}
}
@@ -141,16 +182,22 @@ public class WorldsHolder {
*
*/
public void reloadAll() {
+ // Load global groups
+ GroupManager.getGlobalGroups().load();
+
ArrayList<WorldDataHolder> alreadyDone = new ArrayList<WorldDataHolder>();
for (WorldDataHolder w : worldsData.values()) {
if (alreadyDone.contains(w)) {
continue;
}
- w.reload();
+ if (!mirrorsGroup.containsKey(w.getName().toLowerCase()))
+ w.reloadGroups();
+ if (!mirrorsUser.containsKey(w.getName().toLowerCase()))
+ w.reloadUsers();
+
alreadyDone.add(w);
}
- // Load global groups
- GroupManager.getGlobalGroups().load();
+
}
/**
@@ -158,7 +205,10 @@ public class WorldsHolder {
* @param worldName
*/
public void reloadWorld(String worldName) {
- getWorldData(worldName).reload();
+ if (!mirrorsGroup.containsKey(worldName.toLowerCase()))
+ getWorldData(worldName).reloadGroups();
+ if (!mirrorsUser.containsKey(worldName.toLowerCase()))
+ getWorldData(worldName).reloadUsers();
}
/**
@@ -176,6 +226,16 @@ public class WorldsHolder {
ArrayList<WorldDataHolder> alreadyDone = new ArrayList<WorldDataHolder>();
Tasks.removeOldFiles(plugin, plugin.getBackupFolder());
+ // Write Global Groups
+ if (GroupManager.getGlobalGroups().haveGroupsChanged()) {
+ GroupManager.getGlobalGroups().writeGroups(overwrite);
+ } else {
+ if (GroupManager.getGlobalGroups().getTimeStampGroups() < GroupManager.getGlobalGroups().getGlobalGroupsFile().lastModified()) {
+ System.out.print("Newer GlobalGroups file found (Loading changes)!");
+ GroupManager.getGlobalGroups().load();
+ }
+ }
+
for (OverloadedWorldHolder w : worldsData.values()) {
if (alreadyDone.contains(w)) {
continue;
@@ -184,59 +244,52 @@ public class WorldsHolder {
GroupManager.logger.severe("WHAT HAPPENED?");
continue;
}
- if (w.haveGroupsChanged()) {
- if (overwrite || (!overwrite && (w.getTimeStampGroups() >= w.getGroupsFile().lastModified()))) {
- // Backup Groups file
- backupFile(w,true);
-
- WorldDataHolder.writeGroups(w, w.getGroupsFile());
- //w.removeGroupsChangedFlag();
- } else {
- // Newer file found.
- GroupManager.logger.log(Level.WARNING, "Newer Groups file found for " + w.getName() + ", but we have local changes!");
- throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
- }
- } else {
- //Check for newer file as no local changes.
- if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) {
- System.out.print("Newer Groups file found (Loading changes)!");
- // Backup Groups file
- backupFile(w,true);
- w.reloadGroups();
- }
- }
- if (w.haveUsersChanged()) {
- if (overwrite || (!overwrite && (w.getTimeStampUsers() >= w.getUsersFile().lastModified()))) {
- // Backup Users file
- backupFile(w,false);
-
- WorldDataHolder.writeUsers(w, w.getUsersFile());
- //w.removeUsersChangedFlag();
- } else {
- // Newer file found.
- GroupManager.logger.log(Level.WARNING, "Newer Users file found for " + w.getName() + ", but we have local changes!");
- throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
- }
- } else {
- //Check for newer file as no local changes.
- if (w.getTimeStampUsers() < w.getUsersFile().lastModified()) {
- System.out.print("Newer Users file found (Loading changes)!");
- // Backup Users file
- backupFile(w,false);
- w.reloadUsers();
- }
- }
+ if (!mirrorsGroup.containsKey(w.getName().toLowerCase()))
+ if (w.haveGroupsChanged()) {
+ if (overwrite || (!overwrite && (w.getTimeStampGroups() >= w.getGroupsFile().lastModified()))) {
+ // Backup Groups file
+ backupFile(w,true);
+
+ WorldDataHolder.writeGroups(w, w.getGroupsFile());
+ //w.removeGroupsChangedFlag();
+ } else {
+ // Newer file found.
+ GroupManager.logger.log(Level.WARNING, "Newer Groups file found for " + w.getName() + ", but we have local changes!");
+ throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
+ }
+ } else {
+ //Check for newer file as no local changes.
+ if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) {
+ System.out.print("Newer Groups file found (Loading changes)!");
+ // Backup Groups file
+ backupFile(w,true);
+ w.reloadGroups();
+ }
+ }
+ if (!mirrorsUser.containsKey(w.getName().toLowerCase()))
+ if (w.haveUsersChanged()) {
+ if (overwrite || (!overwrite && (w.getTimeStampUsers() >= w.getUsersFile().lastModified()))) {
+ // Backup Users file
+ backupFile(w,false);
+
+ WorldDataHolder.writeUsers(w, w.getUsersFile());
+ //w.removeUsersChangedFlag();
+ } else {
+ // Newer file found.
+ GroupManager.logger.log(Level.WARNING, "Newer Users file found for " + w.getName() + ", but we have local changes!");
+ throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
+ }
+ } else {
+ //Check for newer file as no local changes.
+ if (w.getTimeStampUsers() < w.getUsersFile().lastModified()) {
+ System.out.print("Newer Users file found (Loading changes)!");
+ // Backup Users file
+ backupFile(w,false);
+ w.reloadUsers();
+ }
+ }
alreadyDone.add(w);
}
- // Write Global Groups
- if (GroupManager.getGlobalGroups().haveGroupsChanged()) {
- GroupManager.getGlobalGroups().writeGroups(overwrite);
- } else {
- if (GroupManager.getGlobalGroups().getTimeStampGroups() < GroupManager.getGlobalGroups().getGlobalGroupsFile().lastModified()) {
- System.out.print("Newer GlobalGroups file found (Loading changes)!");
- GroupManager.getGlobalGroups().load();
- }
- }
}
/**
@@ -269,11 +322,12 @@ public class WorldsHolder {
*/
public OverloadedWorldHolder getWorldData(String worldName) {
String worldNameLowered = worldName.toLowerCase();
+ // If a mirror change to the real world to load.
+ if (mirrorsGroup.containsKey(worldNameLowered)) {
+ worldNameLowered = mirrorsGroup.get(worldNameLowered);
+ }
OverloadedWorldHolder data = worldsData.get(worldNameLowered);
- if (mirrors.containsKey(worldNameLowered)) {
- String realOne = mirrors.get(worldNameLowered);
- data = worldsData.get(realOne.toLowerCase());
- }
+
if (data == null) {
GroupManager.logger.finest("Requested world " + worldName + " not found or badly mirrored. Returning default world...");
data = getDefaultWorld();
@@ -282,8 +336,9 @@ public class WorldsHolder {
}
/**
- * Do a matching of playerName, if it s found only one player, do
+ * Do a matching of playerName, if its found only one player, do
* getWorldData(player)
+ *
* @param playerName
* @return null if matching returned no player, or more than one.
*/
@@ -350,60 +405,45 @@ public class WorldsHolder {
}
- public void setupWorldFolder(String worldName) {
- worldsFolder = new File(plugin.getDataFolder(), "worlds");
- if (!worldsFolder.exists()) {
- worldsFolder.mkdirs();
- }
-
- File defaultWorldFolder = new File(worldsFolder, worldName);
- if (!defaultWorldFolder.exists()) {
- defaultWorldFolder.mkdirs();
- }
- if (defaultWorldFolder.exists()) {
- File groupsFile = new File(defaultWorldFolder, "groups.yml");
- File usersFile = new File(defaultWorldFolder, "users.yml");
- File oldDataFile = new File(plugin.getDataFolder(), "data.yml");
- if (!groupsFile.exists() || groupsFile.length() == 0) {
- if (oldDataFile.exists()) {
- try {
- Tasks.copy(oldDataFile, groupsFile);
- } catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- }
- } else {
- InputStream template = plugin.getResourceAsStream("groups.yml");
- try {
- Tasks.copy(template, groupsFile);
- } catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- }
- }
- }
- if (!usersFile.exists() || usersFile.length() == 0) {
- if (oldDataFile.exists()) {
- try {
- Tasks.copy(oldDataFile, usersFile);
- } catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- }
- } else {
- InputStream template = plugin.getResourceAsStream("users.yml");
- try {
- Tasks.copy(template, usersFile);
- } catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- }
- }
- }
- try {
- if (oldDataFile.exists()) {
- oldDataFile.renameTo(new File(plugin.getDataFolder(), "NOT_USED_ANYMORE_data.yml"));
- }
- } catch (Exception ex) {
- }
- }
- }
+ public void setupWorldFolder(String worldName) {
+ worldsFolder = new File(plugin.getDataFolder(), "worlds");
+ if (!worldsFolder.exists()) {
+ worldsFolder.mkdirs();
+ }
+
+ File defaultWorldFolder = new File(worldsFolder, worldName);
+ if ((!defaultWorldFolder.exists()) && ((!mirrorsGroup.containsKey(worldName.toLowerCase()))) || (!mirrorsUser.containsKey(worldName.toLowerCase()))) {
+ defaultWorldFolder.mkdirs();
+ }
+ if (defaultWorldFolder.exists()) {
+ if (!mirrorsGroup.containsKey(worldName.toLowerCase())) {
+ File groupsFile = new File(defaultWorldFolder, "groups.yml");
+ if (!groupsFile.exists() || groupsFile.length() == 0) {
+
+ InputStream template = plugin.getResourceAsStream("groups.yml");
+ try {
+ Tasks.copy(template, groupsFile);
+ } catch (IOException ex) {
+ GroupManager.logger.log(Level.SEVERE, null, ex);
+ }
+ }
+ }
+
+ if (!mirrorsUser.containsKey(worldName.toLowerCase())) {
+ File usersFile = new File(defaultWorldFolder, "users.yml");
+ if (!usersFile.exists() || usersFile.length() == 0) {
+
+ InputStream template = plugin.getResourceAsStream("users.yml");
+ try {
+ Tasks.copy(template, usersFile);
+ } catch (IOException ex) {
+ GroupManager.logger.log(Level.SEVERE, null, ex);
+ }
+
+ }
+ }
+ }
+ }
/**
* Copies the specified world data to another world
@@ -448,16 +488,36 @@ public class WorldsHolder {
GroupManager.logger.finest("Trying to load world " + worldName + "...");
File thisWorldFolder = new File(worldsFolder, worldName);
if (thisWorldFolder.exists() && thisWorldFolder.isDirectory()) {
- File groupsFile = new File(thisWorldFolder, "groups.yml");
- File usersFile = new File(thisWorldFolder, "users.yml");
- if (!groupsFile.exists()) {
+
+ // Setup file handles, if not mirrored
+ File groupsFile = (mirrorsGroup.containsKey(worldName.toLowerCase()))? null : new File(thisWorldFolder, "groups.yml");
+ File usersFile = (mirrorsUser.containsKey(worldName.toLowerCase()))? null : new File(thisWorldFolder, "users.yml");
+
+ if ((groupsFile != null) && (!groupsFile.exists())) {
throw new IllegalArgumentException("Groups file for world '" + worldName + "' doesnt exist: " + groupsFile.getPath());
}
- if (!usersFile.exists()) {
+ if ((usersFile != null) && (!usersFile.exists())) {
throw new IllegalArgumentException("Users file for world '" + worldName + "' doesnt exist: " + usersFile.getPath());
}
- try {
- OverloadedWorldHolder thisWorldData = new OverloadedWorldHolder(WorldDataHolder.load(worldName, groupsFile, usersFile));
+
+ WorldDataHolder tempHolder = new WorldDataHolder(worldName);
+
+ // Map the group object for any mirror
+ if (mirrorsGroup.containsKey(worldName.toLowerCase()))
+ tempHolder.setGroupsObject(this.getWorldData(mirrorsGroup.get(worldName.toLowerCase())).getGroupsObject());
+ else
+ tempHolder.loadGroups(groupsFile);
+
+ // Map the user object for any mirror
+ if (mirrorsUser.containsKey(worldName.toLowerCase()))
+ tempHolder.setUsersObject(this.getWorldData(mirrorsUser.get(worldName.toLowerCase())).getUsersObject());
+ else
+ tempHolder.loadUsers(usersFile);
+
+ OverloadedWorldHolder thisWorldData = new OverloadedWorldHolder(tempHolder);
+
+ // null the object so we don't keep file handles open where we shouldn't
+ tempHolder = null;
// Set the file TimeStamps as it will be default from the initial load.
thisWorldData.setTimeStamps();
@@ -467,13 +527,7 @@ public class WorldsHolder {
worldsData.put(worldName.toLowerCase(), thisWorldData);
return;
}
- } catch (FileNotFoundException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- return;
- } catch (IOException ex) {
- GroupManager.logger.log(Level.SEVERE, null, ex);
- return;
- }
+
//GroupManager.logger.severe("Failed to load world " + worldName + "...");
}
}
@@ -487,7 +541,7 @@ public class WorldsHolder {
* @return true if world is loaded or mirrored. false if not listed
*/
public boolean isInList(String worldName) {
- if (worldsData.containsKey(worldName.toLowerCase()) || mirrors.containsKey(worldName.toLowerCase())) {
+ if (worldsData.containsKey(worldName.toLowerCase()) || mirrorsGroup.containsKey(worldName.toLowerCase())) {
return true;
}
return false;
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEvent.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEvent.java
index 856abbc28..0834b3ada 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEvent.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEvent.java
@@ -1,6 +1,8 @@
package org.anjocaido.groupmanager.events;
+import org.anjocaido.groupmanager.GroupManager;
+import org.bukkit.Bukkit;
import org.bukkit.event.Event;
/**
@@ -13,10 +15,28 @@ public abstract class GroupManagerEvent extends Event {
*
*/
private static final long serialVersionUID = 8790362185329926951L;
-
+
protected GroupManagerEvent(String name) {
super(name);
}
+ /**
+ * Triggers all GroupManager events for other plugins to see.
+ * Schedules events for 1 tick later to allow GM to finish populating super perms.
+ *
+ * @param event
+ */
+ public void schedule(final GroupManagerEvent event) {
+
+ if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
+
+ @Override
+ public void run() {
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ }
+ }, 1) == -1)
+ GroupManager.logger.warning("Could not schedule GM Event.");
+ }
+
} \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java
index 83cac393d..3c077b6c6 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java
@@ -1,11 +1,9 @@
package org.anjocaido.groupmanager.events;
-import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.data.Group;
import org.anjocaido.groupmanager.data.User;
-
/**
* @author ElgarL
*
@@ -13,13 +11,13 @@ import org.anjocaido.groupmanager.data.User;
public class GroupManagerEventHandler {
protected static void callEvent(GMGroupEvent event) {
- GroupManager.callEvent(event);
+ event.schedule(event);
}
protected static void callEvent(GMUserEvent event) {
- GroupManager.callEvent(event);
+ event.schedule(event);
}
protected static void callEvent(GMSystemEvent event) {
- GroupManager.callEvent(event);
+ event.schedule(event);
}
public static void callEvent(Group group, GMGroupEvent.Action action) {
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
index 6e18bf3f8..167103796 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
@@ -90,13 +90,24 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
/**
* Returns All permissions (including inheritance and sub groups) for the
- * player.
+ * player, including child nodes from Bukkit.
*
* @param userName
* @return List<String> of all players permissions.
*/
@Override
public List<String> getAllPlayersPermissions(String userName) {
+ return getAllPlayersPermissions(userName, true);
+ }
+ /**
+ * Returns All permissions (including inheritance and sub groups) for the
+ * player. With or without Bukkit child nodes.
+ *
+ * @param userName
+ * @return List<String> of all players permissions.
+ */
+ @Override
+ public List<String> getAllPlayersPermissions(String userName, Boolean includeChildren) {
List<String> playerPermArray = new ArrayList<String>();
@@ -104,14 +115,16 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
playerPermArray.add(perm);
- Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
-
- if (children != null) {
- for (String child : children.keySet()) {
- if (children.get(child))
- if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
- playerPermArray.add(child);
- }
+ if (includeChildren) {
+ Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
+
+ if (children != null) {
+ for (String child : children.keySet()) {
+ if (children.get(child))
+ if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
+ playerPermArray.add(child);
+ }
+ }
}
}
}
@@ -122,12 +135,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
playerPermArray.add(perm);
- Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
- if (children != null) {
- for (String child : children.keySet()) {
- if (children.get(child))
- if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child)))
- playerPermArray.add(child);
+ if (includeChildren) {
+ Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
+ if (children != null) {
+ for (String child : children.keySet()) {
+ if (children.get(child))
+ if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child)))
+ playerPermArray.add(child);
+ }
}
}
}
@@ -137,13 +152,15 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
playerPermArray.add(perm);
- Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
- if (children != null) {
- for (String child : children.keySet()) {
- if (children.get(child))
- if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
- playerPermArray.add(child);
- }
+ if (includeChildren) {
+ Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
+ if (children != null) {
+ for (String child : children.keySet()) {
+ if (children.get(child))
+ if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
+ playerPermArray.add(child);
+ }
+ }
}
}
}
@@ -711,12 +728,14 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
PermissionCheckResult resultUser = checkUserOnlyPermission(user, targetPermission);
if (resultUser.resultType != PermissionCheckResult.Type.NOTFOUND) {
+ resultUser.accessLevel = targetPermission;
return resultUser;
}
// IT ONLY CHECKS GROUPS PERMISSIONS IF RESULT FOR USER IS NOT FOUND
PermissionCheckResult resultGroup = checkGroupPermissionWithInheritance(user.getGroup(), targetPermission);
if (resultGroup.resultType != PermissionCheckResult.Type.NOTFOUND) {
+ resultGroup.accessLevel = targetPermission;
return resultGroup;
}
@@ -724,6 +743,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
for (Group subGroup : user.subGroupListCopy()) {
PermissionCheckResult resultSubGroup = checkGroupPermissionWithInheritance(subGroup, targetPermission);
if (resultSubGroup.resultType != PermissionCheckResult.Type.NOTFOUND) {
+ resultSubGroup.accessLevel = targetPermission;
return resultSubGroup;
}
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
index 202e27e3a..91f9a9bd6 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
@@ -16,6 +16,7 @@
package org.anjocaido.groupmanager.permissions;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
@@ -23,9 +24,9 @@ import java.util.List;
import java.util.Map;
import org.anjocaido.groupmanager.GroupManager;
-import org.anjocaido.groupmanager.data.User;
+//import org.anjocaido.groupmanager.data.User;
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
-import org.anjocaido.groupmanager.utils.PermissionCheckResult;
+//import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -43,8 +44,7 @@ import org.bukkit.event.server.ServerListener;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
-import org.bukkit.permissions.PermissionDefault;
-import org.bukkit.plugin.Plugin;
+//import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
@@ -52,7 +52,7 @@ import org.bukkit.plugin.PluginManager;
*
* BukkitPermissions overrides to force GM reponses to Superperms
*
- * @author ElgarL, based upon PermissionsEX implementation
+ * @author ElgarL, originally based upon PermissionsEX implementation
*/
public class BukkitPermissions {
@@ -62,13 +62,25 @@ public class BukkitPermissions {
protected boolean dumpAllPermissions = true;
protected boolean dumpMatchedPermissions = true;
public boolean player_join = false;
+
+ private static Field permissions;
+
+ // Setup reflection (Thanks to Codename_B for the reflection source)
+ static {
+ try {
+ permissions = PermissionAttachment.class.getDeclaredField("permissions");
+ permissions.setAccessible(true);
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NoSuchFieldException e) {
+ e.printStackTrace();
+ }
+ }
public BukkitPermissions(GroupManager plugin) {
this.plugin = plugin;
-
this.collectPermissions();
this.registerEvents();
-
this.updateAllPlayers();
GroupManager.logger.info("Superperms support enabled.");
@@ -93,50 +105,69 @@ public class BukkitPermissions {
manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin);
}
+
public void collectPermissions() {
registeredPermissions.clear();
+ /*
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
for (Permission permission : bukkitPlugin.getDescription().getPermissions())
registeredPermissions.push(permission);
}
+ */
+
+ registeredPermissions = new LinkedList<Permission>(Bukkit.getPluginManager().getPermissions());
+
}
+
public void updatePermissions(Player player) {
this.updatePermissions(player, null);
}
+
+ /**
+ * Push all permissions which are registered with GM for this player, on this world to Bukkit
+ * and make it update for the child nodes.
+ *
+ * @param player
+ * @param world
+ */
public void updatePermissions(Player player, String world) {
if (player == null || !GroupManager.isLoaded()) {
return;
}
- if (!this.attachments.containsKey(player)) {
- this.attachments.put(player, player.addAttachment(plugin));
+ PermissionAttachment attachment;
+ // Find the players current attachment, or add a new one.
+ if (this.attachments.containsKey(player)) {
+ attachment = this.attachments.get(player);
+ } else {
+ attachment = player.addAttachment(plugin);
+ this.attachments.put(player, attachment);;
}
if (world == null) {
world = player.getWorld().getName();
}
- // All permissions registered with Bukkit for this player
- PermissionAttachment attachment = this.attachments.get(player);
-
OverloadedWorldHolder worldData = plugin.getWorldsHolder().getWorldData(world);
+ Boolean value = false;
+ //User user = worldData.getUser(player.getName());
- User user = worldData.getUser(player.getName());
-
+ /*
// clear permissions
for (String permission : attachment.getPermissions().keySet())
attachment.unsetPermission(permission);
-
+ */
+
/*
* find matching permissions
*
* and base bukkit perms if we are set to allow bukkit permissions to
* override.
*/
- Boolean value = false;
-
+
+ /*
for (Permission permission : registeredPermissions) {
PermissionCheckResult result = worldData.getPermissionsHandler().checkFullGMPermission(user, permission.getName(), false);
@@ -163,35 +194,48 @@ public class BukkitPermissions {
if ((value == true) || (result.resultType == PermissionCheckResult.Type.NEGATION)) {
attachment.setPermission(permission, value);
}
- /*
- if ((value == true) || (result.resultType == PermissionCheckResult.Type.NOTFOUND)) {
- // fetch and set all children of this permission node
- Map<String, Boolean> children = permission.getChildren();
- if (children != null) {
- for (String child : children.keySet()) {
- if (children.get(child))
- attachment.setPermission(child, value);
- }
- }
- }*/
-
}
+ */
- // Add any missing permissions for this player (non bukkit plugins and child nodes)
- List<String> playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName());
-
+ // Add all permissions for this player (GM only)
+ // child nodes will be calculated by Bukkit.
+ List<String> playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName(), false);
+ Map<String, Boolean> newPerms = new HashMap<String, Boolean>();
+
for (String permission : playerPermArray) {
value = true;
if (permission.startsWith("-")) {
permission = permission.substring(1); // cut off -
value = false;
}
-
+ /*
if (!attachment.getPermissions().containsKey(permission)) {
attachment.setPermission(permission, value);
}
+ */
+ newPerms.put(permission, value);
+ }
+
+ //player.recalculatePermissions();
+
+ /**
+ * This is put in place until such a time as Bukkit pull 466 is implemented
+ * https://github.com/Bukkit/Bukkit/pull/466
+ */
+ try { // Codename_B source
+ @SuppressWarnings("unchecked")
+ Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(attachment);
+ // Clear the map (faster than removing the attachment and recalculating)
+ orig.clear();
+ // Then whack our map into there
+ orig.putAll(newPerms);
+ // That's all folks!
+ attachment.getPermissible().recalculatePermissions();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
}
- player.recalculatePermissions();
}
/**
@@ -245,6 +289,12 @@ public class BukkitPermissions {
return null;
}
+ /**
+ * List all effective permissions for this player.
+ *
+ * @param player
+ * @return List<String> of permissions
+ */
public List<String> listPerms(Player player) {
List<String> perms = new ArrayList<String>();
@@ -266,6 +316,9 @@ public class BukkitPermissions {
return perms;
}
+ /**
+ * force Bukkit to update every OnlinePlayers permissions.
+ */
public void updateAllPlayers() {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
updatePermissions(player);
@@ -332,7 +385,7 @@ public class BukkitPermissions {
@Override
public void onPluginDisable(PluginDisableEvent event) {
- // collectPermissions();
+ collectPermissions();
// updateAllPlayers();
}
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java
index c0383c160..cf11bd37f 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java
@@ -234,4 +234,6 @@ public abstract class PermissionsReaderInterface {
//////////////////////////////
public abstract List<String> getAllPlayersPermissions(String userName);
+
+ public abstract List<String> getAllPlayersPermissions(String userName, Boolean includeChildren);
}