- Added permission nodes for wearing and spawning in armor!

- armoredelytra.give.<leather/gold/chain/iron/diamond>
  - armoredelytra.wear.<leather/gold/chain/iron/diamond>
- Fixed bug where you could not craft leather/gold armored elytras in version 1.12.x of MineCraft.
This commit is contained in:
Pim van der Loos 2017-09-22 20:47:00 +02:00
parent 49ffc021f7
commit b7059d4544
6 changed files with 204 additions and 48 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>nl.pim16aap2</groupId>
<artifactId>ArmoredElytra</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<repositories>
<repository>
<id>spigot-repo</id>

View File

@ -4,12 +4,17 @@ import java.util.List;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import nl.pim16aap2.armoredElytra.nms.NBTEditor;
import nl.pim16aap2.armoredElytra.nms.V1_11_R1;
import nl.pim16aap2.armoredElytra.nms.V1_12_R1;
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_11_R1;
import nl.pim16aap2.armoredElytra.nms.NBTEditor_V1_12_R1;
public class ArmoredElytra extends JavaPlugin implements Listener
{
@ -23,13 +28,13 @@ public class ArmoredElytra extends JavaPlugin implements Listener
@Override
public void onEnable()
{
{
saveDefaultConfig();
LEATHER_TO_FULL = this.getConfig().getInt("leatherRepair");
GOLD_TO_FULL = this.getConfig().getInt("goldRepair");
IRON_TO_FULL = this.getConfig().getInt("ironRepair");
DIAMONDS_TO_FULL = this.getConfig().getInt("diamondsRepair");
cursesAllowed = this.getConfig().getBoolean("allowCurses");
LEATHER_TO_FULL = this.getConfig().getInt("leatherRepair", 6);
GOLD_TO_FULL = this.getConfig().getInt("goldRepair", 5);
IRON_TO_FULL = this.getConfig().getInt("ironRepair", 4);
DIAMONDS_TO_FULL = this.getConfig().getInt("diamondsRepair", 3);
cursesAllowed = this.getConfig().getBoolean("allowCurses", true);
List<String> list = this.getConfig().getStringList("allowedEnchantments");
allowedEnchants = list.toArray(new String[0]);
@ -47,6 +52,102 @@ public class ArmoredElytra extends JavaPlugin implements Listener
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender instanceof Player)
{
Player player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("ArmoredElytra"))
{
if (args.length == 1)
{
ItemStack newElytra = null;
String tier = args[0];
// Leather armor.
if (tier.equalsIgnoreCase("leather"))
{
if (player.hasPermission("armoredelytra.give.leather"))
{
player.sendMessage("Giving you an armored elytra of the leather armor tier!");
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 1);
} else
{
player.sendMessage("You do not have the required permission node for this armor tier!");
}
// Gold armor.
} else if (tier.equalsIgnoreCase("gold"))
{
if (player.hasPermission("armoredelytra.give.gold"))
{
player.sendMessage("Giving you an armored elytra of the gold armor tier!");
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 2);
} else
{
player.sendMessage("You do not have the required permission node for this armor tier!");
}
// Chain armor.
} else if (tier.equalsIgnoreCase("chain"))
{
if (player.hasPermission("armoredelytra.give.chain"))
{
player.sendMessage("Giving you an armored elytra of the chain armor tier!");
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 3);
} else
{
player.sendMessage("You do not have the required permission node for this armor tier!");
}
// Iron armor.
} else if (tier.equalsIgnoreCase("iron"))
{
if (player.hasPermission("armoredelytra.give.iron"))
{
player.sendMessage("Giving you an armored elytra of the iron armor tier!");
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 4);
} else
{
player.sendMessage("You do not have the required permission node for this armor tier!");
}
// Diamond armor.
} else if (tier.equalsIgnoreCase("diamond"))
{
if (player.hasPermission("armoredelytra.give.diamond"))
{
player.sendMessage("Giving you an armored elytra of the diamond armor tier!");
newElytra = nbtEditor.addArmorNBTTags(new ItemStack(Material.ELYTRA, 1), 5);
} else
{
player.sendMessage("You do not have the required permission node for this armor tier!");
}
} else
{
player.sendMessage("Not a supported armor tier! Try one of these: leather, gold, chain, iron, diamond.");
}
giveArmoredElytraToPlayer(player, newElytra);
return true;
}
}
}
return false;
}
// Give the provided player the provided item.
public void giveArmoredElytraToPlayer(Player player, ItemStack item)
{
if (item != null)
{
player.getInventory().addItem(item);
}
}
// Check + initialize for the correct version of Minecraft.
public boolean compatibleMCVer()
{
@ -62,11 +163,11 @@ public class ArmoredElytra extends JavaPlugin implements Listener
if (version.equals("v1_11_R1"))
{
nbtEditor = new V1_11_R1();
nbtEditor = new NBTEditor_V1_11_R1();
} else if (version.equals("v1_12_R1"))
{
nbtEditor = new V1_12_R1();
nbtEditor = new NBTEditor_V1_12_R1();
}
// Return true if compatible.
return nbtEditor != null;

View File

@ -6,7 +6,6 @@ import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -15,6 +14,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
@ -405,43 +405,73 @@ public class EventHandlers implements Listener
}
// Check if the player tries to equip armor by richt clicking it.
@SuppressWarnings("deprecation")
@EventHandler
public void onRightClick(PlayerInteractEvent event)
{
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
if (item != null)
{
if (item.getType() == Material.ELYTRA && isArmoredElytra(item))
{
int armorTier = nbtEditor.getArmorTier(item);
if ((armorTier == 1 && !player.hasPermission("armoredelytra.wear.leather")) ||
(armorTier == 2 && !player.hasPermission("armoredelytra.wear.gold")) ||
(armorTier == 3 && !player.hasPermission("armoredelytra.wear.chain")) ||
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
{
player.sendMessage(ChatColor.RED + "You do not have the required permission to wear this armor tier!.");
event.setCancelled(true);
}
}
}
}
// Check if the player is trying to equip a broken elytra (and prevent that).
@EventHandler
public void playerEquipsArmor(InventoryClickEvent e)
{
if (e.getWhoClicked() instanceof Player)
{
Player p = (Player) e.getWhoClicked();
int slot = e.getRawSlot();
// Chestplate slot.
if (slot == 6)
Player player = (Player) e.getWhoClicked();
new BukkitRunnable()
{
new BukkitRunnable()
{
@Override
public void run()
{
// If the player equips a new chestplate.
if (p.getInventory().getChestplate() != null)
@Override
public void run()
{
ItemStack chestplate = player.getInventory().getChestplate();
// If the player equips a new chestplate.
if (player.getInventory().getChestplate() != null)
{
// If that chestplate is an (armored) elytra.
if (chestplate.getType() == Material.ELYTRA && isArmoredElytra(chestplate))
{
// If that chestplate is an (armored) elytra.
if (p.getInventory().getChestplate().getType() == Material.ELYTRA && isArmoredElytra(p.getInventory().getChestplate()))
int armorTier = nbtEditor.getArmorTier(chestplate);
if ((chestplate.getDurability() >= chestplate.getType().getMaxDurability()))
{
if (p.getInventory().getChestplate().getDurability() >= p.getInventory().getChestplate().getType().getMaxDurability())
{
p.sendMessage(ChatColor.RED + "You cannot equip this elytra! Please repair it in an anvil first.");
unenquipChestPlayer(p);
}
player.sendMessage(ChatColor.RED + "You cannot equip this elytra! Please repair it in an anvil first.");
unenquipChestPlayer(player);
} else if ((armorTier == 1 && !player.hasPermission("armoredelytra.wear.leather")) ||
(armorTier == 2 && !player.hasPermission("armoredelytra.wear.gold")) ||
(armorTier == 3 && !player.hasPermission("armoredelytra.wear.chain")) ||
(armorTier == 4 && !player.hasPermission("armoredelytra.wear.iron")) ||
(armorTier == 5 && !player.hasPermission("armoredelytra.wear.diamond")))
{
player.sendMessage(ChatColor.RED + "You do not have the required permission to wear this armor tier!.");
unenquipChestPlayer(player);
}
player.updateInventory();
e.setCancelled(true);
}
}
}.runTaskLater(this.plugin, 1);
}
}
}
}
}.runTaskLater(this.plugin, 1);
}
}
}
}

View File

@ -12,7 +12,7 @@ import net.minecraft.server.v1_11_R1.NBTTagInt;
import net.minecraft.server.v1_11_R1.NBTTagList;
import net.minecraft.server.v1_11_R1.NBTTagString;
public class V1_11_R1 implements NBTEditor
public class NBTEditor_V1_11_R1 implements NBTEditor
{
@Override
@ -33,12 +33,10 @@ public class V1_11_R1 implements NBTEditor
switch (armorTier)
{
case 1:
// color = ChatColor.valueOf("733D31");
color = ChatColor.DARK_GREEN;
armorProtection = 3;
break;
case 2:
// color = ChatColor.valueOf("FFD700");
color = ChatColor.YELLOW;
armorProtection = 5;
break;

View File

@ -12,7 +12,7 @@ import net.minecraft.server.v1_12_R1.NBTTagInt;
import net.minecraft.server.v1_12_R1.NBTTagList;
import net.minecraft.server.v1_12_R1.NBTTagString;
public class V1_12_R1 implements NBTEditor
public class NBTEditor_V1_12_R1 implements NBTEditor
{
@Override
public ItemStack addArmorNBTTags(ItemStack item, int armorTier)
@ -32,11 +32,11 @@ public class V1_12_R1 implements NBTEditor
switch (armorTier)
{
case 1:
color = ChatColor.valueOf("733D31");
color = ChatColor.DARK_GREEN;
armorProtection = 3;
break;
case 2:
color = ChatColor.valueOf("FFD700");
color = ChatColor.YELLOW;
armorProtection = 5;
break;
case 3:

View File

@ -1,4 +1,31 @@
name: ArmoredElytra
main: nl.pim16aap2.armoredElytra.ArmoredElytra
version: 1.3.0
author: Pim
version: 1.4.0
author: Pim
commands:
ArmoredElytra:
description: Give an armored elytra of the specified tier.
usage: /ArmoredElytra <tier>
permission: armoredelytra.give
permission-message: You do not have the armoredelytra.give permission node.
permissions:
armoredelytra.wear.leather:
description: Allow the player to wear leather tier armored elytras.
armoredelytra.wear.gold:
description: Allow the player to wear gold tier armored elytras.
armoredelytra.wear.chain:
description: Allow the player to wear chain tier armored elytras.
armoredelytra.wear.iron:
description: Allow the player to wear iron tier armored elytras.
armoredelytra.wear.diamond:
description: Allow the player to wear diamond tier armored elytras.
armoredelytra.give.leather:
description: Allow the player to spawn in leather tier armored elytras.
armoredelytra.give.gold:
description: Allow the player to spawn in gold tier armored elytras.
armoredelytra.give.chain:
description: Allow the player to spawn in chain tier armored elytras.
armoredelytra.give.iron:
description: Allow the player to spawn in iron tier armored elytras.
armoredelytra.give.diamond:
description: Allow the player to spawn in diamond tier armored elytras.