Java Code Examples for org.bukkit.configuration.file.FileConfiguration#contains()
The following examples show how to use
org.bukkit.configuration.file.FileConfiguration#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: CrazyCrates.java From Crazy-Crates with MIT License | 6 votes |
/** * Take keys from an offline player. * @param player The player which you are taking keys from. * @param crate The Crate of which key you are taking from the player. * @param keys The amount of keys you wish to take. * @return Returns true if it took the keys and false if an error occurred. */ public boolean takeOfflineKeys(String player, Crate crate, int keys) { try { FileConfiguration data = Files.DATA.getFile(); player = player.toLowerCase(); int playerKeys = 0; if (data.contains("Offline-Players." + player + "." + crate.getName())) { playerKeys = data.getInt("Offline-Players." + player + "." + crate.getName()); } data.set("Offline-Players." + player + "." + crate.getName(), playerKeys - keys); Files.DATA.saveFile(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
Example 2
Source File: Methods.java From Crazy-Crates with MIT License | 6 votes |
public static HashMap<ItemStack, String> getItems(Player player) { HashMap<ItemStack, String> items = new HashMap<>(); FileConfiguration file = cc.getOpeningCrate(player).getFile(); for (String reward : file.getConfigurationSection("Crate.Prizes").getKeys(false)) { String id = file.getString("Crate.Prizes." + reward + ".DisplayItem"); String name = file.getString("Crate.Prizes." + reward + ".DisplayName"); int chance = file.getInt("Crate.Prizes." + reward + ".Chance"); int max = 99; if (file.contains("Crate.Prizes." + reward + ".MaxRange")) { max = file.getInt("Crate.Prizes." + reward + ".MaxRange") - 1; } try { ItemStack item = new ItemBuilder().setMaterial(id).setName(name).build(); int num; for (int counter = 1; counter <= 1; counter++) { num = 1 + random.nextInt(max); if (num >= 1 && num <= chance) items.put(item, "Crate.Prizes." + reward); } } catch (Exception e) { } } return items; }
Example 3
Source File: GUI.java From Crazy-Auctions with MIT License | 6 votes |
public static ItemStack getBiddingGlass(Player player, String ID) { FileConfiguration config = Files.CONFIG.getFile(); String id = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item"); String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name"); ItemStack item; int bid = bidding.get(player); if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) { List<String> lore = new ArrayList<>(); for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) { lore.add(l.replace("%Bid%", bid + "").replace("%bid%", bid + "").replace("%TopBid%", Methods.getPrice(ID, false)).replace("%topbid%", Methods.getPrice(ID, false))); } item = Methods.makeItem(id, 1, name, lore); } else { item = Methods.makeItem(id, 1, name); } return item; }
Example 4
Source File: BedwarsRel.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
public Integer getRespawnProtectionTime() { FileConfiguration config = this.getConfig(); if (config.contains("respawn-protection") && config.isInt("respawn-protection")) { return config.getInt("respawn-protection"); } return 0; }
Example 5
Source File: ResourceManagerPlayerImpl.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
@Override public boolean save(NovaPlayer nPlayer) { if(!nPlayer.isChanged() && !isInSaveQueue(nPlayer) || nPlayer.isUnloaded()) { return false; } if(!nPlayer.isAdded()) { add(nPlayer); } FileConfiguration playerData = getData(nPlayer); if(playerData != null) { try { //set values playerData.set("name", nPlayer.getName()); playerData.set("guild", nPlayer.hasGuild() ? nPlayer.getGuild().getUUID().toString() : null); playerData.set("invitedto", new ToStringConverterImpl().convert((List) new ResourceToUUIDConverterImpl<NovaGuild>().convert(nPlayer.getInvitedTo()))); playerData.set("points", nPlayer.getPoints()); playerData.set("kills", nPlayer.getKills()); playerData.set("deaths", nPlayer.getDeaths()); if(playerData.contains("uuid")) { playerData.set("uuid", null); } //save playerData.save(getFile(nPlayer)); } catch(IOException e) { LoggerUtils.exception(e); } } else { LoggerUtils.error("Attempting to save non-existing player. " + nPlayer.getName()); } return true; }
Example 6
Source File: SpawnLoader.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
/** * Return whether the file configuration contains all fields necessary to define a spawn * under the given path. * * @param configuration The file configuration to use * @param pathPrefix The path to verify * * @return True if all spawn fields are present, false otherwise */ private static boolean containsAllSpawnFields(FileConfiguration configuration, String pathPrefix) { String[] fields = {"world", "x", "y", "z", "yaw", "pitch"}; for (String field : fields) { if (!configuration.contains(pathPrefix + "." + field)) { return false; } } return true; }
Example 7
Source File: GroupManager.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Loads the groups defined in a 'worlds.yml' file into memory. * * @param config The contents of the configuration file. */ public void loadGroupsToMemory(FileConfiguration config) { groups.clear(); for (String key : config.getConfigurationSection("groups.").getKeys(false)) { List<String> worlds; if (config.contains("groups." + key + ".worlds")) { worlds = config.getStringList("groups." + key + ".worlds"); } else { worlds = config.getStringList("groups." + key); config.set("groups." + key, null); config.set("groups." + key + ".worlds", worlds); if (settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) { config.set("groups." + key + ".default-gamemode", "SURVIVAL"); } } if (settings.getProperty(PwiProperties.MANAGE_GAMEMODES)) { GameMode gameMode = GameMode.SURVIVAL; if (config.getString("groups." + key + ".default-gamemode") != null) { gameMode = GameMode.valueOf(config.getString("groups." + key + ".default-gamemode").toUpperCase()); } addGroup(key, worlds, gameMode); } else { addGroup(key, worlds); } setDefaultsFile(key); } }
Example 8
Source File: CrazyCrates.java From Crazy-Crates with MIT License | 5 votes |
private ItemStack getKey(FileConfiguration file) { String name = file.getString("Crate.PhysicalKey.Name"); List<String> lore = file.getStringList("Crate.PhysicalKey.Lore"); String id = file.getString("Crate.PhysicalKey.Item"); boolean glowing = false; if (file.contains("Crate.PhysicalKey.Glowing")) { glowing = file.getBoolean("Crate.PhysicalKey.Glowing"); } return new ItemBuilder().setMaterial(id).setName(name).setLore(lore).setGlowing(glowing).build(); }
Example 9
Source File: GUI.java From Crazy-Auctions with MIT License | 5 votes |
public static void openBidding(Player player, String ID) { Methods.updateAuction(); FileConfiguration config = Files.CONFIG.getFile(); FileConfiguration data = Files.DATA.getFile(); if (!data.contains("Items." + ID)) { openShop(player, ShopType.BID, shopCategory.get(player), 1); player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage()); return; } Inventory inv = Bukkit.createInventory(null, 27, Methods.color(config.getString("Settings.Bidding-On-Item"))); if (!bidding.containsKey(player)) bidding.put(player, 0); if (Version.getCurrentVersion().isNewer(Version.v1_12_R1)) { inv.setItem(9, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1")); inv.setItem(10, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+10")); inv.setItem(11, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+100")); inv.setItem(12, Methods.makeItem("LIME_STAINED_GLASS_PANE", 1, "&a+1000")); inv.setItem(14, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1000")); inv.setItem(15, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-100")); inv.setItem(16, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-10")); inv.setItem(17, Methods.makeItem("RED_STAINED_GLASS_PANE", 1, "&c-1")); } else { inv.setItem(9, Methods.makeItem("160:5", 1, "&a+1")); inv.setItem(10, Methods.makeItem("160:5", 1, "&a+10")); inv.setItem(11, Methods.makeItem("160:5", 1, "&a+100")); inv.setItem(12, Methods.makeItem("160:5", 1, "&a+1000")); inv.setItem(14, Methods.makeItem("160:14", 1, "&c-1000")); inv.setItem(15, Methods.makeItem("160:14", 1, "&c-100")); inv.setItem(16, Methods.makeItem("160:14", 1, "&c-10")); inv.setItem(17, Methods.makeItem("160:14", 1, "&c-1")); } inv.setItem(13, getBiddingGlass(player, ID)); inv.setItem(22, Methods.makeItem(config.getString("Settings.GUISettings.OtherSettings.Bid.Item"), 1, config.getString("Settings.GUISettings.OtherSettings.Bid.Name"), config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore"))); inv.setItem(4, getBiddingItem(player, ID)); player.openInventory(inv); }
Example 10
Source File: CondYamlExists.java From skUtilities with GNU General Public License v3.0 | 5 votes |
@Override public boolean check(Event e) { File pth = new File(skUtilities.getDefaultPath(path.getSingle(e))); FileConfiguration con = YamlConfiguration.loadConfiguration(pth); Boolean v = con.contains(yaml.getSingle(e)); return (isNegated() ? !v : v); }
Example 11
Source File: PlayerClass.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
/** * Creates a PlayerClass from the given class config. * * @param caliburn the CaliburnAPI instance * @param name the class name * @param config the config */ public PlayerClass(CaliburnAPI caliburn, String name, FileConfiguration config) { this.name = name; if (config.contains("items")) { items = caliburn.deserializeStackList(config, "items"); } if (config.contains("dog")) { dog = config.getBoolean("dog"); } }
Example 12
Source File: CivSettings.java From civcraft with GNU General Public License v2.0 | 5 votes |
public static Integer getInteger(FileConfiguration cfg, String path) throws InvalidConfiguration { if (!cfg.contains(path)) { throw new InvalidConfiguration("Could not get configuration integer "+path); } int data = cfg.getInt(path); return data; }
Example 13
Source File: BedwarsRel.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
public boolean getBooleanConfig(String key, boolean defaultBool) { FileConfiguration config = this.getConfig(); if (config.contains(key) && config.isBoolean(key)) { return config.getBoolean(key); } return defaultBool; }
Example 14
Source File: Cardinal.java From CardinalPGM with MIT License | 5 votes |
private void registerSettings() { FileConfiguration config = YamlConfiguration.loadConfiguration(new InputStreamReader(this.getResource("settings.yml"), Charsets.UTF_8)); if (config.contains("settings")) { for (String settingName : config.getStringList("settings")) { List<String> names = new ArrayList<>(); String description = "No description."; List<SettingValue> values = new ArrayList<>(); names.add(settingName.trim()); if (config.contains("setting." + settingName + ".aliases")) { for (String alias : config.getStringList("setting." + settingName + ".aliases")) { names.add(alias.trim()); } } if (config.contains("setting." + settingName + ".description")) description = config.getString("setting." + settingName + ".description"); if (config.contains("setting." + settingName + ".values")) { for (String valueName : config.getStringList("setting." + settingName + ".values")) { if (valueName.endsWith("[default]")) values.add(new SettingValue(valueName.trim().substring(0, valueName.length() - 9), true)); else values.add(new SettingValue(valueName.trim(), false)); } } new Setting(names, description, values); } } new Setting(Arrays.asList("ChatChannel"), "Choose a default chat channel.", Arrays.asList(new SettingValue("global", false), new SettingValue("team", true), new SettingValue("admin", false))); }
Example 15
Source File: GroupManager.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Loads the groups defined in a 'worlds.yml' file into memory. * * @param config The contents of the configuration file. */ public void loadGroupsToMemory(FileConfiguration config) { groups.clear(); for (String key : config.getConfigurationSection("groups.").getKeys(false)) { List<String> worlds; if (config.contains("groups." + key + ".worlds")) { worlds = config.getStringList("groups." + key + ".worlds"); } else { worlds = config.getStringList("groups." + key); config.set("groups." + key, null); config.set("groups." + key + ".worlds", worlds); if (settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) { config.set("groups." + key + ".default-gamemode", "SURVIVAL"); } } if (settings.getProperty(PwiProperties.MANAGE_GAMEMODES)) { GameMode gameMode = GameMode.SURVIVAL; if (config.getString("groups." + key + ".default-gamemode") != null) { gameMode = GameMode.valueOf(config.getString("groups." + key + ".default-gamemode").toUpperCase()); } addGroup(key, worlds, gameMode); } else { addGroup(key, worlds); } setDefaultsFile(key); } }
Example 16
Source File: BedwarsRel.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
public List<String> getAllowedCommands() { FileConfiguration config = this.getConfig(); if (config.contains("allowed-commands") && config.isList("allowed-commands")) { return config.getStringList("allowed-commands"); } return new ArrayList<String>(); }
Example 17
Source File: ExpansionManager.java From PlaceholderAPI with GNU General Public License v3.0 | 4 votes |
public boolean registerExpansion(PlaceholderExpansion expansion) { if (expansion == null || expansion.getIdentifier() == null) { return false; } if (expansion instanceof Configurable) { Map<String, Object> defaults = ((Configurable) expansion).getDefaults(); String pre = "expansions." + expansion.getIdentifier() + "."; FileConfiguration cfg = plugin.getConfig(); boolean save = false; if (defaults != null) { for (Entry<String, Object> entries : defaults.entrySet()) { if (entries.getKey() == null || entries.getKey().isEmpty()) { continue; } if (entries.getValue() == null) { if (cfg.contains(pre + entries.getKey())) { save = true; cfg.set(pre + entries.getKey(), null); } } else { if (!cfg.contains(pre + entries.getKey())) { save = true; cfg.set(pre + entries.getKey(), entries.getValue()); } } } } if (save) { plugin.saveConfig(); plugin.reloadConfig(); } } if (expansion instanceof VersionSpecific) { VersionSpecific nms = (VersionSpecific) expansion; if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) { plugin.getLogger() .info( "Your server version is not compatible with expansion: " + expansion.getIdentifier() + " version: " + expansion.getVersion()); return false; } } if (!expansion.canRegister()) { return false; } if (!expansion.register()) { return false; } if (expansion instanceof Listener) { Listener l = (Listener) expansion; Bukkit.getPluginManager().registerEvents(l, plugin); } plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier()); if (expansion instanceof Taskable) { ((Taskable) expansion).start(); } if (plugin.getExpansionCloud() != null) { CloudExpansion ce = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier()); if (ce != null) { ce.setHasExpansion(true); if (!ce.getLatestVersion().equals(expansion.getVersion())) { ce.setShouldUpdate(true); } } } return true; }
Example 18
Source File: GunYMLLoader.java From QualityArmory with GNU General Public License v3.0 | 4 votes |
public static void loadAttachments(QAMain main) { if (new File(main.getDataFolder(), "attachments").exists()) { int items = 0; for (File f : new File(main.getDataFolder(), "attachments").listFiles()) { try { if (f.getName().contains("yml")) { FileConfiguration f2 = YamlConfiguration.loadConfiguration(f); if ((!f2.contains("invalid")) || !f2.getBoolean("invalid")) { final String name = f2.getString("name"); main.getLogger().info("-Loading Attachment: " + name); final String displayname = f2.contains("displayname") ? ChatColor.translateAlternateColorCodes('&', f2.getString("displayname")) : (ChatColor.GOLD + name); final List<String> extraLore2 = f2.contains("lore") ? f2.getStringList("lore") : null; Material m = f2.contains("material") ? Material.matchMaterial(f2.getString("material")) : Material.DIAMOND_AXE; int variant = f2.contains("variant") ? f2.getInt("variant") : 0; final MaterialStorage ms = MaterialStorage.getMS(m, f2.getInt("id"), variant); // Gun baseGun = null; MaterialStorage baseGunM = null; String base = f2.getString("baseGun"); for (Entry<MaterialStorage, Gun> g : QAMain.gunRegister.entrySet()) { if (g.getValue().getName().equalsIgnoreCase(base)) { // baseGun = g.getValue(); baseGunM = g.getKey(); } } final List<String> extraLore = new ArrayList<String>(); try { for (String lore : extraLore2) { extraLore.add(ChatColor.translateAlternateColorCodes('&', lore)); } } catch (Error | Exception re52) { } if(baseGunM==null){ main.getLogger().info("--Failed to load "+name+" attachment because the base \""+base+"\" does not exist."); continue; } AttachmentBase attach = new AttachmentBase(baseGunM, ms, name, displayname); QAMain.gunRegister.put(ms, attach); items++; attach.setCustomLore(extraLore); final Object[] materials = main .convertIngredientsRaw(f2.getStringList("craftingRequirements")); attach.setIngredientsRaw(materials); // QAMain.attachmentRegister.put(ms, attach); loadGunSettings(attach, f2); } } } catch (Exception e) { e.printStackTrace(); } } if(!QAMain.verboseLoadingLogging) main.getLogger().info("-Loaded "+items+" Attachment types."); } }
Example 19
Source File: GunYMLLoader.java From QualityArmory with GNU General Public License v3.0 | 4 votes |
public static void loadMisc(QAMain main) { if (new File(main.getDataFolder(), "misc").exists()) { int items = 0; for (File f : new File(main.getDataFolder(), "misc").listFiles()) { try { if (f.getName().contains("yml")) { FileConfiguration f2 = YamlConfiguration.loadConfiguration(f); if ((!f2.contains("invalid")) || !f2.getBoolean("invalid")) { final String name = f2.getString("name"); if (QAMain.verboseLoadingLogging) main.getLogger().info("-Loading Misc: " + name); Material m = f2.contains("material") ? Material.matchMaterial(f2.getString("material")) : Material.DIAMOND_AXE; int variant = f2.contains("variant") ? f2.getInt("variant") : 0; final MaterialStorage ms = MaterialStorage.getMS(m, f2.getInt("id"), variant); final ItemStack[] materails = main .convertIngredients(f2.getStringList("craftingRequirements")); final String displayname = f2.contains("displayname") ? ChatColor.translateAlternateColorCodes('&', f2.getString("displayname")) : (ChatColor.WHITE + name); final List<String> rawLore = f2.contains("lore") ? f2.getStringList("lore") : null; final List<String> lore = new ArrayList<String>(); try { for (String lore2 : rawLore) { lore.add(ChatColor.translateAlternateColorCodes('&', lore2)); } } catch (Error | Exception re52) { } final int price = f2.contains("price") ? f2.getInt("price") : 100; int damage = f2.contains("damage") ? f2.getInt("damage") : 1; // int durib = f2.contains("durability") ? f2.getInt("durability") : 1000; WeaponType wt = WeaponType.getByName(f2.getString("MiscType")); double radius = f2.contains("radius") ? f2.getDouble("radius") : 0; items++; CustomBaseObject base = null; String soundEquip = f2.contains("sound_equip")? f2.getString("sound_equip"):null; String soundHit = f2.contains("sound_meleehit")? f2.getString("sound_meleehit"):null; if (wt == WeaponType.MEDKIT) QAMain.miscRegister.put(ms, base=new MedKit(ms, name, displayname, materails, price)); if (wt == WeaponType.MELEE) { QAMain.miscRegister.put(ms, base = new MeleeItems(ms, name, displayname, materails, price, damage)); base.setSoundOnEquip(soundEquip); base.setSoundOnHit(soundHit); base.setCustomLore(lore); } if (wt == WeaponType.GRENADES) QAMain.miscRegister.put(ms, base=new Grenade(materails, price, damage, radius, name, displayname, lore, ms)); if (wt == WeaponType.SMOKE_GRENADES) QAMain.miscRegister.put(ms, base=new SmokeGrenades(materails, price, damage, radius, name, displayname, lore, ms)); if (wt == WeaponType.INCENDARY_GRENADES) QAMain.miscRegister.put(ms, base=new IncendaryGrenades(materails, price, damage, radius, name, displayname, lore, ms)); if (wt == WeaponType.FLASHBANGS) QAMain.miscRegister.put(ms, base=new Flashbang(materails, price, damage, radius, name, displayname, lore, ms)); if(base!=null) { base.setCustomLore(lore); base.setIngredients(materails); } } } } catch (Exception e) { e.printStackTrace(); } } if(!QAMain.verboseLoadingLogging) main.getLogger().info("-Loaded "+items+" Misc."); } }
Example 20
Source File: GunYMLLoader.java From QualityArmory with GNU General Public License v3.0 | 4 votes |
public static void loadArmor(QAMain main) { if (new File(main.getDataFolder(), "armor").exists()) { int items = 0; for (File f : new File(main.getDataFolder(), "armor").listFiles()) { try { if (f.getName().contains("yml")) { FileConfiguration f2 = YamlConfiguration.loadConfiguration(f); if ((!f2.contains("invalid")) || !f2.getBoolean("invalid")) { final String name = f2.getString("name"); if(QAMain.verboseLoadingLogging) main.getLogger().info("-Loading Armor: " + name); Material m = f2.contains("material") ? Material.matchMaterial(f2.getString("material")) : Material.DIAMOND_AXE; int variant = f2.contains("variant") ? f2.getInt("variant") : 0; final MaterialStorage ms = MaterialStorage.getMS(m, f2.getInt("id"), variant); final ItemStack[] materails = main .convertIngredients(f2.getStringList("craftingRequirements")); final String displayname = f2.contains("displayname") ? ChatColor.translateAlternateColorCodes('&', f2.getString("displayname")) : (ChatColor.WHITE + name); final List<String> rawLore = f2.contains("lore") ? f2.getStringList("lore") : null; final List<String> lore = new ArrayList<String>(); try { for (String lore2 : rawLore) { lore.add(ChatColor.translateAlternateColorCodes('&', lore2)); } } catch (Error | Exception re52) { } final int price = f2.contains("price") ? f2.getInt("price") : 100; WeaponType wt = WeaponType.getByName(f2.getString("MiscType")); if (wt == WeaponType.HELMET) { QAMain.armorRegister.put(ms, new Helmet(name, displayname, lore, materails, ms, price)); items++; } } } } catch (Exception e) { e.printStackTrace(); } } if(!QAMain.verboseLoadingLogging) main.getLogger().info("-Loaded "+items+" Armor types."); } }