Solved Right Click Armor Equiped

Discussion in 'Plugin Development' started by maliimaloo, Jan 7, 2019.

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

    maliimaloo

    Good morning to you;

    I post this message because I have a little problem in my code, my code is currently working but the problem is that when I click right on it it cancels the event well but the armor teams up and gives it back to me in the inventory, how I could solve my problem please.

    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void playerClick(PlayerInteractEvent event)
        {
            if(event.getAction().equals(Action.RIGHT_CLICK_AIR))
            {
                Player player = event.getPlayer();
                if(!(event.getItem() == null))
                {
                    int idItem = event.getItem().getTypeId();
                   
                    List<String> getArmure = new ArrayList<String>();
                    for (String str : settings.getArmureConfig().getConfigurationSection("Armure").getKeys(false)) 
                    {
                        getArmure.add(str);
                    }
                   
                    for (int a = 0; a < getArmure.size(); a++) 
                    {
                        if(idItem == settings.getArmureConfig().getInt("Armure."+getArmure.get(a)+".ID"))
                        {
                            int levelRequis = settings.getArmureConfig().getInt("Armure."+getArmure.get(a)+".LevelRequis");
                            int levelActuel = player.getLevel();
                           
                            if(levelActuel < levelRequis)
                            {
                                player.sendMessage("§9[OmegaArmure] §cVous devez être level: §9" + levelRequis + " §cpour l'équiper.");
                                event.setCancelled(true);
                                return;
                            }
                        }
                    }
                }
                else
                {
                    return;
                }
            }
        }
    
    Resolved issue


    Code:
    if(player.getInventory().getHelmet() == null)
                                {
                                    BukkitScheduler  scheduler  =  Main.getPlugin(Main.class).getServer().getScheduler();
                                    scheduler.scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable()
                                    {
                                        @Override
                                        public void run()
                                        {
                                            player.getInventory().setHelmet(new ItemStack(Material.AIR));
                                            player.updateInventory();
                                        }
                                    }, 20L);
                                }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 7, 2019
Thread Status:
Not open for further replies.

Share This Page