1.12.2 How Use ArmorEquipEvent

Discussion in 'Spigot Plugin Development' started by Snowman-233, Sep 16, 2020 at 6:38 PM.

?

How Use ArmorEqupEvent

  1. How USe ARMOR EQUP EVENT

    2 vote(s)
    100.0%
  2. How USe ARMOR EQUP EVENT

    2 vote(s)
    100.0%
  3. How USe ARMOR EQUP EVENT

    2 vote(s)
    100.0%
Multiple votes are allowed.
  1. How Use ArmorEquipEvent Pls Say Me :(
     
  2. This is not a Resource, please remove the tag. ArmorEquipEvent will run the code when a player equips armor (and maybe changes the armor too idk, never used it). What have you tried, can you show your code?
     
  3. ok w8

    My Commands File
    Code (Java):
    package org.snowman.uaccessories.Commands;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.Color;
    import org.bukkit.DyeColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.snowman.uaccessories.Utils.Utils;

    public class GUICmD implements CommandExecutor {
        ArrayList<String> LLore = new ArrayList<String>();
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player) {
                Player p = (Player)sender;
                if(cmd.getName().equalsIgnoreCase("uac")) {
                    @SuppressWarnings({ "deprecation", "unused" })
                    ItemStack LightningBoots = new ItemStack(Material.LEATHER_CHESTPLATE);
                    LeatherArmorMeta LMeta = (LeatherArmorMeta) LightningBoots.getItemMeta();
                    LMeta.setColor(Color.fromRGB(0, 255, 0));
                    LMeta.setDisplayName(Utils.chat("&f&lLightning Boots &b&l✈"));
                    LLore.remove(Utils.chat("&7Ability » &aSpeed I"));
                    LLore.add(Utils.chat("&7Ability » &aSpeed I"));
                    LMeta.setLore(LLore);
                   
                    LightningBoots.setItemMeta(LMeta);
                   
                   
                    p.getInventory().addItem(LightningBoots);
                }
            }
            return false;
        }

    }
     
    And my Listener File :
    Code (Java):
    package org.snowman.uaccessories.Listener;

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryType.SlotType;
    import org.snowman.uaccessories.Utils.Utils;

    import com.codingforcookies.armorequip.ArmorEquipEvent;



    public class IArmosListener implements Listener {
       
    @EventHandler
    public void onPlayerInteract(ArmorEquipEvent e) {
       
        Player p = (Player) e.getPlayer();
        if(e.getNewArmorPiece().getItemMeta().getDisplayName().equals(Utils.chat("&f&lLightning Boots &b&l✈"))) {
            p.sendMessage("you equip light boots");
        }

    }}
     
    but dos not work :cry:
     
  4. can you say me your discord id?
     
  5. You need to make sure the ItemMeta is not null. Also don't cast player to Event#getPlayer, as it is already a player. It is also best if your ArrayList is camelCase.

    Do you get any errors in console?
     
  6. No, the problem is that you didnt register events.

    Put this on your onEnable():

    this.getServer().getPluginManager().registerEvents(new IArmosListener(), this);

    (could look like this:

    In your main class:

    public void onEnable() {
    this.getServer().getPluginManager().registerEvents(new IArmosListener(), this);

    }

    )
     
    • Funny Funny x 1
  7. Code (Text):
    package org.snowman.uaccessories;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.snowman.uaccessories.Commands.GUICmD;
    import org.snowman.uaccessories.Listener.IArmosListener;

    public class Main
      extends JavaPlugin {
      public void onEnable() {
        Bukkit.getServer().getPluginManager().registerEvents(new IArmosListener(), this);
        getCommand("uac").setExecutor(new GUICmD());
      }
     
      public void onDisable() {}
    }