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

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#getConfigurationSection() . 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: GuildHandler.java    From Guilds with MIT License 6 votes vote down vote up
/**
 * Load all the roles
 */
private void loadRoles() {
    final YamlConfiguration conf = YamlConfiguration.loadConfiguration(new File(guildsPlugin.getDataFolder(), "roles.yml"));
    final ConfigurationSection roleSec = conf.getConfigurationSection("roles");

    for (String s : roleSec.getKeys(false)) {
        final String path = s + ".permissions.";
        final String name = roleSec.getString(s + ".name");
        final String perm = roleSec.getString(s + ".permission-node");
        final int level = Integer.parseInt(s);

        final GuildRole role = new GuildRole(name, perm, level);

        for (GuildRolePerm rolePerm: GuildRolePerm.values()) {
            final String valuePath = path + rolePerm.name().replace("_", "-").toLowerCase();
            if (roleSec.getBoolean(valuePath)) {
                role.addPerm(rolePerm);
            }
        }
        this.roles.add(role);
    }
}
 
Example 2
Source File: GuildHandler.java    From Guilds with MIT License 6 votes vote down vote up
private void loadTiers() {
    final YamlConfiguration conf = YamlConfiguration.loadConfiguration(new File(guildsPlugin.getDataFolder(), "tiers.yml"));
    final ConfigurationSection tierSec = conf.getConfigurationSection("tiers.list");

    for (String key : tierSec.getKeys(false)) {
        tiers.add(GuildTier.builder()
                .level(tierSec.getInt(key + ".level"))
                .name(tierSec.getString(key + ".name"))
                .cost(tierSec.getDouble(key + ".cost", 1000))
                .maxMembers(tierSec.getInt(key + ".max-members", 10))
                .vaultAmount(tierSec.getInt(key + ".vault-amount", 1))
                .mobXpMultiplier(tierSec.getDouble(key + ".mob-xp-multiplier", 1.0))
                .damageMultiplier(tierSec.getDouble(key + ".damage-multiplier", 1.0))
                .maxBankBalance(tierSec.getDouble(key + ".max-bank-balance", 10000))
                .membersToRankup(tierSec.getInt(key + ".members-to-rankup", 5))
                .maxAllies(tierSec.getInt(key + ".max-allies", 10))
                .useBuffs(tierSec.getBoolean(key + ".use-buffs", true))
                .permissions(tierSec.getStringList(key + ".permissions"))
                .build());
    }
}
 
Example 3
Source File: UUIDVaultManager.java    From PlayerVaults with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets an inventory without storing references to it. Used for dropping a players inventories on death.
 *
 * @param holder The holder of the vault.
 * @param number The vault number.
 * @return The inventory of the specified holder and vault number.
 */
public Inventory getVault(UUID holder, int number) {
    YamlConfiguration playerFile = getPlayerVaultFile(holder);
    ConfigurationSection section = playerFile.getConfigurationSection("vault" + number);
    int maxSize = VaultOperations.getMaxVaultSize(holder.toString());

    String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number));

    if (section == null) {
        VaultHolder vaultHolder = new VaultHolder(number);
        Inventory inv = Bukkit.createInventory(vaultHolder, maxSize, title);
        vaultHolder.setInventory(inv);
        return inv;
    } else {
        List<String> data = new ArrayList<>();
        for (String s : section.getKeys(false)) {
            String value = section.getString(s);
            data.add(value);
        }

        return Serialization.toInventory(data, number, maxSize, title);
    }
}
 
Example 4
Source File: CustomItemConfig.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
public CustomItemConfig(String group) {
	_defaultConfig = new YamlConfiguration();
	_defaultItemSection = _defaultConfig.createSection("custom-items");

	_configFile = new File(CustomItemManager._plugin.getDataFolder(), "CustomItems" + File.separator + group + ".yml");

	if (!_configFile.exists()) {
		_config = new YamlConfiguration();
		_config.options().header(
				"----- CustomItems (" + group + ") ----- Item configuration file -----\n" +
				"\n" +
				"Note regarding allowed-worlds/blocked-worlds:\n" +
				"  allowed-worlds, when not empty, acts like a whitelist and only\n" +
				"  on worlds from this list the item will be enabled!\n");
	} else {
		_config = YamlConfiguration.loadConfiguration(_configFile);
	}

	_itemsSection = _config.getConfigurationSection("custom-items");
	if (_itemsSection == null) {
		_itemsSection = _config.createSection("custom-items");
	}

	_config.setDefaults(_defaultConfig);
}
 
Example 5
Source File: ChallengeFactoryTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void createChallenge_IronGolem() {
    InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("challengefactory/requiredEntities.yml");
    YamlConfiguration config = YamlConfiguration.loadConfiguration(new InputStreamReader(resourceAsStream));
    ChallengeDefaults defaults = ChallengeFactory.createDefaults(config.getRoot());
    ConfigurationSection rankSection = config.getConfigurationSection("ranks.Tier1");
    Rank rank = new Rank(rankSection, null, defaults);
    Challenge challenge = ChallengeFactory.createChallenge(rank, rankSection.getConfigurationSection("challenges.villageguard"), defaults);

    assertThat(challenge, notNullValue());
    assertThat(challenge.getRequiredEntities().size(), is(2));
    assertThat(challenge.getRequiredEntities().get(0).getType(), is(EntityType.VILLAGER));
    assertThat(challenge.getRequiredEntities().get(1).getType(), is(EntityType.IRON_GOLEM));
}
 
Example 6
Source File: ChallengeFactoryTest.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void createChallenge_ManyItems() {
    InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("challengefactory/manyRequiredItems.yml");
    YamlConfiguration config = YamlConfiguration.loadConfiguration(new InputStreamReader(resourceAsStream));
    ChallengeDefaults defaults = ChallengeFactory.createDefaults(config.getRoot());
    ConfigurationSection rankSection = config.getConfigurationSection("ranks.Tier1");
    Rank rank = new Rank(rankSection, null, defaults);
    Challenge challenge = ChallengeFactory.createChallenge(rank, rankSection.getConfigurationSection("challenges.villageguard"), defaults);

    assertThat(challenge, notNullValue());
    List<ItemStack> requiredItems = challenge.getRequiredItems(0);
    assertThat(requiredItems.size(), is(1));
    assertThat(ItemStackUtil.asString(requiredItems.get(0)), is(ItemStackUtil.asString(new ItemStack(Material.COBBLESTONE, 257))));
}
 
Example 7
Source File: UUIDVaultManager.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load the player's vault and return it.
 *
 * @param player The holder of the vault.
 * @param number The vault number.
 */
public Inventory loadOwnVault(Player player, int number, int size) {
    if (size % 9 != 0) {
        size = PlayerVaults.getInstance().getDefaultVaultSize();
    }

    String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName());
    VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
    Inventory inv;
    if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
        inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
    } else {
        YamlConfiguration playerFile = getPlayerVaultFile(player.getUniqueId());
        if (playerFile.getConfigurationSection("vault" + number) == null) {
            VaultHolder vaultHolder = new VaultHolder(number);
            if (EconomyOperations.payToCreate(player)) {
                inv = Bukkit.createInventory(vaultHolder, size, title);
                vaultHolder.setInventory(inv);
            } else {
                player.sendMessage(Lang.TITLE.toString() + Lang.INSUFFICIENT_FUNDS.toString());
                return null;
            }
        } else {
            Inventory i = getInventory(playerFile, size, number, title);
            if (i == null) {
                return null;
            } else {
                inv = i;
            }
        }
        PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
    }

    return inv;
}