Solved Killing a custom mob

Discussion in 'Plugin Help/Development/Requests' started by Scorpionvssub, Oct 27, 2015.

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

    Scorpionvssub

    This is both a question aswell as an ask for help, tried finding ways or clues on how to do this but no luck, if i spawn a mob via a plugin which isnt done via /mob <mob> or created ingame like you can with withers and eggs how can i kill them best?

    Example:

    I spawn a creeper in with the name TNT but due to a bug 2 appear so i wanna kill them and have the plugin respawn 1 or do it manually via /mob creeper or an egg but by then the plugin altered the mob diff name more health etc. so /killall wont work on it what is the best method to kill this custom mob.

    Is there an event for this? or..
     
  2. Offline

    Ruptur

    @Scorpionvssub
    What you want is a bit unclear.
    Do you want to be able to spawn a mob, keep a track of it and then kill it?
     
  3. Offline

    Scorpionvssub

    @Ruptur That dragon slaying plugin as u know now spawns a ender dragon in with the name FireDRagon(customizable in config) with adjustable health but if at some point via bug 2 spawn i wanna be able to kill em via command and killall command wont work
     
  4. Offline

    Ruptur

    @Scorpionvssub

    You could either loop thr all entities and get the one which has the same name or if you are specifically looking for a certain mob then you can get all the entities by class.

    An example of getting all pigs in a world:
    Code:
    World w = getServer().getWorld("a world");
    Collection<Entity> entities w.getEntitiesByClasses(Pig.class);
    
    // Do something with the entities
    
     
  5. Offline

    Scorpionvssub

    @Ruptur Just a quick note: i never defined the enderdragon as a dragon class in the dragon plugin idk if that matters but the entities. doesnt give many options to do something with.

    Tried something testing it

    Edit: since i never used this before i tried this:
    Code:
            if (args[0].equalsIgnoreCase("kill")) {
                World w = getServer().getWorld(getName());
                Collection<Entity> entities = w.getEntitiesByClasses(EnderDragon.class);
                w.getEntities().removeAll(entities);
                return true;
            }
    but returns nullpointers on collection and without the = in btween it gives errors for building plugin..
     
    Last edited: Oct 29, 2015
  6. Offline

    Ruptur

    @Scorpionvssub
    Have you check whether the world is null?

    Also, simply clearing entities from the collection will not remove entities in the world.
    You need to check then cast the entity to LivingEntity and kill them by setting health to 0.
     
  7. Offline

    Scorpionvssub

  8. Offline

    Scorpionvssub

    Code:
            if (args[0].equalsIgnoreCase("kill")) {
                Player p = (Player) sender;
                String world = getConfig().getString("Location.world");
                World w = getServer().getWorld(world);
                Collection<Entity> entities = w.getEntitiesByClasses(EnderDragon.class);
                LivingEntity entity = (LivingEntity) entities;
                entity.setHealth(0);
                return true;
            }
    Tried this but i get an error using this: [10-11 17:22:57 ] [Server] [Informatie] Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.bukkit.entity.LivingEntity
     
    Last edited: Nov 10, 2015
Thread Status:
Not open for further replies.

Share This Page