Check for a wool block on players head

Discussion in 'Plugin Development' started by mickedplay, Apr 13, 2014.

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

    mickedplay

    Hello everybody,

    I want to check if a player has a specific wool block on his head while he stepped on a pressure plate.

    But I don't know how?
    I tried the following, but it throws me every time a player moves an error because CraftItemStack cannot cast to block:
    Code:java
    1. if(CTF.status.getStatus() == 2 && CTF.ctfplayers.contains(p))
    2. {
    3. World w = p.getWorld();
    4. Location loc = p.getLocation();
    5. Location d = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ());
    6. Block b = w.getBlockAt(d);
    7. Block flag = (Block) p.getInventory().getHelmet();
    8.  
    9. p.sendMessage("1");
    10. if(b.getType() == Material.STONE_PLATE)
    11. {
    12. p.sendMessage("2");
    13. if(flag.getData() == 14)
    14. {
    15. p.sendMessage("3");
    16. String world = fileConfigLocations.getString("LobbySpawn.world");
    17. double x = fileConfigLocations.getDouble("LobbySpawn.x");
    18. double y = fileConfigLocations.getDouble("LobbySpawn.y");
    19. double z = fileConfigLocations.getDouble("LobbySpawn.z");
    20. Location redFlag = new Location(Bukkit.getWorld(world), x, y, z);
    21. w.strikeLightningEffect(((Block) redFlag).getLocation());
    22.  
    23. CTF.gameScoreRed ++;
    24. for(Player p1 : CTF.ctfplayers)
    25. {
    26. p.sendMessage("4");
    27. p1.setHealth(20.0D);
    28. p1.setFoodLevel(20);
    29. p1.setFireTicks(0);
    30. p1.setFlying(false);
    31. }
    32. CTF_Scoreboard.setScoreboard();
    33. CTF_Teleporter.teleport();
    34. }

    Any ideas how to check for a specific wool block on players head without errors?

    Thanks!
     
  2. I don't know what you're trying to do. But if you've not already, use a PlayerInteractEvent with a type physical. Then check if :

    Code:java
    1. p.getItemInHand() == WhatEver
     
  3. Offline

    Zwander


    Do you even read?

    Back to the topic:
    You cant cast because its not a block while in the inventory, its an itemstack.
     
Thread Status:
Not open for further replies.

Share This Page