You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unit tests are now much more complete.
XTag
A class similar to Spigots XTag, but with more features and directly works with XSeries.
Note that this is a huge class. It's recommended that you exclude this from your project if you don't want to use it.
MaterialUtils
Removed in favor of XTag.
ReflectionUtils
Fixed an issue with 1.17
Attempted to fix a few issues with Bukkit-Forge servers.
XMaterial
Fixed an issue with Regex cache.
XSound
Added a method to stop a particular sound from XSound.Record
NMSExtras
Added support for 1.18 and fixed a small issue for 1.17
XPotion
If you're using this utility, you should consider recoding all those parts.
Most methods are renamed to a shorter and concise version.
Added a wrapper for PotionEffect for chances.
matchXPotion(PotionEffectType) is now extremely more efficient.
Copy file name to clipboardExpand all lines: src/main/java/com/cryptomorin/xseries/ReflectionUtils.java
+33-35Lines changed: 33 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
/*
2
2
* The MIT License (MIT)
3
3
*
4
-
* Copyright (c) 2021 Crypto Morin
4
+
* Copyright (c) 2022 Crypto Morin
5
5
*
6
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
* of this software and associated documentation files (the "Software"), to deal
@@ -46,7 +46,7 @@
46
46
* A useful resource used to compare mappings is <a href="https://minidigger.github.io/MiniMappingViewer/#/spigot">Mini's Mapping Viewer</a>
47
47
*
48
48
* @author Crypto Morin
49
-
* @version 6.0.0
49
+
* @version 6.0.1
50
50
*/
51
51
publicfinalclassReflectionUtils {
52
52
/**
@@ -59,7 +59,34 @@ public final class ReflectionUtils {
59
59
* <p>
60
60
* Performance is not a concern for these specific statically initialized values.
61
61
*/
62
-
publicstaticfinalStringVERSION = parseVersion();
62
+
publicstaticfinalStringVERSION;
63
+
64
+
static {
65
+
// This package loop is used to avoid implementation-dependant strings like Bukkit.getVersion() or Bukkit.getBukkitVersion()
66
+
// which allows easier testing as well.
67
+
Stringfound = null;
68
+
for (Packagepack : Package.getPackages()) {
69
+
Stringname = pack.getName();
70
+
if (name.startsWith("org.bukkit.craftbukkit.v") // .v because there are other packages.
71
+
// As a protection for forge+bukkit implementation that tend to mix versions.
72
+
// The real CraftPlayer should exist in the package.
73
+
// Note: Doesn't seem to function properly. Will need to separate the version
74
+
// handler for NMS and CraftBukkit for softwares like catmc.
75
+
&& name.endsWith("entity")) {
76
+
found = pack.getName().split("\\.")[3];
77
+
78
+
// Just a final guard to make sure it finds this important class.
79
+
try {
80
+
Class.forName("org.bukkit.craftbukkit." + found + ".entity.CraftPlayer");
81
+
break;
82
+
} catch (ClassNotFoundExceptione) {
83
+
found = null;
84
+
}
85
+
}
86
+
}
87
+
if (found == null) thrownewIllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
88
+
VERSION = found;
89
+
}
63
90
64
91
/**
65
92
* The raw minor version number.
@@ -99,9 +126,8 @@ public final class ReflectionUtils {
@@ -120,34 +146,6 @@ public final class ReflectionUtils {
120
146
121
147
privateReflectionUtils() {}
122
148
123
-
/**
124
-
* Gets the package version used for NMS. This method is preferred over
125
-
* <code>
126
-
* Bukkit.getServer().getClass().getPackage()
127
-
* Bukkit.getVersion()
128
-
* </code>
129
-
* because the first solution doesn't work with unit tests and the second version
130
-
* doesn't have the exact package version.
131
-
* <p>
132
-
* Performance doesn't matter here as the method is only called once.
133
-
*
134
-
* @return the exact package version.
135
-
* @see #VERSION
136
-
* @since 6.0.0
137
-
*/
138
-
privatestaticStringparseVersion() {
139
-
Stringfound = null;
140
-
for (Packagepack : Package.getPackages()) {
141
-
if (pack.getName().startsWith("org.bukkit.craftbukkit.v")) { // .v because there are other packages.
142
-
found = pack.getName().split("\\.")[3];
143
-
break;
144
-
}
145
-
}
146
-
147
-
if (found == null) thrownewIllegalArgumentException("Failed to parse server version. Could not find any package starting with name: 'org.bukkit.craftbukkit.v'");
0 commit comments