Simple problem, hopefully a simple solution.

Discussion in 'Plugin Development' started by Taizzz, Aug 13, 2013.

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

    Taizzz

    I'm having a problem which I think logically should work, but it's jut not.
    It should send the player who placed the bedrock block at a certain location that message, but it doesn't.
    Code:java
    1. @EventHandler
    2. public void onBlockPlace(BlockPlaceEvent event) {
    3. Block block = event.getBlock(), relative;
    4. Location loc = new Location(Bukkit.getWorld("world"), 10, 71, 10);
    5. Player player = event.getPlayer();
    6. if (block.getType() == Material.BEDROCK) {
    7. if (block.getLocation() == loc) {
    8. player.sendMessage("You placed the bedrock at the correct location!");
    9. }
    10. }
    11. }

    Any help would be much appreciated!
     
  2. Offline

    raGan.

    Use equals or distance == 0 to compare locations.
     
  3. Offline

    Taizzz


    Code:java
    1. @EventHandler
    2. public void onBlockPlace(BlockPlaceEvent event) {
    3. Block block = event.getBlock(), relative;
    4. Location loc = new Location(Bukkit.getWorld("world"), 10, 71, 10);
    5. Player player = event.getPlayer();
    6. if (block.getType() == Material.BEDROCK) {
    7. if (block.getLocation().equals(loc)) {
    8. player.sendMessage("You placed the bedrock at the correct location!");
    9. }
    10. }
    11. }


    So that's what I changed the code to, but it still doesn't seem to work.
     
  4. Offline

    Staartvin

    What's up with the:

    Code:java
    1.  
    2. Block block = event.getBlock(), relative;
    3.  


    Change it to:

    Code:java
    1.  
    2. Block block = event.getBlock();
    3.  
     
  5. Offline

    raGan.

    Add debug messages that print loc coords and block.getLocation() coords. You will clearly see what is actually wrong.
     
  6. Offline

    bobacadodl

    Try doing this:

    Code:
    Change
            if (block.getLocation().equals(loc)) {
                player.sendMessage("You placed the bedrock at the correct location!");
                }
            }
     
    to:
     
            if (block.getLocation().equals(loc.getBlock().getLocation())) {
                player.sendMessage("You placed the bedrock at the correct location!");
                }
            }
     
  7. Offline

    Taizzz

    It's part of a bigger event, so it needs to be in there:
    Code:java
    1. @EventHandler
    2. public void onBlockPlace(BlockPlaceEvent event) {
    3. Block block = event.getBlock(), relative;
    4. Location loc = new Location(Bukkit.getWorld("world"), 10, 71, 10);
    5. Player player = event.getPlayer();
    6. if (block.getType() == Material.BEDROCK) {
    7. if (block.getLocation().equals(loc)) {
    8. player.sendMessage("done ked");
    9. for (int x = -radius; x < radius; x++) {
    10. for (int y = -radius; y < radius; y++) {
    11. for (int z = -radius; z < radius; z++) {
    12. relative = block.getRelative(x, y, z);
    13. if (relative.getType() == Material.STATIONARY_WATER) {
    14. relative.setType(Material.AIR);
    15. }
    16.  
    17. if (relative.getType() == Material.WATER) {
    18. relative.setType(Material.AIR);
    19. }
    20. }
    21. }
    22. }
    23. }
    24.  
    25. }
    26. }

    I'm just trying to make it so that this block can only be placed in one specific location and have an effect, and from what I've tried none of the suggestions are working.
     
  8. Offline

    Staartvin

    If comparing locations doesn't work, you can always compare world, x, y and z manually.
     
Thread Status:
Not open for further replies.

Share This Page