Add allowAddingEnchantments config option
- Added the "allowAddingEnchantments" config option to control whether enchantments can be added to existing armored elytras.
This commit is contained in:
parent
62f316314f
commit
7e78ee74e9
@ -1,8 +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.nbtEditor.INBTEditor;
|
||||||
import nl.pim16aap2.armoredElytra.util.Action;
|
import nl.pim16aap2.armoredElytra.util.Action;
|
||||||
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 nl.pim16aap2.armoredElytra.util.Util;
|
import nl.pim16aap2.armoredElytra.util.Util;
|
||||||
import nl.pim16aap2.armoredElytra.util.XMaterial;
|
import nl.pim16aap2.armoredElytra.util.XMaterial;
|
||||||
@ -24,9 +26,14 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
public class AnvilHandler extends ArmoredElytraHandler implements Listener
|
public class AnvilHandler extends ArmoredElytraHandler implements Listener
|
||||||
{
|
{
|
||||||
|
private final ConfigLoader configLoader;
|
||||||
|
private final INBTEditor nbtEditor;
|
||||||
|
|
||||||
public AnvilHandler(final ArmoredElytra plugin, final boolean creationEnabled)
|
public AnvilHandler(final ArmoredElytra plugin, final boolean creationEnabled)
|
||||||
{
|
{
|
||||||
super(plugin, creationEnabled);
|
super(plugin, creationEnabled);
|
||||||
|
configLoader = plugin.getConfigLoader();
|
||||||
|
nbtEditor = plugin.getNbtEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AnvilHandler(final ArmoredElytra plugin)
|
public AnvilHandler(final ArmoredElytra plugin)
|
||||||
@ -66,13 +73,13 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
|
|||||||
if (Util.isChestPlate(matTwo))
|
if (Util.isChestPlate(matTwo))
|
||||||
return creationEnabled ? Action.CREATE : Action.NONE;
|
return creationEnabled ? Action.CREATE : Action.NONE;
|
||||||
|
|
||||||
ArmorTier tier = ArmoredElytra.getInstance().getNbtEditor().getArmorTier(itemOne);
|
ArmorTier tier = nbtEditor.getArmorTier(itemOne);
|
||||||
|
|
||||||
if (tier != ArmorTier.NONE)
|
if (tier != ArmorTier.NONE)
|
||||||
{
|
{
|
||||||
// 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 Action.ENCHANT;
|
return configLoader.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)
|
||||||
@ -80,7 +87,7 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
|
|||||||
|
|
||||||
// If the armored elytra is to be combined with another armored elytra of the
|
// If the armored elytra is to be combined with another armored elytra of the
|
||||||
// same tier...
|
// same tier...
|
||||||
if (ArmoredElytra.getInstance().getNbtEditor().getArmorTier(itemTwo) == tier)
|
if (nbtEditor.getArmorTier(itemTwo) == tier)
|
||||||
return creationEnabled ? Action.COMBINE : Action.NONE;
|
return creationEnabled ? Action.COMBINE : Action.NONE;
|
||||||
|
|
||||||
// If the armored elytra is not of the leather tier, but itemTwo is leather,
|
// If the armored elytra is not of the leather tier, but itemTwo is leather,
|
||||||
@ -116,7 +123,7 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
|
|||||||
{
|
{
|
||||||
Action action = isValidInput(itemA, itemB);
|
Action action = isValidInput(itemA, itemB);
|
||||||
ArmorTier newTier = ArmorTier.NONE;
|
ArmorTier newTier = ArmorTier.NONE;
|
||||||
ArmorTier curTier = ArmoredElytra.getInstance().getNbtEditor().getArmorTier(itemA);
|
ArmorTier curTier = nbtEditor.getArmorTier(itemA);
|
||||||
short durability = 0;
|
short durability = 0;
|
||||||
EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemA, plugin);
|
EnchantmentContainer enchantments = EnchantmentContainer.getEnchantments(itemA, plugin);
|
||||||
|
|
||||||
@ -168,9 +175,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 = ArmoredElytra.getInstance().getNbtEditor()
|
result = nbtEditor.addArmorNBTTags(result, newTier, configLoader.unbreakable(), name, color);
|
||||||
.addArmorNBTTags(result, newTier, plugin.getConfigLoader().unbreakable(),
|
|
||||||
name, color);
|
|
||||||
|
|
||||||
event.setResult(result);
|
event.setResult(result);
|
||||||
return;
|
return;
|
||||||
@ -180,15 +185,15 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
|
|||||||
// If one of the input items is null and the other an armored elytra, remove the result.
|
// If one of the input items is null and the other an armored elytra, remove the result.
|
||||||
// This prevent some naming issues.
|
// This prevent some naming issues.
|
||||||
if ((itemA == null ^ itemB == null) &&
|
if ((itemA == null ^ itemB == null) &&
|
||||||
ArmoredElytra.getInstance().getNbtEditor().getArmorTier(itemA == null ? itemB : itemA) != ArmorTier.NONE)
|
nbtEditor.getArmorTier(itemA == null ? itemB : itemA) != ArmorTier.NONE)
|
||||||
event.setResult(null);
|
event.setResult(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getElytraResultName(final ItemStack baseItem, final Action action,
|
private String getElytraResultName(final ItemStack baseItem, final Action action,
|
||||||
final ArmorTier armorTier, final String renameText)
|
final ArmorTier armorTier, final String renameText)
|
||||||
{
|
{
|
||||||
final String tierName = ArmoredElytra.getInstance().getArmoredElytraName(armorTier);
|
final String tierName = plugin.getArmoredElytraName(armorTier);
|
||||||
if (renameText == null || !plugin.getConfigLoader().allowRenaming())
|
if (renameText == null || !configLoader.allowRenaming())
|
||||||
return tierName;
|
return tierName;
|
||||||
|
|
||||||
final ItemMeta meta = baseItem.getItemMeta();
|
final ItemMeta meta = baseItem.getItemMeta();
|
||||||
@ -236,7 +241,7 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener
|
|||||||
if (anvilInventory.getItem(0) != null && anvilInventory.getItem(1) != null &&
|
if (anvilInventory.getItem(0) != null && anvilInventory.getItem(1) != null &&
|
||||||
anvilInventory.getItem(2) != null && anvilInventory.getItem(2).getType() == Material.ELYTRA)
|
anvilInventory.getItem(2) != null && anvilInventory.getItem(2).getType() == Material.ELYTRA)
|
||||||
{
|
{
|
||||||
ArmorTier armortier = ArmoredElytra.getInstance().getNbtEditor().getArmorTier(anvilInventory.getItem(2));
|
ArmorTier armortier = nbtEditor.getArmorTier(anvilInventory.getItem(2));
|
||||||
|
|
||||||
// If there's an armored elytra in the final slot...
|
// If there's an armored elytra in the final slot...
|
||||||
if (armortier != ArmorTier.NONE && plugin.playerHasCraftPerm(player, armortier))
|
if (armortier != ArmorTier.NONE && plugin.playerHasCraftPerm(player, armortier))
|
||||||
|
@ -39,6 +39,7 @@ public class ConfigLoader
|
|||||||
private boolean bypassWearPerm;
|
private boolean bypassWearPerm;
|
||||||
private boolean bypassCraftPerm;
|
private boolean bypassCraftPerm;
|
||||||
private boolean allowRenaming;
|
private boolean allowRenaming;
|
||||||
|
private boolean allowAddingEnchantments;
|
||||||
|
|
||||||
private final ArrayList<nl.pim16aap2.armoredElytra.util.ConfigOption<?>> configOptionsList;
|
private final ArrayList<nl.pim16aap2.armoredElytra.util.ConfigOption<?>> configOptionsList;
|
||||||
private final ArmoredElytra plugin;
|
private final ArmoredElytra plugin;
|
||||||
@ -143,6 +144,12 @@ public class ConfigLoader
|
|||||||
{
|
{
|
||||||
"Whether or not to allow renaming of armored elytras in anvils."
|
"Whether or not to allow renaming of armored elytras in anvils."
|
||||||
};
|
};
|
||||||
|
String[] allowAddingEnchantmentsComment =
|
||||||
|
{
|
||||||
|
"Allow new enchantments to be added to armored elytras.",
|
||||||
|
"When false, no enchantments can be added to armored elytras, even those on the allowed list.",
|
||||||
|
"When true, only enchantments from the allowed list can be added."
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Set default list of allowed enchantments.
|
// Set default list of allowed enchantments.
|
||||||
@ -205,6 +212,8 @@ public class ConfigLoader
|
|||||||
|
|
||||||
allowMultipleProtectionEnchantments = addNewConfigOption(config, "allowMultipleProtectionEnchantments", false,
|
allowMultipleProtectionEnchantments = addNewConfigOption(config, "allowMultipleProtectionEnchantments", false,
|
||||||
allowMultipleProtectionEnchantmentsComment);
|
allowMultipleProtectionEnchantmentsComment);
|
||||||
|
allowAddingEnchantments = addNewConfigOption(config, "allowAddingEnchantments", true,
|
||||||
|
allowAddingEnchantmentsComment);
|
||||||
allowRenaming = addNewConfigOption(config, "allowRenaming", true, allowRenamingComment);
|
allowRenaming = addNewConfigOption(config, "allowRenaming", true, allowRenamingComment);
|
||||||
dropNetheriteAsChestplate = addNewConfigOption(config, "dropNetheriteAsChestplate", true,
|
dropNetheriteAsChestplate = addNewConfigOption(config, "dropNetheriteAsChestplate", true,
|
||||||
dropNetheriteAsChestplateComment);
|
dropNetheriteAsChestplateComment);
|
||||||
@ -334,6 +343,11 @@ public class ConfigLoader
|
|||||||
return allowRenaming;
|
return allowRenaming;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean allowAddingEnchantments()
|
||||||
|
{
|
||||||
|
return allowAddingEnchantments;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean uninstallMode()
|
public boolean uninstallMode()
|
||||||
{
|
{
|
||||||
return uninstallMode;
|
return uninstallMode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user