Solved Stop players placing a block if its near another block

Discussion in 'Plugin Development' started by dan14941, Oct 5, 2014.

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

    dan14941

    Ok so I was playing on a modded server and i found there was a dupe glitch that i could prevent with a plugin but i need to stop the players placing a block near a certain block? but how, i cant let it test for the block after its placed it has to stop it before because the glitch crashes the clients server connection.
     
  2. Offline

    teej107

  3. Offline

    octoshrimpy

    What you want is something that listens for the player nearby that certain block, and then if player is within range, block the event that teej107 posted. I recommend iterating through blocks around players and checking if it's the wanted block.
     
  4. Offline

    dan14941

    octoshrimpy i could use something like this
    Code:java
    1. public void onBlockPlace(BlockPlaceEvent event)
    2. {
    3. Block block = event.getBlockPlaced();
    4. event.getPlayer().sendMessage(block.getType().name());
    5. event.setCancelled(false);
    6.  
    7. if (event.getBlockPlaced().getType().equals(Material.TNT)) {
    8. event.getBlockPlaced().setType(Material.AIR);
    9. event.setCancelled(true);
    10. }


    but instead of Material.TNT what would i put. Do you have an example of finding the blocks like you said im a amateur-is dev.

    octoshrimpy im tryign to stop the Mekanism Mod Digital Miner from being placed next to another block

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  5. Offline

    teej107

  6. Offline

    dan14941

    teej107 could i use like block ids?
     
  7. Offline

    teej107

  8. Offline

    dan14941

    teej107 octoshrimpy the block id of the Digital Miner is X3009 but how do i stop that being placed?
     
  9. Offline

    dan14941

    AdamQpzm how do i get it supported?
     
  10.  
  11. Offline

    dan14941

  12. dan14941 I don't know where you got your mod from.
     
  13. Offline

    dan14941

    AdamQpzm Im using cauldron (MCPC+) as my bukkit alt they dont have a forums?
     
  14. Offline

    octoshrimpy

    dan14941 bukkit doesn't play nicely with modded blocks, simply for the fact that bukkit was not designed for modded blocks. Because of that, it's taboo to talk about it. (still no reason why, nobody has told me. monkey see, monkey do, I guess) Were it vanilla blocks, I would iterate through the player's blocks with nested for loops. This was explained to me, and I didn't understand until I saw code, so here is a visual example. (do not copypasta, it won't work. instead figure out how it works) :
    Code:java
    1. public void doSomething(){
    2.  
    3. for (int x = loc.getBlockX()-3; x <= loc.getBlockX()+3; x++) {
    4. for (int y = loc.getBlockY()-3; y <= loc.getBlockY()+3; y++) {
    5. for (int z = loc.getBlockZ()-3; z <= loc.getBlockX()+3; z++) {
    6. world.getBlockAt(new Location(world, x, y, z));
    7. }
    8. }
    9. }
    10. }
     
Thread Status:
Not open for further replies.

Share This Page