mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-01 13:14:44 +02:00
Repairables can now specify multiple items that can be used for repairs
This commit is contained in:
@ -10,7 +10,7 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairable;
|
||||
import com.gmail.nossr50.util.EventUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -61,9 +61,11 @@ public class RepairManager extends SkillManager {
|
||||
togglePlacedAnvil();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void handleRepair(ItemStack item) {
|
||||
Player player = getPlayer();
|
||||
Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
|
||||
SimpleRepairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
|
||||
|
||||
if (item.getItemMeta().isUnbreakable()) {
|
||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Anvil.Unbreakable");
|
||||
@ -91,8 +93,15 @@ public class RepairManager extends SkillManager {
|
||||
}
|
||||
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
Material repairMaterial = null;
|
||||
|
||||
//Find the first compatible repair material
|
||||
for(Material repairMaterialCandidate : repairable.getRepairMaterials())
|
||||
{
|
||||
if(player.getInventory().contains(new ItemStack(repairMaterialCandidate)))
|
||||
repairMaterial = repairMaterialCandidate;
|
||||
}
|
||||
|
||||
Material repairMaterial = repairable.getRepairMaterial();
|
||||
//byte repairMaterialMetadata = repairable.getRepairMaterialMetadata();
|
||||
ItemStack toRemove = new ItemStack(repairMaterial);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
/*
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
@ -6,70 +7,89 @@ import org.bukkit.Material;
|
||||
|
||||
|
||||
public interface Repairable {
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the type of this repairable item
|
||||
*
|
||||
* @return the type of this repairable
|
||||
*/
|
||||
*//*
|
||||
|
||||
public Material getItemMaterial();
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the id of the material used to repair this item
|
||||
*
|
||||
* @return the id of the repair material
|
||||
*/
|
||||
public Material getRepairMaterial();
|
||||
*//*
|
||||
|
||||
/**
|
||||
public Material getRepairMaterials();
|
||||
|
||||
*/
|
||||
/**
|
||||
* Gets the RepairItemType value for this repairable item
|
||||
*
|
||||
* @return the RepairItemType for this repairable
|
||||
*/
|
||||
*//*
|
||||
|
||||
public ItemType getRepairItemType();
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the RepairMaterialType value for this repairable item
|
||||
*
|
||||
* @return the RepairMaterialType for this repairable
|
||||
*/
|
||||
*//*
|
||||
|
||||
public MaterialType getRepairMaterialType();
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the minimum quantity of repair materials ignoring all other repair bonuses
|
||||
*
|
||||
* This is typically set to the number of items needed to create that item, for example 5 for helmets or 2 for swords
|
||||
*
|
||||
* @return the minimum number of items
|
||||
*/
|
||||
*//*
|
||||
|
||||
public int getMinimumQuantity();
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the maximum durability of this item before it breaks
|
||||
*
|
||||
* @return the maximum durability
|
||||
*/
|
||||
*//*
|
||||
|
||||
public short getMaximumDurability();
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the base repair durability on which to calculate bonuses.
|
||||
*
|
||||
* This is actually the maximum durability divided by the minimum quantity
|
||||
*
|
||||
* @return the base repair durability
|
||||
*/
|
||||
*//*
|
||||
|
||||
public short getBaseRepairDurability();
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the minimum repair level needed to repair this item
|
||||
*
|
||||
* @return the minimum level to repair this item, or 0 for no minimum
|
||||
*/
|
||||
*//*
|
||||
|
||||
public int getMinimumLevel();
|
||||
|
||||
/**
|
||||
*/
|
||||
/**
|
||||
* Gets the xpMultiplier for this repairable
|
||||
*
|
||||
* @return the xpMultiplier of this repairable
|
||||
*/
|
||||
*//*
|
||||
|
||||
public double getXpMultiplier();
|
||||
}
|
||||
*/
|
||||
|
@ -6,41 +6,39 @@ import com.gmail.nossr50.util.ItemUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleRepairable implements Repairable {
|
||||
private final Material itemMaterial, repairMaterial;
|
||||
|
||||
public class SimpleRepairable {
|
||||
private final Material itemMaterial;
|
||||
private final List<Material> repairMaterials;
|
||||
private final int minimumQuantity, minimumLevel;
|
||||
private final short maximumDurability, baseRepairDurability;
|
||||
/*private String repairMaterialPrettyName;*/
|
||||
private final ItemType repairItemType;
|
||||
private final MaterialType repairMaterialType;
|
||||
private final double xpMultiplier;
|
||||
|
||||
/* protected SimpleRepairable(Material type, Material repairMaterial, String repairMaterialPrettyName, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
|
||||
this.itemMaterial = type;
|
||||
this.repairMaterial = repairMaterial;
|
||||
this.repairMaterialPrettyName = repairMaterialPrettyName;
|
||||
this.repairItemType = repairItemType;
|
||||
this.repairMaterialType = repairMaterialType;
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.minimumQuantity = minimumQuantity;
|
||||
this.maximumDurability = maximumDurability;
|
||||
this.baseRepairDurability = (short) (maximumDurability / minimumQuantity);
|
||||
this.xpMultiplier = xpMultiplier;
|
||||
}*/
|
||||
|
||||
public SimpleRepairable(Material itemMaterial, Material repairMaterial, int minimumQuantity, int minimumLevel, double xpMultiplier) {
|
||||
this.itemMaterial = itemMaterial;
|
||||
this.repairMaterial = repairMaterial;
|
||||
this(itemMaterial.getKey().getKey(), ItemUtils.getRepairItemMaterials(Arrays.asList(repairMaterial)), minimumQuantity, minimumLevel, xpMultiplier);
|
||||
}
|
||||
|
||||
public SimpleRepairable(Material itemMaterial, List<Material> repairMaterials, int minimumQuantity, int minimumLevel, double xpMultiplier) {
|
||||
this(itemMaterial.getKey().getKey(), ItemUtils.getRepairItemMaterials(repairMaterials), minimumQuantity, minimumLevel, xpMultiplier);
|
||||
}
|
||||
|
||||
public SimpleRepairable(String itemMaterial, List<String> repairMaterials, int minimumQuantity, int minimumLevel, double xpMultiplier) {
|
||||
this.itemMaterial = Material.matchMaterial(itemMaterial);
|
||||
this.repairMaterials = ItemUtils.matchMaterials(repairMaterials);
|
||||
this.minimumQuantity = minimumQuantity;
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.xpMultiplier = xpMultiplier;
|
||||
|
||||
this.maximumDurability = itemMaterial.getMaxDurability();
|
||||
this.maximumDurability = this.itemMaterial.getMaxDurability();
|
||||
this.baseRepairDurability = (short) (maximumDurability / minimumQuantity);
|
||||
|
||||
this.repairItemType = determineItemType(itemMaterial);
|
||||
this.repairMaterialType = determineMaterialType(repairMaterial);
|
||||
this.repairItemType = determineItemType(this.itemMaterial);
|
||||
this.repairMaterialType = determineMaterialType(this.repairMaterials.get(0));
|
||||
}
|
||||
|
||||
public MaterialType determineMaterialType(Material material) {
|
||||
@ -88,47 +86,43 @@ public class SimpleRepairable implements Repairable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getItemMaterial() {
|
||||
return itemMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getRepairMaterial() {
|
||||
return repairMaterial;
|
||||
public List<Material> getRepairMaterials() {
|
||||
return repairMaterials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRepairMaterialsRegistryKeys() {
|
||||
return ItemUtils.getRepairItemMaterials(repairMaterials);
|
||||
}
|
||||
|
||||
|
||||
public ItemType getRepairItemType() {
|
||||
return repairItemType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialType getRepairMaterialType() {
|
||||
return repairMaterialType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumQuantity() {
|
||||
return minimumQuantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getMaximumDurability() {
|
||||
return maximumDurability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getBaseRepairDurability() {
|
||||
return baseRepairDurability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumLevel() {
|
||||
return minimumLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getXpMultiplier() {
|
||||
return xpMultiplier;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class SimpleRepairableManager implements Unload {
|
||||
return isRepairable(itemStack.getType());
|
||||
}
|
||||
|
||||
public Repairable getRepairable(Material type) {
|
||||
public SimpleRepairable getRepairable(Material type) {
|
||||
return repairables.get(type);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user