mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 01:27:40 +01:00
Merge remote branch 'remotes/origin/groupmanager'
This commit is contained in:
commit
f0def90301
@ -97,4 +97,7 @@ v 1.8:
|
||||
- Reload GlobalGroups when you perform a world load.
|
||||
- Changed GlobalGroups to save/load before local groups in the scheduled data saving/loading
|
||||
- Fix 'manucheckp' to correctly report if a permission is available from GroupManager or Bukkit.
|
||||
- Changed over to a reflection method for populating superperms as Bukkit lags when you handle permissions one at a time.
|
||||
- Changed over to a reflection method for populating superperms as Bukkit lags when you handle permissions one at a time.
|
||||
- Major, MAJOR changes to support partial/full world mirroring.
|
||||
You can now mirror groups.yml, users.yml or both files between different worlds.
|
||||
- Catch NullPointerErrors generated by blank permission nodes.
|
@ -25,14 +25,22 @@ settings:
|
||||
level: INFO
|
||||
|
||||
mirrors:
|
||||
# Worlds listed here have their permissions mirrored in their children.
|
||||
# the first element 'world' is the main worlds name
|
||||
# subsequent elements '- world_nether' are worlds which will use the same
|
||||
# user/groups permissions as the parent.
|
||||
# Worlds listed here have their settings mirrored in their children.
|
||||
# The first element 'world' is the main worlds name
|
||||
# subsequent elements 'world_nether' and 'world_the_end' are worlds which will use
|
||||
# the same user/groups files as the parent.
|
||||
# Each child world can be configured to mirror the 'groups', 'users' or both files from it's parent.
|
||||
world:
|
||||
- world_nether
|
||||
- world_the_end
|
||||
- world2
|
||||
- world3
|
||||
# world4:
|
||||
# - world5
|
||||
world_nether:
|
||||
- users
|
||||
- groups
|
||||
world_the_end:
|
||||
- users
|
||||
- groups
|
||||
# world2: (World2 would have it's own set of user and groups files)
|
||||
# world3:
|
||||
# - users (World3 would use the users.yml from world2, but it's own groups.yml)
|
||||
# world4:
|
||||
# - groups (World4 would use the groups.yml from world2, but it's own users.yml)
|
||||
# world5:
|
||||
# - world6 (this would cause world6 to mirror both files from world5)
|
@ -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 + ", ";
|
||||
@ -1522,7 +1522,8 @@ public class GroupManager extends JavaPlugin {
|
||||
}
|
||||
// WORKING
|
||||
config.load();
|
||||
|
||||
worldsHolder.mirrorSetUp();
|
||||
|
||||
isLoaded = false;
|
||||
|
||||
if (args.length > 0) {
|
||||
@ -1539,7 +1540,6 @@ public class GroupManager extends JavaPlugin {
|
||||
worldsHolder.reloadAll();
|
||||
sender.sendMessage(ChatColor.YELLOW + " The current world was reloaded.");
|
||||
}
|
||||
worldsHolder.mirrorSetUp();
|
||||
|
||||
isLoaded = true;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
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());
|
||||
}
|
||||
|
||||
GroupManager.setLoaded(true);
|
||||
}
|
||||
|
||||
public void loadUsers(File usersFile) {
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
//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());
|
||||
}
|
||||
|
||||
|
||||
//USER INFO NODE - BETA
|
||||
|
||||
//INFO NODE
|
||||
Map<String, Object> infoNode = (Map<String, Object>) thisUserNode.get("info");
|
||||
if (infoNode != null) {
|
||||
thisUser.setVariables(infoNode);
|
||||
}
|
||||
//END INFO NODE - BETA
|
||||
|
||||
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,108 +636,21 @@ 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
|
||||
@ -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;
|
||||
}
|
||||
@ -1100,15 +868,22 @@ public class WorldDataHolder {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,48 +244,50 @@ 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);
|
||||
}
|
||||
}
|
||||
@ -270,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();
|
||||
@ -283,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.
|
||||
*/
|
||||
@ -351,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
|
||||
@ -449,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();
|
||||
@ -468,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 + "...");
|
||||
}
|
||||
}
|
||||
@ -488,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;
|
||||
|
@ -287,7 +287,7 @@ public class BukkitPermissions {
|
||||
* List all effective permissions for this player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
* @return List<String> of permissions
|
||||
*/
|
||||
public List<String> listPerms(Player player) {
|
||||
List<String> perms = new ArrayList<String>();
|
||||
|
Loading…
Reference in New Issue
Block a user