forked from zhdev/griefus
Fixed backwards compatibility with entity serialization
This commit is contained in:
parent
06208a69b0
commit
9aea18749d
6 changed files with 40 additions and 19 deletions
|
|
@ -298,4 +298,14 @@ public class BukkitAdapter implements BukkitInterface {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRegistryKey(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRegistryValue(String key, Object tClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,4 +89,8 @@ public interface BukkitInterface {
|
|||
|
||||
public EntityType getEntityType(Material material);
|
||||
|
||||
public Object getRegistryKey(Object value);
|
||||
|
||||
public Object getRegistryValue(String key, Object tClass);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Frog;
|
||||
import org.bukkit.entity.Goat;
|
||||
|
|
@ -33,7 +31,7 @@ public class Bukkit_v1_19 extends Bukkit_v1_18 implements BukkitInterface {
|
|||
public boolean getEntityMeta(LivingEntity entity, List<Object> info) {
|
||||
if (entity instanceof Frog) {
|
||||
Frog frog = (Frog) entity;
|
||||
info.add(frog.getVariant().getKey().asString());
|
||||
info.add(BukkitAdapter.ADAPTER.getRegistryKey(frog.getVariant()));
|
||||
}
|
||||
else if (entity instanceof Tadpole) {
|
||||
Tadpole tadpole = (Tadpole) entity;
|
||||
|
|
@ -61,8 +59,7 @@ public class Bukkit_v1_19 extends Bukkit_v1_18 implements BukkitInterface {
|
|||
Frog frog = (Frog) entity;
|
||||
if (count == 0) {
|
||||
if (value instanceof String) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
|
||||
value = Bukkit.getRegistry(Frog.Variant.class).get(namespacedKey);
|
||||
value = BukkitAdapter.ADAPTER.getRegistryValue((String) value, Frog.Variant.class);
|
||||
}
|
||||
Frog.Variant set = (Frog.Variant) value;
|
||||
frog.setVariant(set);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ package net.coreprotect.bukkit;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
|
|
@ -40,4 +43,17 @@ public class Bukkit_v1_21 extends Bukkit_v1_20 implements BukkitInterface {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRegistryKey(Object value) {
|
||||
return ((Keyed) value).getKey().asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRegistryValue(String key, Object tClass) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString(key);
|
||||
// return RegistryAccess.registryAccess().getRegistry(RegistryKey.CAT_VARIANT).get((NamespacedKey)value);
|
||||
return Bukkit.getRegistry((Class) tClass).get(namespacedKey);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue