Add NMS access to raw display name of items

This commit is contained in:
Marc Baloup 2024-03-05 18:09:18 +01:00
parent 33e4e053cf
commit c60fb613d4
3 changed files with 31 additions and 1 deletions

View File

@ -107,7 +107,7 @@ import fr.pandacube.lib.paper.reflect.NMSReflect.ClassMapping;
String classToPrint = type; String classToPrint = type;
String classSimpleName = classToPrint.substring(classToPrint.lastIndexOf('.') + 1); String classSimpleName = classToPrint.substring(classToPrint.lastIndexOf('.') + 1);
String htmlTitle = classSimpleName.equals(classToPrint) ? "" : (" title='" + classToPrint + "'"); String htmlTitle = classSimpleName.equals(classToPrint) ? "" : (" title='" + classToPrint + "'");
if (!htmlTitle.equals("")) { if (!htmlTitle.isEmpty()) {
typeHTML = "<span" + htmlTitle + " class='cl'>" + classSimpleName + "</span>"; typeHTML = "<span" + htmlTitle + " class='cl'>" + classSimpleName + "</span>";
} }
else { else {

View File

@ -3,6 +3,7 @@ package fr.pandacube.lib.paper.reflect;
import fr.pandacube.lib.paper.reflect.wrapper.brigadier.CommandNode; import fr.pandacube.lib.paper.reflect.wrapper.brigadier.CommandNode;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftItemStack; import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftItemStack;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftMapView; import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftMapView;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftMetaItem;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftNamespacedKey; import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftNamespacedKey;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftPlayer; import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftPlayer;
import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer; import fr.pandacube.lib.paper.reflect.wrapper.craftbukkit.CraftServer;
@ -111,6 +112,7 @@ public class PandalibPaperReflect {
// craftbukkit // craftbukkit
thAcc.catchThrowable(() -> initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftItemStack.class, CraftItemStack.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftMapView.class, CraftMapView.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftMapView.class, CraftMapView.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftMetaItem.class, CraftMetaItem.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftNamespacedKey.class, CraftNamespacedKey.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftPlayer.class, CraftPlayer.REFLECT.get()));
thAcc.catchThrowable(() -> initWrapper(CraftServer.class, CraftServer.REFLECT.get())); thAcc.catchThrowable(() -> initWrapper(CraftServer.class, CraftServer.REFLECT.get()));

View File

@ -0,0 +1,28 @@
package fr.pandacube.lib.paper.reflect.wrapper.craftbukkit;
import fr.pandacube.lib.paper.reflect.OBCReflect;
import fr.pandacube.lib.reflect.ReflectClass;
import fr.pandacube.lib.reflect.ReflectField;
import fr.pandacube.lib.reflect.wrapper.ReflectWrapperTyped;
import org.bukkit.inventory.meta.ItemMeta;
import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
import static fr.pandacube.lib.util.ThrowableUtil.wrapReflectEx;
public class CraftMetaItem extends ReflectWrapperTyped<ItemMeta> {
public static final ReflectClass<?> REFLECT = wrapEx(() -> OBCReflect.ofClass("inventory.CraftMetaItem"));
public static final ReflectField<?> displayName = wrapEx(() -> REFLECT.field("displayName"));
public String getRawDisplayName() {
return (String) wrapReflectEx(() -> displayName.getValue(__getRuntimeInstance()));
}
public void setRawDisplayName(String rawDisplayName) {
wrapReflectEx(() -> displayName.setValue(__getRuntimeInstance(), rawDisplayName));
}
protected CraftMetaItem(Object obj) {
super(obj);
}
}