Skip to content

Commit 81e444d

Browse files
committed
Mending fix
Fixes mending for /autodrops
1 parent 859cf17 commit 81e444d

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/main/java/us/thezircon/play/autopickup/listeners/BlockBreakEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public void run() {
208208

209209
}
210210

211-
private static int mend(ItemStack item, int xp) {
211+
public static int mend(ItemStack item, int xp) {
212212

213213
if (item.containsEnchantment(Enchantment.MENDING)) {
214214
ItemMeta meta = item.getItemMeta();

src/main/java/us/thezircon/play/autopickup/listeners/EntityDeathEventListener.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.Iterator;
1313
import java.util.List;
1414

15+
import static us.thezircon.play.autopickup.listeners.BlockBreakEventListener.mend;
16+
1517
public class EntityDeathEventListener implements Listener {
1618

1719
private static final AutoPickup PLUGIN = AutoPickup.getPlugin(AutoPickup.class);
@@ -42,9 +44,21 @@ public void onDeath(EntityDeathEvent e) {
4244

4345
if (PLUGIN.autopickup_list_mobs.contains(player)) {
4446

45-
// XP
46-
player.giveExp(e.getDroppedExp());
47-
e.setDroppedExp(0);
47+
// Mend Items & Give Player XP
48+
int xp = e.getDroppedExp();
49+
player.giveExp(xp); // Give player XP
50+
51+
// Mend
52+
mend(player.getInventory().getItemInMainHand(), xp);
53+
mend(player.getInventory().getItemInOffHand(), xp);
54+
ItemStack armor[] = player.getInventory().getArmorContents();
55+
for (ItemStack i : armor)
56+
{
57+
try {
58+
mend(i, xp);
59+
} catch (NullPointerException ignored) {}
60+
}
61+
e.setDroppedExp(0); // Remove default XP
4862

4963
// Drops
5064
Iterator<ItemStack> iter = e.getDrops().iterator();
Binary file not shown.

0 commit comments

Comments
 (0)