Util SkullMeta#setOwner() quick fix!

Discussion in 'Resources' started by TheCodingCat, Dec 26, 2014.

?

Do you find this useful?

  1. Yes

    100.0%
  2. No

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    TheCodingCat

    Hey people! In the UUID update for 1.7.9 i believe, SkullMeta#setOwner() became A bit different. In the meantime while it gets fixed I have come up with an alternative. It places the head as a block then retrieves the itemstack (as now the head only loads on place) This places the block at the farthest edge of the world (where you wouldn't mind blocks to be placed then removed) Well here we go!
    Code:
    public static ItemStack getPlayerHead(String name) {
            ItemStack stack = new ItemStack(Material.AIR);
            //stack is what we will return
            boolean done = false;
            //done is weather we have a free space or not to place or head
            Location loc = null;
            // the location which will be our head blocks location
            int i = 0;
            //an Integer which we will use in the while up ahead -.-
            while (!done) {
                //while we have not found a place for our player head
                if (!Bukkit.getWorld("hub").getBlockAt(-29999970,64,-29999970 + i).getType().equals(Material.AIR)) {
                    //check if block isn't air and if it isn't we add to our Integer "i". The need for it is hard to explain.
                    i++;
                    //adding :D
                }else{
                    //YES we found a clear space!
                    done = Boolean.valueOf(done);
                    //I dont want to suppress warnings for unused even though we use it.
                    done = true;
                    // yes we're almost done
                    loc = new Location(Bukkit.getWorld("hub"),-29999970,64,29999970 + i);
                    //pretty self explanatory
                    break;
                }
            }
            //lets first make our loc a skull
            loc.getBlock().setType(Material.SKULL);
            //get the skull state
            Skull s = (Skull) loc.getBlock().getState();
            //set the owner
            s.setOwner(name);
            //update the block
            s.update();
            //even though it has only one drop Block#getDrops() returns an ItemStack[]
            for (ItemStack s1 : s.getBlock().getDrops()) {
                //we have our head
                stack = s1;
            }
            //return the block back to air
            s.getBlock().setType(Material.AIR);
            //and voila We have a perfect skull!!!!! :D
            return stack;
        }
     
    Last edited: Dec 28, 2014
  2. Offline

    RingOfStorms

    I believe that you are wrong.
     
    ChipDev likes this.
  3. Offline

    DemKazoo

    Works fine for me, I don't see why this is useful, nor why you think SkullMeta is broken?
     
    ChipDev likes this.
  4. Offline

    Assist

    Code:
    done = Boolean.valueOf(done);
    wat.
     
    Avygeil, Cirno and ChipDev like this.
  5. Offline

    TheCodingCat

    @DemKazoo SkullMeta#setOwner() is broken because it doesn't actually update the head until you place it on the ground. And @Assist Its because I don't want to suppress warnings for unused even though i am using it.
     
  6. Offline

    ChipDev

    Can you show me?
    Im absolutely sure my computer's color scheme makes almost the same alex/steve head's colors blend into my skin.
    No xD
     
  7. Offline

    TheCodingCat

    What? I didn't understand one thing you said there @ChipDev :eek:
     
  8. Offline

    DemKazoo

    But your thread definitly tells us that SkullMeta is broken, but SkullMeta is for the skull's skin on the ground yes. Not for the players inventory..
     
  9. Offline

    TheCodingCat

    Sort of @DemKazoo What Happenens with SkullMeta as of 1.7.6 I believe, It stores the owner as a String in the data(The Players name) and the data is only applied when it is placed.
     
  10. Offline

    DemKazoo

    Yes but that doesn't mean It's 'broken' :p
     
  11. Offline

    ChipDev

    Ok.
    POLL:
    WHAT VERSION ARE YOU USING?:

    1.7 - 1
    1.7.2 - 2
    1.7.5 - 3
    1.7. 6 - 4
    1.7.9 - 5
    1.8 - 6
    I say 6. 1.8, 1.7.9 and 1.7.2 are the most known versions, I actually never knew there was a 1.7.6
     
  12. Offline

    TheCodingCat

    This bug isn't even fixed in 1.8 yet
     
Thread Status:
Not open for further replies.

Share This Page