@Override public List<String> read(String string) throws InvalidConfigException { return Arrays.asList(StringHelper.readCommaSeperatedString(string)); }
@Override public String write(List<String> value) { return StringHelper.join(value, ", "); }
@Override public double[] read(String string) throws InvalidConfigException { if (string.isEmpty()) { return new double[0]; } String[] split = StringHelper.readCommaSeperatedString(string); double[] values = new double[split.length]; for (int i = 0; i < split.length; i++) { // Trimming the values allows "Value1, Value2" values[i] = StringHelper.readDouble(split[i], -Double.MAX_VALUE, Double.MAX_VALUE); } return values; }
private static WeightedMobSpawnGroup readSingleGroup(String json) throws InvalidConfigException String[] groupParts = StringHelper.readCommaSeperatedString(group); String mobName = null; int weight = -1; weight = StringHelper.readInt(value, 0, 1000); min = StringHelper.readInt(value, 0, 1000); max = StringHelper.readInt(value, 0, 1000);
@Test public void testSpecifiesBlockData() { assertFalse(StringHelper.specifiesBlockData("wool")); assertTrue(StringHelper.specifiesBlockData("wool:0")); assertTrue(StringHelper.specifiesBlockData("wool:1")); assertFalse(StringHelper.specifiesBlockData("minecraft:wool")); assertTrue(StringHelper.specifiesBlockData("minecraft:wool:0")); assertTrue(StringHelper.specifiesBlockData("minecraft:wool:1")); }
public static Biome getOrCreateBiome(BiomeConfig biomeConfig, BiomeIds biomeIds) final String biomeNameForRegistry = StringHelper.toComputerFriendlyName(biomeConfig.getName()); final ResourceLocation registryKey = new ResourceLocation(PluginStandardValues.PLUGIN_NAME.toLowerCase(), biomeNameForRegistry); if (!StringHelper.toComputerFriendlyName(alreadyRegisteredBiome.biomeName).equalsIgnoreCase(biomeNameForRegistry)) { throw new RuntimeException("Attempt was made to register biome '" + registryKey + "' with id '" + generationBiomeId + "' but this " + "has already been registered to '" + alreadyRegisteredBiome.getRegistryName() + "'!");
/** * Parses the string and returns the rarity between 0.000001 and 100 * (inclusive) * @param string The string to parse. * @return The rarity. * @throws InvalidConfigException If the number is invalid. */ protected final double readRarity(String string) throws InvalidConfigException { return StringHelper.readDouble(string, 0.000001, 100); }
@Override public Integer read(String string) throws InvalidConfigException { return StringHelper.readInt(string, minValue, maxValue); }
@Override public Long read(String string) throws InvalidConfigException { return StringHelper.readLong(string, minValue, maxValue); }
boolean checkIncludesBlockData = StringHelper.specifiesBlockData(input);
String biomeNameWithoutSpaces = StringHelper.toComputerFriendlyName(biomeConfig.getName()); MinecraftKey biomeKey = new MinecraftKey(PluginStandardValues.PLUGIN_NAME, biomeNameWithoutSpaces); int savedBiomeId = biomeIds.getSavedId();
@Override public Double read(String string) throws InvalidConfigException { return StringHelper.readDouble(string, minValue, maxValue); }
/** * Parses the string and returns a number between minValue and * maxValue. * @param string The string to be parsed as an int. * @param minValue The minimum allowed value. * @param maxValue The maximum allowed value. * @return The int, between min and max (inclusive). * @throws InvalidConfigException If the number is invalid. */ protected final int readInt(String string, int minValue, int maxValue) throws InvalidConfigException { return StringHelper.readInt(string, minValue, maxValue); }
@Override public MaterialSet read(String string) throws InvalidConfigException { MaterialSet blocks = new MaterialSet(); for (String blockName : StringHelper.readCommaSeperatedString(string)) { blocks.parseAndAdd(blockName); } return blocks; }
@Override public String toString() { return "CustomObject(" + StringHelper.join(objectNames, ",") + ")"; }
@Override public Float read(String string) throws InvalidConfigException { return (float) StringHelper.readDouble(string, minValue, maxValue); }
public static List<WeightedMobSpawnGroup> fromJson(String originalJson) throws InvalidConfigException { // Example: [{"mob": "Sheep", "weight": 12, "min": 4, "max": 4}] List<WeightedMobSpawnGroup> mobGroups = new ArrayList<WeightedMobSpawnGroup>(); String json = originalJson.trim(); if (json.length() <= 2) { // Empty Json return mobGroups; } // Remove the [..] json = removeFirstAndLastChar(json); // Every group is separated by a , but in the group the , is also // used. // So convert the ( to {, the ) to } and use an existing function to // get each group json = json.replace('{', '('); json = json.replace('}', ')'); String[] groups = StringHelper.readCommaSeperatedString(json); for (String group : groups) { mobGroups.add(readSingleGroup(group)); } return mobGroups; }
/** * Constructs a new exception. Used for failed lookups using a biome name. * * @param biomeName * The biome name that was not found. * @param biomes * All biomes in the list. {@link Object#toString()} is used to * print the biomes. */ public BiomeNotFoundException(String biomeName, Collection<?> biomes) { super("Biome " + biomeName + " not found; available biomes: " + StringHelper.join(biomes, ", ")); this.biomeName = biomeName; }
/** * Parses the string and returns a number between minValue and * maxValue. * @param string The string to parse. * @param minValue The minimum value. * @param maxValue The maximum value. * @return A double between min and max. * @throws InvalidConfigException If the number is invalid. */ protected final double readDouble(String string, double minValue, double maxValue) throws InvalidConfigException { return StringHelper.readDouble(string, minValue, maxValue); }