SPIGOT-4166: Fix Tags being corrupted by early access (and not reflecting reloads)

This commit is contained in:
md_5 2018-07-28 14:39:35 +10:00
parent e3c21decb0
commit 212fd0f230
6 changed files with 89 additions and 18 deletions

View file

@ -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) {

View file

@ -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
}
}

View file

@ -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();
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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;
}
}