More event stuff!

This commit is contained in:
Shaun Bennett 2015-06-11 23:35:29 -05:00
parent 9cdf69b19d
commit d24f01ba86
13 changed files with 130 additions and 261 deletions

View File

@ -55,7 +55,7 @@ public class ClansRegions
* Initializes a server-side clan and claims area according to the * Initializes a server-side clan and claims area according to the
* location and radius properties passed in. * location and radius properties passed in.
* @param clanName - the name of the clan to create/claim territory for * @param clanName - the name of the clan to create/claim territory for
* @param location - the center location to begin the claim * @param locations - the center location to begin the claim
* @param chunkRadius - the radius (in chunks) to claim * @param chunkRadius - the radius (in chunks) to claim
* @param claimOffset - the initial offset in claim (creating a 'hole' with chunk offset radius) * @param claimOffset - the initial offset in claim (creating a 'hole' with chunk offset radius)
* @param safe - whether the chunk claimed is considered a 'safe' (pvp-free) region. * @param safe - whether the chunk claimed is considered a 'safe' (pvp-free) region.

View File

@ -36,10 +36,4 @@ public class ConcreteWorldEventFactory implements WorldEventFactory
{ {
return null; return null;
} }
@Override
public WorldEvent randomFromType(Location locationm, WorldEventType type)
{
return null;
}
} }

View File

@ -15,6 +15,7 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand; import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
import mineplex.game.clans.clans.worldevent.event.EventState;
import mineplex.game.clans.clans.worldevent.event.WorldEvent; import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.damage.DamageManager;
@ -68,7 +69,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener
while (iterator.hasNext()) while (iterator.hasNext())
{ {
WorldEvent event = iterator.next(); WorldEvent event = iterator.next();
if (event.isRunning()) event.cancel(); if (event.getState() != EventState.END) event.cancel();
HandlerList.unregisterAll(event); HandlerList.unregisterAll(event);
iterator.remove(); iterator.remove();
} }
@ -93,17 +94,6 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener
_events.remove(event); _events.remove(event);
} }
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK) return;
for (WorldEvent e : _events)
{
e.tick();
}
}
@Override @Override
public void addCommands() public void addCommands()
{ {

View File

@ -21,7 +21,7 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
// Spawn Data // Spawn Data
private T _entity; private T _entity;
private Class<T> _entityClass; private Class<? extends T> _entityClass;
private Location _spawnLocation; private Location _spawnLocation;
// Creature Data // Creature Data
@ -51,15 +51,20 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
spawnEntity(); spawnEntity();
} }
protected void spawnEntity() protected final void spawnEntity()
{ {
_entity = _spawnLocation.getWorld().spawn(_spawnLocation, _entityClass); Location spawnLocation = _entity == null ? _spawnLocation : _entity.getLocation();
T entity = _spawnLocation.getWorld().spawn(spawnLocation, getEntityClass());
setEntity(entity);
updateEntityHealth(); updateEntityHealth();
updateName(); updateName();
_entity.setRemoveWhenFarAway(false); entity.setRemoveWhenFarAway(false);
spawnCustom();
} }
protected abstract void spawnCustom();
protected void updateEntityHealth() protected void updateEntityHealth()
{ {
_entity.setMaxHealth(10000d); _entity.setMaxHealth(10000d);
@ -85,12 +90,18 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
_entity.setCustomNameVisible(_useName); _entity.setCustomNameVisible(_useName);
} }
protected void remove() public void remove()
{
remove(true);
}
public void remove(boolean removeFromEvent)
{ {
if (_entity != null) if (_entity != null)
_entity.remove(); _entity.remove();
_event.removeCreature(this); if (removeFromEvent)
_event.removeCreature(this);
} }
protected final void die() protected final void die()
@ -118,9 +129,21 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
public void setEntity(T entity) public void setEntity(T entity)
{ {
if (_entity != null) _entity.remove();
_entity = entity; _entity = entity;
} }
public Class<? extends T> getEntityClass()
{
return _entityClass;
}
public void setEntityClass(Class<? extends T> clazz)
{
_entityClass = clazz;
}
public Location getSpawnLocation() public Location getSpawnLocation()
{ {
return _spawnLocation; return _spawnLocation;
@ -225,6 +248,5 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
updateEntityHealth(); updateEntityHealth();
applyDamage(event.GetDamage()); applyDamage(event.GetDamage());
} }
} }

View File

@ -2,6 +2,7 @@ package mineplex.game.clans.clans.worldevent.event;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -12,6 +13,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.creature.Creature;
import mineplex.core.data.BlockData; import mineplex.core.data.BlockData;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -63,6 +65,7 @@ public abstract class WorldEvent implements Listener
public final void cancel() public final void cancel()
{ {
setState(EventState.END); setState(EventState.END);
clearCreatures();
customCancel(); customCancel();
} }
@ -130,6 +133,11 @@ public abstract class WorldEvent implements Listener
return _centerLocation; return _centerLocation;
} }
protected List<EventCreature> getCreatures()
{
return _creatures;
}
public void registerCreature(EventCreature creature) public void registerCreature(EventCreature creature)
{ {
UtilServer.getServer().getPluginManager().registerEvents(creature, _eventManager.getPlugin()); UtilServer.getServer().getPluginManager().registerEvents(creature, _eventManager.getPlugin());
@ -142,6 +150,22 @@ public abstract class WorldEvent implements Listener
_creatures.remove(creature); _creatures.remove(creature);
} }
public void clearCreatures()
{
for (EventCreature creature : _creatures)
{
creature.remove(false);
HandlerList.unregisterAll(creature);
}
_creatures.clear();
}
public void restoreBlocks()
{
}
public void setBlock(Block block, int id, byte data) public void setBlock(Block block, int id, byte data)
{ {
if (!_blocks.containsKey(block)) if (!_blocks.containsKey(block))

View File

@ -1,90 +0,0 @@
package mineplex.game.clans.clans.worldevent.event.boss;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.clans.worldevent.WorldEventListener;
import mineplex.minecraft.game.core.damage.DamageManager;
public abstract class BossEvent extends WorldEvent
{
private double _maxHealth;
private double _health;
private double _lastHealth;
// Action Bar Messages
private float _radiusSquared;
public BossEvent(WorldEventManager eventManager, DamageManager damageManager, String name, Location center, float radius, double maxHealth)
{
super(eventManager, damageManager, name, center);
_health = maxHealth;
_maxHealth = maxHealth;
setRadius(radius);
}
@Override
protected void customTick()
{
if (_lastHealth != _health || getTicks() % 20 == 0)
{
for (Player player : Bukkit.getServer().getOnlinePlayers())
{
if (player.getWorld().equals(getCenterLocation().getWorld()) && getCenterLocation().distanceSquared(player.getLocation()) < _radiusSquared)
{
UtilTextBottom.displayProgress(getName(), _health / _maxHealth, player);
}
}
}
_lastHealth = _health;
if (_health <= 0)
{
onDeath();
if (_health <= 0) // only finish if the health is still less than 0
for (WorldEventListener listener : getListeners()) listener.onComplete(this);
}
}
public void setRadius(float radius)
{
_radiusSquared = radius * radius;
}
protected abstract void onDeath();
protected void damage(double health)
{
_health -= health;
}
protected void setMaxHealth(double maxHealth)
{
_maxHealth = maxHealth;
}
public void setHealth(double health)
{
_health = health;
}
public double getHealth()
{
return _health;
}
public double getMaxHealth()
{
return _maxHealth;
}
public boolean inRange(Location loc)
{
return loc.distanceSquared(getCenterLocation()) <= _radiusSquared;
}
}

View File

@ -1,33 +1,25 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime; package mineplex.game.clans.clans.worldevent.event.boss.slime;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.SlimeSplitEvent; import org.bukkit.event.entity.SlimeSplitEvent;
import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.event.boss.BossEvent; import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.game.clans.clans.worldevent.event.EventState;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.clans.worldevent.event.boss.slime.creature.SlimeCreature;
import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.damage.DamageManager;
public class SlimeBoss extends BossEvent public class SlimeBoss extends WorldEvent
{ {
private static final int MAX_SIZE = 10; private static final int MAX_SIZE = 10;
private static final int MIN_SIZE = 1; private static final int MIN_SIZE = 1;
private List<SlimePart> _slimes;
public SlimeBoss(WorldEventManager eventManager, DamageManager damageManager, Location center) public SlimeBoss(WorldEventManager eventManager, DamageManager damageManager, Location center)
{ {
super(eventManager, damageManager, "Slime King", center, 100, 300); super(eventManager, damageManager, "Slime King", center);
_slimes = new LinkedList<SlimePart>();
spawnSlime(center, MAX_SIZE); spawnSlime(center, MAX_SIZE);
} }
@ -36,81 +28,20 @@ public class SlimeBoss extends BossEvent
protected void customStart() protected void customStart()
{ {
Bukkit.broadcastMessage("Custom Start"); Bukkit.broadcastMessage("Custom Start");
spawnSlime(getCenterLocation(), 10);
setState(EventState.LIVE);
} }
@Override @Override
protected void customCancel() protected void customCancel()
{ {
Bukkit.broadcastMessage("Custom Cancel"); Bukkit.broadcastMessage("Custom Cancel");
// Remove all the slime entities!
for (SlimePart slime : _slimes)
{
slime.getEntity().remove();
}
} }
@Override @Override
protected void customTick() protected void customTick()
{ {
super.customTick();
for (SlimePart slimePart : _slimes)
{
slimePart.tick();
}
}
@EventHandler
public void onSlimeDamage(EntityDamageEvent event)
{
if (event.getEntity().getType() == EntityType.SLIME)
{
for (SlimePart slimePart : _slimes)
{
if (event.getEntity().equals(slimePart.getEntity()))
{
// slime.setHealth(slime.getMaxHealth());
// event.setDamage(0);
break;
}
}
}
}
@EventHandler
public void onSplit(SlimeSplitEvent event)
{
for (SlimePart slimeData : _slimes)
{
if (event.getEntity().equals(slimeData.getEntity()))
event.setCancelled(true);
}
}
@EventHandler
public void onDeath(EntityDeathEvent event)
{
if (event.getEntity().getType() == EntityType.SLIME)
{
Iterator<SlimePart> slimeIterator = _slimes.iterator();
while (slimeIterator.hasNext())
{
SlimePart slimePart = slimeIterator.next();
if (slimePart.getEntity().equals(event.getEntity()))
{
splitSlime(slimePart);
event.setDroppedExp(0);
slimeIterator.remove();
break;
}
}
// Check if our main boss died every time a slime entity dies
checkDeath();
}
} }
/** /**
@ -118,10 +49,22 @@ public class SlimeBoss extends BossEvent
*/ */
private void checkDeath() private void checkDeath()
{ {
if (_slimes.size() == 0) if (getCreatures().size() == 0)
{ {
// SLIME IS DEAD! setState(EventState.END);
setHealth(0); Bukkit.broadcastMessage("FINISHED!");
}
}
@Override
public void removeCreature(EventCreature creature)
{
super.removeCreature(creature);
if (creature instanceof SlimeCreature)
{
splitSlime(((SlimeCreature) creature));
checkDeath();
} }
} }
@ -145,7 +88,7 @@ public class SlimeBoss extends BossEvent
return 40 * slimeSize; return 40 * slimeSize;
} }
private void splitSlime(SlimePart slime) public void splitSlime(SlimeCreature slime)
{ {
int splitCount = getSplitCount(slime.getSize()); int splitCount = getSplitCount(slime.getSize());
int splitSize = getSplitSize(slime.getSize()); int splitSize = getSplitSize(slime.getSize());
@ -159,16 +102,11 @@ public class SlimeBoss extends BossEvent
} }
} }
private SlimePart spawnSlime(Location location, int size) private SlimeCreature spawnSlime(Location location, int size)
{ {
SlimePart slimePart = new SlimePart(this, location, size, getMaxSlimeHealth(size), getEnrageTicks(size)); SlimeCreature slimeCreature = new SlimeCreature(this, location, size, getMaxSlimeHealth(size), getEnrageTicks(size));
_slimes.add(slimePart); registerCreature(slimeCreature);
return slimePart; return slimeCreature;
} }
@Override
protected void onDeath()
{
Bukkit.broadcastMessage("DEATH");
}
} }

View File

@ -1,7 +1,6 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime.ability; package mineplex.game.clans.clans.worldevent.event.boss.slime.ability;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -11,7 +10,7 @@ import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; import mineplex.game.clans.clans.worldevent.event.boss.slime.creature.SlimeCreature;
public class AbsorbAbility extends SlimeAbility public class AbsorbAbility extends SlimeAbility
{ {
@ -20,7 +19,7 @@ public class AbsorbAbility extends SlimeAbility
private int _pulseCount; private int _pulseCount;
private int _maxDistance; private int _maxDistance;
public AbsorbAbility(SlimePart slime) public AbsorbAbility(SlimeCreature slime)
{ {
super(slime); super(slime);
_ticksPerPulse = 20; _ticksPerPulse = 20;
@ -57,8 +56,8 @@ public class AbsorbAbility extends SlimeAbility
Vector dir = UtilAlg.getTrajectory2d(player, getSlime().getEntity()); Vector dir = UtilAlg.getTrajectory2d(player, getSlime().getEntity());
dir.setY(0.4); dir.setY(0.4);
player.setVelocity(dir); player.setVelocity(dir);
getSlime().getBoss().getDamageManager().NewDamageEvent(player, getSlime().getEntity(), null, getSlime().getEvent().getDamageManager().NewDamageEvent(player, getSlime().getEntity(), null,
EntityDamageEvent.DamageCause.MAGIC, getDamage(distance), false, false, false, getSlime().getBoss().getName(), "Absorb"); EntityDamageEvent.DamageCause.MAGIC, getDamage(distance), false, false, false, getSlime().getEvent().getName(), "Absorb");
} }
} }

View File

@ -10,14 +10,14 @@ import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; import mineplex.game.clans.clans.worldevent.event.boss.slime.creature.SlimeCreature;
public class LeapAbility extends SlimeAbility public class LeapAbility extends SlimeAbility
{ {
private Player _target; private Player _target;
private int _jumpTick; private int _jumpTick;
public LeapAbility(SlimePart slime) public LeapAbility(SlimeCreature slime)
{ {
super(slime); super(slime);

View File

@ -19,7 +19,7 @@ import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileManager;
import mineplex.core.projectile.ProjectileUser; import mineplex.core.projectile.ProjectileUser;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; import mineplex.game.clans.clans.worldevent.event.boss.slime.creature.SlimeCreature;
public class RocketAbility extends SlimeAbility implements IThrown public class RocketAbility extends SlimeAbility implements IThrown
{ {
@ -28,12 +28,12 @@ public class RocketAbility extends SlimeAbility implements IThrown
private int _rocketsHit; private int _rocketsHit;
private LinkedList<ShotData> _shots; private LinkedList<ShotData> _shots;
public RocketAbility(SlimePart slime) public RocketAbility(SlimeCreature slime)
{ {
this(slime, 5); this(slime, 5);
} }
public RocketAbility(SlimePart slime, int rocketCount) public RocketAbility(SlimeCreature slime, int rocketCount)
{ {
super(slime); super(slime);
_rocketCount = rocketCount; _rocketCount = rocketCount;
@ -97,7 +97,7 @@ public class RocketAbility extends SlimeAbility implements IThrown
projectile.setSize(2); projectile.setSize(2);
_shots.add(new ShotData(projectile, target)); _shots.add(new ShotData(projectile, target));
ProjectileManager pm = getSlime().getBoss().getEventManager().getClans().getProjectile(); ProjectileManager pm = getSlime().getEvent().getEventManager().getClans().getProjectile();
pm.AddThrow(projectile, getSlime().getEntity(), this, -1, true, true, true, null, 0, 0, UtilParticle.ParticleType.SLIME, UpdateType.FASTEST, 1F); pm.AddThrow(projectile, getSlime().getEntity(), this, -1, true, true, true, null, 0, 0, UtilParticle.ParticleType.SLIME, UpdateType.FASTEST, 1F);
Bukkit.broadcastMessage("Shot Slime at target " + target); Bukkit.broadcastMessage("Shot Slime at target " + target);

View File

@ -12,7 +12,7 @@ import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; import mineplex.game.clans.clans.worldevent.event.boss.slime.creature.SlimeCreature;
public class SlamAbility extends SlimeAbility public class SlamAbility extends SlimeAbility
{ {
@ -27,12 +27,12 @@ public class SlamAbility extends SlimeAbility
private final int _jumpTick; private final int _jumpTick;
private final int _diveTick; private final int _diveTick;
public SlamAbility(SlimePart slime) public SlamAbility(SlimeCreature slime)
{ {
this(slime, 40, 60, 80); this(slime, 40, 60, 80);
} }
public SlamAbility(SlimePart slime, int lockTick, int jumpTick, int diveTick) public SlamAbility(SlimeCreature slime, int lockTick, int jumpTick, int diveTick)
{ {
super(slime); super(slime);
_hasTarget = false; _hasTarget = false;

View File

@ -1,15 +1,15 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime.ability; package mineplex.game.clans.clans.worldevent.event.boss.slime.ability;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; import mineplex.game.clans.clans.worldevent.event.boss.slime.creature.SlimeCreature;
public abstract class SlimeAbility public abstract class SlimeAbility
{ {
private SlimePart _slime; private SlimeCreature _slime;
private boolean _idle; private boolean _idle;
private int _ticks; private int _ticks;
private int _idleTicks; private int _idleTicks;
public SlimeAbility(SlimePart slime) public SlimeAbility(SlimeCreature slime)
{ {
_slime = slime; _slime = slime;
} }
@ -42,7 +42,7 @@ public abstract class SlimeAbility
return _idle; return _idle;
} }
public SlimePart getSlime() public SlimeCreature getSlime()
{ {
return _slime; return _slime;
} }

View File

@ -1,59 +1,53 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime; package mineplex.game.clans.clans.worldevent.event.boss.slime.creature;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.MagmaCube; import org.bukkit.entity.MagmaCube;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.SlimeSplitEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimeBoss;
import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.AbsorbAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.AbsorbAbility;
import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.LeapAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.LeapAbility;
import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.RocketAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.RocketAbility;
import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlamAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlamAbility;
import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlimeAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlimeAbility;
public class SlimePart public class SlimeCreature extends EventCreature<Slime>
{ {
private SlimeBoss _boss; private SlimeBoss _boss;
private Slime _slime;
private SlimeAbility _currentAbility; private SlimeAbility _currentAbility;
private Location _spawnLocation;
private boolean _enraged; private boolean _enraged;
// Storing size here incase one of the slime states decide to change the slime size // Storing size here incase one of the slime states decide to change the slime size
private int _size; private int _size;
private double _maxHealth;
private int _ticksLived; private int _ticksLived;
private int _enrageTicks; private int _enrageTicks;
public SlimePart(SlimeBoss boss, Location location, int size, double maxHealth, int enrageTicks) public SlimeCreature(SlimeBoss boss, Location location, int size, double maxHealth, int enrageTicks)
{ {
super(boss, location, "Slime King", true, maxHealth, Slime.class);
_boss = boss; _boss = boss;
_spawnLocation = location;
_enraged = false; _enraged = false;
_size = size; _size = size;
_maxHealth = maxHealth;
_ticksLived = 0; _ticksLived = 0;
_enrageTicks = enrageTicks; _enrageTicks = enrageTicks;
spawn(location);
} }
private void spawn(Location location) @Override
protected void spawnCustom()
{ {
double health = _maxHealth; getEntity().setSize(_size);
// Remove old slime
if (_slime != null)
{
health = _slime.getHealth();
_slime.remove();
}
_slime = location.getWorld().spawn(location, _enraged ? MagmaCube.class : Slime.class);
_slime.setMaxHealth(_maxHealth);
_slime.setHealth(health);
_slime.setSize(_size);
} }
public void tick() @EventHandler
public void abilityTick(UpdateEvent event)
{ {
if (event.getType() != UpdateType.TICK)
return;
_ticksLived++; _ticksLived++;
if (_currentAbility == null || (_currentAbility.isIdle() && _currentAbility.getIdleTicks() > 80)) if (_currentAbility == null || (_currentAbility.isIdle() && _currentAbility.getIdleTicks() > 80))
@ -86,20 +80,23 @@ public class SlimePart
_currentAbility.tick(); _currentAbility.tick();
} }
@EventHandler
public void onSplit(SlimeSplitEvent event)
{
if (event.getEntity().equals(getEntity()))
event.setCancelled(true);
}
public void setEnraged(boolean enraged) public void setEnraged(boolean enraged)
{ {
if (enraged != _enraged) if (enraged != _enraged)
{ {
_enraged = enraged; _enraged = enraged;
spawn(_slime.getLocation()); setEntityClass(_enraged ? MagmaCube.class : Slime.class);
spawnEntity();
} }
} }
public SlimeBoss getBoss()
{
return _boss;
}
public boolean isEnraged() public boolean isEnraged()
{ {
return _enraged; return _enraged;
@ -110,13 +107,8 @@ public class SlimePart
return _size; return _size;
} }
public Location getSpawnLocation() @Override
public void dieCustom()
{ {
return _spawnLocation;
}
public Slime getEntity()
{
return _slime;
} }
} }