Solved Skull Block getOwner()

Discussion in 'Plugin Development' started by cnaude, Feb 1, 2013.

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

    cnaude

    Has anyone been able to successfully use the getOwner() method on a Skull block? I've been fighting with this for a few hours and it results in nothing. The plugin seems to just stop after I attempt to access getOwner(). It throws no errors. It's as if the getOwner() just forces my class method to return.

    Code:
    Block block = player.getTargetBlock(null, 5);
    org.bukkit.block.Skull skull = (org.bukkit.block.Skull)block;
    if (skull.hasOwner()) {
      logDebug("Skull block has owner");
      pName = skull.getOwner();
    } else {
      logDebug("Skull block has NO owner");
    }
    Full code: https://github.com/cnaude/TrophyHeads/blob/master/src/me/cnaude/plugin/TrophyHeads/THMain.java
     
  2. Offline

    Cjreek

    You should check if block is actually instanceof Skull.
     
  3. Offline

    cnaude

    I left that out of my example. In my actual code use this.

    Code:
    if (block.getType() == Material.SKULL) {
    ...
    }
     
  4. Offline

    Cjreek

    What's the last debug message that gets printed?
    Are there any exception messages?
     
  5. Offline

    cnaude

    It prints nothing to the debug log. It seems to just silently quit when it hits the .hasOwner() or getOwner(). No exceptions or errors.
     
  6. Offline

    cnaude

    Solved!

    Code:
    BlockState bs = block.getState();
    org.bukkit.block.Skull skull = (org.bukkit.block.Skull) bs;           
    String pName;           
    if (skull.hasOwner()) {
      pName = skull.getOwner();
    } else {
      pName = "Unknown";
    }
     
Thread Status:
Not open for further replies.

Share This Page