mirror of
https://e.coding.net/circlecloud/Residence.git
synced 2025-11-25 21:56:06 +00:00
fix WorldFlagManager NullPointerException...
Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
@@ -1,141 +1,149 @@
|
|||||||
/*
|
/*
|
||||||
* To change this template, choose Tools | Templates
|
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.bekvon.bukkit.residence.protection;
|
package com.bekvon.bukkit.residence.protection;
|
||||||
|
|
||||||
import com.bekvon.bukkit.residence.Residence;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.bekvon.bukkit.residence.Residence;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
public class WorldFlagManager {
|
public class WorldFlagManager {
|
||||||
protected Map<String, Map<String,FlagPermissions>> groupperms;
|
protected Map<String, Map<String, FlagPermissions>> groupperms;
|
||||||
protected Map<String,FlagPermissions> worldperms;
|
protected Map<String, FlagPermissions> worldperms;
|
||||||
protected FlagPermissions globaldefaults;
|
protected FlagPermissions globaldefaults;
|
||||||
|
|
||||||
public WorldFlagManager()
|
public WorldFlagManager() {
|
||||||
{
|
globaldefaults = new FlagPermissions();
|
||||||
globaldefaults = new FlagPermissions();
|
worldperms = new HashMap<String, FlagPermissions>();
|
||||||
worldperms = new HashMap<String,FlagPermissions>();
|
groupperms = new HashMap<String, Map<String, FlagPermissions>>();
|
||||||
groupperms = new HashMap<String,Map<String,FlagPermissions>>();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public WorldFlagManager(FileConfiguration config)
|
public WorldFlagManager(FileConfiguration config) {
|
||||||
{
|
this();
|
||||||
this();
|
this.parsePerms(config);
|
||||||
this.parsePerms(config);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public FlagPermissions getPerms(Player player)
|
public FlagPermissions getPerms(Player player) {
|
||||||
{
|
return this.getPerms(player.getWorld().getName(), Residence.getPermissionManager()
|
||||||
return this.getPerms(player.getWorld().getName(), Residence.getPermissionManager().getGroupNameByPlayer(player));
|
.getGroupNameByPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlagPermissions getPerms(String world, String group)
|
public FlagPermissions getPerms(String world) {
|
||||||
{
|
world = world.toLowerCase();
|
||||||
world = world.toLowerCase();
|
FlagPermissions list = worldperms.get(world);
|
||||||
group = group.toLowerCase();
|
if (list == null) {
|
||||||
Map<String, FlagPermissions> groupworldperms = groupperms.get(group);
|
if (globaldefaults == null)
|
||||||
if (groupworldperms == null) {
|
return new FlagPermissions();
|
||||||
return this.getPerms(world);
|
else
|
||||||
}
|
return globaldefaults;
|
||||||
FlagPermissions list = groupworldperms.get(world);
|
}
|
||||||
if (list == null) {
|
return list;
|
||||||
list = groupworldperms.get("global." + world);
|
}
|
||||||
if (list == null) {
|
|
||||||
list = groupworldperms.get("global");
|
|
||||||
}
|
|
||||||
if (list == null) {
|
|
||||||
return this.getPerms(world);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FlagPermissions getPerms(String world)
|
public FlagPermissions getPerms(String world, String group) {
|
||||||
{
|
world = world.toLowerCase();
|
||||||
world = world.toLowerCase();
|
group = group.toLowerCase();
|
||||||
FlagPermissions list = worldperms.get(world);
|
Map<String, FlagPermissions> groupworldperms = groupperms.get(group);
|
||||||
if (list == null) {
|
if (groupworldperms == null)
|
||||||
if (globaldefaults == null)
|
return this.getPerms(world);
|
||||||
return new FlagPermissions();
|
FlagPermissions list = groupworldperms.get(world);
|
||||||
else
|
if (list == null) {
|
||||||
return globaldefaults;
|
list = groupworldperms.get("global." + world);
|
||||||
}
|
if (list == null) {
|
||||||
return list;
|
list = groupworldperms.get("global");
|
||||||
}
|
}
|
||||||
|
if (list == null)
|
||||||
|
return this.getPerms(world);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public void parsePerms(FileConfiguration config) {
|
public void parsePerms(FileConfiguration config) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Set<String> keys = config.getConfigurationSection("Global.Flags").getKeys(false);
|
Set<String> keys = config.getConfigurationSection("Global.Flags").getKeys(false);
|
||||||
if (keys != null) {
|
if (keys != null) {
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
if (key.equalsIgnoreCase("Global")) {
|
if (key.equalsIgnoreCase("Global")) {
|
||||||
globaldefaults = FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags"));
|
globaldefaults = FlagPermissions.parseFromConfigNode(key,
|
||||||
} else {
|
config.getConfigurationSection("Global.Flags"));
|
||||||
worldperms.put(key.toLowerCase(), FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags")));
|
} else {
|
||||||
}
|
worldperms.put(
|
||||||
}
|
key.toLowerCase(),
|
||||||
}
|
FlagPermissions.parseFromConfigNode(key,
|
||||||
for (Entry<String, FlagPermissions> entry : worldperms.entrySet()) {
|
config.getConfigurationSection("Global.Flags")));
|
||||||
entry.getValue().setParent(globaldefaults);
|
}
|
||||||
}
|
}
|
||||||
keys = config.getConfigurationSection("Groups").getKeys(false);
|
}
|
||||||
if (keys != null) {
|
for (Entry<String, FlagPermissions> entry : worldperms.entrySet()) {
|
||||||
for (String key : keys) {
|
entry.getValue().setParent(globaldefaults);
|
||||||
Set<String> worldkeys = config.getConfigurationSection("Groups." + key + ".Flags.World").getKeys(false);
|
}
|
||||||
if (worldkeys != null) {
|
keys = config.getConfigurationSection("Groups").getKeys(false);
|
||||||
Map<String, FlagPermissions> perms = new HashMap<String, FlagPermissions>();
|
if (keys != null) {
|
||||||
for (String wkey : worldkeys) {
|
for (String key : keys) {
|
||||||
FlagPermissions list = FlagPermissions.parseFromConfigNode(wkey, config.getConfigurationSection("Groups." + key + ".Flags.World"));
|
ConfigurationSection worldkeylist = config.getConfigurationSection("Groups."
|
||||||
if(wkey.equalsIgnoreCase("global"))
|
+ key + ".Flags.World");
|
||||||
{
|
if (worldkeylist != null) {
|
||||||
list.setParent(globaldefaults);
|
Set<String> worldkeys = config.getConfigurationSection(
|
||||||
perms.put(wkey.toLowerCase(), list);
|
"Groups." + key + ".Flags.World").getKeys(false);
|
||||||
for(Entry<String, FlagPermissions> worldperm : worldperms.entrySet())
|
if (worldkeys != null) {
|
||||||
{
|
Map<String, FlagPermissions> perms = new HashMap<String, FlagPermissions>();
|
||||||
list = FlagPermissions.parseFromConfigNode(wkey, config.getConfigurationSection("Groups." + key + ".Flags.World"));
|
for (String wkey : worldkeys) {
|
||||||
list.setParent(worldperm.getValue());
|
FlagPermissions list = FlagPermissions.parseFromConfigNode(
|
||||||
perms.put("global."+worldperm.getKey().toLowerCase(), list);
|
wkey,
|
||||||
}
|
config.getConfigurationSection("Groups." + key
|
||||||
}
|
+ ".Flags.World"));
|
||||||
else
|
if (wkey.equalsIgnoreCase("global")) {
|
||||||
{
|
list.setParent(globaldefaults);
|
||||||
perms.put(wkey.toLowerCase(), list);
|
perms.put(wkey.toLowerCase(), list);
|
||||||
}
|
for (Entry<String, FlagPermissions> worldperm : worldperms
|
||||||
}
|
.entrySet()) {
|
||||||
for (Entry<String, FlagPermissions> entry : perms.entrySet()) {
|
list = FlagPermissions.parseFromConfigNode(
|
||||||
String wkey = entry.getKey();
|
wkey,
|
||||||
FlagPermissions list = entry.getValue();
|
config.getConfigurationSection("Groups." + key
|
||||||
if (!wkey.startsWith("global.")) {
|
+ ".Flags.World"));
|
||||||
list.setParent(perms.get("global."+wkey));
|
list.setParent(worldperm.getValue());
|
||||||
if (list.getParent() == null) {
|
perms.put("global." + worldperm.getKey().toLowerCase(),
|
||||||
list.setParent(worldperms.get(wkey));
|
list);
|
||||||
}
|
}
|
||||||
if(list.getParent()==null)
|
} else {
|
||||||
{
|
perms.put(wkey.toLowerCase(), list);
|
||||||
list.setParent(globaldefaults);
|
}
|
||||||
}
|
}
|
||||||
}
|
for (Entry<String, FlagPermissions> entry : perms.entrySet()) {
|
||||||
}
|
String wkey = entry.getKey();
|
||||||
groupperms.put(key.toLowerCase(), perms);
|
FlagPermissions list = entry.getValue();
|
||||||
}
|
if (!wkey.startsWith("global.")) {
|
||||||
}
|
list.setParent(perms.get("global." + wkey));
|
||||||
}
|
if (list.getParent() == null) {
|
||||||
} catch (Exception ex) {
|
list.setParent(worldperms.get(wkey));
|
||||||
Logger.getLogger(WorldFlagManager.class.getName()).log(Level.SEVERE, null, ex);
|
}
|
||||||
}
|
if (list.getParent() == null) {
|
||||||
}
|
list.setParent(globaldefaults);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
groupperms.put(key.toLowerCase(), perms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Logger.getLogger(WorldFlagManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user