Solved Unknown error

Discussion in 'Spigot Plugin Development' started by wiktor_k, Jan 18, 2020.

  1. Hello, I don't know why because the code of the class is fine. Do you know why and what means the errors I get on the console?

     
  2. Yes. The event also gets fired when someone rightclicks without a block as a target.

    Screenshot_4.png

    Check if the retrieved Block is null.
     
  3. Code (Java):
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if(e.getClickedBlock().getType() == null) {
                return;
            } else if((e.getClickedBlock().getType() == Material.LEVER) && (e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                if(!cooldown.contains(p)) {
                    cooldown.add(p);
                    LeverTask.timer(p);
                } else {
                    e.setCancelled(true);
                    Util.sendTitle(p, Util.fixColor("&9&lxMINE&f&lCORE.PL"), Util.fixColor("&8>> &4&oBlad: &cDzwignie mozna uzywac co 5 sekund!"),10,40,20);
                }
            }
        }
    So now should be ok? Yes I know I could add @Nullable what you send me but I think it's better so.
     
  4. No you could not.

    No this does not fix the problem.
    You have to check if the block is null not if the type of the block is null. The type btw is NotNull so it wont be null ever.