Fixing a bug where repairing could leave items with the enchant effect but no enchantments.

This commit is contained in:
Glitchfinder 2012-12-31 16:04:17 -08:00
parent e607e04af4
commit 0e853d44b7

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.skills.repair;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
@ -108,6 +109,7 @@ public class Repair {
is.removeEnchantment(x);
}
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Lost"));
clearEnchantTag(is, player);
return;
}
@ -141,6 +143,7 @@ public class Repair {
if (newEnchants.isEmpty()) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Fail"));
clearEnchantTag(is, player);
}
else if (downgraded || newEnchants.size() < enchants.size()) {
player.sendMessage(LocaleLoader.getString("Repair.Arcane.Downgrade"));
@ -150,6 +153,33 @@ public class Repair {
}
}
private static void clearEnchantTag(ItemStack is, Player player) {
Object o;
Class c;
Field f;
o = is;
c = o.getClass();
try {
f = c.getDeclaredField("handle");
f.setAccessible(true);
o = f.get(o);
c = o.getClass();
f = c.getDeclaredField("tag");
o = f.get(o);
c = o.getClass();
f = c.getDeclaredField("map");
f.setAccessible(true);
Map tagMap = (Map) f.get(o);
tagMap.remove("ench");
}
catch(Exception e) {}
}
/**
* Gets chance of keeping enchantment during repair.
*