mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Remove longly deprecated player initialization callback
This commit is contained in:
parent
ba6e83b6d1
commit
55fa083adf
@ -41,7 +41,6 @@ import java.util.function.Predicate;
|
|||||||
* Manages the connected clients.
|
* Manages the connected clients.
|
||||||
*/
|
*/
|
||||||
public final class ConnectionManager {
|
public final class ConnectionManager {
|
||||||
|
|
||||||
private static final long KEEP_ALIVE_DELAY = 10_000;
|
private static final long KEEP_ALIVE_DELAY = 10_000;
|
||||||
private static final long KEEP_ALIVE_KICK = 30_000;
|
private static final long KEEP_ALIVE_KICK = 30_000;
|
||||||
private static final Component TIMEOUT_TEXT = Component.text("Timeout", NamedTextColor.RED);
|
private static final Component TIMEOUT_TEXT = Component.text("Timeout", NamedTextColor.RED);
|
||||||
@ -59,8 +58,6 @@ public final class ConnectionManager {
|
|||||||
private UuidProvider uuidProvider;
|
private UuidProvider uuidProvider;
|
||||||
// The player provider to have your own Player implementation
|
// The player provider to have your own Player implementation
|
||||||
private PlayerProvider playerProvider;
|
private PlayerProvider playerProvider;
|
||||||
// The consumers to call once a player connect, mostly used to init events
|
|
||||||
private final List<Consumer<Player>> playerInitializations = new CopyOnWriteArrayList<>();
|
|
||||||
|
|
||||||
private Component shutdownText = Component.text("The server is shutting down.", NamedTextColor.RED);
|
private Component shutdownText = Component.text("The server is shutting down.", NamedTextColor.RED);
|
||||||
|
|
||||||
@ -113,8 +110,7 @@ public final class ConnectionManager {
|
|||||||
* @param username the player username (ignoreCase)
|
* @param username the player username (ignoreCase)
|
||||||
* @return the first player who validate the username condition, null if none was found
|
* @return the first player who validate the username condition, null if none was found
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable Player getPlayer(@NotNull String username) {
|
||||||
public Player getPlayer(@NotNull String username) {
|
|
||||||
for (Player player : getOnlinePlayers()) {
|
for (Player player : getOnlinePlayers()) {
|
||||||
if (player.getUsername().equalsIgnoreCase(username))
|
if (player.getUsername().equalsIgnoreCase(username))
|
||||||
return player;
|
return player;
|
||||||
@ -130,8 +126,7 @@ public final class ConnectionManager {
|
|||||||
* @param uuid the player UUID
|
* @param uuid the player UUID
|
||||||
* @return the first player who validate the UUID condition, null if none was found
|
* @return the first player who validate the UUID condition, null if none was found
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable Player getPlayer(@NotNull UUID uuid) {
|
||||||
public Player getPlayer(@NotNull UUID uuid) {
|
|
||||||
for (Player player : getOnlinePlayers()) {
|
for (Player player : getOnlinePlayers()) {
|
||||||
if (player.getUuid().equals(uuid))
|
if (player.getUuid().equals(uuid))
|
||||||
return player;
|
return player;
|
||||||
@ -259,8 +254,7 @@ public final class ConnectionManager {
|
|||||||
* @return the uuid based on {@code playerConnection}
|
* @return the uuid based on {@code playerConnection}
|
||||||
* return a random UUID if no UUID provider is defined see {@link #setUuidProvider(UuidProvider)}
|
* return a random UUID if no UUID provider is defined see {@link #setUuidProvider(UuidProvider)}
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull UUID getPlayerConnectionUuid(@NotNull PlayerConnection playerConnection, @NotNull String username) {
|
||||||
public UUID getPlayerConnectionUuid(@NotNull PlayerConnection playerConnection, @NotNull String username) {
|
|
||||||
if (uuidProvider == null)
|
if (uuidProvider == null)
|
||||||
return UUID.randomUUID();
|
return UUID.randomUUID();
|
||||||
return uuidProvider.provide(playerConnection, username);
|
return uuidProvider.provide(playerConnection, username);
|
||||||
@ -280,49 +274,10 @@ public final class ConnectionManager {
|
|||||||
*
|
*
|
||||||
* @return the current {@link PlayerProvider}
|
* @return the current {@link PlayerProvider}
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull PlayerProvider getPlayerProvider() {
|
||||||
public PlayerProvider getPlayerProvider() {
|
|
||||||
return playerProvider == null ? playerProvider = Player::new : playerProvider;
|
return playerProvider == null ? playerProvider = Player::new : playerProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Those are all the consumers called when a new {@link Player} join.
|
|
||||||
*
|
|
||||||
* @return an unmodifiable list containing all the {@link Player} initialization consumer
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public List<Consumer<Player>> getPlayerInitializations() {
|
|
||||||
return Collections.unmodifiableList(playerInitializations);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new player initialization consumer. Those are called when a {@link Player} join,
|
|
||||||
* mainly to add event callbacks to the player.
|
|
||||||
* <p>
|
|
||||||
* This callback should be exclusively used to add event listeners since it is called directly after a
|
|
||||||
* player join (before any chunk is sent) and the client behavior can therefore be unpredictable.
|
|
||||||
* You can add your "init" code in {@link net.minestom.server.event.player.PlayerLoginEvent}
|
|
||||||
* or even {@link AsyncPlayerPreLoginEvent}.
|
|
||||||
*
|
|
||||||
* @param playerInitialization the {@link Player} initialization consumer
|
|
||||||
* @deprecated use the event API instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void addPlayerInitialization(@NotNull Consumer<Player> playerInitialization) {
|
|
||||||
this.playerInitializations.add(playerInitialization);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an existing player initialization consumer.
|
|
||||||
* <p>
|
|
||||||
* Removal of player initializations should be done by reference, and not cloning.
|
|
||||||
*
|
|
||||||
* @param playerInitialization the {@link Player} initialization consumer
|
|
||||||
*/
|
|
||||||
public void removePlayerInitialization(@NotNull Consumer<Player> playerInitialization) {
|
|
||||||
this.playerInitializations.remove(playerInitialization);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the kick reason when the server is shutdown using {@link MinecraftServer#stopCleanly()}.
|
* Gets the kick reason when the server is shutdown using {@link MinecraftServer#stopCleanly()}.
|
||||||
*
|
*
|
||||||
@ -340,8 +295,7 @@ public final class ConnectionManager {
|
|||||||
*
|
*
|
||||||
* @return the kick reason in case on a shutdown
|
* @return the kick reason in case on a shutdown
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull Component getShutdownText() {
|
||||||
public Component getShutdownText() {
|
|
||||||
return shutdownText;
|
return shutdownText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,11 +361,6 @@ public final class ConnectionManager {
|
|||||||
* @param register true to register the newly created player in {@link ConnectionManager} lists
|
* @param register true to register the newly created player in {@link ConnectionManager} lists
|
||||||
*/
|
*/
|
||||||
public void startPlayState(@NotNull Player player, boolean register) {
|
public void startPlayState(@NotNull Player player, boolean register) {
|
||||||
// Init player (register events)
|
|
||||||
for (Consumer<Player> playerInitialization : getPlayerInitializations()) {
|
|
||||||
playerInitialization.accept(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
AsyncUtils.runAsync(() -> {
|
AsyncUtils.runAsync(() -> {
|
||||||
String username = player.getUsername();
|
String username = player.getUsername();
|
||||||
UUID uuid = player.getUuid();
|
UUID uuid = player.getUuid();
|
||||||
@ -424,7 +373,6 @@ public final class ConnectionManager {
|
|||||||
final boolean online = player.isOnline();
|
final boolean online = player.isOnline();
|
||||||
if (!online) {
|
if (!online) {
|
||||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||||
|
|
||||||
if (playerConnection instanceof NettyPlayerConnection) {
|
if (playerConnection instanceof NettyPlayerConnection) {
|
||||||
((NettyPlayerConnection) playerConnection).getChannel().flush();
|
((NettyPlayerConnection) playerConnection).getChannel().flush();
|
||||||
}
|
}
|
||||||
@ -479,13 +427,11 @@ public final class ConnectionManager {
|
|||||||
* @return the newly created player object
|
* @return the newly created player object
|
||||||
* @see #startPlayState(Player, boolean)
|
* @see #startPlayState(Player, boolean)
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull Player startPlayState(@NotNull PlayerConnection connection,
|
||||||
public Player startPlayState(@NotNull PlayerConnection connection,
|
@NotNull UUID uuid, @NotNull String username,
|
||||||
@NotNull UUID uuid, @NotNull String username,
|
boolean register) {
|
||||||
boolean register) {
|
|
||||||
final Player player = getPlayerProvider().createPlayer(uuid, username, connection);
|
final Player player = getPlayerProvider().createPlayer(uuid, username, connection);
|
||||||
startPlayState(player, register);
|
startPlayState(player, register);
|
||||||
|
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,7 +457,6 @@ public final class ConnectionManager {
|
|||||||
* Connects waiting players.
|
* Connects waiting players.
|
||||||
*/
|
*/
|
||||||
public void updateWaitingPlayers() {
|
public void updateWaitingPlayers() {
|
||||||
// Connect waiting players
|
|
||||||
waitingPlayersTick();
|
waitingPlayersTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,7 +485,6 @@ public final class ConnectionManager {
|
|||||||
private void waitingPlayersTick() {
|
private void waitingPlayersTick() {
|
||||||
Player waitingPlayer;
|
Player waitingPlayer;
|
||||||
while ((waitingPlayer = waitingPlayers.poll()) != null) {
|
while ((waitingPlayer = waitingPlayers.poll()) != null) {
|
||||||
|
|
||||||
PlayerLoginEvent loginEvent = new PlayerLoginEvent(waitingPlayer);
|
PlayerLoginEvent loginEvent = new PlayerLoginEvent(waitingPlayer);
|
||||||
EventDispatcher.call(loginEvent);
|
EventDispatcher.call(loginEvent);
|
||||||
final Instance spawningInstance = loginEvent.getSpawningInstance();
|
final Instance spawningInstance = loginEvent.getSpawningInstance();
|
||||||
|
Loading…
Reference in New Issue
Block a user