mirror of
https://e.coding.net/circlecloud/Residence.git
synced 2025-11-24 21:46:16 +00:00
fix PermissionManager error...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
@@ -60,8 +60,8 @@ public class ConfigManager {
|
||||
|
||||
public ConfigManager(final Residence plugin) {
|
||||
this.plugin = plugin;
|
||||
globalCreatorDefaults = new FlagPermissions(plugin);
|
||||
globalResidenceDefaults = new FlagPermissions(plugin);
|
||||
globalCreatorDefaults = new FlagPermissions();
|
||||
globalResidenceDefaults = new FlagPermissions();
|
||||
globalGroupDefaults = new HashMap<String, FlagPermissions>();
|
||||
this.load(plugin.getConfig());
|
||||
}
|
||||
@@ -247,18 +247,15 @@ public class ConfigManager {
|
||||
customRightClick = config.getIntegerList("Global.CustomRightClick");
|
||||
final ConfigurationSection node = config.getConfigurationSection("Global.GroupDefault");
|
||||
|
||||
if (!plugin.is1_8()) {
|
||||
if (!plugin.is1_8())
|
||||
actionBar = false;
|
||||
}
|
||||
|
||||
if (node != null) {
|
||||
final Set<String> keys = node.getConfigurationSection(defaultGroup).getKeys(false);
|
||||
if (keys != null) {
|
||||
for (final String key : keys) {
|
||||
if (keys != null)
|
||||
for (final String key : keys)
|
||||
globalGroupDefaults.put(key, FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.GroupDefault")));
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
chatColor = ChatColor.valueOf(config.getString("Global.ResidenceChatColor", "DARK_PURPLE"));
|
||||
} catch (final Exception ex) {
|
||||
|
||||
@@ -83,7 +83,9 @@ public class Residence extends JavaPlugin {
|
||||
public static float bukkitver;
|
||||
|
||||
public final static int saveVersion = 1;
|
||||
public final static String[] validLanguages = { "English", "Chinese" };
|
||||
public final static String[] validLanguages = { "English",
|
||||
"Chinese" };
|
||||
protected static Residence instance;
|
||||
protected ResidenceBlockListener blistener;
|
||||
protected ChatManager chatmanager;
|
||||
protected ConfigManager cmanager;
|
||||
@@ -113,6 +115,10 @@ public class Residence extends JavaPlugin {
|
||||
protected boolean useWorldEdit;
|
||||
protected WorldFlagManager wmanager;
|
||||
|
||||
public static Residence getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ResidenceBlockListener getBlockListener() {
|
||||
return blistener;
|
||||
}
|
||||
@@ -428,7 +434,7 @@ public class Residence extends JavaPlugin {
|
||||
if (!this.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
FlagPermissions.initValidFlags();
|
||||
FlagPermissions.initValidFlags(this);
|
||||
final Plugin wep = this.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (wep != null) {
|
||||
smanager = new WorldEditSelectionManager(this);
|
||||
@@ -492,9 +498,10 @@ public class Residence extends JavaPlugin {
|
||||
init = true;
|
||||
} catch (final Exception ex) {
|
||||
init = false;
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
setEnabled(false);
|
||||
this.getLogger().warning(" - 初始化失败! 卸载插件! 请报告以下错误给作者,谢谢!");
|
||||
this.getLogger().warning("错误: " + ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
new VersionChecker(this);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ public class CommandSelect extends BaseCommand {
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException {
|
||||
|
||||
final Player player = (Player) sender;
|
||||
final boolean resadmin = (command != null);
|
||||
final ResidenceManager rmanager = plugin.getResidenceManager();
|
||||
|
||||
@@ -58,24 +58,22 @@ public class PermissionGroup {
|
||||
protected int xmax;
|
||||
protected int ymax;
|
||||
protected int zmax;
|
||||
Residence plugin;
|
||||
|
||||
public PermissionGroup(final Residence plugin, final String name) {
|
||||
this.plugin = plugin;
|
||||
flagPerms = new FlagPermissions(plugin);
|
||||
public PermissionGroup(final String name) {
|
||||
flagPerms = new FlagPermissions();
|
||||
creatorDefaultFlags = new HashMap<String, Boolean>();
|
||||
residenceDefaultFlags = new HashMap<String, Boolean>();
|
||||
groupDefaultFlags = new HashMap<String, Map<String, Boolean>>();
|
||||
groupname = name;
|
||||
}
|
||||
|
||||
public PermissionGroup(final Residence plugin, final String name, final ConfigurationSection node) {
|
||||
this(plugin, name);
|
||||
public PermissionGroup(final String name, final ConfigurationSection node) {
|
||||
this(name);
|
||||
this.parseGroup(node);
|
||||
}
|
||||
|
||||
public PermissionGroup(final Residence plugin, final String name, final ConfigurationSection node, final FlagPermissions parentFlagPerms) {
|
||||
this(plugin, name, node);
|
||||
public PermissionGroup(final String name, final ConfigurationSection node, final FlagPermissions parentFlagPerms) {
|
||||
this(name, node);
|
||||
flagPerms.setParent(parentFlagPerms);
|
||||
}
|
||||
|
||||
@@ -203,6 +201,7 @@ public class PermissionGroup {
|
||||
}
|
||||
|
||||
public void printLimits(final Player player) {
|
||||
final Residence plugin = Residence.getInstance();
|
||||
player.sendMessage(ChatColor.GRAY + "---------------------------");
|
||||
player.sendMessage(ChatColor.YELLOW + "权限 组:" + ChatColor.DARK_AQUA + " " + plugin.getPermissionManager().getPermissionsGroup(player));
|
||||
player.sendMessage(ChatColor.YELLOW + "领地 组:" + ChatColor.DARK_AQUA + " " + groupname);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PermissionManager {
|
||||
this.plugin = plugin;
|
||||
groups = Collections.synchronizedMap(new HashMap<String, PermissionGroup>());
|
||||
playersGroup = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
globalFlagPerms = new FlagPermissions(plugin);
|
||||
globalFlagPerms = new FlagPermissions();
|
||||
this.readConfig(plugin.getConfig());
|
||||
final boolean enable = plugin.getConfig().getBoolean("Global.EnablePermissions", true);
|
||||
if (enable) {
|
||||
@@ -135,10 +135,10 @@ public class PermissionManager {
|
||||
final Set<String> entrys = nodes.getKeys(false);
|
||||
for (final String key : entrys) {
|
||||
try {
|
||||
groups.put(key.toLowerCase(), new PermissionGroup(plugin, key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
||||
groups.put(key.toLowerCase(), new PermissionGroup(key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
||||
final List<String> mirrors = nodes.getConfigurationSection(key).getStringList("Mirror");
|
||||
for (final String group : mirrors) {
|
||||
groups.put(group.toLowerCase(), new PermissionGroup(plugin, key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
||||
groups.put(group.toLowerCase(), new PermissionGroup(key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
plugin.getLogger().info("错误 从配置文件读取:" + key + " 抛出异常:" + ex);
|
||||
@@ -146,7 +146,7 @@ public class PermissionManager {
|
||||
}
|
||||
}
|
||||
if (!groups.containsKey(defaultGroup)) {
|
||||
groups.put(defaultGroup, new PermissionGroup(plugin, defaultGroup));
|
||||
groups.put(defaultGroup, new PermissionGroup(defaultGroup));
|
||||
}
|
||||
final Set<String> keys = config.getConfigurationSection("GroupAssignments").getKeys(false);
|
||||
if (keys != null) {
|
||||
|
||||
@@ -27,6 +27,13 @@ import com.bekvon.bukkit.residence.Residence;
|
||||
*/
|
||||
public class FlagPermissions {
|
||||
|
||||
public static enum FlagState {
|
||||
FALSE,
|
||||
INVALID,
|
||||
NEITHER,
|
||||
TRUE
|
||||
}
|
||||
|
||||
protected static ArrayList<String> validAreaFlags = new ArrayList<String>();
|
||||
protected static HashMap<String, ArrayList<String>> validFlagGroups = new HashMap<String, ArrayList<String>>();
|
||||
protected static ArrayList<String> validFlags = new ArrayList<String>();
|
||||
@@ -36,10 +43,10 @@ public class FlagPermissions {
|
||||
protected Map<String, Boolean> cuboidFlags;
|
||||
protected Map<String, Map<String, Boolean>> groupFlags;
|
||||
protected FlagPermissions parent;
|
||||
|
||||
protected Map<String, Map<String, Boolean>> playerFlags;
|
||||
|
||||
public FlagPermissions(final Residence plugin) {
|
||||
FlagPermissions.plugin = plugin;
|
||||
public FlagPermissions() {
|
||||
cuboidFlags = Collections.synchronizedMap(new HashMap<String, Boolean>());
|
||||
playerFlags = Collections.synchronizedMap(new HashMap<String, Map<String, Boolean>>());
|
||||
groupFlags = Collections.synchronizedMap(new HashMap<String, Map<String, Boolean>>());
|
||||
@@ -97,7 +104,8 @@ public class FlagPermissions {
|
||||
return (EnumMap<Material, String>) matUseFlagList;
|
||||
}
|
||||
|
||||
public static void initValidFlags() {
|
||||
public static void initValidFlags(final Residence plugin) {
|
||||
FlagPermissions.plugin = plugin;
|
||||
validAreaFlags.clear();
|
||||
validPlayerFlags.clear();
|
||||
validFlags.clear();
|
||||
@@ -225,12 +233,12 @@ public class FlagPermissions {
|
||||
}
|
||||
|
||||
public static FlagPermissions load(final Map<String, Object> root) throws Exception {
|
||||
final FlagPermissions newperms = new FlagPermissions(plugin);
|
||||
final FlagPermissions newperms = new FlagPermissions();
|
||||
return FlagPermissions.load(root, newperms);
|
||||
}
|
||||
|
||||
public static FlagPermissions parseFromConfigNode(final String name, final ConfigurationSection node) {
|
||||
final FlagPermissions list = new FlagPermissions(plugin);
|
||||
final FlagPermissions list = new FlagPermissions();
|
||||
final Set<String> keys = node.getConfigurationSection(name).getKeys(false);
|
||||
if (keys != null) {
|
||||
for (String key : keys) {
|
||||
@@ -624,12 +632,4 @@ public class FlagPermissions {
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
public static enum FlagState {
|
||||
|
||||
FALSE,
|
||||
INVALID,
|
||||
NEITHER,
|
||||
TRUE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class PermissionListManager {
|
||||
}
|
||||
FlagPermissions perms = get.get(listname);
|
||||
if (perms == null) {
|
||||
perms = new FlagPermissions(plugin);
|
||||
perms = new FlagPermissions();
|
||||
get.put(listname, perms);
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("ListCreate", listname));
|
||||
} else {
|
||||
|
||||
@@ -37,7 +37,6 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
Residence plugin;
|
||||
|
||||
public ResidencePermissions(final Residence plugin, final ClaimedResidence res) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
this.pm = plugin.getServer().getPluginManager();
|
||||
residence = res;
|
||||
@@ -52,30 +51,24 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
public static ResidencePermissions load(final Residence plugin, final ClaimedResidence res, final Map<String, Object> root) throws Exception {
|
||||
final ResidencePermissions newperms = new ResidencePermissions(plugin, res);
|
||||
newperms.owner = (String) root.get("Owner");
|
||||
if (newperms.owner == null) {
|
||||
if (newperms.owner == null)
|
||||
newperms.owner = (String) root.get("OwnerLastKnownName");
|
||||
}
|
||||
if (newperms.owner == null) {
|
||||
plugin.getLogger().warning("发现未知所有者的领地,转换为Server Land...");
|
||||
newperms.owner = "Server Land";
|
||||
}
|
||||
newperms.world = (String) root.get("World");
|
||||
FlagPermissions.load(root, newperms);
|
||||
if (newperms.owner == null) {
|
||||
if (newperms.owner == null)
|
||||
throw new Exception("错误的Owner数据...");
|
||||
}
|
||||
if (newperms.world == null) {
|
||||
if (newperms.world == null)
|
||||
throw new Exception("错误的World数据...");
|
||||
}
|
||||
if (newperms.playerFlags == null) {
|
||||
if (newperms.playerFlags == null)
|
||||
throw new Exception("错误的PlayerFlags数据...");
|
||||
}
|
||||
if (newperms.groupFlags == null) {
|
||||
if (newperms.groupFlags == null)
|
||||
throw new Exception("错误的GroupFlags数据...");
|
||||
}
|
||||
if (newperms.cuboidFlags == null) {
|
||||
if (newperms.cuboidFlags == null)
|
||||
throw new Exception("错误的CuboidFlags数据...");
|
||||
}
|
||||
newperms.fixNames();
|
||||
return newperms;
|
||||
}
|
||||
@@ -87,74 +80,58 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
final Set<Entry<String, Boolean>> dcflags = group.getDefaultCreatorFlags();
|
||||
final Set<Entry<String, Map<String, Boolean>>> dgflags = group.getDefaultGroupFlags();
|
||||
this.applyGlobalDefaults();
|
||||
for (final Entry<String, Boolean> next : dflags) {
|
||||
if (this.checkValidFlag(next.getKey(), true)) {
|
||||
if (next.getValue()) {
|
||||
for (final Entry<String, Boolean> next : dflags)
|
||||
if (this.checkValidFlag(next.getKey(), true))
|
||||
if (next.getValue())
|
||||
this.setFlag(next.getKey(), FlagState.TRUE);
|
||||
} else {
|
||||
else
|
||||
this.setFlag(next.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Boolean> next : dcflags) {
|
||||
if (this.checkValidFlag(next.getKey(), false)) {
|
||||
if (next.getValue()) {
|
||||
for (final Entry<String, Boolean> next : dcflags)
|
||||
if (this.checkValidFlag(next.getKey(), false))
|
||||
if (next.getValue())
|
||||
this.setPlayerFlag(owner, next.getKey(), FlagState.TRUE);
|
||||
} else {
|
||||
else
|
||||
this.setPlayerFlag(owner, next.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Map<String, Boolean>> entry : dgflags) {
|
||||
final Map<String, Boolean> value = entry.getValue();
|
||||
for (final Entry<String, Boolean> flag : value.entrySet()) {
|
||||
if (flag.getValue()) {
|
||||
for (final Entry<String, Boolean> flag : value.entrySet())
|
||||
if (flag.getValue())
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.TRUE);
|
||||
} else {
|
||||
else
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void applyDefaultFlags(final Player player, final boolean resadmin) {
|
||||
if (this.hasResidencePermission(player, true) || resadmin) {
|
||||
this.applyDefaultFlags();
|
||||
player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("FlagsDefault"));
|
||||
} else {
|
||||
} else
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
}
|
||||
}
|
||||
|
||||
public void applyGlobalDefaults() {
|
||||
this.clearFlags();
|
||||
final FlagPermissions gRD = plugin.getConfigManager().getGlobalResidenceDefaultFlags();
|
||||
final FlagPermissions gCD = plugin.getConfigManager().getGlobalCreatorDefaultFlags();
|
||||
final Map<String, FlagPermissions> gGD = plugin.getConfigManager().getGlobalGroupDefaultFlags();
|
||||
for (final Entry<String, Boolean> entry : gRD.cuboidFlags.entrySet()) {
|
||||
if (entry.getValue()) {
|
||||
for (final Entry<String, Boolean> entry : gRD.cuboidFlags.entrySet())
|
||||
if (entry.getValue())
|
||||
this.setFlag(entry.getKey(), FlagState.TRUE);
|
||||
} else {
|
||||
else
|
||||
this.setFlag(entry.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Boolean> entry : gCD.cuboidFlags.entrySet()) {
|
||||
if (entry.getValue()) {
|
||||
for (final Entry<String, Boolean> entry : gCD.cuboidFlags.entrySet())
|
||||
if (entry.getValue())
|
||||
this.setPlayerFlag(owner, entry.getKey(), FlagState.TRUE);
|
||||
} else {
|
||||
else
|
||||
this.setPlayerFlag(owner, entry.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
for (final Entry<String, FlagPermissions> entry : gGD.entrySet()) {
|
||||
for (final Entry<String, Boolean> flag : entry.getValue().cuboidFlags.entrySet()) {
|
||||
if (flag.getValue()) {
|
||||
for (final Entry<String, FlagPermissions> entry : gGD.entrySet())
|
||||
for (final Entry<String, Boolean> flag : entry.getValue().cuboidFlags.entrySet())
|
||||
if (flag.getValue())
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.TRUE);
|
||||
} else {
|
||||
else
|
||||
this.setGroupFlag(entry.getKey(), flag.getKey(), FlagState.FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void applyTemplate(final Player player, final FlagPermissions list, boolean resadmin) {
|
||||
if (player != null) {
|
||||
@@ -162,55 +139,42 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
resadmin = true;
|
||||
}
|
||||
final PermissionGroup group = plugin.getPermissionManager().getGroup(owner, world);
|
||||
for (final Entry<String, Boolean> flag : list.cuboidFlags.entrySet()) {
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin) {
|
||||
for (final Entry<String, Boolean> flag : list.cuboidFlags.entrySet())
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin)
|
||||
this.cuboidFlags.put(flag.getKey(), flag.getValue());
|
||||
} else if (player != null) {
|
||||
else if (player != null)
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Map<String, Boolean>> plists : list.playerFlags.entrySet()) {
|
||||
for (final Entry<String, Boolean> flag : plists.getValue().entrySet()) {
|
||||
for (final Entry<String, Map<String, Boolean>> plists : list.playerFlags.entrySet())
|
||||
for (final Entry<String, Boolean> flag : plists.getValue().entrySet())
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin) {
|
||||
if (!this.playerFlags.containsKey(plists.getKey())) {
|
||||
if (!this.playerFlags.containsKey(plists.getKey()))
|
||||
this.playerFlags.put(plists.getKey(), Collections.synchronizedMap(new HashMap<String, Boolean>()));
|
||||
}
|
||||
this.playerFlags.get(plists.getKey()).put(flag.getKey(), flag.getValue());
|
||||
} else if (player != null) {
|
||||
} else if (player != null)
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, Map<String, Boolean>> glists : list.groupFlags.entrySet()) {
|
||||
for (final Entry<String, Boolean> flag : glists.getValue().entrySet()) {
|
||||
for (final Entry<String, Map<String, Boolean>> glists : list.groupFlags.entrySet())
|
||||
for (final Entry<String, Boolean> flag : glists.getValue().entrySet())
|
||||
if (group.hasFlagAccess(flag.getKey()) || resadmin) {
|
||||
if (!this.groupFlags.containsKey(glists.getKey())) {
|
||||
if (!this.groupFlags.containsKey(glists.getKey()))
|
||||
this.groupFlags.put(glists.getKey(), Collections.synchronizedMap(new HashMap<String, Boolean>()));
|
||||
}
|
||||
this.groupFlags.get(glists.getKey()).put(flag.getKey(), flag.getValue());
|
||||
} else if (player != null) {
|
||||
} else if (player != null)
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("FlagSetDeny", ChatColor.YELLOW + flag.getKey() + ChatColor.RED));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player != null) {
|
||||
if (player != null)
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("PermissionsApply"));
|
||||
}
|
||||
}
|
||||
|
||||
public void fixNames() {
|
||||
final ArrayList<String> fixNames = new ArrayList<String>();
|
||||
final Iterator<Entry<String, Map<String, Boolean>>> it = playerFlags.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
final String name = it.next().getKey();
|
||||
if (!name.equals(name.toLowerCase())) {
|
||||
if (!name.equals(name.toLowerCase()))
|
||||
fixNames.add(name);
|
||||
}
|
||||
}
|
||||
for (final String name : fixNames) {
|
||||
final Map<String, Boolean> get = playerFlags.get(name);
|
||||
playerFlags.remove(name);
|
||||
@@ -230,9 +194,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
public boolean groupHas(final String group, final String flag, final boolean def) {
|
||||
final ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.GROUP, group, def);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isOverriden()) {
|
||||
if (fc.isOverriden())
|
||||
return fc.getOverrideValue();
|
||||
}
|
||||
return super.groupHas(group, flag, def);
|
||||
}
|
||||
|
||||
@@ -240,9 +203,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
public boolean has(final String flag, final boolean def) {
|
||||
final ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.RESIDENCE, null, def);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isOverriden()) {
|
||||
if (fc.isOverriden())
|
||||
return fc.getOverrideValue();
|
||||
}
|
||||
return super.has(flag, def);
|
||||
}
|
||||
|
||||
@@ -254,20 +216,17 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
if (plugin.getConfigManager().enabledRentSystem()) {
|
||||
final String resname = residence.getName();
|
||||
if (plugin.getRentManager().isRented(resname)) {
|
||||
if (requireOwner) {
|
||||
if (requireOwner)
|
||||
return false;
|
||||
}
|
||||
final String renter = plugin.getRentManager().getRentingPlayer(resname);
|
||||
if (player.getName().equalsIgnoreCase(renter)) {
|
||||
if (player.getName().equalsIgnoreCase(renter))
|
||||
return true;
|
||||
} else {
|
||||
else
|
||||
return (playerHas(player.getName(), "admin", false));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requireOwner) {
|
||||
if (requireOwner)
|
||||
return (owner.equalsIgnoreCase(player.getName()));
|
||||
}
|
||||
return (playerHas(player.getName(), "admin", false) || owner.equalsIgnoreCase(player.getName()));
|
||||
}
|
||||
|
||||
@@ -279,9 +238,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
public boolean playerHas(final String player, final String world, final String flag, final boolean def) {
|
||||
final ResidenceFlagCheckEvent fc = new ResidenceFlagCheckEvent(residence, flag, FlagType.PLAYER, player, def);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isOverriden()) {
|
||||
if (fc.isOverriden())
|
||||
return fc.getOverrideValue();
|
||||
}
|
||||
return super.playerHas(player, world, flag, def);
|
||||
}
|
||||
|
||||
@@ -289,9 +247,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
if (this.hasResidencePermission(player, false) || resadmin) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, "ALL", ResidenceFlagChangeEvent.FlagType.GROUP, FlagState.NEITHER, null);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
super.removeAllGroupFlags(group);
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
@@ -303,9 +260,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
if (this.hasResidencePermission(player, false) || resadmin) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, "ALL", ResidenceFlagChangeEvent.FlagType.RESIDENCE, FlagState.NEITHER, null);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
super.removeAllPlayerFlags(targetPlayer);
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
@@ -322,16 +278,14 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
}
|
||||
|
||||
public boolean setFlag(final Player player, final String flag, final String flagstate, final boolean resadmin) {
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
return this.setFlagGroup(player, flag, flagstate, resadmin);
|
||||
}
|
||||
final FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
if (checkCanSetFlag(player, flag, state, true, resadmin)) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.RESIDENCE, state, null);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
if (super.setFlag(flag, state)) {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
@@ -344,9 +298,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
public boolean setFlag(final String flag, final FlagState state) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.RESIDENCE, state, null);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
return super.setFlag(flag, state);
|
||||
}
|
||||
|
||||
@@ -354,11 +307,9 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
if (ResidencePermissions.validFlagGroups.containsKey(flaggroup)) {
|
||||
final ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
boolean changed = false;
|
||||
for (final String flag : flags) {
|
||||
if (this.setFlag(player, flag, state, resadmin)) {
|
||||
for (final String flag : flags)
|
||||
if (this.setFlag(player, flag, state, resadmin))
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
@@ -368,11 +319,9 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
if (ResidencePermissions.validFlagGroups.containsKey(flaggroup)) {
|
||||
final ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
boolean changed = false;
|
||||
for (final String flag : flags) {
|
||||
if (this.setGroupFlag(player, group, flag, state, resadmin)) {
|
||||
for (final String flag : flags)
|
||||
if (this.setGroupFlag(player, group, flag, state, resadmin))
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
@@ -382,11 +331,9 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
if (ResidencePermissions.validFlagGroups.containsKey(flaggroup)) {
|
||||
final ArrayList<String> flags = ResidencePermissions.validFlagGroups.get(flaggroup);
|
||||
boolean changed = false;
|
||||
for (final String flag : flags) {
|
||||
if (this.setPlayerFlag(player, target, flag, state, resadmin)) {
|
||||
for (final String flag : flags)
|
||||
if (this.setPlayerFlag(player, target, flag, state, resadmin))
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
return false;
|
||||
@@ -394,17 +341,15 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
|
||||
public boolean setGroupFlag(final Player player, String group, final String flag, final String flagstate, final boolean resadmin) {
|
||||
group = group.toLowerCase();
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
return this.setFlagGroupOnGroup(player, flag, group, flagstate, resadmin);
|
||||
}
|
||||
final FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
if (checkCanSetFlag(player, flag, state, false, resadmin)) {
|
||||
if (checkCanSetFlag(player, flag, state, false, resadmin))
|
||||
if (plugin.getPermissionManager().hasGroup(group)) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.GROUP, state, group);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
if (super.setGroupFlag(group, flag, state)) {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
@@ -413,7 +358,6 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("InvalidGroup"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -421,9 +365,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
public boolean setGroupFlag(final String group, final String flag, final FlagState state) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.GROUP, state, group);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
return super.setGroupFlag(group, flag, state);
|
||||
}
|
||||
|
||||
@@ -431,22 +374,19 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
final ResidenceOwnerChangeEvent ownerchange = new ResidenceOwnerChangeEvent(residence, newOwner);
|
||||
pm.callEvent(ownerchange);
|
||||
owner = newOwner;
|
||||
if (resetFlags) {
|
||||
if (resetFlags)
|
||||
this.applyDefaultFlags();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setPlayerFlag(final Player player, final String targetPlayer, final String flag, final String flagstate, final boolean resadmin) {
|
||||
if (validFlagGroups.containsKey(flag)) {
|
||||
if (validFlagGroups.containsKey(flag))
|
||||
return this.setFlagGroupOnPlayer(player, targetPlayer, flag, flagstate, resadmin);
|
||||
}
|
||||
final FlagState state = FlagPermissions.stringToFlagState(flagstate);
|
||||
if (checkCanSetFlag(player, flag, state, false, resadmin)) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, player, flag, ResidenceFlagChangeEvent.FlagType.PLAYER, state, targetPlayer);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
if (super.setPlayerFlag(targetPlayer, flag, state)) {
|
||||
player.sendMessage(ChatColor.GREEN + plugin.getLanguage().getPhrase("FlagSet"));
|
||||
return true;
|
||||
@@ -459,9 +399,8 @@ public class ResidencePermissions extends FlagPermissions {
|
||||
public boolean setPlayerFlag(final String player, final String flag, final FlagState state) {
|
||||
final ResidenceFlagChangeEvent fc = new ResidenceFlagChangeEvent(residence, null, flag, ResidenceFlagChangeEvent.FlagType.PLAYER, state, player);
|
||||
pm.callEvent(fc);
|
||||
if (fc.isCancelled()) {
|
||||
if (fc.isCancelled())
|
||||
return false;
|
||||
}
|
||||
return super.setPlayerFlag(player, flag, state);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class WorldFlagManager {
|
||||
|
||||
public WorldFlagManager(final Residence plugin) {
|
||||
this.plugin = plugin;
|
||||
globaldefaults = new FlagPermissions(plugin);
|
||||
globaldefaults = new FlagPermissions();
|
||||
worldperms = new HashMap<String, FlagPermissions>();
|
||||
groupperms = new HashMap<String, Map<String, FlagPermissions>>();
|
||||
}
|
||||
@@ -46,13 +46,11 @@ public class WorldFlagManager {
|
||||
public FlagPermissions getPerms(String world) {
|
||||
world = world.toLowerCase();
|
||||
final FlagPermissions list = worldperms.get(world);
|
||||
if (list == null) {
|
||||
if (globaldefaults == null) {
|
||||
return new FlagPermissions(plugin);
|
||||
} else {
|
||||
if (list == null)
|
||||
if (globaldefaults == null)
|
||||
return new FlagPermissions();
|
||||
else
|
||||
return globaldefaults;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -60,19 +58,16 @@ public class WorldFlagManager {
|
||||
world = world.toLowerCase();
|
||||
group = group.toLowerCase();
|
||||
final Map<String, FlagPermissions> groupworldperms = groupperms.get(group);
|
||||
if (groupworldperms == null) {
|
||||
if (groupworldperms == null)
|
||||
return this.getPerms(world);
|
||||
}
|
||||
FlagPermissions list = groupworldperms.get(world);
|
||||
if (list == null) {
|
||||
list = groupworldperms.get("global." + world);
|
||||
if (list == null) {
|
||||
if (list == null)
|
||||
list = groupworldperms.get("global");
|
||||
}
|
||||
if (list == null) {
|
||||
if (list == null)
|
||||
return this.getPerms(world);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -80,20 +75,16 @@ public class WorldFlagManager {
|
||||
try {
|
||||
|
||||
Set<String> keys = config.getConfigurationSection("Global.Flags").getKeys(false);
|
||||
if (keys != null) {
|
||||
for (final String key : keys) {
|
||||
if (key.equalsIgnoreCase("Global")) {
|
||||
if (keys != null)
|
||||
for (final String key : keys)
|
||||
if (key.equalsIgnoreCase("Global"))
|
||||
globaldefaults = FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags"));
|
||||
} else {
|
||||
else
|
||||
worldperms.put(key.toLowerCase(), FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags")));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Entry<String, FlagPermissions> entry : worldperms.entrySet()) {
|
||||
for (final Entry<String, FlagPermissions> entry : worldperms.entrySet())
|
||||
entry.getValue().setParent(globaldefaults);
|
||||
}
|
||||
keys = config.getConfigurationSection("Groups").getKeys(false);
|
||||
if (keys != null) {
|
||||
if (keys != null)
|
||||
for (final String key : keys) {
|
||||
final ConfigurationSection worldkeylist = config.getConfigurationSection("Groups." + key + ".Flags.World");
|
||||
if (worldkeylist != null) {
|
||||
@@ -110,28 +101,24 @@ public class WorldFlagManager {
|
||||
list.setParent(worldperm.getValue());
|
||||
perms.put("global." + worldperm.getKey().toLowerCase(), list);
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
perms.put(wkey.toLowerCase(), list);
|
||||
}
|
||||
}
|
||||
for (final Entry<String, FlagPermissions> entry : perms.entrySet()) {
|
||||
final String wkey = entry.getKey();
|
||||
final FlagPermissions list = entry.getValue();
|
||||
if (!wkey.startsWith("global.")) {
|
||||
list.setParent(perms.get("global." + wkey));
|
||||
if (list.getParent() == null) {
|
||||
if (list.getParent() == null)
|
||||
list.setParent(worldperms.get(wkey));
|
||||
}
|
||||
if (list.getParent() == null) {
|
||||
if (list.getParent() == null)
|
||||
list.setParent(globaldefaults);
|
||||
}
|
||||
}
|
||||
}
|
||||
groupperms.put(key.toLowerCase(), perms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
Logger.getLogger(WorldFlagManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user