Solved Change Spawner Type on Block Place

Discussion in 'Plugin Development' started by JRArocks, Oct 5, 2012.

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

    JRArocks

    I've searched the forums (probably not hard enough) and can't seem how to change the creature/entity spawned in a mob spawner in the BlockPlaceEvent. I know that the spawner will not change its type in this event, and I would like to know how to 'wait' a tick to reset it.

    Here is my current code in an event listener, which [should] set the spawner to spawn primed TNT, making an excellent land mine:
    Code:
        @EventHandler
        public void onBlockPlace(BlockPlaceEvent event){
            Player player = event.getPlayer();
            if (event.getBlock().getType() == Material.MOB_SPAWNER){
                    Block bl = event.getBlock();
                    CreatureSpawner s = (CreatureSpawner) bl.getState();
                    s.setSpawnedType(EntityType.PRIMED_TNT);
                    player.sendMessage(ChatColor.GOLD+"Primed TNT Spawner placed!");
                    player.sendMessage(s.getSpawnedType().getName());
                }
            }
        }
    But I need to know how to wait a tick and set it then.
    All help would be appreciated.
     
  2. Offline

    Muddr

  3. Offline

    KeybordPiano459

  4. Offline

    JRArocks

    Thanks, guys, especially Muddr, I wasn't so familiar with scheduled tasks.

    But another thing: I am not sure how to get the event's block and player through a delayed event.

    EDIT: Using a repeated task (used for other things) to also control spawners.
     
Thread Status:
Not open for further replies.

Share This Page