Custom dragons problem

Discussion in 'Plugin Development' started by Lavarite, Mar 17, 2022.

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

    Lavarite

    Wanted to create a couple of new types of dragons with custom names, strength and health
    Ran into a problem... On ender dragon spawn does not change anything
    Code:
    public class DragonTypes {
        @EventHandler
        public void onEnderDragonSpawn (CreatureSpawnEvent event) {
            EnderDragon Drag = (EnderDragon) event.getEntity();
            int matchDrag = new Random().nextInt(100);
            if (matchDrag > 58){
                Bukkit.broadcastMessage("§5§lEnder Dragon §r§5has spawned!");
                Drag.setCustomName("§5§lEnder Dragon");
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20000000, 1));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20000000, 10));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20000000, 1));
            }
            if (matchDrag < 59 && matchDrag > 30){
                Bukkit.broadcastMessage("§2§lGoldor Dragon §r§5has spawned!");
                Drag.setCustomName("§2§lGoldor Dragon");
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20000000, 4));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20000000, 40));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20000000, 1));
            }
            if (matchDrag > 10 && matchDrag < 31){
                Bukkit.broadcastMessage("§3§lStorm Dragon §r§5has spawned!");
                Drag.setCustomName("§3§lStrom Dragon");
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20000000, 2));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20000000, 20));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20000000, 2));
            }
            if (matchDrag > 0 && matchDrag < 11){
                Bukkit.broadcastMessage("§c§lNecron Dragon §r§5has spawned!");
                Drag.setCustomName("§c§lNecron Dragon");
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20000000, 2));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20000000, 10));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20000000, 4));
            }
            if (matchDrag == 0){
                Bukkit.broadcastMessage("§6§lNecrolord Dragon §r§5has spawned!");
                Drag.setCustomName("§6§lNecrolord Dragon");
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20000000, 3));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 20000000, 30));
                Drag.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20000000, 2));
            }
        }
    }
     
  2. Offline

    CraftCreeper6

    @Lavarite
    So what happens? My guess is that you'll get a fair few errors from this since not every entity that gets spawned will be an Ender Dragon.

    Consider adding a check for that first of all.

    Do you get any messages in the chat? Or does it just not run at all?

    If the latter, have you registered your events?
     
  3. Offline

    Lavarite

    I do not get ANY messages or errors in IDE
    although this code only gets triggered on enderdragonspawn
     
  4. Offline

    CraftCreeper6

    @Lavarite
    This code will get trigger when any Creature spawns.

    Did you register your events?
     
  5. Offline

    Lavarite

    oh i see now yes
    i did not register them
    and do you know how to trigger it on enderdragon spawn?
     
  6. Offline

    CraftCreeper6

    @Lavarite
    Check if event.getEntity() is instanceof EnderDragon.
     
  7. Offline

    Lavarite

    did the check and still nothin
     
    Last edited: Mar 17, 2022
  8. Offline

    timtower Administrator Administrator Moderator

    @Lavarite Considered printing a line of what type gets spawned?
     
  9. Offline

    Lavarite

    @timtower
    Yep it gets broadcasted!
    There are parts in code like
    Bukkit.broadcastMessage("§5§lEnder Dragon §r§5has spawned!");
     
    Last edited: Mar 17, 2022
  10. Offline

    timtower Administrator Administrator Moderator

    I am talking about in the event.
    Do you have a line that just prints what entity type gets spawned before any checks.
     
  11. Offline

    Lavarite

    RESOLVED
    didn't set up listener
     
Thread Status:
Not open for further replies.

Share This Page