From 7200e9426267acce869a4862d57301d9b2f4dfdc Mon Sep 17 00:00:00 2001
From: TechnicJelle <22576047+TechnicJelle@users.noreply.github.com>
Date: Sun, 8 Dec 2024 19:37:40 +0100
Subject: [PATCH] Add `equals` and `hashCode` functions for Player class (#629)
* Add `equals` and `hashCode` functions for Player class
* Fix up the extending classes
---
.../common/serverinterface/Player.java | 35 ++++++++++++-------
.../bluemap/fabric/FabricPlayer.java | 2 +-
.../bluemap/forge/ForgePlayer.java | 2 +-
.../bluemap/forge/ForgePlayer.java | 2 +-
.../bluemap/bukkit/BukkitPlayer.java | 2 +-
.../bluemap/bukkit/BukkitPlayer.java | 2 +-
.../bluemap/sponge/SpongePlayer.java | 2 +-
7 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/common/src/main/java/de/bluecolored/bluemap/common/serverinterface/Player.java b/common/src/main/java/de/bluecolored/bluemap/common/serverinterface/Player.java
index 320f2da4..a5242333 100644
--- a/common/src/main/java/de/bluecolored/bluemap/common/serverinterface/Player.java
+++ b/common/src/main/java/de/bluecolored/bluemap/common/serverinterface/Player.java
@@ -29,42 +29,42 @@
import java.util.UUID;
-public interface Player {
+public abstract class Player {
- UUID getUuid();
+ public abstract UUID getUuid();
- Text getName();
+ public abstract Text getName();
- ServerWorld getWorld();
+ public abstract ServerWorld getWorld();
- Vector3d getPosition();
+ public abstract Vector3d getPosition();
/**
* x -> pitch, y -> yaw, z -> roll
*/
- Vector3d getRotation();
+ public abstract Vector3d getRotation();
- int getSkyLight();
+ public abstract int getSkyLight();
- int getBlockLight();
+ public abstract int getBlockLight();
/**
* Return true
if the player is sneaking.
*
If the player is offline the value of this method is undetermined.
*/ - boolean isSneaking(); + public abstract boolean isSneaking(); /** * Returnstrue
if the player has an invisibillity effect
* If the player is offline the value of this method is undetermined.
*/ - boolean isInvisible(); + public abstract boolean isInvisible(); /** * Returnstrue
if the player is vanished
* If the player is offline the value of this method is undetermined.
*/ - default boolean isVanished() { + public boolean isVanished() { return false; } @@ -72,6 +72,17 @@ default boolean isVanished() { * Returns the {@link Gamemode} this player is in *If the player is offline the value of this method is undetermined.
*/ - Gamemode getGamemode(); + public abstract Gamemode getGamemode(); + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) return false; + Player other = (Player) o; + return getUuid().equals(other.getUuid()); + } + + @Override + public int hashCode() { + return getUuid().hashCode(); + } } diff --git a/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java b/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java index 692256dd..d54169ce 100644 --- a/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java +++ b/implementations/fabric/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java @@ -41,7 +41,7 @@ import java.util.Map; import java.util.UUID; -public class FabricPlayer implements Player { +public class FabricPlayer extends Player { private static final Map