mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-30 13:13:45 +01:00
Fixed backwards compatibility with entity serialization
This commit is contained in:
parent
06208a69b0
commit
9aea18749d
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ public final class EntityDeathListener extends Queue implements Listener {
|
||||
}
|
||||
else if (entity instanceof Cat) {
|
||||
Cat cat = (Cat) entity;
|
||||
info.add(cat.getCatType().getKey().asString());
|
||||
info.add(BukkitAdapter.ADAPTER.getRegistryKey(cat.getCatType()));
|
||||
info.add(cat.getCollarColor());
|
||||
}
|
||||
else if (entity instanceof Fox) {
|
||||
@ -404,8 +404,8 @@ public final class EntityDeathListener extends Queue implements Listener {
|
||||
|
||||
if (abstractVillager instanceof Villager) {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
info.add(villager.getProfession().getKey().asString());
|
||||
info.add(villager.getVillagerType().getKey().asString());
|
||||
info.add(BukkitAdapter.ADAPTER.getRegistryKey(villager.getProfession()));
|
||||
info.add(BukkitAdapter.ADAPTER.getRegistryKey(villager.getVillagerType()));
|
||||
info.add(recipes);
|
||||
info.add(villager.getVillagerLevel());
|
||||
info.add(villager.getVillagerExperience());
|
||||
@ -433,7 +433,7 @@ public final class EntityDeathListener extends Queue implements Listener {
|
||||
else if (entity instanceof ZombieVillager) {
|
||||
ZombieVillager zombieVillager = (ZombieVillager) entity;
|
||||
info.add(zombieVillager.isBaby());
|
||||
info.add(zombieVillager.getVillagerProfession().getKey().asString());
|
||||
info.add(BukkitAdapter.ADAPTER.getRegistryKey(zombieVillager.getVillagerProfession()));
|
||||
}
|
||||
else if (entity instanceof Zombie) {
|
||||
Zombie zombie = (Zombie) entity;
|
||||
|
@ -7,7 +7,6 @@ import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.attribute.Attributable;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@ -233,9 +232,7 @@ public class EntityUtil {
|
||||
Cat cat = (Cat) entity;
|
||||
if (count == 0) {
|
||||
if (value instanceof String) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
|
||||
value = Bukkit.getRegistry(Cat.Type.class).get(namespacedKey);
|
||||
// value = RegistryAccess.registryAccess().getRegistry(RegistryKey.CAT_VARIANT).get((NamespacedKey)value);
|
||||
value = BukkitAdapter.ADAPTER.getRegistryValue((String) value, Cat.Type.class);
|
||||
}
|
||||
Cat.Type set = (Cat.Type) value;
|
||||
cat.setCatType(set);
|
||||
@ -334,8 +331,7 @@ public class EntityUtil {
|
||||
if (abstractVillager instanceof Villager) {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
if (value instanceof String) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
|
||||
value = Bukkit.getRegistry(Profession.class).get(namespacedKey);
|
||||
value = BukkitAdapter.ADAPTER.getRegistryValue((String) value, Profession.class);
|
||||
}
|
||||
Profession set = (Profession) value;
|
||||
villager.setProfession(set);
|
||||
@ -345,8 +341,7 @@ public class EntityUtil {
|
||||
if (abstractVillager instanceof Villager && value instanceof Villager.Type) {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
if (value instanceof String) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
|
||||
value = Bukkit.getRegistry(Villager.Type.class).get(namespacedKey);
|
||||
value = BukkitAdapter.ADAPTER.getRegistryValue((String) value, Villager.Type.class);
|
||||
}
|
||||
Villager.Type set = (Villager.Type) value;
|
||||
villager.setVillagerType(set);
|
||||
@ -442,8 +437,7 @@ public class EntityUtil {
|
||||
}
|
||||
else if (count == 1) {
|
||||
if (value instanceof String) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
|
||||
value = Bukkit.getRegistry(Profession.class).get(namespacedKey);
|
||||
value = BukkitAdapter.ADAPTER.getRegistryValue((String) value, Profession.class);
|
||||
}
|
||||
Profession set = (Profession) value;
|
||||
zombieVillager.setVillagerProfession(set);
|
||||
|
Loading…
Reference in New Issue
Block a user