Implement BossBarViewer on Player (#9332)

* Implement BossBarViewer on Player

Author: Riley Park <rileysebastianpark@gmail.com>

* Implement BossBar#viewers
This commit is contained in:
Bjarne Koll 2023-06-12 23:43:39 +02:00 committed by GitHub
parent de19eb8c4a
commit 87dfff4cfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 283 additions and 225 deletions

View file

@ -2043,15 +2043,15 @@ index f3afe67f0832cb828d25be3654518ff73a80b0e1..598abaa82c634178043a29f6caa6ac52
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d24ca556a 100644
index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..b7512fa8fa65a2832cd2123ef30b47cd102492cf 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -42,7 +42,28 @@ import org.jetbrains.annotations.Nullable;
@@ -42,7 +42,41 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a player, connected or not
*/
-public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginMessageRecipient {
+public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginMessageRecipient, net.kyori.adventure.identity.Identified { // Paper
+public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginMessageRecipient, net.kyori.adventure.identity.Identified, net.kyori.adventure.bossbar.BossBarViewer { // Paper
+
+ // Paper start
+ @Override
@ -2060,6 +2060,19 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
+ }
+
+ /**
+ * Gets an unmodifiable view of all known currently active bossbars.
+ * <p>
+ * <b>This currently only returns bossbars shown to the player via
+ * {@link #showBossBar(net.kyori.adventure.bossbar.BossBar)} and does not contain bukkit
+ * {@link org.bukkit.boss.BossBar} instances shown to the player.</b>
+ *
+ * @return an unmodifiable view of all known currently active bossbars
+ * @since 4.14.0
+ */
+ @Override
+ @org.jetbrains.annotations.UnmodifiableView @NotNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars();
+
+ /**
+ * Gets the "friendly" name to display of this player.
+ *
+ * @return the display name
@ -2076,7 +2089,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
/**
* {@inheritDoc}
@@ -59,7 +80,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -59,7 +93,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* places defined by plugins.
*
* @return the friendly name
@ -2086,7 +2099,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
@NotNull
public String getDisplayName();
@@ -71,15 +94,50 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -71,15 +107,50 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* places defined by plugins.
*
* @param name The new display name.
@ -2137,7 +2150,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public String getPlayerListName();
/**
@@ -88,14 +146,18 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -88,14 +159,18 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* If the value is null, the name will be identical to {@link #getName()}.
*
* @param name new player list name
@ -2156,7 +2169,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
@Nullable
public String getPlayerListHeader();
@@ -103,7 +165,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -103,7 +178,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* Gets the currently displayed player list footer for this player.
*
* @return player list header or null
@ -2166,7 +2179,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
@Nullable
public String getPlayerListFooter();
@@ -111,14 +175,18 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -111,14 +188,18 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* Sets the currently displayed player list header for this player.
*
* @param header player list header, null for empty
@ -2185,7 +2198,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void setPlayerListFooter(@Nullable String footer);
/**
@@ -127,7 +195,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -127,7 +208,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*
* @param header player list header, null for empty
* @param footer player list footer, null for empty
@ -2195,7 +2208,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void setPlayerListHeaderFooter(@Nullable String header, @Nullable String footer);
/**
@@ -165,9 +235,25 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -165,9 +248,25 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* Kicks player with custom kick message.
*
* @param message kick message
@ -2221,7 +2234,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
/**
* Says a message (or runs a command).
*
@@ -632,6 +718,90 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -632,6 +731,90 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*/
public void sendEquipmentChange(@NotNull LivingEntity entity, @NotNull Map<EquipmentSlot, ItemStack> items);
@ -2312,7 +2325,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
/**
* Send a sign change. This fakes a sign change packet for a user at
* a certain location. This will not actually change the world in any way.
@@ -646,7 +816,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -646,7 +829,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @param lines the new text on the sign or null to clear it
* @throws IllegalArgumentException if location is null
* @throws IllegalArgumentException if lines is non-null and has a length less than 4
@ -2322,7 +2335,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void sendSignChange(@NotNull Location loc, @Nullable String[] lines) throws IllegalArgumentException;
/**
@@ -665,7 +837,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -665,7 +850,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @throws IllegalArgumentException if location is null
* @throws IllegalArgumentException if dyeColor is null
* @throws IllegalArgumentException if lines is non-null and has a length less than 4
@ -2332,7 +2345,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void sendSignChange(@NotNull Location loc, @Nullable String[] lines, @NotNull DyeColor dyeColor) throws IllegalArgumentException;
/**
@@ -685,7 +859,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -685,7 +872,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @throws IllegalArgumentException if location is null
* @throws IllegalArgumentException if dyeColor is null
* @throws IllegalArgumentException if lines is non-null and has a length less than 4
@ -2342,7 +2355,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void sendSignChange(@NotNull Location loc, @Nullable String[] lines, @NotNull DyeColor dyeColor, boolean hasGlowingText) throws IllegalArgumentException;
/**
@@ -1181,6 +1357,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1181,6 +1370,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* pack correctly.
* </ul>
*
@ -2350,7 +2363,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
* @param url The URL from which the client will download the resource
* pack. The string must contain only US-ASCII characters and should
* be encoded as per RFC 1738.
@@ -1237,8 +1414,10 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1237,8 +1427,57 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @throws IllegalArgumentException Thrown if the hash is not 20 bytes
* long.
*/
@ -2358,25 +2371,6 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void setResourcePack(@NotNull String url, @Nullable byte[] hash, @Nullable String prompt);
+ // Paper start
/**
* Request that the player's client download and switch resource packs.
* <p>
@@ -1274,6 +1453,54 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @param hash The sha1 hash sum of the resource pack file which is used
* to apply a cached version of the pack directly without downloading
* if it is available. Hast to be 20 bytes long!
+ * @param prompt The optional custom prompt message to be shown to client.
+ * @throws IllegalArgumentException Thrown if the URL is null.
+ * @throws IllegalArgumentException Thrown if the URL is too long. The
+ * length restriction is an implementation specific arbitrary value.
+ * @throws IllegalArgumentException Thrown if the hash is not 20 bytes
+ * long.
+ */
+ default void setResourcePack(@NotNull String url, byte @Nullable [] hash, net.kyori.adventure.text.@Nullable Component prompt) {
+ this.setResourcePack(url, hash, prompt, false);
+ }
+ // Paper end
+
+ /**
+ * Request that the player's client download and switch resource packs.
+ * <p>
@ -2406,17 +2400,36 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
+ * pack correctly.
+ * </ul>
+ *
+ * @deprecated in favour of {@link #setResourcePack(String, byte[], Component, boolean)}
+ * @param url The URL from which the client will download the resource
+ * pack. The string must contain only US-ASCII characters and should
+ * be encoded as per RFC 1738.
+ * @param hash The sha1 hash sum of the resource pack file which is used
+ * to apply a cached version of the pack directly without downloading
+ * if it is available. Hast to be 20 bytes long!
* @param force If true, the client will be disconnected from the server
* when it declines to use the resource pack.
* @throws IllegalArgumentException Thrown if the URL is null.
@@ -1328,8 +1555,57 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
+ * @param prompt The optional custom prompt message to be shown to client.
+ * @throws IllegalArgumentException Thrown if the URL is null.
+ * @throws IllegalArgumentException Thrown if the URL is too long. The
+ * length restriction is an implementation specific arbitrary value.
+ * @throws IllegalArgumentException Thrown if the hash is not 20 bytes
+ * long.
+ */
+ default void setResourcePack(@NotNull String url, byte @Nullable [] hash, net.kyori.adventure.text.@Nullable Component prompt) {
+ this.setResourcePack(url, hash, prompt, false);
+ }
+ // Paper end
+
/**
* Request that the player's client download and switch resource packs.
* <p>
@@ -1268,6 +1507,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* pack correctly.
* </ul>
*
+ * @deprecated in favour of {@link #setResourcePack(String, byte[], Component, boolean)}
* @param url The URL from which the client will download the resource
* pack. The string must contain only US-ASCII characters and should
* be encoded as per RFC 1738.
@@ -1328,8 +1568,57 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @throws IllegalArgumentException Thrown if the hash is not 20 bytes
* long.
*/
@ -2474,7 +2487,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
/**
* Gets the Scoreboard displayed to this player
*
@@ -1445,7 +1721,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1445,7 +1734,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*
* @param title Title text
* @param subtitle Subtitle text
@ -2483,7 +2496,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
*/
@Deprecated
public void sendTitle(@Nullable String title, @Nullable String subtitle);
@@ -1464,7 +1740,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1464,7 +1753,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @param fadeIn time in ticks for titles to fade in. Defaults to 10.
* @param stay time in ticks for titles to stay. Defaults to 70.
* @param fadeOut time in ticks for titles to fade out. Defaults to 20.
@ -2493,7 +2506,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void sendTitle(@Nullable String title, @Nullable String subtitle, int fadeIn, int stay, int fadeOut);
/**
@@ -1691,6 +1969,14 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1691,6 +1982,14 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*/
public int getClientViewDistance();
@ -2508,7 +2521,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
/**
* Gets the player's estimated ping in milliseconds.
*
@@ -1716,8 +2002,10 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1716,8 +2015,10 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* they wish.
*
* @return the player's locale
@ -2519,7 +2532,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public String getLocale();
/**
@@ -1769,6 +2057,14 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1769,6 +2070,14 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*/
public boolean isAllowingServerListings();
@ -2534,7 +2547,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
// Spigot start
public class Spigot extends Entity.Spigot {
@@ -1800,11 +2096,13 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1800,11 +2109,13 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
throw new UnsupportedOperationException("Not supported yet.");
}
@ -2548,7 +2561,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
@Override
public void sendMessage(@NotNull net.md_5.bungee.api.chat.BaseComponent... components) {
throw new UnsupportedOperationException("Not supported yet.");
@@ -1815,7 +2113,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1815,7 +2126,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*
* @param position the screen position
* @param component the components to send
@ -2558,7 +2571,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void sendMessage(@NotNull net.md_5.bungee.api.ChatMessageType position, @NotNull net.md_5.bungee.api.chat.BaseComponent component) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -1825,7 +2125,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1825,7 +2138,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*
* @param position the screen position
* @param components the components to send
@ -2568,7 +2581,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void sendMessage(@NotNull net.md_5.bungee.api.ChatMessageType position, @NotNull net.md_5.bungee.api.chat.BaseComponent... components) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -1836,7 +2138,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1836,7 +2151,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @param position the screen position
* @param sender the sender of the message
* @param component the components to send
@ -2578,7 +2591,7 @@ index 73e4d48cd2e424a7ecd6fc37d4c020aca7a6a726..1c072fbfdeb25a4fada75dcaa7cade4d
public void sendMessage(@NotNull net.md_5.bungee.api.ChatMessageType position, @Nullable java.util.UUID sender, @NotNull net.md_5.bungee.api.chat.BaseComponent component) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -1847,7 +2151,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
@@ -1847,7 +2164,9 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @param position the screen position
* @param sender the sender of the message
* @param components the components to send