Skip to content

Commit f5f4450

Browse files
committed
[publish] 6.0.12 Fix TellrawJson#hoverItem(ItemStack) & Fix XSkull
1 parent 9da35a7 commit f5f4450

File tree

6 files changed

+57
-33
lines changed

6 files changed

+57
-33
lines changed

module/module-lang/src/main/kotlin/taboolib/module/lang/ResourceReader.kt

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class ResourceReader(val clazz: Class<*>, val migrate: Boolean = true) {
6868
}
6969
}
7070

71-
@Suppress("SimplifiableCallChain")
7271
fun loadNodes(file: Configuration, nodesMap: HashMap<String, Type>, code: String) {
7372
migrateLegacyVersion(file)
7473
file.getKeys(false).forEach { node ->

module/module-nms-util/src/main/kotlin/taboolib/module/nms/NMSItem.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class NMSItemImpl : NMSItem() {
134134
val nmsItemStack = getNMSCopy(itemStack) as net.minecraft.server.v1_8_R3.ItemStack
135135
val nmsItem = nmsItemStack.item
136136
val name = nmsItem.getProperty<String>("name")!!
137-
name.toCharArray().joinToString { if (it.isUpperCase()) "_${it.lowercase()}" else it.toString() }
137+
name.toCharArray().joinToString("") { if (it.isUpperCase()) "_${it.lowercase()}" else it.toString() }
138138
}
139139
}
140140

platform/platform-bukkit/build.gradle.kts

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ dependencies {
2525
compileOnly(project(":module:module-configuration"))
2626
compileOnly("org.tabooproject.reflex:reflex:1.0.19")
2727
compileOnly("org.tabooproject.reflex:analyser:1.0.19")
28-
29-
compileOnly(fileTree("libs"))
3028
}
3129

3230
tasks {
-108 KB
Binary file not shown.

platform/platform-bukkit/src/main/java/taboolib/library/xseries/XSkull.java

+29-19
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
import com.google.common.collect.Lists;
2525
import com.mojang.authlib.GameProfile;
26-
import com.mojang.authlib.properties.Property;
2726
import java.lang.invoke.MethodType;
27+
28+
import com.mojang.authlib.properties.Property;
2829
import org.bukkit.Bukkit;
2930
import org.bukkit.OfflinePlayer;
3031
import org.bukkit.block.Block;
@@ -65,9 +66,10 @@
6566
* @see XMaterial
6667
*/
6768
public class XSkull {
69+
6870
protected static final MethodHandle
6971
CRAFT_META_SKULL_PROFILE_GETTER, CRAFT_META_SKULL_PROFILE_SETTER,
70-
CRAFT_META_SKULL_BLOCK_SETTER, PROPERTY_GETVALUE;
72+
CRAFT_META_SKULL_BLOCK_SETTER, PROPERTY_GET_VALUE;
7173

7274
/**
7375
* Some people use this without quotes surrounding the keys, not sure what that'd work.
@@ -91,7 +93,7 @@ public class XSkull {
9193
/**
9294
* In v1.20.2 there were some changes to the mojang API.
9395
*/
94-
private static final boolean NULLABILITY_RECORD_UPDATE = ReflectionUtils.VERSION.equals("v1_20_R2");
96+
private static final boolean NULLABILITY_RECORD_UPDATE = ReflectionUtils.VERSION.equals("v1_20_R2") || ReflectionUtils.supports(21);
9597

9698
/**
9799
* Does using a random UUID have any advantage?
@@ -106,10 +108,17 @@ public class XSkull {
106108
* get base64 information from player's UUID.
107109
*/
108110
private static final String TEXTURES = "https://textures.minecraft.net/texture/";
111+
private static final Class<?> CLASS_PROPERTY;
109112

110113
static {
114+
try {
115+
CLASS_PROPERTY = Class.forName("com.mojang.authlib.properties.Property");
116+
} catch (ClassNotFoundException e) {
117+
throw new RuntimeException(e);
118+
}
119+
111120
MethodHandles.Lookup lookup = MethodHandles.lookup();
112-
MethodHandle profileSetter = null, profileGetter = null, blockSetter = null, propGetval = null;
121+
MethodHandle profileSetter = null, profileGetter = null, blockSetter = null, propGetval = null, propConstructor = null;
113122

114123
try {
115124
Class<?> CraftMetaSkull = ReflectionUtils.getCraftClass("inventory.CraftMetaSkull");
@@ -139,16 +148,21 @@ public class XSkull {
139148
e.printStackTrace();
140149
}
141150

142-
if (!NULLABILITY_RECORD_UPDATE) {
151+
if (NULLABILITY_RECORD_UPDATE) {
143152
try {
144-
//noinspection JavaLangInvokeHandleSignature
145-
propGetval = lookup.findVirtual(Property.class, "getValue", MethodType.methodType(String.class));
153+
propGetval = lookup.findVirtual(CLASS_PROPERTY, "value", MethodType.methodType(String.class));
154+
} catch (Throwable ex) {
155+
ex.printStackTrace();
156+
}
157+
} else {
158+
try {
159+
propGetval = lookup.findVirtual(CLASS_PROPERTY, "getValue", MethodType.methodType(String.class));
146160
} catch (Throwable ex) {
147161
ex.printStackTrace();
148162
}
149163
}
150164

151-
PROPERTY_GETVALUE = propGetval;
165+
PROPERTY_GET_VALUE = propGetval;
152166
CRAFT_META_SKULL_PROFILE_SETTER = profileSetter;
153167
CRAFT_META_SKULL_PROFILE_GETTER = profileGetter;
154168
CRAFT_META_SKULL_BLOCK_SETTER = blockSetter;
@@ -310,7 +324,7 @@ public static ItemBuilder.SkullTexture getSkinValue(@NotNull ItemMeta skull) {
310324
} catch (Exception ignored) {
311325
}
312326
if (profile != null && !profile.getProperties().get("textures").isEmpty()) {
313-
for (Property property : profile.getProperties().get("textures")) {
327+
for (Object property : profile.getProperties().get("textures")) {
314328
String value = getPropertyValue(property);
315329
if (!value.isEmpty()) {
316330
return new ItemBuilder.SkullTexture(value, profile.getId());
@@ -321,19 +335,15 @@ public static ItemBuilder.SkullTexture getSkinValue(@NotNull ItemMeta skull) {
321335
}
322336

323337
/**
324-
* They changed {@link Property} to a Java record in 1.20.2
338+
* They changed Property to a Java record in 1.20.2
325339
*
326340
* @since 4.0.1
327341
*/
328-
private static String getPropertyValue(Property property) {
329-
if (NULLABILITY_RECORD_UPDATE) {
330-
return property.value();
331-
} else {
332-
try {
333-
return (String) PROPERTY_GETVALUE.invoke(property);
334-
} catch (Throwable e) {
335-
throw new RuntimeException(e);
336-
}
342+
private static String getPropertyValue(Object property) {
343+
try {
344+
return (String) PROPERTY_GET_VALUE.invoke(property);
345+
} catch (Throwable e) {
346+
throw new RuntimeException(e);
337347
}
338348
}
339349

platform/platform-bukkit/src/main/kotlin/taboolib/platform/util/BukkitTellrawJson.kt

+27-10
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,22 @@ fun ItemStack.toNMSKeyAndItemData(): Pair<String, String> {
1515
val nmsKey = try {
1616
type.key.key
1717
} catch (ex: NoSuchMethodError) {
18+
// #359
19+
// 错误的获取方式
20+
// val nmsItem = nmsItemStack.invokeMethod<Any>("getItem")!!
21+
// val name = nmsItem.getProperty<String>("name")!!
22+
// var key = ""
23+
// name.forEach { c ->
24+
// if (c.isUpperCase()) {
25+
// key += "_" + c.lowercase()
26+
// } else {
27+
// key += c
28+
// }
29+
// }
30+
// key
1831
val nmsItem = nmsItemStack.invokeMethod<Any>("getItem")!!
19-
val name = nmsItem.getProperty<String>("name")!!
20-
var key = ""
21-
name.forEach { c ->
22-
if (c.isUpperCase()) {
23-
key += "_" + c.lowercase()
24-
} else {
25-
key += c
26-
}
27-
}
28-
key
32+
val nmsKey = classNMSItem.getProperty<Any>("REGISTRY", isStatic = true)!!.invokeMethod<Any>("b", nmsItem)!!
33+
nmsKey.invokeMethod<String>("getKey")!!
2934
}
3035
return nmsKey to (nmsItemStack.invokeMethod<Any>("getTag")?.toString() ?: "{}")
3136
}
@@ -44,6 +49,18 @@ private val classCraftItemStack by unsafeLazy {
4449
obcClassLegacy("inventory.CraftItemStack")
4550
}
4651

52+
private val classCraftMagicNumbers by unsafeLazy {
53+
obcClassLegacy("util.CraftMagicNumbers")
54+
}
55+
56+
private val classNMSItem by unsafeLazy {
57+
nmsClassLegacy("Item")
58+
}
59+
4760
private fun obcClassLegacy(name: String): Class<*> {
4861
return Class.forName("org.bukkit.craftbukkit.${Bukkit.getServer().javaClass.name.split('.')[3]}.$name")
62+
}
63+
64+
private fun nmsClassLegacy(name: String): Class<*> {
65+
return Class.forName("net.minecraft.server.${Bukkit.getServer().javaClass.name.split('.')[3]}.$name")
4966
}

0 commit comments

Comments
 (0)