Changing placed blocks?

Discussion in 'Spigot Plugin Development' started by Aderm, May 30, 2016.

Thread Status:
Not open for further replies.
  1. Hey guys, just making a simple plugin for my server, and I can't get it to work xD

    When you place a redstone lamp, it turns on.

    Here's the code xD

    Code (Java):

        @EventHandler
        public void redstoneLampPlace(BlockPlaceEvent e) {
            if(e.getBlock().equals(Material.REDSTONE_LAMP_OFF)) {
                e.getBlock().setType(Material.REDSTONE_LAMP_ON);
            }
        }
     
    And yeah, I'm registering events.
     
  2. Check if is cancelled
     
  3. That, what you want to do, don't work because minecraft dont "accept" that. I think if you cancel event for redstone it can be work, but i don't know that!
     
  4. w0t

    Also, it's not JUST redstone lamps, tried making Stone to Dirt, that didn't work either
     
  5. You're supposed to be comparing the Type of the block not the block itself.
     
  6. This should be work

    Code (Text):
    @EventHandler
        public void onBlockPlace(BlockPlaceEvent e) {
            if(e.getBlock().getType() == Material.DIRT) {
                e.getBlock().setType(Material.STONE);
            }
        }
     
  7. Serializator

    Supporter

    Try to put in a 1 tick delay before modifying the type of the block, it could be that the servers overrides your changes because the event is called before the block is actually set.
     
  8. Fixed now, ty guys.
     
Thread Status:
Not open for further replies.