Java Code Examples for org.bukkit.configuration.ConfigurationSection#get()
The following examples show how to use
org.bukkit.configuration.ConfigurationSection#get() .
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: ItemStackParser.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") private void parseEnchants() { if (this.isMetarizable()) { Enchantment en = null; int level = 0; ConfigurationSection newSection = (ConfigurationSection) (this.configSection); ConfigurationSection enchantSection = (ConfigurationSection) newSection.get("enchants"); for (String key : enchantSection.getKeys(false)) { if (Utils.isNumber(key)) { en = Enchantment.getById(Integer.parseInt(key)); level = Integer.parseInt(enchantSection.get(key).toString()); } else { en = Enchantment.getByName(key.toUpperCase()); level = Integer.parseInt(enchantSection.get(key).toString()); } if (en == null) { continue; } this.finalStack.addUnsafeEnchantment(en, level); } } }
Example 2
Source File: GameRule.java From DungeonsXL with GNU General Public License v3.0 | 6 votes |
/** * Returns the state of the game rule fetched from the config. * <p> * If the type of this game rule is an enum, Strings as config values that are the {@link Enum#name()} of an enum value are converted automatically. * * @param api the API instance * @param container the game rule container whose state is to be set * @param config the config to fetch the value from * @return the value */ public V fromConfig(DungeonsAPI api, GameRuleContainer container, ConfigurationSection config) { Object value = config.get(getKey()); if (reader != null) { V v = reader.read(api, value); container.setState(this, v); return v; } if (Enum.class.isAssignableFrom(type)) { if (!(value instanceof String)) { return null; } value = EnumUtil.getEnumIgnoreCase((Class<? extends Enum>) type, (String) value); } if (isValidValue(value)) { container.setState(this, (V) value); return (V) value; } else { return null; } }
Example 3
Source File: DeluxeMenusMigrater.java From TrMenu with MIT License | 5 votes |
private static String migrateMaterial(ConfigurationSection icon) { String material = icon.getString("material"); String nbtInt = icon.getString("nbt_int"); if (icon.contains("data") && icon.getInt("data", 0) > 0) { material += "<data-value:" + icon.getInt("data") + ">"; } if (nbtInt != null && nbtInt.split(":", 2).length == 2) { String[] splits = nbtInt.split(":"); if ("CustomModelData".equalsIgnoreCase(splits[0])) { material += "<model-data:" + splits[1] + ">"; } } if (icon.contains("banner_meta")) { StringBuilder pattern = new StringBuilder(); icon.getStringList("banner_meta").forEach(b -> { pattern.append(b.replace(";", " ")).append(","); }); material += "<banner:" + pattern.substring(0, pattern.length() - 1) + ">"; } if (icon.contains("rgb")) { material += "<dye:" + icon.get("rgb") + ">"; } if (material.startsWith("head;")) { material = "<head:" + material.substring(5) + ">"; } else if (material.startsWith("basehead-")) { material = "<skull:" + material.substring(9) + ">"; } else if (material.startsWith("heads-")) { material = "<hdb:" + material.substring(6) + ">"; } else if (material.startsWith("hdb-")) { material = "<hdb:" + material.substring(4) + ">"; } else if (material.startsWith("placeholder-")) { material = material.substring(12) + "<variable>"; } return material; }
Example 4
Source File: NBTBase.java From TabooLib with MIT License | 5 votes |
public static NBTCompound translateSection(NBTCompound nbt, ConfigurationSection section) { for (String key : section.getKeys(false)) { Object obj = section.get(key); NBTBase base; if (obj instanceof ConfigurationSection) { base = translateSection(new NBTCompound(), section.getConfigurationSection(key)); } else if ((base = toNBT(obj)) == null) { TabooLib.getLogger().warn("Invalid Type: " + obj + " [" + obj.getClass().getSimpleName() + "]"); continue; } nbt.put(key, base); } return nbt; }
Example 5
Source File: WorldResourcepacks.java From ResourcepacksPlugins with GNU General Public License v3.0 | 5 votes |
private Map<String, Object> getValues(ConfigurationSection config) { Map<String, Object> map = new LinkedHashMap<>(); for (String key : config.getKeys(false)) { if (config.get(key, null) != null) { if (config.isConfigurationSection(key)) { map.put(key, getValues(config.getConfigurationSection(key))); } else { map.put(key, config.get(key)); } } } return map; }
Example 6
Source File: ConfigUtils.java From EffectLib with MIT License | 5 votes |
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 7
Source File: DatabaseConnection.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
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 8
Source File: DefaultConfig.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@Override public void inflate(Configuration config, Object... args) { ConfigurationSection generalSection = config.getConfigurationSection("general"); this.generalSection = new GeneralSection(generalSection); ConfigurationSection queueSection = config.getConfigurationSection("queues"); this.queueSection = new QueueSection(queueSection); defaultGameProperties = new EnumMap<GameProperty, Object>(GameProperty.class); ConfigurationSection propsSection = config.getConfigurationSection("default-game-properties"); Set<String> keys = propsSection.getKeys(false); for (GameProperty property : GameProperty.values()) { for (String key : keys) { GameProperty mappedProperty = mapPropertyString(key); Object value; if (mappedProperty != null) { value = propsSection.get(key, mappedProperty.getDefaultValue()); } else { value = property.getDefaultValue(); } defaultGameProperties.put(mappedProperty, value); } } ConfigurationSection localizationSection = config.getConfigurationSection("localization"); this.localization = new Localization(localizationSection); ConfigurationSection flagSection = config.getConfigurationSection("flags"); this.flagSection = new FlagSection(flagSection); ConfigurationSection signSection = config.getConfigurationSection("signs"); this.signSection = new SignSection(signSection); ConfigurationSection spectateSection = config.getConfigurationSection("spectate"); this.spectateSection = new SpectateSection(spectateSection); ConfigurationSection lobbySection = config.getConfigurationSection("lobby"); this.lobbySection = new LobbySection(lobbySection); ConfigurationSection updateSection = config.getConfigurationSection("update"); this.updateSection = new UpdateSection(updateSection); this.configVersion = config.getInt("config-version", CURRENT_CONFIG_VERSION); }