Prevent Block Placing in Water

Discussion in 'Plugin Development' started by Witherleague, Aug 28, 2014.

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

    Witherleague

    Hello everyone,
    i am running a server with a special SkyPVP-Plugin. But we have one problem. Users are allowed to farm HayBlocks, which respawn, works properly, they can place them too, which is also okay, but we don't want them to place the blocks in Water, because they can use this to grief the Map. Normally when they place a Hayblock, it decays after 60 ticks (3 seconds). We have done that with saving the location in a hashmap and replacing the block with air after 3 seconds. But when they place it in water, after 3 seconds it replaces to air and the water is gone. Same for grass, they can destroy it by placing a block and then it turns to air. So what we want: After the 3 seconds the block should be replaced with the block that has been at the plaedblock-location before. So if you place the block in water it should turn to water again. If you place it in grass, it should turn to grass again. But we don't know how to get the Type of Block that has been replaced. I tried getReplacedBlock but doesn't work. Long text, small problem. I hope you can help me out.

    How can I get the Block that has been at the location before placing another Block? getReplacedBlock doesn't work :/
     
  2. On the Blockplaceevent you get what block is there right now with world.getBlockAt(loc); and save it in a hashmap<Location(clone of the Location of the block), Block(a clone of the block)> and three seconds later get the block and set it.
     
  3. Offline

    teej107

  4. Offline

    Jimfutsu

    Are you attempting to cancel the event? If you are, then check the radius around the block.
    Code:java
    1. World world = loc.getWorld();
    2. for (int x = -radius; x < radius; x++) {
    3. for (int y = -radius; y < radius; y++) {
    4. for (int z = -radius; z < radius; z++) {
    5. Block block = world.getBlockAt(loc.getBlockX()+x, loc.getBlockY()+y, loc.getBlockZ()+z);
    6. if (block.getType() == Material.WATER) {
    7. e.setCancelled(true);
    8. }
    9. }
    10. }
    11. }
     
Thread Status:
Not open for further replies.

Share This Page