Add equals and hashCode functions for Player class (#629)

* Add `equals` and `hashCode` functions for Player class

* Fix up the extending classes
This commit is contained in:
TechnicJelle 2024-12-08 19:37:40 +01:00 committed by GitHub
parent 124cbc6db6
commit 7200e94262
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 18 deletions

View File

@ -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 <code>true</code> if the player is sneaking.
* <p><i>If the player is offline the value of this method is undetermined.</i></p>
*/
boolean isSneaking();
public abstract boolean isSneaking();
/**
* Returns <code>true</code> if the player has an invisibillity effect
* <p><i>If the player is offline the value of this method is undetermined.</i></p>
*/
boolean isInvisible();
public abstract boolean isInvisible();
/**
* Returns <code>true</code> if the player is vanished
* <p><i>If the player is offline the value of this method is undetermined.</i></p>
*/
default boolean isVanished() {
public boolean isVanished() {
return false;
}
@ -72,6 +72,17 @@ default boolean isVanished() {
* Returns the {@link Gamemode} this player is in
* <p><i>If the player is offline the value of this method is undetermined.</i></p>
*/
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();
}
}

View File

@ -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<GameMode, Gamemode> GAMEMODE_MAP = new EnumMap<>(GameMode.class);
static {

View File

@ -42,7 +42,7 @@
import java.util.Map;
import java.util.UUID;
public class ForgePlayer implements Player {
public class ForgePlayer extends Player {
private static final Map<GameType, Gamemode> GAMEMODE_MAP = new EnumMap<>(GameType.class);
static {

View File

@ -42,7 +42,7 @@
import java.util.Map;
import java.util.UUID;
public class ForgePlayer implements Player {
public class ForgePlayer extends Player {
private static final Map<GameType, Gamemode> GAMEMODE_MAP = new EnumMap<>(GameType.class);
static {

View File

@ -38,7 +38,7 @@
import java.util.*;
public class BukkitPlayer implements Player {
public class BukkitPlayer extends Player {
private static final Map<GameMode, Gamemode> GAMEMODE_MAP = new EnumMap<>(GameMode.class);
static {

View File

@ -39,7 +39,7 @@
import java.util.Map;
import java.util.UUID;
public class BukkitPlayer implements Player {
public class BukkitPlayer extends Player {
private static final Map<GameMode, Gamemode> GAMEMODE_MAP = new EnumMap<>(GameMode.class);
static {

View File

@ -41,7 +41,7 @@
import java.util.*;
public class SpongePlayer implements Player {
public class SpongePlayer extends Player {
private static final Map<GameMode, Gamemode> GAMEMODE_MAP = new HashMap<>(5);
static {