Skip to content

Commit 40e80c5

Browse files
committed
8.3.0
Titles: Tab list now supports multiple players. Tab list no longer colorizes messages and it doesn't replace the %player% short placeholder. XPotion: Removed SATURATION and SLOW_FALLING from DEBUFFs
1 parent 40031da commit 40e80c5

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.cryptomorin</groupId>
88
<artifactId>XSeries</artifactId>
9-
<version>8.2.0</version>
9+
<version>8.3.0</version>
1010

1111
<name>XSeries</name>
1212
<description>A set of utilities for Minecraft plugins</description>

src/main/java/com/cryptomorin/xseries/XPotion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public enum XPotion {
106106
* @since 1.1.0
107107
*/
108108
public static final Set<XPotion> DEBUFFS = Collections.unmodifiableSet(EnumSet.of(
109-
BAD_OMEN, BLINDNESS, CONFUSION, HARM, HUNGER, LEVITATION, POISON, SATURATION,
110-
SLOW, SLOW_DIGGING, SLOW_FALLING, UNLUCK, WEAKNESS, WITHER)
109+
BAD_OMEN, BLINDNESS, CONFUSION, HARM, HUNGER, LEVITATION, POISON,
110+
SLOW, SLOW_DIGGING, UNLUCK, WEAKNESS, WITHER)
111111
);
112112

113113
private final PotionEffectType type;

src/main/java/com/cryptomorin/xseries/messages/Titles.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
package com.cryptomorin.xseries.messages;
2323

2424
import com.cryptomorin.xseries.ReflectionUtils;
25-
import com.google.common.base.Strings;
26-
import org.apache.commons.lang.StringUtils;
27-
import org.bukkit.ChatColor;
2825
import org.bukkit.configuration.ConfigurationSection;
2926
import org.bukkit.entity.Player;
3027

@@ -48,7 +45,7 @@
4845
* PacketPlayOutTitle: https://wiki.vg/Protocol#Title
4946
*
5047
* @author Crypto Morin
51-
* @version 2.0.0.1
48+
* @version 2.0.1
5249
* @see ReflectionUtils
5350
*/
5451
public final class Titles {
@@ -233,54 +230,58 @@ public static void clearTitle(@Nonnull Player player) {
233230
/**
234231
* Changes the tablist header and footer message for a player.
235232
* This is not fully completed as it's not used a lot.
233+
* <p>
234+
* Headers and footers cannot be null because the client will simply
235+
* ignore the packet.
236236
*
237-
* @param player the player to change the tablist for.
238-
* @param header the header of the tablist.
239-
* @param footer the footer of the tablist.
237+
* @param header the header of the tablist.
238+
* @param footer the footer of the tablist.
239+
* @param players players to send this change to.
240240
*
241+
* @return the packet.
241242
* @since 1.0.0
242243
*/
243-
public static void sendTabList(@Nonnull Player player, @Nullable String header, @Nullable String footer) {
244-
Objects.requireNonNull(player, "Cannot update tab for null player");
245-
header = Strings.isNullOrEmpty(header) ?
246-
"" : StringUtils.replace(ChatColor.translateAlternateColorCodes('&', header), "%player%", player.getDisplayName());
247-
footer = Strings.isNullOrEmpty(footer) ?
248-
"" : StringUtils.replace(ChatColor.translateAlternateColorCodes('&', footer), "%player%", player.getDisplayName());
244+
@Nonnull
245+
public static Object sendTabList(@Nonnull String header, @Nonnull String footer, Player... players) {
246+
Objects.requireNonNull(players, "Cannot send tab title to null players");
247+
Objects.requireNonNull(header, "Tab title header cannot be null");
248+
Objects.requireNonNull(footer, "Tab title footer cannot be null");
249249

250250
try {
251251
Class<?> IChatBaseComponent = ReflectionUtils.getNMSClass("network.chat", "IChatBaseComponent");
252-
Class<?> packetClass = ReflectionUtils.getNMSClass("network.protocol.game", "PacketPlayOutPlayerListHeaderFooter");
252+
Class<?> PacketPlayOutPlayerListHeaderFooter = ReflectionUtils.getNMSClass("network.protocol.game", "PacketPlayOutPlayerListHeaderFooter");
253253

254254
Method chatComponentBuilderMethod = IChatBaseComponent.getDeclaredClasses()[0].getMethod("a", String.class);
255255
Object tabHeader = chatComponentBuilderMethod.invoke(null, "{\"text\":\"" + header + "\"}");
256256
Object tabFooter = chatComponentBuilderMethod.invoke(null, "{\"text\":\"" + footer + "\"}");
257257

258258
Object packet;
259259
if (ReflectionUtils.supports(17)) {
260-
packet = packetClass.getConstructor(IChatBaseComponent, IChatBaseComponent).newInstance(tabHeader, tabFooter);
260+
packet = PacketPlayOutPlayerListHeaderFooter.getConstructor(IChatBaseComponent, IChatBaseComponent).newInstance(tabHeader, tabFooter);
261261
} else {
262-
packet = packetClass.getConstructor().newInstance();
262+
packet = PacketPlayOutPlayerListHeaderFooter.getConstructor().newInstance();
263263

264264
Field aField;
265265
Field bField;
266266
try {
267-
aField = packet.getClass().getDeclaredField("a");
268-
bField = packet.getClass().getDeclaredField("b");
267+
aField = PacketPlayOutPlayerListHeaderFooter.getDeclaredField("a");
268+
bField = PacketPlayOutPlayerListHeaderFooter.getDeclaredField("b");
269269
} catch (Exception ex) {
270-
aField = packet.getClass().getDeclaredField("header");
271-
bField = packet.getClass().getDeclaredField("footer");
270+
aField = PacketPlayOutPlayerListHeaderFooter.getDeclaredField("header");
271+
bField = PacketPlayOutPlayerListHeaderFooter.getDeclaredField("footer");
272272
}
273273

274274
aField.setAccessible(true);
275275
aField.set(packet, tabHeader);
276276

277277
bField.setAccessible(true);
278278
bField.set(packet, tabFooter);
279-
280279
}
281-
ReflectionUtils.sendPacket(player, packet);
280+
281+
for (Player player : players) ReflectionUtils.sendPacket(player, packet);
282+
return packet;
282283
} catch (Exception ex) {
283-
ex.printStackTrace();
284+
throw new RuntimeException(ex);
284285
}
285286
}
286287
}

0 commit comments

Comments
 (0)