Null lore

Discussion in 'Plugin Development' started by DevManABCD, Aug 31, 2014.

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

    DevManABCD

    Someone knows why on line 33 i get null error in console?

    Code:
    package pl.tradeApi;
     
    import java.util.ArrayList;
     
    import org.bukkit.Bukkit;
    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.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class TradeApi extends JavaPlugin implements Listener{
       
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
       
       
        @EventHandler
        public void onChat(PlayerChatEvent e) {
            Trade.offer(e.getPlayer(), "Handel", Utils.createIm(Material.COOKIE, "&e&oCiasteczko!", 2, 5, "Niesamowicie pyszne ciasteczko!"), 5);
        }
       
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            Player p = (Player) event.getWhoClicked();
            if(event.getInventory().getTitle().equalsIgnoreCase("Handel")) {
                if(event.getCursor().getItemMeta().getLore().contains(Utils.fixColors("&eCena: "))) {
                    event.setCancelled(true);
                    Trade.newTrade(p, "Sprzedaz", 5, event.getCurrentItem());
                }
            }
        }
       
       
     
    }
    
    Item what i click contains in lore Cena:
     
  2. DevManABCD
    I believe getCursor() returns the current item on the cursor when you click, not after you click. Use getCurrentItem() instead, which returns the item in the clicked slot.
     
    hintss likes this.
  3. Offline

    DevManABCD

    Yea, i return null anyway ;/
     
  4. Offline

    Rocoty

    Why don't you post the error? By the way, breaking that line up into multiple lines will make it easier for you to figure out what is actually null. Also, read the documentation please. If there is any doubt as to what a method does you should read the docs. The difference between getCursor() and getCurrentItem() are made crystal clear in the docs.
     
    mine-care likes this.
  5. Offline

    mine-care

    <Offtopic>
    Player p = (Player) event.getWhoClicked();
    PLEASE! read my signature.
     
  6. Offline

    Rocoty

    mine-care Although...Player is the only subclass of HumanEntity :/
     
  7. Offline

    Necrodoom

  8. Offline

    Rocoty

    Necrodoom Of course. Doing an instanceof check will future-proof the code.
     
    mine-care likes this.
  9. Offline

    mine-care

    Rocoty thats my point. Also its a way of making people check beforer casting when needed anyway. :)
     
  10. Offline

    DevManABCD

    Thats not reason of crash, stop cry.


     
  11. Offline

    Rocoty

    I beg your pardon?

    Regardless, it seems as though you are first working with .getCursor() and then later with getCurrentItem(). Is this what you want? The context you have provided is frankly a bit vague.
     
Thread Status:
Not open for further replies.

Share This Page