Fix broadcast event and add Adventure broadcast (#5477)

This commit is contained in:
Kezz 2021-05-29 23:56:24 +01:00
parent 08bb14c394
commit 0d254aed35
2 changed files with 61 additions and 18 deletions

View File

@ -764,7 +764,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
*
* @param message the message
* @return the number of players
+ * @deprecated in favour of {@link Server#sendMessage(net.kyori.adventure.text.Component)}
+ * @deprecated in favour of {@link Server#broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public static int broadcastMessage(@NotNull String message) {
@ -775,6 +775,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
+ // Paper start
+ /**
+ * Broadcast a message to all players.
+ * <p>
+ * This is the same as calling {@link #broadcast(net.kyori.adventure.text.Component,
+ * java.lang.String)} with the {@link Server#BROADCAST_CHANNEL_USERS} permission.
+ *
+ * @param message the message
+ * @return the number of players
+ */
+ public static int broadcast(@NotNull net.kyori.adventure.text.Component message) {
+ return server.broadcast(message);
+ }
/**
* Broadcasts the specified message to every user with the given
* permission name.
@ -1041,11 +1053,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
/**
* Used for all administrative messages, such as an operator using a
* command.
* <p>
- * For use in {@link #broadcast(java.lang.String, java.lang.String)}.
+ * For use in {@link #broadcast(net.kyori.adventure.text.Component, java.lang.String)}.
*/
public static final String BROADCAST_CHANNEL_ADMINISTRATIVE = "bukkit.broadcast.admin";
@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient {
* Used for all announcement messages, such as informing users that a
* player has joined.
* <p>
- * For use in {@link #broadcast(java.lang.String, java.lang.String)}.
+ * For use in {@link #broadcast(net.kyori.adventure.text.Component, java.lang.String)}.
*/
public static final String BROADCAST_CHANNEL_USERS = "bukkit.broadcast.user";
@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient {
*
* @param message the message
* @return the number of players
+ * @deprecated use {@code sendMessage} methods that accept {@link net.kyori.adventure.text.Component}
+ * @deprecated use {@link #broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public int broadcastMessage(@NotNull String message);
@ -1061,6 +1089,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public int broadcast(@NotNull String message, @NotNull String permission);
+ // Paper start
+ /**
+ * Broadcast a message to all players.
+ * <p>
+ * This is the same as calling {@link #broadcast(net.kyori.adventure.text.Component,
+ * java.lang.String)} with the {@link #BROADCAST_CHANNEL_USERS} permission.
+ *
+ * @param message the message
+ * @return the number of players
+ */
+ int broadcast(@NotNull net.kyori.adventure.text.Component message);
+
+ /**
+ * Broadcasts the specified message to every user with the given
+ * permission name.
+ *
@ -1152,6 +1191,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@NotNull
Inventory createInventory(@Nullable InventoryHolder owner, int size, @NotNull String title) throws IllegalArgumentException;
+ // Paper start
/**
* Creates an empty merchant.
*
@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient {
* when the merchant inventory is viewed
* @return a new merchant
*/
+ @NotNull Merchant createMerchant(@Nullable net.kyori.adventure.text.Component title);
+ // Paper start
+ /**
+ * Creates an empty merchant.
@ -1159,17 +1207,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param title the title of the corresponding merchant inventory, displayed
+ * when the merchant inventory is viewed
+ * @return a new merchant
+ */
+ @NotNull Merchant createMerchant(@Nullable net.kyori.adventure.text.Component title);
+ // Paper start
/**
* Creates an empty merchant.
*
* @param title the title of the corresponding merchant inventory, displayed
* when the merchant inventory is viewed
* @return a new merchant
+ * @deprecated in favour of {@link #createMerchant(net.kyori.adventure.text.Component)}
*/
+ */
@NotNull
+ @Deprecated // Paper
Merchant createMerchant(@Nullable String title);
@ -1221,7 +1260,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* Sends the component to the player
*
* @param component the components to send
+ * @deprecated use {@code sendMessage} methods that accept {@link net.kyori.adventure.text.Component}
+ * @deprecated use {@link #broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public void broadcast(@NotNull net.md_5.bungee.api.chat.BaseComponent component) {
@ -1231,7 +1270,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
* Sends an array of components as a single message to the player
*
* @param components the components to send
+ * @deprecated use {@code sendMessage} methods that accept {@link net.kyori.adventure.text.Component}
+ * @deprecated use {@link #broadcast(net.kyori.adventure.text.Component)}
*/
+ @Deprecated // Paper
public void broadcast(@NotNull net.md_5.bungee.api.chat.BaseComponent... components) {

View File

@ -1693,8 +1693,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ @Deprecated // Paper start
public int broadcastMessage(String message) {
- return broadcast(message, BROADCAST_CHANNEL_USERS);
+ this.sendMessage(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(message));
+ return this.getOnlinePlayers().size() + 1;
+ return this.broadcast(message, BROADCAST_CHANNEL_USERS);
+ // Paper end
}
@ -1726,6 +1725,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ @Override
+ public int broadcast(net.kyori.adventure.text.Component message) {
+ return this.broadcast(message, BROADCAST_CHANNEL_USERS);
+ }
+
+ @Override
+ public int broadcast(net.kyori.adventure.text.Component message, String permission) {
+ // Paper end
Set<CommandSender> recipients = new HashSet<>();
@ -1782,12 +1786,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
+ // Paper start
@Override
+ @Override
+ public Merchant createMerchant(net.kyori.adventure.text.Component title) {
+ return new org.bukkit.craftbukkit.inventory.CraftMerchantCustom(title == null ? InventoryType.MERCHANT.defaultTitle() : title);
+ }
+ // Paper end
+ @Override
@Override
+ @Deprecated // Paper
public Merchant createMerchant(String title) {
return new CraftMerchantCustom(title == null ? InventoryType.MERCHANT.getDefaultTitle() : title);