From 13d2ae20d51b21aad7a1fd6fe29f54d75b1538db Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 15 Aug 2018 17:02:17 +1000 Subject: [PATCH] Make end tag singleton --- .../com/boydti/fawe/bukkit/adapter/Spigot_v1_13_R1.java | 2 +- .../src/main/java/com/boydti/fawe/FaweCache.java | 2 +- .../src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java | 8 +++++++- worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java | 3 +++ .../src/main/java/com/sk89q/jnbt/NBTInputStream.java | 2 +- .../main/java/com/sk89q/worldedit/forge/NBTConverter.java | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/Spigot_v1_13_R1.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/Spigot_v1_13_R1.java index f66060e8c..414ecee22 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/Spigot_v1_13_R1.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/Spigot_v1_13_R1.java @@ -399,7 +399,7 @@ public final class Spigot_v1_13_R1 implements BukkitImplAdapter { } else if (foreign instanceof NBTTagString) { return new StringTag(foreign.b_()); // data } else if (foreign instanceof NBTTagEnd) { - return new EndTag(); + return EndTag.INSTANCE; } else { throw new IllegalArgumentException("Don't know how to make native " + foreign.getClass().getCanonicalName()); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java index 41c0c23ce..44301147b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -174,7 +174,7 @@ public class FaweCache { if (clazz.getName().startsWith("com.intellectualcrafters.jnbt")) { try { if (clazz.getName().equals("com.intellectualcrafters.jnbt.EndTag")) { - return new EndTag(); + return EndTag.INSTANCE; } Field field = clazz.getDeclaredField("value"); field.setAccessible(true); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java index 47c0d373f..e9379b390 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/NBTStreamer.java @@ -6,18 +6,24 @@ import com.boydti.fawe.object.exception.FaweException; import com.sk89q.jnbt.NBTInputStream; import java.io.IOException; import java.util.HashMap; +import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; public class NBTStreamer { private final NBTInputStream is; - private final HashMap readers; + private final Map readers; public NBTStreamer(NBTInputStream stream) { this.is = stream; readers = new HashMap<>(); } + public NBTStreamer(NBTInputStream stream, Map readers) { + this.is = stream; + this.readers = readers; + } + /** * Reads the entire stream and runs the applicable readers * diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java b/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java index e5dd2279a..3674740de 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/EndTag.java @@ -23,6 +23,9 @@ package com.sk89q.jnbt; * The {@code TAG_End} tag. */ public final class EndTag extends Tag { + public static final EndTag INSTANCE = new EndTag(); + + private EndTag() {} @Override public Object getValue() { diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java index b8034efed..c4fdf10ec 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTInputStream.java @@ -526,7 +526,7 @@ public final class NBTInputStream implements Closeable { throw new IOException( "TAG_End found without a TAG_Compound/TAG_List tag preceding it."); } else { - return new EndTag(); + return EndTag.INSTANCE; } case NBTConstants.TYPE_BYTE: return new ByteTag(is.readByte()); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/NBTConverter.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/NBTConverter.java index 0992d3d4f..7773845ed 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/NBTConverter.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/NBTConverter.java @@ -217,7 +217,7 @@ final class NBTConverter { } public static EndTag fromNative(NBTTagEnd other) { - return new EndTag(); + return EndTag.INSTANCE; } public static LongTag fromNative(NBTTagLong other) {