diff options
author | md_5 <git@md-5.net> | 2018-07-28 14:39:35 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-07-28 15:00:12 +1000 |
commit | 212fd0f230cb8eebe43e977f171e147c9d85ac71 (patch) | |
tree | e8a531f5841600c5d10871f13b5bb6687c615567 | |
parent | e3c21decb0bff39ec2e4bb3c95a6554ea3755609 (diff) | |
download | craftbukkit-212fd0f230cb8eebe43e977f171e147c9d85ac71.tar craftbukkit-212fd0f230cb8eebe43e977f171e147c9d85ac71.tar.gz craftbukkit-212fd0f230cb8eebe43e977f171e147c9d85ac71.tar.lz craftbukkit-212fd0f230cb8eebe43e977f171e147c9d85ac71.tar.xz craftbukkit-212fd0f230cb8eebe43e977f171e147c9d85ac71.zip |
SPIGOT-4166: Fix Tags being corrupted by early access (and not reflecting reloads)
-rw-r--r-- | nms-patches/TagRegistry.patch | 14 | ||||
-rw-r--r-- | nms-patches/TagsServer.patch | 28 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftServer.java | 6 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java | 15 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java | 15 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java | 29 |
6 files changed, 89 insertions, 18 deletions
diff --git a/nms-patches/TagRegistry.patch b/nms-patches/TagRegistry.patch new file mode 100644 index 00000000..e4dafa6a --- /dev/null +++ b/nms-patches/TagRegistry.patch @@ -0,0 +1,14 @@ +--- a/net/minecraft/server/TagRegistry.java ++++ b/net/minecraft/server/TagRegistry.java +@@ -38,6 +38,11 @@ + TagsBlock.a((Tags) this.a); + TagsItem.a((Tags) this.b); + TagsFluid.a((Tags) this.c); ++ // CraftBukkit start ++ this.a.version++; ++ this.b.version++; ++ this.c.version++; ++ // CraftBukkit end + } + + public void a(PacketDataSerializer packetdataserializer) { diff --git a/nms-patches/TagsServer.patch b/nms-patches/TagsServer.patch new file mode 100644 index 00000000..b5ed85d1 --- /dev/null +++ b/nms-patches/TagsServer.patch @@ -0,0 +1,28 @@ +--- a/net/minecraft/server/TagsServer.java ++++ b/net/minecraft/server/TagsServer.java +@@ -11,6 +11,7 @@ + public class TagsServer<T> extends Tags<T> { + + private final RegistryMaterials<MinecraftKey, T> a; ++ public int version; // CraftBukkit + + public TagsServer(RegistryMaterials<MinecraftKey, T> registrymaterials, String s, String s1) { + super(registrymaterials::d, registrymaterials::get, s, false, s1); +@@ -31,7 +32,7 @@ + while (iterator1.hasNext()) { + Object object = iterator1.next(); + +- packetdataserializer.d(this.a.a(object)); ++ packetdataserializer.d(this.a.a((T) object)); // CraftBukkit - decompile error + } + } + +@@ -49,7 +50,7 @@ + arraylist.add(this.a.getId(packetdataserializer.g())); + } + +- this.c().put(minecraftkey, Tag.a.a().a((Collection) arraylist).b(minecraftkey)); ++ this.c().put(minecraftkey, (Tag<T>) Tag.a.a().a((Collection) arraylist).b(minecraftkey)); // CraftBukkit - decompile error + } + + } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 61d9fa33..abc08ed3 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1749,15 +1749,17 @@ public final class CraftServer implements Server { @Override @SuppressWarnings("unchecked") public <T extends Keyed> org.bukkit.Tag<T> getTag(String registry, NamespacedKey tag, Class<T> clazz) { + MinecraftKey key = CraftNamespacedKey.toMinecraft(tag); + switch (registry) { case org.bukkit.Tag.REGISTRY_BLOCKS: Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Block namespace must have material type"); - return (org.bukkit.Tag<T>) new CraftBlockTag(console.getTagRegistry().a().b(CraftNamespacedKey.toMinecraft(tag))); + return (org.bukkit.Tag<T>) new CraftBlockTag(console.getTagRegistry().a(), key); case org.bukkit.Tag.REGISTRY_ITEMS: Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace must have material type"); - return (org.bukkit.Tag<T>) new CraftItemTag(console.getTagRegistry().b().b(CraftNamespacedKey.toMinecraft(tag))); + return (org.bukkit.Tag<T>) new CraftItemTag(console.getTagRegistry().b(), key); default: throw new IllegalArgumentException(); } diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java index 4b3ac51a..2fe308d9 100644 --- a/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java +++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftBlockTag.java @@ -4,25 +4,24 @@ import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import net.minecraft.server.Block; +import net.minecraft.server.MinecraftKey; +import net.minecraft.server.TagsServer; import org.bukkit.Material; -import org.bukkit.Tag; import org.bukkit.craftbukkit.util.CraftMagicNumbers; -public class CraftBlockTag implements Tag<Material> { +public class CraftBlockTag extends CraftTag<Block, Material> { - private final net.minecraft.server.Tag<Block> handle; - - public CraftBlockTag(net.minecraft.server.Tag<Block> handle) { - this.handle = handle; + public CraftBlockTag(TagsServer<Block> registry, MinecraftKey tag) { + super(registry, tag); } @Override public boolean isTagged(Material item) { - return handle.isTagged(CraftMagicNumbers.getBlock(item)); + return getHandle().isTagged(CraftMagicNumbers.getBlock(item)); } @Override public Set<Material> getValues() { - return Collections.unmodifiableSet(handle.a().stream().map((block) -> CraftMagicNumbers.getMaterial(block)).collect(Collectors.toSet())); + return Collections.unmodifiableSet(getHandle().a().stream().map((block) -> CraftMagicNumbers.getMaterial(block)).collect(Collectors.toSet())); } } diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java index b6b90e3e..4a1a4525 100644 --- a/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java +++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftItemTag.java @@ -4,25 +4,24 @@ import java.util.Collections; import java.util.Set; import java.util.stream.Collectors; import net.minecraft.server.Item; +import net.minecraft.server.MinecraftKey; +import net.minecraft.server.TagsServer; import org.bukkit.Material; -import org.bukkit.Tag; import org.bukkit.craftbukkit.util.CraftMagicNumbers; -public class CraftItemTag implements Tag<Material> { +public class CraftItemTag extends CraftTag<Item, Material> { - private final net.minecraft.server.Tag<Item> handle; - - public CraftItemTag(net.minecraft.server.Tag<Item> handle) { - this.handle = handle; + public CraftItemTag(TagsServer<Item> registry, MinecraftKey tag) { + super(registry, tag); } @Override public boolean isTagged(Material item) { - return handle.isTagged(CraftMagicNumbers.getItem(item)); + return getHandle().isTagged(CraftMagicNumbers.getItem(item)); } @Override public Set<Material> getValues() { - return Collections.unmodifiableSet(handle.a().stream().map((item) -> CraftMagicNumbers.getMaterial(item)).collect(Collectors.toSet())); + return Collections.unmodifiableSet(getHandle().a().stream().map((item) -> CraftMagicNumbers.getMaterial(item)).collect(Collectors.toSet())); } } diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java new file mode 100644 index 00000000..39f157ff --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java @@ -0,0 +1,29 @@ +package org.bukkit.craftbukkit.tag; + +import net.minecraft.server.MinecraftKey; +import net.minecraft.server.TagsServer; +import org.bukkit.Keyed; +import org.bukkit.Tag; + +public abstract class CraftTag<N, B extends Keyed> implements Tag<B> { + + private final net.minecraft.server.TagsServer<N> registry; + private final MinecraftKey tag; + // + private int version = -1; + private net.minecraft.server.Tag<N> handle; + + public CraftTag(TagsServer<N> registry, MinecraftKey tag) { + this.registry = registry; + this.tag = tag; + } + + protected net.minecraft.server.Tag<N> getHandle() { + if (version != registry.version) { + handle = registry.b(tag); + version = registry.version; + } + + return handle; + } +} |