Enderdragon to Falling Sand?

Discussion in 'Plugin Development' started by Quantum64, Nov 22, 2013.

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

    Quantum64

    I need a way to listen for an enderdragon breaking a block, spawn a falling sand entity masked with the block id that the enderdragon broke, then keep track of the sand entity and delete it after 3 seconds of falling, or when it hits a block.

    So the first problem is I have no idea how to listed for an enderdragon break event. It's not BlockBreakEvent. I also need to get the block id of the broken block.

    The second problem is being able to destroy the falling sand entity when it hits a block or after ~3 seconds of falling.

    Any help would be appreciated!
     
  2. Offline

    maxben34

    I think you could maybe look into creating a custom event for this, however I'm not too sure tbh. (Trying to make "Dragons" I see ;)) Quantum64
     
  3. Offline

    Quantum64

    Custom Events? Thats way over my head... Is there any bukkit event for an enderdragon block break event. (If there's not, there should be)
     
  4. Offline

    ZeusAllMighty11 Retired Staff

  5. Offline

    Quantum64

    But then where would the even be called? Still the same problem, really.
     
    werter318 likes this.
  6. Offline

    xTrollxDudex

    Quantum64
    Wait can you listen to Event and print out the name of the event that gets fired when an ender dragon breaks it? I believe it should be block fade but I'm not sure:
    PHP:
    final FallingBlock block event.getBlock().getLocation().getWorld().spawnFallingBlock(event.getBlock().getLocation(), Material.YOURMATERIALHEREevent.getBlock().getData().getData());

    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable {
        public 
    void run() {
            
    block.remove();
        }
    }, 
    60L);
     
    ArthurMaker likes this.
  7. Offline

    Quantum64

    After a bit of tinkering, I finally found out how to do it! I am putting this here for anyone who is to come back to this thread:
    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.block.Block;
    3. import org.bukkit.entity.ComplexEntityPart;
    4. import org.bukkit.entity.EnderDragon;
    5. import org.bukkit.entity.Entity;
    6. import org.bukkit.entity.FallingBlock;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.EntityExplodeEvent;
    10. import org.bukkit.plugin.Plugin;
    11.  
    12. public class EnderDragonListener implements Listener {
    13. Plugin plugin;
    14. public EnderDragonListener(Plugin plugin) {
    15. this.plugin = plugin;
    16. }
    17.  
    18. @EventHandler
    19. public void entityExplodeEvent(EntityExplodeEvent event) // Listen for the event...
    20. {
    21. Entity e = event.getEntity();
    22. if (e instanceof ComplexEntityPart)
    23. e = ((ComplexEntityPart) e).getParent();
    24. if (e instanceof EnderDragon)
    25. for (Block block : event.blockList()) {
    26. final FallingBlock fallingBlock = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), block.getType(), block.getData());
    27.  
    28. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    29. public void run() {
    30. fallingBlock.remove();
    31. }
    32. }, 60L);
    33. }
    34. }
    35. }
    36.  


    The fact that the enderdragon can destroy more that one block per event made it slightly more complicated.

    Apparently the Java code box discarded all my nice formatting :/ oh well. It was indented though

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

    mattrick

    Quantum64
    You forgot to set the block to air when the FallingBlock spawns (unless you didn't want to....)
     
  9. Offline

    Garris0n

    DSH105 and maxben34 like this.
  10. Offline

    Quantum64

    mattrick16
    The block gets set to air anyway, that's the entire point of the event. We detect when the ednerdragon sets a block to air.
     
  11. Offline

    mattrick

    Oops, my bad...
     
Thread Status:
Not open for further replies.

Share This Page