setting/cancel EnderDragon targets

Discussion in 'Plugin Development' started by krooked590, Dec 10, 2011.

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

    krooked590

    so i threw together a quick plugin to make enderdragons not grief your world or target the player but the event.setCancelled(true) doesnt seem to do anything to them. the griefing part works though. Any thoughts?

    Code:
    public class MyEnderDragon extends JavaPlugin{
        private static final Logger log = Logger.getLogger ("MINECRAFT");
        public DragonTargetListener dragonlistener = new DragonTargetListener();
        public DragonGriefListener nodragongrief = new DragonGriefListener();
    
        @Override
        public void onDisable(){
            PluginDescriptionFile plug = this.getDescription();
            String PluginName = plug.getName();
            String PluginVersion = plug.getVersion();
            log.info("[" + PluginName + "] " + PluginVersion + " is disabled.");
        }
    
        @Override
        public void onEnable(){
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.ENTITY_TARGET, this.dragonlistener, Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.nodragongrief, Event.Priority.Normal, this);
            PluginDescriptionFile plug = this.getDescription();
            String PluginName = plug.getName();
            String PluginVersion = plug.getVersion();
            log.info("[" + PluginName + "] " + PluginVersion + " is enabled.");
        }
        class DragonTargetListener extends EntityListener{
            public DragonTargetListener(){
            }
            public void onEntityTarget(EntityTargetEvent event) {
                if ((event.getEntity() instanceof EnderDragon && event.getTarget() instanceof Player)) {
                    event.setCancelled(true);
                }
            }
        }
    
        class DragonGriefListener extends EntityListener{
            public DragonGriefListener(){
            }
            public void onEntityExplode(EntityExplodeEvent event) {
                if ((event.getEntity() instanceof EnderDragon))
                    event.setCancelled(true);
            }
        }
    }
     
  2. Offline

    coldandtired

    You can't put the listener classes inside your plugin class. Create new files for them.
     
  3. Offline

    daemitus

    The hell you cant. Youve never heard of nesting classes? So long as you register the internal class with the plugin manager it works fine.
     
  4. Offline

    coldandtired

    I had a feeling when I posted that I could be wrong :)

    I've heard of them (in C#) but never bothered to use them.
     
  5. Handling the EnderDragon is a bit difficult at the moment as the dragon consists of multiple entites. You should probably wait until the recommended build is out.
     
  6. Offline

    krooked590

    Yea I had a feeling that was the case. Or the the movement code was to follow a player or something and never really "target" anybody.
     
  7. Offline

    bossomeness

    So does anyone know how to make it so ender dragons can't go through blocks? I know you have to somehow modify the ender dragon entity class file, but I dont know how...
     
Thread Status:
Not open for further replies.

Share This Page