Solved bosses mobs

Discussion in 'Spigot Plugin Help' started by spede, Jun 18, 2018.

  1. What do you need to add to the code so that the mob is stationary?



    package ru.meloncode.cristalix.prison.mobs;

    import java.util.HashMap;
    import java.util.Random;
    import net.milkbowl.vault.economy.Economy;
    import net.minecraft.server.v1_8_R3.AttributeInstance;
    import net.minecraft.server.v1_8_R3.DamageSource;
    import net.minecraft.server.v1_8_R3.EntityHuman;
    import net.minecraft.server.v1_8_R3.EntityLiving;
    import net.minecraft.server.v1_8_R3.EntityMonster;
    import net.minecraft.server.v1_8_R3.EntityPlayer;
    import net.minecraft.server.v1_8_R3.GenericAttributes;
    import net.minecraft.server.v1_8_R3.PathfinderGoalHurtByTarget;
    import net.minecraft.server.v1_8_R3.PathfinderGoalLookAtPlayer;
    import net.minecraft.server.v1_8_R3.PathfinderGoalMeleeAttack;
    import net.minecraft.server.v1_8_R3.PathfinderGoalMoveTowardsRestriction;
    import net.minecraft.server.v1_8_R3.PathfinderGoalNearestAttackableTarget;
    import net.minecraft.server.v1_8_R3.PathfinderGoalRandomStroll;
    import net.minecraft.server.v1_8_R3.PathfinderGoalSelector;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.craftbukkit.v1_8_R3.CraftWorld;
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityRegainHealthEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.util.Vector;
    import ru.meloncode.cristalix.prison.Main;
    import ru.meloncode.cristalix.prison.PrisonPlayer;
    import ru.meloncode.cristalix.prison.Utils;

    public class EntityWitch
    extends EntityMonster
    {
    Spawner spawner;
    org.bukkit.entity.Entity bukkitEntity;
    org.bukkit.entity.Entity jockey;
    HashMap<String, Integer> attackers;
    int totalDamage;

    public EntityWitch(Spawner spawner)
    {
    super(((CraftWorld)spawner.getSpawnLocation().getWorld()).getHandle());

    getAttributeInstance(GenericAttributes.maxHealth).setValue(Main.WITCH_HEALTH);
    getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128.0D);
    getAttributeInstance(GenericAttributes.c).setValue(2.147483647E9D);
    getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(Main.WITCH_SPEED);
    getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(Main.WITCH_DAMAGE);
    setHealth(Main.WITCH_HEALTH);
    this.goalSelector.a(1, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 128.0F));
    this.goalSelector.a(5, new PathfinderGoalMoveTowardsRestriction(this, 1.0D));
    this.goalSelector.a(7, new PathfinderGoalRandomStroll(this, 1.0D));
    this.targetSelector.a(4, new PathfinderGoalNearestAttackableTarget(this, EntityHuman.class, 1, true, false, null));
    this.targetSelector.a(5, new PathfinderGoalHurtByTarget(this, true, new Class[0]));
    this.goalSelector.a(9, new PathfinderGoalLookAtPlayer(this, EntityHuman.class, 64.0F));
    this.goalSelector.a(2, new PathfinderGoalMeleeAttack(this, Main.WITCH_DAMAGE, true));
    setCustomName(Main.WITCH_NAME.replace("#", String.valueOf((int)getHealth())).replace("<3", "\u2764"));
    setCustomNameVisible(true);

    this.canPickUpLoot = false;
    this.fireProof = true;
    this.spawner = spawner;
    this.spawner.register(this);
    this.persistent = true;
    this.expToDrop = 0;
    this.bukkitEntity = getBukkitEntity();

    this.attackers = new HashMap();
    this.totalDamage = 0;
    }

    public void superJump()
    {
    getBukkitEntity().getWorld().playEffect(getBukkitEntity().getLocation(), Effect.MOBSPAWNER_FLAMES, 5);
    getBukkitEntity().setVelocity(new Vector(0, 1, 0).multiply(1));

    new BukkitRunnable()
    {
    public void run()
    {
    EntityWitch.this.getBukkitEntity().getWorld().playSound(EntityWitch.this.getBukkitEntity().getLocation(), Sound.EXPLODE, 1.0F, 1.0F);
    for (org.bukkit.entity.Entity entity : EntityWitch.this.getBukkitEntity().getNearbyEntities(7.0D, 4.0D, 7.0D)) {
    if (entity.getType() == EntityType.PLAYER)
    {
    entity.setVelocity(entity.getVelocity().add(entity.getLocation().getDirection()).multiply(-3));
    EntityDamageEvent event = new EntityDamageEvent(entity, EntityDamageEvent.DamageCause.MAGIC, 5);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
    ((LivingEntity)entity).damage(5.0D);
    }
    }
    }
    }
    }.runTaskLater(Main.getInstance(), 25L);
    }

    int jump_delay = Main.WITCH_JUMPDELAY;

    public boolean damageEntity(DamageSource source, float a)
    {
    if (((this.passenger != null) && (source.getEntity() == this.passenger)) || (source == DamageSource.STUCK)) {
    return false;
    }
    setCustomName(Main.WITCH_NAME.replace("#", String.valueOf((int)getHealth())).replace("<3", "\u2764"));
    if (this.passenger != null)
    {
    if (source == DamageSource.projectile(this, this.passenger)) {
    return false;
    }
    return this.passenger.damageEntity(source, a);
    }
    net.minecraft.server.v1_8_R3.Entity entity = source.i();
    PrisonPlayer pp;
    if ((entity != null) &&
    (entity.getBukkitEntity().getType() == EntityType.PLAYER))
    {
    pp = PrisonPlayer.getPrisonPlayer((Player)entity.getBukkitEntity());
    if (!this.attackers.containsKey(pp.getName())) {
    this.attackers.put(pp.getName(), Integer.valueOf((int)a));
    } else {
    this.attackers.put(pp.getName(), Integer.valueOf((int)(((Integer)this.attackers.get(pp.getName())).intValue() + a)));
    }
    this.totalDamage = ((int)(this.totalDamage + a));
    }
    if (this.random.nextFloat() < 0.1D) {
    for (org.bukkit.entity.Entity e : getBukkitEntity().getNearbyEntities(10.0D, 5.0D, 10.0D)) {
    if (e.getType() == EntityType.PLAYER) {
    ((LivingEntity)e).addPotionEffect(new PotionEffect(PotionEffectType.POISON, 200, 0));
    }
    }
    }
    return super.damageEntity(source, a);
    }

    int hp_delay = 5;

    public void m()
    {
    if ((this.spawner.getCurrent() != null) && (this.spawner.getSpawnLocation().distance(this.spawner.getCurrent().getBukkitEntity().getLocation()) > 20.0D)) {
    this.spawner.getCurrent().setLocation(this.spawner.getSpawnLocation().getX(), this.spawner.getSpawnLocation().getY(), this.spawner.getSpawnLocation().getZ(), 0.0F, 0.0F);
    }
    if (this.hp_delay-- <= 0)
    {
    setCustomName(Main.WITCH_NAME.replace("#", String.valueOf((int)getHealth())).replace("<3", "\u2764"));
    if (this.getHealth() < Main.WITCH_HEALTH) {
    this.heal(1.0f, EntityRegainHealthEvent.RegainReason.REGEN);
    }
    this.hp_delay = 5;
    }
    if (getGoalTarget() != null) {
    if (this.passenger == null)
    {
    this.jump_delay -= 1;
    if (this.jump_delay <= 0)
    {
    this.jump_delay = Main.WITCH_JUMPDELAY;
    superJump();
    }
    }
    else
    {
    boolean isSameWorld = getBukkitEntity().getLocation().getWorld() == getGoalTarget().getBukkitEntity().getLocation().getWorld();
    double distance = isSameWorld ? getBukkitEntity().getLocation().distance(getGoalTarget().getBukkitEntity().getLocation()) : 32.0D;
    if (distance > 16.0D) {
    getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(0.0D);
    } else {
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(Main.WITCH_SPEED);
    }
    }
    }
    super.m();
    }

    public void die()
    {
    if (this.spawner != null) {
    this.spawner.iDead();
    }
    if ((this.killer instanceof EntityPlayer))
    {
    Player p = (Player)this.killer.getBukkitEntity();
    if (this.spawner != null) {
    PrisonPlayer.getPrisonPlayer(p).addMobKill(this.spawner.getType());
    }
    }
    if (this.killer != null)
    {
    HashMap<String, Double> percents = Utils.calculatePercents(this.attackers, this.totalDamage);
    for (String key : percents.keySet())
    {
    final int money = (int)(percents.get(key) * Main.WITCH_MONEY / 100.0);
    Main.economy.depositPlayer(key, money);
    if (Bukkit.getPlayer(key) != null) {
    Bukkit.getPlayer(key).sendMessage(ChatColor.GREEN + "На ваш счёт было зачисленно " + ChatColor.GREEN + money + "$");
    }
    }
    Bukkit.broadcastMessage(ChatColor.RED + "Одержимая Ведьма была повержена!Наподавшие получили сокровища!");
    Main.dropGiantDropOn(this.getBukkitEntity().getLocation());
    final Random rnd = new Random();
    final int amount = rnd.nextInt(1) + 2;
    final ItemStack star = new ItemStack(Material.NETHER_STAR);
    final ItemMeta starMeta = star.getItemMeta();
    starMeta.setDisplayName(ChatColor.GOLD + "\u0417\u0432\u0435\u0437\u0434\u0430");
    star.setItemMeta(starMeta);
    star.setAmount(amount);
    this.getBukkitEntity().getLocation().getWorld().dropItemNaturally(this.getBukkitEntity().getLocation(), star);
    }
    super.die();
    }

    public String getName()
    {
    return Main.WITCH_NAME.replace("<3", "").replace("#", "");
    }
    }
     
  2. Please, paste on
    Code (Text):
     form for better reading