Implement some more generic types to make the player objects easier to work with and also create wrapper objects for fake players (NPCs). Potentially fixes PS-27

This commit is contained in:
Alexander Söderberg
2020-05-27 14:08:48 +02:00
parent edbacb8e47
commit 6442922d86
88 changed files with 203 additions and 155 deletions

View File

@ -63,12 +63,11 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.CREATIVE;
import static com.sk89q.worldedit.world.gamemode.GameModes.SPECTATOR;
import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL;
public class BukkitPlayer extends PlotPlayer {
public class BukkitPlayer extends PlotPlayer<Player> {
private static boolean CHECK_EFFECTIVE = true;
public final Player player;
private boolean offline;
private UUID uuid;
private String name;
/**
@ -78,20 +77,29 @@ public class BukkitPlayer extends PlotPlayer {
* @param player Bukkit player instance
*/
public BukkitPlayer(@NotNull final Player player) {
this.player = player;
super.populatePersistentMetaMap();
this(player, false);
}
public BukkitPlayer(@NotNull final Player player, final boolean offline) {
this(player, offline, true);
}
public BukkitPlayer(@NotNull final Player player, final boolean offline, final boolean realPlayer) {
this.player = player;
this.offline = offline;
super.populatePersistentMetaMap();
if (realPlayer) {
super.populatePersistentMetaMap();
}
}
@Override public Actor toActor() {
return BukkitAdapter.adapt(player);
}
@Override public Player getPlatformPlayer() {
return this.player;
}
@NotNull @Override public Location getLocation() {
final Location location = super.getLocation();
return location == null ? BukkitUtil.getLocation(this.player) : location;

View File

@ -36,7 +36,15 @@ import java.util.UUID;
/**
* Player manager providing {@link BukkitPlayer Bukkit players}
*/
public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, BukkitOfflinePlayer> {
public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
@NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) {
try {
return getPlayer(object.getUniqueId());
} catch (final NoSuchPlayerException exception) {
return new BukkitPlayer(object, object.isOnline(), false);
}
}
@Override @NotNull public BukkitPlayer createPlayer(@NotNull final UUID uuid) {
final Player player = Bukkit.getPlayer(uuid);