下面列出了org.bukkit.configuration.file.FileConfiguration#isSet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void LoadGames() {
FileConfiguration c = SettingsManager.getInstance().getSystemConfig();
games.clear();
int no = c.getInt("sg-system.arenano", 0);
int loaded = 0;
int a = 1;
while (loaded < no) {
if (c.isSet("sg-system.arenas." + a + ".x1")) {
//c.set("sg-system.arenas."+a+".enabled",c.getBoolean("sg-system.arena."+a+".enabled", true));
if (c.getBoolean("sg-system.arenas." + a + ".enabled")) {
//SurvivalGames.$(c.getString("sg-system.arenas."+a+".enabled"));
//c.set("sg-system.arenas."+a+".vip",c.getBoolean("sg-system.arenas."+a+".vip", false));
SurvivalGames.$("Loading Arena: " + a);
loaded++;
games.add(new Game(a));
StatsManager.getInstance().addArena(a);
}
}
a++;
}
LobbyManager.getInstance().clearAllSigns();
}
public void loadData() {
plugin.reloadConfig();
FileConfiguration fileConfiguration = plugin.getConfig();
try {
for(Field pathField : getClass().getDeclaredFields()) {
if(pathField.getName().endsWith("_PATH")) {
Field valueField = getClass().getDeclaredField(pathField.getName().substring(0, pathField.getName().length() - 5));
if(fileConfiguration.isSet((String)pathField.get(null))) {
if(fileConfiguration.isString((String)pathField.get(null))) {
valueField.set(this, fileConfiguration.getString((String)pathField.get(null), (String)valueField.get(this)));
} else if(fileConfiguration.isBoolean((String)pathField.get(null))) {
valueField.setBoolean(this, fileConfiguration.getBoolean((String)pathField.get(null), valueField.getBoolean(this)));
} else if(fileConfiguration.isDouble((String)pathField.get(null))) {
valueField.setDouble(this, fileConfiguration.getDouble((String)pathField.get(null), valueField.getDouble(this)));
} else if(fileConfiguration.isInt((String)pathField.get(null))) {
valueField.setInt(this, fileConfiguration.getInt((String)pathField.get(null), valueField.getInt(this)));
} else if(fileConfiguration.isList((String)pathField.get(null))) {
valueField.set(this, fileConfiguration.getList((String)pathField.get(null), (List<String>)valueField.get(this)));
}
}
}
}
} catch(Exception e) {
plugin.getLogger().log(Level.SEVERE, "An error occured while loading the config file.", e);
}
}
private static void checkOrSet(AtomicBoolean modify, FileConfiguration config, String path, Object value) {
if (!config.isSet(path)) {
if (value instanceof Map) {
config.createSection(path, (Map<?, ?>) value);
} else {
config.set(path, value);
}
modify.set(true);
}
}
private static void checkOrSet(AtomicBoolean modify, FileConfiguration config, String path, Object value) {
if (!config.isSet(path)) {
if (value instanceof Map) {
config.createSection(path, (Map<?, ?>) value);
} else {
config.set(path, value);
}
modify.set(true);
}
}
/**
* Will return object from a config with specified path. If the object does not exist in
* the config, it will add it into the config and return the default object.
*
* @param defaultValue default object
* @param config FileConfiguration instance
* @param path path to object
*/
//this method is probably the only necessary method in this util
public static Object getOrSetDefault(Object defaultValue, FileConfiguration config, String path) {
Object result;
if (config.isSet(path)) {
result = config.get(path);
} else {
result = defaultValue;
config.set(path, defaultValue);
}
return result;
}
public static List<String> getOrSetDefault(List<String> defaultValue, FileConfiguration config, String path) {
List<String> result;
if (config.isSet(path)) {
result = config.getStringList(path);
} else {
result = defaultValue;
config.set(path, defaultValue);
}
return result;
}
public static boolean getOrSetDefault(boolean defaultValue, FileConfiguration config, String path) {
boolean result;
if (config.isSet(path)) {
result = config.getBoolean(path);
} else {
result = defaultValue;
config.set(path, defaultValue);
}
return result;
}
public static int getOrSetDefault(int defaultValue, FileConfiguration config, String path) {
int result;
if (config.isSet(path)) {
result = config.getInt(path);
} else {
result = defaultValue;
config.set(path, defaultValue);
}
return result;
}
public static long getOrSetDefault(long defaultValue, FileConfiguration config, String path) {
long result;
if (config.isSet(path)) {
result = config.getInt(path);
} else {
result = defaultValue;
config.set(path, defaultValue);
}
return result;
}
public static double getOrSetDefault(double defaultValue, FileConfiguration config, String path) {
double result;
if (config.isSet(path)) {
result = config.getDouble(path);
} else {
result = defaultValue;
config.set(path, defaultValue);
}
return result;
}
public static String getOrSetDefault(String defaultValue, FileConfiguration config, String path) {
String result;
if (config.isSet(path)) {
result = config.getString(path);
} else {
result = defaultValue;
config.set(path, defaultValue);
}
return result;
}
public void registerCrate(CratesPlus cratesPlus, FileConfiguration config, String crateName) {
if (config.isSet("Crates." + crateName)) {
String type = config.getString("Crates." + crateName + ".Type", "");
switch (type.toLowerCase().replaceAll(" ", "")) {
case "keycrate":
case "key":
addCrate(crateName.toLowerCase(), new KeyCrate(this, crateName));
break;
/*case "virtual":
case "virtualcrate":
addCrate(crateName.toLowerCase(), new VirtualCrate(this, crateName));
break;*/
case "supplycrate":
case "supply":
addCrate(crateName.toLowerCase(), new SupplyCrate(this, crateName));
break;
case "dropcrate":
case "drop":
addCrate(crateName.toLowerCase(), new DropCrate(this, crateName));
break;
case "mystery":
case "mysterycrate":
case "mysterybox":
addCrate(crateName.toLowerCase(), new MysteryCrate(this, crateName));
break;
default:
cratesPlus.getLogger().warning("Invalid \"Type\" set for crate \"" + crateName + "\"");
break;
}
}
}
@Override
public void doSetup() {
FileConfiguration config = getOpenerConfig();
if (config.isSet("Chest Sound")) {
chestSound = config.getBoolean("Chest Sound", true);
} else {
config.set("Chest Sound", true);
try {
config.save(getOpenerConfigFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
private Region loadRegion(File regionFile) {
FileConfiguration regionConfig = new YamlConfiguration();
Region region;
try {
regionConfig.load(regionFile);
int[] radii = new int[6];
radii[0] = regionConfig.getInt("xp-radius");
radii[1] = regionConfig.getInt("zp-radius");
radii[2] = regionConfig.getInt("xn-radius");
radii[3] = regionConfig.getInt("zn-radius");
radii[4] = regionConfig.getInt("yp-radius");
radii[5] = regionConfig.getInt("yn-radius");
Location location = Region.idToLocation(Objects.requireNonNull(regionConfig.getString("location")));
if (location == null) {
throw new NullPointerException();
}
double exp = regionConfig.getDouble("exp");
HashMap<UUID, String> people = new HashMap<>();
for (String s : Objects.requireNonNull(regionConfig.getConfigurationSection("people")).getKeys(false)) {
people.put(UUID.fromString(s), regionConfig.getString("people." + s));
}
RegionType regionType = (RegionType) ItemManager.getInstance()
.getItemType(Objects.requireNonNull(regionConfig.getString("type")).toLowerCase());
region = new Region(
Objects.requireNonNull(regionConfig.getString("type")).toLowerCase(),
people,
location,
radii,
(HashMap<String, String>) regionType.getEffects().clone(),
exp);
region.setWarehouseEnabled(regionConfig.getBoolean("warehouse-enabled", true));
double forSale = regionConfig.getDouble("sale", -1);
if (forSale != -1) {
region.setForSale(forSale);
}
long lastActive = regionConfig.getLong(ActiveEffect.LAST_ACTIVE_KEY, -1);
if (lastActive > -1) {
region.setLastActive(lastActive);
}
if (regionConfig.isSet("upkeep-history")) {
for (String timeString : Objects.requireNonNull(regionConfig
.getConfigurationSection("upkeep-history")).getKeys(false)) {
Long time = Long.parseLong(timeString);
region.getUpkeepHistory().put(time, regionConfig.getInt("upkeep-history." + timeString));
}
}
} catch (Exception e) {
Civs.logger.log(Level.SEVERE, "Unable to read " + regionFile.getName(), e);
return null;
}
return region;
}