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

@@ -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
}
/**