Fix NPE in PlayerInfoData equals

Fixes #1400
Closes #1106
This commit is contained in:
Dan Mulloy 2021-11-14 00:41:20 -05:00
parent 8774d87d59
commit dd687ce175
No known key found for this signature in database
GPG Key ID: BFACD592A5F0DFD6

View File

@ -19,6 +19,7 @@ package com.comphenix.protocol.wrappers;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.reflect.EquivalentConverter; import com.comphenix.protocol.reflect.EquivalentConverter;
@ -26,7 +27,6 @@ import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
import com.google.common.base.Objects;
/** /**
* Represents an immutable PlayerInfoData in the PLAYER_INFO packet. * Represents an immutable PlayerInfoData in the PLAYER_INFO packet.
@ -176,19 +176,19 @@ public class PlayerInfoData {
if (obj instanceof PlayerInfoData) { if (obj instanceof PlayerInfoData) {
PlayerInfoData other = (PlayerInfoData) obj; PlayerInfoData other = (PlayerInfoData) obj;
return profile.equals(other.profile) && latency == other.latency && gameMode == other.gameMode return profile.equals(other.profile) && latency == other.latency && gameMode == other.gameMode
&& displayName.equals(other.displayName); && Objects.equals(displayName, other.displayName);
} }
return false; return false;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(latency, gameMode, profile, displayName); return Objects.hash(latency, gameMode, profile, displayName);
} }
@Override @Override
public String toString() { public String toString() {
return String.format("PlayerInfoData[latency=%s, gameMode=%s, profile=%s, displayName=%s", return String.format("PlayerInfoData[latency=%s, gameMode=%s, profile=%s, displayName=%s]",
latency, gameMode, profile, displayName); latency, gameMode, profile, displayName);
} }
} }