Java Code Examples for org.bukkit.configuration.file.FileConfiguration#get()
The following examples show how to use
org.bukkit.configuration.file.FileConfiguration#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: CommandConsistencyTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
/** * Reads plugin.yml and returns the defined commands by main label and aliases. * * @return collection of all labels and their aliases */ @SuppressWarnings("unchecked") private static Map<String, List<String>> getLabelsFromPluginFile() { FileConfiguration pluginFile = YamlConfiguration.loadConfiguration(getJarFile("/plugin.yml")); MemorySection commandList = (MemorySection) pluginFile.get("commands"); Map<String, Object> commandDefinitions = commandList.getValues(false); Map<String, List<String>> commandLabels = new HashMap<>(); for (Map.Entry<String, Object> commandDefinition : commandDefinitions.entrySet()) { MemorySection definition = (MemorySection) commandDefinition.getValue(); List<String> alternativeLabels = definition.get("aliases") == null ? Collections.EMPTY_LIST : (List<String>) definition.get("aliases"); commandLabels.put(commandDefinition.getKey(), alternativeLabels); } return commandLabels; }
Example 2
Source File: PGMConfig.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
private static void renameKey(FileConfiguration config, String from, String to) { final Object value = config.get(from); if (value == null) return; config.set(to, value); config.set(from, null); }
Example 3
Source File: ConfigHelper.java From Hawk with GNU General Public License v3.0 | 5 votes |
/** * Will return object from a config with specified path. If the object does not exist in * the config, it will add it into the config and return the default object. * * @param defaultValue default object * @param config FileConfiguration instance * @param path path to object */ //this method is probably the only necessary method in this util public static Object getOrSetDefault(Object defaultValue, FileConfiguration config, String path) { Object result; if (config.isSet(path)) { result = config.get(path); } else { result = defaultValue; config.set(path, defaultValue); } return result; }
Example 4
Source File: FallbackConfigUtil.java From Civs with GNU General Public License v3.0 | 5 votes |
public static FileConfiguration getConfigFullPath(File originalFile, String url) { FileConfiguration config = new YamlConfiguration(); try { InputStream inputStream = FallbackConfigUtil.class.getResourceAsStream(url); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); config.load(reader); if (originalFile != null && originalFile.exists()) { FileConfiguration configOverride = new YamlConfiguration(); configOverride.load(originalFile); for (String key : configOverride.getKeys(true)) { if (configOverride.get(key) instanceof ConfigurationSection) { continue; } config.set(key, configOverride.get(key)); } } } catch (Exception e) { if (originalFile != null) { Civs.logger.log(Level.SEVERE, "File name: {0}", originalFile.getName()); } if (url != null) { Civs.logger.log(Level.SEVERE, "Resource path: {0}", url); } Civs.logger.log(Level.SEVERE, "Unable to load config", e); } return config; }
Example 5
Source File: Utils.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public static Location locationDeserialize(String key, FileConfiguration config) { if (!config.contains(key)) { return null; } Object locSec = config.get(key); if (locSec instanceof Location) { return (Location) locSec; } try { Map<String, Object> section = (Map<String, Object>) config.get(key); if (section == null) { return null; } double x = Double.valueOf(section.get("x").toString()); double y = Double.valueOf(section.get("y").toString()); double z = Double.valueOf(section.get("z").toString()); float yaw = Float.valueOf(section.get("yaw").toString()); float pitch = Float.valueOf(section.get("pitch").toString()); World world = BedwarsRel.getInstance().getServer().getWorld(section.get("world").toString()); if (world == null) { return null; } return new Location(world, x, y, z, yaw, pitch); } catch (Exception ex) { BedwarsRel.getInstance().getBugsnag().notify(ex); ex.printStackTrace(); } return null; }
Example 6
Source File: PermissionConsistencyTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Returns all permission entries from the plugin.yml file. * * @return map with the permission entries by permission node */ private static Map<String, PermissionDefinition> getPermissionsFromPluginYmlFile() { FileConfiguration pluginFile = YamlConfiguration.loadConfiguration(getJarFile("/plugin.yml")); MemorySection permsList = (MemorySection) pluginFile.get("permissions"); Map<String, PermissionDefinition> permissions = new HashMap<>(); addChildren(permsList, permissions); return ImmutableMap.copyOf(permissions); }
Example 7
Source File: HelpMessagesConsistencyTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Since CommandInitializer contains all descriptions for commands in English, the help_en.yml file * only contains an entry for one command as to provide an example. */ @Test public void shouldOnlyHaveDescriptionForOneCommand() { // given FileConfiguration configuration = YamlConfiguration.loadConfiguration(DEFAULT_MESSAGES_FILE); // when Object commands = configuration.get("commands"); // then assertThat(commands, instanceOf(MemorySection.class)); assertThat(((MemorySection) commands).getKeys(false), contains("authme")); }
Example 8
Source File: MessageFileVerifier.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
private static boolean isNotInnerNode(String key, FileConfiguration configuration) { return !(configuration.get(key) instanceof MemorySection); }
Example 9
Source File: SpawnLoader.java From AuthMeReloaded with GNU General Public License v3.0 | 2 votes |
/** * Retrieve a property as a float from the given file configuration. * * @param configuration The file configuration to use * @param path The path of the property to retrieve * * @return The float */ private static float getFloat(FileConfiguration configuration, String path) { Object value = configuration.get(path); // This behavior is consistent with FileConfiguration#getDouble return (value instanceof Number) ? ((Number) value).floatValue() : 0; }