Java Code Examples for org.bukkit.configuration.file.YamlConfiguration#contains()
The following examples show how to use
org.bukkit.configuration.file.YamlConfiguration#contains() .
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: CustomGunItem.java From QualityArmory with GNU General Public License v3.0 | 6 votes |
@Override public void initIronsights(File dataFolder) { File ironsights = new File(dataFolder, "default_ironsightstoggleitem.yml"); YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights); if (!ironconfig.contains("displayname")) { ironconfig.set("material", Material.CROSSBOW.name()); ironconfig.set("id", 68); ironconfig.set("displayname", IronsightsHandler.ironsightsDisplay); try { ironconfig.save(ironsights); } catch (IOException e) { e.printStackTrace(); } } IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material")); IronsightsHandler.ironsightsData = ironconfig.getInt("id"); IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname"); }
Example 2
Source File: CustomGunItem.java From QualityArmory with GNU General Public License v3.0 | 6 votes |
@Override public void initIronsights(File dataFolder) { File ironsights = new File(dataFolder,"default_ironsightstoggleitem.yml"); YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights); if(!ironconfig.contains("displayname")){ ironconfig.set("material",Material.DIAMOND_AXE.name()); ironconfig.set("id",21); ironconfig.set("displayname",IronsightsHandler.ironsightsDisplay); try { ironconfig.save(ironsights); } catch (IOException e) { e.printStackTrace(); } } IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material")); IronsightsHandler.ironsightsData = ironconfig.getInt("id"); IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname"); }
Example 3
Source File: YamlIncompleteTranslationTest.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
@Test public void testMessageEnum() throws Exception { File motherLangFile = new File(langDir, "en-en.yml"); YamlConfiguration motherConfiguration = YamlConfiguration.loadConfiguration(motherLangFile); int missingCount = 0; for(MessageWrapper message : Message.values()) { if(!motherConfiguration.contains(message.getPath())) { System.out.println(" - " + message.getPath()); missingCount++; } } if(missingCount == 0) { System.out.println("Result: No missing keys"); } else { throw new Exception("Found " + missingCount + " missing keys in en-en file that are present in Message class"); } }
Example 4
Source File: YamlEnumTest.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
@Test public void testEmptyEnums() throws Exception { System.out.println("Testing empty Config enums"); YamlConfiguration config = getConfig(); int missingCount = 0; for(ConfigWrapper c : Config.values()) { if(!config.contains(c.getPath())) { System.out.println("Empty enum: " + c.getName()); missingCount++; } } if(missingCount == 0) { System.out.println("All values are fine in the Config enum"); } else { throw new Exception("Found " + missingCount + " empty Config enums"); } System.out.println(); }
Example 5
Source File: IslandInfo.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
public IslandInfo(@NotNull String islandName, @NotNull uSkyBlock plugin) { Validate.notNull(islandName, "IslandName cannot be null"); Validate.notEmpty(islandName, "IslandName cannot be empty"); this.plugin = plugin; config = new YamlConfiguration(); file = new File(directory, islandName + ".yml"); name = islandName; if (file.exists()) { readConfig(config, file); if (config.getInt("version", 0) < YML_VERSION || config.contains("maxSize")) { updateConfig(); } } else { log.fine("No file for " + islandName + " found, creating a fresh island!"); } }
Example 6
Source File: DeluxeMenusMigrater.java From TrMenu with MIT License | 5 votes |
public static void migrateDeluxeMenu(File file, boolean useSlot) { YamlConfiguration c = YamlConfiguration.loadConfiguration(file); if (c.contains("gui_menus")) { for (String menu : c.getConfigurationSection("gui_menus").getKeys(false)) { migrateDeluxeMenu(null, menu + ".yml", c.getConfigurationSection("gui_menus." + menu), useSlot); } } else { migrateDeluxeMenu(file, file.getName(), c, useSlot); } }
Example 7
Source File: AttachmentYML.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
public YamlConfiguration getBaseGunFile() { if(this.file==null) return null; File newGunFolder = new File(this.file.getParentFile().getParentFile(), "newGuns"); for (File f : newGunFolder.listFiles()) { YamlConfiguration config = YamlConfiguration.loadConfiguration(f); if (!config.contains("invalid") || !config.getBoolean("invalid")) if (config.contains("name")) { if (config.getString("name").equalsIgnoreCase(getBaseGun())) { return config; } } } return null; }
Example 8
Source File: PlayerData.java From NametagEdit with GNU General Public License v3.0 | 5 votes |
public static PlayerData fromFile(String key, YamlConfiguration file) { if (!file.contains("Players." + key)) return null; PlayerData data = new PlayerData(); data.setUuid(UUID.fromString(key)); data.setName(file.getString("Players." + key + ".Name")); data.setPrefix(file.getString("Players." + key + ".Prefix", "")); data.setSuffix(file.getString("Players." + key + ".Suffix", "")); data.setSortPriority(file.getInt("Players." + key + ".SortPriority", -1)); return data; }
Example 9
Source File: WorldFlatFileRegionManager.java From RedProtect with GNU General Public License v3.0 | 5 votes |
private static void fixdbFlags(YamlConfiguration db, String rname) { if (db.contains(rname + ".flags.mobs")) { db.set("spawn-monsters", db.get(rname + ".flags.mobs")); db.set(rname + ".flags.mobs", null); } if (db.contains(rname + ".flags.spawnpassives")) { db.set("spawn-animals", db.get(rname + ".flags.spawnpassives")); db.set(rname + ".flags.spawnpassives", null); } }
Example 10
Source File: ConverterChestCommands.java From TrMenu with MIT License | 4 votes |
private static int convert(File file, int count) { if (file.isDirectory()) { for (File f : file.listFiles()) { count += convert(f, count); } return count; } else if (!file.getName().endsWith(".yml")) { return count; } try { ListIterator<Character> buttons = Arrays.asList('#', '-', '+', '=', '<', '>', '~', '_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z').listIterator(); YamlConfiguration trmenu = new YamlConfiguration(); YamlConfiguration conf = YamlConfiguration.loadConfiguration(file); List<String> cmds = conf.contains("menu-settings.command") ? Arrays.asList(conf.getString("menu-settings.command").split(";( )?")) : new ArrayList<>(); for (int i = 0; i < cmds.size(); i++) { cmds.set(i, cmds.get(i) + "-fromCC"); } int rows = conf.getInt("menu-settings.rows", 6); int update = conf.getInt("menu-settings.auto-refresh", -1) * 20; trmenu.set("Title", conf.getString("menu-settings.name")); trmenu.set("Open-Commands", cmds); trmenu.set("Open-Actions", conf.contains("menu-settings.open-action") ? conf.getString("menu-settings.open-action").split(";( )?") : ""); List<String> shape = Lists.newArrayList(); while (rows > 0) { shape.add(" "); rows--; } trmenu.set("Shape", shape); conf.getValues(false).forEach((icon, value) -> { if (!"menu-settings".equalsIgnoreCase(icon)) { MemorySection section = (MemorySection) value; int x = section.getInt("POSITION-X") - 1; int y = section.getInt("POSITION-Y") - 1; char[] chars = shape.get(y).toCharArray(); char symbol = buttons.next(); chars[x] = symbol; shape.set(y, new String(chars)); if (update > 0) { trmenu.set("Buttons." + symbol + ".update", update); } trmenu.set("Buttons." + symbol + ".display.mats", section.get("ID")); trmenu.set("Buttons." + symbol + ".display.name", section.get("NAME")); trmenu.set("Buttons." + symbol + ".display.lore", section.get("LORE")); if (section.contains("COMMAND")) { trmenu.set("Buttons." + symbol + ".actions.all", section.getString("COMMAND").split(";( )?")); } if (section.contains("ENCHANTMENT")) { trmenu.set("Buttons." + symbol + ".display.shiny", true); } } }); trmenu.set("Shape", fixShape(shape)); file.renameTo(new File(file.getParent(), file.getName().replace(".yml", "") + ".CONVERTED.TRMENU")); trmenu.save(new File(TrMenu.getPlugin().getDataFolder(), "menus/" + file.getName().replace(".yml", "") + "-fromcc.yml")); return count + 1; } catch (Throwable e) { e.printStackTrace(); } return count; }
Example 11
Source File: YamlIncompleteTranslationTest.java From NovaGuilds with GNU General Public License v3.0 | 4 votes |
@Test public void testTranslations() throws Exception { //Mother lang setup File motherLangFile = new File(langDir, "en-en.yml"); YamlConfiguration motherConfiguration = YamlConfiguration.loadConfiguration(motherLangFile); final List<String> motherKeys = new ArrayList<>(); for(String key : motherConfiguration.getKeys(true)) { if(!motherConfiguration.isConfigurationSection(key)) { motherKeys.add(key); } } //List all languages and configuration sections Map<String, YamlConfiguration> configurationMap = new HashMap<>(); if(langDir.isDirectory()) { File[] list = langDir.listFiles(); if(list != null) { for(File langFile : list) { if(!langFile.getName().equals("en-en.yml")) { configurationMap.put(StringUtils.replace(langFile.getName(), ".yml", ""), Lang.loadConfiguration(langFile)); } } } } //Get keys from all langs System.out.println("Testing lang files for missing keys..."); int globalMissingCount = 0; for(Map.Entry<String, YamlConfiguration> entry : configurationMap.entrySet()) { int missingCount = 0; String name = entry.getKey(); YamlConfiguration configuration = entry.getValue(); System.out.println("---"); System.out.println(); System.out.println("Testing lang: " + name); for(String mKey : motherKeys) { if(!configuration.contains(mKey)) { if(missingCount == 0) { System.out.println("Missing keys:"); } System.out.println(" - " + mKey); missingCount++; } } globalMissingCount += missingCount; } if(globalMissingCount == 0) { System.out.println("Result: No missing keys"); } else { throw new Exception("Found " + globalMissingCount + " missing keys in lang files"); } }