-
-
Save NinjaWaffles/8a5bce451b300d07e171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArmorListener implements Listener | |
{ | |
private Material[] armor = { Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS, Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS, Material.CHAINMAIL_HELMET, Material.CHAINMAIL_CHESTPLATE, Material.CHAINMAIL_LEGGINGS, Material.CHAINMAIL_BOOTS }; | |
@EventHandler | |
public void onInventoryClick(InventoryClickEvent e) | |
{ | |
Player player = (Player) e.getWhoClicked(); | |
for(int i = 0; i < armor.length; i++) | |
{ | |
if(e.getCurrentItem().getType().equals(armor[i]) && e.getSlotType() == SlotType.ARMOR) | |
{ | |
PlayerArmorChangeEvent event = new PlayerArmorChangeEvent(player, armor[i], EnumArmorMethods.INVENTORY_CLICK_EVENT); | |
Bukkit.getServer().getPluginManager().callEvent(event); | |
} | |
} | |
} | |
@EventHandler | |
public void onPlayerInteract(PlayerInteractEvent e) | |
{ | |
Player player = e.getPlayer(); | |
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) | |
{ | |
for(int i = 0; i < armor.length; i++) | |
{ | |
if(player.getItemInHand().getType().equals(armor[i])) | |
{ | |
PlayerArmorChangeEvent event = new PlayerArmorChangeEvent(player, armor[i], EnumArmorMethods.INVENTORY_INTERACT_EVENT); | |
Bukkit.getServer().getPluginManager().callEvent(event); | |
} | |
} | |
} | |
} | |
@EventHandler | |
public void onBlockDispense(BlockDispenseEvent e) | |
{ | |
for(int i = 0; i < armor.length; i++) | |
{ | |
if(e.getItem().getType().equals(armor[i])) | |
{ | |
World world = e.getBlock().getWorld(); | |
for(Entity ent : world.getEntities()) | |
{ | |
if(ent.getLocation().distance(e.getBlock().getLocation()) <= 2 && ent instanceof Player) | |
{ | |
Player player = (Player) ent; | |
PlayerArmorChangeEvent event = new PlayerArmorChangeEvent(player, armor[i], EnumArmorMethods.DISPENSE_EVENT); | |
Bukkit.getServer().getPluginManager().callEvent(event); | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum EnumArmorMethods | |
{ | |
INVENTORY_CLICK_EVENT("InventoryClickEvent"), | |
INVENTORY_INTERACT_EVENT("PlayerInteractEvent"), | |
DISPENSE_EVENT("BlockDispenseEvent"); | |
private String eventName; | |
EnumArmorMethods(String eventName) | |
{ | |
this.eventName = eventName; | |
} | |
public String getEventName() | |
{ | |
return eventName; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PlayerArmorChangeEvent extends Event | |
{ | |
private static final HandlerList handlers = new HandlerList(); | |
private Player player; | |
private Material armorType; | |
private EnumArmorMethods method; | |
public PlayerArmorChangeEvent(Player player, Material armorType, EnumArmorMethods method) | |
{ | |
this.player = player; | |
this.armorType = armorType; | |
this.method = method; | |
} | |
public Player getPlayer() | |
{ | |
return player; | |
} | |
public Material getArmorType() | |
{ | |
return armorType; | |
} | |
public EnumArmorMethods getMethod() | |
{ | |
return method; | |
} | |
public HandlerList getHandlers() | |
{ | |
return handlers; | |
} | |
public static HandlerList getHandlerList() | |
{ | |
return handlers; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment