mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-06 11:14:08 +00:00
Merge remote branch 'remotes/ess/groupmanager' into essmaster
This commit is contained in:
commit
fd4c82b0eb
|
@ -53,4 +53,20 @@ v 1.5:
|
||||||
- Fixed opOverrides and bukkit_perms_override to read the correct entries.
|
- Fixed opOverrides and bukkit_perms_override to read the correct entries.
|
||||||
- Better commenting in config.yml
|
- Better commenting in config.yml
|
||||||
- Fixed GM to recognize Superperm child nodes.
|
- Fixed GM to recognize Superperm child nodes.
|
||||||
If you add a node like Towny.admin GM will now correctly report on all child nodes.
|
If you add a node like Towny.admin GM will now correctly report on all child nodes.
|
||||||
|
- Fixed GM loading world data files twice at startup.
|
||||||
|
- Improved error reporting for invalid groups.yml
|
||||||
|
- Added Global Groups
|
||||||
|
Defined in groupmanager/globalgroups.yml.
|
||||||
|
Create groups in the yml with a g: prefix, then inherit in the worlds groups files.
|
||||||
|
- Added Info node support to Global Groups.
|
||||||
|
- Fixed an error on 'manucheckv'. If the users doesn't have the variable it fell through causing an exception.
|
||||||
|
- Added checking of subgroups for Info nodes.
|
||||||
|
- Expanded 'canUserBuild()' to include inheritance and subgroups.
|
||||||
|
- Added a config.yml setting of 'validate_toggle' for those who prefer 'mantogglevalidate' to always be off.
|
||||||
|
- Prevent setting 'minutes' in the config to zero causing an error.
|
||||||
|
- GM will now check to see if it's data files have been changed at each scheduled save.
|
||||||
|
If the files have been altered (on disc) it will reload, so long as the in-memory data hasn't changed.
|
||||||
|
If the files on Disc have changed AND there have been changes to it's in-memory data it will show a warning.
|
||||||
|
You then MUST issue a '/mansave force' to overwrite the disc files, or a '/manload' to overwrite the memory data.
|
||||||
|
- Fix for an error in checkFullUserPermission caused by players disconnecting mid perms update.
|
|
@ -8,6 +8,10 @@ settings:
|
||||||
# If the player is op any permissions set to Op will follow suit.
|
# If the player is op any permissions set to Op will follow suit.
|
||||||
bukkit_perms_override: false
|
bukkit_perms_override: false
|
||||||
|
|
||||||
|
# Default setting for 'mantoglevalidate'
|
||||||
|
# true will cause GroupManager to attempt name matching by default.
|
||||||
|
validate_toggle: true
|
||||||
|
|
||||||
data:
|
data:
|
||||||
save:
|
save:
|
||||||
# How often GroupManager will save it's data back to groups and users.yml
|
# How often GroupManager will save it's data back to groups and users.yml
|
||||||
|
|
181
EssentialsGroupManager/src/globalgroups.yml
Normal file
181
EssentialsGroupManager/src/globalgroups.yml
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
groups:
|
||||||
|
|
||||||
|
g:bukkit_default:
|
||||||
|
permissions:
|
||||||
|
- bukkit.broadcast.user
|
||||||
|
|
||||||
|
g:essentials_default:
|
||||||
|
permissions:
|
||||||
|
- essentials.help
|
||||||
|
- essentials.helpop
|
||||||
|
- essentials.list
|
||||||
|
- essentials.motd
|
||||||
|
- essentials.rules
|
||||||
|
- essentials.spawn
|
||||||
|
- groupmanager.notify.self
|
||||||
|
|
||||||
|
g:essentials_builder:
|
||||||
|
permissions:
|
||||||
|
- essentials.afk
|
||||||
|
- essentials.back
|
||||||
|
- essentials.back.ondeath
|
||||||
|
- essentials.balance
|
||||||
|
- essentials.balance.others
|
||||||
|
- essentials.balancetop
|
||||||
|
- essentials.chat.color
|
||||||
|
- essentials.chat.shout
|
||||||
|
- essentials.chat.question
|
||||||
|
- essentials.compass
|
||||||
|
- essentials.depth
|
||||||
|
- essentials.home
|
||||||
|
- essentials.ignore
|
||||||
|
- essentials.kit
|
||||||
|
- essentials.kit.tools
|
||||||
|
- essentials.mail
|
||||||
|
- essentials.mail.send
|
||||||
|
- essentials.me
|
||||||
|
- essentials.msg
|
||||||
|
- essentials.nick
|
||||||
|
- essentials.pay
|
||||||
|
- essentials.ping
|
||||||
|
- essentials.powertool
|
||||||
|
- essentials.protect
|
||||||
|
- essentials.sethome
|
||||||
|
- essentials.signs.use.*
|
||||||
|
- essentials.signs.create.disposal
|
||||||
|
- essentials.signs.create.mail
|
||||||
|
- essentials.signs.create.protection
|
||||||
|
- essentials.signs.create.trade
|
||||||
|
- essentials.signs.break.disposal
|
||||||
|
- essentials.signs.break.mail
|
||||||
|
- essentials.signs.break.protection
|
||||||
|
- essentials.signs.break.trade
|
||||||
|
- essentials.suicide
|
||||||
|
- essentials.time
|
||||||
|
- essentials.tpa
|
||||||
|
- essentials.tpaccept
|
||||||
|
- essentials.tpahere
|
||||||
|
- essentials.tpdeny
|
||||||
|
- essentials.warp
|
||||||
|
- essentials.warp.list
|
||||||
|
- essentials.worth
|
||||||
|
|
||||||
|
g:essentials_moderator:
|
||||||
|
permissions:
|
||||||
|
- essentials.ban
|
||||||
|
- essentials.ban.notify
|
||||||
|
- essentials.banip
|
||||||
|
- essentials.broadcast
|
||||||
|
- essentials.clearinventory
|
||||||
|
- essentials.delwarp
|
||||||
|
- essentials.eco.loan
|
||||||
|
- essentials.ext
|
||||||
|
- essentials.getpos
|
||||||
|
- essentials.helpop.recieve
|
||||||
|
- essentials.home.others
|
||||||
|
- essentials.invsee
|
||||||
|
- essentials.jails
|
||||||
|
- essentials.jump
|
||||||
|
- essentials.kick
|
||||||
|
- essentials.kick.notify
|
||||||
|
- essentials.kill
|
||||||
|
- essentials.mute
|
||||||
|
- essentials.nick.others
|
||||||
|
- essentials.realname
|
||||||
|
- essentials.setwarp
|
||||||
|
- essentials.signs.create.*
|
||||||
|
- essentials.signs.break.*
|
||||||
|
- essentials.spawner
|
||||||
|
- essentials.thunder
|
||||||
|
- essentials.time
|
||||||
|
- essentials.time.set
|
||||||
|
- essentials.protect.alerts
|
||||||
|
- essentials.protect.admin
|
||||||
|
- essentials.protect.ownerinfo
|
||||||
|
- essentials.ptime
|
||||||
|
- essentials.ptime.others
|
||||||
|
- essentials.togglejail
|
||||||
|
- essentials.top
|
||||||
|
- essentials.tp
|
||||||
|
- essentials.tphere
|
||||||
|
- essentials.tppos
|
||||||
|
- essentials.tptoggle
|
||||||
|
- essentials.unban
|
||||||
|
- essentials.unbanip
|
||||||
|
- essentials.weather
|
||||||
|
- essentials.whois
|
||||||
|
- essentials.world
|
||||||
|
- groupmanager.listgroups
|
||||||
|
- groupmanager.mandemote
|
||||||
|
- groupmanager.manpromote
|
||||||
|
- groupmanager.manselect
|
||||||
|
- groupmanager.manuadd
|
||||||
|
- groupmanager.manudel
|
||||||
|
- groupmanager.manwhois
|
||||||
|
- groupmanager.notify.other
|
||||||
|
|
||||||
|
g:essentials_admin:
|
||||||
|
permissions:
|
||||||
|
- -essentials.backup
|
||||||
|
- -essentials.essentials
|
||||||
|
- -essentials.setspawn
|
||||||
|
- -essentials.reloadall
|
||||||
|
- -essentials.plugin
|
||||||
|
- essentials.*
|
||||||
|
- groupmanager.mantogglevalidate
|
||||||
|
- groupmanager.mansave
|
||||||
|
- groupmanager.mangcheckp
|
||||||
|
- groupmanager.manglistp
|
||||||
|
- groupmanager.manucheckp
|
||||||
|
- groupmanager.manulistp
|
||||||
|
|
||||||
|
g:bukkit_moderator:
|
||||||
|
permissions:
|
||||||
|
- bukkit.command.ban
|
||||||
|
- bukkit.command.ban.ip
|
||||||
|
- bukkit.command.ban.player
|
||||||
|
- bukkit.command.gamemode
|
||||||
|
- bukkit.command.kick
|
||||||
|
- bukkit.command.unban
|
||||||
|
- bukkit.command.unban.ip
|
||||||
|
- bukkit.command.unban.player
|
||||||
|
|
||||||
|
g:bukkit_admin:
|
||||||
|
permissions:
|
||||||
|
- bPermissions.admin
|
||||||
|
- bPermissions.demote.admin
|
||||||
|
- bPermissions.gui
|
||||||
|
- bPermissions.iplock.lock
|
||||||
|
- bPermissions.promote.admin
|
||||||
|
- bukkit.broadcast
|
||||||
|
- bukkit.broadcast.admin
|
||||||
|
- bukkit.command
|
||||||
|
- bukkit.command.give
|
||||||
|
- bukkit.command.help
|
||||||
|
- bukkit.command.kill
|
||||||
|
- bukkit.command.list
|
||||||
|
- bukkit.command.me
|
||||||
|
- bukkit.command.op
|
||||||
|
- bukkit.command.op.give
|
||||||
|
- bukkit.command.op.take
|
||||||
|
- bukkit.command.plugins
|
||||||
|
- bukkit.command.reload
|
||||||
|
- bukkit.command.save
|
||||||
|
- bukkit.command.save.disable
|
||||||
|
- bukkit.command.save.enable
|
||||||
|
- bukkit.command.save.perform
|
||||||
|
- bukkit.command.say
|
||||||
|
- bukkit.command.stop
|
||||||
|
- bukkit.command.teleport
|
||||||
|
- bukkit.command.tell
|
||||||
|
- bukkit.command.time
|
||||||
|
- bukkit.command.time.add
|
||||||
|
- bukkit.command.time.set
|
||||||
|
- bukkit.command.version
|
||||||
|
- bukkit.command.whitelist
|
||||||
|
- bukkit.command.whitelist.add
|
||||||
|
- bukkit.command.whitelist.disable
|
||||||
|
- bukkit.command.whitelist.enable
|
||||||
|
- bukkit.command.whitelist.list
|
||||||
|
- bukkit.command.whitelist.reload
|
||||||
|
- bukkit.command.whitelist.remove
|
|
@ -2,147 +2,42 @@ groups:
|
||||||
Default:
|
Default:
|
||||||
default: true
|
default: true
|
||||||
permissions:
|
permissions:
|
||||||
- essentials.help
|
- -bukkit.command.kill
|
||||||
- essentials.helpop
|
inheritance:
|
||||||
- essentials.list
|
- g:essentials_default
|
||||||
- essentials.motd
|
- g:bukkit_default
|
||||||
- essentials.rules
|
|
||||||
- essentials.spawn
|
|
||||||
- groupmanager.notify.self
|
|
||||||
inheritance: []
|
|
||||||
info:
|
info:
|
||||||
prefix: '&e'
|
prefix: '&e'
|
||||||
build: false
|
build: false
|
||||||
suffix: ''
|
suffix: ''
|
||||||
Builder:
|
Builder:
|
||||||
default: false
|
default: false
|
||||||
permissions:
|
permissions: []
|
||||||
- essentials.afk
|
|
||||||
- essentials.back
|
|
||||||
- essentials.back.ondeath
|
|
||||||
- essentials.balance
|
|
||||||
- essentials.balance.others
|
|
||||||
- essentials.balancetop
|
|
||||||
- essentials.chat.color
|
|
||||||
- essentials.chat.shout
|
|
||||||
- essentials.chat.question
|
|
||||||
- essentials.compass
|
|
||||||
- essentials.depth
|
|
||||||
- essentials.home
|
|
||||||
- essentials.ignore
|
|
||||||
- essentials.kit
|
|
||||||
- essentials.kit.tools
|
|
||||||
- essentials.mail
|
|
||||||
- essentials.mail.send
|
|
||||||
- essentials.me
|
|
||||||
- essentials.msg
|
|
||||||
- essentials.nick
|
|
||||||
- essentials.pay
|
|
||||||
- essentials.ping
|
|
||||||
- essentials.powertool
|
|
||||||
- essentials.protect
|
|
||||||
- essentials.sethome
|
|
||||||
- essentials.signs.use.*
|
|
||||||
- essentials.signs.create.disposal
|
|
||||||
- essentials.signs.create.mail
|
|
||||||
- essentials.signs.create.protection
|
|
||||||
- essentials.signs.create.trade
|
|
||||||
- essentials.signs.break.disposal
|
|
||||||
- essentials.signs.break.mail
|
|
||||||
- essentials.signs.break.protection
|
|
||||||
- essentials.signs.break.trade
|
|
||||||
- essentials.suicide
|
|
||||||
- essentials.time
|
|
||||||
- essentials.tpa
|
|
||||||
- essentials.tpaccept
|
|
||||||
- essentials.tpahere
|
|
||||||
- essentials.tpdeny
|
|
||||||
- essentials.warp
|
|
||||||
- essentials.warp.list
|
|
||||||
- essentials.worth
|
|
||||||
inheritance:
|
inheritance:
|
||||||
- default
|
- default
|
||||||
|
- g:essentials_builder
|
||||||
info:
|
info:
|
||||||
prefix: '&2'
|
prefix: '&2'
|
||||||
build: true
|
build: true
|
||||||
suffix: ''
|
suffix: ''
|
||||||
Moderator:
|
Moderator:
|
||||||
default: false
|
default: false
|
||||||
permissions:
|
permissions: []
|
||||||
- essentials.ban
|
|
||||||
- essentials.ban.notify
|
|
||||||
- essentials.banip
|
|
||||||
- essentials.broadcast
|
|
||||||
- essentials.clearinventory
|
|
||||||
- essentials.delwarp
|
|
||||||
- essentials.eco.loan
|
|
||||||
- essentials.ext
|
|
||||||
- essentials.getpos
|
|
||||||
- essentials.helpop.recieve
|
|
||||||
- essentials.home.others
|
|
||||||
- essentials.invsee
|
|
||||||
- essentials.jails
|
|
||||||
- essentials.jump
|
|
||||||
- essentials.kick
|
|
||||||
- essentials.kick.notify
|
|
||||||
- essentials.kill
|
|
||||||
- essentials.mute
|
|
||||||
- essentials.nick.others
|
|
||||||
- essentials.realname
|
|
||||||
- essentials.setwarp
|
|
||||||
- essentials.signs.create.*
|
|
||||||
- essentials.signs.break.*
|
|
||||||
- essentials.spawner
|
|
||||||
- essentials.thunder
|
|
||||||
- essentials.time
|
|
||||||
- essentials.time.set
|
|
||||||
- essentials.protect.alerts
|
|
||||||
- essentials.protect.admin
|
|
||||||
- essentials.protect.ownerinfo
|
|
||||||
- essentials.ptime
|
|
||||||
- essentials.ptime.others
|
|
||||||
- essentials.togglejail
|
|
||||||
- essentials.top
|
|
||||||
- essentials.tp
|
|
||||||
- essentials.tphere
|
|
||||||
- essentials.tppos
|
|
||||||
- essentials.tptoggle
|
|
||||||
- essentials.unban
|
|
||||||
- essentials.unbanip
|
|
||||||
- essentials.weather
|
|
||||||
- essentials.whois
|
|
||||||
- essentials.world
|
|
||||||
- groupmanager.listgroups
|
|
||||||
- groupmanager.mandemote
|
|
||||||
- groupmanager.manpromote
|
|
||||||
- groupmanager.manselect
|
|
||||||
- groupmanager.manuadd
|
|
||||||
- groupmanager.manudel
|
|
||||||
- groupmanager.manwhois
|
|
||||||
- groupmanager.notify.other
|
|
||||||
inheritance:
|
inheritance:
|
||||||
- builder
|
- builder
|
||||||
|
- g:essentials_moderator
|
||||||
|
- g:bukkit_moderator
|
||||||
info:
|
info:
|
||||||
prefix: '&5'
|
prefix: '&5'
|
||||||
build: true
|
build: true
|
||||||
suffix: ''
|
suffix: ''
|
||||||
Admin:
|
Admin:
|
||||||
default: false
|
default: false
|
||||||
permissions:
|
permissions: []
|
||||||
- -essentials.backup
|
|
||||||
- -essentials.essentials
|
|
||||||
- -essentials.setspawn
|
|
||||||
- -essentials.reloadall
|
|
||||||
- -essentials.plugin
|
|
||||||
- essentials.*
|
|
||||||
- groupmanager.mantogglevalidate
|
|
||||||
- groupmanager.mansave
|
|
||||||
- groupmanager.mangcheckp
|
|
||||||
- groupmanager.manglistp
|
|
||||||
- groupmanager.manucheckp
|
|
||||||
- groupmanager.manulistp
|
|
||||||
inheritance:
|
inheritance:
|
||||||
- moderator
|
- moderator
|
||||||
|
- g:essentials_admin
|
||||||
|
- g:bukkit_admin
|
||||||
info:
|
info:
|
||||||
prefix: '&c'
|
prefix: '&c'
|
||||||
build: true
|
build: true
|
||||||
|
|
|
@ -48,7 +48,10 @@ public class GMConfiguration {
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
|
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + configFile.getPath(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup defaults
|
||||||
adjustLoggerLevel();
|
adjustLoggerLevel();
|
||||||
|
plugin.setValidateOnlinePlayer(isToggleValidate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOpOverride() {
|
public boolean isOpOverride() {
|
||||||
|
@ -57,6 +60,9 @@ public class GMConfiguration {
|
||||||
public boolean isBukkitPermsOverride() {
|
public boolean isBukkitPermsOverride() {
|
||||||
return GMconfig.getBoolean("settings.config.bukkit_perms_override", false);
|
return GMconfig.getBoolean("settings.config.bukkit_perms_override", false);
|
||||||
}
|
}
|
||||||
|
public boolean isToggleValidate() {
|
||||||
|
return GMconfig.getBoolean("settings.config.validate_toggle", true);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Object> getMirrorsMap() {
|
public Map<String, Object> getMirrorsMap() {
|
||||||
// Try to fetch the old mirror path first
|
// Try to fetch the old mirror path first
|
||||||
|
|
|
@ -0,0 +1,393 @@
|
||||||
|
package org.anjocaido.groupmanager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.anjocaido.groupmanager.data.Group;
|
||||||
|
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
||||||
|
import org.anjocaido.groupmanager.utils.Tasks;
|
||||||
|
import org.bukkit.configuration.MemorySection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ElgarL
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class GlobalGroups {
|
||||||
|
|
||||||
|
private GroupManager plugin;
|
||||||
|
private YamlConfiguration GGroups;
|
||||||
|
|
||||||
|
private Map<String, Group> groups;
|
||||||
|
|
||||||
|
protected long timeStampGroups = 0;
|
||||||
|
protected boolean haveGroupsChanged = false;
|
||||||
|
protected File GlobalGroupsFile = null;
|
||||||
|
|
||||||
|
public GlobalGroups(GroupManager plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the haveGroupsChanged
|
||||||
|
*/
|
||||||
|
public boolean haveGroupsChanged() {
|
||||||
|
if (this.haveGroupsChanged) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (Group g : groups.values()) {
|
||||||
|
if (g.isChanged()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the timeStampGroups
|
||||||
|
*/
|
||||||
|
public long getTimeStampGroups() {
|
||||||
|
return timeStampGroups;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param timeStampGroups the timeStampGroups to set
|
||||||
|
*/
|
||||||
|
protected void setTimeStampGroups(long timeStampGroups) {
|
||||||
|
this.timeStampGroups = timeStampGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param haveGroupsChanged
|
||||||
|
* the haveGroupsChanged to set
|
||||||
|
*/
|
||||||
|
public void setGroupsChanged(boolean haveGroupsChanged) {
|
||||||
|
this.haveGroupsChanged = haveGroupsChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void load() {
|
||||||
|
|
||||||
|
GGroups = new YamlConfiguration();
|
||||||
|
groups = new HashMap<String, Group>();
|
||||||
|
|
||||||
|
GroupManager.setLoaded(false);
|
||||||
|
|
||||||
|
// READ globalGroups FILE
|
||||||
|
if (GlobalGroupsFile == null)
|
||||||
|
GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
|
||||||
|
|
||||||
|
if (!GlobalGroupsFile.exists()) {
|
||||||
|
try {
|
||||||
|
// Create a new file if it doesn't exist.
|
||||||
|
Tasks.copy(plugin.getResourceAsStream("globalgroups.yml"), GlobalGroupsFile);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
GroupManager.logger.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
GGroups.load(GlobalGroupsFile);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new IllegalArgumentException("The following file couldn't pass on Parser.\n" + GlobalGroupsFile.getPath(), ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read all global groups
|
||||||
|
Map<String, Object> allGroups = (Map<String, Object>) GGroups.getConfigurationSection("groups").getValues(false);
|
||||||
|
|
||||||
|
// Load each groups permissions list.
|
||||||
|
if (allGroups != null)
|
||||||
|
for (String groupName : allGroups.keySet()) {
|
||||||
|
Group newGroup = new Group(groupName.toLowerCase());
|
||||||
|
Object element;
|
||||||
|
|
||||||
|
// Permission nodes
|
||||||
|
element = GGroups.get("groups." + groupName + ".permissions");
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
if (element instanceof List) {
|
||||||
|
for (String node : (List<String>) element) {
|
||||||
|
newGroup.addPermission(node);
|
||||||
|
}
|
||||||
|
} else if (element instanceof String) {
|
||||||
|
newGroup.addPermission((String) element);
|
||||||
|
} else
|
||||||
|
throw new IllegalArgumentException("Unknown type of permission node for global group: " + groupName);
|
||||||
|
|
||||||
|
// Info nodes
|
||||||
|
element = GGroups.get("groups." + groupName + ".info");
|
||||||
|
|
||||||
|
if (element != null)
|
||||||
|
if (element instanceof MemorySection) {
|
||||||
|
Map<String, Object> vars = new HashMap<String, Object>();
|
||||||
|
for (String key : ((MemorySection) element).getKeys(false)) {
|
||||||
|
vars.put(key, ((MemorySection) element).get(key));
|
||||||
|
}
|
||||||
|
newGroup.setVariables(vars);
|
||||||
|
} else
|
||||||
|
throw new IllegalArgumentException("Unknown type of info node for global group: " + groupName);
|
||||||
|
|
||||||
|
// Push a new group
|
||||||
|
addGroup(newGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeGroupsChangedFlag();
|
||||||
|
setTimeStampGroups(GlobalGroupsFile.lastModified());
|
||||||
|
GroupManager.setLoaded(true);
|
||||||
|
//GlobalGroupsFile = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write the globalgroups.yml file
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void writeGroups(boolean overwrite) {
|
||||||
|
|
||||||
|
//File GlobalGroupsFile = new File(plugin.getDataFolder(), "globalgroups.yml");
|
||||||
|
|
||||||
|
if (haveGroupsChanged()) {
|
||||||
|
if (overwrite || (!overwrite && (getTimeStampGroups() >= GlobalGroupsFile.lastModified()))) {
|
||||||
|
Map<String, Object> root = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
Map<String, Object> groupsMap = new HashMap<String, Object>();
|
||||||
|
root.put("groups", groupsMap);
|
||||||
|
for (String groupKey : groups.keySet()) {
|
||||||
|
Group group = groups.get(groupKey);
|
||||||
|
|
||||||
|
// Group header
|
||||||
|
Map<String, Object> aGroupMap = new HashMap<String, Object>();
|
||||||
|
groupsMap.put(group.getName(), aGroupMap);
|
||||||
|
|
||||||
|
// Info nodes
|
||||||
|
Map<String, Object> infoMap = new HashMap<String, Object>();
|
||||||
|
aGroupMap.put("info", infoMap);
|
||||||
|
|
||||||
|
for (String infoKey : group.getVariables().getVarKeyList()) {
|
||||||
|
infoMap.put(infoKey, group.getVariables().getVarObject(infoKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Permission nodes
|
||||||
|
aGroupMap.put("permissions", group.getPermissionList());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!root.isEmpty()) {
|
||||||
|
DumperOptions opt = new DumperOptions();
|
||||||
|
opt.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
||||||
|
final Yaml yaml = new Yaml(opt);
|
||||||
|
try {
|
||||||
|
yaml.dump(root, new OutputStreamWriter(new FileOutputStream(GlobalGroupsFile), "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException ex) {
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTimeStampGroups(GlobalGroupsFile.lastModified());
|
||||||
|
} else {
|
||||||
|
// Newer file found.
|
||||||
|
GroupManager.logger.log(Level.WARNING, "Newer GlobalGroups file found, but we have local changes!");
|
||||||
|
throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
|
||||||
|
}
|
||||||
|
removeGroupsChangedFlag();
|
||||||
|
} else {
|
||||||
|
//Check for newer file as no local changes.
|
||||||
|
if (getTimeStampGroups() < GlobalGroupsFile.lastModified()) {
|
||||||
|
System.out.print("Newer GlobalGroups file found (Loading changes)!");
|
||||||
|
// Backup GlobalGroups file
|
||||||
|
backupFile();
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backup the BlobalGroups file
|
||||||
|
* @param w
|
||||||
|
*/
|
||||||
|
private void backupFile() {
|
||||||
|
|
||||||
|
File backupFile = new File(plugin.getBackupFolder(), "bkp_ggroups_" + Tasks.getDateString() + ".yml");
|
||||||
|
try {
|
||||||
|
Tasks.copy(GlobalGroupsFile, backupFile);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
GroupManager.logger.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a group, or replaces an existing one.
|
||||||
|
*
|
||||||
|
* @param groupToAdd
|
||||||
|
*/
|
||||||
|
public void addGroup(Group groupToAdd) {
|
||||||
|
// Create a new group if it already exists
|
||||||
|
if (hasGroup(groupToAdd.getName())) {
|
||||||
|
groupToAdd = groupToAdd.clone();
|
||||||
|
removeGroup(groupToAdd.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
newGroup(groupToAdd);
|
||||||
|
haveGroupsChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new group if it doesn't already exist.
|
||||||
|
*
|
||||||
|
* @param newGroup
|
||||||
|
*/
|
||||||
|
public Group newGroup(Group newGroup) {
|
||||||
|
// Push a new group
|
||||||
|
if (!groups.containsKey(newGroup.getName().toLowerCase())) {
|
||||||
|
groups.put(newGroup.getName().toLowerCase(), newGroup);
|
||||||
|
this.setGroupsChanged(true);
|
||||||
|
return newGroup;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a group if it exist.
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
*/
|
||||||
|
public boolean removeGroup(String groupName) {
|
||||||
|
// Push a new group
|
||||||
|
if (groups.containsKey(groupName.toLowerCase())) {
|
||||||
|
groups.remove(groupName.toLowerCase());
|
||||||
|
this.setGroupsChanged(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the Global Group exists in the globalgroups.yml
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @return true if the group exists
|
||||||
|
*/
|
||||||
|
public boolean hasGroup(String groupName) {
|
||||||
|
return groups.containsKey(groupName.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the group has the correct permission node.
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @param permissionNode
|
||||||
|
* @return true if node exists
|
||||||
|
*/
|
||||||
|
public boolean hasPermission(String groupName, String permissionNode) {
|
||||||
|
|
||||||
|
if (!hasGroup(groupName.toLowerCase()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return groups.get(groupName.toLowerCase()).hasSamePermissionNode(permissionNode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a PermissionCheckResult of the permission node for the group to
|
||||||
|
* be tested against.
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @param permissionNode
|
||||||
|
* @return PermissionCheckResult object
|
||||||
|
*/
|
||||||
|
public PermissionCheckResult checkPermission(String groupName, String permissionNode) {
|
||||||
|
|
||||||
|
PermissionCheckResult result = new PermissionCheckResult();
|
||||||
|
result.askedPermission = permissionNode;
|
||||||
|
result.resultType = PermissionCheckResult.Type.NOTFOUND;
|
||||||
|
|
||||||
|
if (!hasGroup(groupName.toLowerCase()))
|
||||||
|
return result;
|
||||||
|
|
||||||
|
Group tempGroup = groups.get(groupName.toLowerCase());
|
||||||
|
|
||||||
|
if (tempGroup.hasSamePermissionNode(permissionNode))
|
||||||
|
result.resultType = PermissionCheckResult.Type.FOUND;
|
||||||
|
if (tempGroup.hasSamePermissionNode("-" + permissionNode))
|
||||||
|
result.resultType = PermissionCheckResult.Type.NEGATION;
|
||||||
|
if (tempGroup.hasSamePermissionNode("+" + permissionNode))
|
||||||
|
result.resultType = PermissionCheckResult.Type.EXCEPTION;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a List of all permission nodes for this group null if none
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @return List of all group names
|
||||||
|
*/
|
||||||
|
public List<String> getGroupsPermissions(String groupName) {
|
||||||
|
if (!hasGroup(groupName.toLowerCase()))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return groups.get(groupName.toLowerCase()).getPermissionList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a Set of all global group names.
|
||||||
|
*
|
||||||
|
* @return Set containing all group names.
|
||||||
|
*/
|
||||||
|
public Set<String> getGlobalGroups() {
|
||||||
|
return groups.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return a collection of the groups
|
||||||
|
*/
|
||||||
|
public Collection<Group> getGroupList() {
|
||||||
|
return groups.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Global Group or null if it doesn't exist.
|
||||||
|
*
|
||||||
|
* @param groupName
|
||||||
|
* @return Group object
|
||||||
|
*/
|
||||||
|
public Group getGroup(String groupName) {
|
||||||
|
if (!hasGroup(groupName.toLowerCase()))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return groups.get(groupName.toLowerCase());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the globalGroupsFile
|
||||||
|
*/
|
||||||
|
public File getGlobalGroupsFile() {
|
||||||
|
return GlobalGroupsFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void removeGroupsChangedFlag() {
|
||||||
|
setGroupsChanged(false);
|
||||||
|
for (Group g : groups.values()) {
|
||||||
|
g.flagAsSaved();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load diff
|
@ -26,7 +26,11 @@ public abstract class DataUnit {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public DataUnit(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Every group is matched only by their names and DataSources names.
|
* Every group is matched only by their names and DataSources names.
|
||||||
* @param o
|
* @param o
|
||||||
* @return true if they are equal. false if not.
|
* @return true if they are equal. false if not.
|
||||||
|
@ -64,7 +68,15 @@ public abstract class DataUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flagAsChanged() {
|
public void flagAsChanged() {
|
||||||
GroupManager.logger.finest("DataSource: " + getDataSource().getName() + " - DataUnit: " + getName() + " flagged as changed!");
|
WorldDataHolder testSource = getDataSource();
|
||||||
|
String source = "";
|
||||||
|
|
||||||
|
if (testSource == null)
|
||||||
|
source = "GlobalGroups";
|
||||||
|
else
|
||||||
|
source = testSource.getName();
|
||||||
|
|
||||||
|
GroupManager.logger.finest("DataSource: " + source + " - DataUnit: " + getName() + " flagged as changed!");
|
||||||
// for(StackTraceElement st: Thread.currentThread().getStackTrace()){
|
// for(StackTraceElement st: Thread.currentThread().getStackTrace()){
|
||||||
// GroupManager.logger.finest(st.toString());
|
// GroupManager.logger.finest(st.toString());
|
||||||
// }
|
// }
|
||||||
|
@ -76,7 +88,15 @@ public abstract class DataUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flagAsSaved() {
|
public void flagAsSaved() {
|
||||||
GroupManager.logger.finest("DataSource: " + getDataSource().getName() + " - DataUnit: " + getName() + " flagged as saved!");
|
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;
|
changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,22 @@ public class Group extends DataUnit implements Cloneable {
|
||||||
private GroupVariables variables = new GroupVariables(this);
|
private GroupVariables variables = new GroupVariables(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor for individual World Groups.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public Group(WorldDataHolder source, String name) {
|
public Group(WorldDataHolder source, String name) {
|
||||||
super(source, name);
|
super(source, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for Global Groups.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public Group(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone this group
|
* Clone this group
|
||||||
|
@ -40,8 +50,15 @@ public class Group extends DataUnit implements Cloneable {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Group clone() {
|
public Group clone() {
|
||||||
Group clone = new Group(getDataSource(), this.getName());
|
Group clone;
|
||||||
clone.inherits = new ArrayList<String>(this.getInherits());
|
|
||||||
|
if (getDataSource() == null) {
|
||||||
|
clone = new Group(this.getName());
|
||||||
|
} else {
|
||||||
|
clone = new Group(getDataSource(), this.getName());
|
||||||
|
clone.inherits = new ArrayList<String>(this.getInherits());
|
||||||
|
}
|
||||||
|
|
||||||
for (String perm : this.getPermissionList()) {
|
for (String perm : this.getPermissionList()) {
|
||||||
clone.addPermission(perm);
|
clone.addPermission(perm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class GroupVariables extends Variables implements Cloneable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A clone of all vars here.
|
* A clone of all vars here.
|
||||||
* @return
|
* @return GroupVariables clone
|
||||||
*/
|
*/
|
||||||
protected GroupVariables clone(Group newOwner) {
|
protected GroupVariables clone(Group newOwner) {
|
||||||
GroupVariables clone = new GroupVariables(newOwner);
|
GroupVariables clone = new GroupVariables(newOwner);
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class User extends DataUnit implements Cloneable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return User clone
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public User clone() {
|
public User clone() {
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class UserVariables extends Variables {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A clone of all vars here.
|
* A clone of all vars here.
|
||||||
* @return
|
* @return UserVariables clone
|
||||||
*/
|
*/
|
||||||
protected UserVariables clone(User newOwner) {
|
protected UserVariables clone(User newOwner) {
|
||||||
UserVariables clone = new UserVariables(newOwner);
|
UserVariables clone = new UserVariables(newOwner);
|
||||||
|
|
|
@ -115,7 +115,7 @@ public abstract class Variables implements Cloneable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All variable keys this is holding
|
* All variable keys this is holding
|
||||||
* @return
|
* @return Set of all variable names.
|
||||||
*/
|
*/
|
||||||
public Set<String> getVarKeyList() {
|
public Set<String> getVarKeyList() {
|
||||||
return variables.keySet();
|
return variables.keySet();
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param userName
|
* @param userName
|
||||||
* @return
|
* @return user object or a new user if none exists.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public User getUser(String userName) {
|
public User getUser(String userName) {
|
||||||
|
@ -86,7 +86,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param userName
|
* @param userName
|
||||||
* @return
|
* @return true if removed/false if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean removeUser(String userName) {
|
public boolean removeUser(String userName) {
|
||||||
|
@ -137,7 +137,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return Collection of all users
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<User> getUserList() {
|
public Collection<User> getUserList() {
|
||||||
|
@ -156,7 +156,7 @@ public class OverloadedWorldHolder extends WorldDataHolder {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param userName
|
* @param userName
|
||||||
* @return
|
* @return true if user is overloaded.
|
||||||
*/
|
*/
|
||||||
public boolean isOverloaded(String userName) {
|
public boolean isOverloaded(String userName) {
|
||||||
return overloadedUsers.containsKey(userName.toLowerCase());
|
return overloadedUsers.containsKey(userName.toLowerCase());
|
||||||
|
@ -189,8 +189,9 @@ public class OverloadedWorldHolder extends WorldDataHolder {
|
||||||
* Gets the user in normal state. Surpassing the overload state.
|
* Gets the user in normal state. Surpassing the overload state.
|
||||||
* It doesn't affect permissions. But it enables plugins change the
|
* It doesn't affect permissions. But it enables plugins change the
|
||||||
* actual user permissions even in overload mode.
|
* actual user permissions even in overload mode.
|
||||||
|
*
|
||||||
* @param userName
|
* @param userName
|
||||||
* @return
|
* @return user object
|
||||||
*/
|
*/
|
||||||
public User surpassOverload(String userName) {
|
public User surpassOverload(String userName) {
|
||||||
if (!isOverloaded(userName)) {
|
if (!isOverloaded(userName)) {
|
||||||
|
|
|
@ -45,20 +45,23 @@ public class WorldDataHolder {
|
||||||
* The actual groups holder
|
* The actual groups holder
|
||||||
*/
|
*/
|
||||||
protected Map<String, Group> groups = new HashMap<String, Group>();
|
protected Map<String, Group> groups = new HashMap<String, Group>();
|
||||||
/**
|
/**
|
||||||
* The actual users holder
|
* The actual users holder
|
||||||
*/
|
*/
|
||||||
protected Map<String, User> users = new HashMap<String, User>();
|
protected Map<String, User> users = new HashMap<String, User>();
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* Points to the default group
|
* Points to the default group
|
||||||
*/
|
*/
|
||||||
protected Group defaultGroup = null;
|
protected Group defaultGroup = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The file, which this class loads/save data from/to
|
* The file, which this class loads/save data from/to
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected File f;
|
protected File f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -79,8 +82,17 @@ public class WorldDataHolder {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected boolean haveGroupsChanged = false;
|
protected boolean haveGroupsChanged = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected long timeStampGroups = 0;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected long timeStampUsers = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
* Prevent direct instantiation
|
* Prevent direct instantiation
|
||||||
* @param worldName
|
* @param worldName
|
||||||
*/
|
*/
|
||||||
|
@ -151,7 +163,7 @@ public class WorldDataHolder {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param userName
|
* @param userName
|
||||||
* @return
|
* @return true if we have data for this player.
|
||||||
*/
|
*/
|
||||||
public boolean isUserDeclared(String userName) {
|
public boolean isUserDeclared(String userName) {
|
||||||
return users.containsKey(userName.toLowerCase());
|
return users.containsKey(userName.toLowerCase());
|
||||||
|
@ -183,7 +195,10 @@ public class WorldDataHolder {
|
||||||
* @return a group if it is found. null if not found.
|
* @return a group if it is found. null if not found.
|
||||||
*/
|
*/
|
||||||
public Group getGroup(String groupName) {
|
public Group getGroup(String groupName) {
|
||||||
return groups.get(groupName.toLowerCase());
|
if (groupName.startsWith("g:"))
|
||||||
|
return GroupManager.getGlobalGroups().getGroup(groupName);
|
||||||
|
else
|
||||||
|
return groups.get(groupName.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,7 +208,10 @@ public class WorldDataHolder {
|
||||||
* @return true if exists. false if not.
|
* @return true if exists. false if not.
|
||||||
*/
|
*/
|
||||||
public boolean groupExists(String groupName) {
|
public boolean groupExists(String groupName) {
|
||||||
return groups.containsKey(groupName.toLowerCase());
|
if (groupName.startsWith("g:"))
|
||||||
|
return GroupManager.getGlobalGroups().hasGroup(groupName);
|
||||||
|
else
|
||||||
|
return groups.containsKey(groupName.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,6 +219,11 @@ public class WorldDataHolder {
|
||||||
* @param groupToAdd
|
* @param groupToAdd
|
||||||
*/
|
*/
|
||||||
public void addGroup(Group groupToAdd) {
|
public void addGroup(Group groupToAdd) {
|
||||||
|
if (groupToAdd.getName().startsWith("g:")) {
|
||||||
|
GroupManager.getGlobalGroups().addGroup(groupToAdd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (groupToAdd.getDataSource() != this) {
|
if (groupToAdd.getDataSource() != this) {
|
||||||
groupToAdd = groupToAdd.clone(this);
|
groupToAdd = groupToAdd.clone(this);
|
||||||
}
|
}
|
||||||
|
@ -215,6 +238,10 @@ public class WorldDataHolder {
|
||||||
* @return true if had something to remove. false the group was default or non-existant
|
* @return true if had something to remove. false the group was default or non-existant
|
||||||
*/
|
*/
|
||||||
public boolean removeGroup(String groupName) {
|
public boolean removeGroup(String groupName) {
|
||||||
|
if (groupName.startsWith("g:")) {
|
||||||
|
return GroupManager.getGlobalGroups().removeGroup(groupName);
|
||||||
|
}
|
||||||
|
|
||||||
if (defaultGroup != null && groupName.equalsIgnoreCase(defaultGroup.getName())) {
|
if (defaultGroup != null && groupName.equalsIgnoreCase(defaultGroup.getName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -251,10 +278,16 @@ public class WorldDataHolder {
|
||||||
* @return null if group already exists. or new Group
|
* @return null if group already exists. or new Group
|
||||||
*/
|
*/
|
||||||
public Group createGroup(String groupName) {
|
public Group createGroup(String groupName) {
|
||||||
if (this.groups.containsKey(groupName.toLowerCase())) {
|
if (groupName.startsWith("g:")) {
|
||||||
|
Group newGroup = new Group(groupName);
|
||||||
|
return GroupManager.getGlobalGroups().newGroup(newGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.groups.containsKey(groupName.toLowerCase())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Group newGroup = new Group(this, groupName);
|
|
||||||
|
Group newGroup = new Group(this, groupName);
|
||||||
this.addGroup(newGroup);
|
this.addGroup(newGroup);
|
||||||
haveGroupsChanged = true;
|
haveGroupsChanged = true;
|
||||||
return newGroup;
|
return newGroup;
|
||||||
|
@ -281,14 +314,34 @@ public class WorldDataHolder {
|
||||||
*/
|
*/
|
||||||
public void reload() {
|
public void reload() {
|
||||||
try {
|
try {
|
||||||
WorldDataHolder ph = load(this.getName(), getGroupsFile(), getUsersFile());
|
reloadGroups();
|
||||||
this.defaultGroup = ph.defaultGroup;
|
reloadUsers();
|
||||||
this.groups = ph.groups;
|
|
||||||
this.users = ph.users;
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reloadGroups() {
|
||||||
|
GroupManager.setLoaded(false);
|
||||||
|
try {
|
||||||
|
resetGroups();
|
||||||
|
loadGroups(this, getGroupsFile());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
GroupManager.setLoaded(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadUsers() {
|
||||||
|
GroupManager.setLoaded(false);
|
||||||
|
try {
|
||||||
|
resetUsers();
|
||||||
|
loadUsers(this, getUsersFile());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
GroupManager.setLoaded(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save by yourself!
|
* Save by yourself!
|
||||||
|
@ -302,9 +355,11 @@ public class WorldDataHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a data holder for the given file
|
* Returns a data holder for the given file
|
||||||
|
*
|
||||||
* @param worldName
|
* @param worldName
|
||||||
* @param file
|
* @param file
|
||||||
* @return
|
* @return a new WorldDataHolder
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
|
@ -448,26 +503,66 @@ public class WorldDataHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a data holder for the given file
|
* Returns a NEW data holder containing data read from the files
|
||||||
|
*
|
||||||
* @param worldName
|
* @param worldName
|
||||||
* @param groupsFile
|
* @param groupsFile
|
||||||
* @param usersFile
|
* @param usersFile
|
||||||
* @return
|
*
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static WorldDataHolder load(String worldName, File groupsFile, File usersFile) throws FileNotFoundException, IOException {
|
||||||
|
WorldDataHolder ph = new WorldDataHolder(worldName);
|
||||||
|
|
||||||
|
GroupManager.setLoaded(false);
|
||||||
|
loadGroups(ph, groupsFile);
|
||||||
|
loadUsers(ph, usersFile);
|
||||||
|
GroupManager.setLoaded(true);
|
||||||
|
|
||||||
|
return ph;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the WorldDataHolder from the files
|
||||||
|
*
|
||||||
|
* @param ph
|
||||||
|
* @param groupsFile
|
||||||
|
* @param usersFile
|
||||||
|
*
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static WorldDataHolder Update(WorldDataHolder ph, File groupsFile, File usersFile) throws FileNotFoundException, IOException {
|
||||||
|
|
||||||
|
GroupManager.setLoaded(false);
|
||||||
|
ph.resetGroups();
|
||||||
|
loadGroups(ph, groupsFile);
|
||||||
|
|
||||||
|
ph.resetUsers();
|
||||||
|
loadUsers(ph, usersFile);
|
||||||
|
GroupManager.setLoaded(true);
|
||||||
|
|
||||||
|
return ph;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the WorldDataHolder from the Groups file
|
||||||
|
*
|
||||||
|
* @param ph
|
||||||
|
* @param groupsFile
|
||||||
|
*
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public static WorldDataHolder load(String worldName, File groupsFile, File usersFile) throws FileNotFoundException, IOException {
|
protected static void loadGroups(WorldDataHolder ph, File groupsFile) throws FileNotFoundException, IOException {
|
||||||
WorldDataHolder ph = new WorldDataHolder(worldName);
|
|
||||||
ph.groupsFile = groupsFile;
|
|
||||||
ph.usersFile = usersFile;
|
|
||||||
|
|
||||||
|
|
||||||
//READ GROUPS FILE
|
//READ GROUPS FILE
|
||||||
Yaml yamlGroups = new Yaml(new SafeConstructor());
|
Yaml yamlGroups = new Yaml(new SafeConstructor());
|
||||||
Map<String, Object> groupsRootDataNode;
|
Map<String, Object> groupsRootDataNode;
|
||||||
if (!groupsFile.exists()) {
|
if (!groupsFile.exists()) {
|
||||||
throw new IllegalArgumentException("The file which should contain permissions does not exist!\n" + groupsFile.getPath());
|
throw new IllegalArgumentException("The file which should contain groups does not exist!\n" + groupsFile.getPath());
|
||||||
}
|
}
|
||||||
FileInputStream groupsInputStream = new FileInputStream(groupsFile);
|
FileInputStream groupsInputStream = new FileInputStream(groupsFile);
|
||||||
try {
|
try {
|
||||||
|
@ -483,7 +578,7 @@ public class WorldDataHolder {
|
||||||
|
|
||||||
//PROCESS GROUPS FILE
|
//PROCESS GROUPS FILE
|
||||||
Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
|
Map<String, List<String>> inheritance = new HashMap<String, List<String>>();
|
||||||
try {
|
//try {
|
||||||
Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
|
Map<String, Object> allGroupsNode = (Map<String, Object>) groupsRootDataNode.get("groups");
|
||||||
for (String groupKey : allGroupsNode.keySet()) {
|
for (String groupKey : allGroupsNode.keySet()) {
|
||||||
Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
|
Map<String, Object> thisGroupNode = (Map<String, Object>) allGroupsNode.get(groupKey);
|
||||||
|
@ -513,36 +608,43 @@ public class WorldDataHolder {
|
||||||
} else if (thisGroupNode.get("permissions") instanceof String) {
|
} else if (thisGroupNode.get("permissions") instanceof String) {
|
||||||
thisGrp.addPermission((String) thisGroupNode.get("permissions"));
|
thisGrp.addPermission((String) thisGroupNode.get("permissions"));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>): " + thisGroupNode.get("permissions").getClass().getName());
|
throw new IllegalArgumentException("Unknown type of permissions node(Should be String or List<String>) for group: " + thisGrp.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
//INFO NODE
|
//INFO NODE
|
||||||
Map<String, Object> infoNode = (Map<String, Object>) thisGroupNode.get("info");
|
if (thisGroupNode.get("info") instanceof Map) {
|
||||||
if (infoNode != null) {
|
Map<String, Object> infoNode = (Map<String, Object>) thisGroupNode.get("info");
|
||||||
thisGrp.setVariables(infoNode);
|
if (infoNode != null) {
|
||||||
}
|
thisGrp.setVariables(infoNode);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
throw new IllegalArgumentException("Unknown entry found in Info section for group: " + thisGrp.getName());
|
||||||
|
|
||||||
|
|
||||||
//END INFO NODE
|
//END INFO NODE
|
||||||
|
|
||||||
Object inheritNode = thisGroupNode.get("inheritance");
|
if (thisGroupNode.get("inheritance") == null || thisGroupNode.get("inheritance") instanceof List) {
|
||||||
if (inheritNode == null) {
|
Object inheritNode = thisGroupNode.get("inheritance");
|
||||||
thisGroupNode.put("inheritance", new ArrayList<String>());
|
if (inheritNode == null) {
|
||||||
} else if (inheritNode instanceof List) {
|
thisGroupNode.put("inheritance", new ArrayList<String>());
|
||||||
List<String> groupsInh = (List<String>) inheritNode;
|
} else if (inheritNode instanceof List) {
|
||||||
for (String grp : groupsInh) {
|
List<String> groupsInh = (List<String>) inheritNode;
|
||||||
if (inheritance.get(groupKey) == null) {
|
for (String grp : groupsInh) {
|
||||||
List<String> thisInherits = new ArrayList<String>();
|
if (inheritance.get(groupKey) == null) {
|
||||||
inheritance.put(groupKey, thisInherits);
|
List<String> thisInherits = new ArrayList<String>();
|
||||||
}
|
inheritance.put(groupKey, thisInherits);
|
||||||
inheritance.get(groupKey).add(grp);
|
}
|
||||||
|
inheritance.get(groupKey).add(grp);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}else
|
||||||
|
throw new IllegalArgumentException("Unknown entry found in inheritance section for group: " + thisGrp.getName());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
//} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
// ex.printStackTrace();
|
||||||
throw new IllegalArgumentException("Your Permissions config file is invalid. See console for details.");
|
// throw new IllegalArgumentException("Your Permissions config file is invalid. See console for details.");
|
||||||
}
|
//}
|
||||||
if (ph.defaultGroup == null) {
|
if (ph.defaultGroup == null) {
|
||||||
throw new IllegalArgumentException("There was no Default Group declared.");
|
throw new IllegalArgumentException("There was no Default Group declared.");
|
||||||
}
|
}
|
||||||
|
@ -556,13 +658,32 @@ public class WorldDataHolder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ph.removeGroupsChangedFlag();
|
||||||
|
// Update the LastModified time.
|
||||||
|
ph.groupsFile = groupsFile;
|
||||||
|
ph.setTimeStamps();
|
||||||
|
|
||||||
|
//return ph;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the WorldDataHolder from the Users file
|
||||||
|
*
|
||||||
|
* @param ph
|
||||||
|
* @param usersFile
|
||||||
|
*
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
protected static void loadUsers(WorldDataHolder ph, File usersFile) throws FileNotFoundException, IOException {
|
||||||
|
|
||||||
//READ USERS FILE
|
//READ USERS FILE
|
||||||
Yaml yamlUsers = new Yaml(new SafeConstructor());
|
Yaml yamlUsers = new Yaml(new SafeConstructor());
|
||||||
Map<String, Object> usersRootDataNode;
|
Map<String, Object> usersRootDataNode;
|
||||||
if (!groupsFile.exists()) {
|
if (!usersFile.exists()) {
|
||||||
throw new IllegalArgumentException("The file which should contain permissions does not exist!\n" + usersFile.getPath());
|
throw new IllegalArgumentException("The file which should contain users does not exist!\n" + usersFile.getPath());
|
||||||
}
|
}
|
||||||
FileInputStream usersInputStream = new FileInputStream(usersFile);
|
FileInputStream usersInputStream = new FileInputStream(usersFile);
|
||||||
try {
|
try {
|
||||||
|
@ -581,7 +702,7 @@ public class WorldDataHolder {
|
||||||
|
|
||||||
// Stop loading if the file is empty
|
// Stop loading if the file is empty
|
||||||
if (allUsersNode == null)
|
if (allUsersNode == null)
|
||||||
return ph;
|
return ;
|
||||||
|
|
||||||
for (String usersKey : allUsersNode.keySet()) {
|
for (String usersKey : allUsersNode.keySet()) {
|
||||||
Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
|
Map<String, Object> thisUserNode = (Map<String, Object>) allUsersNode.get(usersKey);
|
||||||
|
@ -644,7 +765,13 @@ public class WorldDataHolder {
|
||||||
thisUser.setGroup(ph.defaultGroup);
|
thisUser.setGroup(ph.defaultGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ph;
|
|
||||||
|
ph.removeUsersChangedFlag();
|
||||||
|
// Update the LastModified time.
|
||||||
|
ph.usersFile = usersFile;
|
||||||
|
ph.setTimeStamps();
|
||||||
|
|
||||||
|
//return ph;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -777,6 +904,11 @@ public class WorldDataHolder {
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the LastModified time.
|
||||||
|
ph.groupsFile = groupsFile;
|
||||||
|
ph.setTimeStampGroups(groupsFile.lastModified());
|
||||||
|
ph.removeGroupsChangedFlag();
|
||||||
|
|
||||||
/*FileWriter tx = null;
|
/*FileWriter tx = null;
|
||||||
try {
|
try {
|
||||||
|
@ -842,6 +974,12 @@ public class WorldDataHolder {
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the LastModified time.
|
||||||
|
ph.usersFile = usersFile;
|
||||||
|
ph.setTimeStampUsers(usersFile.lastModified());
|
||||||
|
ph.removeUsersChangedFlag();
|
||||||
|
|
||||||
/*FileWriter tx = null;
|
/*FileWriter tx = null;
|
||||||
try {
|
try {
|
||||||
tx = new FileWriter(usersFile, false);
|
tx = new FileWriter(usersFile, false);
|
||||||
|
@ -894,7 +1032,7 @@ public class WorldDataHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return true if any user data has changed
|
||||||
*/
|
*/
|
||||||
public boolean haveUsersChanged() {
|
public boolean haveUsersChanged() {
|
||||||
if (haveUsersChanged) {
|
if (haveUsersChanged) {
|
||||||
|
@ -910,7 +1048,7 @@ public class WorldDataHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return true if any group data has changed.
|
||||||
*/
|
*/
|
||||||
public boolean haveGroupsChanged() {
|
public boolean haveGroupsChanged() {
|
||||||
if (haveGroupsChanged) {
|
if (haveGroupsChanged) {
|
||||||
|
@ -964,4 +1102,64 @@ public class WorldDataHolder {
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets Groups.
|
||||||
|
*/
|
||||||
|
public void resetGroups() {
|
||||||
|
this.defaultGroup = null;
|
||||||
|
this.groups = new HashMap<String, Group>();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Resets Users
|
||||||
|
*/
|
||||||
|
public void resetUsers() {
|
||||||
|
this.users = new HashMap<String, User>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the groups
|
||||||
|
*/
|
||||||
|
public Map<String, Group> getGroups() {
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the users
|
||||||
|
*/
|
||||||
|
public Map<String, User> getUsers() {
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the timeStampGroups
|
||||||
|
*/
|
||||||
|
public long getTimeStampGroups() {
|
||||||
|
return timeStampGroups;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the timeStampUsers
|
||||||
|
*/
|
||||||
|
public long getTimeStampUsers() {
|
||||||
|
return timeStampUsers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param timeStampGroups the timeStampGroups to set
|
||||||
|
*/
|
||||||
|
protected void setTimeStampGroups(long timeStampGroups) {
|
||||||
|
this.timeStampGroups = timeStampGroups;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param timeStampUsers the timeStampUsers to set
|
||||||
|
*/
|
||||||
|
protected void setTimeStampUsers(long timeStampUsers) {
|
||||||
|
this.timeStampUsers = timeStampUsers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeStamps() {
|
||||||
|
if (groupsFile != null)
|
||||||
|
setTimeStampGroups(groupsFile.lastModified());
|
||||||
|
if (usersFile != null)
|
||||||
|
setTimeStampUsers(usersFile.lastModified());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class WorldsHolder {
|
||||||
* or mirrored worlds that don't need data.
|
* or mirrored worlds that don't need data.
|
||||||
*/
|
*/
|
||||||
if (!worldsData.containsKey(folder.getName().toLowerCase())
|
if (!worldsData.containsKey(folder.getName().toLowerCase())
|
||||||
|| !mirrors.containsKey(folder.getName().toLowerCase())) {
|
&& !mirrors.containsKey(folder.getName().toLowerCase())) {
|
||||||
loadWorld(folder.getName());
|
loadWorld(folder.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +149,8 @@ public class WorldsHolder {
|
||||||
w.reload();
|
w.reload();
|
||||||
alreadyDone.add(w);
|
alreadyDone.add(w);
|
||||||
}
|
}
|
||||||
|
// Load global groups
|
||||||
|
GroupManager.getGlobalGroups().load();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,44 +160,98 @@ public class WorldsHolder {
|
||||||
public void reloadWorld(String worldName) {
|
public void reloadWorld(String worldName) {
|
||||||
getWorldData(worldName).reload();
|
getWorldData(worldName).reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper to retain backwards compatibility
|
||||||
|
* (call this function to auto overwrite files)
|
||||||
|
*/
|
||||||
|
public void saveChanges() {
|
||||||
|
saveChanges(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void saveChanges() {
|
public void saveChanges(boolean overwrite) {
|
||||||
ArrayList<WorldDataHolder> alreadyDone = new ArrayList<WorldDataHolder>();
|
ArrayList<WorldDataHolder> alreadyDone = new ArrayList<WorldDataHolder>();
|
||||||
|
Tasks.removeOldFiles(plugin, plugin.getBackupFolder());
|
||||||
|
|
||||||
for (OverloadedWorldHolder w : worldsData.values()) {
|
for (OverloadedWorldHolder w : worldsData.values()) {
|
||||||
if (alreadyDone.contains(w)) {
|
if (alreadyDone.contains(w)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Tasks.removeOldFiles(plugin, plugin.getBackupFolder());
|
|
||||||
if (w == null) {
|
if (w == null) {
|
||||||
GroupManager.logger.severe("WHAT HAPPENED?");
|
GroupManager.logger.severe("WHAT HAPPENED?");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (w.haveGroupsChanged()) {
|
if (w.haveGroupsChanged()) {
|
||||||
//String groupsFolderName = w.getGroupsFile().getParentFile().getName();
|
if (overwrite || (!overwrite && (w.getTimeStampGroups() >= w.getGroupsFile().lastModified()))) {
|
||||||
File backupGroups = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + "_g_" + Tasks.getDateString() + ".yml");
|
// Backup Groups file
|
||||||
try {
|
backupFile(w,true);
|
||||||
Tasks.copy(w.getGroupsFile(), backupGroups);
|
|
||||||
} catch (IOException ex) {
|
WorldDataHolder.writeGroups(w, w.getGroupsFile());
|
||||||
GroupManager.logger.log(Level.SEVERE, null, ex);
|
//w.removeGroupsChangedFlag();
|
||||||
}
|
} else {
|
||||||
WorldDataHolder.writeGroups(w, w.getGroupsFile());
|
// Newer file found.
|
||||||
w.removeGroupsChangedFlag();
|
GroupManager.logger.log(Level.WARNING, "Newer Groups file found for " + w.getName() + ", but we have local changes!");
|
||||||
|
throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Check for newer file as no local changes.
|
||||||
|
if (w.getTimeStampGroups() < w.getGroupsFile().lastModified()) {
|
||||||
|
System.out.print("Newer Groups file found (Loading changes)!");
|
||||||
|
// Backup Users file
|
||||||
|
backupFile(w,false);
|
||||||
|
w.reloadGroups();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (w.haveUsersChanged()) {
|
if (w.haveUsersChanged()) {
|
||||||
File backupUsers = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + "_u_" + Tasks.getDateString() + ".yml");
|
if (overwrite || (!overwrite && (w.getTimeStampUsers() >= w.getUsersFile().lastModified()))) {
|
||||||
try {
|
// Backup Users file
|
||||||
Tasks.copy(w.getUsersFile(), backupUsers);
|
backupFile(w,false);
|
||||||
} catch (IOException ex) {
|
|
||||||
GroupManager.logger.log(Level.SEVERE, null, ex);
|
WorldDataHolder.writeUsers(w, w.getUsersFile());
|
||||||
}
|
//w.removeUsersChangedFlag();
|
||||||
WorldDataHolder.writeUsers(w, w.getUsersFile());
|
} else {
|
||||||
w.removeUsersChangedFlag();
|
// Newer file found.
|
||||||
|
GroupManager.logger.log(Level.WARNING, "Newer Users file found for " + w.getName() + ", but we have local changes!");
|
||||||
|
throw new IllegalStateException("Unable to save unless you issue a '/mansave force'");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//Check for newer file as no local changes.
|
||||||
|
if (w.getTimeStampUsers() < w.getUsersFile().lastModified()) {
|
||||||
|
System.out.print("Newer Users file found (Loading changes)!");
|
||||||
|
// Backup Users file
|
||||||
|
backupFile(w,false);
|
||||||
|
w.reloadUsers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
alreadyDone.add(w);
|
alreadyDone.add(w);
|
||||||
}
|
}
|
||||||
|
// Write Global Groups
|
||||||
|
if (GroupManager.getGlobalGroups().haveGroupsChanged()) {
|
||||||
|
GroupManager.getGlobalGroups().writeGroups(overwrite);
|
||||||
|
} else {
|
||||||
|
if (GroupManager.getGlobalGroups().getTimeStampGroups() < GroupManager.getGlobalGroups().getGlobalGroupsFile().lastModified()) {
|
||||||
|
System.out.print("Newer GlobalGroups file found (Loading changes)!");
|
||||||
|
GroupManager.getGlobalGroups().load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backup the Groups/Users file
|
||||||
|
* @param w
|
||||||
|
* @param groups
|
||||||
|
*/
|
||||||
|
private void backupFile(OverloadedWorldHolder w, Boolean groups) {
|
||||||
|
|
||||||
|
File backupFile = new File(plugin.getBackupFolder(), "bkp_" + w.getName() + (groups ? "_g_" : "_u_") + Tasks.getDateString() + ".yml");
|
||||||
|
try {
|
||||||
|
Tasks.copy((groups ? w.getGroupsFile() : w.getUsersFile()), backupFile);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
GroupManager.logger.log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,7 +265,7 @@ public class WorldsHolder {
|
||||||
* Mirrors prevails original data.
|
* Mirrors prevails original data.
|
||||||
*
|
*
|
||||||
* @param worldName
|
* @param worldName
|
||||||
* @return
|
* @return OverloadedWorldHolder
|
||||||
*/
|
*/
|
||||||
public OverloadedWorldHolder getWorldData(String worldName) {
|
public OverloadedWorldHolder getWorldData(String worldName) {
|
||||||
OverloadedWorldHolder data = worldsData.get(worldName.toLowerCase());
|
OverloadedWorldHolder data = worldsData.get(worldName.toLowerCase());
|
||||||
|
@ -239,31 +295,31 @@ public class WorldsHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the field p.getWorld().getName() and do
|
* Retrieves the field player.getWorld().getName() and do
|
||||||
* getWorld(worldName)
|
* getWorld(worldName)
|
||||||
* @param p
|
* @param player
|
||||||
* @return
|
* @return OverloadedWorldHolder
|
||||||
*/
|
*/
|
||||||
public OverloadedWorldHolder getWorldData(Player p) {
|
public OverloadedWorldHolder getWorldData(Player player) {
|
||||||
return getWorldData(p.getWorld().getName());
|
return getWorldData(player.getWorld().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It does getWorld(worldName).getPermissionsHandler()
|
* It does getWorld(worldName).getPermissionsHandler()
|
||||||
* @param worldName
|
* @param worldName
|
||||||
* @return
|
* @return AnjoPermissionsHandler
|
||||||
*/
|
*/
|
||||||
public AnjoPermissionsHandler getWorldPermissions(String worldName) {
|
public AnjoPermissionsHandler getWorldPermissions(String worldName) {
|
||||||
return getWorldData(worldName).getPermissionsHandler();
|
return getWorldData(worldName).getPermissionsHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*It does getWorldData(p).getPermission
|
* Returns the PermissionsHandler for this player data
|
||||||
* @param p
|
* @param player
|
||||||
* @return
|
* @return AnjoPermissionsHandler
|
||||||
*/
|
*/
|
||||||
public AnjoPermissionsHandler getWorldPermissions(Player p) {
|
public AnjoPermissionsHandler getWorldPermissions(Player player) {
|
||||||
return getWorldData(p).getPermissionsHandler();
|
return getWorldData(player).getPermissionsHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -352,7 +408,7 @@ public class WorldsHolder {
|
||||||
* Copies the specified world data to another world
|
* Copies the specified world data to another world
|
||||||
* @param fromWorld
|
* @param fromWorld
|
||||||
* @param toWorld
|
* @param toWorld
|
||||||
* @return
|
* @return true if successfully copied.
|
||||||
*/
|
*/
|
||||||
public boolean cloneWorld(String fromWorld, String toWorld) {
|
public boolean cloneWorld(String fromWorld, String toWorld) {
|
||||||
File fromWorldFolder = new File(worldsFolder, fromWorld);
|
File fromWorldFolder = new File(worldsFolder, fromWorld);
|
||||||
|
@ -401,6 +457,10 @@ public class WorldsHolder {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
OverloadedWorldHolder thisWorldData = new OverloadedWorldHolder(WorldDataHolder.load(worldName, groupsFile, usersFile));
|
OverloadedWorldHolder thisWorldData = new OverloadedWorldHolder(WorldDataHolder.load(worldName, groupsFile, usersFile));
|
||||||
|
|
||||||
|
// Set the file TimeStamps as it will be default from the initial load.
|
||||||
|
thisWorldData.setTimeStamps();
|
||||||
|
|
||||||
if (thisWorldData != null) {
|
if (thisWorldData != null) {
|
||||||
GroupManager.logger.finest("Successful load of world " + worldName + "...");
|
GroupManager.logger.finest("Successful load of world " + worldName + "...");
|
||||||
worldsData.put(worldName.toLowerCase(), thisWorldData);
|
worldsData.put(worldName.toLowerCase(), thisWorldData);
|
||||||
|
@ -454,7 +514,7 @@ public class WorldsHolder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all physically loaded worlds.
|
* Returns all physically loaded worlds.
|
||||||
* @return
|
* @return ArrayList<OverloadedWorldHolder> of all loaded worlds
|
||||||
*/
|
*/
|
||||||
public ArrayList<OverloadedWorldHolder> allWorldsDataList() {
|
public ArrayList<OverloadedWorldHolder> allWorldsDataList() {
|
||||||
ArrayList<OverloadedWorldHolder> list = new ArrayList<OverloadedWorldHolder>();
|
ArrayList<OverloadedWorldHolder> list = new ArrayList<OverloadedWorldHolder>();
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -187,7 +187,7 @@ public class BukkitPermissions {
|
||||||
* null is empty
|
* null is empty
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @return
|
* @return Map of child permissions
|
||||||
*/
|
*/
|
||||||
public Map<String, Boolean> getChildren(String node) {
|
public Map<String, Boolean> getChildren(String node) {
|
||||||
for (Permission permission : registeredPermissions) {
|
for (Permission permission : registeredPermissions) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.bukkit.entity.Player;
|
||||||
*
|
*
|
||||||
* @author Nijikokun
|
* @author Nijikokun
|
||||||
* @author Gabriel Couto
|
* @author Gabriel Couto
|
||||||
|
* @author ElgarL
|
||||||
*/
|
*/
|
||||||
public abstract class PermissionsReaderInterface {
|
public abstract class PermissionsReaderInterface {
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ public abstract class PermissionsReaderInterface {
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param string
|
* @param string
|
||||||
* @return
|
* @return true if has permission
|
||||||
*/
|
*/
|
||||||
public abstract boolean has(Player player, String string);
|
public abstract boolean has(Player player, String string);
|
||||||
|
|
||||||
|
@ -31,141 +32,141 @@ public abstract class PermissionsReaderInterface {
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param string
|
* @param string
|
||||||
* @return
|
* @return true if has permission
|
||||||
*/
|
*/
|
||||||
public abstract boolean permission(Player player, String string);
|
public abstract boolean permission(Player player, String string);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @return
|
* @return group name for this player.
|
||||||
*/
|
*/
|
||||||
public abstract String getGroup(String string);
|
public abstract String getGroup(String userName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param groupName
|
||||||
* @return
|
* @return true if in group
|
||||||
*/
|
*/
|
||||||
public abstract boolean inGroup(String string, String string1);
|
public abstract boolean inGroup(String userName, String groupName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param groupName
|
||||||
* @return
|
* @return String of prefix
|
||||||
*/
|
*/
|
||||||
public abstract String getGroupPrefix(String string);
|
public abstract String getGroupPrefix(String groupName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param groupName
|
||||||
* @return
|
* @return String of suffix
|
||||||
*/
|
*/
|
||||||
public abstract String getGroupSuffix(String string);
|
public abstract String getGroupSuffix(String groupName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param groupName
|
||||||
* @return
|
* @return true if can build
|
||||||
*/
|
*/
|
||||||
public abstract boolean canGroupBuild(String string);
|
public abstract boolean canGroupBuild(String groupName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param groupName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return String value
|
||||||
*/
|
*/
|
||||||
public abstract String getGroupPermissionString(String string, String string1);
|
public abstract String getGroupPermissionString(String groupName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param groupName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return integer value
|
||||||
*/
|
*/
|
||||||
public abstract int getGroupPermissionInteger(String string, String string1);
|
public abstract int getGroupPermissionInteger(String groupName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param groupName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return boolean value
|
||||||
*/
|
*/
|
||||||
public abstract boolean getGroupPermissionBoolean(String string, String string1);
|
public abstract boolean getGroupPermissionBoolean(String groupName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param groupName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return double value
|
||||||
*/
|
*/
|
||||||
public abstract double getGroupPermissionDouble(String string, String string1);
|
public abstract double getGroupPermissionDouble(String groupName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return String value
|
||||||
*/
|
*/
|
||||||
public abstract String getUserPermissionString(String string, String string1);
|
public abstract String getUserPermissionString(String userName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return integer value
|
||||||
*/
|
*/
|
||||||
public abstract int getUserPermissionInteger(String string, String string1);
|
public abstract int getUserPermissionInteger(String userName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return boolean value
|
||||||
*/
|
*/
|
||||||
public abstract boolean getUserPermissionBoolean(String string, String string1);
|
public abstract boolean getUserPermissionBoolean(String userName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return double value
|
||||||
*/
|
*/
|
||||||
public abstract double getUserPermissionDouble(String string, String string1);
|
public abstract double getUserPermissionDouble(String userName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return String value
|
||||||
*/
|
*/
|
||||||
public abstract String getPermissionString(String string, String string1);
|
public abstract String getPermissionString(String userName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return integer value
|
||||||
*/
|
*/
|
||||||
public abstract int getPermissionInteger(String string, String string1);
|
public abstract int getPermissionInteger(String userName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return boolean value
|
||||||
*/
|
*/
|
||||||
public abstract boolean getPermissionBoolean(String string, String string1);
|
public abstract boolean getPermissionBoolean(String userName, String node);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string
|
* @param userName
|
||||||
* @param string1
|
* @param node
|
||||||
* @return
|
* @return double value
|
||||||
*/
|
*/
|
||||||
public abstract double getPermissionDouble(String string, String string1);
|
public abstract double getPermissionDouble(String userName, String node);
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
/**
|
/**
|
||||||
|
@ -173,7 +174,7 @@ public abstract class PermissionsReaderInterface {
|
||||||
* This method is a utility method for chat plugins to get the user's prefix
|
* 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.
|
* without having to look at every one of the user's ancestors.
|
||||||
* Returns an empty string if user has no parent groups.
|
* Returns an empty string if user has no parent groups.
|
||||||
* @param world Player's world
|
*
|
||||||
* @param user Player's name
|
* @param user Player's name
|
||||||
* @return Player's prefix
|
* @return Player's prefix
|
||||||
*/
|
*/
|
||||||
|
@ -184,7 +185,7 @@ public abstract class PermissionsReaderInterface {
|
||||||
* This method is a utility method for chat plugins to get the user's suffix
|
* 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.
|
* without having to look at every one of the user's ancestors.
|
||||||
* Returns an empty string if user has no parent groups.
|
* Returns an empty string if user has no parent groups.
|
||||||
* @param world Player's world
|
*
|
||||||
* @param user Player's name
|
* @param user Player's name
|
||||||
* @return Player's suffix
|
* @return Player's suffix
|
||||||
*/
|
*/
|
||||||
|
@ -215,7 +216,7 @@ public abstract class PermissionsReaderInterface {
|
||||||
* @param entryName
|
* @param entryName
|
||||||
* @param path
|
* @param path
|
||||||
* @param isGroup
|
* @param isGroup
|
||||||
* @return
|
* @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);
|
||||||
//public abstract double getInfoDouble(String entryName, String path, boolean isGroup, Comparator<Double> comparator);
|
//public abstract double getInfoDouble(String entryName, String path, boolean isGroup, Comparator<Double> comparator);
|
||||||
|
|
Loading…
Reference in a new issue