Skip to content

Commit

Permalink
Add equals and hashCode functions for Player class (#629)
Browse files Browse the repository at this point in the history
* Add `equals` and `hashCode` functions for Player class

* Fix up the extending classes
  • Loading branch information
TechnicJelle authored Dec 8, 2024
1 parent 124cbc6 commit 7200e94
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,60 @@

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;
}

/**
* 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7200e94

Please sign in to comment.