Skip to content

Commit f400479

Browse files
committed
v11.2.0.1
* Removed all usage of the old XReflection within XSeries code. * Fixed a few issues with NMSExtras. * Due to people reporting "NMS_VERSION" from getVersionInformation() returning null, it was changed to "Unknown NMS" instead. * Fixed an issue where trying to reflect a class handle with no names provided didn't provide a proper error.
1 parent 7727233 commit f400479

File tree

8 files changed

+215
-82
lines changed

8 files changed

+215
-82
lines changed

pom.xml

Lines changed: 4 additions & 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>11.2.0</version>
9+
<version>11.2.0.1</version>
1010

1111
<name>XSeries</name>
1212
<description>A set of utilities for Minecraft plugins</description>
@@ -74,6 +74,9 @@
7474
<!-- https://repo.codemc.io/service/rest/repository/browse/nms/org/spigotmc/spigot/ -->
7575
<!-- 1.8.8-R0.1-SNAPSHOT -->
7676
<!-- 1.9.4-R0.1-SNAPSHOT -->
77+
<!-- 1.10.2-R0.1-SNAPSHOT -->
78+
<!-- 1.11.2-R0.1-SNAPSHOT -->
79+
<!-- 1.12.2-R0.1-SNAPSHOT -->
7780
<!-- 1.13.2-R0.1-SNAPSHOT -->
7881
<!-- 1.14.4-R0.1-SNAPSHOT -->
7982
<!-- 1.15.2-R0.1-SNAPSHOT -->

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cryptomorin.xseries;
22

3+
import com.cryptomorin.xseries.reflection.XReflection;
34
import com.cryptomorin.xseries.reflection.minecraft.MinecraftClassHandle;
45
import com.cryptomorin.xseries.reflection.minecraft.MinecraftConnection;
56
import com.cryptomorin.xseries.reflection.minecraft.MinecraftMapping;
@@ -307,10 +308,13 @@ public BorderBounds() {
307308
try {
308309
wbType = Class.forName("EnumWorldBorderAction");
309310
} catch (ClassNotFoundException e) {
310-
wbType = getNMSClass("PacketPlayOutWorldBorder$EnumWorldBorderAction");
311+
wbType = XReflection.ofMinecraft().inPackage(MinecraftPackage.NMS)
312+
.named("PacketPlayOutWorldBorder$EnumWorldBorderAction").unreflect();
311313
}
312314

313-
packetInit = lookup.findConstructor(getNMSClass("PacketPlayOutWorldBorder"), MethodType.methodType(void.class, wb.reflect(), wbType));
315+
packetInit = lookup.findConstructor(XReflection.ofMinecraft().inPackage(MinecraftPackage.NMS)
316+
.named("PacketPlayOutWorldBorder").unreflect(),
317+
MethodType.methodType(void.class, wb.reflect(), wbType));
314318

315319
for (Object type : wbType.getEnumConstants()) {
316320
if (type.toString().equals("INITIALIZE")) {

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import com.cryptomorin.xseries.reflection.XReflection;
2525
import com.cryptomorin.xseries.reflection.minecraft.MinecraftConnection;
26+
import com.cryptomorin.xseries.reflection.minecraft.MinecraftPackage;
2627
import com.google.common.base.Strings;
2728
import net.md_5.bungee.api.ChatMessageType;
2829
import net.md_5.bungee.api.chat.TextComponent;
@@ -94,10 +95,14 @@ public final class ActionBar {
9495

9596
if (!USE_SPIGOT_API) {
9697
// Supporting 1.12+ is not necessary, the package guards are just for readability.
98+
// Since these methods are old, we don't need to add Mojang mappings
9799
MethodHandles.Lookup lookup = MethodHandles.lookup();
98-
Class<?> packetPlayOutChatClass = getNMSClass("network.protocol.game", "PacketPlayOutChat");
99-
Class<?> iChatBaseComponentClass = getNMSClass("network.chat", "IChatBaseComponent");
100-
Class<?> ChatSerializerClass = getNMSClass("network.chat", "IChatBaseComponent$ChatSerializer");
100+
Class<?> packetPlayOutChatClass = ofMinecraft().inPackage(MinecraftPackage.NMS, "network.protocol.game")
101+
.named("PacketPlayOutChat").unreflect();
102+
Class<?> iChatBaseComponentClass = ofMinecraft().inPackage(MinecraftPackage.NMS, "network.chat")
103+
.named("IChatBaseComponent").unreflect();
104+
Class<?> ChatSerializerClass = ofMinecraft().inPackage(MinecraftPackage.NMS, "network.chat")
105+
.named("IChatBaseComponent$ChatSerializer").unreflect();
101106

102107
try {
103108
// JSON Message Builder
@@ -191,6 +196,7 @@ public static void sendActionBar(@Nonnull Player player, @Nullable String messag
191196
Objects.requireNonNull(message, "Cannot send null actionbar message");
192197

193198
if (USE_SPIGOT_API) {
199+
// noinspection deprecation
194200
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
195201
return;
196202
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,10 @@ public static void sendTabList(@Nonnull String header, @Nonnull String footer, P
322322
}
323323

324324
try {
325-
Class<?> IChatBaseComponent = XReflection.getNMSClass("network.chat", "IChatBaseComponent");
326-
Class<?> PacketPlayOutPlayerListHeaderFooter = XReflection.getNMSClass("network.protocol.game", "PacketPlayOutPlayerListHeaderFooter");
325+
Class<?> IChatBaseComponent = ofMinecraft().inPackage(MinecraftPackage.NMS, "network.chat")
326+
.named("IChatBaseComponent").unreflect();
327+
Class<?> PacketPlayOutPlayerListHeaderFooter = ofMinecraft().inPackage(MinecraftPackage.NMS, "network.protocol.game")
328+
.named("PacketPlayOutPlayerListHeaderFooter").unreflect();
327329

328330
Method chatComponentBuilderMethod = IChatBaseComponent.getDeclaredClasses()[0].getMethod("a", String.class);
329331
Object tabHeader = chatComponentBuilderMethod.invoke(null, "{\"text\":\"" + header + "\"}");

src/main/java/com/cryptomorin/xseries/reflection/XReflection.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
* <li>{@link #relativizeSuppressedExceptions(Throwable)}: Relativize the stacktrace of exceptions that are thrown from the same location.</li>
6666
* </ul>
6767
* @author Crypto Morin
68-
* @version 11.2.0
68+
* @version 11.2.1
6969
* @see com.cryptomorin.xseries.reflection.minecraft.MinecraftConnection
7070
* @see com.cryptomorin.xseries.reflection.minecraft.NMSExtras
7171
*/
@@ -196,12 +196,14 @@ public static String findNMSVersionString() {
196196

197197
/**
198198
* Gets the full version information of the server. Useful for including in errors.
199+
* "NMS" might return "Unknown NMS", which means that they're running a Paper
200+
* server that removed the CraftBukkit NMS version guard.
199201
*
200202
* @since 7.0.0
201203
*/
202204
public static String getVersionInformation() {
203205
// Bukkit.getServer().getMinecraftVersion() is for Paper
204-
return "(NMS: " + NMS_VERSION + " | " +
206+
return "(NMS: " + (NMS_VERSION == null ? "Unknown NMS" : NMS_VERSION) + " | " +
205207
"Parsed: " + MAJOR_NUMBER + '.' + MINOR_NUMBER + '.' + PATCH_NUMBER + " | " +
206208
"Minecraft: " + Bukkit.getVersion() + " | " +
207209
"Bukkit: " + Bukkit.getBukkitVersion() + ')';
@@ -501,6 +503,7 @@ public static <T, H extends ReflectiveHandle<T>> AggregateReflectiveHandle<T, H>
501503
*/
502504
@ApiStatus.Experimental
503505
public static <T extends Throwable> T relativizeSuppressedExceptions(T ex) {
506+
Objects.requireNonNull(ex, "Cannot relativize null exception");
504507
final StackTraceElement[] EMPTY_STACK_TRACE_ARRAY = new StackTraceElement[0];
505508
StackTraceElement[] mainStackTrace = ex.getStackTrace();
506509

@@ -565,6 +568,7 @@ private static <T extends Throwable> void throwException(Throwable exception) th
565568
* from complaining about non-terminating statements.
566569
*/
567570
public static RuntimeException throwCheckedException(Throwable exception) {
571+
Objects.requireNonNull(exception, "Cannot throw null exception");
568572
// The following commented statement is not needed because the exception was created somewhere else and the stacktrace reflects that.
569573
// exception.setStackTrace(Arrays.stream(exception.getStackTrace()).skip(1).toArray(StackTraceElement[]::new));
570574
throwException(exception);

src/main/java/com/cryptomorin/xseries/reflection/jvm/classes/DynamicClassHandle.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public String[] reflectClassNames() {
6161

6262
int i = 0;
6363
for (String className : this.classNames) {
64-
6564
@SuppressWarnings("NonConstantStringShouldBeStringBuffer")
6665
String clazz;
6766
if (parent == null) clazz = packageName + '.' + className;
@@ -86,9 +85,11 @@ public DynamicClassHandle clone() {
8685

8786
@Override
8887
public Class<?> reflect() throws ClassNotFoundException {
89-
ClassNotFoundException errors = null;
88+
String[] classNames = reflectClassNames();
89+
if (classNames.length == 0) throw new IllegalStateException("No class name specified for " + this);
9090

91-
for (String className : reflectClassNames()) {
91+
ClassNotFoundException errors = null;
92+
for (String className : classNames) {
9293
try {
9394
return Class.forName(className);
9495
} catch (ClassNotFoundException ex) {

0 commit comments

Comments
 (0)