Adventure

Co-authored-by: zml <zml@stellardrift.ca>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
This commit is contained in:
Riley Park
2021-01-29 17:21:55 +01:00
parent 8888031206
commit 15081a5912
70 changed files with 3298 additions and 160 deletions

View File

@@ -22,7 +22,11 @@ import org.jetbrains.annotations.NotNull;
* <p>
* Care should be taken to check {@link #isAsynchronous()} and treat the event
* appropriately.
*
* @deprecated use {@link io.papermc.paper.event.player.AsyncChatEvent} instead
*/
@Deprecated // Paper
@org.bukkit.Warning(value = false, reason = "Don't nag on old event yet") // Paper
public class AsyncPlayerChatEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;

View File

@@ -10,11 +10,18 @@ import org.jetbrains.annotations.NotNull;
* Stores details for players attempting to log in.
* <p>
* This event is asynchronous, and not run using main thread.
* <p>
* When this event is fired, the player's locale is not
* available. Therefore, any translatable component will be
* rendered with the default locale, {@link java.util.Locale#US}.
* <p>
* Consider rendering any translatable yourself with {@link net.kyori.adventure.translation.GlobalTranslator#render}
* if the client's language is known.
*/
public class AsyncPlayerPreLoginEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Result result;
private String message;
private net.kyori.adventure.text.Component message; // Paper
private final String name;
private final InetAddress ipAddress;
private final UUID uniqueId;
@@ -33,7 +40,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
public AsyncPlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final UUID uniqueId, boolean transferred) {
super(true);
this.result = Result.ALLOWED;
this.message = "";
this.message = net.kyori.adventure.text.Component.empty(); // Paper
this.name = name;
this.ipAddress = ipAddress;
this.uniqueId = uniqueId;
@@ -86,6 +93,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
this.result = result == null ? null : Result.valueOf(result.name());
}
// Paper start
/**
* Gets the current kick message that will be used if getResult() !=
* Result.ALLOWED
@@ -93,7 +101,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
* @return Current kick message
*/
@NotNull
public String getKickMessage() {
public net.kyori.adventure.text.Component kickMessage() {
return message;
}
@@ -102,29 +110,81 @@ public class AsyncPlayerPreLoginEvent extends Event {
*
* @param message New kick message
*/
public void setKickMessage(@NotNull final String message) {
public void kickMessage(@NotNull final net.kyori.adventure.text.Component message) {
this.message = message;
}
/**
* Allows the player to log in
*/
public void allow() {
result = Result.ALLOWED;
message = "";
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
*/
public void disallow(@NotNull final Result result, @NotNull final String message) {
public void disallow(@NotNull final Result result, @NotNull final net.kyori.adventure.text.Component message) {
this.result = result;
this.message = message;
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
* @deprecated This method uses a deprecated enum from {@link
* PlayerPreLoginEvent}
* @see #disallow(Result, String)
*/
@Deprecated
public void disallow(@NotNull final PlayerPreLoginEvent.Result result, @NotNull final net.kyori.adventure.text.Component message) {
this.result = result == null ? null : Result.valueOf(result.name());
this.message = message;
}
// Paper end
/**
* Gets the current kick message that will be used if getResult() !=
* Result.ALLOWED
*
* @return Current kick message
* @deprecated in favour of {@link #kickMessage()}
*/
@NotNull
@Deprecated // Paper
public String getKickMessage() {
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.message); // Paper
}
/**
* Sets the kick message to display if getResult() != Result.ALLOWED
*
* @param message New kick message
* @deprecated in favour of {@link #kickMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setKickMessage(@NotNull final String message) {
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
/**
* Allows the player to log in
*/
public void allow() {
result = Result.ALLOWED;
message = net.kyori.adventure.text.Component.empty(); // Paper
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
* @deprecated in favour of {@link #disallow(org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result, net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void disallow(@NotNull final Result result, @NotNull final String message) {
this.result = result;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
/**
* Disallows the player from logging in, with the given reason
*
@@ -137,7 +197,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
@Deprecated(since = "1.3.2")
public void disallow(@NotNull final PlayerPreLoginEvent.Result result, @NotNull final String message) {
this.result = result == null ? null : Result.valueOf(result.name());
this.message = message;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
/**

View File

@@ -12,12 +12,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Holds information for player chat and commands
*
* @deprecated This event will fire from the main thread and allows the use of
* all of the Bukkit API, unlike the {@link AsyncPlayerChatEvent}.
* <p>
* Listening to this event forces chat to wait for the main thread which
* causes delays for chat. {@link AsyncPlayerChatEvent} is the encouraged
* alternative for thread safe implementations.
* @deprecated Listening to this event forces chat to wait for the main thread, delaying chat messages. It is recommended to use {@link io.papermc.paper.event.player.AsyncChatEvent} instead, wherever possible.
*/
@Deprecated(since = "1.3.1")
@Warning(reason = "Listening to this event forces chat to wait for the main thread, delaying chat messages.")

View File

@@ -14,7 +14,7 @@ public abstract class PlayerEvent extends Event {
player = who;
}
PlayerEvent(@NotNull final Player who, boolean async) {
public PlayerEvent(@NotNull final Player who, boolean async) { // Paper - public
super(async);
player = who;

View File

@@ -10,21 +10,27 @@ import org.jetbrains.annotations.Nullable;
*/
public class PlayerJoinEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
private String joinMessage;
public PlayerJoinEvent(@NotNull final Player playerJoined, @Nullable final String joinMessage) {
// Paper start
private net.kyori.adventure.text.Component joinMessage;
public PlayerJoinEvent(@NotNull final Player playerJoined, @Nullable final net.kyori.adventure.text.Component joinMessage) {
super(playerJoined);
this.joinMessage = joinMessage;
}
@Deprecated // Paper end
public PlayerJoinEvent(@NotNull final Player playerJoined, @Nullable final String joinMessage) {
super(playerJoined);
this.joinMessage = joinMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(joinMessage) : null; // Paper end
}
// Paper start
/**
* Gets the join message to send to all online players
*
* @return string join message. Can be null
*/
@Nullable
public String getJoinMessage() {
return joinMessage;
public net.kyori.adventure.text.@Nullable Component joinMessage() {
return this.joinMessage;
}
/**
@@ -32,9 +38,33 @@ public class PlayerJoinEvent extends PlayerEvent {
*
* @param joinMessage join message. If null, no message will be sent
*/
public void setJoinMessage(@Nullable String joinMessage) {
public void joinMessage(net.kyori.adventure.text.@Nullable Component joinMessage) {
this.joinMessage = joinMessage;
}
// Paper end
/**
* Gets the join message to send to all online players
*
* @return string join message. Can be null
* @deprecated in favour of {@link #joinMessage()}
*/
@Nullable
@Deprecated // Paper
public String getJoinMessage() {
return this.joinMessage == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.joinMessage); // Paper
}
/**
* Sets the join message to send to all online players
*
* @param joinMessage join message. If null, no message will be sent
* @deprecated in favour of {@link #joinMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setJoinMessage(@Nullable String joinMessage) {
this.joinMessage = joinMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(joinMessage) : null; // Paper
}
@NotNull
@Override

View File

@@ -10,35 +10,84 @@ import org.jetbrains.annotations.NotNull;
*/
public class PlayerKickEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private String leaveMessage;
private String kickReason;
private net.kyori.adventure.text.Component leaveMessage; // Paper
private net.kyori.adventure.text.Component kickReason; // Paper
private boolean cancel;
@Deprecated // Paper
public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final String kickReason, @NotNull final String leaveMessage) {
super(playerKicked);
this.kickReason = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(kickReason); // Paper
this.leaveMessage = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(leaveMessage); // Paper
this.cancel = false;
}
// Paper start
public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final net.kyori.adventure.text.Component kickReason, @NotNull final net.kyori.adventure.text.Component leaveMessage) {
super(playerKicked);
this.kickReason = kickReason;
this.leaveMessage = leaveMessage;
this.cancel = false;
}
/**
* Gets the leave message send to all online players
*
* @return string kick reason
*/
public net.kyori.adventure.text.@NotNull Component leaveMessage() {
return this.leaveMessage;
}
/**
* Sets the leave message send to all online players
*
* @param leaveMessage leave message
*/
public void leaveMessage(net.kyori.adventure.text.@NotNull Component leaveMessage) {
this.leaveMessage = leaveMessage;
}
/**
* Gets the reason why the player is getting kicked
*
* @return string kick reason
*/
public net.kyori.adventure.text.@NotNull Component reason() {
return this.kickReason;
}
/**
* Sets the reason why the player is getting kicked
*
* @param kickReason kick reason
*/
public void reason(net.kyori.adventure.text.@NotNull Component kickReason) {
this.kickReason = kickReason;
}
// Paper end
/**
* Gets the reason why the player is getting kicked
*
* @return string kick reason
* @deprecated in favour of {@link #reason()}
*/
@NotNull
@Deprecated // Paper
public String getReason() {
return kickReason;
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.kickReason); // Paper
}
/**
* Gets the leave message send to all online players
*
* @return string kick reason
* @deprecated in favour of {@link #leaveMessage()}
*/
@NotNull
@Deprecated // Paper
public String getLeaveMessage() {
return leaveMessage;
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.leaveMessage); // Paper
}
@Override
@@ -55,18 +104,22 @@ public class PlayerKickEvent extends PlayerEvent implements Cancellable {
* Sets the reason why the player is getting kicked
*
* @param kickReason kick reason
* @deprecated in favour of {@link #reason(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setReason(@NotNull String kickReason) {
this.kickReason = kickReason;
this.kickReason = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(kickReason); // Paper
}
/**
* Sets the leave message send to all online players
*
* @param leaveMessage leave message
* @deprecated in favour of {@link #leaveMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setLeaveMessage(@NotNull String leaveMessage) {
this.leaveMessage = leaveMessage;
this.leaveMessage = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(leaveMessage); // Paper
}
@NotNull

View File

@@ -12,17 +12,31 @@ public class PlayerLocaleChangeEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
//
private final String locale;
// Paper start
private final java.util.Locale adventure$locale;
/**
* @see Player#locale()
*
* @return the player's new locale
*/
public @NotNull java.util.Locale locale() {
return this.adventure$locale;
}
// Paper end
public PlayerLocaleChangeEvent(@NotNull Player who, @NotNull String locale) {
super(who);
this.locale = locale;
this.adventure$locale = java.util.Objects.requireNonNullElse(net.kyori.adventure.translation.Translator.parseLocale(locale), java.util.Locale.US); // Paper start
}
/**
* @return the player's new locale
* @see Player#getLocale()
* @deprecated in favour of {@link #locale()}
*/
@NotNull
@Deprecated // Paper
public String getLocale() {
return locale;
}

View File

@@ -18,7 +18,7 @@ public class PlayerLoginEvent extends PlayerEvent {
private final InetAddress realAddress;
private final String hostname;
private Result result = Result.ALLOWED;
private String message = "";
private net.kyori.adventure.text.Component message = net.kyori.adventure.text.Component.empty();
/**
* This constructor defaults message to an empty string, and result to
@@ -60,13 +60,53 @@ public class PlayerLoginEvent extends PlayerEvent {
* @param result The result status for this event
* @param message The message to be displayed if result denies login
* @param realAddress the actual, unspoofed connecting address
* @deprecated in favour of {@link #PlayerLoginEvent(Player, String, InetAddress, Result, net.kyori.adventure.text.Component, InetAddress)}
*/
@Deprecated // Paper
public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final String message, @NotNull final InetAddress realAddress) {
this(player, hostname, address, realAddress);
this.result = result;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
// Paper start
/**
* This constructor pre-configures the event with a result and message
*
* @param player The {@link Player} for this event
* @param hostname The hostname that was used to connect to the server
* @param address The address the player used to connect, provided for
* timing issues
* @param result The result status for this event
* @param message The message to be displayed if result denies login
* @param realAddress the actual, unspoofed connecting address
*/
public PlayerLoginEvent(@NotNull final Player player, @NotNull String hostname, @NotNull final InetAddress address, @NotNull final Result result, @NotNull final net.kyori.adventure.text.Component message, @NotNull final InetAddress realAddress) {
this(player, hostname, address, realAddress); // Spigot
this.result = result;
this.message = message;
}
/**
* Gets the current kick message that will be used if getResult() !=
* Result.ALLOWED
*
* @return Current kick message
*/
public net.kyori.adventure.text.@NotNull Component kickMessage() {
return this.message;
}
/**
* Sets the kick message to display if getResult() != Result.ALLOWED
*
* @param message New kick message
*/
public void kickMessage(net.kyori.adventure.text.@NotNull Component message) {
this.message = message;
}
// Paper end
/**
* Gets the current result of the login, as an enum
*
@@ -91,19 +131,23 @@ public class PlayerLoginEvent extends PlayerEvent {
* Result.ALLOWED
*
* @return Current kick message
* @deprecated in favour of {@link #kickMessage()}
*/
@NotNull
@Deprecated // Paper
public String getKickMessage() {
return message;
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.message); // Paper
}
/**
* Sets the kick message to display if getResult() != Result.ALLOWED
*
* @param message New kick message
* @deprecated in favour of {@link #kickMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setKickMessage(@NotNull final String message) {
this.message = message;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
/**
@@ -122,7 +166,7 @@ public class PlayerLoginEvent extends PlayerEvent {
*/
public void allow() {
result = Result.ALLOWED;
message = "";
message = net.kyori.adventure.text.Component.empty(); // Paper
}
/**
@@ -130,8 +174,21 @@ public class PlayerLoginEvent extends PlayerEvent {
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
* @deprecated in favour of {@link #disallow(Result, net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper start
public void disallow(@NotNull final Result result, @NotNull final String message) {
this.result = result;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message);
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
*/
public void disallow(@NotNull final Result result, @NotNull final net.kyori.adventure.text.Component message) {
// Paper end
this.result = result;
this.message = message;
}

View File

@@ -9,6 +9,13 @@ import org.jetbrains.annotations.NotNull;
/**
* Stores details for players attempting to log in
* <p>
* When this event is fired, the player's locale is not
* available. Therefore, any translatable component will be
* rendered with the default locale, {@link java.util.Locale#US}.
* <p>
* Consider rendering any translatable yourself with {@link net.kyori.adventure.translation.GlobalTranslator#render}
* if the client's language is known.
*
* @deprecated This event causes synchronization from the login thread; {@link
* AsyncPlayerPreLoginEvent} is preferred to keep the secondary threads
@@ -19,7 +26,7 @@ import org.jetbrains.annotations.NotNull;
public class PlayerPreLoginEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private Result result;
private String message;
private net.kyori.adventure.text.Component message; // Paper
private final String name;
private final InetAddress ipAddress;
private final UUID uniqueId;
@@ -31,7 +38,7 @@ public class PlayerPreLoginEvent extends Event {
public PlayerPreLoginEvent(@NotNull final String name, @NotNull final InetAddress ipAddress, @NotNull final UUID uniqueId) {
this.result = Result.ALLOWED;
this.message = "";
this.message = net.kyori.adventure.text.Component.empty(); // Paper
this.name = name;
this.ipAddress = ipAddress;
this.uniqueId = uniqueId;
@@ -56,6 +63,7 @@ public class PlayerPreLoginEvent extends Event {
this.result = result;
}
// Paper start
/**
* Gets the current kick message that will be used if getResult() !=
* Result.ALLOWED
@@ -63,7 +71,7 @@ public class PlayerPreLoginEvent extends Event {
* @return Current kick message
*/
@NotNull
public String getKickMessage() {
public net.kyori.adventure.text.Component kickMessage() {
return message;
}
@@ -72,28 +80,65 @@ public class PlayerPreLoginEvent extends Event {
*
* @param message New kick message
*/
public void setKickMessage(@NotNull final String message) {
public void kickMessage(@NotNull final net.kyori.adventure.text.Component message) {
this.message = message;
}
/**
* Allows the player to log in
*/
public void allow() {
result = Result.ALLOWED;
message = "";
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
*/
public void disallow(@NotNull final Result result, @NotNull final String message) {
public void disallow(@NotNull final Result result, @NotNull final net.kyori.adventure.text.Component message) {
this.result = result;
this.message = message;
}
// Paper end
/**
* Gets the current kick message that will be used if getResult() !=
* Result.ALLOWED
*
* @return Current kick message
* @deprecated in favour of {@link #kickMessage()}
*/
@Deprecated // Paper
@NotNull
public String getKickMessage() {
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.message); // Paper
}
/**
* Sets the kick message to display if getResult() != Result.ALLOWED
*
* @param message New kick message
* @deprecated in favour of {@link #kickMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setKickMessage(@NotNull final String message) {
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
/**
* Allows the player to log in
*/
public void allow() {
result = Result.ALLOWED;
message = net.kyori.adventure.text.Component.empty(); // Paper
}
/**
* Disallows the player from logging in, with the given reason
*
* @param result New result for disallowing the player
* @param message Kick message to display to the user
* @deprecated in favour of {@link #disallow(org.bukkit.event.player.PlayerPreLoginEvent.Result, net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void disallow(@NotNull final Result result, @NotNull final String message) {
this.result = result;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
/**
* Gets the player's name.

View File

@@ -10,9 +10,15 @@ import org.jetbrains.annotations.Nullable;
*/
public class PlayerQuitEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
private String quitMessage;
private net.kyori.adventure.text.Component quitMessage; // Paper
@Deprecated // Paper
public PlayerQuitEvent(@NotNull final Player who, @Nullable final String quitMessage) {
super(who);
this.quitMessage = quitMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(quitMessage) : null; // Paper
}
// Paper start
public PlayerQuitEvent(@NotNull final Player who, @Nullable final net.kyori.adventure.text.Component quitMessage) {
super(who);
this.quitMessage = quitMessage;
}
@@ -22,8 +28,7 @@ public class PlayerQuitEvent extends PlayerEvent {
*
* @return string quit message
*/
@Nullable
public String getQuitMessage() {
public net.kyori.adventure.text.@Nullable Component quitMessage() {
return quitMessage;
}
@@ -32,9 +37,33 @@ public class PlayerQuitEvent extends PlayerEvent {
*
* @param quitMessage quit message
*/
public void setQuitMessage(@Nullable String quitMessage) {
public void quitMessage(net.kyori.adventure.text.@Nullable Component quitMessage) {
this.quitMessage = quitMessage;
}
// Paper end
/**
* Gets the quit message to send to all online players
*
* @return string quit message
* @deprecated in favour of {@link #quitMessage()}
*/
@Nullable
@Deprecated // Paper
public String getQuitMessage() {
return this.quitMessage == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.quitMessage); // Paper
}
/**
* Sets the quit message to send to all online players
*
* @param quitMessage quit message
* @deprecated in favour of {@link #quitMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setQuitMessage(@Nullable String quitMessage) {
this.quitMessage = quitMessage != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(quitMessage) : null; // Paper
}
@NotNull
@Override