Java Code Examples for org.bukkit.configuration.ConfigurationSection#getStringList()

The following examples show how to use org.bukkit.configuration.ConfigurationSection#getStringList() . 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: HelpYamlReader.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extracts a list of all index topics from help.yml
 *
 * @return A list of index topics.
 */
public List<HelpTopic> getIndexTopics() {
    List<HelpTopic> topics = new LinkedList<HelpTopic>();
    ConfigurationSection indexTopics = helpYaml.getConfigurationSection("index-topics");
    if (indexTopics != null) {
        for (String topicName : indexTopics.getKeys(false)) {
            ConfigurationSection section = indexTopics.getConfigurationSection(topicName);
            String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String preamble = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("preamble", ""));
            String permission = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("permission", ""));
            List<String> commands = section.getStringList("commands");
            topics.add(new CustomIndexHelpTopic(server.getHelpMap(), topicName, shortText, permission, commands, preamble));
        }
    }
    return topics;
}
 
Example 2
Source File: HologramFormat.java    From ShopChest with MIT License 6 votes vote down vote up
/**
 * @return Whether the hologram text has to change dynamically without reloading
 */
public boolean isDynamic() {
    int count = getLineCount();
    for (int i = 0; i < count; i++) {
        ConfigurationSection options = config.getConfigurationSection("lines." + i + ".options");

        for (String key : options.getKeys(false)) {
            ConfigurationSection option = options.getConfigurationSection(key);

            String format = option.getString("format");
            if (format.contains(Placeholder.STOCK.toString()) || format.contains(Placeholder.CHEST_SPACE.toString())) {
                return true;
            }

            for (String req : option.getStringList("requirements")) {
                if (req.contains(Requirement.IN_STOCK.toString()) || req.contains(Requirement.CHEST_SPACE.toString())) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 3
Source File: HologramFormat.java    From ShopChest with MIT License 6 votes vote down vote up
/**
 * Get the format for the given line of the hologram
 * @param line Line of the hologram
 * @param reqMap Values of the requirements that might be needed by the format (contains {@code null} if not comparable)
 * @param plaMap Values of the placeholders that might be needed by the format
 * @return  The format of the first working option, or an empty String if no option is working
 *          because of not fulfilled requirements
 */
public String getFormat(int line, Map<Requirement, Object> reqMap, Map<Placeholder, Object> plaMap) {
    ConfigurationSection options = config.getConfigurationSection("lines." + line + ".options");

    optionLoop:
    for (String key : options.getKeys(false)) {
        ConfigurationSection option = options.getConfigurationSection(key);
        List<String> requirements = option.getStringList("requirements");

        String format = option.getString("format");

        for (String sReq : requirements) {
            for (Requirement req : reqMap.keySet()) {
                if (sReq.contains(req.toString())) {
                    if (!evalRequirement(sReq, reqMap)) {
                        continue optionLoop;
                    }
                }
            }
        }

        return evalPlaceholder(format, plaMap);
    }

    return "";
}
 
Example 4
Source File: GeneralSection.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
public GeneralSection(ConfigurationSection section) {
	String prefix = section.getString("spleef-prefix");
	if (prefix != null) {
		this.spleefPrefix = ChatColor.translateAlternateColorCodes(TRANSLATE_CHAR, prefix);
	} else {
		this.spleefPrefix = ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + ChatColor.BOLD + "Spleef" + ChatColor.DARK_GRAY + "]";
	}
	
	this.whitelistedCommands = section.getStringList("command-whitelist");
	String vipPrefix = section.getString("vip-prefix");
	if (vipPrefix != null) {
		this.vipPrefix = ChatColor.translateAlternateColorCodes(TRANSLATE_CHAR, vipPrefix);
	} else {
		this.vipPrefix = ChatColor.RED.toString();
	}
	
	this.vipJoinFull = section.getBoolean("vip-join-full", true);
	this.pvpTimer = section.getInt("pvp-timer", 0);
	this.broadcastGameStart = section.getBoolean("broadcast-game-start", true);
	this.broadcastGameStartBlacklist = section.getStringList("broadcast-game-start-blacklist");
	this.winMessageToAll = section.getBoolean("win-message-to-all", true);
       this.warmupMode = section.getBoolean("warmup-mode", false);
       this.warmupTime = section.getInt("warmup-time", 10);
       this.adventureMode = section.getBoolean("adventure-mode", true);
}
 
Example 5
Source File: HelpYamlReader.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extracts a list of all index topics from help.yml
 *
 * @return A list of index topics.
 */
public List<HelpTopic> getIndexTopics() {
    List<HelpTopic> topics = new LinkedList<HelpTopic>();
    ConfigurationSection indexTopics = helpYaml.getConfigurationSection("index-topics");
    if (indexTopics != null) {
        for (String topicName : indexTopics.getKeys(false)) {
            ConfigurationSection section = indexTopics.getConfigurationSection(topicName);
            String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText", ""));
            String preamble = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("preamble", ""));
            String permission = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("permission", ""));
            List<String> commands = section.getStringList("commands");
            topics.add(new CustomIndexHelpTopic(server.getHelpMap(), topicName, shortText, permission, commands, preamble));
        }
    }
    return topics;
}
 
Example 6
Source File: InventoryEntryConfig.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Override
public final void inflateUnsafe(Configuration config, Object[] args) throws ParseException {
	ConfigurationSection layoutSection = config.getConfigurationSection("layout");
	String title;
	List<String> lore;
	
	if (layoutSection != null) {
		title = layoutSection.getString("title", DEFAULT_TITLE);
		lore = layoutSection.getStringList("lore");
		
		if (lore == null || lore.isEmpty()) {
			lore = DEFAULT_LORE;
		}
	} else {
		title = DEFAULT_TITLE;
		lore = DEFAULT_LORE;
	}
	
	layout = new InventoryEntryLayout(title, lore);
}
 
Example 7
Source File: ConfigManager.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
private Map<String, List<String>> processMap(ConfigurationSection section) {
    HashMap<String, List<String>> returnMap = new HashMap<>();
    if (section == null) {
        return returnMap;
    }
    for (String key : section.getKeys(false)) {
        List<String> returnList = section.getStringList(key);
        if (returnList.isEmpty()) {
            returnList.add(key);
        } else if (returnList.size() == 1) {
            returnMap.put(key, Util.textWrap(Util.parseColors(returnList.get(0))));
        }
        returnMap.put(key, returnList);
    }
    return returnMap;
}
 
Example 8
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, String[]> getCommandAliases() {
    ConfigurationSection section = commandsConfiguration.getConfigurationSection("aliases");
    Map<String, String[]> result = new LinkedHashMap<String, String[]>();

    if (section != null) {
        for (String key : section.getKeys(false)) {
            List<String> commands;

            if (section.isList(key)) {
                commands = section.getStringList(key);
            } else {
                commands = ImmutableList.of(section.getString(key));
            }

            result.put(key, commands.toArray(new String[commands.size()]));
        }
    }

    return result;
}
 
Example 9
Source File: CustomItem.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
protected void applyConfig(ConfigurationSection section) {
	_enabled = section.getBoolean("enabled");
	_name = section.getString("name");

	ItemMeta meta = _item.getItemMeta();
	if (meta instanceof BookMeta) {
		((BookMeta) meta).setTitle(_name);
	} else {
		meta.setDisplayName(_name);
	}
	meta.setLore(section.getStringList("lore"));
	_item.setItemMeta(meta);

	List<String> allowedWorlds = section.getStringList("allowed-worlds");
	if (allowedWorlds == null || allowedWorlds.size() == 0) {
		List<String> blockedWorlds = section.getStringList("blocked-worlds");
		_blockedWorlds = (blockedWorlds.size() > 0 ? new HashSet<String>(blockedWorlds) : null);
		_allowedWorlds = null;
	} else {
		_allowedWorlds = new HashSet<String>(allowedWorlds);
	}
}
 
Example 10
Source File: PGMConfig.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
private static Permission getPermission(
    ConfigurationSection config, String id, PermissionDefault def, String realm) {
  final Map<String, Boolean> permissions = new HashMap<>();

  for (String permission : config.getStringList(realm)) {
    if (permission.startsWith("-")) {
      permissions.put(permission.substring(1), false);
    } else if (permission.startsWith("+")) {
      permissions.put(permission.substring(1), true);
    } else {
      permissions.put(permission, true);
    }
  }

  final String node =
      Permissions.GROUP
          + "."
          + id
          + (realm.contains("-") ? "-" + realm.substring(0, realm.indexOf('-')) : "");

  return Permissions.register(new Permission(node, def, permissions));
}
 
Example 11
Source File: MenuIcon.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public MenuIcon(String key, ConfigurationSection section) {
    this.key = key;
    if (section != null) {
        this.index = parseIndexArrayFromString(section.getString("index", "-1"));
        if (key.equals("back")) {
            MenuIcon backIcon = MenuManager.getInstance().getBackButton();
            this.icon = backIcon.getIcon();
            this.name = backIcon.getName();
            this.desc = backIcon.getDesc();
        } else if (key.equals("prev")) {
            MenuIcon prevButton = MenuManager.getInstance().getPrevButton();
            this.icon = prevButton.getIcon();
            this.name = prevButton.getName();
            this.desc = prevButton.getDesc();
        } else if (key.equals("next")) {
            MenuIcon nextButton = MenuManager.getInstance().getNextButton();
            this.icon = nextButton.getIcon();
            this.name = nextButton.getName();
            this.desc = nextButton.getDesc();
        } else {
            this.icon = section.getString("icon", "STONE");
            this.name = section.getString("name", "");
            this.desc = section.getString("desc", "");
            this.actions = section.getStringList("actions");
            this.perm = section.getString("permission", "");
        }
    }
}
 
Example 12
Source File: GovernmentManager.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
private HashSet<GovTypeBuff> getBuffs(ConfigurationSection section) {
    HashSet<GovTypeBuff> buffs = new HashSet<>();

    for (String key : section.getKeys(false)) {
        GovTypeBuff.BuffType buffType = GovTypeBuff.BuffType.valueOf(key.toUpperCase());
        List<String> groups = section.getStringList(key + ".groups");
        List<String> regions = section.getStringList(key + ".regions");
        HashSet<String> groupSet;
        if (groups.isEmpty()) {
            groupSet = new HashSet<>();
        } else {
            groupSet = new HashSet<>(groups);
        }
        HashSet<String> regionSet;
        if (regions.isEmpty()) {
            regionSet = new HashSet<>();
        } else {
            regionSet = new HashSet<>(regions);
        }

        GovTypeBuff govTypeBuff = new GovTypeBuff(buffType,
                section.getInt(key + ".percent", 10),
                groupSet,
                regionSet);
        buffs.add(govTypeBuff);
    }

    return buffs;
}
 
Example 13
Source File: ChallengeFactory.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static Challenge createChallenge(Rank rank, ConfigurationSection section, ChallengeDefaults defaults) {
    String name = section.getName().toLowerCase();
    if (section.getBoolean("disabled", false)) {
        return null; // Skip this challenge
    }
    String displayName = section.getString("name", name);
    Challenge.Type type = Challenge.Type.from(section.getString("type", "onPlayer"));
    List<String> requiredItems = section.isList("requiredItems") ? section.getStringList("requiredItems") : Arrays.asList(section.getString("requiredItems", "").split(" "));
    List<EntityMatch> requiredEntities = createEntities(section.getStringList("requiredEntities"));
    int resetInHours = section.getInt("resetInHours", rank.getResetInHours());
    String description = section.getString("description");
    ItemStack displayItem = createItemStack(
            section.getString("displayItem", defaults.displayItem),
            normalize(displayName), description);
    ItemStack lockedItem = section.isString("lockedDisplayItem") ? createItemStack(section.getString("lockedDisplayItem", "BARRIER"), displayName, description) : null;
    boolean takeItems = section.getBoolean("takeItems", true);
    int radius = section.getInt("radius", 10);
    Reward reward = createReward(section.getConfigurationSection("reward"));
    Reward repeatReward = createReward(section.getConfigurationSection("repeatReward"));
    if (repeatReward == null && section.getBoolean("repeatable", false)) {
        repeatReward = reward;
    }
    List<String> requiredChallenges = section.getStringList("requiredChallenges");
    int offset = section.getInt("offset", 0);
    int repeatLimit = section.getInt("repeatLimit", 0);
    return new Challenge(name, displayName, description, type,
            requiredItems, requiredEntities, requiredChallenges, section.getDouble("requiredLevel", 0d), rank,
            resetInHours, displayItem, section.getString("tool", null), lockedItem, offset, takeItems,
            radius, reward, repeatReward, repeatLimit);
}
 
Example 14
Source File: Rewards.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Reward setupReward(String rewardId, ConfigurationSection rewardInfo) {
    ICombatLogX plugin = getPlugin();
    Logger logger = getLogger();

    int chance = rewardInfo.getInt("chance");
    int maxChance = rewardInfo.getInt("max-chance");
    if(chance <= 0 || maxChance <= 0) {
        logger.info("Ignoring invalid reward '" + rewardId + "' with chance/max-chance 0.");
        return null;
    }

    if(chance > maxChance) {
        logger.info("Ignoring invalid reward '" + rewardId + "' with chance greater than max-chance.");
        return null;
    }

    List<String> commandList = rewardInfo.getStringList("commands");
    if(commandList.isEmpty()) {
        logger.info("Ignoring invalid reward '" + rewardId + "' with empty/null commands.");
        return null;
    }

    boolean mobWhiteList = rewardInfo.getBoolean("mob-whitelist");
    List<String> mobTypeList = rewardInfo.getStringList("mob-list");

    boolean worldWhiteList = rewardInfo.getBoolean("world-whitelist");
    List<String> worldNameList = rewardInfo.getStringList("world-list");

    boolean randomCommand = rewardInfo.getBoolean("random-command");
    return new Reward(plugin, chance, maxChance, mobWhiteList, worldWhiteList, randomCommand, mobTypeList, worldNameList, commandList);
}
 
Example 15
Source File: CommandManager.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets up the manager
 */
public void setUp() {
	Command.init();

	ConfigurationSection section = plugin.getConfig().getConfigurationSection("aliases");

	for(String key : section.getKeys(false)) {
		for(String alias : section.getStringList(key)) {
			aliases.put(alias, key);
		}
	}

	LoggerUtils.info("Enabled");
}
 
Example 16
Source File: DatabaseRecord.java    From PlayTimeTracker with MIT License 5 votes vote down vote up
public static DatabaseRecord deserialize(UUID id, ConfigurationSection sec) {
    DatabaseRecord rec = new DatabaseRecord();
    rec.uuid = id;
    rec.lastSeen = ZonedDateTime.parse(sec.getString("last_seen"));
    rec.dailyTime = sec.getLong("daily_play_time");
    rec.weeklyTime = sec.getLong("weekly_play_time");
    rec.monthlyTime = sec.getLong("monthly_play_time");
    rec.totalTime = sec.getLong("total_play_time");
    rec.completedDailyMissions = new HashSet<>(sec.getStringList("completed_daily_mission"));
    rec.completedWeeklyMissions = new HashSet<>(sec.getStringList("completed_weekly_mission"));
    rec.completedMonthlyMissions = new HashSet<>(sec.getStringList("completed_monthly_mission"));
    rec.completedLifetimeMissions = new HashSet<>(sec.getStringList("completed_lifetime_mission"));
    return rec;
}
 
Example 17
Source File: ConfigUtil.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
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 18
Source File: ItemGetter_Late_1_8.java    From Quests with MIT License 4 votes vote down vote up
@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 19
Source File: PlantTreeEventHandler.java    From GiantTrees with GNU General Public License v3.0 4 votes vote down vote up
public PlantTreeEventHandler(final Plugin plugin) {
  this.plugin = plugin;
  this.renderer = new TreeRenderer(plugin);
  this.popup = new PopupHandler(plugin);

  try {
    // Read the raw config
    final ConfigurationSection patternSection = plugin.getConfig()
                                                      .getConfigurationSection("planting-pattern");
    final List<String> rows = patternSection.getStringList("pattern");
    final ConfigurationSection materialsSection = patternSection.getConfigurationSection("materials");
    final Map<String, Object> configMaterialMap = materialsSection.getValues(false);

    final Map<Character, String> materialDataMap = new HashMap<>();
    for (final Map.Entry<String, Object> kvp : configMaterialMap.entrySet()) {
      materialDataMap.put(kvp.getKey().charAt(0), (String) kvp.getValue());
    }

    if (materialDataMap.values().stream().noneMatch(s -> s.equals("SAPLING"))) {
      throw new Exception("Must have at least one 'SAPLING' in the recipe.");
    }

    boneMealConsumed = patternSection.getInt("bone-meal-consumed");

    // Create a PhysicalCraftingRecipe for each kind of sapling
    List<Material> saplings = Lists.newArrayList(Material.OAK_SAPLING, Material.SPRUCE_SAPLING, Material.BIRCH_SAPLING, Material.JUNGLE_SAPLING, Material.ACACIA_SAPLING, Material.DARK_OAK_SAPLING);

    for (Material sapling : saplings) {
      Map<Character, String> patchedMaterialDataMap = new HashMap<>(materialDataMap);
      for (Character c : patchedMaterialDataMap.keySet()) {
        if (patchedMaterialDataMap.get(c).equals("SAPLING")) {
          patchedMaterialDataMap.put(c, sapling.name());
        }
      }

      recipes.add(PhysicalCraftingRecipe.fromStringRepresentation(rows.toArray(new String[] {}),
              patchedMaterialDataMap));
    }

    enabled = true;
  } catch (final Exception e) {
    plugin.getLogger().severe("The planting-pattern config section is invalid! Disabling survival planting of giant trees. " + e.toString());
    enabled = false;
  }
}
 
Example 20
Source File: RentRegion.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Send the expiration warnings from the selected profile which is specified in the config.
 * Sends all warnings since previous call until (now + normal delay), delay can be found in the config as well.
 */
public void sendExpirationWarnings() {
	// Send from warningsDoneUntil to current+delay
	if(isDeleted() || !isRented()) {
		return;
	}
	ConfigurationSection profileSection = getConfigurationSectionSetting("rent.expirationWarningProfile", "expirationWarningProfiles");
	if(profileSection == null) {
		return;
	}

	// Check if a warning needs to be send for each defined point in time
	Player player = Bukkit.getPlayer(getRenter());
	long sendUntil = Calendar.getInstance().getTimeInMillis() + (plugin.getConfig().getInt("expireWarning.delay") * 60 * 1000);
	for(String timeBefore : profileSection.getKeys(false)) {
		long timeBeforeParsed = Utils.durationStringToLong(timeBefore);
		if(timeBeforeParsed <= 0) {
			return;
		}
		long checkTime = getRentedUntil() - timeBeforeParsed;

		if(checkTime > warningsDoneUntil && checkTime <= sendUntil) {
			List<String> commands;
			if(profileSection.isConfigurationSection(timeBefore)) {
				/* Legacy config layout:
				 *   "1 minute":
				 *     warnPlayer: true
				 *     commands: ["say hi"]
				 */
				commands = profileSection.getStringList(timeBefore + ".commands");
				// Warn player
				if(profileSection.getBoolean(timeBefore + ".warnPlayer") && player != null) {
					message(player, "rent-expireWarning");
				}
			} else {
				commands = profileSection.getStringList(timeBefore);
			}
			this.runCommands(Bukkit.getConsoleSender(), commands);
		}
	}
	warningsDoneUntil = sendUntil;
}