@Override public String toString() { return "CustomObject(" + StringHelper.join(objectNames, ",") + ")"; }
@Override public Float read(String string) throws InvalidConfigException { return (float) StringHelper.readDouble(string, minValue, maxValue); }
@Override public Integer read(String string) throws InvalidConfigException { return StringHelper.readInt(string, minValue, maxValue); }
/** * Changes a village to a sandstone village. (Just sets the first * boolean it can find in the WorldGenVillageStartPiece.class to * sandstoneVillage.) * * @param subject The village. * @param sandstoneVillage Whether the village should be a sandstone * village. */ private void changeToSandstoneVillage(WorldGenVillageStartPiece subject, boolean sandstoneVillage) { ReflectionHelper.setValueInFieldOfType(subject, boolean.class, sandstoneVillage); }
/** * Monkey has two fields of type boolean. In {@link #testAmbiguousGet()}, * this was a problem. However, in this case one of the booleans in stored * in the parent class, so it is clear which field should be retrieved. */ @Test public void testActuallyNotAmbiguousGet() { Monkey monkey = new Monkey(); boolean isClimbing = ReflectionHelper.getValueInFieldOfType(monkey, boolean.class); assertEquals(monkey.isClimbing, isClimbing); }
@Override public List<String> read(String string) throws InvalidConfigException { return Arrays.asList(StringHelper.readCommaSeperatedString(string)); }
/** * Dog has two fields of type String. We can't known which one should be * retrieved. */ @Test(expected = NoSuchFieldError.class) public void testAmbiguousGet() { Dog dog = new Dog(); ReflectionHelper.getValueInFieldOfType(dog, String.class); }
@Override public Long read(String string) throws InvalidConfigException { return StringHelper.readLong(string, minValue, maxValue); }
private void injectInternalChunkGenerator(CustomChunkGenerator chunkGenerator) { ChunkProviderServer chunkProvider = this.world.getChunkProviderServer(); ChunkGenerator oldChunkGenerator = chunkProvider.chunkGenerator; if (oldChunkGenerator instanceof CustomChunkGenerator) { ReflectionHelper.setValueInFieldOfType(chunkProvider, ChunkGenerator.class, chunkGenerator); } }
/** * Simplest use case: retrieve a field stored in the class itself. */ @Test public void testGet() { Monkey monkey = new Monkey(); String name = ReflectionHelper.getValueInFieldOfType(monkey, String.class); assertEquals(monkey.name, name); }
@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 write(List<String> value) { return StringHelper.join(value, ", "); }
/** * 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); }
/** * 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); }
/** * Tests whether the list (stored in a parent class) is found. */ @Test public void testGetInParent() { Monkey monkey = new Monkey(); List<?> friends = ReflectionHelper.getValueInFieldOfType(monkey, List.class); assertEquals(monkey.friends, friends); }
/** * Constructs a new exception. Used for failed lookups using a biome id. * * @param biomeId * The id of the biome. * @param biomes * All biomes in the list. {@link Object#toString()} is used to * print the biomes. */ public BiomeNotFoundException(int biomeId, Collection<?> biomes) { super("Biome with id " + biomeId + " not found; available biomes: " + StringHelper.join(biomes, ", ")); this.biomeName = "biome-" + biomeId; }
@Override public Double read(String string) throws InvalidConfigException { return StringHelper.readDouble(string, minValue, maxValue); }
/** * 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); }
/** * Logs the message(s) with the given importance. Message will be prefixed * with [TerrainControl], so don't do that yourself. * * @param level The severity of the message * @param message The messages to log */ public void log(LogMarker level, List<String> message) { log(level, "{}", (Object) StringHelper.join(message, " ")); }