error on checking if clicked skull-owner equals "playername"

Discussion in 'Plugin Development' started by baenii, Oct 30, 2019.

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

    baenii

    Hej everyone again,

    Im currently getting an error code when checking if the owner of the clicked player skull is "playername".
    I am actually only getting that error, when Im rightclicking a custom head which I got from commandblock. I got the command for the head from a head-database internet-page.
    When I rightclick a head which has an actuall player set as owner, it works like a charm without any errors.

    I was thinking about sth like that but I cannot ask for the instance of the owner:
    Code:
    //Pseudo Code
    if(skull.getOwner() instanceof Player) {
        ...
    }
    
    But ehm.. I actually already asked if the skulltype is "SkullType.PLAYER"..

    My current code:
    Code:
    @EventHandler
        public void onInteractBaeniHead(PlayerInteractEvent e) {
         
            Player p = e.getPlayer();
         
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
             
                if(e.getClickedBlock().getType() == Material.SKULL) {
                 
                    Skull skull = (Skull) e.getClickedBlock().getState();
                 
                    if(skull.getSkullType() == SkullType.PLAYER) {
                     
                        if(skull.hasOwner()) {
                         
                            if(skull.getOwner().equals("baeni")) {
    
                                if(CheckForRank.minPremium(p)) {
                                 
                                    ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
                                    LeatherArmorMeta bootsMeta = (LeatherArmorMeta) boots.getItemMeta();
                                    bootsMeta.setDisplayName("§cPuschen §7(Secret)");
                                    bootsMeta.addEnchant(Enchantment.DURABILITY, 5, true);
                                    bootsMeta.setColor(Color.RED);
                                    bootsMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
                                    boots.setItemMeta(bootsMeta);
                                 
                                    p.getInventory().addItem(boots);
                                 
                                    p.updateInventory();
                                 
                                    p.sendMessage(Main.prefix + "Du hast das §4Secret§7-Item erhalten.");
                                 
                                } else {
                                    p.sendMessage(Main.prefix + "Du benötigst den §6Premium§7-Rang für dieses Secret.");
                                }
                             
                            }
                         
                        }
                     
                    }
             
                } 
             
            }
         
        }
    
    Error (open)

    [02:41:21 ERROR]: Could not pass event PlayerInteractEvent to System v1.0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.java:305) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:724) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:80) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_231] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_231] at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at java.lang.Thread.run(Unknown Source) [?:1.8.0_231] Caused by: java.lang.NullPointerException at de.baeni.skypvpsystem.listeners.ManagerSecretBoots.onInteractBaeniHead(ManagerSecretBoots.java:39) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231] at org.bukkit.plugin.java.JavaPluginLoader.execute(JavaPluginLoader.java:301) ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] ... 16 more
     
  2. Offline

    KarimAKL

  3. Offline

    baenii

    @KarimAKL Oh yeah, sorry.. I should have mention that directly.
    This is like 39:
    //Edit
    Actually I start to believe that the issue is not fixable and the problem belongs to the custom heads since the custom heads have a owner set, but its blank. I checked that via returning the skull owner and I got an empty line ingame. I think I should use actuall playerheads but not custom heads which come from command blocks.
     
    Last edited: Oct 31, 2019
  4. Offline

    KarimAKL

    That doesn't make any sense to me, is the error up to date with your code?

    The only way "skull.hasOwner()" could throw a NullPointerException is if 'skull' is null but, if 'skull' is null, the exception should be thrown at "skull.getSkullType()".
     
Thread Status:
Not open for further replies.

Share This Page