Skip to content

Commit e4a6ba7

Browse files
committed
fix(UnbreakableRune): fix runes not work on items without ItemMeta, resolve #32
1 parent b5ee826 commit e4a6ba7

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

pom.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
</properties>
1515

1616
<repositories>
17+
1718
<repository>
18-
<id>paper-repo</id>
19-
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
19+
<id>papermc</id>
20+
<url>https://repo.papermc.io/repository/maven-public/</url>
2021
</repository>
2122

2223
<repository>
@@ -108,16 +109,16 @@
108109

109110
<dependencies>
110111
<dependency>
111-
<groupId>org.spigotmc</groupId>
112-
<artifactId>spigot-api</artifactId>
113-
<version>1.19.4-R0.1-SNAPSHOT</version>
112+
<groupId>io.papermc.paper</groupId>
113+
<artifactId>paper-api</artifactId>
114+
<version>1.20.4-R0.1-SNAPSHOT</version>
114115
<scope>provided</scope>
115116
</dependency>
116117

117118
<dependency>
118-
<groupId>com.github.StarWishsama</groupId>
119+
<groupId>com.github.SlimefunGuguProject</groupId>
119120
<artifactId>Slimefun4</artifactId>
120-
<version>2024.3</version>
121+
<version>2025.1</version>
121122
<scope>provided</scope>
122123
</dependency>
123124

src/main/java/me/gallowsdove/foxymachines/implementation/consumables/UnbreakableRune.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ItemDropHandler getItemHandler() {
6767
return (e, p, item) -> {
6868
if (isItem(item.getItemStack())) {
6969

70-
if (!SlimefunUtils.canPlayerUseItem(p, Items.UNBREAKABLE_RUNE , true)) {
70+
if (!SlimefunUtils.canPlayerUseItem(p, Items.UNBREAKABLE_RUNE, true)) {
7171
return true;
7272
}
7373

@@ -90,21 +90,19 @@ private void activate(@Nonnull Player p, @Nonnull Item rune) {
9090

9191
if (optional.isPresent()) {
9292
Item item = (Item) optional.get();
93-
ItemStack itemStack = item.getItemStack();
93+
ItemStack itemStack = item.getItemStack().clone();
9494

9595
if (itemStack.getAmount() == 1) {
9696
l.getWorld().strikeLightningEffect(l);
9797

9898
Scheduler.run(10, () -> {
99-
if (rune.isValid() && item.isValid() && itemStack.getAmount() == 1) {
100-
99+
if (rune.isValid() && item.isValid() && itemStack.getAmount() == 1 && setUnbreakable(itemStack)) {
101100
l.getWorld().createExplosion(l, 0);
102101
l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1);
103102

104103
item.remove();
105104
rune.remove();
106105

107-
setUnbreakable(itemStack);
108106
l.getWorld().dropItemNaturally(l, itemStack);
109107

110108
p.sendMessage(ChatColor.LIGHT_PURPLE + "你的物品已经不可破坏了");
@@ -127,16 +125,20 @@ private boolean findCompatibleItem(Player player, Entity entity) {
127125
return false;
128126
}
129127

130-
public static void setUnbreakable(@Nullable ItemStack item) {
131-
if (item != null && item.getType() != Material.AIR) {
132-
133-
if (!isUnbreakable(item) && item.hasItemMeta()) {
134-
ItemMeta meta = item.getItemMeta();
128+
public static boolean setUnbreakable(@Nullable ItemStack item) {
129+
if (item == null || item.getType().isAir() || isUnbreakable(item)) {
130+
return false;
131+
}
135132

136-
meta.setUnbreakable(true);
137-
item.setItemMeta(meta);
138-
}
133+
ItemMeta meta = item.getItemMeta();
134+
// if no meta is returned, we cant proceed
135+
if (meta == null) {
136+
return false;
139137
}
138+
139+
meta.setUnbreakable(true);
140+
item.setItemMeta(meta);
141+
return true;
140142
}
141143

142144
public static boolean isUnbreakable(@Nullable ItemStack item) {

0 commit comments

Comments
 (0)