adding equals and hashcode in ClientSettings, ClientSettingsWrapper and SkinParts (#765)

* adding equals and hashcode in ClientSettings, ClientSettingsWrapper and SkinParts

* fixing format
This commit is contained in:
foxley
2022-06-23 05:37:38 +02:00
committed by GitHub
parent 93df65fdfb
commit 86c65f3910
3 changed files with 73 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ import com.velocitypowered.api.proxy.player.PlayerSettings;
import com.velocitypowered.api.proxy.player.SkinParts;
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
import java.util.Locale;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientSettingsWrapper implements PlayerSettings {
@@ -79,4 +80,21 @@ public class ClientSettingsWrapper implements PlayerSettings {
return settings.isClientListingAllowed();
}
@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ClientSettingsWrapper that = (ClientSettingsWrapper) o;
return Objects.equals(settings, that.settings) && Objects.equals(parts, that.parts)
&& Objects.equals(locale, that.locale);
}
@Override
public int hashCode() {
return Objects.hash(settings, parts, locale);
}
}

View File

@@ -22,6 +22,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientSettings implements MinecraftPacket {
@@ -190,4 +191,38 @@ public class ClientSettings implements MinecraftPacket {
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
@Override
public boolean equals(@Nullable final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final ClientSettings that = (ClientSettings) o;
return viewDistance == that.viewDistance
&& chatVisibility == that.chatVisibility
&& chatColors == that.chatColors
&& difficulty == that.difficulty
&& skinParts == that.skinParts
&& mainHand == that.mainHand
&& chatFilteringEnabled == that.chatFilteringEnabled
&& clientListingAllowed == that.clientListingAllowed
&& Objects.equals(locale, that.locale);
}
@Override
public int hashCode() {
return Objects.hash(
locale,
viewDistance,
chatVisibility,
chatColors,
difficulty,
skinParts,
mainHand,
chatFilteringEnabled,
clientListingAllowed);
}
}