Do something when creature spawner fails to spawn entity

Discussion in 'Plugin Development' started by Kevinzuman22, Oct 3, 2017.

Thread Status:
Not open for further replies.
  1. I am currently working on a plugin that sets spawner delay whenever an entity has been spawned by a spawner. But for some reason, the delay is not being set. It does not give any errors. I have printed out the number that it would be set to, and it was correct, but it still did not want to set the delay. I am using Spigot 1.12.2.

    And other than that, when I try to use SpawnerSpawnEvent's .setCancelled() method, and set it to 'true', the spawner will still spawn only babies of the EntityType of the spawner, but without the particle effects of spawning an entity by a mob spawner. Also here I do not get any errors in console.

    My current code:
    Listener:
    Code:java
    1. @EventHandler(priority = EventPriority.MONITOR)
    2. public void onSpawnerSpawn(SpawnerSpawnEvent e) {
    3. Block b = e.getSpawner().getBlock();
    4. Spawner spawner = new Spawner(b, main);
    5.  
    6. if(!spawner.isEnabled()) {
    7. e.setCancelled(true);
    8. return;
    9. }
    10.  
    11. main.getServer().getScheduler().scheduleSyncDelayedTask(main, new SpawnerEventsListener.schedule(spawner), 5L);
    12. return;
    13. }
    14.  
    15.  
    16. class schedule implements Runnable {
    17.  
    18. private Spawner spawner;
    19.  
    20. public schedule(Spawner spawner) {
    21. this.spawner = spawner;
    22. }
    23.  
    24. @Override
    25. public void run() {
    26. spawner.setDelay(spawner.getDefaultDelay());
    27. }
    28.  
    29. }

    'main' is an instance of the main class of the plugin.
    I've tried using a runnable instead of instantly setting the delay to see if that worked, but without result.

    The spawner.setDelay() method:
    Code:java
    1. public void setDelay(int delay) {
    2. cs.setDelay(delay);
    3. }

    'cs' is an instance of CreatureSpawner, which is cast from BlockState.
     
  2. Offline

    Caderape2

  3. @Caderape2
    It works now, although I have tried using .update() it before. Odd. Thanks anyways!
    However, it does not set the delay if the spawner fails to spawn the entity. Any way to still be able to set the delay when this happens?
     
  4. Offline

    Reflxction

Thread Status:
Not open for further replies.

Share This Page