Skip to content

Commit f8ff251

Browse files
EpicPlayerA10ybw0014WalshyDev
authored
Support 1.20.6 (#271)
* 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]>
1 parent baf2d79 commit f8ff251

File tree

14 files changed

+374
-38
lines changed

14 files changed

+374
-38
lines changed

dough-api/pom.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@
167167
<id>enginehub-repo</id>
168168
<url>https://maven.enginehub.org/repo/</url>
169169
</repository>
170-
<repository>
171-
<id>IntellectualSites</id>
172-
<url>https://mvn.intellectualsites.com/content/repositories/snapshots/</url>
173-
</repository>
174170
<repository>
175171
<id>funnyguilds-repo</id>
176172
<url>https://repo.panda-lang.org/releases</url>
@@ -415,6 +411,13 @@
415411
<artifactId>plugin</artifactId>
416412
<version>4.12.0</version>
417413
<scope>provided</scope>
414+
<exclusions>
415+
<!-- Exclude invalid dependency -->
416+
<exclusion>
417+
<groupId>com.github.PikaMug</groupId>
418+
<artifactId>LocaleLib</artifactId>
419+
</exclusion>
420+
</exclusions>
418421
</dependency>
419422

420423
<!-- HuskTowns -->

dough-items/src/main/java/io/github/bakedlibs/dough/items/ItemUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import javax.annotation.Nullable;
77

88
import org.bukkit.Material;
9+
import org.bukkit.NamespacedKey;
10+
import org.bukkit.Registry;
911
import org.bukkit.enchantments.Enchantment;
1012
import org.bukkit.inventory.ItemStack;
1113
import org.bukkit.inventory.meta.Damageable;
@@ -174,8 +176,8 @@ public static void damageItem(@Nonnull ItemStack item, int damage, boolean ignor
174176
if (item.getType() != Material.AIR && item.getAmount() > 0) {
175177
int remove = damage;
176178

177-
if (!ignoreEnchantments && item.getEnchantments().containsKey(Enchantment.DURABILITY)) {
178-
int level = item.getEnchantmentLevel(Enchantment.DURABILITY);
179+
if (!ignoreEnchantments && item.getEnchantments().containsKey(Registry.ENCHANTMENT.get(NamespacedKey.minecraft("unbreaking")))) {
180+
int level = item.getEnchantmentLevel(Registry.ENCHANTMENT.get(NamespacedKey.minecraft("unbreaking")));
179181

180182
for (int i = 0; i < damage; i++) {
181183
if (Math.random() * 100 <= (60 + Math.floorDiv(40, (level + 1)))) {

dough-items/src/main/java/io/github/bakedlibs/dough/items/nms/ItemNameAdapter.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.annotation.Nullable;
88
import javax.annotation.ParametersAreNonnullByDefault;
99

10+
import io.papermc.lib.PaperLib;
1011
import org.bukkit.inventory.ItemStack;
1112

1213
import io.github.bakedlibs.dough.common.DoughLogger;
@@ -20,11 +21,19 @@ public interface ItemNameAdapter {
2021

2122
public static @Nullable ItemNameAdapter get() {
2223
try {
23-
MinecraftVersion version = MinecraftVersion.get();
24-
2524
if (MinecraftVersion.isMocked()) {
2625
// Special case for MockBukkit
2726
return new ItemNameAdapterMockBukkit();
27+
}
28+
29+
MinecraftVersion version = MinecraftVersion.get();
30+
31+
if (version.isAtLeast(1, 20, 4) && PaperLib.isPaper()) {
32+
return new ItemNameAdapterPaper();
33+
}
34+
35+
if (version.isAtLeast(1, 20, 5)) {
36+
return new ItemNameAdapter20v5();
2837
} else if (version.isAtLeast(1, 20)) {
2938
return new ItemNameAdapter20();
3039
} else if (version.isAtLeast(1, 19)) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.github.bakedlibs.dough.items.nms;
2+
3+
import io.github.bakedlibs.dough.reflection.ReflectionUtils;
4+
import io.github.bakedlibs.dough.versions.UnknownServerVersionException;
5+
import org.bukkit.inventory.ItemStack;
6+
7+
import javax.annotation.ParametersAreNonnullByDefault;
8+
import java.lang.reflect.InvocationTargetException;
9+
import java.lang.reflect.Method;
10+
11+
class ItemNameAdapter20v5 implements ItemNameAdapter {
12+
13+
private final Method getCopy;
14+
private final Method getName;
15+
private final Method toString;
16+
17+
ItemNameAdapter20v5() throws NoSuchMethodException, SecurityException, ClassNotFoundException, UnknownServerVersionException {
18+
super();
19+
20+
getCopy = ReflectionUtils.getOBCClass("inventory.CraftItemStack").getMethod("asNMSCopy", ItemStack.class);
21+
getName = ReflectionUtils.getMethodOrAlternative(ReflectionUtils.getNetMinecraftClass("world.item.ItemStack"), "getDisplayName", "G");
22+
toString = ReflectionUtils.getMethod(ReflectionUtils.getNetMinecraftClass("network.chat.IChatBaseComponent"), "getString");
23+
}
24+
25+
@Override
26+
@ParametersAreNonnullByDefault
27+
public String getName(ItemStack item) throws IllegalAccessException, InvocationTargetException {
28+
Object instance = getCopy.invoke(null, item);
29+
return (String) toString.invoke(getName.invoke(instance));
30+
}
31+
32+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.bakedlibs.dough.items.nms;
2+
3+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
4+
import org.bukkit.Bukkit;
5+
import org.bukkit.inventory.ItemStack;
6+
7+
import javax.annotation.ParametersAreNonnullByDefault;
8+
import java.lang.reflect.InvocationTargetException;
9+
10+
public class ItemNameAdapterPaper implements ItemNameAdapter {
11+
@Override
12+
@ParametersAreNonnullByDefault
13+
public String getName(ItemStack item) throws IllegalAccessException, InvocationTargetException {
14+
return PlainTextComponentSerializer.plainText().serialize(Bukkit.getItemFactory().displayName(item));
15+
}
16+
}

0 commit comments

Comments
 (0)