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

@@ -17,18 +17,38 @@ public class SignChangeEvent extends BlockEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final Player player;
private final String[] lines;
private final java.util.List<net.kyori.adventure.text.Component> adventure$lines; // Paper
private final Side side;
// Paper start
public SignChangeEvent(@NotNull final Block theBlock, @NotNull final Player player, @NotNull final java.util.List<net.kyori.adventure.text.Component> adventure$lines, @NotNull Side side) {
super(theBlock);
this.player = player;
this.adventure$lines = adventure$lines;
this.side = side;
}
@Deprecated
public SignChangeEvent(@NotNull final Block theBlock, @NotNull final Player player, @NotNull final java.util.List<net.kyori.adventure.text.Component> adventure$lines) {
this(theBlock, player, adventure$lines, Side.FRONT);
}
// Paper end
@Deprecated(since = "1.19.4")
public SignChangeEvent(@NotNull final Block theBlock, @NotNull final Player thePlayer, @NotNull final String[] theLines) {
this(theBlock, thePlayer, theLines, Side.FRONT);
}
@Deprecated // Paper
public SignChangeEvent(@NotNull final Block theBlock, @NotNull final Player thePlayer, @NotNull final String[] theLines, @NotNull Side side) {
super(theBlock);
this.player = thePlayer;
this.lines = theLines;
// Paper start
this.adventure$lines = new java.util.ArrayList<>();
for (String theLine : theLines) {
this.adventure$lines.add(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(theLine));
}
// Paper end
this.side = side;
}
@@ -42,14 +62,14 @@ public class SignChangeEvent extends BlockEvent implements Cancellable {
return player;
}
// Paper start
/**
* Gets all of the lines of text from the sign involved in this event.
*
* @return the String array for the sign's lines new text
*/
@NotNull
public String[] getLines() {
return lines;
public @NotNull java.util.List<net.kyori.adventure.text.Component> lines() {
return this.adventure$lines;
}
/**
@@ -61,9 +81,8 @@ public class SignChangeEvent extends BlockEvent implements Cancellable {
* @throws IndexOutOfBoundsException thrown when the provided index is {@literal > 3
* or < 0}
*/
@Nullable
public String getLine(int index) throws IndexOutOfBoundsException {
return lines[index];
public net.kyori.adventure.text.@Nullable Component line(int index) throws IndexOutOfBoundsException {
return this.adventure$lines.get(index);
}
/**
@@ -74,8 +93,51 @@ public class SignChangeEvent extends BlockEvent implements Cancellable {
* @throws IndexOutOfBoundsException thrown when the provided index is {@literal > 3
* or < 0}
*/
public void line(int index, net.kyori.adventure.text.@Nullable Component line) throws IndexOutOfBoundsException {
this.adventure$lines.set(index, line);
}
// Paper end
/**
* Gets all of the lines of text from the sign involved in this event.
*
* @return the String array for the sign's lines new text
* @deprecated in favour of {@link #lines()}
*/
@NotNull
@Deprecated // Paper
public String[] getLines() {
return adventure$lines.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).toArray(String[]::new); // Paper
}
/**
* Gets a single line of text from the sign involved in this event.
*
* @param index index of the line to get
* @return the String containing the line of text associated with the
* provided index
* @throws IndexOutOfBoundsException thrown when the provided index is {@literal > 3
* or < 0}
* @deprecated in favour of {@link #line(int)}
*/
@Nullable
@Deprecated // Paper
public String getLine(int index) throws IndexOutOfBoundsException {
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.adventure$lines.get(index)); // Paper
}
/**
* Sets a single line for the sign involved in this event
*
* @param index index of the line to set
* @param line text to set
* @throws IndexOutOfBoundsException thrown when the provided index is {@literal > 3
* or < 0}
* @deprecated in favour of {@link #line(int, net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setLine(int index, @Nullable String line) throws IndexOutOfBoundsException {
lines[index] = line;
adventure$lines.set(index, line != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(line) : null); // Paper
}
/**

View File

@@ -12,27 +12,50 @@ import org.jetbrains.annotations.Nullable;
*/
public class PlayerDeathEvent extends EntityDeathEvent {
private int newExp = 0;
private String deathMessage = "";
private net.kyori.adventure.text.Component deathMessage; // Paper - adventure
private int newLevel = 0;
private int newTotalExp = 0;
private boolean keepLevel = false;
private boolean keepInventory = false;
public PlayerDeathEvent(@NotNull final Player player, @NotNull DamageSource damageSource, @NotNull final List<ItemStack> drops, final int droppedExp, @Nullable final String deathMessage) {
// Paper start - adventure
@org.jetbrains.annotations.ApiStatus.Internal
public PlayerDeathEvent(final @NotNull Player player, final @NotNull DamageSource damageSource, final @NotNull List<ItemStack> drops, final int droppedExp, final @Nullable net.kyori.adventure.text.Component deathMessage) {
this(player, damageSource, drops, droppedExp, 0, deathMessage);
}
public PlayerDeathEvent(@NotNull final Player player, @NotNull DamageSource damageSource, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, @Nullable final String deathMessage) {
@org.jetbrains.annotations.ApiStatus.Internal
public PlayerDeathEvent(final @NotNull Player player, final @NotNull DamageSource damageSource, final @NotNull List<ItemStack> drops, final int droppedExp, final int newExp, final @Nullable net.kyori.adventure.text.Component deathMessage) {
this(player, damageSource, drops, droppedExp, newExp, 0, 0, deathMessage);
}
public PlayerDeathEvent(@NotNull final Player player, @NotNull DamageSource damageSource, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final String deathMessage) {
@org.jetbrains.annotations.ApiStatus.Internal
public PlayerDeathEvent(final @NotNull Player player, final @NotNull DamageSource damageSource, final @NotNull List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, final @Nullable net.kyori.adventure.text.Component deathMessage) {
super(player, damageSource, drops, droppedExp);
this.newExp = newExp;
this.newTotalExp = newTotalExp;
this.newLevel = newLevel;
this.deathMessage = deathMessage;
}
// Paper end - adventure
@Deprecated // Paper
public PlayerDeathEvent(@NotNull final Player player, @NotNull DamageSource damageSource, @NotNull final List<ItemStack> drops, final int droppedExp, @Nullable final String deathMessage) {
this(player, damageSource, drops, droppedExp, 0, deathMessage);
}
@Deprecated // Paper
public PlayerDeathEvent(@NotNull final Player player, @NotNull DamageSource damageSource, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, @Nullable final String deathMessage) {
this(player, damageSource, drops, droppedExp, newExp, 0, 0, deathMessage);
}
@Deprecated // Paper
public PlayerDeathEvent(@NotNull final Player player, @NotNull DamageSource damageSource, @NotNull final List<ItemStack> drops, final int droppedExp, final int newExp, final int newTotalExp, final int newLevel, @Nullable final String deathMessage) {
super(player, damageSource, drops, droppedExp);
this.newExp = newExp;
this.newTotalExp = newTotalExp;
this.newLevel = newLevel;
this.deathMessage = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOrNull(deathMessage); // Paper
}
@NotNull
@Override
@@ -40,25 +63,49 @@ public class PlayerDeathEvent extends EntityDeathEvent {
return (Player) entity;
}
// Paper start - adventure
/**
* Set the death message that will appear to everyone on the server.
*
* @param deathMessage Message to appear to other players on the server.
* @param deathMessage Component message to appear to other players on the server.
*/
public void setDeathMessage(@Nullable String deathMessage) {
public void deathMessage(final net.kyori.adventure.text.@Nullable Component deathMessage) {
this.deathMessage = deathMessage;
}
/**
* Get the death message that will appear to everyone on the server.
*
* @return Message to appear to other players on the server.
* @return Component message to appear to other players on the server.
*/
@Nullable
public String getDeathMessage() {
return deathMessage;
public net.kyori.adventure.text.@Nullable Component deathMessage() {
return this.deathMessage;
}
// Paper end - adventure
/**
* Set the death message that will appear to everyone on the server.
*
* @param deathMessage Message to appear to other players on the server.
* @deprecated in favour of {@link #deathMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setDeathMessage(@Nullable String deathMessage) {
this.deathMessage = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOrNull(deathMessage); // Paper
}
/**
* Get the death message that will appear to everyone on the server.
*
* @return Message to appear to other players on the server.
* @deprecated in favour of {@link #deathMessage()}
*/
@Nullable
@Deprecated // Paper
public String getDeathMessage() {
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serializeOrNull(this.deathMessage); // Paper
}
// Paper end
/**
* Gets how much EXP the Player should have at respawn.
* <p>

View File

@@ -163,7 +163,18 @@ public enum InventoryType {
private final String title;
private final MenuType menuType;
private final boolean isCreatable;
// Paper start
private final net.kyori.adventure.text.Component defaultTitleComponent;
/**
* Gets the inventory's default title.
*
* @return the inventory's default title
*/
public net.kyori.adventure.text.@NotNull Component defaultTitle() {
return defaultTitleComponent;
}
// Paper end
private InventoryType(int defaultSize, /*@NotNull*/ String defaultTitle, @Nullable MenuType type) {
this(defaultSize, defaultTitle, type, true);
}
@@ -173,6 +184,7 @@ public enum InventoryType {
title = defaultTitle;
this.menuType = type;
this.isCreatable = isCreatable;
this.defaultTitleComponent = net.kyori.adventure.text.Component.text(defaultTitle); // Paper - Adventure
}
public int getDefaultSize() {
@@ -180,6 +192,7 @@ public enum InventoryType {
}
@NotNull
@Deprecated // Paper
public String getDefaultTitle() {
return title;
}

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

View File

@@ -9,16 +9,16 @@ import org.jetbrains.annotations.NotNull;
/**
* Event triggered for server broadcast messages such as from
* {@link org.bukkit.Server#broadcast(String, String)}.
* {@link org.bukkit.Server#broadcast(net.kyori.adventure.text.Component)} (String, String)}.
*
* <b>This event behaves similarly to {@link AsyncPlayerChatEvent} in that it
* <b>This event behaves similarly to {@link io.papermc.paper.event.player.AsyncChatEvent} in that it
* should be async if fired from an async thread. Please see that event for
* further information.</b>
*/
public class BroadcastMessageEvent extends ServerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private String message;
private net.kyori.adventure.text.Component message; // Paper
private final Set<CommandSender> recipients;
private boolean cancelled = false;
@@ -27,29 +27,66 @@ public class BroadcastMessageEvent extends ServerEvent implements Cancellable {
this(false, message, recipients);
}
@Deprecated // Paper
public BroadcastMessageEvent(boolean isAsync, @NotNull String message, @NotNull Set<CommandSender> recipients) {
// Paper start
super(isAsync);
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message);
this.recipients = recipients;
}
@Deprecated
public BroadcastMessageEvent(net.kyori.adventure.text.@NotNull Component message, @NotNull Set<CommandSender> recipients) {
this(false, message, recipients);
}
public BroadcastMessageEvent(boolean isAsync, net.kyori.adventure.text.@NotNull Component message, @NotNull Set<CommandSender> recipients) {
// Paper end
super(isAsync);
this.message = message;
this.recipients = recipients;
}
// Paper start
/**
* Get the broadcast message.
*
* @return Message to broadcast
*/
public net.kyori.adventure.text.@NotNull Component message() {
return this.message;
}
/**
* Set the broadcast message.
*
* @param message New message to broadcast
*/
public void message(net.kyori.adventure.text.@NotNull Component message) {
this.message = message;
}
// Paper end
/**
* Get the message to broadcast.
*
* @return Message to broadcast
* @deprecated in favour of {@link #message()}
*/
@NotNull
@Deprecated // Paper
public String getMessage() {
return message;
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.message); // Paper
}
/**
* Set the message to broadcast.
*
* @param message New message to broadcast
* @deprecated in favour of {@link #message(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setMessage(@NotNull String message) {
this.message = message;
this.message = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message); // Paper
}
/**

View File

@@ -22,7 +22,7 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
private static final HandlerList handlers = new HandlerList();
private final String hostname;
private final InetAddress address;
private String motd;
private net.kyori.adventure.text.Component motd; // Paper
private final int numPlayers;
private int maxPlayers;
@@ -31,7 +31,7 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
Preconditions.checkArgument(numPlayers >= 0, "Cannot have negative number of players online", numPlayers);
this.hostname = hostname;
this.address = address;
this.motd = motd;
this.motd = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(motd); // Paper
this.numPlayers = numPlayers;
this.maxPlayers = maxPlayers;
}
@@ -45,15 +45,80 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
* @param address the address of the pinger
* @param motd the message of the day
* @param maxPlayers the max number of players
* @deprecated in favour of {@link #ServerListPingEvent(String, java.net.InetAddress, net.kyori.adventure.text.Component, int)}
*/
@Deprecated // Paper
protected ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final String motd, final int maxPlayers) {
super(true);
this.numPlayers = MAGIC_PLAYER_COUNT;
this.hostname = hostname;
this.address = address;
this.motd = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(motd); // Paper
this.maxPlayers = maxPlayers;
}
// Paper start
@Deprecated
public ServerListPingEvent(@NotNull final InetAddress address, @NotNull final net.kyori.adventure.text.Component motd, final int numPlayers, final int maxPlayers) {
this("", address, motd, numPlayers, maxPlayers);
}
public ServerListPingEvent(@NotNull final String hostname, @NotNull final InetAddress address, @NotNull final net.kyori.adventure.text.Component motd, final int numPlayers, final int maxPlayers) {
super(true);
Preconditions.checkArgument(numPlayers >= 0, "Cannot have negative number of players online (%s)", numPlayers);
this.hostname = hostname;
this.address = address;
this.motd = motd;
this.numPlayers = numPlayers;
this.maxPlayers = maxPlayers;
}
/**
* This constructor is intended for implementations that provide the
* {@link #iterator()} method, thus provided the {@link #getNumPlayers()}
* count.
*
* @param address the address of the pinger
* @param motd the message of the day
* @param maxPlayers the max number of players
* @deprecated in favour of {@link #ServerListPingEvent(String, java.net.InetAddress, net.kyori.adventure.text.Component, int)}
*/
@Deprecated
protected ServerListPingEvent(@NotNull final InetAddress address, @NotNull final net.kyori.adventure.text.Component motd, final int maxPlayers) {
this("", address, motd, maxPlayers);
}
/**
* This constructor is intended for implementations that provide the
* {@link #iterator()} method, thus provided the {@link #getNumPlayers()}
* count.
*
* @param hostname The hostname that was used to connect to the server
* @param address the address of the pinger
* @param motd the message of the day
* @param maxPlayers the max number of players
*/
protected ServerListPingEvent(final @NotNull String hostname, final @NotNull InetAddress address, final net.kyori.adventure.text.@NotNull Component motd, final int maxPlayers) {
this.numPlayers = MAGIC_PLAYER_COUNT;
this.hostname = hostname;
this.address = address;
this.motd = motd;
this.maxPlayers = maxPlayers;
}
/**
* Get the message of the day message.
*
* @return the message of the day
*/
public net.kyori.adventure.text.@NotNull Component motd() {
return motd;
}
/**
* Change the message of the day message.
*
* @param motd the message of the day
*/
public void motd(net.kyori.adventure.text.@NotNull Component motd) {
this.motd = motd;
}
// Paper end
/**
* Gets the hostname that the player used to connect to the server, or
@@ -80,19 +145,23 @@ public class ServerListPingEvent extends ServerEvent implements Iterable<Player>
* Get the message of the day message.
*
* @return the message of the day
* @deprecated in favour of {@link #motd()}
*/
@NotNull
@Deprecated // Paper
public String getMotd() {
return motd;
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.motd); // Paper
}
/**
* Change the message of the day message.
*
* @param motd the message of the day
* @deprecated in favour of {@link #motd(net.kyori.adventure.text.Component)}
*/
@Deprecated // Paper
public void setMotd(@NotNull String motd) {
this.motd = motd;
this.motd = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(motd); // Paper
}
/**