NullPointerException when interacting with a proxy.
Summary
Interacting with an NPC via a proxy (unintentionally) while the proxy's owner is in another dimension crashes the server.
Steps to reproduce
Create's Deployer attempted to interact with a wandering NPC while the player was in another dimension.
What is the current bug behavior?
When a TrainerMob calls startBattleWith(), it attempts to grab the realPlayer from the parameter player's level. If they do not match, it logs a warning. However, the warning assumes the realPlayer was found and calls for its display name, which will crash the server if realPlayer is null (due to the real player being in another dimension).
var realPlayer = player.level().getPlayerByUUID(player.getUUID());
ModCommon.LOG.warn(String.format("attempt to start battle against '%s' with proxy '%s' for '%s'", this.getDisplayName().getString(), player.getDisplayName().getString(), realPlayer.getDisplayName().getString()));
What is the expected correct behavior?
The log message should check if the real player is null.
Relevant logs and/or screenshots
java.lang.NullPointerException: Cannot invoke "net.minecraft.world.entity.player.Player.getDisplayName()" because "realPlayer" is null
at TRANSFORMER/rctmod@0.16.8-beta/com.gitlab.srcmc.rctmod.world.entities.TrainerMob.startBattleWith(TrainerMob.java:193) ~[rctmod-neoforge-1.21.1-0.16.8-beta.jar%23578!/:?] {re:classloading}
at TRANSFORMER/rctmod@0.16.8-beta/com.gitlab.srcmc.rctmod.world.entities.TrainerMob.mobInteract(TrainerMob.java:555) ~[rctmod-neoforge-1.21.1-0.16.8-beta.jar%23578!/:?] {re:classloading}
at TRANSFORMER/minecraft@1.21.1/net.minecraft.world.entity.Mob.mixinextras$bridge$mobInteract$175(Mob.java) ~[server-1.21.1-20240808.144430-srg.jar%23380!/:?]