- Added armoredelytra.craft.<tier> permissions.

- Removed cursesAllowed option. It is now part of the allowedEnchantments. (Fixed mending not allowed when curses are not allowed).
- Fixed glitch where "ghosts" of items remained in the anvil after taking the result out using shift + click.
This commit is contained in:
Pim van der Loos 2018-02-05 12:20:29 +01:00
parent e5044a7300
commit 511a0c85f9
7 changed files with 64 additions and 59 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>nl.pim16aap2</groupId>
<artifactId>ArmoredElytra</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.4-SNAPSHOT</version>
<repositories>

View File

@ -132,8 +132,6 @@ public class ArmoredElytra extends JavaPlugin implements Listener
myLogger(Level.INFO, ("Allowed enchantments:"));
for (String s : config.getStringList("allowedEnchantments"))
myLogger(Level.INFO, " - " + s);
// Log whether or not curses are allowed.
myLogger(Level.INFO, "Curses on armored elytras are " + (config.getBool("allowCurses") ? "" : "not " + "allowed!"));
}
else
{
@ -298,6 +296,25 @@ public class ArmoredElytra extends JavaPlugin implements Listener
return ret;
}
public boolean playerHasCraftPerm(Player player, ArmorTier tier)
{
switch (tier)
{
case LEATHER:
return player.hasPermission("armoredelytra.craft.leather");
case GOLD:
return player.hasPermission("armoredelytra.craft.gold");
case CHAIN:
return player.hasPermission("armoredelytra.craft.chain");
case IRON:
return player.hasPermission("armoredelytra.craft.iron");
case DIAMOND:
return player.hasPermission("armoredelytra.craft.diamond");
default:
return false;
}
}
public void setUpToDate(boolean upToDate)
{

View File

@ -120,7 +120,7 @@ public class CommandHandler implements CommandExecutor
plugin.giveArmoredElytraToPlayer(receiver, newElytra);
}
else
plugin.messagePlayer(player, "You do not have the required permission node to give " + plugin.getArmoredElytrName(armorTier) + " armored elytras.");
plugin.messagePlayer(player, "You do not have the required permission node to give " + plugin.getArmoredElytrName(armorTier));
return true;
}
}

View File

@ -36,13 +36,9 @@ public class EventHandlers implements Listener
private int LEATHER_TO_FULL;
private int GOLD_TO_FULL;
private int IRON_TO_FULL;
private boolean cursesAllowed;
private NBTEditor nbtEditor;
private final ArmoredElytra plugin;
private List<String> allowedEnchantments;
private String[] cursedEnchantments = { "MENDING" ,
"VANISHING_CURSE" ,
"BINDING_CURSE" };
public EventHandlers(ArmoredElytra plugin, NBTEditor nbtEditor)
{
@ -50,7 +46,6 @@ public class EventHandlers implements Listener
this.nbtEditor = nbtEditor;
// Get the values of the config options.
this.cursesAllowed = plugin.getConfigLoader().getBool("allowCurses");
this.allowedEnchantments = plugin.getConfigLoader().getStringList("allowedEnchantments");
this.LEATHER_TO_FULL = plugin.getConfigLoader().getInt("leatherRepair");
this.GOLD_TO_FULL = plugin.getConfigLoader().getInt("goldRepair");
@ -76,15 +71,6 @@ public class EventHandlers implements Listener
return false;
}
// Check if the enchantment is a curse.
public boolean isCursedEnchantment(Enchantment enchant)
{
for (String s : cursedEnchantments)
if (Enchantment.getByName(s).equals(enchant))
return true;
return false;
}
// Combine 2 maps of enchantments (and remove any invalid ones).
public Map<Enchantment, Integer> combineEnchantments(Map<Enchantment, Integer> enchantments0, Map<Enchantment, Integer> enchantments1)
{
@ -98,11 +84,7 @@ public class EventHandlers implements Listener
for (Map.Entry<Enchantment, Integer > entry : enchantments1.entrySet())
{
Integer enchantLevel = enchantments0.get(entry.getKey());
// If the enchantment is a curse and if the result does not already have it.
if (isCursedEnchantment(entry.getKey()) && !enchantments0.containsKey(entry.getKey()))
combined.put(entry.getKey(), entry.getValue());
// If the enchantment is already on the list...
else if (enchantLevel != null)
if (enchantLevel != null)
{
if (entry.getValue() == enchantLevel && entry.getValue() < entry.getKey().getMaxLevel())
enchantLevel = entry.getValue() + 1;
@ -189,23 +171,21 @@ public class EventHandlers implements Listener
return (short) (newDurability <= 0 ? 0 : newDurability);
}
// Remove any disallowed enchantments / curses in the map.
// Remove any disallowed enchantments in the map.
public Map<Enchantment, Integer> fixEnchantments(Map<Enchantment, Integer> enchantments)
{
Map<Enchantment, Integer> ret = new HashMap<Enchantment, Integer>(enchantments);
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet())
// If it is not an allowed enchantment OR a curse while it's not allowed
if (!isAllowedEnchantment(entry.getKey()) || (!cursesAllowed && isCursedEnchantment(entry.getKey())))
if (!isAllowedEnchantment(entry.getKey()))
ret.remove(entry.getKey());
return ret;
}
// Verify there aren't any disallowed enchantments / curses in the map.
// Verify there aren't any disallowed enchantments in the map.
public boolean verifyEnchantments(Map<Enchantment, Integer> enchantments)
{
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet())
// If it is not an allowed enchantment OR a curse while it's not allowed
if (!isAllowedEnchantment(entry.getKey()) || (!cursesAllowed && isCursedEnchantment(entry.getKey())))
if (!isAllowedEnchantment(entry.getKey()))
return false;
return true;
}
@ -311,7 +291,7 @@ public class EventHandlers implements Listener
@EventHandler
public void onAnvilInventoryOpen(PrepareAnvilEvent event)
{
Player p = (Player) event.getView().getPlayer();
Player player = (Player) event.getView().getPlayer();
ItemStack itemA = event.getInventory().getItem(0);
ItemStack itemB = event.getInventory().getItem(1);
@ -369,24 +349,28 @@ public class EventHandlers implements Listener
}
case BLOCK:
event.setResult(null);
p.updateInventory();
player.updateInventory();
case NONE:
return;
}
if (plugin.playerHasCraftPerm(player, newTier))
{
result = new ItemStack(Material.ELYTRA, 1);
if (enchantments != null)
result.addUnsafeEnchantments(enchantments);
result.setDurability(durability);
result = nbtEditor.addArmorNBTTags(result, newTier, plugin.getConfigLoader().getBool("unbreakable"));
event.setResult(result);
}
}
// Check if either itemA or itemB is unoccupied.
if ((itemA == null || itemB == null) && nbtEditor.getArmorTier(event.getInventory().getItem(2)) != ArmorTier.NONE)
// If Item2 is occupied despite itemA or itemB not being occupied. (only for armored elytra)/
event.setResult(null);
p.updateInventory();
player.updateInventory();
}
// Let the player take items out of the anvil.
@ -396,7 +380,7 @@ public class EventHandlers implements Listener
if (e.getWhoClicked() instanceof Player)
{
// Check if the event was a player who interacted with an anvil.
Player p = (Player) e.getWhoClicked();
Player player = (Player) e.getWhoClicked();
if (e.getView().getType() == InventoryType.ANVIL)
{
AnvilInventory anvilInventory;
@ -410,7 +394,7 @@ public class EventHandlers implements Listener
catch (ClassCastException exception)
{
// Print warning to console and exit onInventoryClick event (no support for custom inventories as they are usually used for GUI's).
plugin.debugMsg(Level.WARNING, "Could not cast inventory to anvilInventory for player " + p.getName() + "! Armored Elytras cannot be crafted!");
plugin.debugMsg(Level.WARNING, "Could not cast inventory to anvilInventory for player " + player.getName() + "! Armored Elytras cannot be crafted!");
return;
}
@ -420,7 +404,7 @@ public class EventHandlers implements Listener
{
ArmorTier armortier = nbtEditor.getArmorTier(anvilInventory.getItem(2));
// If there's an armored elytra in the final slot...
if (armortier != ArmorTier.NONE)
if (armortier != ArmorTier.NONE && plugin.playerHasCraftPerm(player, armortier))
{
// Create a new armored elytra and give that one to the player instead of the result.
// This is done because after putting item0 in AFTER item1, the first letter of the color code shows up, this gets rid of that problem.
@ -429,14 +413,15 @@ public class EventHandlers implements Listener
if (e.isShiftClick())
{
// If the player's inventory is full, don't do anything.
if (p.getInventory().firstEmpty() == -1)
if (player.getInventory().firstEmpty() == -1)
return;
p.getInventory().addItem(result);
player.getInventory().addItem(result);
}
else
p.setItemOnCursor(result);
player.setItemOnCursor(result);
// Clean the anvil's inventory after transferring the items.
cleanAnvil(anvilInventory);
player.updateInventory();
return;
}
}

View File

@ -27,7 +27,6 @@ public class ConfigLoader
private String ironName;
private String diamondName;
private String elytraLore;
private boolean cursesAllowed;
private List<String> allowedEnchantments;
private String usageDeniedMessage;
private String elytraReceivedMessage;
@ -48,11 +47,9 @@ public class ConfigLoader
"Repair cost for every tier of armored elytra in number of items to repair 100%."};
private String[] tierNameComment =
{"Name for every armored elytra tier."};
private String[] cursesComment =
{"Will curses (vanishing, binding) be transferred when creating armored elytras?"};
private String[] enchantmentsComment =
{"List of enchantments that are allowed to be put on an armored elytra.",
"If you do not want to allow any enchantments, remove them all and add \"NONE\"",
"If you do not want to allow any enchantments at all, remove them all and add \"NONE\"",
"You can find supported enchantments here:",
"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html",
"Note that only 1 protection enchantment (PROTECTION_FIRE, PROTECTION_ENVIRONMENTAL etc) can be active on an elytra."};
@ -128,8 +125,6 @@ public class ConfigLoader
elytraReceivedMessage = config.getString ("elytraReceivedMessage" );
configOptionsList.add(new ConfigOption ("elytraReceivedMessage", elytraReceivedMessage, elytraReceivedComment));
cursesAllowed = config.getBoolean ("allowCurses", true );
configOptionsList.add(new ConfigOption ("allowCurses", cursesAllowed, cursesComment));
allowedEnchantments = config.getStringList("allowedEnchantments");
configOptionsList.add(new ConfigOption ("allowedEnchantments", allowedEnchantments, enchantmentsComment ));

View File

@ -16,10 +16,6 @@ chain:
iron:
diamond:
# Will curses (vanishing, binding) be transferred when creating armored elytras?
allowCurses: true
# List of enchantments that are allowed to be put on an armored elytra.
# If you do not want to allow any enchantments, remove them all and add "NONE"
# You can find supported enchantments here:
@ -32,17 +28,19 @@ allowedEnchantments:
- PROTECTION_PROJECTILE
- PROTECTION_ENVIRONMENTAL
- THORNS
- BINDING_CURSE
- VANISHING_CURSE
# Message players receive when they lack the required permissions to wear a certain armor tier. "NONE" = no message.
# %ARMOR_TIER% is replaced by the name of the armor tier.
usageDeniedMessage: 'You do not have the required permissions to wear %ARMOR_TIER% armored elytras!'
usageDeniedMessage: 'You do not have the required permissions to wear %ARMOR_TIER%!'
# Message players receive when they are given an armored elytra using commands. "NONE" = no message.
# %ARMOR_TIER% is replaced by the name of the armor tier.
elytraReceivedMessage: '&2A(n) %ARMOR_TIER% armored elytra has been bestowed upon you!'
elytraReceivedMessage: '&2A(n) %ARMOR_TIER% has been bestowed upon you!'
# The name of armored elytras. %ARMOR_TIER% is replaced by the name of the armor tier.
elytraName: '%ARMOR_TIER% Armored Elytra'
elytraName: '%ARMOR_TIER%'
# The lore of armored elytras. "NONE" = no lore. %ARMOR_TIER% is replaced by the name of the armor tier.
elytraLore: 'Elytra with %ARMOR_TIER% level protection'

View File

@ -1,6 +1,6 @@
name: ArmoredElytra
main: nl.pim16aap2.armoredElytra.ArmoredElytra
version: 2.3
version: 2.4
author: Pim
commands:
ArmoredElytra:
@ -17,6 +17,16 @@ permissions:
description: Allow the player to wear iron tier armored elytras.
armoredelytra.wear.diamond:
description: Allow the player to wear diamond tier armored elytras.
armoredelytra.craft.leather:
description: Allow the player to craft leather tier armored elytras.
armoredelytra.craft.gold:
description: Allow the player to craft gold tier armored elytras.
armoredelytra.craft.chain:
description: Allow the player to craft chain tier armored elytras.
armoredelytra.craft.iron:
description: Allow the player to craft iron tier armored elytras.
armoredelytra.craft.diamond:
description: Allow the player to craft diamond tier armored elytras.
armoredelytra.give.leather:
description: Allow the player to spawn in leather tier armored elytras.
armoredelytra.give.gold: