From e9cb4ef576590d5772b4c7d79bfbc42ee21c0dd6 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sat, 27 Aug 2016 01:40:48 -0400 Subject: [PATCH] Added a diamond armor blocker --- src/alisolarflare/DiamondArmorBlocker.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/alisolarflare/DiamondArmorBlocker.java diff --git a/src/alisolarflare/DiamondArmorBlocker.java b/src/alisolarflare/DiamondArmorBlocker.java new file mode 100644 index 0000000..80d8eaf --- /dev/null +++ b/src/alisolarflare/DiamondArmorBlocker.java @@ -0,0 +1,49 @@ +package alisolarflare; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.inventory.ItemStack; + +public class DiamondArmorBlocker implements Listener{ + public static List blockedItems = Arrays.asList(Material.DIAMOND_BOOTS, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_HELMET); + @EventHandler + public void onArmorSmith(CraftItemEvent event){ + //SANITATION - hardcore + if(event.getWhoClicked().getWorld().getName() != "hardcore"){ + return; + } + + //INIT - inventory, targetItem + ItemStack targetItem = event.getRecipe().getResult(); + + //REPLACE - Diamond Chestplate > Chainmail Chestplate + if (blockedItems.contains(targetItem.getType())){ + event.setCancelled(true); + //GIVE - chainmail chestplate + event.getWhoClicked().getInventory().addItem(failArmor(targetItem.getType())); + //PLAY - cave sound + event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0); + event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.ENTITY_ITEM_BREAK,0,0); + } + + + } + public ItemStack failArmor(Material material){ + ItemStack failArmor = new ItemStack(material); + failArmor.addEnchantment(Enchantment.THORNS, 1); + + //INIT - Chainmail's lore + List loreString = new ArrayList(); + loreString.add("This world is forever dangerous. There is no protection here"); + failArmor.getItemMeta().setLore(loreString); + return failArmor; + } +}