getName does not work

Discussion in 'Plugin Development' started by Fondit, Apr 2, 2021.

  1. Offline

    Fondit

    @EventHandler
    public void onIteract(PlayerInteractEvent event){

    Player player = event.getPlayer();
    ItemStack it = event.getItem();

    if(it == null) return;

    if(it.getType() == Material.COMPASS && it.hasItemMeta() && it.getItemMeta().hasDisplayName() && it.getItemMeta().getDisplayName().equalsIgnoreCase("§f Menu")){

    Inventory inv = Bukkit.createInventory(null, 27, "§8 Menu");

    inv.setItem(11, getItem(Material.GLASS, "§f Créatif"));
    inv.setItem(13, getItem(Material.END_CRYSTAL, "§5 Mini-jeux"));
    inv.setItem(15, getItem(Material.GRASS_BLOCK, "§3 Survie"));

    player.openInventory(inv);

    }
    }

    @EventHandler
    public void onClick(InventoryClickEvent event){

    Inventory inv = event.getInventory();
    Player player = (Player) event.getWhoClicked();
    ItemStack current = event.getCurrentItem();

    if(inv.getName().equalsIgnaoreCase("§8 Menu"){


    }


    Solutions ?
     
  2. Offline

    Newdel

    To get the Inventory name use e.getView().getTitle()

    Edit: Oh and it's a good idea to safe this name in a variable so you can compare the name to the variable AND you don't have to change 50 lines in order to rename it
     
  3. Offline

    Fondit

    .getView().getTitle() does not work either
     
  4. Offline

    Newdel

    You have to call it on the event itself
     
  5. Offline

    Fondit

    [QUOTE = "Newdel, post: 3634141, member: 91342395"] Vous devez l'appeler sur l'événement lui-même [/ QUOTE]
    can you give me an example
     
  6. Offline

    Newdel

    Code:
    if(event.getView().getTitle().equalsIgnoreCase("§8 Menu"){
    
    
    }
    
    ?
     

Share This Page