Fixed NotSerializableException when killing certain entities (fixes #589)

This commit is contained in:
Intelli 2024-07-23 20:06:18 -06:00
parent 77a4a9476a
commit a93bf2f047
3 changed files with 29 additions and 5 deletions

View File

@ -4,7 +4,9 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Frog; import org.bukkit.entity.Frog;
import org.bukkit.entity.Goat; import org.bukkit.entity.Goat;
@ -31,7 +33,7 @@ public class Bukkit_v1_19 extends Bukkit_v1_18 implements BukkitInterface {
public boolean getEntityMeta(LivingEntity entity, List<Object> info) { public boolean getEntityMeta(LivingEntity entity, List<Object> info) {
if (entity instanceof Frog) { if (entity instanceof Frog) {
Frog frog = (Frog) entity; Frog frog = (Frog) entity;
info.add(frog.getVariant()); info.add(frog.getVariant().getKey().asString());
} }
else if (entity instanceof Tadpole) { else if (entity instanceof Tadpole) {
Tadpole tadpole = (Tadpole) entity; Tadpole tadpole = (Tadpole) entity;
@ -58,6 +60,10 @@ public class Bukkit_v1_19 extends Bukkit_v1_18 implements BukkitInterface {
if (entity instanceof Frog) { if (entity instanceof Frog) {
Frog frog = (Frog) entity; Frog frog = (Frog) entity;
if (count == 0) { if (count == 0) {
if (value instanceof String) {
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
value = Bukkit.getRegistry(Frog.Variant.class).get(namespacedKey);
}
Frog.Variant set = (Frog.Variant) value; Frog.Variant set = (Frog.Variant) value;
frog.setVariant(set); frog.setVariant(set);
} }

View File

@ -322,7 +322,7 @@ public final class EntityDeathListener extends Queue implements Listener {
} }
else if (entity instanceof Cat) { else if (entity instanceof Cat) {
Cat cat = (Cat) entity; Cat cat = (Cat) entity;
info.add(cat.getCatType()); info.add(cat.getCatType().getKey().asString());
info.add(cat.getCollarColor()); info.add(cat.getCollarColor());
} }
else if (entity instanceof Fox) { else if (entity instanceof Fox) {
@ -404,8 +404,8 @@ public final class EntityDeathListener extends Queue implements Listener {
if (abstractVillager instanceof Villager) { if (abstractVillager instanceof Villager) {
Villager villager = (Villager) abstractVillager; Villager villager = (Villager) abstractVillager;
info.add(villager.getProfession()); info.add(villager.getProfession().getKey().asString());
info.add(villager.getVillagerType()); info.add(villager.getVillagerType().getKey().asString());
info.add(recipes); info.add(recipes);
info.add(villager.getVillagerLevel()); info.add(villager.getVillagerLevel());
info.add(villager.getVillagerExperience()); info.add(villager.getVillagerExperience());
@ -433,7 +433,7 @@ public final class EntityDeathListener extends Queue implements Listener {
else if (entity instanceof ZombieVillager) { else if (entity instanceof ZombieVillager) {
ZombieVillager zombieVillager = (ZombieVillager) entity; ZombieVillager zombieVillager = (ZombieVillager) entity;
info.add(zombieVillager.isBaby()); info.add(zombieVillager.isBaby());
info.add(zombieVillager.getVillagerProfession()); info.add(zombieVillager.getVillagerProfession().getKey().asString());
} }
else if (entity instanceof Zombie) { else if (entity instanceof Zombie) {
Zombie zombie = (Zombie) entity; Zombie zombie = (Zombie) entity;

View File

@ -7,6 +7,7 @@ import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attributable; import org.bukkit.attribute.Attributable;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
@ -231,6 +232,11 @@ public class EntityUtil {
else if (entity instanceof Cat) { else if (entity instanceof Cat) {
Cat cat = (Cat) entity; Cat cat = (Cat) entity;
if (count == 0) { 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);
}
Cat.Type set = (Cat.Type) value; Cat.Type set = (Cat.Type) value;
cat.setCatType(set); cat.setCatType(set);
} }
@ -327,6 +333,10 @@ public class EntityUtil {
if (count == 0) { if (count == 0) {
if (abstractVillager instanceof Villager) { if (abstractVillager instanceof Villager) {
Villager villager = (Villager) abstractVillager; Villager villager = (Villager) abstractVillager;
if (value instanceof String) {
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
value = Bukkit.getRegistry(Profession.class).get(namespacedKey);
}
Profession set = (Profession) value; Profession set = (Profession) value;
villager.setProfession(set); villager.setProfession(set);
} }
@ -334,6 +344,10 @@ public class EntityUtil {
else if (count == 1) { else if (count == 1) {
if (abstractVillager instanceof Villager && value instanceof Villager.Type) { if (abstractVillager instanceof Villager && value instanceof Villager.Type) {
Villager villager = (Villager) abstractVillager; Villager villager = (Villager) abstractVillager;
if (value instanceof String) {
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
value = Bukkit.getRegistry(Villager.Type.class).get(namespacedKey);
}
Villager.Type set = (Villager.Type) value; Villager.Type set = (Villager.Type) value;
villager.setVillagerType(set); villager.setVillagerType(set);
} }
@ -427,6 +441,10 @@ public class EntityUtil {
zombieVillager.setBaby(set); zombieVillager.setBaby(set);
} }
else if (count == 1) { else if (count == 1) {
if (value instanceof String) {
NamespacedKey namespacedKey = NamespacedKey.fromString((String) value);
value = Bukkit.getRegistry(Profession.class).get(namespacedKey);
}
Profession set = (Profession) value; Profession set = (Profession) value;
zombieVillager.setVillagerProfession(set); zombieVillager.setVillagerProfession(set);
} }