Solved Stopping EnderDragon spawning in

Discussion in 'Spigot Plugin Development' started by Xsm0deus, Jul 8, 2018.

  1. So I'm trying to stop the enderdragon spawn in sequence, after you place endercrystals to spawn the dragon in I want a command that I can run to stop the event, I have tried removing the endercrystals but the dragon event still works and spawns in the Dragon.
     
  2. Check when a creature spawns and if its an enderdragon cancel the event or just kill the entity?
     
  3. No because if no one is in the world while the spawning sequence is happening, it freezes til players are in the arena, it doesn't stop or continue going to spawn in the dragon
     
  4. I'm sure you can freeze movement on a mob?
     
  5. You need to grab the battle manager and set the respawn state to null. This requires NMS.

    I left the fully qualified names in there so you can see which packages these things come from.
    Code (Java):
    @EventHandler
    public void on(CreatureSpawnEvent event) {
        if (event.getEntityType() != org.bukkit.entity.EntityType.ENDER_DRAGON) {
            return;
        }
        org.bukkit.World world = event.getEntity().getWorld();
        if (world.getEnvironment() != org.bukkit.World.Environment.THE_END) {
            return;
        }
        org.bukkit.craftbukkit.v1_12_R1.CraftWorld craftWorld = (org.bukkit.craftbukkit.v1_12_R1.CraftWorld) world;
        net.minecraft.server.v1_12_R1.WorldServer nmsWorld = craftWorld.getHandle();
        net.minecraft.server.v1_12_R1.WorldProviderTheEnd nmsEndProvider = (net.minecraft.server.v1_12_R1.WorldProviderTheEnd) nmsWorld.worldProvider;
        net.minecraft.server.v1_12_R1.EnderDragonBattle battleManager = nmsEndProvider.t();
        try {
            java.lang.reflect.Field p = net.minecraft.server.v1_12_R1.EnderDragonBattle.class.getDeclaredField("p");
            p.setAccessible(true);
            p.set(battleManager, null);
        } catch (NoSuchFieldException | IllegalAccessException ignore) {
        }
    }
    Without FQN by using imports this can be shortened to
    Code (Java):
    @EventHandler
    public void on(CreatureSpawnEvent event) {
        if (event.getEntityType() != EntityType.ENDER_DRAGON) {
            return;
        }
        World world = event.getEntity().getWorld();
        if (world.getEnvironment() != World.Environment.THE_END) {
            return;
        }
        try {
            Field p = EnderDragonBattle.class.getDeclaredField("p");
            p.setAccessible(true);
            p.set(((WorldProviderTheEnd) ((CraftWorld) world).getHandle().worldProvider).t(), null);
        } catch (NoSuchFieldException | IllegalAccessException ignore) {
        }
    }
     
    #5 BillyGalbreath, Jul 9, 2018
    Last edited: Jul 9, 2018
    • Like Like x 1
  6. This would be after the dragon spawns?
     
  7. Hmm, I did not think about that when I posted. Put it in the interact event or something. Idk if there is an event for when the process starts or not. Definitely not going to work in the spawn event.

    Just figure out when they are placing the last crystal, then run that code to cancel the respawn process.
     
  8. It works, thanks :)
     
    • Like Like x 1