1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

[CI Skip] Merge pull request #3425 from poma123/api/biome-map-parser

This commit is contained in:
Daniel Walsh 2022-01-15 16:36:33 +00:00 committed by GitHub
commit 7054b50e43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -148,6 +148,15 @@ public class BiomeMap<T> implements Keyed {
return parser.buildBiomeMap();
}
@ParametersAreNonnullByDefault
public static <T> @Nonnull BiomeMap<T> fromJson(NamespacedKey key, String json, BiomeDataConverter<T> valueConverter, boolean isLenient) throws BiomeMapException {
// All parameters are validated by the Parser.
BiomeMapParser<T> parser = new BiomeMapParser<>(key, valueConverter);
parser.setLenient(isLenient);
parser.read(json);
return parser.buildBiomeMap();
}
@ParametersAreNonnullByDefault
public static <T> @Nonnull BiomeMap<T> fromResource(NamespacedKey key, JavaPlugin plugin, String path, BiomeDataConverter<T> valueConverter) throws BiomeMapException {
Validate.notNull(key, "The key shall not be null.");

View File

@ -33,7 +33,7 @@ import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
*
* @see BiomeMap
*/
class BiomeMapParser<T> {
public class BiomeMapParser<T> {
private static final String VALUE_KEY = "value";
private static final String BIOMES_KEY = "biomes";
@ -61,7 +61,7 @@ class BiomeMapParser<T> {
* A function to convert {@link JsonElement}s into your desired data type
*/
@ParametersAreNonnullByDefault
BiomeMapParser(NamespacedKey key, BiomeDataConverter<T> valueConverter) {
public BiomeMapParser(NamespacedKey key, BiomeDataConverter<T> valueConverter) {
Validate.notNull(key, "The key shall not be null.");
Validate.notNull(valueConverter, "You must provide a Function to convert raw json values to your desired data type.");
@ -79,7 +79,7 @@ class BiomeMapParser<T> {
* @param isLenient
* Whether this parser should be lenient or not.
*/
void setLenient(boolean isLenient) {
public void setLenient(boolean isLenient) {
this.isLenient = isLenient;
}
@ -92,11 +92,11 @@ class BiomeMapParser<T> {
*
* @return Whether this parser is lenient or not.
*/
boolean isLenient() {
public boolean isLenient() {
return isLenient;
}
void read(@Nonnull String json) throws BiomeMapException {
public void read(@Nonnull String json) throws BiomeMapException {
Validate.notNull(json, "The JSON string should not be null!");
JsonArray root = null;
@ -113,7 +113,7 @@ class BiomeMapParser<T> {
read(root);
}
void read(@Nonnull JsonArray json) throws BiomeMapException {
public void read(@Nonnull JsonArray json) throws BiomeMapException {
Validate.notNull(json, "The JSON Array should not be null!");
for (JsonElement element : json) {
@ -200,7 +200,7 @@ class BiomeMapParser<T> {
* @return The resulting {@link BiomeMap}
*/
@Nonnull
BiomeMap<T> buildBiomeMap() {
public BiomeMap<T> buildBiomeMap() {
BiomeMap<T> biomeMap = new BiomeMap<>(key);
biomeMap.putAll(map);
return biomeMap;