SOLVED. I just used a different namespace to store the different classes so it didn't conflict with each other. I don't know what exactly the problem was, but it's gone now! yppee!
I'm having a casting error and I have no clue why this happens.
This is occurring at the deserialization of a custom persistent data storage container.
The class that is being deserialized is a child of the class that I'm trying to cast from - except I have no clue why my deserialization is returning the parent class instead of the child class, and why the cast from parent to child is not working.
VASCraftEntityStat extends LivingEntityStat
This is the code where the issue occurs:
I'm having a casting error and I have no clue why this happens.
This is occurring at the deserialization of a custom persistent data storage container.
The class that is being deserialized is a child of the class that I'm trying to cast from - except I have no clue why my deserialization is returning the parent class instead of the child class, and why the cast from parent to child is not working.
VASCraftEntityStat extends LivingEntityStat
Java:
[13:02:32 ERROR]: Could not pass event EntityDamageByEntityEvent to VASCraft v1.0-SNAPSHOT
java.lang.ClassCastException: class me.alexhayato.vascraft.StatWorkings.LivingEntityStat cannot be cast to class me.alexhayato.vascraft.StatWorkings.VASCraftEntityStat (me.alexhayato.vascraft.StatWorkings.LivingEntityStat and me.alexhayato.vascraft.StatWorkings.VASCraftEntityStat are in unnamed module of loader 'VASCraft.jar' @49aac716)
at VASCraft.jar/me.alexhayato.vascraft.StatWorkings.VASCraftEntityDataType.fromPrimitive(VASCraftEntityDataType.java:52) ~[VASCraft.jar:?]
at VASCraft.jar/me.alexhayato.vascraft.StatWorkings.VASCraftEntityDataType.fromPrimitive(VASCraftEntityDataType.java:16) ~[VASCraft.jar:?]
at org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer.get(CraftPersistentDataContainer.java:74) ~[paper-1.20.6.jar:1.20.6-134-4f13be9]
This is the code where the issue occurs:
Java:
InputStream is = new ByteArrayInputStream(primitive);
ObjectInputStream o = new ObjectInputStream(is);
//error here:
return (VASCraftEntityStat) o.readObject();
Java:
public class VASCraftEntityDataType implements PersistentDataType<byte[], VASCraftEntityStat> {
@Override
public @NotNull Class<byte[]> getPrimitiveType() {
return byte[].class;
}
@Override
public @NotNull Class<VASCraftEntityStat> getComplexType() {
return VASCraftEntityStat.class;
}
@Override
public byte @NotNull [] toPrimitive(@NotNull VASCraftEntityStat complex, @NotNull PersistentDataAdapterContext context) {
return SerializationUtils.serialize(complex);
}
@Override
public @NotNull VASCraftEntityStat fromPrimitive(byte @NotNull [] primitive, @NotNull PersistentDataAdapterContext context) {
try{
InputStream is = new ByteArrayInputStream(primitive);
ObjectInputStream o = new ObjectInputStream(is);
return (VASCraftEntityStat) o.readObject();
}
catch(IOException | ClassNotFoundException e){
e.printStackTrace();
Bukkit.getLogger().info("ERROR WITH DESERIALIZATION (fromPrimitive) ");
}
return null;
}
}
Last edited: