mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Why we were making this so complicated, I'll never know.
This commit is contained in:
parent
a8e23e08ee
commit
14eb473355
@ -2,8 +2,6 @@ package com.gmail.nossr50.skills.repair;
|
|||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.material.MaterialData;
|
|
||||||
|
|
||||||
import com.gmail.nossr50.config.AdvancedConfig;
|
import com.gmail.nossr50.config.AdvancedConfig;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
@ -53,65 +51,6 @@ public class Repair {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Search the inventory for an item and return the index.
|
|
||||||
*
|
|
||||||
* @param inventory PlayerInventory to scan
|
|
||||||
* @param itemId Item id to look for
|
|
||||||
* @return index location where the item was found, or -1 if not found
|
|
||||||
*/
|
|
||||||
protected static int findInInventory(PlayerInventory inventory, int itemId) {
|
|
||||||
int location = inventory.first(itemId);
|
|
||||||
|
|
||||||
// VALIDATE
|
|
||||||
if (inventory.getItem(location).getTypeId() == itemId) {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search the inventory for an item and return the index.
|
|
||||||
*
|
|
||||||
* @param inventory PlayerInventory to scan
|
|
||||||
* @param itemId Item id to look for
|
|
||||||
* @param metadata Metadata to look for
|
|
||||||
* @return index location where the item was found, or -1 if not found
|
|
||||||
*/
|
|
||||||
protected static int findInInventory(PlayerInventory inventory, int itemId, byte metadata) {
|
|
||||||
int location = -1;
|
|
||||||
|
|
||||||
ItemStack[] contents = inventory.getContents();
|
|
||||||
|
|
||||||
for (int i = 0; i < contents.length; i++) {
|
|
||||||
ItemStack item = contents[i];
|
|
||||||
|
|
||||||
if (item == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.getData().equals(new MaterialData(itemId, metadata))) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decrease the amount of items in this slot by one
|
|
||||||
*
|
|
||||||
* @param inventory PlayerInventory to work in
|
|
||||||
* @param index Item index to decrement
|
|
||||||
*/
|
|
||||||
protected static void removeOneFrom(PlayerInventory inventory, int index) {
|
|
||||||
ItemStack item = inventory.getItem(index).clone();
|
|
||||||
item.setAmount(1);
|
|
||||||
|
|
||||||
inventory.removeItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Material getSalvagedItem(ItemStack inHand) {
|
protected static Material getSalvagedItem(ItemStack inHand) {
|
||||||
if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) {
|
if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) {
|
||||||
return Material.DIAMOND;
|
return Material.DIAMOND;
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.enchantments.Enchantment;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
@ -79,17 +80,15 @@ public class RepairManager extends SkillManager {
|
|||||||
|
|
||||||
int repairMaterialId = repairable.getRepairMaterialId();
|
int repairMaterialId = repairable.getRepairMaterialId();
|
||||||
byte repairMaterialMetadata = repairable.getRepairMaterialMetadata();
|
byte repairMaterialMetadata = repairable.getRepairMaterialMetadata();
|
||||||
|
ItemStack toRemove = new MaterialData(repairMaterialId, repairMaterialMetadata).toItemStack(1);
|
||||||
|
|
||||||
// Check if they have the proper material to repair with
|
// Check if they have the proper material to repair with
|
||||||
if (!inventory.contains(repairMaterialId)) {
|
if (!inventory.containsAtLeast(toRemove, 1)) {
|
||||||
String message = LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(repairMaterialId));
|
String message = LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(repairMaterialId));
|
||||||
|
|
||||||
if (repairMaterialMetadata != (byte) -1) {
|
if (repairMaterialMetadata > 0) {
|
||||||
// TODO: Do something nicer than append the metadata as a :# ?
|
|
||||||
if (Repair.findInInventory(inventory, repairMaterialId, repairMaterialMetadata) == -1) {
|
|
||||||
message += ":" + repairMaterialMetadata;
|
message += ":" + repairMaterialMetadata;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
return;
|
return;
|
||||||
@ -117,24 +116,8 @@ public class RepairManager extends SkillManager {
|
|||||||
int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
|
int baseRepairAmount = repairable.getBaseRepairDurability(); // Did they send me daughters?
|
||||||
short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
|
short newDurability = repairCalculate(startDurability, baseRepairAmount); // When I asked for sons?
|
||||||
|
|
||||||
// We're going to hold onto our repair item location
|
|
||||||
int repairItemLocation;
|
|
||||||
if (repairable.getRepairMaterialMetadata() == (byte) -1) {
|
|
||||||
repairItemLocation = Repair.findInInventory(inventory, repairMaterialId);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Special case for when the repairable has metadata that must be addressed
|
|
||||||
repairItemLocation = Repair.findInInventory(inventory, repairMaterialId, repairMaterialMetadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should never happen, but if it does we need to complain loudly about it.
|
|
||||||
if (repairItemLocation == -1) {
|
|
||||||
player.sendMessage(LocaleLoader.getString("Repair.Error"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call event
|
// Call event
|
||||||
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (startDurability - newDurability), inventory.getItem(repairItemLocation), item);
|
McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (startDurability - newDurability), toRemove, item);
|
||||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
@ -147,7 +130,7 @@ public class RepairManager extends SkillManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove the item
|
// Remove the item
|
||||||
Repair.removeOneFrom(inventory, repairItemLocation);
|
inventory.removeItem(toRemove);
|
||||||
|
|
||||||
// Give out XP like candy
|
// Give out XP like candy
|
||||||
applyXpGain((float) ((getPercentageRepaired(startDurability, newDurability, repairable.getMaximumDurability()) * repairable.getXpMultiplier()) * ExperienceConfig.getInstance().getRepairXPBase() * ExperienceConfig.getInstance().getRepairXP(repairable.getRepairMaterialType())));
|
applyXpGain((float) ((getPercentageRepaired(startDurability, newDurability, repairable.getMaximumDurability()) * repairable.getXpMultiplier()) * ExperienceConfig.getInstance().getRepairXPBase() * ExperienceConfig.getInstance().getRepairXP(repairable.getRepairMaterialType())));
|
||||||
|
Loading…
Reference in New Issue
Block a user