Attempting to set one of a villager's memories to null using LivingEntity#setMemory throws the following UnsupportedOperationException:
Caused by: java.lang.UnsupportedOperationException: Do not know how to map null
at org.bukkit.craftbukkit.v1_14_R1.entity.memory.CraftMemoryMapper.toNms(CraftMemoryMapper.java:29) ~[spigot.jar:git-Spigot-df0eb25-8003ced]
at org.bukkit.craftbukkit.v1_14_R1.entity.CraftLivingEntity.setMemory(CraftLivingEntity.java:596) ~[spigot.jar:git-Spigot-df0eb25-8003ced]
See attached txt file for full error when using TestPlugin.jar.
This is despite the second argument of LivingEntity#setMemory being annotated as Nullable. Something else to note is that egg-spawned or summoned villagers have all memories null by default, so it should definitely be possible to do this.
Reproducing:
- Install attached TestPlugin.jar on a 1.14.2 spigot server.
- Create a world and spawn a villager using a spawn egg or /summon command.
- Right click the villager, and the error should appear in the console.
Test plugin source code:
public class TestPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { Bukkit.getPluginManager().registerEvents(this, this); } @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if(event.getRightClicked() instanceof Villager) { ((Villager) event.getRightClicked()).setMemory(MemoryKey.HOME, null); } } }
The same error occurs when MemoryKey.HOME is replaced with MemoryKey.JOB_SITE or MemoryKey.MEETING_POINT.