Java Code Examples for org.bukkit.configuration.file.FileConfiguration#isSet()

The following examples show how to use org.bukkit.configuration.file.FileConfiguration#isSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameManager.java    From Survival-Games with GNU General Public License v3.0 6 votes vote down vote up
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();
	
}
 
Example 2
Source File: Configuration.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
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);
	}
}
 
Example 3
Source File: Configurator.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 4
Source File: Configurator.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: ConfigHelper.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: ConfigHandler.java    From CratesPlus with GNU General Public License v3.0 5 votes vote down vote up
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;
        }
    }
}
 
Example 13
Source File: NoGUIOpener.java    From CratesPlus with GNU General Public License v3.0 5 votes vote down vote up
@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();
        }
    }
}
 
Example 14
Source File: RegionManager.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@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;
}