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 /src/main/java/org | |
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)
Diffstat (limited to 'src/main/java/org')
4 files changed, 47 insertions, 18 deletions
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; + } +} |