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

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

  1. Offline


    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:
    //Pseudo Code
    if(skull.getOwner() instanceof Player) {
    But ehm.. I actually already asked if the skulltype is "SkullType.PLAYER"..

    My current code:
        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);
                                    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 ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerInteractEvent( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PlayerConnection.a( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at java.util.concurrent.Executors$ Source) [?:1.8.0_231] at Source) [?:1.8.0_231] at net.minecraft.server.v1_8_R1.MinecraftServer.z( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.DedicatedServer.z( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at net.minecraft.server.v1_8_R1.MinecraftServer.y( [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at [spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] at Source) [?:1.8.0_231] Caused by: java.lang.NullPointerException at de.baeni.skypvpsystem.listeners.ManagerSecretBoots.onInteractBaeniHead( ~[?:?] 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 ~[spigot-1.8.jar:git-Spigot-c3c767f-33d5de3] ... 16 more
  2. Offline


  3. Offline


    @KarimAKL Oh yeah, sorry.. I should have mention that directly.
    This is like 39:
    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


    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()".

Share This Page