Java Code Examples for org.bukkit.configuration.ConfigurationSection#isSet()
The following examples show how to use
org.bukkit.configuration.ConfigurationSection#isSet() .
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: Util.java From Civs with GNU General Public License v3.0 | 6 votes |
public static ArrayList<Bounty> readBountyList(FileConfiguration config) { ArrayList<Bounty> bountyList = new ArrayList<>(); ConfigurationSection section1 = config.getConfigurationSection("bounties"); for (String key : section1.getKeys(false)) { Bounty bounty; if (section1.isSet(key + ".issuer")) { bounty = new Bounty(UUID.fromString(section1.getString(key + ".issuer")), section1.getDouble(key + ".amount")); } else { bounty = new Bounty(null, section1.getDouble(key + ".amount")); } bountyList.add(bounty); } return bountyList; }
Example 2
Source File: RegionSign.java From AreaShop with GNU General Public License v3.0 | 6 votes |
/** * Check if the sign needs to update periodically. * @return true if it needs periodic updates, otherwise false */ public boolean needsPeriodicUpdate() { ConfigurationSection signConfig = getProfile(); if(signConfig == null || !signConfig.isSet(getRegion().getState().getValue().toLowerCase())) { return false; } ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue().toLowerCase()); if(stateConfig == null) { return false; } // Check the lines for the timeleft tag for(int i = 1; i <= 4; i++) { String line = stateConfig.getString("line" + i); if(line != null && !line.isEmpty() && line.contains(Message.VARIABLE_START + AreaShop.tagTimeLeft + Message.VARIABLE_END)) { return true; } } return false; }
Example 3
Source File: SpawnEffects.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public static void spawnEffect(Game game, Player player, String particleName) { BedwarsPreSpawnEffectEvent firstEvent = new BedwarsPreSpawnEffectEvent(game, player, particleName); Main.getInstance().getServer().getPluginManager().callEvent(firstEvent); if (firstEvent.isCancelled()) { return; } ConfigurationSection effect = Main.getConfigurator().config.getConfigurationSection(particleName); if (effect != null && effect.isSet("type")) { try { String type = effect.getString("type"); if (type.equalsIgnoreCase("List")) { if (effect.isSet("list")) { List<Map<String, Object>> sections = (List<Map<String, Object>>) effect.getList("list"); for (Map<String, Object> section : sections) { useEffect((String) section.get("type"), section, player, game); } } } else { useEffect(type, effect.getValues(false), player, game); } } catch (Throwable ignored) { } } BedwarsPostSpawnEffectEvent secondEvent = new BedwarsPostSpawnEffectEvent(game, player, particleName); Main.getInstance().getServer().getPluginManager().callEvent(secondEvent); }
Example 4
Source File: SpawnEffects.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
public static void spawnEffect(Game game, Player player, String particleName) { BedwarsPreSpawnEffectEvent firstEvent = new BedwarsPreSpawnEffectEvent(game, player, particleName); Main.getInstance().getServer().getPluginManager().callEvent(firstEvent); if (firstEvent.isCancelled()) { return; } ConfigurationSection effect = Main.getConfigurator().config.getConfigurationSection(particleName); if (effect != null && effect.isSet("type")) { try { String type = effect.getString("type"); if (type.equalsIgnoreCase("List")) { if (effect.isSet("list")) { List<Map<String, Object>> sections = (List<Map<String, Object>>) effect.getList("list"); for (Map<String, Object> section : sections) { useEffect((String) section.get("type"), section, player, game); } } } else { useEffect(type, effect.getValues(false), player, game); } } catch (Throwable ignored) { } } BedwarsPostSpawnEffectEvent secondEvent = new BedwarsPostSpawnEffectEvent(game, player, particleName); Main.getInstance().getServer().getPluginManager().callEvent(secondEvent); }
Example 5
Source File: ConfigManager.java From AnnihilationPro with MIT License | 5 votes |
public static int setDefaultIfNotSet(ConfigurationSection section, String path, Object value) { if(section != null) { if(!section.isSet(path)) { section.set(path, value); return 1; } } return 0; }
Example 6
Source File: ConfigUtil.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
public static Integer getAnyInt(ConfigurationSection config, String... paths) { for (String path : paths) { if (config.isSet(path)) { return config.getInt(path); } } return null; }
Example 7
Source File: ConfigUtil.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
public static List<String> getStringListOrInlineList(ConfigurationSection config, String separator, String... paths) { for (String path : paths) { if (config.isSet(path)) { if (config.isList(path)) { return config.getStringList(path); } else { return getSeparatedValues(config.getString(path), separator); } } } return null; }
Example 8
Source File: ConfigUtil.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
public static List<String> getStringListOrSingle(ConfigurationSection config, String... paths) { for (String path : paths) { if (config.isSet(path)) { if (config.isList(path)) { return config.getStringList(path); } else { return Collections.singletonList(config.getString(path)); } } } return null; }
Example 9
Source File: ItemGetter_Late_1_8.java From Quests with MIT License | 4 votes |
@Override public ItemStack getItem(String path, ConfigurationSection config, Quests plugin, Filter... excludes) { if (path != null && !path.equals("")) { path = path + "."; } List<Filter> filters = Arrays.asList(excludes); String cName = config.getString(path + "name", path + "name"); String cType = config.getString(path + "item", config.getString(path + "type", path + "item")); List<String> cLore = config.getStringList(path + "lore"); List<String> cItemFlags = config.getStringList(path + "itemflags"); String name; Material type = null; int data = 0; // material ItemStack is = getItemStack(cType, plugin); ItemMeta ism = is.getItemMeta(); // lore if (!filters.contains(Filter.LORE)) { List<String> lore = new ArrayList<>(); if (cLore != null) { for (String s : cLore) { lore.add(ChatColor.translateAlternateColorCodes('&', s)); } } ism.setLore(lore); } // name if (!filters.contains(Filter.DISPLAY_NAME)) { name = ChatColor.translateAlternateColorCodes('&', cName); ism.setDisplayName(name); } // item flags if (!filters.contains(Filter.ITEM_FLAGS)) { if (config.isSet(path + "itemflags")) { for (String flag : cItemFlags) { for (ItemFlag iflag : ItemFlag.values()) { if (iflag.toString().equals(flag)) { ism.addItemFlags(iflag); break; } } } } } // enchantments if (!filters.contains(Filter.ENCHANTMENTS)) { if (config.isSet(path + "enchantments")) { for (String key : config.getStringList(path + "enchantments")) { String[] split = key.split(":"); String ench = split[0]; String levelName; if (split.length >= 2) { levelName = split[1]; } else { levelName = "1"; } Enchantment enchantment; if ((enchantment = Enchantment.getByName(ench)) == null) { plugin.getQuestsLogger().debug("Unrecognised enchantment: " + ench); continue; } int level; try { level = Integer.parseInt(levelName); } catch (NumberFormatException e) { level = 1; } is.addUnsafeEnchantment(enchantment, level); } } } is.setItemMeta(ism); return is; }
Example 10
Source File: UHC.java From UHC with MIT License | 4 votes |
protected void setupTeamCommands() { final Optional<TeamModule> teamModuleOptional = registry.get(TeamModule.class); if (!teamModuleOptional.isPresent()) { getLogger().info("Skipping registering team commands as the team module is not loaded"); setupCommand( dummyCommands.forModule("TeamModule"), "teams", "team", "noteam", "pmt", "randomteams", "clearteams", "tc", "teamrequest" ); return; } final TeamModule teamModule = teamModuleOptional.get(); setupCommand(new ListTeamsCommand(commandMessages("teams"), teamModule), "teams"); setupCommand(new NoTeamCommand(commandMessages("noteam"), teamModule), "noteam"); setupCommand(new TeamPMCommand(commandMessages("pmt"), teamModule), "pmt"); setupCommand(new RandomTeamsCommand(commandMessages("randomteams"), teamModule), "randomteams"); setupCommand(new ClearTeamsCommand(commandMessages("clearteams"), teamModule), "clearteams"); setupCommand(new TeamCoordinatesCommand(commandMessages("tc"), teamModule), "tc"); final SubcommandCommand team = new SubcommandCommand(); team.registerSubcommand("teamup", new TeamupCommand(commandMessages("team.teamup"), teamModule)); team.registerSubcommand("add", new TeamAddCommand(commandMessages("team.add"), teamModule)); team.registerSubcommand("remove", new TeamRemoveCommand(commandMessages("team.remove"), teamModule)); setupCommand(team , "team"); final ConfigurationSection teamModuleConfig = teamModule.getConfig(); if (!teamModuleConfig.isSet(RequestManager.AUTO_WHITELIST_KEY)) { teamModuleConfig.set(RequestManager.AUTO_WHITELIST_KEY, true); } final boolean autoWhitelistAcceptedTeams = teamModuleConfig.getBoolean(RequestManager.AUTO_WHITELIST_KEY); final MessageTemplates requestMessages = commandMessages("team.teamrequest"); final RequestManager requestManager = new RequestManager( this, requestMessages, teamModule, 20 * 120, autoWhitelistAcceptedTeams ); final SubcommandCommand teamrequest = new SubcommandCommand(); teamrequest.registerSubcommand( "accept", new RequestResponseCommand(requestMessages, requestManager, RequestManager.AcceptState.ACCEPT) ); teamrequest.registerSubcommand( "deny", new RequestResponseCommand(requestMessages, requestManager, RequestManager.AcceptState.DENY) ); teamrequest.registerSubcommand("request", new TeamRequestCommand(requestMessages, requestManager)); teamrequest.registerSubcommand("list", new RequestListCommand(requestMessages, requestManager)); setupCommand(teamrequest, "teamrequest"); }
Example 11
Source File: RegionSign.java From AreaShop with GNU General Public License v3.0 | 4 votes |
/** * Update this sign. * @return true if the update was successful, otherwise false */ public boolean update() { // Ignore updates of signs in chunks that are not loaded Location signLocation = getLocation(); if(signLocation == null || signLocation.getWorld() == null || !signLocation.getWorld().isChunkLoaded(signLocation.getBlockX() >> 4, signLocation.getBlockZ() >> 4)) { return false; } if(getRegion().isDeleted()) { return false; } YamlConfiguration regionConfig = getRegion().getConfig(); ConfigurationSection signConfig = getProfile(); Block block = signLocation.getBlock(); if(signConfig == null || !signConfig.isSet(getRegion().getState().getValue())) { block.setType(Material.AIR); return true; } ConfigurationSection stateConfig = signConfig.getConfigurationSection(getRegion().getState().getValue()); // Get the lines String[] signLines = new String[4]; boolean signEmpty = true; for(int i = 0; i < 4; i++) { signLines[i] = stateConfig.getString("line" + (i + 1)); signEmpty &= (signLines[i] == null || signLines[i].isEmpty()); } if(signEmpty) { block.setType(Material.AIR); return true; } // Place the sign back (with proper rotation and type) after it has been hidden or (indirectly) destroyed if(!Materials.isSign(block.getType())) { Material signType = getMaterial(); // Don't do physics here, we first need to update the direction block.setType(signType, false); // This triggers a physics update, which pops the sign if not attached properly if (!AreaShop.getInstance().getBukkitHandler().setSignFacing(block, getFacing())) { AreaShop.warn("Failed to update the facing direction of the sign at", getStringLocation(), "to ", getFacing(), ", region:", getRegion().getName()); } // Check if the sign has popped if(!Materials.isSign(block.getType())) { AreaShop.warn("Setting sign", key, "of region", getRegion().getName(), "failed, could not set sign block back"); return false; } } // Save current rotation and type if(!regionConfig.isString("general.signs." + key + ".signType")) { getRegion().setSetting("general.signs." + key + ".signType", block.getType().name()); } if(!regionConfig.isString("general.signs." + key + ".facing")) { BlockFace signFacing = AreaShop.getInstance().getBukkitHandler().getSignFacing(block); getRegion().setSetting("general.signs." + key + ".facing", signFacing == null ? null : signFacing.toString()); } // Apply replacements and color and then set it on the sign Sign signState = (Sign) block.getState(); for(int i = 0; i < signLines.length; i++) { if(signLines[i] == null) { signState.setLine(i, ""); continue; } signLines[i] = Message.fromString(signLines[i]).replacements(getRegion()).getSingle(); signLines[i] = Utils.applyColors(signLines[i]); signState.setLine(i, signLines[i]); } signState.update(); return true; }