}
public void handleSalvage(Location location, ItemStack item) {
Player player = getPlayer();
Salvageable salvageable = mcMMO.getSalvageableManager().getSalvageable(item.getType());
// Permissions checks on material and item types
if (!Permissions.salvageItemType(player, salvageable.getSalvageItemType())) {
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return;
}
if (!Permissions.salvageMaterialType(player, salvageable.getSalvageMaterialType())) {
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return;
}
int skillLevel = getSkillLevel();
int minimumSalvageableLevel = salvageable.getMinimumLevel();
// Level check
if (skillLevel < minimumSalvageableLevel) {
player.sendMessage(LocaleLoader.getString("Salvage.Skills.Adept.Level", minimumSalvageableLevel, StringUtils.getPrettyItemString(item.getType())));
return;
}
if (item.getDurability() != 0 && (getSkillLevel() < Salvage.advancedSalvageUnlockLevel || !Permissions.advancedSalvage(player))) {
player.sendMessage(LocaleLoader.getString("Salvage.Skills.Adept.Damaged"));
return;
}
int salvageableAmount = Salvage.calculateSalvageableAmount(item.getDurability(), salvageable.getMaximumDurability(), salvageable.getMaximumQuantity());
if (salvageableAmount == 0) {
player.sendMessage(LocaleLoader.getString("Salvage.Skills.TooDamaged"));
return;
}
salvageableAmount = Math.max((int) (salvageableAmount * getMaxSalvagePercentage()), 1); // Always get at least something back, if you're capable of salvaging it.
player.setItemInHand(new ItemStack(Material.AIR));
location.add(0, 1, 0);
Map<Enchantment, Integer> enchants = item.getEnchantments();
if (!enchants.isEmpty()) {
ItemStack enchantBook = arcaneSalvageCheck(enchants);
if (enchantBook != null) {
Misc.dropItem(location, enchantBook);
}
}
byte salvageMaterialMetadata = (salvageable.getSalvageMaterialMetadata() != (byte) -1) ? salvageable.getSalvageMaterialMetadata() : 0;
Misc.dropItems(location, new MaterialData(salvageable.getSalvageMaterial(), salvageMaterialMetadata).toItemStack(salvageableAmount), 1);
// BWONG BWONG BWONG - CLUNK!
if (Config.getInstance().getSalvageAnvilUseSoundsEnabled()) {
player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);