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

The following examples show how to use org.bukkit.configuration.ConfigurationSection#getKeys() . 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: SpigotConfig.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
private static void stats()
{
    disableStatSaving = getBoolean( "stats.disable-saving", false );

    if ( !config.contains( "stats.forced-stats" ) ) {
        config.createSection( "stats.forced-stats" );
    }

    ConfigurationSection section = config.getConfigurationSection( "stats.forced-stats" );
    for ( String name : section.getKeys( true ) )
    {
        if ( section.isInt( name ) )
        {
            forcedStats.put( name, section.getInt( name ) );
        }
    }

    if ( disableStatSaving && section.getInt( "achievement.openInventory", 0 ) < 1 )
    {
        Bukkit.getLogger().warning( "*** WARNING *** stats.disable-saving is true but stats.forced-stats.achievement.openInventory" +
                " isn't set to 1. Disabling stat saving without forcing the achievement may cause it to get stuck on the player's " +
                "screen." );
    }
}
 
Example 2
Source File: IslandInfo.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
public Set<UUID> getMemberUUIDs() {
    ConfigurationSection memberSection = config.getConfigurationSection("party.members");
    Set<UUID> members = new HashSet<>();
    if (memberSection != null) {
        for (String uuid : memberSection.getKeys(false)) {
            try {
                UUID id = UUIDUtil.fromString(uuid);
                if (id == null) {
                    throw new IllegalArgumentException();
                }
                members.add(id);
            } catch (IllegalArgumentException e) {
                log.info("Island " + name + " has invalid member-section " + uuid);
            }
        }
    }
    return members;
}
 
Example 3
Source File: HologramFormat.java    From ShopChest with MIT License 6 votes vote down vote up
/**
 * @return Whether the hologram text has to change dynamically without reloading
 */
public boolean isDynamic() {
    int count = getLineCount();
    for (int i = 0; i < count; i++) {
        ConfigurationSection options = config.getConfigurationSection("lines." + i + ".options");

        for (String key : options.getKeys(false)) {
            ConfigurationSection option = options.getConfigurationSection(key);

            String format = option.getString("format");
            if (format.contains(Placeholder.STOCK.toString()) || format.contains(Placeholder.CHEST_SPACE.toString())) {
                return true;
            }

            for (String req : option.getStringList("requirements")) {
                if (req.contains(Requirement.IN_STOCK.toString()) || req.contains(Requirement.CHEST_SPACE.toString())) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 4
Source File: BlockLimitLogic.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public BlockLimitLogic(uSkyBlock plugin) {
    this.plugin = plugin;
    FileConfiguration config = plugin.getConfig();
    limitsEnabled = config.getBoolean("options.island.block-limits.enabled", false);
    if (limitsEnabled) {
        ConfigurationSection section = config.getConfigurationSection("options.island.block-limits");
        Set<String> keys = section.getKeys(false);
        keys.remove("enabled");
        for (String key : keys) {
            Material material = Material.getMaterial(key.toUpperCase());
            int limit = section.getInt(key, -1);
            if (material != null && limit >= 0) {
                blockLimits.put(material, limit);
            } else {
                log.warning("Unknown material " + key + " supplied for block-limit, or value not an integer");
            }
        }
    }
}
 
Example 5
Source File: FileRotationProviderFactory.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public Set<RotationProviderInfo> parse(MapLibrary mapLibrary, Path dataPath, Configuration config) {
    ConfigurationSection base = config.getConfigurationSection("rotation.providers.file");
    if(base == null) return Collections.emptySet();

    Set<RotationProviderInfo> providers = new HashSet<>();
    for(String name : base.getKeys(false)) {
        ConfigurationSection provider = base.getConfigurationSection(name);

        Path rotationFile = Paths.get(provider.getString("path"));
        if(!rotationFile.isAbsolute()) rotationFile = dataPath.resolve(rotationFile);

        int priority = provider.getInt("priority", 0);

        if(Files.isRegularFile(rotationFile)) {
            providers.add(new RotationProviderInfo(new FileRotationProvider(mapLibrary, name, rotationFile, dataPath), name, priority));
        } else if(minecraftService.getLocalServer().startup_visibility() == ServerDoc.Visibility.PUBLIC) {
            // This is not a perfect way to decide whether or not to throw an error, but it's the best we can do right now
            mapLibrary.getLogger().severe("Missing rotation file: " + rotationFile);
        }
    }

    return providers;
}
 
Example 6
Source File: IslandInfo.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean hasOnlineMembers() {
    ConfigurationSection members = config.getConfigurationSection("party.members");
    if (members != null) {
        for (String uuid : members.getKeys(false)) {
            if (uuid != null) {
                UUID id = UUIDUtil.fromString(uuid);
                if (id != null) {
                    Player onlinePlayer = plugin.getPlayerDB().getPlayer(id);
                    if (onlinePlayer != null) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 7
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, String[]> getCommandAliases() {
    ConfigurationSection section = commandsConfiguration.getConfigurationSection("aliases");
    Map<String, String[]> result = new LinkedHashMap<String, String[]>();

    if (section != null) {
        for (String key : section.getKeys(false)) {
            List<String> commands;

            if (section.isList(key)) {
                commands = section.getStringList(key);
            } else {
                commands = ImmutableList.of(section.getString(key));
            }

            result.put(key, commands.toArray(new String[commands.size()]));
        }
    }

    return result;
}
 
Example 8
Source File: Config.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the ID of a conversation assigned to specified NPC, across all
 * packages. If there are multiple assignments for the same value, the first
 * one will be returned.
 *
 * @param value the name of the NPC (as defined in <i>main.yml</i>)
 * @return the ID of the conversation assigned to this NPC or null if there
 * isn't one
 */
public static String getNpc(String value) {
    // load npc assignments from all packages
    for (String packName : packages.keySet()) {
        ConfigPackage pack = packages.get(packName);
        ConfigurationSection assignments = pack.getMain().getConfig().getConfigurationSection("npcs");
        if (assignments != null) {
            for (String assignment : assignments.getKeys(false)) {
                if (assignment.equalsIgnoreCase(value)) {
                    return packName + "." + assignments.getString(assignment);
                }
            }
        }
    }
    return null;
}
 
Example 9
Source File: IslandInfo.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@Override
@NotNull
public Set<String> getMembers() {
    ConfigurationSection memberSection = config.getConfigurationSection("party.members");
    Set<String> members = new LinkedHashSet<>();
    if (memberSection != null) {
        for (String uuid : memberSection.getKeys(false)) {
            UUID id = UUIDUtil.fromString(uuid);
            if (id != null) {
                String nm = plugin.getPlayerDB().getName(id);
                if (nm != null) {
                    members.add(nm);
                } else {
                    log.info("Island " + name + " has unknown member-section " + uuid);
                    // Remove broken UUID from island file
                    config.set("party.members." + uuid, null);
                    config.set("party.currentSize", getPartySize() - 1);
                    save();
                }
            } else {
                log.info("Island " + name + " has invalid member-section " + uuid);
            }
        }
    }
    return members;
}
 
Example 10
Source File: ItemStackParser.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private LinkedHashMap<String, Object> getLinkedMap() {
  LinkedHashMap<String, Object> linkedMap = new LinkedHashMap<String, Object>();

  if (!(this.configSection instanceof LinkedHashMap)) {
    ConfigurationSection newSection = (ConfigurationSection) this.configSection;
    for (String key : newSection.getKeys(false)) {
      linkedMap.put(key, newSection.get(key));
    }
  } else {
    linkedMap = (LinkedHashMap<String, Object>) this.configSection;
  }

  return linkedMap;
}
 
Example 11
Source File: HelpYamlReader.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts a list of topic amendments from help.yml
 *
 * @return A list of amendments.
 */
public List<HelpTopicAmendment> getTopicAmendments() {
    List<HelpTopicAmendment> amendments = new LinkedList<HelpTopicAmendment>();
    ConfigurationSection commandTopics = helpYaml.getConfigurationSection("amended-topics");
    if (commandTopics != null) {
        for (String topicName : commandTopics.getKeys(false)) {
            ConfigurationSection section = commandTopics.getConfigurationSection(topicName);
            String description = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String usage = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText", ""));
            String permission = section.getString("permission", "");
            amendments.add(new HelpTopicAmendment(topicName, description, usage, permission));
        }
    }
    return amendments;
}
 
Example 12
Source File: DatabaseConnection.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public DatabaseConnection(ConfigurationSection connectionSection, File basedir) {
	this.identifier = connectionSection.getName();
	this.properties = new HashMap<String, Object>();
	
	/* Save all properties from the section */
	for (String key : connectionSection.getKeys(false)) {
		Object value = connectionSection.get(key);
		if (value instanceof String) {
			//Replace {basedir} variable
			value = ((String)value).replace("{basedir}", basedir.getPath());
		}
		
		properties.put(key, value);
	}
}
 
Example 13
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 14
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 15
Source File: NavigatorInterface.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
void load(ConfigurationSection config) throws InvalidConfigurationException {
    final boolean enabled;
    final BaseComponent title;
    final ItemStack openButtonIcon;
    final Map<Slot.Container, Button> buttons = new HashMap<>();

    try {
        enabled = config.getBoolean("enabled", false);
        title = new TranslatableComponent(config.getString("title", "navigator.title"));
        final ItemConfigurationParser itemParser = new ItemConfigurationParser(config);
        openButtonIcon = itemParser.getItem(config, "icon", () -> new ItemStack(Material.SIGN));

        if(enabled) {
            final ConfigurationSection buttonSection = config.getSection("buttons");
            for(String key : buttonSection.getKeys()) {
                final Button button = new Button(buttonSection.getSection(key), itemParser);
                buttons.put(button.slot, button);
            }
        }
    } catch(InvalidConfigurationException e) {
        buttons.values().forEach(Button::release);
        throw e;
    }

    clear();

    NavigatorInterface.this.enabled = enabled;
    NavigatorInterface.this.title = title;
    NavigatorInterface.this.openButtonIcon = openButtonIcon;
    NavigatorInterface.this.buttons = ImmutableMap.copyOf(buttons);
    NavigatorInterface.this.height = buttons.values()
                                            .stream()
                                            .mapToInt(button -> button.slot.getRow() + 1)
                                            .max()
                                            .orElse(0);
}
 
Example 16
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 17
Source File: SavePortals.java    From WildernessTp with MIT License 5 votes vote down vote up
private void fillMap() {
    ConfigurationSection sec = portals.getConfigurationSection("Portals");
    if(sec == null){
        plugin.getLogger().info("Portals file is empty probably not a problem");
        return;
    }
    for (String name : sec.getKeys(false)) {
        if (name == null) {
            plugin.getLogger().info("Portals file is empty probably not a problem if it is report this");
            return;
        }
        String loc = portals.getString("Portals." + name);
        plugin.portals.put(name, loc);
    }
}
 
Example 18
Source File: RepairConfig.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    Set<String> tmp = new HashSet<>(config.getKeys(false));
    for (String key : tmp) { // clear section
        config.set(key, null);
    }

    for (Map.Entry<Material, RepairConfigItem> pair : repairMap.entrySet()) {
        ConfigurationSection section = config.createSection(pair.getKey().name());
        pair.getValue().normalize().serialize(section);
    }
}
 
Example 19
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private void addExtraMenus(Player player, Inventory menu) {
    ConfigurationSection extras = plugin.getConfig().getConfigurationSection("options.extra-menus");
    if (extras == null) {
        return;
    }
    for (String sIndex : extras.getKeys(false)) {
        ConfigurationSection menuSection = extras.getConfigurationSection(sIndex);
        if (menuSection == null) {
            continue;
        }
        try {
            int index = Integer.parseInt(sIndex, 10);
            String title = menuSection.getString("title", "\u00a9Unknown");
            String icon = menuSection.getString("displayItem", "CHEST");
            List<String> lores = new ArrayList<>();
            for (String l : menuSection.getStringList("lore")) {
                Matcher matcher = PERM_VALUE_PATTERN.matcher(l);
                if (matcher.matches()) {
                    String perm = matcher.group("perm");
                    String lore = matcher.group("value");
                    boolean not = matcher.group("not") != null;
                    if (perm != null) {
                        boolean hasPerm = player.hasPermission(perm);
                        if ((hasPerm && !not) || (!hasPerm && not)) {
                            lores.add(lore);
                        }
                    } else {
                        lores.add(lore);
                    }
                }
            }
            // Only SIMPLE icons supported...
            ItemStack item = new ItemStack(Material.matchMaterial(icon), 1);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(title);
            meta.setLore(lores);
            item.setItemMeta(meta);
            menu.setItem(index, item);
        } catch (Exception e) {
            log(Level.INFO, "\u00a79[uSkyBlock]\u00a7r Unable to add extra-menu " + sIndex + ": " + e);
        }
    }
}
 
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;
}