From 390155e03bd4dc48feebfd2958084449b2d40408 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 16 Nov 2021 13:15:27 +0100 Subject: [PATCH] Make Mappings extendable --- .../viaversion/viaversion/api/data/IntArrayMappings.java | 6 +++++- .../java/com/viaversion/viaversion/api/data/Mappings.java | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/IntArrayMappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/IntArrayMappings.java index 2c8541384..a23357c0c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/IntArrayMappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/IntArrayMappings.java @@ -32,11 +32,15 @@ public class IntArrayMappings implements Mappings { private final int[] oldToNew; private final int mappedIds; - private IntArrayMappings(int[] oldToNew, int mappedIds) { + protected IntArrayMappings(final int[] oldToNew, final int mappedIds) { this.oldToNew = oldToNew; this.mappedIds = mappedIds; } + public static IntArrayMappings of(final int[] oldToNew, final int mappedIds) { + return new IntArrayMappings(oldToNew, mappedIds); + } + public static Builder builder() { return Mappings.builder(IntArrayMappings::new); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java index b682df578..b05f8e4c9 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java @@ -70,7 +70,7 @@ public interface Mappings { T supply(int[] mappings, int mappedIds); } - final class Builder { + class Builder { private final MappingsSupplier supplier; private JsonElement unmapped; @@ -80,7 +80,7 @@ public interface Mappings { private int size = -1; private boolean warnOnMissing = true; - private Builder(final MappingsSupplier supplier) { + protected Builder(final MappingsSupplier supplier) { this.supplier = supplier; } @@ -163,11 +163,11 @@ public interface Mappings { return supplier.supply(mappings, mappedSize); } - private int size(final JsonElement element) { + protected int size(final JsonElement element) { return element.isJsonObject() ? element.getAsJsonObject().size() : element.getAsJsonArray().size(); } - private JsonObject toJsonObject(final JsonArray array) { + protected JsonObject toJsonObject(final JsonArray array) { final JsonObject object = new JsonObject(); for (int i = 0; i < array.size(); i++) { final JsonElement element = array.get(i);