mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-27 11:14:44 +02:00
A whole bunch of more work to convert Salvage to a child skill
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
package com.gmail.nossr50.skills.repair;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
@ -12,5 +10,4 @@ public class Repair {
|
||||
public static double repairMasteryMaxBonus = AdvancedConfig.getInstance().getRepairMasteryMaxBonus();
|
||||
|
||||
public static Material anvilMaterial = Config.getInstance().getRepairAnvilMaterial();
|
||||
public static boolean anvilMessagesEnabled = Config.getInstance().getRepairAnvilMessagesEnabled();
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.skills.repair.ArcaneForging.Tier;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import com.gmail.nossr50.skills.salvage.Salvage;
|
||||
import com.gmail.nossr50.util.EventUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -30,8 +29,8 @@ import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
|
||||
public class RepairManager extends SkillManager {
|
||||
private boolean placedRepairAnvil;
|
||||
private int lastRepairClick;
|
||||
private boolean placedAnvil;
|
||||
private int lastClick;
|
||||
|
||||
public RepairManager(McMMOPlayer mcMMOPlayer) {
|
||||
super(mcMMOPlayer, SkillType.REPAIR);
|
||||
@ -39,23 +38,23 @@ public class RepairManager extends SkillManager {
|
||||
|
||||
/**
|
||||
* Handles notifications for placing an anvil.
|
||||
*
|
||||
* @param anvilType The {@link Material} of the anvil block
|
||||
*/
|
||||
public void placedAnvilCheck(Material anvilType) {
|
||||
public void placedAnvilCheck() {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (getPlacedAnvil(anvilType)) {
|
||||
if (getPlacedAnvil()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil"));
|
||||
if (Config.getInstance().getRepairAnvilMessagesEnabled()) {
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil"));
|
||||
}
|
||||
|
||||
if (Config.getInstance().getRepairAnvilPlaceSoundsEnabled()) {
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
}
|
||||
|
||||
togglePlacedAnvil(anvilType);
|
||||
togglePlacedAnvil();
|
||||
}
|
||||
|
||||
public void handleRepair(ItemStack item) {
|
||||
@ -63,12 +62,12 @@ public class RepairManager extends SkillManager {
|
||||
Repairable repairable = mcMMO.getRepairableManager().getRepairable(item.getType());
|
||||
|
||||
// Permissions checks on material and item types
|
||||
if (!repairable.getRepairItemType().getPermissions(player)) {
|
||||
if (!Permissions.repairMaterialType(player, repairable.getRepairMaterialType())) {
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!repairable.getRepairMaterialType().getPermissions(player)) {
|
||||
if (!Permissions.repairMaterialType(player, repairable.getRepairMaterialType())) {
|
||||
player.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
|
||||
return;
|
||||
}
|
||||
@ -161,9 +160,9 @@ public class RepairManager extends SkillManager {
|
||||
*
|
||||
* @return true if the player has confirmed using an Anvil
|
||||
*/
|
||||
public boolean checkConfirmation(Material anvilType, boolean actualize) {
|
||||
public boolean checkConfirmation(boolean actualize) {
|
||||
Player player = getPlayer();
|
||||
long lastUse = getLastAnvilUse(anvilType);
|
||||
long lastUse = getLastAnvilUse();
|
||||
|
||||
if (!SkillUtils.cooldownExpired(lastUse, 3) || !Config.getInstance().getRepairConfirmRequired()) {
|
||||
return true;
|
||||
@ -173,14 +172,8 @@ public class RepairManager extends SkillManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
actualizeLastAnvilUse(anvilType);
|
||||
|
||||
if (anvilType == Repair.anvilMaterial) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.ConfirmOrCancel", LocaleLoader.getString("Repair.Pretty.Name")));
|
||||
}
|
||||
else if (anvilType == Salvage.anvilMaterial) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.ConfirmOrCancel", LocaleLoader.getString("Salvage.Pretty.Name")));
|
||||
}
|
||||
actualizeLastAnvilUse();
|
||||
player.sendMessage(LocaleLoader.getString("Skills.ConfirmOrCancel", LocaleLoader.getString("Repair.Pretty.Name")));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -339,41 +332,27 @@ public class RepairManager extends SkillManager {
|
||||
* Repair Anvil Placement
|
||||
*/
|
||||
|
||||
public boolean getPlacedAnvil(Material anvilType) {
|
||||
if (anvilType == Repair.anvilMaterial) {
|
||||
return placedRepairAnvil;
|
||||
}
|
||||
|
||||
return true;
|
||||
public boolean getPlacedAnvil() {
|
||||
return placedAnvil;
|
||||
}
|
||||
|
||||
public void togglePlacedAnvil(Material anvilType) {
|
||||
if (anvilType == Repair.anvilMaterial) {
|
||||
placedRepairAnvil = !placedRepairAnvil;
|
||||
}
|
||||
public void togglePlacedAnvil() {
|
||||
placedAnvil = !placedAnvil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Repair Anvil Usage
|
||||
*/
|
||||
|
||||
public int getLastAnvilUse(Material anvilType) {
|
||||
if (anvilType == Repair.anvilMaterial) {
|
||||
return lastRepairClick;
|
||||
}
|
||||
|
||||
return 0;
|
||||
public int getLastAnvilUse() {
|
||||
return lastClick;
|
||||
}
|
||||
|
||||
public void setLastAnvilUse(Material anvilType, int value) {
|
||||
if (anvilType == Repair.anvilMaterial) {
|
||||
lastRepairClick = value;
|
||||
}
|
||||
public void setLastAnvilUse(int value) {
|
||||
lastClick = value;
|
||||
}
|
||||
|
||||
public void actualizeLastAnvilUse(Material anvilType) {
|
||||
if (anvilType == Repair.anvilMaterial) {
|
||||
lastRepairClick = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
public void actualizeLastAnvilUse() {
|
||||
lastClick = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public enum RepairItemType {
|
||||
ARMOR,
|
||||
TOOL,
|
||||
OTHER;
|
||||
|
||||
/**
|
||||
* Get the base permissions associated with this RepairItemType.
|
||||
*
|
||||
* @param player The player to check the permissions for
|
||||
* @return true if the player has permissions, false otherwise
|
||||
*/
|
||||
public boolean getPermissions(Player player) {
|
||||
switch (this) {
|
||||
case ARMOR:
|
||||
return Permissions.repairArmor(player);
|
||||
|
||||
case TOOL:
|
||||
return Permissions.repairTools(player);
|
||||
|
||||
case OTHER:
|
||||
return Permissions.repairOtherItems(player);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public enum RepairMaterialType {
|
||||
STRING,
|
||||
LEATHER,
|
||||
WOOD,
|
||||
STONE,
|
||||
IRON,
|
||||
GOLD,
|
||||
DIAMOND,
|
||||
OTHER;
|
||||
|
||||
/**
|
||||
* Get the base permissions associated with this RepairMaterialType.
|
||||
*
|
||||
* @param player The player to check the permissions for
|
||||
*
|
||||
* @return true if the player has permissions, false otherwise
|
||||
*/
|
||||
public boolean getPermissions(Player player) {
|
||||
switch (this) {
|
||||
case STRING:
|
||||
return Permissions.repairString(player);
|
||||
|
||||
case LEATHER:
|
||||
return Permissions.repairLeather(player);
|
||||
|
||||
case WOOD:
|
||||
return Permissions.repairWood(player);
|
||||
|
||||
case STONE:
|
||||
return Permissions.repairStone(player);
|
||||
|
||||
case IRON:
|
||||
return Permissions.repairIron(player);
|
||||
|
||||
case GOLD:
|
||||
return Permissions.repairGold(player);
|
||||
|
||||
case DIAMOND:
|
||||
return Permissions.repairDiamond(player);
|
||||
|
||||
case OTHER:
|
||||
return Permissions.repairOtherMaterials(player);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Material getDefaultRepairMaterial() {
|
||||
switch (this) {
|
||||
case STRING:
|
||||
return Material.STRING;
|
||||
|
||||
case LEATHER:
|
||||
return Material.LEATHER;
|
||||
|
||||
case WOOD:
|
||||
return Material.WOOD;
|
||||
|
||||
case STONE:
|
||||
return Material.COBBLESTONE;
|
||||
|
||||
case IRON:
|
||||
return Material.IRON_INGOT;
|
||||
|
||||
case GOLD:
|
||||
return Material.GOLD_INGOT;
|
||||
|
||||
case DIAMOND:
|
||||
return Material.DIAMOND;
|
||||
|
||||
case OTHER:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,9 @@ package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
|
||||
|
||||
public interface Repairable {
|
||||
/**
|
||||
@ -30,14 +33,14 @@ public interface Repairable {
|
||||
*
|
||||
* @return the RepairItemType for this repairable
|
||||
*/
|
||||
public RepairItemType getRepairItemType();
|
||||
public ItemType getRepairItemType();
|
||||
|
||||
/**
|
||||
* Gets the RepairMaterialType value for this repairable item
|
||||
*
|
||||
* @return the RepairMaterialType for this repairable
|
||||
*/
|
||||
public RepairMaterialType getRepairMaterialType();
|
||||
public MaterialType getRepairMaterialType();
|
||||
|
||||
/**
|
||||
* Gets the minimum quantity of repair materials ignoring all other repair bonuses
|
||||
|
@ -2,13 +2,16 @@ package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
|
||||
|
||||
public class RepairableFactory {
|
||||
public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumQuantity, short maximumDurability) {
|
||||
return getRepairable(itemMaterial, repairMaterial, repairMetadata, 0, minimumQuantity, maximumDurability, RepairItemType.OTHER, RepairMaterialType.OTHER, 1);
|
||||
return getRepairable(itemMaterial, repairMaterial, repairMetadata, 0, minimumQuantity, maximumDurability, ItemType.OTHER, MaterialType.OTHER, 1);
|
||||
}
|
||||
|
||||
public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, RepairItemType repairItemType, RepairMaterialType repairMaterialType, double xpMultiplier) {
|
||||
public static Repairable getRepairable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
|
||||
// TODO: Add in loading from config what type of repairable we want.
|
||||
return new SimpleRepairable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, minimumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
|
||||
}
|
||||
|
@ -2,17 +2,20 @@ package com.gmail.nossr50.skills.repair.repairables;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
|
||||
|
||||
public class SimpleRepairable implements Repairable {
|
||||
private final Material itemMaterial, repairMaterial;
|
||||
private final int minimumQuantity, minimumLevel;
|
||||
private final short maximumDurability, baseRepairDurability;
|
||||
private final byte repairMetadata;
|
||||
private final RepairItemType repairItemType;
|
||||
private final RepairMaterialType repairMaterialType;
|
||||
private final ItemType repairItemType;
|
||||
private final MaterialType repairMaterialType;
|
||||
private final double xpMultiplier;
|
||||
|
||||
protected SimpleRepairable(Material type, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, RepairItemType repairItemType, RepairMaterialType repairMaterialType, double xpMultiplier) {
|
||||
protected SimpleRepairable(Material type, Material repairMaterial, byte repairMetadata, int minimumLevel, int minimumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
|
||||
this.itemMaterial = type;
|
||||
this.repairMaterial = repairMaterial;
|
||||
this.repairMetadata = repairMetadata;
|
||||
@ -41,12 +44,12 @@ public class SimpleRepairable implements Repairable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepairItemType getRepairItemType() {
|
||||
public ItemType getRepairItemType() {
|
||||
return repairItemType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepairMaterialType getRepairMaterialType() {
|
||||
public MaterialType getRepairMaterialType() {
|
||||
return repairMaterialType;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.gmail.nossr50.skills.salvage;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
|
||||
public class Salvage {
|
||||
// The order of the values is extremely important, a few methods depend on it to work properly
|
||||
@ -53,58 +50,8 @@ public class Salvage {
|
||||
public static boolean arcaneSalvageDowngrades = AdvancedConfig.getInstance().getArcaneSalvageEnchantDowngradeEnabled();
|
||||
public static boolean arcaneSalvageEnchantLoss = AdvancedConfig.getInstance().getArcaneSalvageEnchantLossEnabled();
|
||||
|
||||
/**
|
||||
* Checks if the item is salvageable.
|
||||
*
|
||||
* @param item Item to check
|
||||
*
|
||||
* @return true if the item is salvageable, false otherwise
|
||||
*/
|
||||
public static boolean isSalvageable(ItemStack item) {
|
||||
if (Config.getInstance().getSalvageTools() && ItemUtils.isMinecraftTool(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Config.getInstance().getSalvageArmor() && !ItemUtils.isChainmailArmor(item) && ItemUtils.isMinecraftArmor(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static Material getSalvagedItem(ItemStack inHand) {
|
||||
if (ItemUtils.isDiamondTool(inHand) || ItemUtils.isDiamondArmor(inHand)) {
|
||||
return Material.DIAMOND;
|
||||
}
|
||||
else if (ItemUtils.isGoldTool(inHand) || ItemUtils.isGoldArmor(inHand)) {
|
||||
return Material.GOLD_INGOT;
|
||||
}
|
||||
else if (ItemUtils.isIronTool(inHand) || ItemUtils.isIronArmor(inHand)) {
|
||||
return Material.IRON_INGOT;
|
||||
}
|
||||
else if (ItemUtils.isStoneTool(inHand)) {
|
||||
return Material.COBBLESTONE;
|
||||
}
|
||||
else if (ItemUtils.isWoodTool(inHand)) {
|
||||
return Material.WOOD;
|
||||
}
|
||||
else if (ItemUtils.isLeatherArmor(inHand)) {
|
||||
return Material.LEATHER;
|
||||
}
|
||||
else if (ItemUtils.isStringTool(inHand)) {
|
||||
return Material.STRING;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected static int getSalvagedAmount(ItemStack inHand) {
|
||||
return SkillUtils.getRepairAndSalvageQuantities(inHand, getSalvagedItem(inHand), (byte) -1);
|
||||
}
|
||||
|
||||
protected static int calculateSalvageableAmount(short currentDurability, short maxDurability, int baseAmount) {
|
||||
double percentDamaged = (double) (maxDurability - currentDurability) / maxDurability;
|
||||
double percentDamaged = (maxDurability <= 0) ? 1D : (double) (maxDurability - currentDurability) / maxDurability;
|
||||
|
||||
return (int) Math.floor(baseAmount * percentDamaged);
|
||||
}
|
||||
|
@ -11,14 +11,20 @@ import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.skills.salvage.Salvage.Tier;
|
||||
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import com.gmail.nossr50.util.StringUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
|
||||
public class SalvageManager extends SkillManager {
|
||||
private boolean placedAnvil;
|
||||
@ -30,20 +36,23 @@ public class SalvageManager extends SkillManager {
|
||||
|
||||
/**
|
||||
* Handles notifications for placing an anvil.
|
||||
*
|
||||
* @param anvilType The {@link Material} of the anvil block
|
||||
*/
|
||||
public void placedAnvilCheck(Material anvilType) {
|
||||
public void placedAnvilCheck() {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (getPlacedAnvil(anvilType)) {
|
||||
if (getPlacedAnvil()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Salvage.Listener.Anvil"));
|
||||
if (Config.getInstance().getSalvageAnvilMessagesEnabled()) {
|
||||
player.sendMessage(LocaleLoader.getString("Salvage.Listener.Anvil"));
|
||||
}
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
togglePlacedAnvil(anvilType);
|
||||
if (Config.getInstance().getSalvageAnvilPlaceSoundsEnabled()) {
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_LAND, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
}
|
||||
|
||||
togglePlacedAnvil();
|
||||
}
|
||||
|
||||
public void handleSalvage(Location location, ItemStack item) {
|
||||
@ -53,20 +62,43 @@ public class SalvageManager extends SkillManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.getDurability() != 0 && (getSkillLevel() < Salvage.advancedSalvageUnlockLevel || !Permissions.advancedSalvage(player))) {
|
||||
player.sendMessage(LocaleLoader.getString("Salvage.Skills.AdeptDamaged"));
|
||||
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;
|
||||
}
|
||||
|
||||
int salvageableAmount = Salvage.calculateSalvageableAmount(item.getDurability(), item.getType().getMaxDurability(), Salvage.getSalvagedAmount(item));
|
||||
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;
|
||||
}
|
||||
|
||||
byte salvageMaterialMetadata = salvageable.getSalvageMaterialMetadata();
|
||||
|
||||
int salvageableAmount = Salvage.calculateSalvageableAmount(item.getDurability(), salvageable.getMaximumDurability(), salvageable.getMaximumQuantity());
|
||||
|
||||
if (salvageableAmount == 0) {
|
||||
player.sendMessage(LocaleLoader.getString("Salvage.Skills.TooDamaged"));
|
||||
return;
|
||||
}
|
||||
|
||||
double salvagePercentage = Math.min((((Salvage.salvageMaxPercentage / Salvage.salvageMaxPercentageLevel) * getSkillLevel()) / 100.0D), Salvage.salvageMaxPercentage / 100.0D);
|
||||
salvageableAmount = Math.max((int) (salvageableAmount * salvagePercentage), 1); // Always get at least something back, if you're capable of repairing it.
|
||||
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);
|
||||
@ -81,10 +113,19 @@ public class SalvageManager extends SkillManager {
|
||||
}
|
||||
}
|
||||
|
||||
Misc.dropItems(location, new ItemStack(Salvage.getSalvagedItem(item)), salvageableAmount);
|
||||
Misc.dropItems(location, new MaterialData(salvageable.getSalvageMaterial(), salvageMaterialMetadata).toItemStack(salvageableAmount), 1);
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_USE, Misc.ANVIL_USE_VOLUME, Misc.ANVIL_USE_PITCH);
|
||||
player.sendMessage(LocaleLoader.getString("Repair.Skills.SalvageSuccess"));
|
||||
// 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);
|
||||
}
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Salvage.Skills.Success"));
|
||||
}
|
||||
|
||||
public double getMaxSalvagePercentage() {
|
||||
return Math.min((((Salvage.salvageMaxPercentage / Salvage.salvageMaxPercentageLevel) * getSkillLevel()) / 100.0D), Salvage.salvageMaxPercentage / 100.0D);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,45 +215,56 @@ public class SalvageManager extends SkillManager {
|
||||
return book;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has tried to use an Anvil before.
|
||||
* @param actualize
|
||||
*
|
||||
* @return true if the player has confirmed using an Anvil
|
||||
*/
|
||||
public boolean checkConfirmation(boolean actualize) {
|
||||
Player player = getPlayer();
|
||||
long lastUse = getLastAnvilUse();
|
||||
|
||||
if (!SkillUtils.cooldownExpired(lastUse, 3) || !Config.getInstance().getSalvageConfirmRequired()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!actualize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
actualizeLastAnvilUse();
|
||||
|
||||
player.sendMessage(LocaleLoader.getString("Skills.ConfirmOrCancel", LocaleLoader.getString("Salvage.Pretty.Name")));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Salvage Anvil Placement
|
||||
*/
|
||||
|
||||
public boolean getPlacedAnvil(Material anvilType) {
|
||||
if (anvilType == Salvage.anvilMaterial) {
|
||||
return placedAnvil;
|
||||
}
|
||||
|
||||
return true;
|
||||
public boolean getPlacedAnvil() {
|
||||
return placedAnvil;
|
||||
}
|
||||
|
||||
public void togglePlacedAnvil(Material anvilType) {
|
||||
if (anvilType == Salvage.anvilMaterial) {
|
||||
placedAnvil = !placedAnvil;
|
||||
}
|
||||
public void togglePlacedAnvil() {
|
||||
placedAnvil = !placedAnvil;
|
||||
}
|
||||
|
||||
/*
|
||||
* Salvage Anvil Usage
|
||||
*/
|
||||
|
||||
public int getLastAnvilUse(Material anvilType) {
|
||||
if (anvilType == Salvage.anvilMaterial) {
|
||||
return lastClick;
|
||||
}
|
||||
|
||||
return 0;
|
||||
public int getLastAnvilUse() {
|
||||
return lastClick;
|
||||
}
|
||||
|
||||
public void setLastAnvilUse(Material anvilType, int value) {
|
||||
if (anvilType == Salvage.anvilMaterial) {
|
||||
lastClick = value;
|
||||
}
|
||||
public void setLastAnvilUse(int value) {
|
||||
lastClick = value;
|
||||
}
|
||||
|
||||
public void actualizeLastAnvilUse(Material anvilType) {
|
||||
if (anvilType == Salvage.anvilMaterial) {
|
||||
lastClick = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
public void actualizeLastAnvilUse() {
|
||||
lastClick = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,82 @@
|
||||
package com.gmail.nossr50.skills.salvage.salvageables;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
|
||||
public interface Salvageable {
|
||||
/**
|
||||
* 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 getSalvageMaterial();
|
||||
|
||||
/**
|
||||
* Gets the metadata byte value of the material used to repair this item
|
||||
*
|
||||
* @return the byte metadata of the repair material
|
||||
*/
|
||||
public byte getSalvageMaterialMetadata();
|
||||
|
||||
/**
|
||||
* Gets the RepairItemType value for this repairable item
|
||||
*
|
||||
* @return the RepairItemType for this repairable
|
||||
*/
|
||||
public ItemType getSalvageItemType();
|
||||
|
||||
/**
|
||||
* Gets the RepairMaterialType value for this repairable item
|
||||
*
|
||||
* @return the RepairMaterialType for this repairable
|
||||
*/
|
||||
public MaterialType getSalvageMaterialType();
|
||||
|
||||
/**
|
||||
* Gets the maximum quantity of salvage materials ignoring all other salvage 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 maximum number of items
|
||||
*/
|
||||
public int getMaximumQuantity();
|
||||
|
||||
/**
|
||||
* 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 getBaseSalvageDurability();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.gmail.nossr50.skills.salvage.salvageables;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
|
||||
public class SalvageableFactory {
|
||||
public static Salvageable getSalvageable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int maximumQuantity, short maximumDurability) {
|
||||
return getSalvageable(itemMaterial, repairMaterial, repairMetadata, 0, maximumQuantity, maximumDurability, ItemType.OTHER, MaterialType.OTHER, 1);
|
||||
}
|
||||
|
||||
public static Salvageable getSalvageable(Material itemMaterial, Material repairMaterial, byte repairMetadata, int minimumLevel, int maximumQuantity, short maximumDurability, ItemType repairItemType, MaterialType repairMaterialType, double xpMultiplier) {
|
||||
// TODO: Add in loading from config what type of repairable we want.
|
||||
return new SimpleSalvageable(itemMaterial, repairMaterial, repairMetadata, minimumLevel, maximumQuantity, maximumDurability, repairItemType, repairMaterialType, xpMultiplier);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.gmail.nossr50.skills.salvage.salvageables;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface SalvageableManager {
|
||||
/**
|
||||
* Register a salvageable with the SalvageManager
|
||||
*
|
||||
* @param salvageable Salvageable to register
|
||||
*/
|
||||
public void registerSalvageable(Salvageable salvageable);
|
||||
|
||||
/**
|
||||
* Register a list of salvageables with the SalvageManager
|
||||
*
|
||||
* @param salvageables List<Salvageable> to register
|
||||
*/
|
||||
public void registerSalvageables(List<Salvageable> salvageables);
|
||||
|
||||
/**
|
||||
* Checks if an item is salvageable
|
||||
*
|
||||
* @param type Material to check if salvageable
|
||||
*
|
||||
* @return true if salvageable, false if not
|
||||
*/
|
||||
public boolean isSalvageable(Material type);
|
||||
|
||||
/**
|
||||
* Checks if an item is salvageable
|
||||
*
|
||||
* @param itemStack Item to check if salvageable
|
||||
*
|
||||
* @return true if salvageable, false if not
|
||||
*/
|
||||
public boolean isSalvageable(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Gets the salvageable with this type
|
||||
*
|
||||
* @param type Material of the salvageable to look for
|
||||
*
|
||||
* @return the salvageable, can be null
|
||||
*/
|
||||
public Salvageable getSalvageable(Material type);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.gmail.nossr50.skills.salvage.salvageables;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.ItemType;
|
||||
import com.gmail.nossr50.datatypes.skills.MaterialType;
|
||||
|
||||
|
||||
public class SimpleSalvageable implements Salvageable {
|
||||
private final Material itemMaterial, salvageMaterial;
|
||||
private final int maximumQuantity, minimumLevel;
|
||||
private final short maximumDurability, baseSalvageDurability;
|
||||
private final byte salvageMetadata;
|
||||
private final ItemType salvageItemType;
|
||||
private final MaterialType salvageMaterialType;
|
||||
private final double xpMultiplier;
|
||||
|
||||
protected SimpleSalvageable(Material type, Material salvageMaterial, byte salvageMetadata, int minimumLevel, int maximumQuantity, short maximumDurability, ItemType salvageItemType, MaterialType salvageMaterialType, double xpMultiplier) {
|
||||
this.itemMaterial = type;
|
||||
this.salvageMaterial = salvageMaterial;
|
||||
this.salvageMetadata = salvageMetadata;
|
||||
this.salvageItemType = salvageItemType;
|
||||
this.salvageMaterialType = salvageMaterialType;
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.maximumQuantity = maximumQuantity;
|
||||
this.maximumDurability = maximumDurability;
|
||||
this.baseSalvageDurability = (short) (maximumDurability / maximumQuantity);
|
||||
this.xpMultiplier = xpMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getItemMaterial() {
|
||||
return itemMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getSalvageMaterial() {
|
||||
return salvageMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getSalvageMaterialMetadata() {
|
||||
return salvageMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemType getSalvageItemType() {
|
||||
return salvageItemType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialType getSalvageMaterialType() {
|
||||
return salvageMaterialType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumQuantity() {
|
||||
return maximumQuantity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getMaximumDurability() {
|
||||
return maximumDurability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getBaseSalvageDurability() {
|
||||
return baseSalvageDurability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinimumLevel() {
|
||||
return minimumLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getXpMultiplier() {
|
||||
return xpMultiplier;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.gmail.nossr50.skills.salvage.salvageables;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class SimpleSalvageableManager implements SalvageableManager {
|
||||
private HashMap<Material, Salvageable> salvageables;
|
||||
|
||||
public SimpleSalvageableManager() {
|
||||
this(55);
|
||||
}
|
||||
|
||||
public SimpleSalvageableManager(int salvageablesSize) {
|
||||
this.salvageables = new HashMap<Material, Salvageable>(salvageablesSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSalvageable(Salvageable salvageable) {
|
||||
Material item = salvageable.getItemMaterial();
|
||||
salvageables.put(item, salvageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSalvageables(List<Salvageable> salvageables) {
|
||||
for (Salvageable salvageable : salvageables) {
|
||||
registerSalvageable(salvageable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSalvageable(Material type) {
|
||||
return salvageables.containsKey(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSalvageable(ItemStack itemStack) {
|
||||
return isSalvageable(itemStack.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Salvageable getSalvageable(Material type) {
|
||||
return salvageables.get(type);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user