Browse Source

使用YUMC统计系统...

Signed-off-by: 502647092 <jtb1@163.com>
master
502647092 6 years ago
commit
ae31156f72
  1. 31
      .classpath
  2. 38
      .gitignore
  3. 23
      .project
  4. 78
      pom.xml
  5. 208
      src/main/java/org/anjocaido/groupmanager/GMConfiguration.java
  6. 483
      src/main/java/org/anjocaido/groupmanager/GlobalGroups.java
  7. 2237
      src/main/java/org/anjocaido/groupmanager/GroupManager.java
  8. 29
      src/main/java/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java
  9. 205
      src/main/java/org/anjocaido/groupmanager/data/DataUnit.java
  10. 197
      src/main/java/org/anjocaido/groupmanager/data/Group.java
  11. 97
      src/main/java/org/anjocaido/groupmanager/data/GroupVariables.java
  12. 323
      src/main/java/org/anjocaido/groupmanager/data/User.java
  13. 56
      src/main/java/org/anjocaido/groupmanager/data/UserVariables.java
  14. 213
      src/main/java/org/anjocaido/groupmanager/data/Variables.java
  15. 136
      src/main/java/org/anjocaido/groupmanager/dataholder/GroupsDataHolder.java
  16. 220
      src/main/java/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java
  17. 118
      src/main/java/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java
  18. 1466
      src/main/java/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
  19. 794
      src/main/java/org/anjocaido/groupmanager/dataholder/worlds/WorldsHolder.java
  20. 92
      src/main/java/org/anjocaido/groupmanager/events/GMGroupEvent.java
  21. 66
      src/main/java/org/anjocaido/groupmanager/events/GMSystemEvent.java
  22. 94
      src/main/java/org/anjocaido/groupmanager/events/GMUserEvent.java
  23. 61
      src/main/java/org/anjocaido/groupmanager/events/GMWorldListener.java
  24. 82
      src/main/java/org/anjocaido/groupmanager/events/GroupManagerEventHandler.java
  25. 1353
      src/main/java/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
  26. 497
      src/main/java/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
  27. 255
      src/main/java/org/anjocaido/groupmanager/permissions/PermissionsReaderInterface.java
  28. 27
      src/main/java/org/anjocaido/groupmanager/utils/GMLoggerHandler.java
  29. 56
      src/main/java/org/anjocaido/groupmanager/utils/GroupManagerPermissions.java
  30. 67
      src/main/java/org/anjocaido/groupmanager/utils/PermissionCheckResult.java
  31. 52
      src/main/java/org/anjocaido/groupmanager/utils/StringPermissionComparator.java
  32. 175
      src/main/java/org/anjocaido/groupmanager/utils/Tasks.java
  33. 233
      src/main/resources/Changelog.txt
  34. 50
      src/main/resources/config.yml
  35. 329
      src/main/resources/globalgroups.yml
  36. 74
      src/main/resources/groups.yml
  37. 184
      src/main/resources/plugin.yml
  38. 18
      src/main/resources/users.yml

31
.classpath

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

38
.gitignore

@ -0,0 +1,38 @@
# Eclipse stuff
/.settings
# netbeans
/nbproject
# we use maven!
/build.xml
# maven
/target
/repo
# vim
.*.sw[a-p]
# various other potential build files
/build
/bin
/dist
/manifest.mf
/world
# Mac filesystem dust
*.DS_Store
# intellij
*.iml
*.ipr
*.iws
.idea/
# Project Stuff
/src/main/resources/Soulbound
# Atlassian Stuff
/atlassian-ide-plugin.xml

23
.project

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GroupManager</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

78
pom.xml

@ -0,0 +1,78 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.anjocaido</groupId>
<artifactId>GroupManager</artifactId>
<version>2.3</version>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>cn.citycraft:PluginHelper</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>cn.citycraft.PluginHelper</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>citycraft-repo</id>
<url>${jenkins.url}/plugin/repository/everything/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.8.8-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>PluginHelper</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
</dependencies>
</project>

208
src/main/java/org/anjocaido/groupmanager/GMConfiguration.java

@ -0,0 +1,208 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.anjocaido.groupmanager;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.anjocaido.groupmanager.utils.Tasks;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.reader.UnicodeReader;
/**
*
* @author gabrielcouto
*/
public class GMConfiguration {
private boolean allowCommandBlocks = false;
private boolean opOverride = true;
private boolean toggleValidate = true;
private Integer saveInterval = 10;
private Integer backupDuration = 24;
private String loggerLevel = "OFF";
private Map<String, Object> mirrorsMap;
private GroupManager plugin;
private Map<String, Object> GMconfig;
public GMConfiguration(GroupManager plugin) {
this.plugin = plugin;
/*
* Set defaults
*/
allowCommandBlocks = false;
opOverride = true;
toggleValidate = true;
saveInterval = 10;
backupDuration = 24;
loggerLevel = "OFF";
load();
}
@SuppressWarnings("unchecked")
public void load() {
if (!plugin.getDataFolder().exists()) {
plugin.getDataFolder().mkdirs();
}
File configFile = new File(plugin.getDataFolder(), "config.yml");
if (!configFile.exists()) {
try {
Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile);
} catch (IOException ex) {
GroupManager.logger.log(Level.SEVERE, "Error creating a new config.yml", ex);
}
}
Yaml configYAML = new Yaml(new SafeConstructor());
try {
FileInputStream configInputStream = new FileInputStream(configFile);
GMconfig = (Map<String, Object>) configYAML.load(new UnicodeReader(configInputStream));
configInputStream.close();
} catch (Exception ex) {
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
}
/*
* Read our config settings and store them for reading later.
*/
try {
Map<String, Object> config = getElement("config", getElement("settings", GMconfig));
try {
allowCommandBlocks = (Boolean) config.get("allow_commandblocks");
} catch (Exception ex) {
GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'allow_commandblocks' node. Using default settings", ex);
}
try {
opOverride = (Boolean) config.get("opOverrides");
} catch (Exception ex) {
GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'opOverrides' node. Using default settings", ex);
}
try {
toggleValidate = (Boolean) config.get("validate_toggle");
} catch (Exception ex) {
GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'validate_toggle' node. Using default settings", ex);
}
/*
* data node for save/backup timers.
*/
try {
Map<String, Object> save = getElement("save", getElement("data", getElement("settings", GMconfig)));
try {
saveInterval = (Integer) save.get("minutes");
} catch (Exception ex) {
GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'minutes' node. Using default setting", ex);
}
try {
backupDuration = (Integer) save.get("hours");
} catch (Exception ex) {
GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'hours' node. Using default setting", ex);
}
} catch (Exception ex) {
GroupManager.logger.log(Level.SEVERE, "Missing or corrupt 'data' node. Using default settings", ex);
}
Object level = ((Map<String, String>) getElement("settings", GMconfig).get("logging")).get("level");
if (level instanceof String)
loggerLevel = (String) level;
/*
* Store our mirrors map for parsing later.
*/
mirrorsMap = (Map<String, Object>) ((Map<String, Object>) GMconfig.get("settings")).get("mirrors");
if (mirrorsMap == null)
throw new Exception();
} catch (Exception ex) {
/*
* Flag the error and use defaults
*/
GroupManager.logger.log(Level.SEVERE, "There are errors in your config.yml. Using default settings", ex);
mirrorsMap = new HashMap<String, Object>();
}
// Setup defaults
adjustLoggerLevel();
plugin.setValidateOnlinePlayer(isToggleValidate());
}
@SuppressWarnings("unchecked")
private Map<String, Object> getElement(String element, Map<String, Object> map) {
if (!map.containsKey(element)) {
throw new IllegalArgumentException("The config.yml has no '" + element + ".\n");
}
return (Map<String, Object>) map.get(element);
}
public boolean isAllowCommandBlocks() {
return allowCommandBlocks;
}
public boolean isOpOverride() {
return opOverride;
}
public boolean isToggleValidate() {
return toggleValidate;
}
public Integer getSaveInterval() {
return saveInterval;
}
public Integer getBackupDuration() {
return backupDuration;
}
public void adjustLoggerLevel() {
try {
GroupManager.logger.setLevel(Level.parse(loggerLevel));
return;
} catch (Exception e) {
}
GroupManager.logger.setLevel(Level.INFO);
}
public Map<String, Object> getMirrorsMap() {
if (!mirrorsMap.isEmpty()) {
return mirrorsMap;
}
return null;
}
}

483
src/main/java/org/anjocaido/groupmanager/GlobalGroups.java

@ -0,0 +1,483 @@
package org.anjocaido.groupmanager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.anjocaido.groupmanager.data.Group;
import org.anjocaido.groupmanager.events.GMGroupEvent;
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.anjocaido.groupmanager.utils.Tasks;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.reader.UnicodeReader;
/**
* @author ElgarL
*
*/
public class GlobalGroups {
private GroupManager plugin;
// private Yaml GGroups;
private final Map<String, Group> groups = Collections.synchronizedMap(new HashMap<String, Group>());
protected long timeStampGroups = 0;
protected boolean haveGroupsChanged = false;
protected File GlobalGroupsFile = null;
public GlobalGroups(GroupManager plugin) {
this.plugin = plugin;
load();
}
/**
* @return the haveGroupsChanged
*/
public boolean haveGroupsChanged() {
if (this.haveGroupsChanged) {
return true;
}
synchronized (groups) {
for (Group g : groups.values()) {
if (g.isChanged()) {
return true;
}
}
}
return false;
}
/**
* @return the timeStampGroups
*/
public long getTimeStampGroups() {
return timeStampGroups;
}
/**
* @param timeStampGroups
* the timeStampGroups to set
*/
protected void setTimeStampGroups(long timeStampGroups) {
this.timeStampGroups = timeStampGroups;
}
/**
* @param haveGroupsChanged
* the haveGroupsChanged to set
*/
public void setGroupsChanged(boolean haveGroupsChanged) {
this.haveGroupsChanged = haveGroupsChanged;
}
@SuppressWarnings("unchecked")
public void load() {
Yaml GGroupYAML = new Yaml(new SafeConstructor());
Map<String, Object> GGroups;
GroupManager.setLoaded(false);
// READ globalGroups FILE
if (GlobalGroupsFile == null)
GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
if (!GlobalGroupsFile.exists()) {
try {
// Create a new file if it doesn't exist.
Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"), GlobalGroupsFile);
} catch (IOException ex) {
GroupManager.logger.log(Level.SEVERE, null, ex);
}
}
/*
* Load the YAML file.
*/
try {
FileInputStream groupsInputStream = new FileInputStream(GlobalGroupsFile);
GGroups = (Map<String, Object>) GGroupYAML.load(new UnicodeReader(groupsInputStream));
groupsInputStream.close();
} catch (Exception ex) {
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + GlobalGroupsFile.getPath(), ex);
}
// Clear out old groups
resetGlobalGroups();
if (!GGroups.keySet().isEmpty()) {
// Read all global groups
Map<String, Object> allGroups = new HashMap<String, Object>();
try {
allGroups = (Map<String, Object>) GGroups.get("groups");
} catch (Exception ex) {
// ex.printStackTrace();
throw new IllegalArgumentException("Your " + GlobalGroupsFile.getPath() + " file is invalid. See console for details.", ex);
}
// Load each groups permissions list.
if (allGroups != null) {
Iterator<String> groupItr = allGroups.keySet().iterator();
String groupName;
Integer groupCount = 0;
/*
* loop each group entry
* and read it's data.
*/
while (groupItr.hasNext()) {
try {
groupCount++;
// Attempt to fetch the next group name.
groupName = groupItr.next();
} catch (Exception ex) {
throw new IllegalArgumentException("Invalid group name for GlobalGroup entry (" + groupCount + ") in file: " + GlobalGroupsFile.getPath(), ex);
}
/*
* Create a new group with this name.
*/
Group newGroup = new Group(groupName.toLowerCase());
Object element;
// Permission nodes
try {
element = ((Map<String, Object>) allGroups.get(groupName)).get("permissions");
} catch (Exception ex) {
throw new IllegalArgumentException("The GlobalGroup ' " + groupName + "' is formatted incorrectly: ", ex);
}
if (element != null)
if (element instanceof List) {
try {
for (String node : (List<String>) element) {
if ((node != null) && !node.isEmpty())
newGroup.addPermission(node);
}
} catch (ClassCastException ex) {
throw new IllegalArgumentException("Invalid permission node for global group: " + groupName, ex);
}
} else if (element instanceof String) {
if ((element != null) && !((String) element).isEmpty())
newGroup.addPermission((String) element);
} else
throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName);
// // Info nodes
// try {
// element = ((Map<String, Object>)allGroups.get(groupName)).get("info");
// } catch ( Exception ex) {
// throw new IllegalArgumentException("The GlobalGroup ' " + groupName + "' is formatted incorrectly: ", ex);
// }
//
// if (element != null)
// if (element instanceof MemorySection) {
// Map<String, Object> vars = new HashMap<String, Object>();
// for (String key : ((MemorySection) element).getKeys(false)) {
// vars.put(key, ((MemorySection) element).get(key));
// }
// newGroup.setVariables(vars);
// } else
// throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName);
// Push a new group
addGroup(newGroup);
}
}
removeGroupsChangedFlag();
}
setTimeStampGroups(GlobalGroupsFile.lastModified());
GroupManager.setLoaded(true);
// GlobalGroupsFile = null;
}
/**
* Write the globalgroups.yml file
*/
public void writeGroups(boolean overwrite) {
// File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
if (haveGroupsChanged()) {
if (overwrite || (!overwrite && (getTimeStampGroups() >= GlobalGroupsFile.lastModified()))) {
Map<String, Object> root = new HashMap<String, Object>();
Map<String, Object> groupsMap = new HashMap<String, Object>();
root.put("groups", groupsMap);
synchronized (groups) {
for (String groupKey : groups.keySet()) {
Group group = groups.get(groupKey);
// Group header
Map<String, Object> aGroupMap = new HashMap<String, Object>();
groupsMap.put(group.getName(), aGroupMap);
// // Info nodes
// 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));
// }
// Permission nodes
aGroupMap.put("permissions", group.getPermissionList());
}
}
if (!root.isEmpty()) {
DumperOptions opt = new DumperOptions();
opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final Yaml yaml = new Yaml(opt);
try {
yaml.dump(root, new OutputStreamWriter(new FileOutputStream(GlobalGroupsFile), "UTF-8"));
} catch (UnsupportedEncodingException ex) {
} catch (FileNotFoundException ex) {
}
}
setTimeStampGroups(GlobalGroupsFile.lastModified());
} else {
// Newer file found.
GroupManager.logger.log(Level.WARNING, "Newer GlobalGroups file found, but we have local changes!");
throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
}
removeGroupsChangedFlag();
} else {
// Check for newer file as no local changes.
if (getTimeStampGroups() < GlobalGroupsFile.lastModified()) {
System.out.print("Newer GlobalGroups file found (Loading changes)!");
// Backup GlobalGroups file
backupFile();
load();
}
}
}
/**
* Backup the BlobalGroups file
*
* @param w
*/
private void backupFile() {
File backupFile = new File(plugin.getBackupFolder(), "bkp_ggroups_" + Tasks.getDateString() + ".yml");
try {
Tasks.copy(GlobalGroupsFile, backupFile);
} catch (IOException ex) {
GroupManager.logger.log(Level.SEVERE, null, ex);
}
}
/**
* Adds a group, or replaces an existing one.
*
* @param groupToAdd
*/
public void addGroup(Group groupToAdd) {
// Create a new group if it already exists
if (hasGroup(groupToAdd.getName())) {
groupToAdd = groupToAdd.clone();
removeGroup(groupToAdd.getName());
}
newGroup(groupToAdd);
haveGroupsChanged = true;
if (GroupManager.isLoaded())
GroupManager.getGMEventHandler().callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
}
/**
* Creates a new group if it doesn't already exist.
*
* @param newGroup
*/
public Group newGroup(Group newGroup) {
// Push a new group
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
groups.put(newGroup.getName().toLowerCase(), newGroup);
this.setGroupsChanged(true);
return newGroup;
}
return null;
}
/**
* Delete a group if it exist.
*
* @param groupName
*/
public boolean removeGroup(String groupName) {
// Push a new group
if (groups.containsKey(groupName.toLowerCase())) {
groups.remove(groupName.toLowerCase());
this.setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManager.getGMEventHandler().callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
return true;
}
return false;
}
/**
* Returns true if the Global Group exists in the globalgroups.yml
*
* @param groupName
* @return true if the group exists
*/
public boolean hasGroup(String groupName) {
return groups.containsKey(groupName.toLowerCase());
}
/**
* Returns true if the group has the correct permission node.
*
* @param groupName
* @param permissionNode
* @return true if node exists
*/
public boolean hasPermission(String groupName, String permissionNode) {
if (!hasGroup(groupName))
return false;
return groups.get(groupName.toLowerCase()).hasSamePermissionNode(permissionNode);
}
/**
* Returns a PermissionCheckResult of the permission node for the group to
* be tested against.
*
* @param groupName
* @param permissionNode
* @return PermissionCheckResult object
*/
public PermissionCheckResult checkPermission(String groupName, String permissionNode) {
PermissionCheckResult result = new PermissionCheckResult();
result.askedPermission = permissionNode;
result.resultType = PermissionCheckResult.Type.NOTFOUND;
if (!hasGroup(groupName))
return result;
Group tempGroup = groups.get(groupName.toLowerCase());
if (tempGroup.hasSamePermissionNode(permissionNode))
result.resultType = PermissionCheckResult.Type.FOUND;
if (tempGroup.hasSamePermissionNode("-" + permissionNode))
result.resultType = PermissionCheckResult.Type.NEGATION;
if (tempGroup.hasSamePermissionNode("+" + permissionNode))
result.resultType = PermissionCheckResult.Type.EXCEPTION;
return result;
}
/**
* Returns a List of all permission nodes for this group null if none
*
* @param groupName
* @return List of all group names
*/
public List<String> getGroupsPermissions(String groupName) {
if (!hasGroup(groupName))
return null;
return groups.get(groupName.toLowerCase()).getPermissionList();
}
/**
* Returns a Set of all global group names.
*
* @return Set containing all group names.
*/
/*
* public Set<String> getGlobalGroups() {
*
* return groups.keySet();
* }
*/
/**
* Resets GlobalGroups.
*/
public void resetGlobalGroups() {
this.groups.clear();
}
/**
*
* @return a collection of the groups
*/
public Group[] getGroupList() {
synchronized (groups) {
return groups.values().toArray(new Group[0]);
}
}
/**
* Returns the Global Group or null if it doesn't exist.
*
* @param groupName
* @return Group object
*/
public Group getGroup(String groupName) {
if (!hasGroup(groupName))
return null;
return groups.get(groupName.toLowerCase());
}
/**
* @return the globalGroupsFile
*/
public File getGlobalGroupsFile() {
return GlobalGroupsFile;
}
/**
*
*/
public void removeGroupsChangedFlag() {
setGroupsChanged(false);
synchronized (groups) {
for (Group g : groups.values()) {
g.flagAsSaved();
}
}
}
}

2237
src/main/java/org/anjocaido/groupmanager/GroupManager.java

File diff suppressed because it is too large

29
src/main/java/org/anjocaido/groupmanager/Tasks/BukkitPermsUpdateTask.java

@ -0,0 +1,29 @@
package org.anjocaido.groupmanager.Tasks;
import org.anjocaido.groupmanager.GroupManager;
/*
*
* Created by ElgarL
*/
public class BukkitPermsUpdateTask implements Runnable {
public BukkitPermsUpdateTask() {
super();
}
@Override
public void run() {
// Signal loaded and update BukkitPermissions.
GroupManager.setLoaded(true);
GroupManager.BukkitPermissions.collectPermissions();
GroupManager.BukkitPermissions.updateAllPlayers();
GroupManager.logger.info("Bukkit Permissions Updated!");
}
}

205
src/main/java/org/anjocaido/groupmanager/data/DataUnit.java

@ -0,0 +1,205 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.anjocaido.groupmanager.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.utils.StringPermissionComparator;
/**
*
* @author gabrielcouto
*/
public abstract class DataUnit {
private WorldDataHolder dataSource;
private String uUID;
private String lastName;
private boolean changed, sorted = false;
private List<String> permissions = Collections.unmodifiableList(Collections.<String> emptyList());
public DataUnit(WorldDataHolder dataSource, String name) {
this.dataSource = dataSource;
this.uUID = name;
}
public DataUnit(String name) {
this.uUID = name;
}
/**
* Every group is matched only by their names and DataSources names.
*
* @param o
* @return true if they are equal. false if not.
*/
@Override
public boolean equals(Object o) {
if (o instanceof DataUnit) {
DataUnit go = (DataUnit) o;
if (this.getUUID().equalsIgnoreCase(go.getUUID())) {
// Global Group match.
if (this.dataSource == null && go.getDataSource() == null)
return true;
// This is a global group, the object to test isn't.
if (this.dataSource == null && go.getDataSource() != null)
return false;
// This is not a global group, but the object to test is.
if (this.dataSource != null && go.getDataSource() == null)
return false;
// Match on group name and world name.
if (this.dataSource.getName().equalsIgnoreCase(go.getDataSource().getName()))
return true;
}
}
return false;
}
@Override
public int hashCode() {
int hash = 5;
hash = 71 * hash + (this.uUID != null ? this.uUID.toLowerCase().hashCode() : 0);
return hash;
}
/**
* Set the data source to point to a different worldDataHolder
*
* @param source
*/
public void setDataSource(WorldDataHolder source) {
this.dataSource = source;
}
/**
* Get the current worldDataHolder this object is pointing to
*
* @return the dataSource
*/
public WorldDataHolder getDataSource() {
return dataSource;
}
public String getUUID() {
return uUID;
}
public String getLastName() {
if (uUID.length() < 36)
return this.uUID;
return this.lastName;
}
public void setLastName(String lastName) {
if (!lastName.equals(this.lastName)) {
this.lastName = lastName;
changed = true;
}
}
public void flagAsChanged() {
WorldDataHolder testSource = getDataSource();
String source = "";
if (testSource == null)
source = "GlobalGroups";
else
source = testSource.getName();
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getUUID() + " flagged as changed!");
// for(StackTraceElement st: Thread.currentThread().getStackTrace()){
// GroupManager.logger.finest(st.toString());
// }
sorted = false;
changed = true;
}
public boolean isChanged() {
return changed;
}
public void flagAsSaved() {
WorldDataHolder testSource = getDataSource();
String source = "";
if (testSource == null)
source = "GlobalGroups";
else
source = testSource.getName();
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getUUID() + " flagged as saved!");
changed = false;
}
public boolean hasSamePermissionNode(String permission) {
return permissions.contains(permission);
}
public void addPermission(String permission) {
if (!hasSamePermissionNode(permission)) {
List<String> clone = new ArrayList<String>(permissions);
clone.add(permission);
permissions = Collections.unmodifiableList(clone);
}
flagAsChanged();
}
public boolean removePermission(String permission) {
flagAsChanged();
List<String> clone = new ArrayList<String>(permissions);
boolean ret = clone.remove(permission);
permissions = Collections.unmodifiableList(clone);
return ret;
}
/**
* Use this only to list permissions.
* You can't edit the permissions using the returned ArrayList instance
*
* @return a copy of the permission list
*/
public List<String> getPermissionList() {
sortPermissions();
return permissions;
}
public boolean isSorted() {
return this.sorted;
}
public void sortPermissions() {
if (!isSorted()) {
List<String> clone = new ArrayList<String>(permissions);
Collections.sort(clone, StringPermissionComparator.getInstance());
permissions = Collections.unmodifiableList(clone);
sorted = true;
}
}
}

197
src/main/java/org/anjocaido/groupmanager/data/Group.java

@ -0,0 +1,197 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.anjocaido.groupmanager.data;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.events.GMGroupEvent.Action;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
*
* @author gabrielcouto/ElgarL
*/
public class Group extends DataUnit implements Cloneable {
/**
* The group it inherits DIRECTLY!
*/
private List<String> inherits = Collections.unmodifiableList(Collections.<String> emptyList());
/**
* This one holds the fields in INFO node.
* like prefix = 'c'
* or build = false
*/
private GroupVariables variables = new GroupVariables(this);
/**
* Constructor for individual World Groups.
*
* @param name
*/
public Group(WorldDataHolder source, String name) {
super(source, name);
}
/**
* Constructor for Global Groups.
*
* @param name
*/
public Group(String name) {
super(name);
}
/**
* @return the name
*/
public String getName() {
return this.getUUID();
}
/**
* Is this a GlobalGroup
*
* @return true if this is a global group
*/
public boolean isGlobal() {
return (getDataSource() == null);
}
/**
* Clone this group
*
* @return a clone of this group
*/
@Override
public Group clone() {
Group clone;
if (isGlobal()) {
clone = new Group(this.getName());
} else {
clone = new Group(getDataSource(), this.getName());
clone.inherits = this.getInherits().isEmpty() ? Collections.unmodifiableList(Collections.<String> emptyList()) : Collections.unmodifiableList(new ArrayList<String>(this.getInherits()));
}
for (String perm : this.getPermissionList()) {
clone.addPermission(perm);
}
clone.variables = ((GroupVariables) variables).clone(clone);
// clone.flagAsChanged();
return clone;
}
/**
* Use this to deliver a group from a different dataSource to another
*
* @param dataSource
* @return Null or Clone
*/
public Group clone(WorldDataHolder dataSource) {
if (dataSource.groupExists(this.getName())) {
return null;
}
Group clone = dataSource.createGroup(this.getName());
// Don't add inheritance for GlobalGroups
if (!isGlobal()) {
clone.inherits = this.getInherits().isEmpty() ? Collections.unmodifiableList(Collections.<String> emptyList()) : Collections.unmodifiableList(new ArrayList<String>(this.getInherits()));
}
for (String perm : this.getPermissionList()) {
clone.addPermission(perm);
}
clone.variables = variables.clone(clone);
clone.flagAsChanged(); // use this to make the new dataSource save the new group
return clone;
}
/**
* an unmodifiable list of inherits list
* You can't manage the list by here
* Lol... version 0.6 had a problem because this.
*
* @return the inherits
*/
public List<String> getInherits() {
return inherits;
}
/**
* @param inherit
* the inherits to set
*/
public void addInherits(Group inherit) {
if (!isGlobal()) {
if (!this.getDataSource().groupExists(inherit.getName())) {
getDataSource().addGroup(inherit);
}
if (!inherits.contains(inherit.getName().toLowerCase())) {
List<String> clone = new ArrayList<String>(inherits);
clone.add(inherit.getName().toLowerCase());
inherits = Collections.unmodifiableList(clone);
}
flagAsChanged();
if (GroupManager.isLoaded()) {
GroupManager.BukkitPermissions.updateAllPlayers();
GroupManager.getGMEventHandler().callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
}
}
}
public boolean removeInherits(String inherit) {
if (!isGlobal()) {
if (this.inherits.contains(inherit.toLowerCase())) {
List<String> clone = new ArrayList<String>(inherits);
clone.remove(inherit.toLowerCase());
inherits = Collections.unmodifiableList(clone);
flagAsChanged();
GroupManager.getGMEventHandler().callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
return true;
}
}
return false;
}
/**
* @return the variables
*/
public GroupVariables getVariables() {
return variables;
}
/**
*
* @param varList
*/
public void setVariables(Map<String, Object> varList) {
if (!isGlobal()) {
GroupVariables temp = new GroupVariables(this, varList);
variables.clearVars();
for (String key : temp.getVarKeyList()) {
variables.addVar(key, temp.getVarObject(key));
}
flagAsChanged();
if (GroupManager.isLoaded()) {
GroupManager.BukkitPermissions.updateAllPlayers();
GroupManager.getGMEventHandler().callEvent(this, Action.GROUP_INFO_CHANGED);
}
}
}
}

97
src/main/java/org/anjocaido/groupmanager/data/GroupVariables.java

@ -0,0 +1,97 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.anjocaido.groupmanager.data;
import java.util.Map;
/**
*
* @author gabrielcouto
*/
public class GroupVariables extends Variables implements Cloneable {
private Group owner;
public GroupVariables(Group owner) {
super(owner);
this.owner = owner;
addVar("prefix", "");
addVar("suffix", "");
addVar("build", false);
}
public GroupVariables(Group owner, Map<String, Object> varList) {
super(owner);
variables.clear();
variables.putAll(varList);
if (variables.get("prefix") == null) {
variables.put("prefix", "");
owner.flagAsChanged();
}
// thisGrp.prefix = infoNode.get("prefix").toString();
if (variables.get("suffix") == null) {
variables.put("suffix", "");
owner.flagAsChanged();
}
// thisGrp.suffix = infoNode.get("suffix").toString();
if (variables.get("build") == null) {
variables.put("build", false);
owner.flagAsChanged();
}
this.owner = owner;
}
/**
* A clone of all vars here.
*
* @return GroupVariables clone
*/
protected GroupVariables clone(Group newOwner) {
GroupVariables clone = new GroupVariables(newOwner);
synchronized (variables) {
for (String key : variables.keySet()) {
clone.variables.put(key, variables.get(key));
}
}
newOwner.flagAsChanged();
return clone;
}
/**
* Remove a var from the list
*
* @param name
*/
@Override
public void removeVar(String name) {
try {
this.variables.remove(name);
} catch (Exception e) {
}
if (name.equals("prefix")) {
addVar("prefix", "");
} else if (name.equals("suffix")) {
addVar("suffix", "");
} else if (name.equals("build")) {
addVar("build", false);
}
owner.flagAsChanged();
}
/**
* @return the owner
*/
@Override
public Group getOwner() {
return owner;
}
}

323
src/main/java/org/anjocaido/groupmanager/data/User.java

@ -0,0 +1,323 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.anjocaido.groupmanager.data;
// import com.sun.org.apache.bcel.internal.generic.AALOAD;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.events.GMUserEvent.Action;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
/**
*
* @author gabrielcouto/ElgarL
*/
public class User extends DataUnit implements Cloneable {
/**
*
*/
private String group = null;
private final List<String> subGroups = Collections.synchronizedList(new ArrayList<String>());
/**
* This one holds the fields in INFO node. like prefix = 'c' or build =
* false
*/
private UserVariables variables = new UserVariables(this);
private transient Player bukkitPlayer = null;
/**
*
* @param name
*/
public User(WorldDataHolder source, String name) {
super(source, name);
this.group = source.getDefaultGroup().getName();
}
/**
*
* @return User clone
*/
@Override
public User clone() {
User clone = new User(getDataSource(), this.getLastName());
clone.group = this.group;
// Clone all subgroups.
clone.subGroups.addAll(this.subGroupListStringCopy());
for (String perm : this.getPermissionList()) {
clone.addPermission(perm);
}
// clone.variables = this.variables.clone();
// clone.flagAsChanged();
return clone;
}
/**
* Use this to deliver a user from one WorldDataHolder to another
*
* @param dataSource
* @return null if given dataSource already contains the same user
*/
public User clone(WorldDataHolder dataSource) {
if (dataSource.isUserDeclared(this.getUUID())) {
return null;
}
User clone = dataSource.createUser(this.getUUID());
if (dataSource.getGroup(group) == null) {
clone.setGroup(dataSource.getDefaultGroup());
} else {
clone.setGroup(dataSource.getGroup(this.getGroupName()));
}
// Clone all subgroups.
clone.subGroups.addAll(this.subGroupListStringCopy());
for (String perm : this.getPermissionList()) {
clone.addPermission(perm);
}
clone.variables = this.variables.clone(this);
clone.flagAsChanged();
return clone;
}
public User clone(String uUID, String CurrentName) {
User clone = this.getDataSource().createUser(uUID);
clone.setLastName(CurrentName);
// Set the group silently.
clone.setGroup(this.getDataSource().getGroup(this.getGroupName()), false);
// Clone all subgroups.
clone.subGroups.addAll(this.subGroupListStringCopy());
for (String perm : this.getPermissionList()) {
clone.addPermission(perm);
}
clone.variables = this.variables.clone(this);
clone.flagAsChanged();
return clone;
}
public Group getGroup() {
Group result = getDataSource().getGroup(group);
if (result == null) {
this.setGroup(getDataSource().getDefaultGroup());
result = getDataSource().getDefaultGroup();
}
return result;
}
/**
* @return the group
*/
public String getGroupName() {
Group result = getDataSource().getGroup(group);
if (result == null) {
group = getDataSource().getDefaultGroup().getName();
}
return group;
}
/**
* Place holder to let people know to stop using this method.
*
* @deprecated use {@link #getLastName()} and {@link #getUUID()}.
* @return a string containing the players last known name.
*/
@Deprecated
public String getName() {
return this.getLastName();
}
/**
* @param group
* the group to set
*/
public void setGroup(Group group) {
setGroup(group, true);
}
/**
* @param group
* the group to set
* @param updatePerms
* if we are to trigger a superperms update.
*
*/
public void setGroup(Group group, Boolean updatePerms) {
if (!this.getDataSource().groupExists(group.getName())) {
getDataSource().addGroup(group);
}
group = getDataSource().getGroup(group.getName());
String oldGroup = this.group;
this.group = group.getName();
flagAsChanged();
if (GroupManager.isLoaded()) {
if (!GroupManager.BukkitPermissions.isPlayer_join() && (updatePerms))
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
// Do we notify of the group change?
String defaultGroupName = getDataSource().getDefaultGroup().getName();
// if we were not in the default group
// or we were in the default group and the move is to a different
// group.
boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName)));
if (notify)
GroupManager.notify(this.getLastName(), String.format(" moved to the group %s in %s.", group.getName(), this.getDataSource().getName()));
if (updatePerms)
GroupManager.getGMEventHandler().callEvent(this, Action.USER_GROUP_CHANGED);
}
}
public boolean addSubGroup(Group subGroup) {
// Don't allow adding a subgroup if it's already set as the primary.
if (this.group.equalsIgnoreCase(subGroup.getName())) {
return false;
}
// User already has this subgroup
if (containsSubGroup(subGroup))
return false;
// If the group doesn't exists add it
if (!this.getDataSource().groupExists(subGroup.getName())) {
getDataSource().addGroup(subGroup);
}
subGroups.add(subGroup.getName());
flagAsChanged();
if (GroupManager.isLoaded()) {
if (!GroupManager.BukkitPermissions.isPlayer_join())
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
GroupManager.getGMEventHandler().callEvent(this, Action.USER_SUBGROUP_CHANGED);
}
return true;
// subGroup = getDataSource().getGroup(subGroup.getName());
// removeSubGroup(subGroup);
// subGroups.add(subGroup.getName());
}
public int subGroupsSize() {
return subGroups.size();