Use new durability in other classes
This commit is contained in:
		@@ -50,6 +50,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
 | 
				
			|||||||
    private UpdateManager updateManager;
 | 
					    private UpdateManager updateManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private INBTEditor nbtEditor;
 | 
					    private INBTEditor nbtEditor;
 | 
				
			||||||
 | 
					    private DurabilityManager durabilityManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onEnable()
 | 
					    public void onEnable()
 | 
				
			||||||
@@ -75,6 +76,9 @@ public class ArmoredElytra extends JavaPlugin implements Listener
 | 
				
			|||||||
        nbtEditor = new NBTEditor();
 | 
					        nbtEditor = new NBTEditor();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        config = new ConfigLoader(this);
 | 
					        config = new ConfigLoader(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        durabilityManager = new DurabilityManager(nbtEditor, config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        messages = new Messages(this);
 | 
					        messages = new Messages(this);
 | 
				
			||||||
        readMessages();
 | 
					        readMessages();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -94,29 +98,26 @@ public class ArmoredElytra extends JavaPlugin implements Listener
 | 
				
			|||||||
                     "Stats disabled, not loading stats :(... Please consider enabling it! I am a simple man, " +
 | 
					                     "Stats disabled, not loading stats :(... Please consider enabling it! I am a simple man, " +
 | 
				
			||||||
                         "seeing higher user numbers helps me stay motivated!");
 | 
					                         "seeing higher user numbers helps me stay motivated!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this);
 | 
					        Bukkit.getPluginManager().registerEvents(new EventHandlers(this, nbtEditor, durabilityManager), this);
 | 
				
			||||||
        getCommand("ArmoredElytra").setExecutor(new CommandHandler(this));
 | 
					        getCommand("ArmoredElytra").setExecutor(new CommandHandler(this, nbtEditor, durabilityManager));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Load the plugin normally if not in uninstall mode.
 | 
					        // Load the plugin normally if not in uninstall mode.
 | 
				
			||||||
        if (!config.uninstallMode())
 | 
					        if (!config.uninstallMode())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Check if the user wants to disable durability penalty for flying with an armored elytra.
 | 
					            Bukkit.getPluginManager().registerEvents(new FlyDurabilityHandler(config.noFlightDurability(),
 | 
				
			||||||
            if (config.noFlightDurability())
 | 
					                                                                              nbtEditor, durabilityManager), this);
 | 
				
			||||||
            {
 | 
					            final Listener creationListener =
 | 
				
			||||||
                Bukkit.getPluginManager().registerEvents(new FlyDurabilityHandler(), this);
 | 
					                config.craftingInSmithingTable() ?
 | 
				
			||||||
                myLogger(Level.INFO, "Durability penalty for flying disabled!");
 | 
					                new SmithingTableCraftHandler(this, nbtEditor, durabilityManager, config) :
 | 
				
			||||||
            }
 | 
					                new AnvilHandler(this, nbtEditor, durabilityManager, config);
 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
                myLogger(Level.INFO, "Durability penalty for flying enabled!");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            final Listener creationListener = config.craftingInSmithingTable() ?
 | 
					 | 
				
			||||||
                                              new SmithingTableCraftHandler(this) : new AnvilHandler(this);
 | 
					 | 
				
			||||||
            Bukkit.getPluginManager().registerEvents(creationListener, this);
 | 
					            Bukkit.getPluginManager().registerEvents(creationListener, this);
 | 
				
			||||||
            if (config.allowUpgradeToNetherite())
 | 
					            if (config.allowUpgradeToNetherite())
 | 
				
			||||||
                Bukkit.getPluginManager().registerEvents(new NetheriteUpgradeListener(this), this);
 | 
					                Bukkit.getPluginManager()
 | 
				
			||||||
 | 
					                      .registerEvents(new NetheriteUpgradeListener(this, nbtEditor, durabilityManager, config), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (config.dropNetheriteAsChestplate())
 | 
					            if (config.dropNetheriteAsChestplate())
 | 
				
			||||||
                Bukkit.getPluginManager().registerEvents(new ItemDropListener(this), this);
 | 
					                Bukkit.getPluginManager().registerEvents(new ItemDropListener(nbtEditor), this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Log all allowed enchantments.
 | 
					            // Log all allowed enchantments.
 | 
				
			||||||
            myLogger(Level.INFO, ("Allowed enchantments:"));
 | 
					            myLogger(Level.INFO, ("Allowed enchantments:"));
 | 
				
			||||||
@@ -126,7 +127,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener
 | 
				
			|||||||
        else
 | 
					        else
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            myLogger(Level.WARNING, "Plugin in uninstall mode!");
 | 
					            myLogger(Level.WARNING, "Plugin in uninstall mode!");
 | 
				
			||||||
            Bukkit.getPluginManager().registerEvents(new Uninstaller(this), this);
 | 
					            Bukkit.getPluginManager().registerEvents(new Uninstaller(this, nbtEditor), this);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,7 @@ public class DurabilityManager
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    private static final int ELYTRA_MAX_DURABILITY = Material.ELYTRA.getMaxDurability();
 | 
					    private static final int ELYTRA_MAX_DURABILITY = Material.ELYTRA.getMaxDurability();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final int[] repairSteps = new int[ArmorTier.values().length];
 | 
					    private final int[] repairAmounts = new int[ArmorTier.values().length];
 | 
				
			||||||
    private final int[] maxDurabilities = new int[ArmorTier.values().length];
 | 
					    private final int[] maxDurabilities = new int[ArmorTier.values().length];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final INBTEditor nbtEditor;
 | 
					    private final INBTEditor nbtEditor;
 | 
				
			||||||
@@ -26,6 +26,28 @@ public class DurabilityManager
 | 
				
			|||||||
        init();
 | 
					        init();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Combination of {@link #getCombinedDurability(ItemStack, ItemStack, ArmorTier, ArmorTier)} and {@link
 | 
				
			||||||
 | 
					     * #setDurability(ItemStack, int, ArmorTier)}.
 | 
				
			||||||
 | 
					     * <p>
 | 
				
			||||||
 | 
					     * First gets the combined of the input armored elytra and the other item and then applies it to the target armored
 | 
				
			||||||
 | 
					     * elytra.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param armoredElytraOut The output armored elytra item. This is the elytra that will be updated.
 | 
				
			||||||
 | 
					     * @param armoredElytraIn  The input armored elytra item.
 | 
				
			||||||
 | 
					     * @param other            The other item that will be combined with the armored elytra. This can be another armored
 | 
				
			||||||
 | 
					     *                         elytra, a chestplate, or any other item.
 | 
				
			||||||
 | 
					     * @param currentTier      The current armor tier of the armored elytra.
 | 
				
			||||||
 | 
					     * @param targetTier       The target tier of the armored elytra.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public int setCombinedDurability(ItemStack armoredElytraOut, ItemStack armoredElytraIn, ItemStack other,
 | 
				
			||||||
 | 
					                                     ArmorTier currentTier, ArmorTier targetTier)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        final int combinedDurability = getCombinedDurability(armoredElytraIn, other, currentTier, targetTier);
 | 
				
			||||||
 | 
					        setDurability(armoredElytraOut, combinedDurability, targetTier);
 | 
				
			||||||
 | 
					        return combinedDurability;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Gets durability value resulting from combining an armored elytra with some other item with durability.
 | 
					     * Gets durability value resulting from combining an armored elytra with some other item with durability.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -43,17 +65,36 @@ public class DurabilityManager
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        final int currentMaxDurability = getMaxDurability(currentTier);
 | 
					        final int currentMaxDurability = getMaxDurability(currentTier);
 | 
				
			||||||
        final int targetMaxDurability = getMaxDurability(targetTier);
 | 
					        final int targetMaxDurability = getMaxDurability(targetTier);
 | 
				
			||||||
        final int otherMaxDurability = otherTier == ArmorTier.NONE ?
 | 
					        final int otherMaxDurability = otherTier != ArmorTier.NONE ?
 | 
				
			||||||
                                       other.getType().getMaxDurability() : getMaxDurability(otherTier);
 | 
					                                       getMaxDurability(otherTier) : other.getType().getMaxDurability();
 | 
				
			||||||
 | 
					        //noinspection deprecation
 | 
				
			||||||
        final int otherDurability = other.getType().equals(Material.ELYTRA) ?
 | 
					        final int otherDurability = other.getType().equals(Material.ELYTRA) ?
 | 
				
			||||||
                                    getRealDurability(other, null) : other.getType().getMaxDurability();
 | 
					                                    getRealDurability(other, null) : other.getDurability();
 | 
				
			||||||
 | 
					 | 
				
			||||||
        final int currentDurability = getRealDurability(armoredElytra, currentTier);
 | 
					        final int currentDurability = getRealDurability(armoredElytra, currentTier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return targetMaxDurability -
 | 
					        final int combinedDurability = targetMaxDurability -
 | 
				
			||||||
            (otherMaxDurability - otherDurability) -
 | 
					            (otherMaxDurability - otherDurability) -
 | 
				
			||||||
            (currentMaxDurability - currentDurability);
 | 
					            (currentMaxDurability - currentDurability);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return Util.between(combinedDurability, 0, targetMaxDurability);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Removes durability from an armored elytra.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param armoredElytra  The armored elytra item to damage.
 | 
				
			||||||
 | 
					     * @param durabilityLoss The amount of durability to remove from the armored elytra.
 | 
				
			||||||
 | 
					     * @param providedTier   The tier of the armored elytra (if this is available). If this is null, it will be
 | 
				
			||||||
 | 
					     *                       retrieved from the item itself.
 | 
				
			||||||
 | 
					     * @return The new durability after removing the provided amount.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public int removeDurability(ItemStack armoredElytra, int durabilityLoss, @Nullable ArmorTier providedTier)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        final ArmorTier currentTier = providedTier == null ? nbtEditor.getArmorTier(armoredElytra) : providedTier;
 | 
				
			||||||
 | 
					        final int currentDurability = getRealDurability(armoredElytra, currentTier);
 | 
				
			||||||
 | 
					        final int newDurability = Util.between(currentDurability + durabilityLoss, 0, getMaxDurability(currentTier));
 | 
				
			||||||
 | 
					        setDurability(armoredElytra, newDurability, providedTier);
 | 
				
			||||||
 | 
					        return newDurability;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -71,7 +112,7 @@ public class DurabilityManager
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        final ArmorTier currentTier = providedTier == null ? nbtEditor.getArmorTier(armoredElytra) : providedTier;
 | 
					        final ArmorTier currentTier = providedTier == null ? nbtEditor.getArmorTier(armoredElytra) : providedTier;
 | 
				
			||||||
        final int repairableDurability = getMaxDurability(currentTier) - getRealDurability(armoredElytra, currentTier);
 | 
					        final int repairableDurability = getMaxDurability(currentTier) - getRealDurability(armoredElytra, currentTier);
 | 
				
			||||||
        return (int) Math.ceil((float) repairableDurability / getRepairSteps(currentTier));
 | 
					        return (int) Math.ceil((float) repairableDurability / getRepairAmount(currentTier));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -87,7 +128,7 @@ public class DurabilityManager
 | 
				
			|||||||
    public int getRepairedDurability(ItemStack armoredElytra, int repairCount, @Nullable ArmorTier providedTier)
 | 
					    public int getRepairedDurability(ItemStack armoredElytra, int repairCount, @Nullable ArmorTier providedTier)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        final ArmorTier currentTier = providedTier == null ? nbtEditor.getArmorTier(armoredElytra) : providedTier;
 | 
					        final ArmorTier currentTier = providedTier == null ? nbtEditor.getArmorTier(armoredElytra) : providedTier;
 | 
				
			||||||
        final int restoredDurability = repairCount * getRepairSteps(currentTier);
 | 
					        final int restoredDurability = repairCount * getRepairAmount(currentTier);
 | 
				
			||||||
        final int currentDurability = getRealDurability(armoredElytra, currentTier);
 | 
					        final int currentDurability = getRealDurability(armoredElytra, currentTier);
 | 
				
			||||||
        return Math.max(0, currentDurability - restoredDurability);
 | 
					        return Math.max(0, currentDurability - restoredDurability);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -125,8 +166,8 @@ public class DurabilityManager
 | 
				
			|||||||
    public void setDurability(ItemStack item, int durability, @Nullable ArmorTier providedTier)
 | 
					    public void setDurability(ItemStack item, int durability, @Nullable ArmorTier providedTier)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        final ArmorTier currentTier = providedTier == null ? nbtEditor.getArmorTier(item) : providedTier;
 | 
					        final ArmorTier currentTier = providedTier == null ? nbtEditor.getArmorTier(item) : providedTier;
 | 
				
			||||||
        final int rawDurability = getRemappedDurability(durability, getMaxDurability(currentTier),
 | 
					        final int oldMaxDurability = getMaxDurability(currentTier);
 | 
				
			||||||
                                                        ELYTRA_MAX_DURABILITY);
 | 
					        final int rawDurability = getRemappedDurability(durability, oldMaxDurability, ELYTRA_MAX_DURABILITY);
 | 
				
			||||||
        nbtEditor.updateDurability(item, durability, rawDurability);
 | 
					        nbtEditor.updateDurability(item, durability, rawDurability);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -174,7 +215,7 @@ public class DurabilityManager
 | 
				
			|||||||
     * @param armorTier The armor tier for which to get the maximum durability.
 | 
					     * @param armorTier The armor tier for which to get the maximum durability.
 | 
				
			||||||
     * @return The maximum durability of the given armor tier.
 | 
					     * @return The maximum durability of the given armor tier.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private int getMaxDurability(ArmorTier armorTier)
 | 
					    public int getMaxDurability(ArmorTier armorTier)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return maxDurabilities[armorTier.ordinal()];
 | 
					        return maxDurabilities[armorTier.ordinal()];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -185,9 +226,9 @@ public class DurabilityManager
 | 
				
			|||||||
     * @param armorTier The armor tier.
 | 
					     * @param armorTier The armor tier.
 | 
				
			||||||
     * @return The amount of durability restored per repair step for the given armor tier.
 | 
					     * @return The amount of durability restored per repair step for the given armor tier.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private int getRepairSteps(ArmorTier armorTier)
 | 
					    public int getRepairAmount(ArmorTier armorTier)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return repairSteps[armorTier.ordinal()];
 | 
					        return repairAmounts[armorTier.ordinal()];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -207,11 +248,11 @@ public class DurabilityManager
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Initializes the {@link #maxDurabilities} and {@link #repairSteps} arrays.
 | 
					     * Initializes the {@link #maxDurabilities} and {@link #repairAmounts} arrays.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private void init()
 | 
					    private void init()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        repairSteps[0] = 0;
 | 
					        repairAmounts[0] = 0;
 | 
				
			||||||
        maxDurabilities[0] = ELYTRA_MAX_DURABILITY;
 | 
					        maxDurabilities[0] = ELYTRA_MAX_DURABILITY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final ArmorTier[] armorTiers = ArmorTier.values();
 | 
					        final ArmorTier[] armorTiers = ArmorTier.values();
 | 
				
			||||||
@@ -223,7 +264,7 @@ public class DurabilityManager
 | 
				
			|||||||
            maxDurabilities[idx] = maxDurability;
 | 
					            maxDurabilities[idx] = maxDurability;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            final int steps = Math.max(1, config.getFullRepairItemCount(armorTier));
 | 
					            final int steps = Math.max(1, config.getFullRepairItemCount(armorTier));
 | 
				
			||||||
            repairSteps[idx] = (int) Math.ceil((float) maxDurability / steps);
 | 
					            repairAmounts[idx] = (int) Math.ceil((float) maxDurability / steps);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,21 +27,16 @@ import java.util.logging.Level;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class AnvilHandler extends ArmoredElytraHandler implements Listener
 | 
					public class AnvilHandler extends ArmoredElytraHandler implements Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private final ConfigLoader configLoader;
 | 
					    protected AnvilHandler(ArmoredElytra plugin, boolean creationEnabled,
 | 
				
			||||||
    private final INBTEditor nbtEditor;
 | 
					                           INBTEditor nbtEditor, DurabilityManager durabilityManager, ConfigLoader config)
 | 
				
			||||||
    private final DurabilityManager durabilityManager;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public AnvilHandler(final ArmoredElytra plugin, final boolean creationEnabled)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super(plugin, creationEnabled);
 | 
					        super(plugin, creationEnabled, nbtEditor, durabilityManager, config);
 | 
				
			||||||
        configLoader = plugin.getConfigLoader();
 | 
					 | 
				
			||||||
        nbtEditor = plugin.getNbtEditor();
 | 
					 | 
				
			||||||
        durabilityManager = new DurabilityManager(nbtEditor, configLoader);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public AnvilHandler(final ArmoredElytra plugin)
 | 
					    public AnvilHandler(ArmoredElytra plugin, INBTEditor nbtEditor,
 | 
				
			||||||
 | 
					                        DurabilityManager durabilityManager, ConfigLoader config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this(plugin, true);
 | 
					        super(plugin, true, nbtEditor, durabilityManager, config);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Valid inputs:
 | 
					    // Valid inputs:
 | 
				
			||||||
@@ -74,11 +69,11 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            // If the armored elytra is to be enchanted using an enchanted book...
 | 
					            // If the armored elytra is to be enchanted using an enchanted book...
 | 
				
			||||||
            if (matTwo == Material.ENCHANTED_BOOK)
 | 
					            if (matTwo == Material.ENCHANTED_BOOK)
 | 
				
			||||||
                return configLoader.allowAddingEnchantments() ? Action.ENCHANT : Action.BLOCK;
 | 
					                return config.allowAddingEnchantments() ? Action.ENCHANT : Action.BLOCK;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // If the armored elytra is to be repaired using its repair item...
 | 
					            // If the armored elytra is to be repaired using its repair item...
 | 
				
			||||||
            if (ArmorTier.getRepairItem(tier) == matTwo)
 | 
					            if (ArmorTier.getRepairItem(tier) == matTwo)
 | 
				
			||||||
                return itemOne.getDurability() == 0 ? Action.BLOCK : Action.REPAIR;
 | 
					                return durabilityManager.getRealDurability(itemOne, tier) == 0 ? Action.BLOCK : Action.REPAIR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // If the armored elytra is to be combined with another armored elytra of the same tier...
 | 
					            // If the armored elytra is to be combined with another armored elytra of the same tier...
 | 
				
			||||||
            if (nbtEditor.getArmorTier(itemTwo) == tier)
 | 
					            if (nbtEditor.getArmorTier(itemTwo) == tier)
 | 
				
			||||||
@@ -120,7 +115,7 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
 | 
				
			|||||||
            final ArmorTier curTier = nbtEditor.getArmorTier(itemA);
 | 
					            final ArmorTier curTier = nbtEditor.getArmorTier(itemA);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            int newDurability = 0;
 | 
					            int newDurability = 0;
 | 
				
			||||||
            EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemA, plugin);
 | 
					            final EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemA, plugin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            switch (action)
 | 
					            switch (action)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -168,7 +163,7 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
 | 
				
			|||||||
                final String name = getElytraResultName(itemA, action, newTier, event.getInventory().getRenameText());
 | 
					                final String name = getElytraResultName(itemA, action, newTier, event.getInventory().getRenameText());
 | 
				
			||||||
                final Color color = getItemColor(itemA, itemB);
 | 
					                final Color color = getItemColor(itemA, itemB);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                result = nbtEditor.addArmorNBTTags(result, newTier, configLoader.unbreakable(), name, color);
 | 
					                result = nbtEditor.addArmorNBTTags(result, newTier, config.unbreakable(), name, color);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                event.setResult(result);
 | 
					                event.setResult(result);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
@@ -186,13 +181,13 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
 | 
				
			|||||||
                                       final ArmorTier armorTier, final String renameText)
 | 
					                                       final ArmorTier armorTier, final String renameText)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        final String tierName = plugin.getArmoredElytraName(armorTier);
 | 
					        final String tierName = plugin.getArmoredElytraName(armorTier);
 | 
				
			||||||
        if (renameText == null || !configLoader.allowRenaming())
 | 
					        if (renameText == null || !config.allowRenaming())
 | 
				
			||||||
            return tierName;
 | 
					            return tierName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final ItemMeta meta = baseItem.getItemMeta();
 | 
					        final ItemMeta meta = baseItem.getItemMeta();
 | 
				
			||||||
        final String currentName = meta == null ? null : meta.getDisplayName();
 | 
					        final String currentName = meta == null ? null : meta.getDisplayName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // When the rename text is empty, give it the default tier-name when creating a new armored elytra
 | 
					        // When the renameText is empty, give it the default tier-name when creating a new armored elytra
 | 
				
			||||||
        // (so it's named properly) or when the current name is already the tier name (just returning the current
 | 
					        // (so it's named properly) or when the current name is already the tier name (just returning the current
 | 
				
			||||||
        // name would strip the tier's color in this case).
 | 
					        // name would strip the tier's color in this case).
 | 
				
			||||||
        if ((action == Action.CREATE && renameText.equals("")) ||
 | 
					        if ((action == Action.CREATE && renameText.equals("")) ||
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.DurabilityManager;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ConfigLoader;
 | 
					import nl.pim16aap2.armoredElytra.util.ConfigLoader;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.XMaterial;
 | 
					 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.Color;
 | 
					import org.bukkit.Color;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
@@ -24,38 +24,18 @@ abstract class ArmoredElytraHandler
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected final ArmoredElytra plugin;
 | 
					    protected final ArmoredElytra plugin;
 | 
				
			||||||
    protected final boolean creationEnabled;
 | 
					    protected final boolean creationEnabled;
 | 
				
			||||||
    private final ConfigLoader config;
 | 
					    protected final ConfigLoader config;
 | 
				
			||||||
 | 
					    protected final INBTEditor nbtEditor;
 | 
				
			||||||
 | 
					    protected final DurabilityManager durabilityManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public ArmoredElytraHandler(final ArmoredElytra plugin, final boolean creationEnabled)
 | 
					    protected ArmoredElytraHandler(ArmoredElytra plugin, boolean creationEnabled, INBTEditor nbtEditor,
 | 
				
			||||||
 | 
					                                   DurabilityManager durabilityManager, ConfigLoader config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
        this.creationEnabled = creationEnabled;
 | 
					        this.creationEnabled = creationEnabled;
 | 
				
			||||||
        config = plugin.getConfigLoader();
 | 
					        this.nbtEditor = nbtEditor;
 | 
				
			||||||
    }
 | 
					        this.durabilityManager = durabilityManager;
 | 
				
			||||||
 | 
					        this.config = config;
 | 
				
			||||||
    // Repair an Armored Elytra
 | 
					 | 
				
			||||||
    protected short repairItem(short curDur, ItemStack repairItem)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        final ArmorTier repairTier;
 | 
					 | 
				
			||||||
        if (repairItem.getType().equals(Material.LEATHER))
 | 
					 | 
				
			||||||
            repairTier = ArmorTier.LEATHER;
 | 
					 | 
				
			||||||
        else if (repairItem.getType().equals(Material.GOLD_INGOT))
 | 
					 | 
				
			||||||
            repairTier = ArmorTier.GOLD;
 | 
					 | 
				
			||||||
        else if (repairItem.getType().equals(Material.IRON_INGOT))
 | 
					 | 
				
			||||||
            repairTier = ArmorTier.IRON;
 | 
					 | 
				
			||||||
        else if (repairItem.getType().equals(Material.DIAMOND))
 | 
					 | 
				
			||||||
            repairTier = ArmorTier.DIAMOND;
 | 
					 | 
				
			||||||
        else if (repairItem.getType().equals(XMaterial.NETHERITE_INGOT.parseMaterial()))
 | 
					 | 
				
			||||||
            repairTier = ArmorTier.NETHERITE;
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
            repairTier = ArmorTier.NONE;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        final int repairCount = Math.max(1, config.getFullRepairItemCount(repairTier));
 | 
					 | 
				
			||||||
        final double repairPercentage = 1f / repairCount;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        int maxDurability = Material.ELYTRA.getMaxDurability();
 | 
					 | 
				
			||||||
        int newDurability = (int) (curDur - repairItem.getAmount() * (maxDurability * repairPercentage));
 | 
					 | 
				
			||||||
        return (short) (Math.max(newDurability, 0));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -83,7 +63,7 @@ abstract class ArmoredElytraHandler
 | 
				
			|||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (itemStack.getType() == Material.ELYTRA)
 | 
					        if (itemStack.getType() == Material.ELYTRA)
 | 
				
			||||||
            return ArmoredElytra.getInstance().getNbtEditor().getColorOfArmoredElytra(itemStack);
 | 
					            return nbtEditor.getColorOfArmoredElytra(itemStack);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!itemStack.hasItemMeta() || !(itemStack.getItemMeta() instanceof LeatherArmorMeta))
 | 
					        if (!itemStack.hasItemMeta() || !(itemStack.getItemMeta() instanceof LeatherArmorMeta))
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.DurabilityManager;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.messages.Message;
 | 
					import nl.pim16aap2.armoredElytra.util.messages.Message;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
@@ -21,11 +23,15 @@ import java.util.logging.Level;
 | 
				
			|||||||
public class CommandHandler implements CommandExecutor
 | 
					public class CommandHandler implements CommandExecutor
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private final ArmoredElytra plugin;
 | 
					    private final ArmoredElytra plugin;
 | 
				
			||||||
 | 
					    private final INBTEditor nbtEditor;
 | 
				
			||||||
 | 
					    private final DurabilityManager durabilityManager;
 | 
				
			||||||
    private static Field BY_KEY_FIELD;
 | 
					    private static Field BY_KEY_FIELD;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public CommandHandler(ArmoredElytra plugin)
 | 
					    public CommandHandler(ArmoredElytra plugin, INBTEditor nbtEditor, DurabilityManager durabilityManager)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
 | 
					        this.nbtEditor = nbtEditor;
 | 
				
			||||||
 | 
					        this.durabilityManager = durabilityManager;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@@ -80,9 +86,9 @@ public class CommandHandler implements CommandExecutor
 | 
				
			|||||||
                    if (allowed)
 | 
					                    if (allowed)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        plugin.elytraReceivedMessage(receiver, armorTier);
 | 
					                        plugin.elytraReceivedMessage(receiver, armorTier);
 | 
				
			||||||
                        newElytra = ArmoredElytra.getInstance().getNbtEditor()
 | 
					                        newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier,
 | 
				
			||||||
                                                 .addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier,
 | 
					                                                              plugin.getConfigLoader().unbreakable());
 | 
				
			||||||
                                                                  plugin.getConfigLoader().unbreakable());
 | 
					                        durabilityManager.setDurability(newElytra, 0, armorTier);
 | 
				
			||||||
                        plugin.giveArmoredElytraToPlayer(receiver, newElytra);
 | 
					                        plugin.giveArmoredElytraToPlayer(receiver, newElytra);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					                    else
 | 
				
			||||||
@@ -119,9 +125,10 @@ public class CommandHandler implements CommandExecutor
 | 
				
			|||||||
                        return false;
 | 
					                        return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    plugin.elytraReceivedMessage(player, armorTier);
 | 
					                    plugin.elytraReceivedMessage(player, armorTier);
 | 
				
			||||||
                    newElytra = ArmoredElytra.getInstance().getNbtEditor()
 | 
					                    newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier,
 | 
				
			||||||
                                             .addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), armorTier,
 | 
					                                                          plugin.getConfigLoader().unbreakable());
 | 
				
			||||||
                                                              plugin.getConfigLoader().unbreakable());
 | 
					                    durabilityManager.setDurability(newElytra, 0, armorTier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    plugin.giveArmoredElytraToPlayer(player, newElytra);
 | 
					                    plugin.giveArmoredElytraToPlayer(player, newElytra);
 | 
				
			||||||
                    plugin.myLogger(Level.INFO, ("Giving an armored elytra of the " + ArmorTier.getArmor(armorTier) +
 | 
					                    plugin.myLogger(Level.INFO, ("Giving an armored elytra of the " + ArmorTier.getArmor(armorTier) +
 | 
				
			||||||
                        " armor tier to player " + player.getName()));
 | 
					                        " armor tier to player " + player.getName()));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +1,12 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.DurabilityManager;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.lib.armorequip.ArmorEquipEvent;
 | 
					import nl.pim16aap2.armoredElytra.lib.armorequip.ArmorEquipEvent;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.lib.armorequip.ArmorListener;
 | 
					import nl.pim16aap2.armoredElytra.lib.armorequip.ArmorListener;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.lib.armorequip.ArmorType;
 | 
					import nl.pim16aap2.armoredElytra.lib.armorequip.ArmorType;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.lib.armorequip.DispenserArmorListener;
 | 
					import nl.pim16aap2.armoredElytra.lib.armorequip.DispenserArmorListener;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.AllowedToWearEnum;
 | 
					import nl.pim16aap2.armoredElytra.util.AllowedToWearEnum;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.Util;
 | 
					import nl.pim16aap2.armoredElytra.util.Util;
 | 
				
			||||||
@@ -14,6 +16,7 @@ import org.bukkit.Material;
 | 
				
			|||||||
import org.bukkit.enchantments.Enchantment;
 | 
					import org.bukkit.enchantments.Enchantment;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
 | 
					import org.bukkit.event.EventPriority;
 | 
				
			||||||
import org.bukkit.event.Listener;
 | 
					import org.bukkit.event.Listener;
 | 
				
			||||||
import org.bukkit.event.entity.EntityDamageEvent;
 | 
					import org.bukkit.event.entity.EntityDamageEvent;
 | 
				
			||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
 | 
					import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
 | 
				
			||||||
@@ -24,12 +27,16 @@ import java.util.Random;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class EventHandlers implements Listener
 | 
					public class EventHandlers implements Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private final ArmoredElytra plugin;
 | 
					 | 
				
			||||||
    private final Random random = new Random();
 | 
					    private final Random random = new Random();
 | 
				
			||||||
 | 
					    private final ArmoredElytra plugin;
 | 
				
			||||||
 | 
					    private final INBTEditor nbtEditor;
 | 
				
			||||||
 | 
					    private final DurabilityManager durabilityManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public EventHandlers(ArmoredElytra plugin)
 | 
					    public EventHandlers(ArmoredElytra plugin, INBTEditor nbtEditor, DurabilityManager durabilityManager)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
 | 
					        this.nbtEditor = nbtEditor;
 | 
				
			||||||
 | 
					        this.durabilityManager = durabilityManager;
 | 
				
			||||||
        initializeArmorEquipEvent();
 | 
					        initializeArmorEquipEvent();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,13 +46,6 @@ public class EventHandlers implements Listener
 | 
				
			|||||||
        Bukkit.getPluginManager().registerEvents(new DispenserArmorListener(), plugin);
 | 
					        Bukkit.getPluginManager().registerEvents(new DispenserArmorListener(), plugin);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void moveChestplateToInventory(Player player)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        player.getInventory().addItem(player.getInventory().getChestplate());
 | 
					 | 
				
			||||||
        player.getInventory().getChestplate().setAmount(0);
 | 
					 | 
				
			||||||
        player.updateInventory();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // Make sure the player has the correct permission and that the item is not
 | 
					    // Make sure the player has the correct permission and that the item is not
 | 
				
			||||||
    // broken.
 | 
					    // broken.
 | 
				
			||||||
    private AllowedToWearEnum isAllowedToWear(ItemStack elytra, Player player, ArmorTier armorTier)
 | 
					    private AllowedToWearEnum isAllowedToWear(ItemStack elytra, Player player, ArmorTier armorTier)
 | 
				
			||||||
@@ -60,62 +60,44 @@ public class EventHandlers implements Listener
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Handle armored elytra durability loss.
 | 
					    // Handle armored elytra durability loss.
 | 
				
			||||||
    @EventHandler(ignoreCancelled = true)
 | 
					    @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
 | 
				
			||||||
    public void onPlayerDamage(EntityDamageEvent e)
 | 
					    public void onPlayerDamage(EntityDamageEvent e)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!(e.getEntity() instanceof Player))
 | 
					        if (!(e.getEntity() instanceof Player))
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
 | 
					        final Player p = (Player) e.getEntity();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (plugin.getConfigLoader().unbreakable())
 | 
					        final ItemStack elytra = p.getInventory().getChestplate();
 | 
				
			||||||
 | 
					        if (elytra == null)
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Player p = (Player) e.getEntity();
 | 
					        final ArmorTier armorTier = nbtEditor.getArmorTier(elytra);
 | 
				
			||||||
        // If the player didn't die from the damage.
 | 
					        if (armorTier == ArmorTier.NONE)
 | 
				
			||||||
        if ((p.getHealth() - e.getFinalDamage()) > 0)
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final DamageCause cause = e.getCause();
 | 
				
			||||||
 | 
					        // The elytra doesn't receive any damage for these causes:
 | 
				
			||||||
 | 
					        if (cause == DamageCause.DROWNING || cause == DamageCause.STARVATION || cause == DamageCause.SUFFOCATION ||
 | 
				
			||||||
 | 
					            cause == DamageCause.SUICIDE || cause == DamageCause.FLY_INTO_WALL || cause == DamageCause.POISON)
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final boolean removeDurability;
 | 
				
			||||||
 | 
					        if (elytra.containsEnchantment(Enchantment.DURABILITY))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (p.getInventory().getChestplate() == null)
 | 
					            final int randomInt = random.nextInt(101);
 | 
				
			||||||
                return;
 | 
					            final int enchantLevel = elytra.getEnchantmentLevel(Enchantment.DURABILITY);
 | 
				
			||||||
 | 
					            // Formula taken from: https://minecraft.fandom.com/wiki/Unbreaking#Usage
 | 
				
			||||||
            if (ArmoredElytra.getInstance().getNbtEditor().getArmorTier(p.getInventory().getChestplate()) ==
 | 
					            final float removeDurabilityChance = 60 + 40f / (enchantLevel + 1);
 | 
				
			||||||
                ArmorTier.NONE)
 | 
					            removeDurability = randomInt <= removeDurabilityChance;
 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            ItemStack elytra = p.getInventory().getChestplate();
 | 
					 | 
				
			||||||
            DamageCause cause = e.getCause();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // The elytra doesn't receive any damage for these causes:
 | 
					 | 
				
			||||||
            if (cause != DamageCause.DROWNING && cause != DamageCause.STARVATION && cause != DamageCause.SUFFOCATION &&
 | 
					 | 
				
			||||||
                cause != DamageCause.SUICIDE && cause != DamageCause.FLY_INTO_WALL && cause != DamageCause.POISON)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                int durability = p.getInventory().getChestplate().getDurability();
 | 
					 | 
				
			||||||
                int maxDurability = p.getInventory().getChestplate().getType().getMaxDurability();
 | 
					 | 
				
			||||||
                int newDurability = durability + ((int) (e.getDamage() / 4) > 1 ? (int) (e.getDamage() / 4) : 1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // If the elytra has the durability enchantment, we calculate the durability
 | 
					 | 
				
			||||||
                // loss ourselves.
 | 
					 | 
				
			||||||
                if (p.getInventory().getChestplate().containsEnchantment(Enchantment.DURABILITY))
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    // Get a random int between 0 and 100 to use in deciding if the durability
 | 
					 | 
				
			||||||
                    // enchantment will take effect.
 | 
					 | 
				
			||||||
                    int randomInt = random.nextInt(101);
 | 
					 | 
				
			||||||
                    int enchantLevel = p.getInventory().getChestplate().getEnchantmentLevel(Enchantment.DURABILITY);
 | 
					 | 
				
			||||||
                    int durabilityDelta = (100 / (enchantLevel + 1)) < randomInt ? 0 : 1;
 | 
					 | 
				
			||||||
                    // If the durability equals/exceeds maxDurability, it's broken (0 = full item
 | 
					 | 
				
			||||||
                    // durability).
 | 
					 | 
				
			||||||
                    if (durability >= maxDurability)
 | 
					 | 
				
			||||||
                        moveChestplateToInventory(p);
 | 
					 | 
				
			||||||
                    else
 | 
					 | 
				
			||||||
                        newDurability = durability + durabilityDelta;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                // If the item should be broken, make sure it really is broken and unequip it.
 | 
					 | 
				
			||||||
                if (newDurability >= maxDurability)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    newDurability = maxDurability;
 | 
					 | 
				
			||||||
                    moveChestplateToInventory(p);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                elytra.setDurability((short) (newDurability));
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            removeDurability = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Even when we don't subtract durability, we still want to update the durability, so just subtract 0.
 | 
				
			||||||
 | 
					        final int durabilityLoss = removeDurability ? (int) Math.max(1, e.getDamage() / 4) : 0;
 | 
				
			||||||
 | 
					        final int newDurability = durabilityManager.removeDurability(elytra, durabilityLoss, armorTier);
 | 
				
			||||||
 | 
					        if (newDurability >= durabilityManager.getMaxDurability(armorTier))
 | 
				
			||||||
 | 
					            Util.moveChestplateToInventory(p);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler
 | 
					    @EventHandler
 | 
				
			||||||
@@ -130,8 +112,8 @@ public class EventHandlers implements Listener
 | 
				
			|||||||
            !e.getNewArmorPiece().getType().equals(Material.ELYTRA))
 | 
					            !e.getNewArmorPiece().getType().equals(Material.ELYTRA))
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ArmorTier armorTier = ArmoredElytra.getInstance().getNbtEditor().getArmorTier(e.getNewArmorPiece());
 | 
					        final ArmorTier armorTier = nbtEditor.getArmorTier(e.getNewArmorPiece());
 | 
				
			||||||
        AllowedToWearEnum allowed = isAllowedToWear(e.getNewArmorPiece(), e.getPlayer(), armorTier);
 | 
					        final AllowedToWearEnum allowed = isAllowedToWear(e.getNewArmorPiece(), e.getPlayer(), armorTier);
 | 
				
			||||||
        switch (allowed)
 | 
					        switch (allowed)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            case ALLOWED:
 | 
					            case ALLOWED:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,21 +1,30 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.DurabilityManager;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.util.Util;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
 | 
					import org.bukkit.event.EventPriority;
 | 
				
			||||||
import org.bukkit.event.Listener;
 | 
					import org.bukkit.event.Listener;
 | 
				
			||||||
import org.bukkit.event.player.PlayerItemDamageEvent;
 | 
					import org.bukkit.event.player.PlayerItemDamageEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class FlyDurabilityHandler implements Listener
 | 
					public class FlyDurabilityHandler implements Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public FlyDurabilityHandler()
 | 
					    private final boolean disableDurability;
 | 
				
			||||||
 | 
					    private final INBTEditor nbtEditor;
 | 
				
			||||||
 | 
					    private final DurabilityManager durabilityManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public FlyDurabilityHandler(boolean disableDurability, INBTEditor nbtEditor, DurabilityManager durabilityManager)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        this.disableDurability = disableDurability;
 | 
				
			||||||
 | 
					        this.nbtEditor = nbtEditor;
 | 
				
			||||||
 | 
					        this.durabilityManager = durabilityManager;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Do not decrease elytra durability while flying. This also cancels durability decrease when
 | 
					    // Do not decrease elytra durability while flying.
 | 
				
			||||||
    // it should (i.e. getting hit) while flying, but I don't really care.
 | 
					    @EventHandler(priority = EventPriority.LOWEST)
 | 
				
			||||||
    @EventHandler
 | 
					 | 
				
			||||||
    public void onItemDamage(PlayerItemDamageEvent e)
 | 
					    public void onItemDamage(PlayerItemDamageEvent e)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (e.getItem().getType() != Material.ELYTRA)
 | 
					        if (e.getItem().getType() != Material.ELYTRA)
 | 
				
			||||||
@@ -24,7 +33,18 @@ public class FlyDurabilityHandler implements Listener
 | 
				
			|||||||
        if (!e.getPlayer().isGliding())
 | 
					        if (!e.getPlayer().isGliding())
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (ArmoredElytra.getInstance().getNbtEditor().getArmorTier(e.getItem()) != ArmorTier.NONE)
 | 
					        final ArmorTier armorTier = nbtEditor.getArmorTier(e.getItem());
 | 
				
			||||||
            e.setCancelled(true);
 | 
					        if (armorTier == ArmorTier.NONE)
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // This also cancels durability decrease when it should (i.e. getting hit) while flying,
 | 
				
			||||||
 | 
					        // but that is likely to be rare enough for it to not matter.
 | 
				
			||||||
 | 
					        e.setCancelled(true);
 | 
				
			||||||
 | 
					        if (disableDurability)
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final int newDurability = durabilityManager.removeDurability(e.getItem(), e.getDamage(), armorTier);
 | 
				
			||||||
 | 
					        if (newDurability >= durabilityManager.getMaxDurability(armorTier))
 | 
				
			||||||
 | 
					            Util.moveChestplateToInventory(e.getPlayer());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
@@ -13,11 +13,11 @@ import org.bukkit.inventory.ItemStack;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class ItemDropListener implements Listener
 | 
					public class ItemDropListener implements Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    protected final ArmoredElytra plugin;
 | 
					    private final INBTEditor nbtEditor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public ItemDropListener(final ArmoredElytra plugin)
 | 
					    public ItemDropListener(INBTEditor nbtEditor)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.nbtEditor = nbtEditor;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -32,10 +32,10 @@ public class ItemDropListener implements Listener
 | 
				
			|||||||
    private ItemStack getNewDrop(final ItemStack itemStack)
 | 
					    private ItemStack getNewDrop(final ItemStack itemStack)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (itemStack == null || itemStack.getType() != Material.ELYTRA ||
 | 
					        if (itemStack == null || itemStack.getType() != Material.ELYTRA ||
 | 
				
			||||||
            plugin.getNbtEditor().getArmorTier(itemStack) != ArmorTier.NETHERITE)
 | 
					            nbtEditor.getArmorTier(itemStack) != ArmorTier.NETHERITE)
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ItemStack newDrop = new ItemStack(Material.NETHERITE_CHESTPLATE, 1);
 | 
					        final ItemStack newDrop = new ItemStack(Material.NETHERITE_CHESTPLATE, 1);
 | 
				
			||||||
        newDrop.setItemMeta(itemStack.getItemMeta());
 | 
					        newDrop.setItemMeta(itemStack.getItemMeta());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return newDrop;
 | 
					        return newDrop;
 | 
				
			||||||
@@ -53,10 +53,10 @@ public class ItemDropListener implements Listener
 | 
				
			|||||||
    private ItemStack getNewPickup(final ItemStack itemStack)
 | 
					    private ItemStack getNewPickup(final ItemStack itemStack)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (itemStack == null || itemStack.getType() != Material.NETHERITE_CHESTPLATE ||
 | 
					        if (itemStack == null || itemStack.getType() != Material.NETHERITE_CHESTPLATE ||
 | 
				
			||||||
            plugin.getNbtEditor().getArmorTier(itemStack) != ArmorTier.NETHERITE)
 | 
					            nbtEditor.getArmorTier(itemStack) != ArmorTier.NETHERITE)
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ItemStack newDrop = new ItemStack(Material.ELYTRA, 1);
 | 
					        final ItemStack newDrop = new ItemStack(Material.ELYTRA, 1);
 | 
				
			||||||
        newDrop.setItemMeta(itemStack.getItemMeta());
 | 
					        newDrop.setItemMeta(itemStack.getItemMeta());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return newDrop;
 | 
					        return newDrop;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,10 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.DurabilityManager;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.util.ConfigLoader;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.event.EventHandler;
 | 
					import org.bukkit.event.EventHandler;
 | 
				
			||||||
@@ -12,12 +15,13 @@ import org.bukkit.inventory.SmithingInventory;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class NetheriteUpgradeListener extends SmithingTableListener
 | 
					public class NetheriteUpgradeListener extends SmithingTableListener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public NetheriteUpgradeListener(final ArmoredElytra plugin)
 | 
					    public NetheriteUpgradeListener(final ArmoredElytra plugin, INBTEditor nbtEditor,
 | 
				
			||||||
 | 
					                                    DurabilityManager durabilityManager, ConfigLoader config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super(plugin);
 | 
					        super(plugin, false, nbtEditor, durabilityManager, config);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler(ignoreCancelled = true)
 | 
					    @Override @EventHandler(ignoreCancelled = true)
 | 
				
			||||||
    public void onSmithingTableUsage(final PrepareSmithingEvent event)
 | 
					    public void onSmithingTableUsage(final PrepareSmithingEvent event)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super.onSmithingTableUsage(event);
 | 
					        super.onSmithingTableUsage(event);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,10 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.DurabilityManager;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.util.ConfigLoader;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.Util;
 | 
					import nl.pim16aap2.armoredElytra.util.Util;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
@@ -14,13 +17,16 @@ import org.bukkit.inventory.SmithingInventory;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class SmithingTableCraftHandler extends SmithingTableListener
 | 
					public class SmithingTableCraftHandler extends SmithingTableListener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public SmithingTableCraftHandler(final ArmoredElytra plugin)
 | 
					    public SmithingTableCraftHandler(final ArmoredElytra plugin, INBTEditor nbtEditor,
 | 
				
			||||||
 | 
					                                     DurabilityManager durabilityManager, ConfigLoader config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super(plugin, true);
 | 
					        super(plugin, true, nbtEditor, durabilityManager, config);
 | 
				
			||||||
        // Register the anvil handler with creation disabled so AEs can still be repaired and stuff.
 | 
					        // Register the anvil handler with creation disabled so AEs can still be repaired and stuff.
 | 
				
			||||||
        Bukkit.getPluginManager().registerEvents(new AnvilHandler(plugin, false), plugin);
 | 
					        Bukkit.getPluginManager()
 | 
				
			||||||
 | 
					              .registerEvents(new AnvilHandler(plugin, false, nbtEditor, durabilityManager, config), plugin);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
    @EventHandler(ignoreCancelled = true)
 | 
					    @EventHandler(ignoreCancelled = true)
 | 
				
			||||||
    public void onSmithingTableUsage(final PrepareSmithingEvent event)
 | 
					    public void onSmithingTableUsage(final PrepareSmithingEvent event)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -42,7 +48,7 @@ public class SmithingTableCraftHandler extends SmithingTableListener
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!isAESmithingTableEvent(e))
 | 
					        if (!isAESmithingTableEvent(e))
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        SmithingInventory smithingInventory = (SmithingInventory) e.getInventory();
 | 
					        final SmithingInventory smithingInventory = (SmithingInventory) e.getInventory();
 | 
				
			||||||
        final ItemStack result = smithingInventory.getItem(2);
 | 
					        final ItemStack result = smithingInventory.getItem(2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // This cast may look unchecked, but it was checked by isSmithingTableEvent already.
 | 
					        // This cast may look unchecked, but it was checked by isSmithingTableEvent already.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,10 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.DurabilityManager;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.util.ConfigLoader;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.EnchantmentContainer;
 | 
					import nl.pim16aap2.armoredElytra.util.EnchantmentContainer;
 | 
				
			||||||
import org.bukkit.Color;
 | 
					import org.bukkit.Color;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
@@ -17,15 +20,10 @@ import java.util.logging.Level;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
abstract class SmithingTableListener extends ArmoredElytraHandler implements Listener
 | 
					abstract class SmithingTableListener extends ArmoredElytraHandler implements Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    protected SmithingTableListener(ArmoredElytra plugin, boolean creationEnabled)
 | 
					    protected SmithingTableListener(ArmoredElytra plugin, boolean creationEnabled,
 | 
				
			||||||
 | 
					                                    INBTEditor nbtEditor, DurabilityManager durabilityManager, ConfigLoader config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        super(plugin, creationEnabled);
 | 
					        super(plugin, creationEnabled, nbtEditor, durabilityManager, config);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    protected SmithingTableListener(ArmoredElytra plugin)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        this(plugin, false);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void onSmithingTableUsage(final PrepareSmithingEvent event)
 | 
					    public void onSmithingTableUsage(final PrepareSmithingEvent event)
 | 
				
			||||||
@@ -42,17 +40,17 @@ abstract class SmithingTableListener extends ArmoredElytraHandler implements Lis
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        final Player player = (Player) event.getView().getPlayer();
 | 
					        final Player player = (Player) event.getView().getPlayer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final ItemStack result;
 | 
					 | 
				
			||||||
        if (plugin.playerHasCraftPerm(player, newTier))
 | 
					        if (plugin.playerHasCraftPerm(player, newTier))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            final EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemStackA, plugin);
 | 
				
			||||||
            EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemStackA, plugin);
 | 
					 | 
				
			||||||
            enchantments.merge(EnchantmentContainer.getEnchantments(itemStackB, plugin));
 | 
					            enchantments.merge(EnchantmentContainer.getEnchantments(itemStackB, plugin));
 | 
				
			||||||
            final Color color = getItemColor(itemStackA, itemStackB);
 | 
					            final Color color = getItemColor(itemStackA, itemStackB);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            result = ArmoredElytra.getInstance().getNbtEditor()
 | 
					            final ItemStack result = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), newTier,
 | 
				
			||||||
                                  .addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), newTier,
 | 
					                                                               plugin.getConfigLoader().unbreakable(), color);
 | 
				
			||||||
                                                   plugin.getConfigLoader().unbreakable(), color);
 | 
					            durabilityManager.setCombinedDurability(result, itemStackA, itemStackB,
 | 
				
			||||||
 | 
					                                                    nbtEditor.getArmorTier(itemStackA), newTier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            enchantments.applyEnchantments(result);
 | 
					            enchantments.applyEnchantments(result);
 | 
				
			||||||
            event.setResult(result);
 | 
					            event.setResult(result);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -82,7 +80,7 @@ abstract class SmithingTableListener extends ArmoredElytraHandler implements Lis
 | 
				
			|||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Check if the event was a player who interacted with a smithing table.
 | 
					        // Check if the event was a player who interacted with a smithing table.
 | 
				
			||||||
        Player player = (Player) event.getWhoClicked();
 | 
					        final Player player = (Player) event.getWhoClicked();
 | 
				
			||||||
        if (event.getView().getType() != InventoryType.SMITHING)
 | 
					        if (event.getView().getType() != InventoryType.SMITHING)
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -110,9 +108,8 @@ abstract class SmithingTableListener extends ArmoredElytraHandler implements Lis
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        final ItemStack result = smithingInventory.getItem(2);
 | 
					        final ItemStack result = smithingInventory.getItem(2);
 | 
				
			||||||
        if (result == null || result.getType() != Material.ELYTRA ||
 | 
					        if (result == null || result.getType() != Material.ELYTRA ||
 | 
				
			||||||
            ArmoredElytra.getInstance().getNbtEditor().getArmorTier(result) == ArmorTier.NONE)
 | 
					            nbtEditor.getArmorTier(result) == ArmorTier.NONE)
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
package nl.pim16aap2.armoredElytra.handlers;
 | 
					package nl.pim16aap2.armoredElytra.handlers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
					import nl.pim16aap2.armoredElytra.ArmoredElytra;
 | 
				
			||||||
 | 
					import nl.pim16aap2.armoredElytra.nbtEditor.INBTEditor;
 | 
				
			||||||
import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
					import nl.pim16aap2.armoredElytra.util.ArmorTier;
 | 
				
			||||||
import org.bukkit.ChatColor;
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
@@ -17,10 +18,12 @@ import org.bukkit.scheduler.BukkitRunnable;
 | 
				
			|||||||
public class Uninstaller implements Listener
 | 
					public class Uninstaller implements Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private final ArmoredElytra plugin;
 | 
					    private final ArmoredElytra plugin;
 | 
				
			||||||
 | 
					    private final INBTEditor nbtEditor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Uninstaller(ArmoredElytra plugin)
 | 
					    public Uninstaller(ArmoredElytra plugin, INBTEditor nbtEditor)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
 | 
					        this.nbtEditor = nbtEditor;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public int removeArmoredElytras(Inventory inv)
 | 
					    public int removeArmoredElytras(Inventory inv)
 | 
				
			||||||
@@ -28,7 +31,7 @@ public class Uninstaller implements Listener
 | 
				
			|||||||
        int count = 0;
 | 
					        int count = 0;
 | 
				
			||||||
        for (ItemStack is : inv)
 | 
					        for (ItemStack is : inv)
 | 
				
			||||||
            if (is != null && is.getType() == Material.ELYTRA &&
 | 
					            if (is != null && is.getType() == Material.ELYTRA &&
 | 
				
			||||||
                ArmoredElytra.getInstance().getNbtEditor().getArmorTier(is) != ArmorTier.NONE)
 | 
					                nbtEditor.getArmorTier(is) != ArmorTier.NONE)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                inv.remove(is);
 | 
					                inv.remove(is);
 | 
				
			||||||
                ++count;
 | 
					                ++count;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -130,12 +130,4 @@ public interface INBTEditor
 | 
				
			|||||||
     * @return The real durability of the itemstack if the itemstack has the AE durability attribute, or -1 otherwise.
 | 
					     * @return The real durability of the itemstack if the itemstack has the AE durability attribute, or -1 otherwise.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    int getRealDurability(ItemStack itemStack, @Nullable ArmorTier armorTier);
 | 
					    int getRealDurability(ItemStack itemStack, @Nullable ArmorTier armorTier);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * See {@link #getRealDurability(ItemStack, ArmorTier)}.
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    default int getRealDurability(ItemStack itemStack)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return getRealDurability(itemStack, null);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,7 @@ public class ConfigLoader
 | 
				
			|||||||
    private boolean uninstallMode;
 | 
					    private boolean uninstallMode;
 | 
				
			||||||
    private boolean checkForUpdates;
 | 
					    private boolean checkForUpdates;
 | 
				
			||||||
    private boolean noFlightDurability;
 | 
					    private boolean noFlightDurability;
 | 
				
			||||||
 | 
					    private boolean useTierDurability;
 | 
				
			||||||
    private boolean dropNetheriteAsChestplate;
 | 
					    private boolean dropNetheriteAsChestplate;
 | 
				
			||||||
    private LinkedHashSet<Enchantment> allowedEnchantments;
 | 
					    private LinkedHashSet<Enchantment> allowedEnchantments;
 | 
				
			||||||
    private boolean allowMultipleProtectionEnchantments;
 | 
					    private boolean allowMultipleProtectionEnchantments;
 | 
				
			||||||
@@ -70,6 +71,12 @@ public class ConfigLoader
 | 
				
			|||||||
                "Setting this to true will cause armored elytras to not lose any durability while flying.",
 | 
					                "Setting this to true will cause armored elytras to not lose any durability while flying.",
 | 
				
			||||||
                "This is not a permanent option and will affect ALL elytras."
 | 
					                "This is not a permanent option and will affect ALL elytras."
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					        String[] useTierDurabilityComment =
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "Use the maximum durability of the armor tier of armored elytras.",
 | 
				
			||||||
 | 
					                "For example, when this is true, a diamond armored elytra would have a durability of 528.",
 | 
				
			||||||
 | 
					                "When this is false, all armored elytras have the maximum durability of a regular elytra."
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
        String[] repairComment =
 | 
					        String[] repairComment =
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                "Amount of items it takes to fully repair an armored elytra",
 | 
					                "Amount of items it takes to fully repair an armored elytra",
 | 
				
			||||||
@@ -156,7 +163,6 @@ public class ConfigLoader
 | 
				
			|||||||
                "When true, only enchantments from the allowed list can be added."
 | 
					                "When true, only enchantments from the allowed list can be added."
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Set default list of allowed enchantments.
 | 
					        // Set default list of allowed enchantments.
 | 
				
			||||||
        List<String> defaultAllowedEnchantments = new ArrayList<>(
 | 
					        List<String> defaultAllowedEnchantments = new ArrayList<>(
 | 
				
			||||||
            Arrays.asList("minecraft:unbreaking", "minecraft:fire_protection", "minecraft:blast_protection",
 | 
					            Arrays.asList("minecraft:unbreaking", "minecraft:fire_protection", "minecraft:blast_protection",
 | 
				
			||||||
@@ -166,8 +172,10 @@ public class ConfigLoader
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        FileConfiguration config = plugin.getConfig();
 | 
					        FileConfiguration config = plugin.getConfig();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        unbreakable = addNewConfigOption(config, "unbreakable", false, unbreakableComment);
 | 
					        unbreakable = addNewConfigOption(config, "unbreakable", false, unbreakableComment);
 | 
				
			||||||
        noFlightDurability = addNewConfigOption(config, "noFlightDurability", false, flyDurabilityComment);
 | 
					        noFlightDurability = addNewConfigOption(config, "noFlightDurability", false, flyDurabilityComment);
 | 
				
			||||||
 | 
					        useTierDurability = addNewConfigOption(config, "useTierDurability", true, useTierDurabilityComment);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final ArmorTier[] armorTiers = ArmorTier.values();
 | 
					        final ArmorTier[] armorTiers = ArmorTier.values();
 | 
				
			||||||
        for (int idx = 1; idx < armorTiers.length; ++idx)
 | 
					        for (int idx = 1; idx < armorTiers.length; ++idx)
 | 
				
			||||||
@@ -384,7 +392,6 @@ public class ConfigLoader
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public boolean useTierDurability()
 | 
					    public boolean useTierDurability()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // TODO: Implement this option.
 | 
					        return useTierDurability;
 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,8 +2,11 @@ package nl.pim16aap2.armoredElytra.util;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.enchantments.Enchantment;
 | 
					import org.bukkit.enchantments.Enchantment;
 | 
				
			||||||
 | 
					import org.bukkit.entity.Player;
 | 
				
			||||||
import org.bukkit.inventory.ItemStack;
 | 
					import org.bukkit.inventory.ItemStack;
 | 
				
			||||||
 | 
					import org.bukkit.inventory.PlayerInventory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Nullable;
 | 
				
			||||||
import java.io.PrintWriter;
 | 
					import java.io.PrintWriter;
 | 
				
			||||||
import java.io.StringWriter;
 | 
					import java.io.StringWriter;
 | 
				
			||||||
import java.util.Locale;
 | 
					import java.util.Locale;
 | 
				
			||||||
@@ -138,6 +141,18 @@ public class Util
 | 
				
			|||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void moveChestplateToInventory(Player player)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        final PlayerInventory inventory = player.getInventory();
 | 
				
			||||||
 | 
					        inventory.addItem(inventory.getChestplate());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        final @Nullable ItemStack chestplate = inventory.getChestplate();
 | 
				
			||||||
 | 
					        if (chestplate != null)
 | 
				
			||||||
 | 
					            chestplate.setAmount(0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        player.updateInventory();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Ensures that a given value does not exceed the provided upper and lower bounds.
 | 
					     * Ensures that a given value does not exceed the provided upper and lower bounds.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user