Material on player interact event

Discussion in 'Plugin Development' started by Texgabs, Apr 4, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Texgabs

    I have a small thing in my plugin of brooms, i have a class called "CustomItem" is this:
    Code:
        package me.texgabs.mdescobas;
        
        import java.util.Arrays;
        import java.util.List;
        
        import org.bukkit.Material;
        import org.bukkit.entity.Player;
        import org.bukkit.inventory.Inventory;
        import org.bukkit.inventory.ItemStack;
        import org.bukkit.inventory.meta.ItemMeta;
        
        
        public class CustomItem extends ItemStack {
        
        public CustomItem(Material material){
        this.setType(material);
        this.setAmount(1);
        }
        
        
        public CustomItem(Material material, Integer count){
        this.setType(material);
        this.setAmount(count);
        }
        
        public CustomItem(Material material, String displayName){
        this.setType(material);
        ItemMeta im = this.getItemMeta();
        im.setDisplayName(displayName);
        this.setItemMeta(im);
        this.setAmount(1);
        }
        
        public CustomItem(Material material, List<String> lores){
        this.setType(material);
        ItemMeta im = this.getItemMeta();
        im.setLore(lores);
        this.setItemMeta(im);
        this.setAmount(1);
        }
        
        public CustomItem(Material material, Integer count, String displayName){
        this.setType(material);
        this.setAmount(count);
        ItemMeta im = this.getItemMeta();
        im.setDisplayName(displayName);
        this.setItemMeta(im);
        
        }
        
        public CustomItem(Material material, Integer count, List<String> lores){
        this.setType(material);
        this.setAmount(count);
        ItemMeta im = this.getItemMeta();
        im.setLore(lores);
        this.setItemMeta(im);
        }
        
        public CustomItem(Material material, String displayName, List<String> lores){
        this.setType(material);
        ItemMeta im = this.getItemMeta();
        im.setDisplayName(displayName);
        im.setLore(lores);
        this.setItemMeta(im);
        this.setAmount(1);
        }
        
        public CustomItem(Material material, Integer count, String displayName, List<String> lores){
        this.setType(material);
        this.setAmount(count);
        ItemMeta im = this.getItemMeta();
        im.setDisplayName(displayName);
        im.setLore(lores);
        this.setItemMeta(im);
        }
        
        public void add(Player player){
        player.getInventory().addItem(this);
        }
        
        public void add(Inventory inventory){
        inventory.addItem(this);
        }
        
        public void set(Player player, Integer slot){
        player.getInventory().setItem(slot, this);
        }
        
        public void set(Inventory inventory, Integer slot){
        inventory.setItem(slot, this);
        }
        
        }
    
    

    And i use this class to use custom item to fly, i try use this:
    Code:
      @EventHandler
      public void onCleanSweep(PlayerInteractEvent e)
      {
      final Player p = e.getPlayer();
      if (p.getItemInHand().getType() == CustomItem(Material.RECORD_5, "§aBarredora")) {
      if (p.hasPermission("mds.barredora")) {
      if (!this.flying.contains(p.getName()))
    {
    But no works, you can help me please, and sorry for my bad english :S
     
  2. Offline

    mcdorli

    What doesn't work?
     
  3. Offline

    Lordloss

    you try to compare a material with an itemStack..
     
  4. Offline

    Texgabs

    .
     
    Last edited: Apr 7, 2016
  5. @Texgabs set thread as solved if you are done.
     
  6. Offline

    Texgabs

    My plugin use item to fly like BroomStick , in this case : ID:2256 with the name &aBarredora but you can fly with any item with the ID:2256 I need you can only fly when the item has the same name. :/
     
Thread Status:
Not open for further replies.

Share This Page