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

The following examples show how to use org.bukkit.configuration.ConfigurationSection#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: Spell.java    From Civs with GNU General Public License v3.0 7 votes vote down vote up
public boolean useAbilityFromListener(Player caster, int level, ConfigurationSection useSection, Object newTarget) {
    HashMap<String, Set<?>> mappedTargets = new HashMap<>();
    HashSet<LivingEntity> tempSet = new HashSet<>();
    tempSet.add(caster);
    mappedTargets.put("self", tempSet);
    HashSet<Object> tempTarget = new HashSet<>();
    tempTarget.add(newTarget);
    mappedTargets.put("target", tempTarget);
    SpellType spellType = (SpellType) ItemManager.getInstance().getItemType(type);

    ConfigurationSection targetSections = spellType.getConfig().getConfigurationSection("targets");
    for (String key : targetSections.getKeys(false)) {
        ConfigurationSection targetSection = targetSections.getConfigurationSection(key);
        String targetName = targetSection.getString("type", "nearby");
        Target abilityTarget = SpellType.getTarget(targetName, key, targetSection, level, caster, this);
        if (abilityTarget == null) {
            continue;
        }
        mappedTargets.put(key, abilityTarget.getTargets());
        if (targetSection.getBoolean("cancel-if-empty", false) && mappedTargets.get(key).isEmpty()) {
            return false;
        }
    }

    useAbility(mappedTargets, true, new HashMap<String, ConfigurationSection>());

    return useSection.getBoolean("cancel", false);
}
 
Example 2
Source File: HologramFormat.java    From ShopChest with MIT License 6 votes vote down vote up
/**
 * Get the format for the given line of the hologram
 * @param line Line of the hologram
 * @param reqMap Values of the requirements that might be needed by the format (contains {@code null} if not comparable)
 * @param plaMap Values of the placeholders that might be needed by the format
 * @return  The format of the first working option, or an empty String if no option is working
 *          because of not fulfilled requirements
 */
public String getFormat(int line, Map<Requirement, Object> reqMap, Map<Placeholder, Object> plaMap) {
    ConfigurationSection options = config.getConfigurationSection("lines." + line + ".options");

    optionLoop:
    for (String key : options.getKeys(false)) {
        ConfigurationSection option = options.getConfigurationSection(key);
        List<String> requirements = option.getStringList("requirements");

        String format = option.getString("format");

        for (String sReq : requirements) {
            for (Requirement req : reqMap.keySet()) {
                if (sReq.contains(req.toString())) {
                    if (!evalRequirement(sReq, reqMap)) {
                        continue optionLoop;
                    }
                }
            }
        }

        return evalPlaceholder(format, plaMap);
    }

    return "";
}
 
Example 3
Source File: AdminShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
private List<ItemStack[]> loadRecipesOld(ConfigurationSection config, String node) {
	List<ItemStack[]> recipes = new ArrayList<ItemStack[]>();
	ConfigurationSection recipesSection = config.getConfigurationSection(node);
	if (recipesSection != null) {
		for (String key : recipesSection.getKeys(false)) {
			ConfigurationSection recipeSection = recipesSection.getConfigurationSection(key);
			ItemStack[] recipe = new ItemStack[3];
			for (int slot = 0; slot < 3; slot++) {
				if (recipeSection.isConfigurationSection(String.valueOf(slot))) {
					recipe[slot] = Utils.getNullIfEmpty(this.loadItemStackOld(recipeSection.getConfigurationSection(String.valueOf(slot))));
				}
			}
			if (recipe[0] == null || recipe[2] == null) continue; // invalid recipe
			recipes.add(recipe);
		}
	}
	return recipes;
}
 
Example 4
Source File: AnniSign.java    From AnnihilationPro with MIT License 6 votes vote down vote up
public AnniSign(ConfigurationSection configSection)
{
	if(configSection == null)
		throw new NullPointerException();
	
	boolean signpost = configSection.getBoolean("isSignPost");
	//Location loc = ConfigManager.getLocation(configSection.getConfigurationSection("Location"));
	Loc loc = new Loc(configSection.getConfigurationSection("Location"));
	BlockFace facing = BlockFace.valueOf(configSection.getString("FacingDirection"));	
	obj = new FacingObject(facing, loc);
	this.signPost = signpost;
	String data = configSection.getString("Data");
	if(data.equalsIgnoreCase("Brewing"))
		type = SignType.Brewing;
	else if(data.equalsIgnoreCase("Weapon"))
		type = SignType.Weapon;
	else
		type = SignType.newTeamSign(AnniTeam.getTeamByName(data.split("-")[1]));
}
 
Example 5
Source File: ConfigUtils.java    From EffectLib with MIT License 5 votes vote down vote up
public static ConfigurationSection getConfigurationSection(ConfigurationSection base, String key)
{
    ConfigurationSection section = base.getConfigurationSection(key);
    if (section != null) {
        return section;
    }
    Object value = base.get(key);
    if (value == null) return null;

    if (value instanceof ConfigurationSection)
    {
        return (ConfigurationSection)value;
    }

    if (value instanceof Map)
    {
        ConfigurationSection newChild = base.createSection(key);
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>)value;
        for (Map.Entry<String, Object> entry : map.entrySet())
        {
            newChild.set(entry.getKey(), entry.getValue());
        }
        base.set(key, newChild);
        return newChild;
    }

    return null;
}
 
Example 6
Source File: TradingOffer.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
public static List<TradingOffer> loadFromConfig(ConfigurationSection config, String node) {
	List<TradingOffer> offers = new ArrayList<TradingOffer>();
	ConfigurationSection offersSection = config.getConfigurationSection(node);
	if (offersSection != null) {
		for (String key : offersSection.getKeys(false)) {
			ConfigurationSection offerSection = offersSection.getConfigurationSection(key);
			ItemStack resultItem = Utils.loadItem(offerSection, "resultItem");
			ItemStack item1 = Utils.loadItem(offerSection, "item1");
			ItemStack item2 = Utils.loadItem(offerSection, "item2");
			if (Utils.isEmpty(resultItem) || Utils.isEmpty(item1)) continue; // invalid offer
			offers.add(new TradingOffer(resultItem, item1, item2));
		}
	}
	return offers;
}
 
Example 7
Source File: ChallengeFactory.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static Map<String, Rank> createRankMap(ConfigurationSection ranksSection, ChallengeDefaults defaults) {
    LinkedHashMap<String, Rank> ranks = new LinkedHashMap<>();
    Rank previous = null;
    for (String rankName : ranksSection.getKeys(false)) {
        Rank rank = new Rank(ranksSection.getConfigurationSection(rankName), previous, defaults);
        ranks.put(rankName, rank);
        previous = rank;
    }
    return ranks;
}
 
Example 8
Source File: Timer.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void deserialize(ConfigurationSection config) {
    ISerializable.deserialize(config, this);
    if (config.isConfigurationSection("checkpoint")) {
        ConfigurationSection list = config.getConfigurationSection("checkpoint");
        for (String k : list.getKeys(false)) {
            Checkpoint checkpoint = new Checkpoint();
            checkpoint.deserialize(list.getConfigurationSection(String.valueOf(k)));
            checkpoint.setTimerName(getName());
            checkpoint.setCheckpointID(Integer.valueOf(k));
            checkpointList.add(checkpoint.clone());
        }
    }
}
 
Example 9
Source File: TimerConfig.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void deserialize(ConfigurationSection config) {
    timers.clear();
    ISerializable.deserialize(config, this);
    if (config.isConfigurationSection("timers")) {
        ConfigurationSection list = config.getConfigurationSection("timers");
        for (String k : list.getKeys(false)) {
            Timer timer = new Timer();
            timer.deserialize(list.getConfigurationSection(k));
            timers.put(timer.getName(), timer.clone());
        }
    }
}
 
Example 10
Source File: ParticleSet.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void deserialize(ConfigurationSection config) {
    contents.clear();
    ISerializable.deserialize(config, this);
    if (config.isConfigurationSection("contents")) {
        ConfigurationSection list = config.getConfigurationSection("contents");
        for (String index : list.getKeys(false)) {
            ParticleData p = new ParticleData();
            p.deserialize(list.getConfigurationSection(index));
            contents.add(p);
        }
    }
}
 
Example 11
Source File: AnniTeam.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public AnniTeam loadFromConfig(ConfigurationSection configSection)
{
	if(configSection != null)
	{
		//Location nexusloc = ConfigManager.getLocation(configSection.getConfigurationSection("Nexus.Location"));
		Loc nexusloc = new Loc(configSection.getConfigurationSection("Nexus.Location"));
		if(nexusloc != null)
		{
			Nexus.setLocation(nexusloc);
		}
		
		//Location spectatorspawn = ConfigManager.getLocation(configSection.getConfigurationSection("SpectatorLocation"));
		Loc spectatorspawn = new Loc(configSection.getConfigurationSection("SpectatorLocation"));
		if(spectatorspawn != null)
			setSpectatorLocation(spectatorspawn);
		
		ConfigurationSection spawns = configSection.getConfigurationSection("Spawns");
		if(spawns != null)
		{
			for(String key : spawns.getKeys(false))
			{
				//Location loc = ConfigManager.getPreciseLocation(spawns.getConfigurationSection(key));
				Loc loc = new Loc(spawns.getConfigurationSection(key));
				if(loc != null)
				{
					//int num = Integer.parseInt(key); //incase I do numbered spawns, then we can add at each number
					addSpawn(loc);
				}
			}
		}
	}
	return this;
}
 
Example 12
Source File: HelpYamlReader.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts a list of all general help topics from help.yml
 *
 * @return A list of general topics.
 */
public List<HelpTopic> getGeneralTopics() {
    List<HelpTopic> topics = new LinkedList<HelpTopic>();
    ConfigurationSection generalTopics = helpYaml.getConfigurationSection("general-topics");
    if (generalTopics != null) {
        for (String topicName : generalTopics.getKeys(false)) {
            ConfigurationSection section = generalTopics.getConfigurationSection(topicName);
            String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String fullText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText", ""));
            String permission = section.getString("permission", "");
            topics.add(new CustomHelpTopic(topicName, shortText, fullText, permission));
        }
    }
    return topics;
}
 
Example 13
Source File: BookOffer.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
public static List<BookOffer> loadFromConfig(ConfigurationSection config, String node) {
	List<BookOffer> offers = new ArrayList<BookOffer>();
	ConfigurationSection offersSection = config.getConfigurationSection(node);
	if (offersSection != null) {
		for (String bookTitle : offersSection.getKeys(false)) {
			int price = offersSection.getInt(bookTitle);
			offers.add(new BookOffer(bookTitle, price));
		}
	}
	return offers;
}
 
Example 14
Source File: WorldGuardRegionFlagsFeature.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the region flags/options to the values of a ConfigurationSection.
 * @param region The region to update the flags for
 * @return true if the flags have been set correctly, otherwise false
 */
private boolean updateRegionFlags(GeneralRegion region) {
	boolean result = true;

	// Get section defining the region flag profile
	ConfigurationSection flagProfileSection = region.getConfigurationSectionSetting("general.flagProfile", "flagProfiles");
	if(flagProfileSection == null) {
		return false;
	}

	// Region flags for all states
	ConfigurationSection allFlags = flagProfileSection.getConfigurationSection("ALL");
	if(allFlags != null) {
		result = updateRegionFlags(region, allFlags);
	}

	// Region flags for the current state
	ConfigurationSection stateFlags = flagProfileSection.getConfigurationSection(region.getState().getValue());

	// If in reselling mode, fallback to 'resale' section if 'resell' is not found (legacy configuration problem: https://github.com/NLthijs48/AreaShop/issues/303)
	if(stateFlags == null && region.getState() == GeneralRegion.RegionState.RESELL) {
		stateFlags = flagProfileSection.getConfigurationSection("resale");
	}
	if(stateFlags != null) {
		result &= updateRegionFlags(region, stateFlags);
	}

	return result;
}
 
Example 15
Source File: IslandInfo.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@Override
@NotNull
public Map<Material, Integer> getBlockLimits() {
    Map<Material, Integer> blockLimitMap = new HashMap<>();
    ConfigurationSection membersSection = config.getConfigurationSection("party.members");
    if (membersSection != null) {
        for (String memberName : membersSection.getKeys(false)) {
            ConfigurationSection memberSection = membersSection.getConfigurationSection(memberName);
            if (memberSection != null) {
                if (memberSection.isConfigurationSection("blockLimits")) {
                    ConfigurationSection blockLimits = memberSection.getConfigurationSection("blockLimits");
                    for (String material : blockLimits.getKeys(false)) {
                        Material type = Material.matchMaterial(material);
                        if (type != null) {
                            blockLimitMap.computeIfAbsent(type, (k) -> {
                                int memberMax = blockLimits.getInt(material, 0);
                                return blockLimitMap.compute(type, (key, oldValue) ->
                                        oldValue != null && memberMax > 0 ? Math.max(memberMax, oldValue) : null);
                            });
                        }
                    }
                }
            }
        }
    }
    return blockLimitMap;
}
 
Example 16
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public ChunkGenerator getGenerator(String world) {
    ConfigurationSection section = configuration.getConfigurationSection("worlds");
    ChunkGenerator result = null;

    if (section != null) {
        section = section.getConfigurationSection(world);

        if (section != null) {
            String name = section.getString("generator");

            if ((name != null) && (!name.equals(""))) {
                String[] split = name.split(":", 2);
                String id = (split.length > 1) ? split[1] : null;
                Plugin plugin = pluginManager.getPlugin(split[0]);

                if (plugin == null) {
                    getLogger().severe("Could not set generator for default world '" + world + "': Plugin '"
                            + split[0] + "' does not exist");
                } else if (!plugin.isEnabled()) {
                    getLogger().severe("Could not set generator for default world '" + world + "': Plugin '"
                            + plugin.getDescription().getFullName() + "' is not enabled yet (is it load:STARTUP?)");
                } else {
                    try {
                        result = plugin.getDefaultWorldGenerator(world, id);
                        if (result == null) {
                            getLogger().severe("Could not set generator for default world '" + world + "': Plugin '"
                                    + plugin.getDescription().getFullName() + "' lacks a default world generator");
                        }
                    } catch (Throwable t) {
                        plugin.getLogger().log(Level.SEVERE, "Could not set generator for default world '" + world
                                + "': Plugin '" + plugin.getDescription().getFullName(), t);
                    }
                }
            }
        }
    }

    return result;
}
 
Example 17
Source File: PriceOffer.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
public static List<PriceOffer> loadFromConfig(ConfigurationSection config, String node) {
	List<PriceOffer> offers = new ArrayList<PriceOffer>();
	ConfigurationSection offersSection = config.getConfigurationSection(node);
	if (offersSection != null) {
		for (String id : offersSection.getKeys(false)) {
			ConfigurationSection offerSection = offersSection.getConfigurationSection(id);
			ItemStack item = Utils.loadItem(offerSection, "item");
			int price = offerSection.getInt("price");
			if (Utils.isEmpty(item) || price < 0) continue; // invalid offer
			offers.add(new PriceOffer(item, price));
		}
	}
	return offers;
}
 
Example 18
Source File: SpellType.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
public SpellType(List<String> reqs,
                 String name,
                 Material material,
                 CVItem shopIcon,
                 int qty,
                 int min,
                 int max,
                 double price,
                 String permission,
                 List<String> groups,
                 FileConfiguration config,
                 boolean isInShop,
                 int level) {
    super(reqs,
            false,
            ItemType.SPELL,
            name,
            material,
            shopIcon,
            qty,
            min,
            max,
            price,
            permission,
            groups,
            isInShop,
            level);
    this.config = config;
    this.components = new HashMap<>();
    ConfigurationSection componentSection = config.getConfigurationSection("components");
    if (componentSection == null) {
        Civs.logger.severe("Failed to load spell type " + name + " no components");
        return;
    }
    for (String key : componentSection.getKeys(false)) {
        ConfigurationSection currentSection = componentSection.getConfigurationSection(key);
        if (currentSection != null) {
            components.put(key, currentSection);
        }
    }
}
 
Example 19
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private boolean isExtraMenuAction(Player player, ItemStack currentItem) {
    ConfigurationSection extras = plugin.getConfig().getConfigurationSection("options.extra-menus");
    if (extras == null || currentItem == null || currentItem.getItemMeta() == null) {
        return false;
    }
    Material itemType = currentItem.getType();
    String itemTitle = currentItem.getItemMeta().getDisplayName();
    for (String sIndex : extras.getKeys(false)) {
        ConfigurationSection menuSection = extras.getConfigurationSection(sIndex);
        if (menuSection == null) {
            continue;
        }
        try {
            String title = menuSection.getString("title", "\u00a9Unknown");
            String icon = menuSection.getString("displayItem", "CHEST");
            Material material = Material.matchMaterial(icon);
            if (title.equals(itemTitle) && material == itemType) {
                for (String command : menuSection.getStringList("commands")) {
                    Matcher matcher = PERM_VALUE_PATTERN.matcher(command);
                    if (matcher.matches()) {
                        String perm = matcher.group("perm");
                        String cmd = matcher.group("value");
                        boolean not = matcher.group("not") != null;
                        if (perm != null) {
                            boolean hasPerm = player.hasPermission(perm);
                            if ((hasPerm && !not) || (!hasPerm && not)) {
                                plugin.execCommand(player, cmd, false);
                            }
                        } else {
                            plugin.execCommand(player, cmd, false);
                        }
                    } else {
                        log(Level.INFO, "\u00a7a[uSkyBlock] Malformed menu " + title + ", invalid command : " + command);
                    }
                }
                return true;
            }
        } catch (Exception e) {
            log(Level.INFO, "\u00a79[uSkyBlock]\u00a7r Unable to execute commands for extra-menu " + sIndex + ": " + e);
        }
    }
    return false;
}
 
Example 20
Source File: BackpackConverter.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
private int convert(File worldFolder, int intoVaultNum) {
    PlayerVaults plugin = PlayerVaults.getInstance();
    VaultManager vaults = VaultManager.getInstance();
    int converted = 0;
    long lastUpdate = 0;
    File[] files = worldFolder.listFiles();
    for (File file : files != null ? files : new File[0]) {
        if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) {
            try {
                OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().substring(0, file.getName().lastIndexOf('.')));
                if (player == null || player.getUniqueId() == null) {
                    plugin.getLogger().warning("Unable to convert Backpack for player: " + (player != null ? player.getName() : file.getName()));
                } else {
                    UUID uuid = player.getUniqueId();
                    FileConfiguration yaml = YamlConfiguration.loadConfiguration(file);
                    ConfigurationSection section = yaml.getConfigurationSection("backpack");
                    if (section.getKeys(false).size() <= 0) {
                        continue; // No slots
                    }

                    Inventory vault = vaults.getVault(uuid.toString(), intoVaultNum);
                    if (vault == null) {
                        vault = plugin.getServer().createInventory(null, section.getKeys(false).size());
                    }
                    for (String key : section.getKeys(false)) {
                        ConfigurationSection slotSection = section.getConfigurationSection(key);
                        ItemStack item = slotSection.getItemStack("ItemStack");
                        if (item == null) {
                            continue;
                        }

                        // Overwrite
                        vault.setItem(Integer.parseInt(key.split(" ")[1]), item);
                    }
                    vaults.saveVault(vault, uuid.toString(), intoVaultNum);
                    converted++;

                    if (System.currentTimeMillis() - lastUpdate >= 1500) {
                        plugin.getLogger().info(converted + " backpacks have been converted in " + worldFolder.getAbsolutePath());
                        lastUpdate = System.currentTimeMillis();
                    }
                }
            } catch (Exception e) {
                plugin.getLogger().warning("Error converting " + file.getAbsolutePath());
                e.printStackTrace();
            }
        }
    }
    return converted;
}