-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support 1.20.6 and add paper adapters * remove space * reduce to one call * fix build due to funnyguilds invalid dependency * use registry instead of enum * fix: use old getter of property for older versions * Put paper adapter behind 1.19.4 gate The adapter is using adventure which was not bundled into Paper until 1.19.4 so to support it, we can only use this version or higher. * Disable paper head adapter --------- Co-authored-by: ybw0014 <[email protected]> Co-authored-by: Daniel Walsh <[email protected]>
- Loading branch information
1 parent
baf2d79
commit f8ff251
Showing
14 changed files
with
374 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
dough-items/src/main/java/io/github/bakedlibs/dough/items/nms/ItemNameAdapter20v5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.bakedlibs.dough.items.nms; | ||
|
||
import io.github.bakedlibs.dough.reflection.ReflectionUtils; | ||
import io.github.bakedlibs.dough.versions.UnknownServerVersionException; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
class ItemNameAdapter20v5 implements ItemNameAdapter { | ||
|
||
private final Method getCopy; | ||
private final Method getName; | ||
private final Method toString; | ||
|
||
ItemNameAdapter20v5() throws NoSuchMethodException, SecurityException, ClassNotFoundException, UnknownServerVersionException { | ||
super(); | ||
|
||
getCopy = ReflectionUtils.getOBCClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class); | ||
getName = ReflectionUtils.getMethodOrAlternative(ReflectionUtils.getNetMinecraftClass("world.item.ItemStack"), "getDisplayName", "G"); | ||
toString = ReflectionUtils.getMethod(ReflectionUtils.getNetMinecraftClass("network.chat.IChatBaseComponent"), "getString"); | ||
} | ||
|
||
@Override | ||
@ParametersAreNonnullByDefault | ||
public String getName(ItemStack item) throws IllegalAccessException, InvocationTargetException { | ||
Object instance = getCopy.invoke(null, item); | ||
return (String) toString.invoke(getName.invoke(instance)); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
dough-items/src/main/java/io/github/bakedlibs/dough/items/nms/ItemNameAdapterPaper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.bakedlibs.dough.items.nms; | ||
|
||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
public class ItemNameAdapterPaper implements ItemNameAdapter { | ||
@Override | ||
@ParametersAreNonnullByDefault | ||
public String getName(ItemStack item) throws IllegalAccessException, InvocationTargetException { | ||
return PlainTextComponentSerializer.plainText().serialize(Bukkit.getItemFactory().displayName(item)); | ||
} | ||
} |
Oops, something went wrong.