Command execute in the item hand

Discussion in 'Bukkit Help' started by raphtsonga, Oct 18, 2016.

Thread Status:
Not open for further replies.
  1. Hello all I would firstly like to prevent that I am originally a French so I use google translation. So my problem is that I wish that when the player clicks on a red dye he executes the command / red which will have been previously made in another class and how to make it checks whether a red dye but with a custom name for if not with any red dye, you'll be able to do what we want. thank you very much
    Code:
    package fr.raphtsonga.totem;
    
    import java.util.ArrayList;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class Kit implements Listener {
     
        @EventHandler
        public void onClickEvent(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            if(e.getInventory().getTitle().equalsIgnoreCase(ChatColor.GRAY+"Selection d'un kit")) {
                if(e.getCurrentItem().getType() == Material.WOOD_SWORD) {
                    e.setCancelled(true);
                }
                if(e.getCurrentItem().getType() == Material.ARROW) {
                    e.setCancelled(true);
                }
                if(e.getCurrentItem().getType() == Material.FEATHER) {
                    e.setCancelled(true);
                }
                if(e.getCurrentItem().getType() == Material.GOLDEN_APPLE) {
                    e.setCancelled(true);
                }
                if(e.getCurrentItem().getType() == Material.STONE_AXE) {
                    e.setCancelled(true);
                }
                if(e.getCurrentItem().getType() == Material.GLASS_BOTTLE) {
                    e.setCancelled(true);
                }
            }
        }
     
        @EventHandler
        public void onClickNameTag(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            int taille = 1*9;
            if(e.getItem().getType() == Material.NAME_TAG) {
                if(e.getAction() == Action.RIGHT_CLICK_AIR) {
                    Inventory inv = Bukkit.createInventory(null, taille, ChatColor.GRAY+"Selection d'un kit");
                 
                    ArrayList<String> description1 = new ArrayList<String>();
                    ItemStack defaut = new ItemStack(Material.WOOD_SWORD, 1);
                    ItemMeta defautM = defaut.getItemMeta();
                    defautM.setDisplayName(ChatColor.GRAY+"Defaut");
                    description1.clear();
                    description1.add("");
                    description1.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Epée en pierre");
                    description1.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Arc + 12 flèches");
                    description1.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Hâche en pierre");
                    description1.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Pelle en pierre");
                    defautM.setLore(description1);
                    defaut.setItemMeta(defautM);
                 
                    ArrayList<String> description2 = new ArrayList<String>();
                    ItemStack archer = new ItemStack(Material.ARROW, 1);
                    ItemMeta archerM = archer.getItemMeta();
                    archerM.setDisplayName(ChatColor.GRAY+"Archer");
                    description2.add("");
                    description2.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Arc punch I + 32 flèches");
                    description2.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Protection projectiles I (plastrons + pantalon");
                    archerM.setLore(description2);
                    archer.setItemMeta(archerM);
                 
                    ArrayList<String> description3 = new ArrayList<String>();
                    ItemStack scout = new ItemStack(Material.FEATHER, 1);
                    ItemMeta scoutM = scout.getItemMeta();
                    scoutM.setDisplayName(ChatColor.GRAY+"Scout");
                    description3.add("");
                    description3.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Epée en bois knockback II");
                    description3.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 2 potions de vitesse");
                    description3.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 1 potion de saut");
                    description3.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Chûte amortie IV");
                    scoutM.setLore(description3);
                    scout.setItemMeta(scoutM);
                 
                    ArrayList<String> description4 = new ArrayList<String>();
                    ItemStack medic = new ItemStack(Material.GOLDEN_APPLE, 1);
                    ItemMeta medicM = medic.getItemMeta();
                    medicM.setDisplayName(ChatColor.GRAY+"Medic");
                    description4.add("");
                    description4.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Epée en pierre");
                    description4.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Arc + 8 flèches");
                    description4.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 1 potion de soin");
                    description4.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 1 potion de regen");
                    description4.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 2 pommes d'or");
                    medicM.setLore(description4);
                    medic.setItemMeta(medicM);
                 
                    ArrayList<String> description5 = new ArrayList<String>();
                    ItemStack bucheron = new ItemStack(Material.STONE_AXE, 1);
                    ItemMeta bucheronM = bucheron.getItemMeta();
                    bucheronM.setDisplayName(ChatColor.GRAY+"Bucheron");
                    description5.add("");
                    description5.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Hâche en fer sharp. II eff. II");
                    description5.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 64 planches");
                    description5.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Arc + 8 flèches");
                    bucheronM.setLore(description5);
                    bucheron.setItemMeta(bucheronM);
                 
                    ArrayList<String> description6 = new ArrayList<String>();
                    ItemStack alchimiste = new ItemStack(Material.GLASS_BOTTLE, 1);
                    ItemMeta alchimisteM = alchimiste.getItemMeta();
                    alchimisteM.setDisplayName(ChatColor.GRAY+"Alchimiste");
                    description6.add("");
                    description6.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Epée en pierre");
                    description6.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- Arc + 8 flèches");
                    description6.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 2 potions de dégâts");
                    description6.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 1 potion de lenteur");
                    description6.add(ChatColor.GRAY.toString()+ChatColor.ITALIC+"- 1 potion de vitesse");
                    alchimisteM.setLore(description6);
                    alchimiste.setItemMeta(alchimisteM);
                 
                    inv.setItem(0, defaut);
                    inv.setItem(1, archer);
                    inv.setItem(2, scout);
                    inv.setItem(3, medic);
                    inv.setItem(4, bucheron);
                    inv.setItem(5, alchimiste);
                    p.openInventory(inv);
                }
            }
        }
    
    }
    
    Original message :
    Bonjour à tous je tient en premier lieu à prévenir que je suis d'origine un français donc j'utilise google traduction. Donc mon problème étant que je souhaite que lorsque le joueur clique sur un colo
    Hello all I would firstly like to prevent that I am originally a French so I use google translation. So my problem is that I wish that when the player clicks on a red dye he executes the command / red which will have been previously made in another class and how to make it checks whether a red dye but with a custom name for if not with any red dye, you'll be able to do what we want. thank you very muchrant rouge il exécute la commande /rouge qui auras été préalablement faites dans une autre class et comment faire pour que cela vérifie que ce soit un colorant rouge mais avec un nom custom car sinon avec le moindre colorant rouge, on pourras faire ce qu'on veut. Merci beaucoup
     
    Last edited: Oct 18, 2016
Thread Status:
Not open for further replies.

Share This Page