Verified Commit 98c43a88 authored by Yannick Schinko's avatar Yannick Schinko
Browse files

Handle not existing players

parent 63c26118
......@@ -7,10 +7,6 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
public class PlayerDataBungeeCord extends PlayerDataCommon {
public PlayerDataBungeeCord(@Nonnull UUID uuid) {
super(uuid, getPlayerFromUUID(uuid).getName());
}
public PlayerDataBungeeCord(@Nonnull UUID uuid, @Nonnull String playerName) {
super(uuid, playerName);
}
......@@ -21,7 +17,7 @@ public class PlayerDataBungeeCord extends PlayerDataCommon {
return getPlayerFromUUID(uuid).getDisplayName();
}
private static ProxiedPlayer getPlayerFromUUID(UUID uuid) {
public static ProxiedPlayer getPlayerFromUUID(UUID uuid) {
return ProxyServer.getInstance().getPlayer(uuid);
}
}
......@@ -12,7 +12,8 @@ import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerBungeeCord extends PlayerManagerCommon {
@Override
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataBungeeCord(uuid));
return Optional.ofNullable(PlayerDataBungeeCord.getPlayerFromUUID(uuid))
.map(player -> new PlayerDataBungeeCord(uuid, player.getName()));
}
@Nonnull
......
......@@ -2,15 +2,12 @@ package team.aura_dev.aurasudo.platform.nukkit.player;
import cn.nukkit.Server;
import cn.nukkit.player.Player;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
public class PlayerDataNukkit extends PlayerDataCommon {
public PlayerDataNukkit(@Nonnull UUID uuid) {
super(uuid, getPlayerFromUUID(uuid).getName());
}
public PlayerDataNukkit(@Nonnull UUID uuid, @Nonnull String playerName) {
super(uuid, playerName);
}
......@@ -18,10 +15,10 @@ public class PlayerDataNukkit extends PlayerDataCommon {
@Nonnull
@Override
public String getDisplayName() {
return getPlayerFromUUID(uuid).getDisplayName();
return getPlayerFromUUID(uuid).get().getDisplayName();
}
private static Player getPlayerFromUUID(UUID uuid) {
return Server.getInstance().getPlayer(uuid).get();
public static Optional<Player> getPlayerFromUUID(UUID uuid) {
return Server.getInstance().getPlayer(uuid);
}
}
......@@ -11,7 +11,8 @@ import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerNukkit extends PlayerManagerCommon {
@Override
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataNukkit(uuid));
return PlayerDataNukkit.getPlayerFromUUID(uuid)
.map(player -> new PlayerDataNukkit(uuid, player.getName()));
}
@Nonnull
......
......@@ -7,10 +7,6 @@ import org.bukkit.entity.Player;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
public class PlayerDataSpigot extends PlayerDataCommon {
public PlayerDataSpigot(@Nonnull UUID uuid) {
super(uuid, getPlayerFromUUID(uuid).getName());
}
public PlayerDataSpigot(@Nonnull UUID uuid, @Nonnull String playerName) {
super(uuid, playerName);
}
......@@ -21,7 +17,7 @@ public class PlayerDataSpigot extends PlayerDataCommon {
return getPlayerFromUUID(uuid).getDisplayName();
}
private static Player getPlayerFromUUID(UUID uuid) {
public static Player getPlayerFromUUID(UUID uuid) {
return Bukkit.getPlayer(uuid);
}
}
......@@ -11,7 +11,8 @@ import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerSpigot extends PlayerManagerCommon {
@Override
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataSpigot(uuid));
return Optional.ofNullable(PlayerDataSpigot.getPlayerFromUUID(uuid))
.map(player -> new PlayerDataSpigot(uuid, player.getName()));
}
@Nonnull
......
package team.aura_dev.aurasudo.platform.sponge.player;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nonnull;
import org.spongepowered.api.Sponge;
......@@ -7,10 +8,6 @@ import org.spongepowered.api.entity.living.player.Player;
import team.aura_dev.aurasudo.platform.common.player.PlayerDataCommon;
public class PlayerDataSponge extends PlayerDataCommon {
public PlayerDataSponge(@Nonnull UUID uuid) {
super(uuid, getPlayerFromUUID(uuid).getName());
}
public PlayerDataSponge(@Nonnull UUID uuid, @Nonnull String playerName) {
super(uuid, playerName);
}
......@@ -18,10 +15,10 @@ public class PlayerDataSponge extends PlayerDataCommon {
@Nonnull
@Override
public String getDisplayName() {
return getPlayerFromUUID(uuid).getDisplayNameData().displayName().get().toString();
return getPlayerFromUUID(uuid).get().getDisplayNameData().displayName().get().toString();
}
private static Player getPlayerFromUUID(UUID uuid) {
return Sponge.getServer().getPlayer(uuid).get();
public static Optional<Player> getPlayerFromUUID(UUID uuid) {
return Sponge.getServer().getPlayer(uuid);
}
}
......@@ -12,7 +12,8 @@ import team.aura_dev.aurasudo.platform.common.player.PlayerManagerCommon;
public class PlayerManagerSponge extends PlayerManagerCommon {
@Override
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataSponge(uuid));
return PlayerDataSponge.getPlayerFromUUID(uuid)
.map(player -> new PlayerDataSponge(uuid, player.getName()));
}
@Nonnull
......
......@@ -17,7 +17,7 @@ public class PlayerManagerVelocity extends PlayerManagerCommon {
@Override
protected Optional<PlayerDataCommon> generatePlayerData(@Nonnull @NonNull UUID uuid) {
return Optional.of(new PlayerDataCommon(uuid, server.getPlayer(uuid).get().getUsername()));
return server.getPlayer(uuid).map(player -> new PlayerDataCommon(uuid, player.getUsername()));
}
@Nonnull
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment