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

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#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: ListenerNewbieProtection.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
private boolean isProtected(Player player) {
    if(player == null) return false;
    long firstJoinMillis = player.getFirstPlayed();
    if(firstJoinMillis == 0) return false;

    long systemMillis = System.currentTimeMillis();
    long subtract = (systemMillis - firstJoinMillis);

    FileConfiguration config = this.expansion.getConfig("newbie-helper.yml");
    long protectionTimeMillis = config.getLong("newbie-protection.protection-timer") * 1000L;
    if(subtract > protectionTimeMillis) {
        removeProtection(player);
        return false;
    }

    YamlConfiguration dataFile = this.plugin.getDataFile(player);
    if(!dataFile.isSet("newbie-helper.protected")) {
        dataFile.set("newbie-helper.protected", true);
        this.plugin.saveDataFile(player, dataFile);
    }
    return dataFile.getBoolean("newbie-helper.protected");
}
 
Example 2
Source File: CrateHandler.java    From CratesPlus with GNU General Public License v3.0 6 votes vote down vote up
public CrateHandler(CratesPlus cratesPlus) {
    this.cratesPlus = cratesPlus;

    // Load in any pending keys from the data file
    YamlConfiguration dataConfig = cratesPlus.getStorageHandler().getFlatConfig();

    if (dataConfig.isSet("Claims")) {
        for (String uuidStr : dataConfig.getConfigurationSection("Claims").getKeys(false)) {
            UUID uuid = UUID.fromString(uuidStr);
            HashMap<String, Integer> keys = new HashMap<>();
            List<String> dataList = dataConfig.getStringList("Claims." + uuidStr);
            for (String data : dataList) {
                String[] args = data.split("\\|");
                if (args.length == 1) {
                    keys.put(args[0], 1);
                } else {
                    keys.put(args[0], Integer.valueOf(args[1]));
                }
            }
            pendingKeys.put(uuid, keys);
        }
    }
}
 
Example 3
Source File: TopTen.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads the top ten from the file system topten.yml. If it does not exist
 * then the top ten is created
 */
public void topTenLoad() {
    plugin.getLogger().info("Loading Top Ten");
    topTenList.clear();
    // Check to see if the top ten list exists
    File topTenFile = new File(plugin.getDataFolder(), "topten.yml");
    if (!topTenFile.exists()) {
        plugin.getLogger().warning("Top ten file does not exist - creating it. This could take some time with a large number of players");
        topTenCreate();
    } else {
        // Load the top ten
        YamlConfiguration topTenConfig = Util.loadYamlFile("topten.yml");
        // Load the values
        if (topTenConfig.isSet("topten")) {
            for (String playerUUID : topTenConfig.getConfigurationSection("topten").getKeys(false)) {
                try {
                    UUID uuid = UUID.fromString(playerUUID);
                    int level = topTenConfig.getInt("topten." + playerUUID);
                    topTenAddEntry(uuid, level);
                } catch (Exception e) {
                    e.printStackTrace();
                    plugin.getLogger().severe("Problem loading top ten list - recreating - this may take some time");
                    topTenCreate();
                }
            }
        }
    }
}