Stable death effect version.
This commit is contained in:
parent
edb6318f31
commit
faa866fba1
@ -8,6 +8,7 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -21,6 +22,7 @@ import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.common.util.UtilSkull;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class DeathEffect
|
||||
@ -32,11 +34,10 @@ public class DeathEffect
|
||||
// attack will start.
|
||||
private Location _chickens;
|
||||
|
||||
// All the spawned eggs from death effects that haven't been removed.
|
||||
// All the spawned eggs that have yet to be removed.
|
||||
private ArrayList<Item> _eggs = new ArrayList<Item>();
|
||||
|
||||
// All the spawned armor stands from the death effects that haven't been
|
||||
// removed.
|
||||
// All the spawned armor stands that have yet to be removed.
|
||||
private ArrayList<ArmorStand> _stands = new ArrayList<ArmorStand>();
|
||||
|
||||
public DeathEffect(MineWare host, Location chickens)
|
||||
@ -52,48 +53,52 @@ public class DeathEffect
|
||||
Block belowFirst = loc.getBlock().getRelative(BlockFace.DOWN);
|
||||
Block belowSecond = belowFirst.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (belowFirst.isEmpty() && belowSecond.isEmpty())
|
||||
loc.add(0, 0.5, 0);
|
||||
spawnChickenHead(loc);
|
||||
playChickenSounds(loc);
|
||||
|
||||
if (!belowFirst.isEmpty() || !belowSecond.isEmpty())
|
||||
startFoodSpawnTask(loc);
|
||||
|
||||
System.out.println("Death effect triggered for " + player.getName() + ".");
|
||||
startEggSpawnTask(loc);
|
||||
spawnChickenHead(loc);
|
||||
}
|
||||
|
||||
private void startEggSpawnTask(Location loc)
|
||||
private void startFoodSpawnTask(Location loc)
|
||||
{
|
||||
for (int i = 0; i < 20; i++)
|
||||
Location dropsite = loc.clone().add(0, 0.5, 0);
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
loc.add(0, 1, 0);
|
||||
Material material = Material.EGG;
|
||||
|
||||
ItemBuilder builder = new ItemBuilder(Material.EGG);
|
||||
builder.setTitle(UtilMath.r(999999) + "Egg");
|
||||
if (UtilMath.random.nextBoolean())
|
||||
material = Material.COOKED_CHICKEN;
|
||||
|
||||
Item egg = loc.getWorld().dropItem(loc, builder.build());
|
||||
ItemBuilder builder = new ItemBuilder(material);
|
||||
builder.setTitle(UtilMath.r(999999) + "Food");
|
||||
|
||||
Item food = dropsite.getWorld().dropItem(dropsite, builder.build());
|
||||
|
||||
Vector velocity = new Vector((Math.random() - 0.5) * 0.5, 0, (Math.random() - 0.5) * 0.5);
|
||||
egg.setVelocity(velocity);
|
||||
food.setVelocity(velocity);
|
||||
|
||||
_eggs.add(egg);
|
||||
removeSpawnedEggTask(egg);
|
||||
_eggs.add(food);
|
||||
removeSpawnedFoodTask(food);
|
||||
}
|
||||
|
||||
loc.getWorld().playSound(loc, Sound.CHICKEN_EGG_POP, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
private void removeSpawnedEggTask(Item egg)
|
||||
private void removeSpawnedFoodTask(Item food)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (egg.isValid() && _eggs.contains(egg))
|
||||
if (food.isValid() && _eggs.contains(food))
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, egg.getLocation(), 0.0F, 0.0F, 0.0F,
|
||||
UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, food.getLocation(), 0.0F, 0.0F, 0.0F,
|
||||
0.0F, 1, ViewDist.MAX);
|
||||
_eggs.remove(egg);
|
||||
egg.remove();
|
||||
_eggs.remove(food);
|
||||
food.remove();
|
||||
}
|
||||
}
|
||||
}.runTaskLater(_plugin, 60L);
|
||||
@ -101,20 +106,20 @@ public class DeathEffect
|
||||
|
||||
private void spawnChickenHead(Location dropsite)
|
||||
{
|
||||
ArmorStand stand = _host.WorldData.World.spawn(dropsite, ArmorStand.class);
|
||||
// stand.setVegetated(true);
|
||||
Location modifiedDropsite = dropsite.clone().subtract(0, 0.5, 0);
|
||||
|
||||
ArmorStand stand = _host.WorldData.World.spawn(modifiedDropsite, ArmorStand.class);
|
||||
stand.setVisible(false);
|
||||
stand.setGravity(false);
|
||||
stand.setBasePlate(false);
|
||||
stand.setVisible(false);
|
||||
|
||||
ItemStack chickenHead = new ItemStack(Material.SKULL_ITEM);
|
||||
ItemStack chickenHead = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, (byte) 3);
|
||||
SkullMeta meta = (SkullMeta) chickenHead.getItemMeta();
|
||||
meta.setOwner("MHF_Chicken");
|
||||
meta.setOwner(UtilSkull.getPlayerHeadName(EntityType.CHICKEN));
|
||||
chickenHead.setItemMeta(meta);
|
||||
|
||||
stand.getEquipment().setHelmet(chickenHead);
|
||||
_stands.add(stand);
|
||||
|
||||
playHeadRotation(stand);
|
||||
}
|
||||
|
||||
@ -127,20 +132,52 @@ public class DeathEffect
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (shouldCancel() || !stand.isValid())
|
||||
if (!stand.isValid())
|
||||
{
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
i++;
|
||||
i += 12;
|
||||
|
||||
if (i <= 360)
|
||||
stand.getLocation().setYaw(i);
|
||||
{
|
||||
stand.setHeadPose(new EulerAngle(0, Math.toRadians(i), 0));
|
||||
}
|
||||
else
|
||||
cancel();
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!stand.isValid())
|
||||
{
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
stand.remove();
|
||||
}
|
||||
}.runTaskLater(_plugin, 40L);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(_plugin, 5L);
|
||||
}.runTaskTimer(_plugin, 1L, 1L);
|
||||
}
|
||||
|
||||
private void playChickenSounds(Location loc)
|
||||
{
|
||||
loc.getWorld().playSound(loc, Sound.CHICKEN_HURT, 0.5F, 1.0F);
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
loc.getWorld().playSound(loc, Sound.EAT, 1.5F, 1.0F);
|
||||
loc.getWorld().playSound(loc, Sound.BURP, 1.5F, 1.0F);
|
||||
}
|
||||
}.runTaskLater(_plugin, 10L);
|
||||
}
|
||||
|
||||
public void removeSpawnedEntities()
|
||||
@ -164,9 +201,4 @@ public class DeathEffect
|
||||
_eggs.clear();
|
||||
_stands.clear();
|
||||
}
|
||||
|
||||
private boolean shouldCancel()
|
||||
{
|
||||
return !_host.IsLive() || !_host.isChallengeStarted();
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +146,7 @@ public class MineWare extends SoloGame implements IThrown
|
||||
AutomaticRespawn = false;
|
||||
DeathMessages = false;
|
||||
GiveClock = false;
|
||||
CreatureAllow = true;
|
||||
|
||||
Manager.GetCreature().SetDisableCustomDrops(true);
|
||||
|
||||
@ -661,6 +662,7 @@ public class MineWare extends SoloGame implements IThrown
|
||||
_currentCrumble = false;
|
||||
}
|
||||
|
||||
_deathEffect.removeSpawnedEntities();
|
||||
_challenge.generateRoom();
|
||||
|
||||
ArrayList<Location> spawns = _challenge.getSpawns();
|
||||
@ -953,7 +955,6 @@ public class MineWare extends SoloGame implements IThrown
|
||||
Bukkit.getServer().getPluginManager().callEvent(new ChallengeEndEvent(_challenge));
|
||||
HandlerList.unregisterAll(_challenge);
|
||||
|
||||
_deathEffect.removeSpawnedEntities();
|
||||
_challenge.EndOrder();
|
||||
_isChallengeStarted = false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user