Despawning mob

Discussion in 'Spigot Plugin Development' started by The_AxeMaster, Feb 13, 2017.

  1. Alright, so im trying to make it so the Guardian spawns, fires it laser, and then despawn, um trying to add a delayed task to the command but its not working.

    This is my code in this class so far...

    Code (Text):


    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_11_R1.entity.CraftGuardian;
    import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Guardian;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    import net.minecraft.server.v1_11_R1.EntityGuardian;
    import net.minecraft.server.v1_11_R1.EntityPlayer;

    import java.util.HashMap;
    import java.util.Map;

    public class GuardianBeam {

        private static Main main;
        public GuardianBeam(Main main) {
            GuardianBeam.main = main;



        }


        public static void LaunchAnimation(final Player target)
        {
            final Map<Player, Entity> entityMap = new HashMap<>();
            Location location = target.getLocation().toVector().add(target.getLocation().getDirection().multiply(5)).toLocation(target.getWorld()).add(0, 2, 0);

            final Guardian dabeast = target.getWorld().spawn(location, Guardian.class);
            entityMap.put(target, dabeast);
            LivingEntity pig = (LivingEntity) target.getWorld().spawnEntity(location, EntityType.PIG);
            pig.setAI(false);
            pig.setPassenger(dabeast);
            pig.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 10000000, 2));
            EntityGuardian entity = (EntityGuardian) ((CraftGuardian) dabeast).getHandle();
            EntityPlayer ep = ((CraftPlayer) target).getHandle();
            entity.setGoalTarget(ep);
            Bukkit.broadcastMessage(ChatColor.RED + "Guardian Class Online");

            Bukkit.getScheduler().scheduleSyncDelayedTask(main, new Runnable(){
                @Override
                public void run() {
                    entityMap.get(target).remove();
                }
            },100L);
        }
       
        //dabeast.setAI(false);

    }
       

     
    It kind of works. It spawns the guardian, it fires its laser, but it doesn't despawn. Any replies would be helpful.
     
    • Like Like x 1
  2. NathanWolf

    Supporter

    I'm curious if you've tried just doing daBeast.remove()?

    Not sure if you also need to remove the pig or not .. but I think if you're firing up a timer for each one of these you can simply remove the entities directly, rather than put them in a map.
     
  3. So i should just replace
    Code (Text):
    entityMap.get(target).remove();
    with
    Code (Text):
     daBeast.remove()
    ?

    Also, is everything else correct?
     
    • Like Like x 1
  4. Is everything around line 29 correct?
     
    • Like Like x 1