mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-20 18:32:49 +00:00
Update all code formatting to use tabs for indentation.
This commit is contained in:
parent
677534c0b7
commit
a028abe036
|
@ -177,3 +177,4 @@ v 2.0:
|
|||
- Expand GlobalGroups.yml and groups.yml to cover the VanishNoPacket plugin. Demonstrating how to negate and add nodes when using the '*' permission with inheritance.
|
||||
- Fix silly nested throw/catch statements. Errors are now correctly generated when reading yml's.
|
||||
- Unregister the worldsHolder as a service on a reload/shutdown instead of the whole plugin.
|
||||
- Update all code formatting to use tabs for indentation.
|
|
@ -18,76 +18,84 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||
*/
|
||||
public class GMConfiguration {
|
||||
|
||||
private GroupManager plugin;
|
||||
private File configFile;
|
||||
private YamlConfiguration GMconfig;
|
||||
private GroupManager plugin;
|
||||
private File configFile;
|
||||
private YamlConfiguration GMconfig;
|
||||
|
||||
public GMConfiguration(GroupManager plugin) {
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
}
|
||||
public GMConfiguration(GroupManager plugin) {
|
||||
|
||||
public void load() {
|
||||
if (!plugin.getDataFolder().exists()) {
|
||||
plugin.getDataFolder().mkdirs();
|
||||
}
|
||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
}
|
||||
|
||||
if (!configFile.exists()) {
|
||||
try {
|
||||
Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile);
|
||||
} catch (IOException ex) {
|
||||
GroupManager.logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
public void load() {
|
||||
|
||||
GMconfig = new YamlConfiguration();
|
||||
if (!plugin.getDataFolder().exists()) {
|
||||
plugin.getDataFolder().mkdirs();
|
||||
}
|
||||
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
|
||||
try {
|
||||
GMconfig.load(configFile);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
|
||||
}
|
||||
if (!configFile.exists()) {
|
||||
try {
|
||||
Tasks.copy(plugin.getResourceAsStream("config.yml"), configFile);
|
||||
} catch (IOException ex) {
|
||||
GroupManager.logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup defaults
|
||||
adjustLoggerLevel();
|
||||
plugin.setValidateOnlinePlayer(isToggleValidate());
|
||||
}
|
||||
GMconfig = new YamlConfiguration();
|
||||
|
||||
public boolean isOpOverride() {
|
||||
return GMconfig.getBoolean("settings.config.opOverrides", true);
|
||||
}
|
||||
public boolean isToggleValidate() {
|
||||
return GMconfig.getBoolean("settings.config.validate_toggle", true);
|
||||
}
|
||||
try {
|
||||
GMconfig.load(configFile);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
|
||||
}
|
||||
|
||||
// Setup defaults
|
||||
adjustLoggerLevel();
|
||||
plugin.setValidateOnlinePlayer(isToggleValidate());
|
||||
}
|
||||
|
||||
public boolean isOpOverride() {
|
||||
|
||||
return GMconfig.getBoolean("settings.config.opOverrides", true);
|
||||
}
|
||||
|
||||
public boolean isToggleValidate() {
|
||||
|
||||
return GMconfig.getBoolean("settings.config.validate_toggle", true);
|
||||
}
|
||||
|
||||
public Map<String, Object> getMirrorsMap() {
|
||||
// Try to fetch the old mirror path first
|
||||
|
||||
// Try to fetch the old mirror path first
|
||||
if (GMconfig.isConfigurationSection("settings.permission.world.mirror")) {
|
||||
return (Map<String, Object>) GMconfig.getConfigurationSection("settings.permission.world.mirror").getValues(false);
|
||||
} else if (GMconfig.isConfigurationSection("settings.mirrors")){
|
||||
} else if (GMconfig.isConfigurationSection("settings.mirrors")) {
|
||||
return (Map<String, Object>) GMconfig.getConfigurationSection("settings.mirrors").getValues(false);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getSaveInterval() {
|
||||
return GMconfig.getInt("settings.data.save.minutes", 10);
|
||||
}
|
||||
public Integer getSaveInterval() {
|
||||
|
||||
public Integer getBackupDuration() {
|
||||
return GMconfig.getInt("settings.data.save.hours", 24);
|
||||
}
|
||||
return GMconfig.getInt("settings.data.save.minutes", 10);
|
||||
}
|
||||
|
||||
public void adjustLoggerLevel() {
|
||||
public Integer getBackupDuration() {
|
||||
|
||||
try {
|
||||
GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO")));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return GMconfig.getInt("settings.data.save.hours", 24);
|
||||
}
|
||||
|
||||
GroupManager.logger.setLevel(Level.INFO);
|
||||
}
|
||||
public void adjustLoggerLevel() {
|
||||
|
||||
try {
|
||||
GroupManager.logger.setLevel(Level.parse(GMconfig.getString("settings.logging.level", "INFO")));
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
GroupManager.logger.setLevel(Level.INFO);
|
||||
}
|
||||
}
|
|
@ -24,8 +24,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author ElgarL
|
||||
*
|
||||
|
@ -42,6 +40,7 @@ public class GlobalGroups {
|
|||
protected File GlobalGroupsFile = null;
|
||||
|
||||
public GlobalGroups(GroupManager plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
}
|
||||
|
@ -50,6 +49,7 @@ public class GlobalGroups {
|
|||
* @return the haveGroupsChanged
|
||||
*/
|
||||
public boolean haveGroupsChanged() {
|
||||
|
||||
if (this.haveGroupsChanged) {
|
||||
return true;
|
||||
}
|
||||
|
@ -65,12 +65,15 @@ public class GlobalGroups {
|
|||
* @return the timeStampGroups
|
||||
*/
|
||||
public long getTimeStampGroups() {
|
||||
|
||||
return timeStampGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeStampGroups the timeStampGroups to set
|
||||
*/
|
||||
protected void setTimeStampGroups(long timeStampGroups) {
|
||||
|
||||
this.timeStampGroups = timeStampGroups;
|
||||
}
|
||||
|
||||
|
@ -79,6 +82,7 @@ public class GlobalGroups {
|
|||
* the haveGroupsChanged to set
|
||||
*/
|
||||
public void setGroupsChanged(boolean haveGroupsChanged) {
|
||||
|
||||
this.haveGroupsChanged = haveGroupsChanged;
|
||||
}
|
||||
|
||||
|
@ -118,34 +122,34 @@ public class GlobalGroups {
|
|||
try {
|
||||
allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
|
||||
} catch (Exception ex) {
|
||||
//ex.printStackTrace();
|
||||
throw new IllegalArgumentException("Your " + GlobalGroupsFile.getPath() + " file is invalid. See console for details.", 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;
|
||||
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) {
|
||||
/*
|
||||
* 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());
|
||||
/*
|
||||
* Create a new group with this name.
|
||||
*/
|
||||
Group newGroup = new Group(groupName.toLowerCase());
|
||||
Object element;
|
||||
|
||||
// Permission nodes
|
||||
|
@ -172,8 +176,8 @@ public class GlobalGroups {
|
|||
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));
|
||||
}
|
||||
vars.put(key, ((MemorySection) element).get(key));
|
||||
}
|
||||
newGroup.setVariables(vars);
|
||||
} else
|
||||
throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName);
|
||||
|
@ -188,7 +192,7 @@ public class GlobalGroups {
|
|||
|
||||
setTimeStampGroups(GlobalGroupsFile.lastModified());
|
||||
GroupManager.setLoaded(true);
|
||||
//GlobalGroupsFile = null;
|
||||
// GlobalGroupsFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +201,7 @@ public class GlobalGroups {
|
|||
|
||||
public void writeGroups(boolean overwrite) {
|
||||
|
||||
//File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
|
||||
// File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
|
||||
|
||||
if (haveGroupsChanged()) {
|
||||
if (overwrite || (!overwrite && (getTimeStampGroups() >= GlobalGroupsFile.lastModified()))) {
|
||||
|
@ -214,13 +218,13 @@ public class GlobalGroups {
|
|||
|
||||
// Info nodes
|
||||
Map<String, Object> infoMap = new HashMap<String, Object>();
|
||||
aGroupMap.put("info", infoMap);
|
||||
aGroupMap.put("info", infoMap);
|
||||
|
||||
for (String infoKey : group.getVariables().getVarKeyList()) {
|
||||
infoMap.put(infoKey, group.getVariables().getVarObject(infoKey));
|
||||
}
|
||||
for (String infoKey : group.getVariables().getVarKeyList()) {
|
||||
infoMap.put(infoKey, group.getVariables().getVarObject(infoKey));
|
||||
}
|
||||
|
||||
// Permission nodes
|
||||
// Permission nodes
|
||||
aGroupMap.put("permissions", group.getPermissionList());
|
||||
}
|
||||
|
||||
|
@ -236,36 +240,37 @@ public class GlobalGroups {
|
|||
}
|
||||
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'");
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
// 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() {
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
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.
|
||||
|
@ -273,6 +278,7 @@ public class GlobalGroups {
|
|||
* @param groupToAdd
|
||||
*/
|
||||
public void addGroup(Group groupToAdd) {
|
||||
|
||||
// Create a new group if it already exists
|
||||
if (hasGroup(groupToAdd.getName())) {
|
||||
groupToAdd = groupToAdd.clone();
|
||||
|
@ -280,9 +286,9 @@ public class GlobalGroups {
|
|||
}
|
||||
|
||||
newGroup(groupToAdd);
|
||||
haveGroupsChanged = true;
|
||||
if (GroupManager.isLoaded())
|
||||
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
|
||||
haveGroupsChanged = true;
|
||||
if (GroupManager.isLoaded())
|
||||
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,6 +297,7 @@ public class GlobalGroups {
|
|||
* @param newGroup
|
||||
*/
|
||||
public Group newGroup(Group newGroup) {
|
||||
|
||||
// Push a new group
|
||||
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
|
||||
groups.put(newGroup.getName().toLowerCase(), newGroup);
|
||||
|
@ -306,6 +313,7 @@ public class GlobalGroups {
|
|||
* @param groupName
|
||||
*/
|
||||
public boolean removeGroup(String groupName) {
|
||||
|
||||
// Push a new group
|
||||
if (groups.containsKey(groupName.toLowerCase())) {
|
||||
groups.remove(groupName.toLowerCase());
|
||||
|
@ -324,6 +332,7 @@ public class GlobalGroups {
|
|||
* @return true if the group exists
|
||||
*/
|
||||
public boolean hasGroup(String groupName) {
|
||||
|
||||
return groups.containsKey(groupName.toLowerCase());
|
||||
}
|
||||
|
||||
|
@ -379,6 +388,7 @@ public class GlobalGroups {
|
|||
* @return List of all group names
|
||||
*/
|
||||
public List<String> getGroupsPermissions(String groupName) {
|
||||
|
||||
if (!hasGroup(groupName))
|
||||
return null;
|
||||
|
||||
|
@ -391,6 +401,7 @@ public class GlobalGroups {
|
|||
* @return Set containing all group names.
|
||||
*/
|
||||
public Set<String> getGlobalGroups() {
|
||||
|
||||
return groups.keySet();
|
||||
}
|
||||
|
||||
|
@ -398,6 +409,7 @@ public class GlobalGroups {
|
|||
* Resets GlobalGroups.
|
||||
*/
|
||||
public void resetGlobalGroups() {
|
||||
|
||||
this.groups = new HashMap<String, Group>();
|
||||
}
|
||||
|
||||
|
@ -406,6 +418,7 @@ public class GlobalGroups {
|
|||
* @return a collection of the groups
|
||||
*/
|
||||
public Collection<Group> getGroupList() {
|
||||
|
||||
return groups.values();
|
||||
}
|
||||
|
||||
|
@ -416,6 +429,7 @@ public class GlobalGroups {
|
|||
* @return Group object
|
||||
*/
|
||||
public Group getGroup(String groupName) {
|
||||
|
||||
if (!hasGroup(groupName))
|
||||
return null;
|
||||
|
||||
|
@ -427,17 +441,19 @@ public class GlobalGroups {
|
|||
* @return the globalGroupsFile
|
||||
*/
|
||||
public File getGlobalGroupsFile() {
|
||||
|
||||
return GlobalGroupsFile;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void removeGroupsChangedFlag() {
|
||||
setGroupsChanged(false);
|
||||
for (Group g : groups.values()) {
|
||||
g.flagAsSaved();
|
||||
}
|
||||
}
|
||||
public void removeGroupsChangedFlag() {
|
||||
|
||||
setGroupsChanged(false);
|
||||
for (Group g : groups.values()) {
|
||||
g.flagAsSaved();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -45,7 +45,6 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
/**
|
||||
*
|
||||
|
@ -68,6 +67,7 @@ public class GroupManager extends JavaPlugin {
|
|||
* @return the validateOnlinePlayer
|
||||
*/
|
||||
public boolean isValidateOnlinePlayer() {
|
||||
|
||||
return validateOnlinePlayer;
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,7 @@ public class GroupManager extends JavaPlugin {
|
|||
* @param validateOnlinePlayer the validateOnlinePlayer to set
|
||||
*/
|
||||
public void setValidateOnlinePlayer(boolean validateOnlinePlayer) {
|
||||
|
||||
this.validateOnlinePlayer = validateOnlinePlayer;
|
||||
}
|
||||
|
||||
|
@ -95,6 +96,7 @@ public class GroupManager extends JavaPlugin {
|
|||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
setLoaded(false);
|
||||
|
||||
// Un-register this service.
|
||||
|
@ -117,14 +119,13 @@ public class GroupManager extends JavaPlugin {
|
|||
BukkitPermissions = null;
|
||||
}
|
||||
|
||||
// EXAMPLE: Custom code, here we just output some info so we can check that
|
||||
// all is well
|
||||
// EXAMPLE: Custom code, here we just output some info so we can check that all is well
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
|
||||
GroupManager.logger.removeHandler(ch);
|
||||
}
|
||||
|
||||
//@Override
|
||||
// @Override
|
||||
public void onEnable() {
|
||||
|
||||
try {
|
||||
|
@ -143,7 +144,6 @@ public class GroupManager extends JavaPlugin {
|
|||
globalGroups = new GlobalGroups(this);
|
||||
worldsHolder = new WorldsHolder(this);
|
||||
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
if (worldsHolder == null) {
|
||||
GroupManager.logger.severe("Can't enable " + pdfFile.getName() + " version " + pdfFile.getVersion() + ", bad loading!");
|
||||
|
@ -154,15 +154,15 @@ public class GroupManager extends JavaPlugin {
|
|||
// Set a few defaults (reloads)
|
||||
setLoaded(false);
|
||||
|
||||
// Initialize the world listener and bukkit permissions to handle
|
||||
// events.
|
||||
// Initialize the world listener and bukkit permissions to handle events.
|
||||
WorldEvents = new GMWorldListener(this);
|
||||
BukkitPermissions = new BukkitPermissions(this);
|
||||
|
||||
enableScheduler();
|
||||
|
||||
/*
|
||||
* Schedule a Bukiit Permissions update for 1 tick later. All plugins
|
||||
* Schedule a Bukiit Permissions update for 1 tick later. All
|
||||
* plugins
|
||||
* will be loaded by then
|
||||
*/
|
||||
|
||||
|
@ -185,7 +185,7 @@ public class GroupManager extends JavaPlugin {
|
|||
/*
|
||||
* Throw an error so Bukkit knows about it.
|
||||
*/
|
||||
throw new IllegalArgumentException(ex.getMessage(),ex);
|
||||
throw new IllegalArgumentException(ex.getMessage(), ex);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -198,8 +198,8 @@ public class GroupManager extends JavaPlugin {
|
|||
private void saveErrorLog(Exception ex) {
|
||||
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdirs();
|
||||
}
|
||||
getDataFolder().mkdirs();
|
||||
}
|
||||
|
||||
lastError = ex.getMessage();
|
||||
|
||||
|
@ -215,10 +215,10 @@ public class GroupManager extends JavaPlugin {
|
|||
GroupManager.logger.severe("===================================================");
|
||||
|
||||
// Append this error to the error log.
|
||||
try {
|
||||
String error = "=============================== GM ERROR LOG ===============================\n\n";
|
||||
error += Tasks.getStackTraceAsString(ex);
|
||||
error += "\n============================================================================\n";
|
||||
try {
|
||||
String error = "=============================== GM ERROR LOG ===============================\n\n";
|
||||
error += Tasks.getStackTraceAsString(ex);
|
||||
error += "\n============================================================================\n";
|
||||
|
||||
Tasks.appendStringToFile(error, (getDataFolder() + System.getProperty("file.separator") + "ERROR.LOG"));
|
||||
} catch (IOException e) {
|
||||
|
@ -229,18 +229,22 @@ public class GroupManager extends JavaPlugin {
|
|||
}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
public static void setLoaded(boolean isLoaded) {
|
||||
|
||||
GroupManager.isLoaded = isLoaded;
|
||||
}
|
||||
|
||||
public InputStream getResourceAsStream(String fileName) {
|
||||
|
||||
return this.getClassLoader().getResourceAsStream(fileName);
|
||||
}
|
||||
|
||||
private void prepareFileFields() {
|
||||
|
||||
// configFile = new File(this.getDataFolder(), "config.yml");
|
||||
backupFolder = new File(this.getDataFolder(), "backup");
|
||||
if (!backupFolder.exists()) {
|
||||
|
@ -249,16 +253,19 @@ public class GroupManager extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void prepareConfig() {
|
||||
|
||||
config = new GMConfiguration(this);
|
||||
}
|
||||
|
||||
public void enableScheduler() {
|
||||
|
||||
if (worldsHolder != null) {
|
||||
disableScheduler();
|
||||
commiter = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
worldsHolder.saveChanges(false);
|
||||
GroupManager.logger.log(Level.INFO, " Data files refreshed.");
|
||||
|
@ -268,9 +275,9 @@ public class GroupManager extends JavaPlugin {
|
|||
}
|
||||
};
|
||||
scheduler = new ScheduledThreadPoolExecutor(1);
|
||||
long minutes = (long)getGMConfig().getSaveInterval();
|
||||
long minutes = (long) getGMConfig().getSaveInterval();
|
||||
if (minutes > 0) {
|
||||
scheduler.scheduleAtFixedRate(commiter, minutes, minutes, TimeUnit.MINUTES);
|
||||
scheduler.scheduleAtFixedRate(commiter, minutes, minutes, TimeUnit.MINUTES);
|
||||
GroupManager.logger.info("Scheduled Data Saving is set for every " + minutes + " minutes!");
|
||||
} else
|
||||
GroupManager.logger.info("Scheduled Data Saving is Disabled!");
|
||||
|
@ -280,6 +287,7 @@ public class GroupManager extends JavaPlugin {
|
|||
}
|
||||
|
||||
public void disableScheduler() {
|
||||
|
||||
if (scheduler != null) {
|
||||
try {
|
||||
scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
|
||||
|
@ -297,6 +305,7 @@ public class GroupManager extends JavaPlugin {
|
|||
*/
|
||||
@Deprecated
|
||||
public void commit() {
|
||||
|
||||
if (worldsHolder != null) {
|
||||
worldsHolder.saveChanges();
|
||||
}
|
||||
|
@ -307,10 +316,12 @@ public class GroupManager extends JavaPlugin {
|
|||
*/
|
||||
@Deprecated
|
||||
public void reload() {
|
||||
|
||||
worldsHolder.reloadAll();
|
||||
}
|
||||
|
||||
public WorldsHolder getWorldsHolder() {
|
||||
|
||||
return worldsHolder;
|
||||
}
|
||||
|
||||
|
@ -321,6 +332,7 @@ public class GroupManager extends JavaPlugin {
|
|||
*/
|
||||
@Deprecated
|
||||
public AnjoPermissionsHandler getPermissionHandler() {
|
||||
|
||||
return worldsHolder.getDefaultWorld().getPermissionsHandler();
|
||||
}
|
||||
|
||||
|
@ -332,6 +344,7 @@ public class GroupManager extends JavaPlugin {
|
|||
*/
|
||||
@Deprecated
|
||||
public WorldDataHolder getData() {
|
||||
|
||||
return worldsHolder.getDefaultWorld();
|
||||
}
|
||||
|
||||
|
@ -342,6 +355,7 @@ public class GroupManager extends JavaPlugin {
|
|||
*/
|
||||
@Deprecated
|
||||
public OverloadedWorldHolder getOverloadedClassData() {
|
||||
|
||||
return worldsHolder.getDefaultWorld();
|
||||
}
|
||||
|
||||
|
@ -355,6 +369,7 @@ public class GroupManager extends JavaPlugin {
|
|||
@SuppressWarnings({ "deprecation" })
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
|
||||
boolean playerCanDo = false;
|
||||
boolean isConsole = false;
|
||||
Player senderPlayer = null, targetPlayer = null;
|
||||
|
@ -362,7 +377,6 @@ public class GroupManager extends JavaPlugin {
|
|||
User senderUser = null;
|
||||
boolean isOpOverride = config.isOpOverride();
|
||||
|
||||
|
||||
// DETERMINING PLAYER INFORMATION
|
||||
if (sender instanceof Player) {
|
||||
senderPlayer = (Player) sender;
|
||||
|
@ -471,7 +485,7 @@ public class GroupManager extends JavaPlugin {
|
|||
}
|
||||
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -522,7 +536,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -561,7 +575,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -599,7 +613,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -622,9 +636,9 @@ public class GroupManager extends JavaPlugin {
|
|||
auxUser.removeSubGroup(auxGroup);
|
||||
sender.sendMessage(ChatColor.YELLOW + "You removed subgroup '" + auxGroup.getName() + "' from player '" + auxUser.getName() + "' list.");
|
||||
|
||||
//targetPlayer = this.getServer().getPlayer(auxUser.getName());
|
||||
//if (targetPlayer != null)
|
||||
// BukkitPermissions.updatePermissions(targetPlayer);
|
||||
// targetPlayer = this.getServer().getPlayer(auxUser.getName());
|
||||
// if (targetPlayer != null)
|
||||
// BukkitPermissions.updatePermissions(targetPlayer);
|
||||
|
||||
return true;
|
||||
|
||||
|
@ -686,7 +700,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -751,7 +765,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -803,7 +817,7 @@ public class GroupManager extends JavaPlugin {
|
|||
}
|
||||
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -868,7 +882,7 @@ public class GroupManager extends JavaPlugin {
|
|||
}
|
||||
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -881,7 +895,7 @@ public class GroupManager extends JavaPlugin {
|
|||
permissionResult = permissionHandler.checkFullGMPermission(auxUser, args[1], false);
|
||||
|
||||
if (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
|
||||
//No permissions found in GM so fall through and check Bukkit.
|
||||
// No permissions found in GM so fall through and check Bukkit.
|
||||
sender.sendMessage(ChatColor.RED + "The player doesn't have access to that permission");
|
||||
|
||||
} else {
|
||||
|
@ -1078,8 +1092,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
// Seems OK
|
||||
// auxString =
|
||||
// permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
|
||||
// auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
|
||||
if (permissionResult.owner instanceof Group) {
|
||||
if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
|
||||
sender.sendMessage(ChatColor.RED + "The group inherits the a negation permission from group: " + permissionResult.owner.getName());
|
||||
|
@ -1185,7 +1198,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -1219,7 +1232,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (match != null) {
|
||||
|
@ -1249,7 +1262,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (match != null) {
|
||||
auxUser = dataHolder.getUser(match.get(0));
|
||||
|
@ -1284,7 +1297,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (match != null) {
|
||||
auxUser = dataHolder.getUser(match.get(0));
|
||||
|
@ -1300,7 +1313,8 @@ public class GroupManager extends JavaPlugin {
|
|||
if (!auxUser.isSubGroupsEmpty() && auxGroup2 == null)
|
||||
for (Group subGroup : auxUser.subGroupListCopy()) {
|
||||
auxGroup2 = permissionHandler.nextGroupWithVariable(subGroup, args[1]);
|
||||
if (auxGroup2 != null) continue;
|
||||
if (auxGroup2 != null)
|
||||
continue;
|
||||
}
|
||||
if (auxGroup2 == null) {
|
||||
sender.sendMessage(ChatColor.RED + "The user doesn't have access to that variable!");
|
||||
|
@ -1471,7 +1485,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (match != null) {
|
||||
auxUser = dataHolder.getUser(match.get(0));
|
||||
|
@ -1511,7 +1525,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (match != null) {
|
||||
auxUser = dataHolder.getUser(match.get(0));
|
||||
|
@ -1545,7 +1559,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (match != null) {
|
||||
auxUser = dataHolder.getUser(match.get(0));
|
||||
|
@ -1693,7 +1707,7 @@ public class GroupManager extends JavaPlugin {
|
|||
* Fire an event as none will have been triggered in the reload.
|
||||
*/
|
||||
if (GroupManager.isLoaded())
|
||||
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED);
|
||||
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED);
|
||||
|
||||
return true;
|
||||
|
||||
|
@ -1730,7 +1744,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (match != null) {
|
||||
auxUser = dataHolder.getUser(match.get(0));
|
||||
|
@ -1786,7 +1800,7 @@ public class GroupManager extends JavaPlugin {
|
|||
return false;
|
||||
}
|
||||
if ((validateOnlinePlayer) && ((match = validatePlayer(args[0], sender)) == null)) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
if (match != null) {
|
||||
auxUser = dataHolder.getUser(match.get(0));
|
||||
|
@ -1974,7 +1988,7 @@ public class GroupManager extends JavaPlugin {
|
|||
if (Arrays.asList(this.getServer().getOfflinePlayers()).contains(Bukkit.getOfflinePlayer(playerName))) {
|
||||
match.add(playerName);
|
||||
} else {
|
||||
//look for partial matches
|
||||
// look for partial matches
|
||||
for (OfflinePlayer offline : this.getServer().getOfflinePlayers()) {
|
||||
if (offline.getName().toLowerCase().startsWith(playerName.toLowerCase()))
|
||||
match.add(offline.getName());
|
||||
|
@ -2003,6 +2017,7 @@ public class GroupManager extends JavaPlugin {
|
|||
* @return the config
|
||||
*/
|
||||
public GMConfiguration getGMConfig() {
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -2010,10 +2025,12 @@ public class GroupManager extends JavaPlugin {
|
|||
* @return the backupFolder
|
||||
*/
|
||||
public File getBackupFolder() {
|
||||
|
||||
return backupFolder;
|
||||
}
|
||||
|
||||
public static GlobalGroups getGlobalGroups() {
|
||||
|
||||
return globalGroups;
|
||||
|
||||
}
|
||||
|
|
|
@ -5,17 +5,18 @@ import org.anjocaido.groupmanager.GroupManager;
|
|||
/*
|
||||
*
|
||||
* Created by ElgarL
|
||||
*
|
||||
*/
|
||||
|
||||
public class BukkitPermsUpdateTask implements Runnable {
|
||||
|
||||
public BukkitPermsUpdateTask() {
|
||||
super();
|
||||
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// Signal loaded and update BukkitPermissions.
|
||||
GroupManager.setLoaded(true);
|
||||
GroupManager.BukkitPermissions.collectPermissions();
|
||||
|
|
|
@ -18,146 +18,164 @@ import org.anjocaido.groupmanager.utils.StringPermissionComparator;
|
|||
*/
|
||||
public abstract class DataUnit {
|
||||
|
||||
private WorldDataHolder dataSource;
|
||||
private String name;
|
||||
private boolean changed, sorted = false;
|
||||
private ArrayList<String> permissions = new ArrayList<String>();
|
||||
private WorldDataHolder dataSource;
|
||||
private String name;
|
||||
private boolean changed, sorted = false;
|
||||
private ArrayList<String> permissions = new ArrayList<String>();
|
||||
|
||||
public DataUnit(WorldDataHolder dataSource, String name) {
|
||||
this.dataSource = dataSource;
|
||||
this.name = name;
|
||||
}
|
||||
public DataUnit(WorldDataHolder dataSource, String name) {
|
||||
|
||||
public DataUnit(String name) {
|
||||
this.name = name;
|
||||
this.dataSource = dataSource;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DataUnit(String name) {
|
||||
|
||||
this.name = 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.getName().equalsIgnoreCase(go.getName())) {
|
||||
// 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;
|
||||
}
|
||||
* 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) {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 71 * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
if (o instanceof DataUnit) {
|
||||
DataUnit go = (DataUnit) o;
|
||||
if (this.getName().equalsIgnoreCase(go.getName())) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data source to point to a different worldDataHolder
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public void setDataSource(WorldDataHolder source) {
|
||||
this.dataSource = source;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
/**
|
||||
* Get the current worldDataHolder this object is pointing to
|
||||
*
|
||||
* @return the dataSource
|
||||
*/
|
||||
public WorldDataHolder getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
int hash = 5;
|
||||
hash = 71 * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* Set the data source to point to a different worldDataHolder
|
||||
*
|
||||
* @param source
|
||||
*/
|
||||
public void setDataSource(WorldDataHolder source) {
|
||||
|
||||
public void flagAsChanged() {
|
||||
WorldDataHolder testSource = getDataSource();
|
||||
String source = "";
|
||||
this.dataSource = source;
|
||||
}
|
||||
|
||||
if (testSource == null)
|
||||
source = "GlobalGroups";
|
||||
else
|
||||
source = testSource.getName();
|
||||
/**
|
||||
* Get the current worldDataHolder this object is pointing to
|
||||
*
|
||||
* @return the dataSource
|
||||
*/
|
||||
public WorldDataHolder getDataSource() {
|
||||
|
||||
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!");
|
||||
// for(StackTraceElement st: Thread.currentThread().getStackTrace()){
|
||||
// GroupManager.logger.finest(st.toString());
|
||||
// }
|
||||
sorted = false;
|
||||
changed = true;
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
public boolean isChanged() {
|
||||
return changed;
|
||||
}
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
|
||||
public void flagAsSaved() {
|
||||
WorldDataHolder testSource = getDataSource();
|
||||
String source = "";
|
||||
return name;
|
||||
}
|
||||
|
||||
if (testSource == null)
|
||||
source = "GlobalGroups";
|
||||
else
|
||||
source = testSource.getName();
|
||||
public void flagAsChanged() {
|
||||
|
||||
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as saved!");
|
||||
changed = false;
|
||||
}
|
||||
WorldDataHolder testSource = getDataSource();
|
||||
String source = "";
|
||||
|
||||
public boolean hasSamePermissionNode(String permission) {
|
||||
return permissions.contains(permission);
|
||||
}
|
||||
if (testSource == null)
|
||||
source = "GlobalGroups";
|
||||
else
|
||||
source = testSource.getName();
|
||||
|
||||
public void addPermission(String permission) {
|
||||
if (!hasSamePermissionNode(permission)) {
|
||||
permissions.add(permission);
|
||||
}
|
||||
flagAsChanged();
|
||||
}
|
||||
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!");
|
||||
// for(StackTraceElement st: Thread.currentThread().getStackTrace()){
|
||||
// GroupManager.logger.finest(st.toString());
|
||||
// }
|
||||
sorted = false;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
public boolean removePermission(String permission) {
|
||||
flagAsChanged();
|
||||
return permissions.remove(permission);
|
||||
}
|
||||
public boolean isChanged() {
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return Collections.unmodifiableList(permissions);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean isSorted() {
|
||||
return this.sorted;
|
||||
}
|
||||
public void flagAsSaved() {
|
||||
|
||||
public void sortPermissions() {
|
||||
if (!isSorted()) {
|
||||
Collections.sort(permissions, StringPermissionComparator.getInstance());
|
||||
sorted = true;
|
||||
}
|
||||
}
|
||||
WorldDataHolder testSource = getDataSource();
|
||||
String source = "";
|
||||
|
||||
if (testSource == null)
|
||||
source = "GlobalGroups";
|
||||
else
|
||||
source = testSource.getName();
|
||||
|
||||
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as saved!");
|
||||
changed = false;
|
||||
}
|
||||
|
||||
public boolean hasSamePermissionNode(String permission) {
|
||||
|
||||
return permissions.contains(permission);
|
||||
}
|
||||
|
||||
public void addPermission(String permission) {
|
||||
|
||||
if (!hasSamePermissionNode(permission)) {
|
||||
permissions.add(permission);
|
||||
}
|
||||
flagAsChanged();
|
||||
}
|
||||
|
||||
public boolean removePermission(String permission) {
|
||||
|
||||
flagAsChanged();
|
||||
return permissions.remove(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
return Collections.unmodifiableList(permissions);
|
||||
}
|
||||
|
||||
public boolean isSorted() {
|
||||
|
||||
return this.sorted;
|
||||
}
|
||||
|
||||
public void sortPermissions() {
|
||||
|
||||
if (!isSorted()) {
|
||||
Collections.sort(permissions, StringPermissionComparator.getInstance());
|
||||
sorted = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,155 +20,168 @@ import java.util.Map;
|
|||
*/
|
||||
public class Group extends DataUnit implements Cloneable {
|
||||
|
||||
/**
|
||||
* The group it inherits DIRECTLY!
|
||||
*/
|
||||
private ArrayList<String> inherits = new ArrayList<String>();
|
||||
/**
|
||||
*This one holds the fields in INFO node.
|
||||
* like prefix = 'c'
|
||||
* or build = false
|
||||
*/
|
||||
private GroupVariables variables = new GroupVariables(this);
|
||||
/**
|
||||
* The group it inherits DIRECTLY!
|
||||
*/
|
||||
private ArrayList<String> inherits = new ArrayList<String>();
|
||||
/**
|
||||
* 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 individual World Groups.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public Group(WorldDataHolder source, String name) {
|
||||
|
||||
/**
|
||||
* Constructor for Global Groups.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public Group(String name) {
|
||||
super(name);
|
||||
}
|
||||
super(source, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a GlobalGroup
|
||||
*
|
||||
* @return true if this is a global group
|
||||
*/
|
||||
public boolean isGlobal() {
|
||||
return (getDataSource() == null);
|
||||
}
|
||||
/**
|
||||
* Constructor for Global Groups.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public Group(String name) {
|
||||
|
||||
/**
|
||||
* Clone this group
|
||||
* @return a clone of this group
|
||||
*/
|
||||
@Override
|
||||
public Group clone() {
|
||||
Group clone;
|
||||
super(name);
|
||||
}
|
||||
|
||||
if (isGlobal()) {
|
||||
clone = new Group(this.getName());
|
||||
} else {
|
||||
clone = new Group(getDataSource(), this.getName());
|
||||
clone.inherits = new ArrayList<String>(this.getInherits());
|
||||
}
|
||||
/**
|
||||
* Is this a GlobalGroup
|
||||
*
|
||||
* @return true if this is a global group
|
||||
*/
|
||||
public boolean isGlobal() {
|
||||
|
||||
for (String perm : this.getPermissionList()) {
|
||||
clone.addPermission(perm);
|
||||
}
|
||||
clone.variables = ((GroupVariables) variables).clone(clone);
|
||||
//clone.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
return (getDataSource() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
/**
|
||||
* Clone this group
|
||||
*
|
||||
* @return a clone of this group
|
||||
*/
|
||||
@Override
|
||||
public Group clone() {
|
||||
|
||||
Group clone = dataSource.createGroup(this.getName());
|
||||
Group clone;
|
||||
|
||||
// Don't add inheritance for GlobalGroups
|
||||
if (!isGlobal()) {
|
||||
clone.inherits = 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;
|
||||
}
|
||||
if (isGlobal()) {
|
||||
clone = new Group(this.getName());
|
||||
} else {
|
||||
clone = new Group(getDataSource(), this.getName());
|
||||
clone.inherits = new ArrayList<String>(this.getInherits());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Collections.unmodifiableList(inherits);
|
||||
}
|
||||
for (String perm : this.getPermissionList()) {
|
||||
clone.addPermission(perm);
|
||||
}
|
||||
clone.variables = ((GroupVariables) variables).clone(clone);
|
||||
//clone.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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())) {
|
||||
inherits.add(inherit.getName().toLowerCase());
|
||||
}
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded()) {
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Use this to deliver a group from a different dataSource to another
|
||||
*
|
||||
* @param dataSource
|
||||
* @return Null or Clone
|
||||
*/
|
||||
public Group clone(WorldDataHolder dataSource) {
|
||||
|
||||
public boolean removeInherits(String inherit) {
|
||||
if (!isGlobal()) {
|
||||
if (this.inherits.contains(inherit.toLowerCase())) {
|
||||
this.inherits.remove(inherit.toLowerCase());
|
||||
flagAsChanged();
|
||||
GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (dataSource.groupExists(this.getName())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the variables
|
||||
*/
|
||||
public GroupVariables getVariables() {
|
||||
return variables;
|
||||
}
|
||||
Group clone = dataSource.createGroup(this.getName());
|
||||
|
||||
/**
|
||||
*
|
||||
* @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();
|
||||
GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Don't add inheritance for GlobalGroups
|
||||
if (!isGlobal()) {
|
||||
clone.inherits = 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 Collections.unmodifiableList(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())) {
|
||||
inherits.add(inherit.getName().toLowerCase());
|
||||
}
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded()) {
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeInherits(String inherit) {
|
||||
|
||||
if (!isGlobal()) {
|
||||
if (this.inherits.contains(inherit.toLowerCase())) {
|
||||
this.inherits.remove(inherit.toLowerCase());
|
||||
flagAsChanged();
|
||||
GroupManagerEventHandler.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();
|
||||
GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,76 +12,83 @@ import java.util.Map;
|
|||
*/
|
||||
public class GroupVariables extends Variables implements Cloneable {
|
||||
|
||||
private Group owner;
|
||||
private Group owner;
|
||||
|
||||
public GroupVariables(Group owner) {
|
||||
super(owner);
|
||||
this.owner = owner;
|
||||
addVar("prefix", "");
|
||||
addVar("suffix", "");
|
||||
addVar("build", false);
|
||||
}
|
||||
public GroupVariables(Group owner) {
|
||||
|
||||
public GroupVariables(Group owner, Map<String, Object> varList) {
|
||||
super(owner);
|
||||
variables = varList;
|
||||
if (variables.get("prefix") == null) {
|
||||
variables.put("prefix", "");
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
//thisGrp.prefix = infoNode.get("prefix").toString();
|
||||
super(owner);
|
||||
this.owner = owner;
|
||||
addVar("prefix", "");
|
||||
addVar("suffix", "");
|
||||
addVar("build", false);
|
||||
}
|
||||
|
||||
if (variables.get("suffix") == null) {
|
||||
variables.put("suffix", "");
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
//thisGrp.suffix = infoNode.get("suffix").toString();
|
||||
public GroupVariables(Group owner, Map<String, Object> varList) {
|
||||
|
||||
if (variables.get("build") == null) {
|
||||
variables.put("build", false);
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
this.owner = owner;
|
||||
}
|
||||
super(owner);
|
||||
variables = varList;
|
||||
if (variables.get("prefix") == null) {
|
||||
variables.put("prefix", "");
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
//thisGrp.prefix = infoNode.get("prefix").toString();
|
||||
|
||||
/**
|
||||
* A clone of all vars here.
|
||||
* @return GroupVariables clone
|
||||
*/
|
||||
protected GroupVariables clone(Group newOwner) {
|
||||
GroupVariables clone = new GroupVariables(newOwner);
|
||||
for (String key : variables.keySet()) {
|
||||
clone.variables.put(key, variables.get(key));
|
||||
}
|
||||
newOwner.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
if (variables.get("suffix") == null) {
|
||||
variables.put("suffix", "");
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
//thisGrp.suffix = infoNode.get("suffix").toString();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
if (variables.get("build") == null) {
|
||||
variables.put("build", false);
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
*/
|
||||
@Override
|
||||
public Group getOwner() {
|
||||
return owner;
|
||||
}
|
||||
/**
|
||||
* A clone of all vars here.
|
||||
*
|
||||
* @return GroupVariables clone
|
||||
*/
|
||||
protected GroupVariables clone(Group newOwner) {
|
||||
|
||||
GroupVariables clone = new GroupVariables(newOwner);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.util.Map;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author gabrielcouto/ElgarL
|
||||
|
@ -40,6 +39,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
* @param name
|
||||
*/
|
||||
public User(WorldDataHolder source, String name) {
|
||||
|
||||
super(source, name);
|
||||
this.group = source.getDefaultGroup().getName();
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
*/
|
||||
@Override
|
||||
public User clone() {
|
||||
|
||||
User clone = new User(getDataSource(), this.getName());
|
||||
clone.group = this.group;
|
||||
for (String perm : this.getPermissionList()) {
|
||||
|
@ -67,6 +68,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
* @return null if given dataSource already contains the same user
|
||||
*/
|
||||
public User clone(WorldDataHolder dataSource) {
|
||||
|
||||
if (dataSource.isUserDeclared(this.getName())) {
|
||||
return null;
|
||||
}
|
||||
|
@ -85,6 +87,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
}
|
||||
|
||||
public Group getGroup() {
|
||||
|
||||
Group result = getDataSource().getGroup(group);
|
||||
if (result == null) {
|
||||
this.setGroup(getDataSource().getDefaultGroup());
|
||||
|
@ -97,6 +100,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
* @return the group
|
||||
*/
|
||||
public String getGroupName() {
|
||||
|
||||
Group result = getDataSource().getGroup(group);
|
||||
if (result == null) {
|
||||
group = getDataSource().getDefaultGroup().getName();
|
||||
|
@ -110,6 +114,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
*/
|
||||
@Deprecated
|
||||
public void setGroup(String group) {
|
||||
|
||||
this.group = group;
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
|
@ -122,6 +127,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
* the group to set
|
||||
*/
|
||||
public void setGroup(Group group) {
|
||||
|
||||
setGroup(group, true);
|
||||
}
|
||||
|
||||
|
@ -131,6 +137,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
*
|
||||
*/
|
||||
public void setGroup(Group group, Boolean updatePerms) {
|
||||
|
||||
if (!this.getDataSource().groupExists(group.getName())) {
|
||||
getDataSource().addGroup(group);
|
||||
}
|
||||
|
@ -157,6 +164,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -185,18 +193,22 @@ public class User extends DataUnit implements Cloneable {
|
|||
}
|
||||
|
||||
public int subGroupsSize() {
|
||||
|
||||
return subGroups.size();
|
||||
}
|
||||
|
||||
public boolean isSubGroupsEmpty() {
|
||||
|
||||
return subGroups.isEmpty();
|
||||
}
|
||||
|
||||
public boolean containsSubGroup(Group subGroup) {
|
||||
|
||||
return subGroups.contains(subGroup.getName());
|
||||
}
|
||||
|
||||
public boolean removeSubGroup(Group subGroup) {
|
||||
|
||||
try {
|
||||
if (subGroups.remove(subGroup.getName())) {
|
||||
flagAsChanged();
|
||||
|
@ -212,6 +224,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
}
|
||||
|
||||
public ArrayList<Group> subGroupListCopy() {
|
||||
|
||||
ArrayList<Group> val = new ArrayList<Group>();
|
||||
for (String gstr : subGroups) {
|
||||
Group g = getDataSource().getGroup(gstr);
|
||||
|
@ -225,6 +238,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
}
|
||||
|
||||
public ArrayList<String> subGroupListStringCopy() {
|
||||
|
||||
return new ArrayList<String>(subGroups);
|
||||
}
|
||||
|
||||
|
@ -232,6 +246,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
* @return the variables
|
||||
*/
|
||||
public UserVariables getVariables() {
|
||||
|
||||
return variables;
|
||||
}
|
||||
|
||||
|
@ -240,6 +255,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
* @param varList
|
||||
*/
|
||||
public void setVariables(Map<String, Object> varList) {
|
||||
|
||||
//UserVariables temp = new UserVariables(this, varList);
|
||||
variables.clearVars();
|
||||
for (String key : varList.keySet()) {
|
||||
|
@ -254,6 +270,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
}
|
||||
|
||||
public User updatePlayer(Player player) {
|
||||
|
||||
if (player != null) {
|
||||
bukkitPlayer = player;
|
||||
}
|
||||
|
@ -261,6 +278,7 @@ public class User extends DataUnit implements Cloneable {
|
|||
}
|
||||
|
||||
public Player getBukkitPlayer() {
|
||||
|
||||
if (bukkitPlayer == null) {
|
||||
bukkitPlayer = Bukkit.getPlayer(this.getName());
|
||||
}
|
||||
|
|
|
@ -12,37 +12,42 @@ import java.util.Map;
|
|||
*/
|
||||
public class UserVariables extends Variables {
|
||||
|
||||
private User owner;
|
||||
private User owner;
|
||||
|
||||
public UserVariables(User owner) {
|
||||
super(owner);
|
||||
this.owner = owner;
|
||||
}
|
||||
public UserVariables(User owner) {
|
||||
|
||||
public UserVariables(User owner, Map<String, Object> varList) {
|
||||
super(owner);
|
||||
this.variables = varList;
|
||||
this.owner = owner;
|
||||
}
|
||||
super(owner);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* A clone of all vars here.
|
||||
* @return UserVariables clone
|
||||
*/
|
||||
protected UserVariables clone(User newOwner) {
|
||||
UserVariables clone = new UserVariables(newOwner);
|
||||
for (String key : variables.keySet()) {
|
||||
clone.variables.put(key, variables.get(key));
|
||||
}
|
||||
newOwner.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
public UserVariables(User owner, Map<String, Object> varList) {
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
*/
|
||||
@Override
|
||||
public User getOwner() {
|
||||
return owner;
|
||||
}
|
||||
super(owner);
|
||||
this.variables = varList;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* A clone of all vars here.
|
||||
*
|
||||
* @return UserVariables clone
|
||||
*/
|
||||
protected UserVariables clone(User newOwner) {
|
||||
|
||||
UserVariables clone = new UserVariables(newOwner);
|
||||
for (String key : variables.keySet()) {
|
||||
clone.variables.put(key, variables.get(key));
|
||||
}
|
||||
newOwner.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
*/
|
||||
@Override
|
||||
public User getOwner() {
|
||||
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*A class that holds variables of a user/group.
|
||||
* A class that holds variables of a user/group.
|
||||
* In groups, it holds the contents of INFO node.
|
||||
* Like:
|
||||
* prefix
|
||||
|
@ -20,167 +20,189 @@ import java.util.Set;
|
|||
*/
|
||||
public abstract class Variables implements Cloneable {
|
||||
|
||||
private DataUnit owner;
|
||||
protected Map<String, Object> variables = new HashMap<String, Object>();
|
||||
private DataUnit owner;
|
||||
protected Map<String, Object> variables = new HashMap<String, Object>();
|
||||
|
||||
public Variables(DataUnit owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
public Variables(DataUnit owner) {
|
||||
|
||||
/**
|
||||
* Add var to the the INFO node.
|
||||
* examples:
|
||||
* addVar("build",true);
|
||||
* addVar("prefix","c");
|
||||
* @param name key name of the var
|
||||
* @param o the object value of the var
|
||||
*/
|
||||
public void addVar(String name, Object o) {
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
if (variables.containsKey(name)) {
|
||||
variables.remove(name);
|
||||
}
|
||||
variables.put(name, o);
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the object inside the var
|
||||
* @param name
|
||||
* @return a Object if exists. null if doesn't exists
|
||||
*/
|
||||
public Object getVarObject(String name) {
|
||||
return variables.get(name);
|
||||
}
|
||||
/**
|
||||
* Add var to the the INFO node.
|
||||
* examples:
|
||||
* addVar("build",true);
|
||||
* addVar("prefix","c");
|
||||
*
|
||||
* @param name key name of the var
|
||||
* @param o the object value of the var
|
||||
*/
|
||||
public void addVar(String name, Object o) {
|
||||
|
||||
/**
|
||||
* Get the String value for the given var name
|
||||
* @param name the var key name
|
||||
* @return "" if null. or the toString() value of object
|
||||
*/
|
||||
public String getVarString(String name) {
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? "" : o.toString();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
if (o == null) {
|
||||
return;
|
||||
}
|
||||
if (variables.containsKey(name)) {
|
||||
variables.remove(name);
|
||||
}
|
||||
variables.put(name, o);
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return false if null. or a Boolean.parseBoolean of the string
|
||||
*/
|
||||
public Boolean getVarBoolean(String name) {
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? false : Boolean.parseBoolean(o.toString());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the object inside the var
|
||||
*
|
||||
* @param name
|
||||
* @return a Object if exists. null if doesn't exists
|
||||
*/
|
||||
public Object getVarObject(String name) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return -1 if null. or a parseInt of the string
|
||||
*/
|
||||
public Integer getVarInteger(String name) {
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? -1 : Integer.parseInt(o.toString());
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return variables.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return -1 if null. or a parseDouble of the string
|
||||
*/
|
||||
public Double getVarDouble(String name) {
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? -1.0D : Double.parseDouble(o.toString());
|
||||
} catch (Exception e) {
|
||||
return -1.0D;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the String value for the given var name
|
||||
*
|
||||
* @param name the var key name
|
||||
* @return "" if null. or the toString() value of object
|
||||
*/
|
||||
public String getVarString(String name) {
|
||||
|
||||
/**
|
||||
* All variable keys this is holding
|
||||
* @return Set of all variable names.
|
||||
*/
|
||||
public Set<String> getVarKeyList() {
|
||||
return variables.keySet();
|
||||
}
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? "" : o.toString();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* verify is a var exists
|
||||
* @param name the key name of the var
|
||||
* @return true if that var exists
|
||||
*/
|
||||
public boolean hasVar(String name) {
|
||||
return variables.containsKey(name);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return false if null. or a Boolean.parseBoolean of the string
|
||||
*/
|
||||
public Boolean getVarBoolean(String name) {
|
||||
|
||||
/**
|
||||
* Returns the quantity of vars this is holding
|
||||
* @return the number of vars
|
||||
*/
|
||||
public int getSize() {
|
||||
return variables.size();
|
||||
}
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? false : Boolean.parseBoolean(o.toString());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a var from the list
|
||||
* @param name
|
||||
*/
|
||||
public void removeVar(String name) {
|
||||
try {
|
||||
variables.remove(name);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return -1 if null. or a parseInt of the string
|
||||
*/
|
||||
public Integer getVarInteger(String name) {
|
||||
|
||||
public static Object parseVariableValue(String value) {
|
||||
try {
|
||||
Integer i = Integer.parseInt(value);
|
||||
return i;
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
try {
|
||||
Double d = Double.parseDouble(value);
|
||||
return d;
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on")) {
|
||||
return true;
|
||||
} else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("off")) {
|
||||
return false;
|
||||
}
|
||||
return value;
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? -1 : Integer.parseInt(o.toString());
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return -1 if null. or a parseDouble of the string
|
||||
*/
|
||||
public Double getVarDouble(String name) {
|
||||
|
||||
public void clearVars() {
|
||||
variables.clear();
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
Object o = variables.get(name);
|
||||
try {
|
||||
return o == null ? -1.0D : Double.parseDouble(o.toString());
|
||||
} catch (Exception e) {
|
||||
return -1.0D;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
*/
|
||||
public DataUnit getOwner() {
|
||||
return owner;
|
||||
}
|
||||
/**
|
||||
* All variable keys this is holding
|
||||
*
|
||||
* @return Set of all variable names.
|
||||
*/
|
||||
public Set<String> getVarKeyList() {
|
||||
|
||||
public boolean isEmpty() {
|
||||
return variables.isEmpty();
|
||||
}
|
||||
return variables.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* verify is a var exists
|
||||
*
|
||||
* @param name the key name of the var
|
||||
* @return true if that var exists
|
||||
*/
|
||||
public boolean hasVar(String name) {
|
||||
|
||||
return variables.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quantity of vars this is holding
|
||||
*
|
||||
* @return the number of vars
|
||||
*/
|
||||
public int getSize() {
|
||||
|
||||
return variables.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a var from the list
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void removeVar(String name) {
|
||||
|
||||
try {
|
||||
variables.remove(name);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
|
||||
public static Object parseVariableValue(String value) {
|
||||
|
||||
try {
|
||||
Integer i = Integer.parseInt(value);
|
||||
return i;
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
try {
|
||||
Double d = Double.parseDouble(value);
|
||||
return d;
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("on")) {
|
||||
return true;
|
||||
} else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no") || value.equalsIgnoreCase("off")) {
|
||||
return false;
|
||||
}
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
public void clearVars() {
|
||||
|
||||
variables.clear();
|
||||
owner.flagAsChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
*/
|
||||
public DataUnit getOwner() {
|
||||
|
||||
return owner;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
||||
return variables.isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ import java.util.Map;
|
|||
|
||||
import org.anjocaido.groupmanager.data.Group;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This container holds all Groups loaded from the relevant groupsFile.
|
||||
*
|
||||
|
@ -31,9 +29,11 @@ public class GroupsDataHolder {
|
|||
* Constructor
|
||||
*/
|
||||
protected GroupsDataHolder() {
|
||||
|
||||
}
|
||||
|
||||
public void setDataSource(WorldDataHolder dataSource) {
|
||||
|
||||
this.dataSource = dataSource;
|
||||
//push this data source to the users, so they pull the correct groups data.
|
||||
for (Group group : groups.values())
|
||||
|
@ -44,6 +44,7 @@ public class GroupsDataHolder {
|
|||
* @return the defaultGroup
|
||||
*/
|
||||
public Group getDefaultGroup() {
|
||||
|
||||
return defaultGroup;
|
||||
}
|
||||
|
||||
|
@ -51,6 +52,7 @@ public class GroupsDataHolder {
|
|||
* @param defaultGroup the defaultGroup to set
|
||||
*/
|
||||
public void setDefaultGroup(Group defaultGroup) {
|
||||
|
||||
this.defaultGroup = defaultGroup;
|
||||
}
|
||||
|
||||
|
@ -58,6 +60,7 @@ public class GroupsDataHolder {
|
|||
* @return the groups
|
||||
*/
|
||||
public Map<String, Group> getGroups() {
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
|
@ -65,6 +68,7 @@ public class GroupsDataHolder {
|
|||
* @param groups the groups to set
|
||||
*/
|
||||
public void setGroups(Map<String, Group> groups) {
|
||||
|
||||
this.groups = groups;
|
||||
}
|
||||
|
||||
|
@ -72,6 +76,7 @@ public class GroupsDataHolder {
|
|||
* @return the groupsFile
|
||||
*/
|
||||
public File getGroupsFile() {
|
||||
|
||||
return groupsFile;
|
||||
}
|
||||
|
||||
|
@ -79,6 +84,7 @@ public class GroupsDataHolder {
|
|||
* @param groupsFile the groupsFile to set
|
||||
*/
|
||||
public void setGroupsFile(File groupsFile) {
|
||||
|
||||
this.groupsFile = groupsFile;
|
||||
}
|
||||
|
||||
|
@ -86,6 +92,7 @@ public class GroupsDataHolder {
|
|||
* @return the haveGroupsChanged
|
||||
*/
|
||||
public boolean HaveGroupsChanged() {
|
||||
|
||||
return haveGroupsChanged;
|
||||
}
|
||||
|
||||
|
@ -93,6 +100,7 @@ public class GroupsDataHolder {
|
|||
* @param haveGroupsChanged the haveGroupsChanged to set
|
||||
*/
|
||||
public void setGroupsChanged(boolean haveGroupsChanged) {
|
||||
|
||||
this.haveGroupsChanged = haveGroupsChanged;
|
||||
}
|
||||
|
||||
|
@ -100,6 +108,7 @@ public class GroupsDataHolder {
|
|||
* @return the timeStampGroups
|
||||
*/
|
||||
public long getTimeStampGroups() {
|
||||
|
||||
return timeStampGroups;
|
||||
}
|
||||
|
||||
|
@ -107,6 +116,7 @@ public class GroupsDataHolder {
|
|||
* @param timeStampGroups the timeStampGroups to set
|
||||
*/
|
||||
public void setTimeStampGroups(long timeStampGroups) {
|
||||
|
||||
this.timeStampGroups = timeStampGroups;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,190 +16,200 @@ import org.anjocaido.groupmanager.data.User;
|
|||
*/
|
||||
public class OverloadedWorldHolder extends WorldDataHolder {
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected Map<String, User> overloadedUsers = new HashMap<String, User>();
|
||||
protected Map<String, User> overloadedUsers = new HashMap<String, User>();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ph
|
||||
*/
|
||||
public OverloadedWorldHolder(WorldDataHolder ph) {
|
||||
super(ph.getName());
|
||||
this.setGroupsFile(ph.getGroupsFile());
|
||||
this.setUsersFile(ph.getUsersFile());
|
||||
//this.setDefaultGroup(ph.getDefaultGroup());
|
||||
this.groups = ph.groups;
|
||||
this.users = ph.users;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param ph
|
||||
*/
|
||||
public OverloadedWorldHolder(WorldDataHolder ph) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return user object or a new user if none exists.
|
||||
*/
|
||||
@Override
|
||||
public User getUser(String userName) {
|
||||
//OVERLOADED CODE
|
||||
String userNameLowered = userName.toLowerCase();
|
||||
if (overloadedUsers.containsKey(userNameLowered)) {
|
||||
return overloadedUsers.get(userNameLowered);
|
||||
}
|
||||
//END CODE
|
||||
if (getUsers().containsKey(userNameLowered)) {
|
||||
return getUsers().get(userNameLowered);
|
||||
}
|
||||
User newUser = createUser(userName);
|
||||
setUsersChanged(true);
|
||||
return newUser;
|
||||
}
|
||||
super(ph.getName());
|
||||
this.setGroupsFile(ph.getGroupsFile());
|
||||
this.setUsersFile(ph.getUsersFile());
|
||||
//this.setDefaultGroup(ph.getDefaultGroup());
|
||||
this.groups = ph.groups;
|
||||
this.users = ph.users;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param theUser
|
||||
*/
|
||||
@Override
|
||||
public void addUser(User theUser) {
|
||||
if (theUser.getDataSource() != this) {
|
||||
theUser = theUser.clone(this);
|
||||
}
|
||||
if (theUser == null) {
|
||||
return;
|
||||
}
|
||||
if ((theUser.getGroup() == null) || (!getGroups().containsKey(theUser.getGroupName().toLowerCase()))) {
|
||||
theUser.setGroup(getDefaultGroup());
|
||||
}
|
||||
//OVERLOADED CODE
|
||||
if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) {
|
||||
overloadedUsers.remove(theUser.getName().toLowerCase());
|
||||
overloadedUsers.put(theUser.getName().toLowerCase(), theUser);
|
||||
return;
|
||||
}
|
||||
//END CODE
|
||||
removeUser(theUser.getName());
|
||||
getUsers().put(theUser.getName().toLowerCase(), theUser);
|
||||
setUsersChanged(true);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return user object or a new user if none exists.
|
||||
*/
|
||||
@Override
|
||||
public User getUser(String userName) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return true if removed/false if not found.
|
||||
*/
|
||||
@Override
|
||||
public boolean removeUser(String userName) {
|
||||
//OVERLOADED CODE
|
||||
if (overloadedUsers.containsKey(userName.toLowerCase())) {
|
||||
overloadedUsers.remove(userName.toLowerCase());
|
||||
return true;
|
||||
}
|
||||
//END CODE
|
||||
if (getUsers().containsKey(userName.toLowerCase())) {
|
||||
getUsers().remove(userName.toLowerCase());
|
||||
setUsersChanged(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//OVERLOADED CODE
|
||||
String userNameLowered = userName.toLowerCase();
|
||||
if (overloadedUsers.containsKey(userNameLowered)) {
|
||||
return overloadedUsers.get(userNameLowered);
|
||||
}
|
||||
//END CODE
|
||||
if (getUsers().containsKey(userNameLowered)) {
|
||||
return getUsers().get(userNameLowered);
|
||||
}
|
||||
User newUser = createUser(userName);
|
||||
setUsersChanged(true);
|
||||
return newUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeGroup(String groupName) {
|
||||
if (groupName.equals(getDefaultGroup())) {
|
||||
return false;
|
||||
}
|
||||
for (String key : getGroups().keySet()) {
|
||||
if (groupName.equalsIgnoreCase(key)) {
|
||||
getGroups().remove(key);
|
||||
for (String userKey : getUsers().keySet()) {
|
||||
User user = getUsers().get(userKey);
|
||||
if (user.getGroupName().equalsIgnoreCase(key)) {
|
||||
user.setGroup(getDefaultGroup());
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param theUser
|
||||
*/
|
||||
@Override
|
||||
public void addUser(User theUser) {
|
||||
|
||||
}
|
||||
//OVERLOADED CODE
|
||||
for (String userKey : overloadedUsers.keySet()) {
|
||||
User user = overloadedUsers.get(userKey);
|
||||
if (user.getGroupName().equalsIgnoreCase(key)) {
|
||||
user.setGroup(getDefaultGroup());
|
||||
}
|
||||
if (theUser.getDataSource() != this) {
|
||||
theUser = theUser.clone(this);
|
||||
}
|
||||
if (theUser == null) {
|
||||
return;
|
||||
}
|
||||
if ((theUser.getGroup() == null) || (!getGroups().containsKey(theUser.getGroupName().toLowerCase()))) {
|
||||
theUser.setGroup(getDefaultGroup());
|
||||
}
|
||||
//OVERLOADED CODE
|
||||
if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) {
|
||||
overloadedUsers.remove(theUser.getName().toLowerCase());
|
||||
overloadedUsers.put(theUser.getName().toLowerCase(), theUser);
|
||||
return;
|
||||
}
|
||||
//END CODE
|
||||
removeUser(theUser.getName());
|
||||
getUsers().put(theUser.getName().toLowerCase(), theUser);
|
||||
setUsersChanged(true);
|
||||
}
|
||||
|
||||
}
|
||||
//END OVERLOAD
|
||||
setGroupsChanged(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return true if removed/false if not found.
|
||||
*/
|
||||
@Override
|
||||
public boolean removeUser(String userName) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Collection of all users
|
||||
*/
|
||||
@Override
|
||||
public Collection<User> getUserList() {
|
||||
Collection<User> overloadedList = new ArrayList<User>();
|
||||
Collection<User> normalList = getUsers().values();
|
||||
for (User u : normalList) {
|
||||
if (overloadedUsers.containsKey(u.getName().toLowerCase())) {
|
||||
overloadedList.add(overloadedUsers.get(u.getName().toLowerCase()));
|
||||
} else {
|
||||
overloadedList.add(u);
|
||||
}
|
||||
}
|
||||
return overloadedList;
|
||||
}
|
||||
//OVERLOADED CODE
|
||||
if (overloadedUsers.containsKey(userName.toLowerCase())) {
|
||||
overloadedUsers.remove(userName.toLowerCase());
|
||||
return true;
|
||||
}
|
||||
//END CODE
|
||||
if (getUsers().containsKey(userName.toLowerCase())) {
|
||||
getUsers().remove(userName.toLowerCase());
|
||||
setUsersChanged(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return true if user is overloaded.
|
||||
*/
|
||||
public boolean isOverloaded(String userName) {
|
||||
return overloadedUsers.containsKey(userName.toLowerCase());
|
||||
}
|
||||
@Override
|
||||
public boolean removeGroup(String groupName) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
*/
|
||||
public void overloadUser(String userName) {
|
||||
if (!isOverloaded(userName)) {
|
||||
User theUser = getUser(userName);
|
||||
theUser = theUser.clone();
|
||||
if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) {
|
||||
overloadedUsers.remove(theUser.getName().toLowerCase());
|
||||
}
|
||||
overloadedUsers.put(theUser.getName().toLowerCase(), theUser);
|
||||
}
|
||||
}
|
||||
if (groupName.equals(getDefaultGroup())) {
|
||||
return false;
|
||||
}
|
||||
for (String key : getGroups().keySet()) {
|
||||
if (groupName.equalsIgnoreCase(key)) {
|
||||
getGroups().remove(key);
|
||||
for (String userKey : getUsers().keySet()) {
|
||||
User user = getUsers().get(userKey);
|
||||
if (user.getGroupName().equalsIgnoreCase(key)) {
|
||||
user.setGroup(getDefaultGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
*/
|
||||
public void removeOverload(String userName) {
|
||||
overloadedUsers.remove(userName.toLowerCase());
|
||||
}
|
||||
}
|
||||
//OVERLOADED CODE
|
||||
for (String userKey : overloadedUsers.keySet()) {
|
||||
User user = overloadedUsers.get(userKey);
|
||||
if (user.getGroupName().equalsIgnoreCase(key)) {
|
||||
user.setGroup(getDefaultGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user in normal state. Surpassing the overload state.
|
||||
* It doesn't affect permissions. But it enables plugins change the
|
||||
* actual user permissions even in overload mode.
|
||||
*
|
||||
* @param userName
|
||||
* @return user object
|
||||
*/
|
||||
public User surpassOverload(String userName) {
|
||||
if (!isOverloaded(userName)) {
|
||||
return getUser(userName);
|
||||
}
|
||||
if (getUsers().containsKey(userName.toLowerCase())) {
|
||||
return getUsers().get(userName.toLowerCase());
|
||||
}
|
||||
User newUser = createUser(userName);
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
//END OVERLOAD
|
||||
setGroupsChanged(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Collection of all users
|
||||
*/
|
||||
@Override
|
||||
public Collection<User> getUserList() {
|
||||
|
||||
Collection<User> overloadedList = new ArrayList<User>();
|
||||
Collection<User> normalList = getUsers().values();
|
||||
for (User u : normalList) {
|
||||
if (overloadedUsers.containsKey(u.getName().toLowerCase())) {
|
||||
overloadedList.add(overloadedUsers.get(u.getName().toLowerCase()));
|
||||
} else {
|
||||
overloadedList.add(u);
|
||||
}
|
||||
}
|
||||
return overloadedList;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return true if user is overloaded.
|
||||
*/
|
||||
public boolean isOverloaded(String userName) {
|
||||
|
||||
return overloadedUsers.containsKey(userName.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
*/
|
||||
public void overloadUser(String userName) {
|
||||
|
||||
if (!isOverloaded(userName)) {
|
||||
User theUser = getUser(userName);
|
||||
theUser = theUser.clone();
|
||||
if (overloadedUsers.containsKey(theUser.getName().toLowerCase())) {
|
||||
overloadedUsers.remove(theUser.getName().toLowerCase());
|
||||
}
|
||||
overloadedUsers.put(theUser.getName().toLowerCase(), theUser);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
*/
|
||||
public void removeOverload(String userName) {
|
||||
|
||||
overloadedUsers.remove(userName.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user in normal state. Surpassing the overload state.
|
||||
* It doesn't affect permissions. But it enables plugins change the
|
||||
* actual user permissions even in overload mode.
|
||||
*
|
||||
* @param userName
|
||||
* @return user object
|
||||
*/
|
||||
public User surpassOverload(String userName) {
|
||||
|
||||
if (!isOverloaded(userName)) {
|
||||
return getUser(userName);
|
||||
}
|
||||
if (getUsers().containsKey(userName.toLowerCase())) {
|
||||
return getUsers().get(userName.toLowerCase());
|
||||
}
|
||||
User newUser = createUser(userName);
|
||||
return newUser;
|
||||
}
|
||||
}
|
|
@ -6,8 +6,6 @@ import java.util.Map;
|
|||
|
||||
import org.anjocaido.groupmanager.data.User;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This container holds all Users loaded from the relevant usersFile.
|
||||
*
|
||||
|
@ -30,9 +28,11 @@ public class UsersDataHolder {
|
|||
* Constructor
|
||||
*/
|
||||
protected UsersDataHolder() {
|
||||
|
||||
}
|
||||
|
||||
public void setDataSource(WorldDataHolder dataSource) {
|
||||
|
||||
this.dataSource = dataSource;
|
||||
//push this data source to the users, so they pull the correct groups data.
|
||||
for (User user : users.values())
|
||||
|
@ -44,6 +44,7 @@ public class UsersDataHolder {
|
|||
* @return the users
|
||||
*/
|
||||
public Map<String, User> getUsers() {
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
|
@ -51,6 +52,7 @@ public class UsersDataHolder {
|
|||
* @param users the users to set
|
||||
*/
|
||||
public void setUsers(Map<String, User> users) {
|
||||
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
|
@ -58,6 +60,7 @@ public class UsersDataHolder {
|
|||
* @return the usersFile
|
||||
*/
|
||||
public File getUsersFile() {
|
||||
|
||||
return usersFile;
|
||||
}
|
||||
|
||||
|
@ -65,6 +68,7 @@ public class UsersDataHolder {
|
|||
* @param usersFile the usersFile to set
|
||||
*/
|
||||
public void setUsersFile(File usersFile) {
|
||||
|
||||
this.usersFile = usersFile;
|
||||
}
|
||||
|
||||
|
@ -72,6 +76,7 @@ public class UsersDataHolder {
|
|||
* @return the haveUsersChanged
|
||||
*/
|
||||
public boolean HaveUsersChanged() {
|
||||
|
||||
return haveUsersChanged;
|
||||
}
|
||||
|
||||
|
@ -79,6 +84,7 @@ public class UsersDataHolder {
|
|||
* @param haveUsersChanged the haveUsersChanged to set
|
||||
*/
|
||||
public void setUsersChanged(boolean haveUsersChanged) {
|
||||
|
||||
this.haveUsersChanged = haveUsersChanged;
|
||||
}
|
||||
|
||||
|
@ -86,6 +92,7 @@ public class UsersDataHolder {
|
|||
* @return the timeStampUsers
|
||||
*/
|
||||
public long getTimeStampUsers() {
|
||||
|
||||
return timeStampUsers;
|
||||
}
|
||||
|
||||
|
@ -93,6 +100,7 @@ public class UsersDataHolder {
|
|||
* @param timeStampUsers the timeStampUsers to set
|
||||
*/
|
||||
public void setTimeStampUsers(long timeStampUsers) {
|
||||
|
||||
this.timeStampUsers = timeStampUsers;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -6,79 +6,82 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
/**
|
||||
* @author ElgarL
|
||||
*
|
||||
*/
|
||||
public class GMGroupEvent extends Event {
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
public static HandlerList getHandlerList() {
|
||||
|
||||
return handlers;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
protected Group group;
|
||||
|
||||
protected String groupName;
|
||||
|
||||
protected Action action;
|
||||
protected Action action;
|
||||
|
||||
public GMGroupEvent(Group group, Action action) {
|
||||
super();
|
||||
public GMGroupEvent(Group group, Action action) {
|
||||
|
||||
this.group = group;
|
||||
this.action = action;
|
||||
this.groupName = group.getName();
|
||||
}
|
||||
super();
|
||||
|
||||
public GMGroupEvent(String groupName, Action action) {
|
||||
super();
|
||||
this.group = group;
|
||||
this.action = action;
|
||||
this.groupName = group.getName();
|
||||
}
|
||||
|
||||
this.groupName = groupName;
|
||||
this.action = action;
|
||||
}
|
||||
public GMGroupEvent(String groupName, Action action) {
|
||||
|
||||
public Action getAction(){
|
||||
return this.action;
|
||||
}
|
||||
super();
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
this.groupName = groupName;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
public Action getAction() {
|
||||
|
||||
public enum Action {
|
||||
GROUP_PERMISSIONS_CHANGED,
|
||||
GROUP_INHERITANCE_CHANGED,
|
||||
GROUP_INFO_CHANGED,
|
||||
GROUP_ADDED,
|
||||
GROUP_REMOVED,
|
||||
}
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public void schedule(final GMGroupEvent event) {
|
||||
public Group getGroup() {
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
|
||||
return groupName;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
GROUP_PERMISSIONS_CHANGED, GROUP_INHERITANCE_CHANGED, GROUP_INFO_CHANGED, GROUP_ADDED, GROUP_REMOVED,
|
||||
}
|
||||
|
||||
public void schedule(final GMGroupEvent event) {
|
||||
|
||||
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,57 +5,58 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
/**
|
||||
* @author ElgarL
|
||||
*
|
||||
*/
|
||||
public class GMSystemEvent extends Event {
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
public static HandlerList getHandlerList() {
|
||||
|
||||
return handlers;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
protected Action action;
|
||||
|
||||
public GMSystemEvent(Action action) {
|
||||
super();
|
||||
public GMSystemEvent(Action action) {
|
||||
|
||||
this.action = action;
|
||||
}
|
||||
super();
|
||||
|
||||
public Action getAction(){
|
||||
return this.action;
|
||||
}
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
RELOADED,
|
||||
SAVED,
|
||||
DEFAULT_GROUP_CHANGED,
|
||||
VALIDATE_TOGGLE,
|
||||
}
|
||||
public Action getAction() {
|
||||
|
||||
public void schedule(final GMSystemEvent event) {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
RELOADED, SAVED, DEFAULT_GROUP_CHANGED, VALIDATE_TOGGLE,
|
||||
}
|
||||
|
||||
public void schedule(final GMSystemEvent event) {
|
||||
|
||||
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,81 +6,82 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
/**
|
||||
* @author ElgarL
|
||||
*
|
||||
*/
|
||||
public class GMUserEvent extends Event {
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
public static HandlerList getHandlerList() {
|
||||
|
||||
return handlers;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
protected User user;
|
||||
|
||||
protected String userName;
|
||||
|
||||
protected Action action;
|
||||
protected Action action;
|
||||
|
||||
public GMUserEvent(User user, Action action) {
|
||||
super();
|
||||
public GMUserEvent(User user, Action action) {
|
||||
|
||||
this.user = user;
|
||||
this.action = action;
|
||||
this.userName = user.getName();
|
||||
}
|
||||
super();
|
||||
|
||||
public GMUserEvent(String userName, Action action) {
|
||||
super();
|
||||
this.user = user;
|
||||
this.action = action;
|
||||
this.userName = user.getName();
|
||||
}
|
||||
|
||||
this.userName = userName;
|
||||
this.action = action;
|
||||
}
|
||||
public GMUserEvent(String userName, Action action) {
|
||||
|
||||
public Action getAction(){
|
||||
return this.action;
|
||||
}
|
||||
super();
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
this.userName = userName;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public Action getAction() {
|
||||
|
||||
public enum Action {
|
||||
USER_PERMISSIONS_CHANGED,
|
||||
USER_INHERITANCE_CHANGED,
|
||||
USER_INFO_CHANGED,
|
||||
USER_GROUP_CHANGED,
|
||||
USER_SUBGROUP_CHANGED,
|
||||
USER_ADDED,
|
||||
USER_REMOVED,
|
||||
}
|
||||
return this.action;
|
||||
}
|
||||
|
||||
public void schedule(final GMUserEvent event) {
|
||||
public User getUser() {
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
|
||||
return userName;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
USER_PERMISSIONS_CHANGED, USER_INHERITANCE_CHANGED, USER_INFO_CHANGED, USER_GROUP_CHANGED, USER_SUBGROUP_CHANGED, USER_ADDED, USER_REMOVED,
|
||||
}
|
||||
|
||||
public void schedule(final GMUserEvent event) {
|
||||
|
||||
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,11 +6,10 @@ import org.bukkit.event.EventPriority;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
|
||||
|
||||
/**
|
||||
* @author ElgarL
|
||||
*
|
||||
* Handle new world creation from other plugins
|
||||
* Handle new world creation from other plugins
|
||||
*
|
||||
*/
|
||||
public class GMWorldListener implements Listener {
|
||||
|
@ -18,17 +17,20 @@ public class GMWorldListener implements Listener {
|
|||
private final GroupManager plugin;
|
||||
|
||||
public GMWorldListener(GroupManager instance) {
|
||||
|
||||
plugin = instance;
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
String worldName = event.getWorld().getName();
|
||||
|
||||
String worldName = event.getWorld().getName();
|
||||
|
||||
if (GroupManager.isLoaded() && !plugin.getWorldsHolder().isInList(worldName)) {
|
||||
GroupManager.logger.info("New world detected...");
|
||||
|
|
|
@ -3,40 +3,51 @@ package org.anjocaido.groupmanager.events;
|
|||
import org.anjocaido.groupmanager.data.Group;
|
||||
import org.anjocaido.groupmanager.data.User;
|
||||
|
||||
|
||||
/**
|
||||
* @author ElgarL
|
||||
*
|
||||
* Handles all Event generation.
|
||||
* Handles all Event generation.
|
||||
*
|
||||
*/
|
||||
public class GroupManagerEventHandler {
|
||||
|
||||
protected static void callEvent(GMGroupEvent event) {
|
||||
|
||||
event.schedule(event);
|
||||
}
|
||||
|
||||
protected static void callEvent(GMUserEvent event) {
|
||||
|
||||
event.schedule(event);
|
||||
}
|
||||
|
||||
protected static void callEvent(GMSystemEvent event) {
|
||||
|
||||
event.schedule(event);
|
||||
}
|
||||
|
||||
public static void callEvent(Group group, GMGroupEvent.Action action) {
|
||||
|
||||
callEvent(new GMGroupEvent(group, action));
|
||||
}
|
||||
|
||||
public static void callEvent(String groupName, GMGroupEvent.Action action) {
|
||||
|
||||
callEvent(new GMGroupEvent(groupName, action));
|
||||
}
|
||||
|
||||
public static void callEvent(User user, GMUserEvent.Action action) {
|
||||
|
||||
callEvent(new GMUserEvent(user, action));
|
||||
}
|
||||
|
||||
public static void callEvent(String userName, GMUserEvent.Action action) {
|
||||
|
||||
callEvent(new GMUserEvent(userName, action));
|
||||
}
|
||||
|
||||
public static void callEvent(GMSystemEvent.Action action) {
|
||||
|
||||
callEvent(new GMSystemEvent(action));
|
||||
}
|
||||
}
|
|
@ -39,6 +39,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @param holder
|
||||
*/
|
||||
public AnjoPermissionsHandler(WorldDataHolder holder) {
|
||||
|
||||
ph = holder;
|
||||
}
|
||||
|
||||
|
@ -51,6 +52,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public boolean has(Player player, String permission) {
|
||||
|
||||
return permission(player, permission);
|
||||
}
|
||||
|
||||
|
@ -63,6 +65,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public boolean permission(Player player, String permission) {
|
||||
|
||||
return checkUserPermission(ph.getUser(player.getName()).updatePlayer(player), permission);
|
||||
}
|
||||
|
||||
|
@ -74,6 +77,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return true if the player has the permission
|
||||
*/
|
||||
public boolean permission(String playerName, String permission) {
|
||||
|
||||
return checkUserPermission(ph.getUser(playerName), permission);
|
||||
}
|
||||
|
||||
|
@ -85,6 +89,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public String getGroup(String userName) {
|
||||
|
||||
return ph.getUser(userName).getGroup().getName();
|
||||
}
|
||||
|
||||
|
@ -97,6 +102,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public List<String> getAllPlayersPermissions(String userName) {
|
||||
|
||||
List<String> perms = new ArrayList<String>();
|
||||
|
||||
perms.addAll(getAllPlayersPermissions(userName, true));
|
||||
|
@ -143,8 +149,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
boolean negated = (perm.startsWith("-"));
|
||||
// Perm doesn't already exists and there is no negation for it
|
||||
// or It's a negated perm where a normal perm doesn't exists (don't allow inheritance to negate higher perms)
|
||||
if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm))
|
||||
|| (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm)))
|
||||
if ((!negated && !playerPermArray.contains(perm) && !playerPermArray.contains("-" + perm)) || (negated && !playerPermArray.contains(perm.substring(1)) && !playerPermArray.contains("-" + perm)))
|
||||
playerPermArray.add(perm);
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +160,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
return playerPermArray;
|
||||
}
|
||||
|
||||
private Set<String> populatePerms (List<String> permsList, boolean includeChildren) {
|
||||
private Set<String> populatePerms(List<String> permsList, boolean includeChildren) {
|
||||
|
||||
// Create a new array so it's modifiable.
|
||||
List<String> perms = new ArrayList<String>(permsList);
|
||||
|
@ -171,37 +176,38 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
|
||||
for (String perm : perms) {
|
||||
|
||||
/**
|
||||
* all permission sets are passed here pre-sorted, alphabetically.
|
||||
* This means negated nodes will be processed before all permissions
|
||||
* other than *.
|
||||
*/
|
||||
boolean negated = perm.startsWith("-");
|
||||
|
||||
if (!permArray.contains(perm)) {
|
||||
permArray.add(perm);
|
||||
|
||||
if ((negated) && (permArray.contains(perm.substring(1))))
|
||||
permArray.remove(perm.substring(1));
|
||||
|
||||
/**
|
||||
* all permission sets are passed here pre-sorted, alphabetically.
|
||||
* This means negated nodes will be processed before all permissions
|
||||
* other than *.
|
||||
* Process child nodes if required,
|
||||
* or this is a negated node AND we used * to include all
|
||||
* permissions,
|
||||
* in which case we need to remove all children of that node.
|
||||
*/
|
||||
boolean negated = perm.startsWith("-");
|
||||
if ((includeChildren) || (negated && allPerms)) {
|
||||
|
||||
if (!permArray.contains(perm)) {
|
||||
permArray.add(perm);
|
||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet<String>());
|
||||
|
||||
if ((negated) && (permArray.contains(perm.substring(1))))
|
||||
permArray.remove(perm.substring(1));
|
||||
if (children != null) {
|
||||
if (negated)
|
||||
if (allPerms) {
|
||||
|
||||
/**
|
||||
* Process child nodes if required,
|
||||
* or this is a negated node AND we used * to include all permissions,
|
||||
* in which case we need to remove all children of that node.
|
||||
*/
|
||||
if ((includeChildren) || (negated && allPerms)) {
|
||||
|
||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren((negated ? perm.substring(1) : perm), new HashSet<String>());
|
||||
|
||||
if (children != null) {
|
||||
if (negated)
|
||||
if (allPerms) {
|
||||
|
||||
// Remove children of negated nodes
|
||||
for (String child : children.keySet())
|
||||
if (children.get(child))
|
||||
if (permArray.contains(child))
|
||||
permArray.remove(child);
|
||||
// Remove children of negated nodes
|
||||
for (String child : children.keySet())
|
||||
if (children.get(child))
|
||||
if (permArray.contains(child))
|
||||
permArray.remove(child);
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -211,9 +217,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
if ((!permArray.contains(child)) && (!permArray.contains("-" + child)))
|
||||
permArray.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return permArray;
|
||||
|
@ -236,6 +242,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public boolean inGroup(String name, String group) {
|
||||
|
||||
if (hasGroupInInheritance(ph.getUser(name).getGroup(), group)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -326,6 +333,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public String getGroupPrefix(String groupName) {
|
||||
|
||||
Group g = ph.getGroup(groupName);
|
||||
if (g == null) {
|
||||
return "";
|
||||
|
@ -341,6 +349,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public String getGroupSuffix(String groupName) {
|
||||
|
||||
Group g = ph.getGroup(groupName);
|
||||
if (g == null) {
|
||||
return "";
|
||||
|
@ -357,6 +366,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public boolean canGroupBuild(String groupName) {
|
||||
|
||||
Group g = ph.getGroup(groupName);
|
||||
if (g == null) {
|
||||
return false;
|
||||
|
@ -374,6 +384,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public String getGroupPermissionString(String groupName, String variable) {
|
||||
|
||||
Group start = ph.getGroup(groupName);
|
||||
if (start == null) {
|
||||
return null;
|
||||
|
@ -395,6 +406,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public int getGroupPermissionInteger(String groupName, String variable) {
|
||||
|
||||
Group start = ph.getGroup(groupName);
|
||||
if (start == null) {
|
||||
return -1;
|
||||
|
@ -416,6 +428,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public boolean getGroupPermissionBoolean(String group, String variable) {
|
||||
|
||||
Group start = ph.getGroup(group);
|
||||
if (start == null) {
|
||||
return false;
|
||||
|
@ -437,6 +450,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public double getGroupPermissionDouble(String group, String variable) {
|
||||
|
||||
Group start = ph.getGroup(group);
|
||||
if (start == null) {
|
||||
return -1;
|
||||
|
@ -457,6 +471,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public String getUserPermissionString(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return "";
|
||||
|
@ -473,6 +488,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public int getUserPermissionInteger(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return -1;
|
||||
|
@ -489,6 +505,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public boolean getUserPermissionBoolean(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return false;
|
||||
|
@ -505,6 +522,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public double getUserPermissionDouble(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return -1;
|
||||
|
@ -523,6 +541,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public String getPermissionString(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return "";
|
||||
|
@ -562,6 +581,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public int getPermissionInteger(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return -1;
|
||||
|
@ -601,6 +621,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public boolean getPermissionBoolean(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return false;
|
||||
|
@ -640,6 +661,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public double getPermissionDouble(String user, String variable) {
|
||||
|
||||
User auser = ph.getUser(user);
|
||||
if (auser == null) {
|
||||
return -1.0D;
|
||||
|
@ -676,6 +698,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return PermissionCheckResult
|
||||
*/
|
||||
public PermissionCheckResult checkUserOnlyPermission(User user, String permission) {
|
||||
|
||||
user.sortPermissions();
|
||||
PermissionCheckResult result = new PermissionCheckResult();
|
||||
result.askedPermission = permission;
|
||||
|
@ -699,6 +722,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return the node if permission is found. if not found, return null
|
||||
*/
|
||||
public PermissionCheckResult checkGroupOnlyPermission(Group group, String permission) {
|
||||
|
||||
group.sortPermissions();
|
||||
PermissionCheckResult result = new PermissionCheckResult();
|
||||
result.owner = group;
|
||||
|
@ -721,6 +745,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return true if permission was found. false if not, or was negated.
|
||||
*/
|
||||
public boolean checkUserPermission(User user, String permission) {
|
||||
|
||||
PermissionCheckResult result = checkFullGMPermission(user, permission, true);
|
||||
if (result.resultType == PermissionCheckResult.Type.EXCEPTION || result.resultType == PermissionCheckResult.Type.FOUND) {
|
||||
return true;
|
||||
|
@ -752,6 +777,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return PermissionCheckResult
|
||||
*/
|
||||
public PermissionCheckResult checkFullGMPermission(User user, String targetPermission, Boolean checkBukkit) {
|
||||
|
||||
PermissionCheckResult result = new PermissionCheckResult();
|
||||
result.accessLevel = targetPermission;
|
||||
result.resultType = PermissionCheckResult.Type.NOTFOUND;
|
||||
|
@ -813,6 +839,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Deprecated
|
||||
public Group nextGroupWithVariable(Group start, String variable, List<Group> alreadyChecked) {
|
||||
|
||||
return nextGroupWithVariable(start, variable);
|
||||
}
|
||||
|
||||
|
@ -829,6 +856,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return The group if found. Null if not.
|
||||
*/
|
||||
public Group nextGroupWithVariable(Group start, String targetVariable) {
|
||||
|
||||
if (start == null || targetVariable == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -870,6 +898,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Deprecated
|
||||
public boolean searchGroupInInheritance(Group start, String askedGroup, List<Group> alreadyChecked) {
|
||||
|
||||
return hasGroupInInheritance(start, askedGroup);
|
||||
}
|
||||
|
||||
|
@ -885,6 +914,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return true if it inherits the group.
|
||||
*/
|
||||
public boolean hasGroupInInheritance(Group start, String askedGroup) {
|
||||
|
||||
if (start == null || askedGroup == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -920,6 +950,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Deprecated
|
||||
public boolean checkGroupPermissionWithInheritance(Group start, String permission, List<Group> alreadyChecked) {
|
||||
|
||||
PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
|
||||
if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
|
||||
return true;
|
||||
|
@ -942,6 +973,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return PermissionCheckResult
|
||||
*/
|
||||
public PermissionCheckResult checkGroupPermissionWithInheritance(Group start, String targetPermission) {
|
||||
|
||||
if (start == null || targetPermission == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -982,6 +1014,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Deprecated
|
||||
public Group nextGroupWithPermission(Group start, String permission, List<Group> alreadyChecked) {
|
||||
|
||||
PermissionCheckResult result = checkGroupPermissionWithInheritance(start, permission);
|
||||
if (result.resultType.equals(Type.EXCEPTION) || result.resultType.equals(Type.FOUND)) {
|
||||
return (Group) checkGroupPermissionWithInheritance(start, permission).owner;
|
||||
|
@ -1003,6 +1036,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Deprecated
|
||||
public ArrayList<String> listAllGroupsInherited(Group start, ArrayList<String> alreadyChecked) {
|
||||
|
||||
return listAllGroupsInherited(start);
|
||||
}
|
||||
|
||||
|
@ -1016,6 +1050,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return the group that passed on test. null if no group passed.
|
||||
*/
|
||||
public ArrayList<String> listAllGroupsInherited(Group start) {
|
||||
|
||||
if (start == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1055,6 +1090,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
* @return PermissionCheckResult.Type
|
||||
*/
|
||||
public PermissionCheckResult.Type comparePermissionString(String userAccessLevel, String fullPermissionName) {
|
||||
|
||||
int userAccessLevelLength;
|
||||
if (userAccessLevel == null || fullPermissionName == null || fullPermissionName.length() == 0 || (userAccessLevelLength = userAccessLevel.length()) == 0) {
|
||||
return PermissionCheckResult.Type.NOTFOUND;
|
||||
|
@ -1080,12 +1116,9 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
}
|
||||
|
||||
if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
|
||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ?
|
||||
result : PermissionCheckResult.Type.NOTFOUND;
|
||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ? result : PermissionCheckResult.Type.NOTFOUND;
|
||||
} else {
|
||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset,
|
||||
Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ?
|
||||
result : PermissionCheckResult.Type.NOTFOUND;
|
||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ? result : PermissionCheckResult.Type.NOTFOUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1099,6 +1132,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@Override
|
||||
public String[] getGroups(String userName) {
|
||||
|
||||
ArrayList<String> allGroups = listAllGroupsInherited(ph.getUser(userName).getGroup());
|
||||
for (Group subg : ph.getUser(userName).subGroupListCopy()) {
|
||||
allGroups.addAll(listAllGroupsInherited(subg));
|
||||
|
@ -1120,6 +1154,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private Group breadthFirstSearch(Group start, String targerPermission) {
|
||||
|
||||
if (start == null || targerPermission == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1149,11 +1184,13 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
|
||||
@Override
|
||||
public Group getDefaultGroup() {
|
||||
|
||||
return ph.getDefaultGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoString(String entryName, String path, boolean isGroup) {
|
||||
|
||||
if (isGroup) {
|
||||
Group data = ph.getGroup(entryName);
|
||||
if (data == null) {
|
||||
|
@ -1171,6 +1208,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
|
||||
@Override
|
||||
public int getInfoInteger(String entryName, String path, boolean isGroup) {
|
||||
|
||||
if (isGroup) {
|
||||
Group data = ph.getGroup(entryName);
|
||||
if (data == null) {
|
||||
|
@ -1188,6 +1226,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
|
||||
@Override
|
||||
public double getInfoDouble(String entryName, String path, boolean isGroup) {
|
||||
|
||||
if (isGroup) {
|
||||
Group data = ph.getGroup(entryName);
|
||||
if (data == null) {
|
||||
|
@ -1206,6 +1245,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
|
||||
@Override
|
||||
public boolean getInfoBoolean(String entryName, String path, boolean isGroup) {
|
||||
|
||||
if (isGroup) {
|
||||
Group data = ph.getGroup(entryName);
|
||||
if (data == null) {
|
||||
|
@ -1223,21 +1263,25 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
|||
|
||||
@Override
|
||||
public void addUserInfo(String name, String path, Object data) {
|
||||
|
||||
ph.getUser(name).getVariables().addVar(path, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUserInfo(String name, String path) {
|
||||
|
||||
ph.getUser(name).getVariables().removeVar(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroupInfo(String name, String path, Object data) {
|
||||
|
||||
ph.getGroup(name).getVariables().addVar(path, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroupInfo(String name, String path) {
|
||||
|
||||
ph.getGroup(name).getVariables().removeVar(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
/*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
package org.anjocaido.groupmanager.permissions;
|
||||
|
||||
|
@ -47,7 +48,6 @@ import org.bukkit.permissions.PermissionAttachment;
|
|||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* BukkitPermissions overrides to force GM reponses to Superperms
|
||||
|
@ -67,6 +67,7 @@ public class BukkitPermissions {
|
|||
* @return the player_join
|
||||
*/
|
||||
public boolean isPlayer_join() {
|
||||
|
||||
return player_join;
|
||||
}
|
||||
|
||||
|
@ -74,6 +75,7 @@ public class BukkitPermissions {
|
|||
* @param player_join the player_join to set
|
||||
*/
|
||||
public void setPlayer_join(boolean player_join) {
|
||||
|
||||
this.player_join = player_join;
|
||||
}
|
||||
|
||||
|
@ -92,6 +94,7 @@ public class BukkitPermissions {
|
|||
}
|
||||
|
||||
public BukkitPermissions(GroupManager plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
this.collectPermissions();
|
||||
this.registerEvents();
|
||||
|
@ -101,35 +104,38 @@ public class BukkitPermissions {
|
|||
}
|
||||
|
||||
private void registerEvents() {
|
||||
|
||||
PluginManager manager = plugin.getServer().getPluginManager();
|
||||
|
||||
manager.registerEvents(new PlayerEvents(), plugin);
|
||||
manager.registerEvents(new BukkitEvents(), plugin);
|
||||
}
|
||||
|
||||
|
||||
public void collectPermissions() {
|
||||
|
||||
registeredPermissions.clear();
|
||||
|
||||
for (Permission perm : Bukkit.getPluginManager().getPermissions()) {
|
||||
registeredPermissions.put(perm.getName().toLowerCase(), perm);
|
||||
registeredPermissions.put(perm.getName().toLowerCase(), perm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updatePermissions(Player player) {
|
||||
|
||||
this.updatePermissions(player, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Push all permissions which are registered with GM for this player, on this world to Bukkit
|
||||
* Push all permissions which are registered with GM for this player, on
|
||||
* this world to Bukkit
|
||||
* and make it update for the child nodes.
|
||||
*
|
||||
* @param player
|
||||
* @param world
|
||||
*/
|
||||
public void updatePermissions(Player player, String world) {
|
||||
|
||||
if (player == null || !GroupManager.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
@ -159,13 +165,14 @@ public class BukkitPermissions {
|
|||
Boolean value = false;
|
||||
for (String permission : playerPermArray) {
|
||||
value = (!permission.startsWith("-"));
|
||||
newPerms.put((value? permission : permission.substring(1)), value);
|
||||
newPerms.put((value ? permission : permission.substring(1)), value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is put in place until such a time as Bukkit pull 466 is implemented
|
||||
* https://github.com/Bukkit/Bukkit/pull/466
|
||||
*/
|
||||
* This is put in place until such a time as Bukkit pull 466 is
|
||||
* implemented
|
||||
* https://github.com/Bukkit/Bukkit/pull/466
|
||||
*/
|
||||
try { // Codename_B source
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(attachment);
|
||||
|
@ -194,15 +201,15 @@ public class BukkitPermissions {
|
|||
List<String> result = new ArrayList<String>();
|
||||
|
||||
for (String key : permList) {
|
||||
String a = key.charAt(0) == '-'? key.substring(1):key;
|
||||
String a = key.charAt(0) == '-' ? key.substring(1) : key;
|
||||
Map<String, Boolean> allchildren = GroupManager.BukkitPermissions.getAllChildren(a, new HashSet<String>());
|
||||
if (allchildren != null) {
|
||||
|
||||
ListIterator<String> itr = result.listIterator();
|
||||
|
||||
while (itr.hasNext()){
|
||||
while (itr.hasNext()) {
|
||||
String node = (String) itr.next();
|
||||
String b = node.charAt(0) == '-'? node.substring(1):node;
|
||||
String b = node.charAt(0) == '-' ? node.substring(1) : node;
|
||||
|
||||
// Insert the parent node before the child
|
||||
if (allchildren.containsKey(b)) {
|
||||
|
@ -219,7 +226,6 @@ public class BukkitPermissions {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch all permissions which are registered with superperms.
|
||||
* {can include child nodes)
|
||||
|
@ -254,7 +260,8 @@ public class BukkitPermissions {
|
|||
* null is empty
|
||||
*
|
||||
* @param node
|
||||
* @param playerPermArray current list of perms to check against for negations
|
||||
* @param playerPermArray current list of perms to check against for
|
||||
* negations
|
||||
* @return Map of child permissions
|
||||
*/
|
||||
public Map<String, Boolean> getAllChildren(String node, Set<String> playerPermArray) {
|
||||
|
@ -269,7 +276,7 @@ public class BukkitPermissions {
|
|||
|
||||
Map<String, Boolean> children = getChildren(now);
|
||||
|
||||
if ((children != null) && (!playerPermArray.contains("-"+now))) {
|
||||
if ((children != null) && (!playerPermArray.contains("-" + now))) {
|
||||
for (String childName : children.keySet()) {
|
||||
if (!alreadyVisited.containsKey(childName)) {
|
||||
stack.push(childName);
|
||||
|
@ -279,13 +286,15 @@ public class BukkitPermissions {
|
|||
}
|
||||
}
|
||||
alreadyVisited.remove(node);
|
||||
if (!alreadyVisited.isEmpty()) return alreadyVisited;
|
||||
if (!alreadyVisited.isEmpty())
|
||||
return alreadyVisited;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the child permissions (1 node deep) as registered with Bukkit.
|
||||
* Returns a map of the child permissions (1 node deep) as registered with
|
||||
* Bukkit.
|
||||
* null is empty
|
||||
*
|
||||
* @param node
|
||||
|
@ -308,6 +317,7 @@ public class BukkitPermissions {
|
|||
* @return List<String> of permissions
|
||||
*/
|
||||
public List<String> listPerms(Player player) {
|
||||
|
||||
List<String> perms = new ArrayList<String>();
|
||||
|
||||
/*
|
||||
|
@ -332,6 +342,7 @@ public class BukkitPermissions {
|
|||
* force Bukkit to update every OnlinePlayers permissions.
|
||||
*/
|
||||
public void updateAllPlayers() {
|
||||
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
updatePermissions(player);
|
||||
}
|
||||
|
@ -341,6 +352,7 @@ public class BukkitPermissions {
|
|||
* force Bukkit to update this Players permissions.
|
||||
*/
|
||||
public void updatePlayer(Player player) {
|
||||
|
||||
if (player != null)
|
||||
this.updatePermissions(player, null);
|
||||
}
|
||||
|
@ -351,6 +363,7 @@ public class BukkitPermissions {
|
|||
* @param player
|
||||
*/
|
||||
private void removeAttachment(Player player) {
|
||||
|
||||
if (attachments.containsKey(player)) {
|
||||
try {
|
||||
player.removeAttachment(attachments.get(player));
|
||||
|
@ -371,7 +384,7 @@ public class BukkitPermissions {
|
|||
|
||||
Iterator<Player> itr = attachments.keySet().iterator();
|
||||
|
||||
while (itr.hasNext()){
|
||||
while (itr.hasNext()) {
|
||||
Player player = itr.next();
|
||||
try {
|
||||
player.removeAttachment(attachments.get(player));
|
||||
|
@ -395,6 +408,7 @@ public class BukkitPermissions {
|
|||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
setPlayer_join(true);
|
||||
Player player = event.getPlayer();
|
||||
|
||||
|
@ -413,11 +427,13 @@ public class BukkitPermissions {
|
|||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) { // has changed worlds
|
||||
|
||||
updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
/*
|
||||
|
@ -428,6 +444,7 @@ public class BukkitPermissions {
|
|||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
|
||||
if (!GroupManager.isLoaded())
|
||||
return;
|
||||
|
||||
|
@ -444,6 +461,7 @@ public class BukkitPermissions {
|
|||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
|
||||
if (!GroupManager.isLoaded())
|
||||
return;
|
||||
|
||||
|
@ -453,6 +471,7 @@ public class BukkitPermissions {
|
|||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
|
||||
collectPermissions();
|
||||
// updateAllPlayers();
|
||||
}
|
||||
|
|
|
@ -21,218 +21,230 @@ import org.bukkit.entity.Player;
|
|||
*/
|
||||
public abstract class PermissionsReaderInterface {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param string
|
||||
* @return true if has permission
|
||||
*/
|
||||
public abstract boolean has(Player player, String string);
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param string
|
||||
* @return true if has permission
|
||||
*/
|
||||
public abstract boolean has(Player player, String string);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param string
|
||||
* @return true if has permission
|
||||
*/
|
||||
public abstract boolean permission(Player player, String string);
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param string
|
||||
* @return true if has permission
|
||||
*/
|
||||
public abstract boolean permission(Player player, String string);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return group name for this player.
|
||||
*/
|
||||
public abstract String getGroup(String userName);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @return group name for this player.
|
||||
*/
|
||||
public abstract String getGroup(String userName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param groupName
|
||||
* @return true if in group
|
||||
*/
|
||||
public abstract boolean inGroup(String userName, String groupName);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param groupName
|
||||
* @return true if in group
|
||||
*/
|
||||
public abstract boolean inGroup(String userName, String groupName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @return String of prefix
|
||||
*/
|
||||
public abstract String getGroupPrefix(String groupName);
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @return String of prefix
|
||||
*/
|
||||
public abstract String getGroupPrefix(String groupName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @return String of suffix
|
||||
*/
|
||||
public abstract String getGroupSuffix(String groupName);
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @return String of suffix
|
||||
*/
|
||||
public abstract String getGroupSuffix(String groupName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @return true if can build
|
||||
*/
|
||||
public abstract boolean canGroupBuild(String groupName);
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @return true if can build
|
||||
*/
|
||||
public abstract boolean canGroupBuild(String groupName);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return String value
|
||||
*/
|
||||
public abstract String getGroupPermissionString(String groupName, String node);
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return String value
|
||||
*/
|
||||
public abstract String getGroupPermissionString(String groupName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return integer value
|
||||
*/
|
||||
public abstract int getGroupPermissionInteger(String groupName, String node);
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return integer value
|
||||
*/
|
||||
public abstract int getGroupPermissionInteger(String groupName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return boolean value
|
||||
*/
|
||||
public abstract boolean getGroupPermissionBoolean(String groupName, String node);
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return boolean value
|
||||
*/
|
||||
public abstract boolean getGroupPermissionBoolean(String groupName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return double value
|
||||
*/
|
||||
public abstract double getGroupPermissionDouble(String groupName, String node);
|
||||
/**
|
||||
*
|
||||
* @param groupName
|
||||
* @param node
|
||||
* @return double value
|
||||
*/
|
||||
public abstract double getGroupPermissionDouble(String groupName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return String value
|
||||
*/
|
||||
public abstract String getUserPermissionString(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return String value
|
||||
*/
|
||||
public abstract String getUserPermissionString(String userName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return integer value
|
||||
*/
|
||||
public abstract int getUserPermissionInteger(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return integer value
|
||||
*/
|
||||
public abstract int getUserPermissionInteger(String userName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return boolean value
|
||||
*/
|
||||
public abstract boolean getUserPermissionBoolean(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return boolean value
|
||||
*/
|
||||
public abstract boolean getUserPermissionBoolean(String userName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return double value
|
||||
*/
|
||||
public abstract double getUserPermissionDouble(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return double value
|
||||
*/
|
||||
public abstract double getUserPermissionDouble(String userName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return String value
|
||||
*/
|
||||
public abstract String getPermissionString(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return String value
|
||||
*/
|
||||
public abstract String getPermissionString(String userName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return integer value
|
||||
*/
|
||||
public abstract int getPermissionInteger(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return integer value
|
||||
*/
|
||||
public abstract int getPermissionInteger(String userName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return boolean value
|
||||
*/
|
||||
public abstract boolean getPermissionBoolean(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return boolean value
|
||||
*/
|
||||
public abstract boolean getPermissionBoolean(String userName, String node);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return double value
|
||||
*/
|
||||
public abstract double getPermissionDouble(String userName, String node);
|
||||
/**
|
||||
*
|
||||
* @param userName
|
||||
* @param node
|
||||
* @return double value
|
||||
*/
|
||||
public abstract double getPermissionDouble(String userName, String node);
|
||||
|
||||
/////////////////////////////
|
||||
/**
|
||||
* Gets the appropriate prefix for the user.
|
||||
* This method is a utility method for chat plugins to get the user's prefix
|
||||
* without having to look at every one of the user's ancestors.
|
||||
* Returns an empty string if user has no parent groups.
|
||||
*
|
||||
* @param user Player's name
|
||||
* @return Player's prefix
|
||||
*/
|
||||
public abstract String getUserPrefix(String user);
|
||||
/////////////////////////////
|
||||
/**
|
||||
* Gets the appropriate prefix for the user.
|
||||
* This method is a utility method for chat plugins to get the user's prefix
|
||||
* without having to look at every one of the user's ancestors.
|
||||
* Returns an empty string if user has no parent groups.
|
||||
*
|
||||
* @param user Player's name
|
||||
* @return Player's prefix
|
||||
*/
|
||||
public abstract String getUserPrefix(String user);
|
||||
|
||||
/**
|
||||
* Gets the appropriate suffix for the user.
|
||||
* This method is a utility method for chat plugins to get the user's suffix
|
||||
* without having to look at every one of the user's ancestors.
|
||||
* Returns an empty string if user has no parent groups.
|
||||
*
|
||||
* @param user Player's name
|
||||
* @return Player's suffix
|
||||
*/
|
||||
public abstract String getUserSuffix(String user);
|
||||
/**
|
||||
* Gets the appropriate suffix for the user.
|
||||
* This method is a utility method for chat plugins to get the user's suffix
|
||||
* without having to look at every one of the user's ancestors.
|
||||
* Returns an empty string if user has no parent groups.
|
||||
*
|
||||
* @param user Player's name
|
||||
* @return Player's suffix
|
||||
*/
|
||||
public abstract String getUserSuffix(String user);
|
||||
|
||||
/**
|
||||
* Returns the group object representing the default group of the given world.
|
||||
* This method will return null if the object does not exist or the world has no default group.
|
||||
* @return Group object representing default world, or null if it doesn't exist or is not defined.
|
||||
*/
|
||||
public abstract Group getDefaultGroup();
|
||||
/**
|
||||
* Returns the group object representing the default group of the given
|
||||
* world.
|
||||
* This method will return null if the object does not exist or the world
|
||||
* has no default group.
|
||||
*
|
||||
* @return Group object representing default world, or null if it doesn't
|
||||
* exist or is not defined.
|
||||
*/
|
||||
public abstract Group getDefaultGroup();
|
||||
|
||||
/**
|
||||
* Gets a array of the names of all parent groups in the same world.
|
||||
* @param name Target user's name
|
||||
* @return An array containing the names of all parent groups (including ancestors) that are in the same world
|
||||
*/
|
||||
public abstract String[] getGroups(String name);
|
||||
/**
|
||||
* Gets a array of the names of all parent groups in the same world.
|
||||
*
|
||||
* @param name Target user's name
|
||||
* @return An array containing the names of all parent groups (including
|
||||
* ancestors) that are in the same world
|
||||
*/
|
||||
public abstract String[] getGroups(String name);
|
||||
|
||||
public abstract String getInfoString(String entryName, String path, boolean isGroup);
|
||||
//public abstract String getInfoString(String entryName, String path, boolean isGroup, Comparator<String> comparator);
|
||||
public abstract String getInfoString(String entryName, String path, boolean isGroup);
|
||||
|
||||
public abstract int getInfoInteger(String entryName, String path, boolean isGroup);
|
||||
//public abstract int getInfoInteger(String entryName, String path, boolean isGroup, Comparator<Integer> comparator);
|
||||
//public abstract String getInfoString(String entryName, String path, boolean isGroup, Comparator<String> comparator);
|
||||
|
||||
/**
|
||||
* Gets a double from the Info node without inheritance.
|
||||
* @param entryName
|
||||
* @param path
|
||||
* @param isGroup
|
||||
* @return -1 if not found
|
||||
*/
|
||||
public abstract double getInfoDouble(String entryName, String path, boolean isGroup);
|
||||
//public abstract double getInfoDouble(String entryName, String path, boolean isGroup, Comparator<Double> comparator);
|
||||
public abstract int getInfoInteger(String entryName, String path, boolean isGroup);
|
||||
|
||||
public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup);
|
||||
//public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup, Comparator<Boolean> comparator);
|
||||
//public abstract int getInfoInteger(String entryName, String path, boolean isGroup, Comparator<Integer> comparator);
|
||||
|
||||
public abstract void addUserInfo(String name, String path, Object data);
|
||||
/**
|
||||
* Gets a double from the Info node without inheritance.
|
||||
*
|
||||
* @param entryName
|
||||
* @param path
|
||||
* @param isGroup
|
||||
* @return -1 if not found
|
||||
*/
|
||||
public abstract double getInfoDouble(String entryName, String path, boolean isGroup);
|
||||
|
||||
public abstract void removeUserInfo(String name, String path);
|
||||
//public abstract double getInfoDouble(String entryName, String path, boolean isGroup, Comparator<Double> comparator);
|
||||
|
||||
public abstract void addGroupInfo(String name, String path, Object data);
|
||||
public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup);
|
||||
|
||||
public abstract void removeGroupInfo(String name, String path);
|
||||
//////////////////////////////
|
||||
//public abstract boolean getInfoBoolean(String entryName, String path, boolean isGroup, Comparator<Boolean> comparator);
|
||||
|
||||
public abstract void addUserInfo(String name, String path, Object data);
|
||||
|
||||
public abstract void removeUserInfo(String name, String path);
|
||||
|
||||
public abstract void addGroupInfo(String name, String path, Object data);
|
||||
|
||||
public abstract void removeGroupInfo(String name, String path);
|
||||
|
||||
//////////////////////////////
|
||||
|
||||
public abstract List<String> getAllPlayersPermissions(String userName);
|
||||
|
||||
|
|
|
@ -14,13 +14,14 @@ import java.util.logging.LogRecord;
|
|||
*/
|
||||
public class GMLoggerHandler extends ConsoleHandler {
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
String message = "GroupManager - " + record.getLevel() + " - " + record.getMessage();
|
||||
if (record.getLevel().equals(Level.SEVERE) || record.getLevel().equals(Level.WARNING)) {
|
||||
System.err.println(message);
|
||||
} else {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
|
||||
String message = "GroupManager - " + record.getLevel() + " - " + record.getMessage();
|
||||
if (record.getLevel().equals(Level.SEVERE) || record.getLevel().equals(Level.WARNING)) {
|
||||
System.err.println(message);
|
||||
} else {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,47 +6,10 @@ package org.anjocaido.groupmanager.utils;
|
|||
|
||||
/**
|
||||
* Just a list of commands for this plugin
|
||||
*
|
||||
* @author gabrielcouto
|
||||
*/
|
||||
public enum GroupManagerPermissions {
|
||||
|
||||
manuadd,
|
||||
manudel,
|
||||
manuaddsub,
|
||||
manudelsub,
|
||||
mangadd,
|
||||
mangdel,
|
||||
manuaddp,
|
||||
manudelp,
|
||||
manulistp,
|
||||
manucheckp,
|
||||
mangaddp,
|
||||
mangdelp,
|
||||
manglistp,
|
||||
mangcheckp,
|
||||
mangaddi,
|
||||
mangdeli,
|
||||
manuaddv,
|
||||
manudelv,
|
||||
manulistv,
|
||||
manucheckv,
|
||||
mangaddv,
|
||||
mangdelv,
|
||||
manglistv,
|
||||
mangcheckv,
|
||||
manwhois,
|
||||
tempadd,
|
||||
tempdel,
|
||||
templist,
|
||||
tempdelall,
|
||||
mansave,
|
||||
manload,
|
||||
listgroups,
|
||||
manpromote,
|
||||
mandemote,
|
||||
mantogglevalidate,
|
||||
mantogglesave,
|
||||
manworld,
|
||||
manselect,
|
||||
manclear
|
||||
manuadd, manudel, manuaddsub, manudelsub, mangadd, mangdel, manuaddp, manudelp, manulistp, manucheckp, mangaddp, mangdelp, manglistp, mangcheckp, mangaddi, mangdeli, manuaddv, manudelv, manulistv, manucheckv, mangaddv, mangdelv, manglistv, mangcheckv, manwhois, tempadd, tempdel, templist, tempdelall, mansave, manload, listgroups, manpromote, mandemote, mantogglevalidate, mantogglesave, manworld, manselect, manclear
|
||||
}
|
||||
|
|
|
@ -12,56 +12,56 @@ import org.anjocaido.groupmanager.data.DataUnit;
|
|||
*/
|
||||
public class PermissionCheckResult {
|
||||
|
||||
/**
|
||||
* It should be the owner of the access level found.
|
||||
*
|
||||
* Use instanceof to find the owner type
|
||||
*/
|
||||
public DataUnit owner;
|
||||
/**
|
||||
* The permission node found in the DataUnit.
|
||||
*/
|
||||
public String accessLevel;
|
||||
/**
|
||||
* The full name of the permission you are looking for
|
||||
*/
|
||||
public String askedPermission;
|
||||
/**
|
||||
* The result conclusion of the search.
|
||||
* It determines if the owner can do, or not.
|
||||
*
|
||||
* It even determines if it has an owner.
|
||||
*/
|
||||
public Type resultType = Type.NOTFOUND;
|
||||
/**
|
||||
* It should be the owner of the access level found.
|
||||
*
|
||||
* Use instanceof to find the owner type
|
||||
*/
|
||||
public DataUnit owner;
|
||||
/**
|
||||
* The permission node found in the DataUnit.
|
||||
*/
|
||||
public String accessLevel;
|
||||
/**
|
||||
* The full name of the permission you are looking for
|
||||
*/
|
||||
public String askedPermission;
|
||||
/**
|
||||
* The result conclusion of the search.
|
||||
* It determines if the owner can do, or not.
|
||||
*
|
||||
* It even determines if it has an owner.
|
||||
*/
|
||||
public Type resultType = Type.NOTFOUND;
|
||||
|
||||
/**
|
||||
* The type of result the search can give.
|
||||
*/
|
||||
public enum Type {
|
||||
/**
|
||||
* The type of result the search can give.
|
||||
*/
|
||||
public enum Type {
|
||||
|
||||
/**
|
||||
* If found a matching node starting with '+'.
|
||||
* It means the user CAN do the permission.
|
||||
*/
|
||||
EXCEPTION,
|
||||
/**
|
||||
* If found a matching node starting with '-'.
|
||||
* It means the user CANNOT do the permission.
|
||||
*/
|
||||
NEGATION,
|
||||
/**
|
||||
* If just found a common matching node.
|
||||
* IT means the user CAN do the permission.
|
||||
*/
|
||||
FOUND,
|
||||
/**
|
||||
* If no matchin node was found.
|
||||
* It means the user CANNOT do the permission.
|
||||
*
|
||||
* owner field and accessLevel field should not be considered,
|
||||
* when type is
|
||||
* NOTFOUND
|
||||
*/
|
||||
NOTFOUND
|
||||
}
|
||||
/**
|
||||
* If found a matching node starting with '+'.
|
||||
* It means the user CAN do the permission.
|
||||
*/
|
||||
EXCEPTION,
|
||||
/**
|
||||
* If found a matching node starting with '-'.
|
||||
* It means the user CANNOT do the permission.
|
||||
*/
|
||||
NEGATION,
|
||||
/**
|
||||
* If just found a common matching node.
|
||||
* IT means the user CAN do the permission.
|
||||
*/
|
||||
FOUND,
|
||||
/**
|
||||
* If no matchin node was found.
|
||||
* It means the user CANNOT do the permission.
|
||||
*
|
||||
* owner field and accessLevel field should not be considered,
|
||||
* when type is
|
||||
* NOTFOUND
|
||||
*/
|
||||
NOTFOUND
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,38 +12,41 @@ import java.util.Comparator;
|
|||
*/
|
||||
public class StringPermissionComparator implements Comparator<String> {
|
||||
|
||||
@Override
|
||||
public int compare(String permA, String permB) {
|
||||
boolean ap = permA.startsWith("+");
|
||||
boolean bp = permB.startsWith("+");
|
||||
boolean am = permA.startsWith("-");
|
||||
boolean bm = permB.startsWith("-");
|
||||
if (ap && bp) {
|
||||
return 0;
|
||||
}
|
||||
if (ap && !bp) {
|
||||
return -1;
|
||||
}
|
||||
if (!ap && bp) {
|
||||
return 1;
|
||||
}
|
||||
if (am && bm) {
|
||||
return 0;
|
||||
}
|
||||
if (am && !bm) {
|
||||
return -1;
|
||||
}
|
||||
if (!am && bm) {
|
||||
return 1;
|
||||
}
|
||||
return permA.compareToIgnoreCase(permB);
|
||||
}
|
||||
private static StringPermissionComparator instance;
|
||||
@Override
|
||||
public int compare(String permA, String permB) {
|
||||
|
||||
public static StringPermissionComparator getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new StringPermissionComparator();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
boolean ap = permA.startsWith("+");
|
||||
boolean bp = permB.startsWith("+");
|
||||
boolean am = permA.startsWith("-");
|
||||
boolean bm = permB.startsWith("-");
|
||||
if (ap && bp) {
|
||||
return 0;
|
||||
}
|
||||
if (ap && !bp) {
|
||||
return -1;
|
||||
}
|
||||
if (!ap && bp) {
|
||||
return 1;
|
||||
}
|
||||
if (am && bm) {
|
||||
return 0;
|
||||
}
|
||||
if (am && !bm) {
|
||||
return -1;
|
||||
}
|
||||
if (!am && bm) {
|
||||
return 1;
|
||||
}
|
||||
return permA.compareToIgnoreCase(permB);
|
||||
}
|
||||
|
||||
private static StringPermissionComparator instance;
|
||||
|
||||
public static StringPermissionComparator getInstance() {
|
||||
|
||||
if (instance == null) {
|
||||
instance = new StringPermissionComparator();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
|||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.data.Group;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author gabrielcouto
|
||||
|
@ -36,35 +35,38 @@ public abstract class Tasks {
|
|||
* @return stack trace as a string
|
||||
*/
|
||||
public static String getStackTraceAsString(Exception exception) {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
exception.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
public static void copy(InputStream src, File dst) throws IOException {
|
||||
InputStream in = src;
|
||||
OutputStream out = new FileOutputStream(dst);
|
||||
public static void copy(InputStream src, File dst) throws IOException {
|
||||
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
InputStream in = src;
|
||||
OutputStream out = new FileOutputStream(dst);
|
||||
|
||||
public static void copy(File src, File dst) throws IOException {
|
||||
InputStream in = new FileInputStream(src);
|
||||
copy(in, dst);
|
||||
}
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
public static void copy(File src, File dst) throws IOException {
|
||||
|
||||
InputStream in = new FileInputStream(src);
|
||||
copy(in, dst);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a string to a file
|
||||
*
|
||||
* @param data
|
||||
|
@ -86,82 +88,88 @@ public abstract class Tasks {
|
|||
out.close();
|
||||
}
|
||||
|
||||
public static void removeOldFiles(GroupManager gm, File folder) {
|
||||
if (folder.isDirectory()) {
|
||||
long oldTime = System.currentTimeMillis() - (((long)gm.getGMConfig().getBackupDuration()*60*60)*1000);
|
||||
for (File olds : folder.listFiles()) {
|
||||
if (olds.isFile()) {
|
||||
if (olds.lastModified() < oldTime) {
|
||||
try {
|
||||
olds.delete();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void removeOldFiles(GroupManager gm, File folder) {
|
||||
|
||||
public static String getDateString() {
|
||||
GregorianCalendar now = new GregorianCalendar();
|
||||
String date = "";
|
||||
date += now.get(Calendar.DAY_OF_MONTH);
|
||||
date += "-";
|
||||
date += now.get(Calendar.HOUR);
|
||||
date += "-";
|
||||
date += now.get(Calendar.MINUTE);
|
||||
return date;
|
||||
}
|
||||
if (folder.isDirectory()) {
|
||||
long oldTime = System.currentTimeMillis() - (((long) gm.getGMConfig().getBackupDuration() * 60 * 60) * 1000);
|
||||
for (File olds : folder.listFiles()) {
|
||||
if (olds.isFile()) {
|
||||
if (olds.lastModified() < oldTime) {
|
||||
try {
|
||||
olds.delete();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getStringListInString(List<String> list) {
|
||||
if (list == null) {
|
||||
return "";
|
||||
}
|
||||
String result = "";
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
result += list.get(i);
|
||||
if (i < list.size() - 1) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String getDateString() {
|
||||
|
||||
public static String getStringArrayInString(String[] list) {
|
||||
if (list == null) {
|
||||
return "";
|
||||
}
|
||||
String result = "";
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
result += list[i];
|
||||
if (i < ((list.length) - 1)) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
GregorianCalendar now = new GregorianCalendar();
|
||||
String date = "";
|
||||
date += now.get(Calendar.DAY_OF_MONTH);
|
||||
date += "-";
|
||||
date += now.get(Calendar.HOUR);
|
||||
date += "-";
|
||||
date += now.get(Calendar.MINUTE);
|
||||
return date;
|
||||
}
|
||||
|
||||
public static String getGroupListInString(List<Group> list) {
|
||||
if (list == null) {
|
||||
return "";
|
||||
}
|
||||
String result = "";
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
result += list.get(i).getName();
|
||||
if (i < list.size() - 1) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static String getStringListInString(List<String> list) {
|
||||
|
||||
public static String join(String[] arr, String separator) {
|
||||
if (arr.length == 0)
|
||||
return "";
|
||||
String out = arr[0].toString();
|
||||
for (int i = 1; i < arr.length; i++)
|
||||
out += separator + arr[i];
|
||||
return out;
|
||||
}
|
||||
if (list == null) {
|
||||
return "";
|
||||
}
|
||||
String result = "";
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
result += list.get(i);
|
||||
if (i < list.size() - 1) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getStringArrayInString(String[] list) {
|
||||
|
||||
if (list == null) {
|
||||
return "";
|
||||
}
|
||||
String result = "";
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
result += list[i];
|
||||
if (i < ((list.length) - 1)) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getGroupListInString(List<Group> list) {
|
||||
|
||||
if (list == null) {
|
||||
return "";
|
||||
}
|
||||
String result = "";
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
result += list.get(i).getName();
|
||||
if (i < list.size() - 1) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String join(String[] arr, String separator) {
|
||||
|
||||
if (arr.length == 0)
|
||||
return "";
|
||||
String out = arr[0].toString();
|
||||
for (int i = 1; i < arr.length; i++)
|
||||
out += separator + arr[i];
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue