From bbfa6321060d7b4218d8646110ea2c4d85d63688 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Wed, 3 May 2017 22:05:54 -0300 Subject: [PATCH] Add all the mechanics to the win effects --- .../rankwineffects/WinEffectRankEternal.java | 100 +++++++++++++++++- .../rankwineffects/WinEffectRankHero.java | 100 +++++++++++++++++- .../rankwineffects/WinEffectRankLegend.java | 98 ++++++++++++++++- .../rankwineffects/WinEffectRankTitan.java | 60 ++++++++++- .../rankwineffects/WinEffectRankUltra.java | 12 +-- .../core/gadget/types/WinEffectGadget.java | 22 ++++ 6 files changed, 372 insertions(+), 20 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankEternal.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankEternal.java index 846f43216..030f6b24c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankEternal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankEternal.java @@ -1,14 +1,39 @@ package mineplex.core.gadget.gadgets.wineffect.rankrooms.rankwineffects; -import org.bukkit.Bukkit; +import java.util.Set; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Guardian; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.util.Vector; + +import mineplex.core.common.MaterialData; import mineplex.core.common.Rank; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.wineffect.rankrooms.WinEffectRankBased; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; public class WinEffectRankEternal extends WinEffectRankBased { + private DisguisePlayer _npc; + private Guardian _guardian = null; + private int _step = 0; + + private static final int POINTS = 100; + private static final float RADIUS = 15F; + private static final int BLOCK_RADIUS = 5; + public WinEffectRankEternal(GadgetManager manager) { super(manager, Rank.ETERNAL, WinEffectType.RANK_WIN_EFFECT); @@ -17,13 +42,82 @@ public class WinEffectRankEternal extends WinEffectRankBased @Override public void play() { - Bukkit.broadcastMessage("Playing effect win effect eternal: " + getName()); + Location loc = getBaseLocation(); + + loc.setDirection(_player.getLocation().subtract(loc).toVector().multiply(-1)); + + _npc = getNPC(getPlayer(), loc, true); } @Override public void finish() { - Bukkit.broadcastMessage("Playing effect win effect eternal: " + getName()); + if (_guardian != null) + { + _guardian.remove(); + _guardian = null; + } + _step = 0; + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!isRunning()) + return; + + if (event.getType() != UpdateType.FASTEST) + return; + + Location npcLocation = _npc.getEntity().getBukkitEntity().getLocation(); + + if (_guardian == null) + { + _guardian = npcLocation.getWorld().spawn(npcLocation.add(0, 20, 0), Guardian.class); + } + + double increment = (2 * Math.PI) / POINTS; + + double angle = _step * increment; + Vector vector = new Vector(Math.cos(angle) * RADIUS, 0, Math.sin(angle) * RADIUS); + _guardian.setVelocity(new Vector(0,0,0)); + _guardian.teleport(_player.getLocation().clone().add(vector)); + Vector direction = npcLocation.toVector().subtract(_guardian.getEyeLocation().toVector()); + Location enderLocation = _guardian.getLocation().setDirection(direction); + _guardian.teleport(enderLocation); + + _step++; + + if (_step % 2 == 0) + zap(); + + if (_step == 25) + { + breakBlocks(); + } + } + + private void zap() + { + if (_guardian != null) + { + _guardian.setTarget((LivingEntity) _npc.getEntity().getBukkitEntity()); + } + } + + private void breakBlocks() + { + Set blocks = UtilBlock.getBlocksInRadius(_npc.getEntity().getBukkitEntity().getLocation(), BLOCK_RADIUS, BLOCK_RADIUS); + for (Block block : blocks) + { + MaterialData materialData = MaterialData.of(block.getType(), block.getData()); + block.setType(Material.AIR); + FallingBlock fallingBlock = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), materialData.getMaterial(), materialData.getData()); + fallingBlock.setDropItem(false); + UtilAction.velocity(fallingBlock, UtilAlg.getTrajectory(fallingBlock.getLocation(), _npc.getEntity().getBukkitEntity().getLocation()).multiply(-1), .75, true, 0.8, 0, 1.0, true); + } + ArmorStand armorStand = (ArmorStand) _npc.getEntity().getBukkitEntity(); + armorStand.setHealth(0); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankHero.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankHero.java index eff18f125..9144436e5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankHero.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankHero.java @@ -1,14 +1,39 @@ package mineplex.core.gadget.gadgets.wineffect.rankrooms.rankwineffects; -import org.bukkit.Bukkit; +import java.util.Set; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEnderDragon; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.FallingBlock; +import org.bukkit.event.EventHandler; +import org.bukkit.util.Vector; + +import mineplex.core.common.MaterialData; import mineplex.core.common.Rank; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.wineffect.rankrooms.WinEffectRankBased; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; public class WinEffectRankHero extends WinEffectRankBased { + private DisguisePlayer _npc; + private EnderDragon _enderDragon = null; + private int _step = 0; + + private static final int POINTS = 100; + private static final float RADIUS = 15F; + private static final int BLOCK_RADIUS = 5; + public WinEffectRankHero(GadgetManager manager) { super(manager, Rank.HERO, WinEffectType.RANK_WIN_EFFECT); @@ -17,13 +42,82 @@ public class WinEffectRankHero extends WinEffectRankBased @Override public void play() { - Bukkit.broadcastMessage("Playing effect win effect hero: " + getName()); + Location loc = getBaseLocation(); + + loc.setDirection(_player.getLocation().subtract(loc).toVector().multiply(-1)); + + _npc = getNPC(getPlayer(), loc, true); } @Override public void finish() { - Bukkit.broadcastMessage("Playing effect win effect hero: " + getName()); + if (_enderDragon != null) + { + _enderDragon.remove(); + _enderDragon = null; + } + _step = 0; + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!isRunning()) + return; + + if (_step > 70) + return; + + if (_step == 70) + { + breakBlocks(); + } + + if (event.getType() != UpdateType.FASTEST) + return; + + Location npcLocation = _npc.getEntity().getBukkitEntity().getLocation(); + + if (_enderDragon == null) + { + _enderDragon = npcLocation.getWorld().spawn(npcLocation.add(0, 20, 0), EnderDragon.class); + } + + double increment = (2 * Math.PI) / POINTS; + + double angle = _step * increment; + Vector vector = new Vector(Math.cos(angle) * RADIUS, 0, Math.sin(angle) * RADIUS); + _enderDragon.setVelocity(new Vector(0,0,0)); + _enderDragon.teleport(_player.getLocation().clone().add(vector)); + Vector direction = npcLocation.toVector().subtract(_enderDragon.getEyeLocation().toVector()).multiply(-1); + Location enderLocation = _enderDragon.getLocation().setDirection(direction); + _enderDragon.teleport(enderLocation); + + _step++; + + if (_step >= 50) + setTarget(); + } + + private void setTarget() + { + ((CraftEnderDragon) _enderDragon).getHandle().setTargetBlock(_baseLocation.getBlockX(), _baseLocation.getBlockY(), _baseLocation.getBlockZ()); + } + + private void breakBlocks() + { + Set blocks = UtilBlock.getBlocksInRadius(_baseLocation.add(0, 1, 0), BLOCK_RADIUS, BLOCK_RADIUS); + for (Block block : blocks) + { + MaterialData materialData = MaterialData.of(block.getType(), block.getData()); + block.setType(Material.AIR); + FallingBlock fallingBlock = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), materialData.getMaterial(), materialData.getData()); + fallingBlock.setDropItem(false); + UtilAction.velocity(fallingBlock, UtilAlg.getTrajectory(fallingBlock.getLocation(), _npc.getEntity().getBukkitEntity().getLocation()).multiply(-1), .75, true, 0.8, 0, 1.0, true); + } + ArmorStand armorStand = (ArmorStand) _npc.getEntity().getBukkitEntity(); + armorStand.setHealth(0); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankLegend.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankLegend.java index bf15f89a3..d1ba4afbd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankLegend.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankLegend.java @@ -1,14 +1,39 @@ package mineplex.core.gadget.gadgets.wineffect.rankrooms.rankwineffects; -import org.bukkit.Bukkit; +import java.util.Set; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Wither; +import org.bukkit.entity.WitherSkull; +import org.bukkit.event.EventHandler; +import org.bukkit.util.Vector; + +import mineplex.core.common.MaterialData; import mineplex.core.common.Rank; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.wineffect.rankrooms.WinEffectRankBased; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; public class WinEffectRankLegend extends WinEffectRankBased { + private DisguisePlayer _npc; + private Wither _wither = null; + private int _step = 0; + + private static final int POINTS = 100; + private static final float RADIUS = 15F; + private static final int BLOCK_RADIUS = 5; + public WinEffectRankLegend(GadgetManager manager) { super(manager, Rank.LEGEND, WinEffectType.RANK_WIN_EFFECT); @@ -17,13 +42,80 @@ public class WinEffectRankLegend extends WinEffectRankBased @Override public void play() { - Bukkit.broadcastMessage("Playing effect win effect legend: " + getName()); + Location loc = getBaseLocation(); + + loc.setDirection(_player.getLocation().subtract(loc).toVector().multiply(-1)); + + _npc = getNPC(getPlayer(), loc, true); } @Override public void finish() { - Bukkit.broadcastMessage("Playing effect win effect legend: " + getName()); + if (_wither != null) + { + _wither.remove(); + _wither = null; + } + _step = 0; + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!isRunning()) + return; + + if (event.getType() != UpdateType.FASTEST) + return; + + Location npcLocation = _npc.getEntity().getBukkitEntity().getLocation(); + + if (_wither == null) + { + _wither = npcLocation.getWorld().spawn(npcLocation.add(0, 20, 0), Wither.class); + } + + double increment = (2 * Math.PI) / POINTS; + + double angle = _step * increment; + Vector vector = new Vector(Math.cos(angle) * RADIUS, 0, Math.sin(angle) * RADIUS); + _wither.setVelocity(new Vector(0,0,0)); + _wither.teleport(_player.getLocation().clone().add(vector)); + Vector direction = npcLocation.toVector().subtract(_wither.getEyeLocation().toVector()); + Location enderLocation = _wither.getLocation().setDirection(direction); + _wither.teleport(enderLocation); + + _step++; + + if (_step % 5 == 0) + spawnSkull(); + + if (_step == 40) + breakBlocks(); + } + + private void spawnSkull() + { + if (_wither != null) + { + _wither.launchProjectile(WitherSkull.class); + } + } + + private void breakBlocks() + { + Set blocks = UtilBlock.getBlocksInRadius(_npc.getEntity().getBukkitEntity().getLocation(), BLOCK_RADIUS, BLOCK_RADIUS); + for (Block block : blocks) + { + MaterialData materialData = MaterialData.of(block.getType(), block.getData()); + block.setType(Material.AIR); + FallingBlock fallingBlock = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), materialData.getMaterial(), materialData.getData()); + fallingBlock.setDropItem(false); + UtilAction.velocity(fallingBlock, UtilAlg.getTrajectory(fallingBlock.getLocation(), _npc.getEntity().getBukkitEntity().getLocation()).multiply(-1), .75, true, 0.8, 0, 1.0, true); + } + ArmorStand armorStand = (ArmorStand) _npc.getEntity().getBukkitEntity(); + armorStand.setHealth(0); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankTitan.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankTitan.java index 607dc9b39..8526e8df5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankTitan.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankTitan.java @@ -1,14 +1,33 @@ package mineplex.core.gadget.gadgets.wineffect.rankrooms.rankwineffects; -import org.bukkit.Bukkit; +import java.util.Set; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Giant; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; + +import mineplex.core.common.MaterialData; import mineplex.core.common.Rank; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.wineffect.rankrooms.WinEffectRankBased; public class WinEffectRankTitan extends WinEffectRankBased { + private DisguisePlayer _npc; + private Giant _giant = null; + + private static final int RADIUS = 5; + public WinEffectRankTitan(GadgetManager manager) { super(manager, Rank.TITAN, WinEffectType.RANK_WIN_EFFECT); @@ -17,13 +36,48 @@ public class WinEffectRankTitan extends WinEffectRankBased @Override public void play() { - Bukkit.broadcastMessage("Playing effect win effect titan: " + getName()); + Location loc = getBaseLocation(); + + loc.setDirection(_player.getLocation().subtract(loc).toVector().multiply(-1)); + + _npc = getNPC(getPlayer(), loc); + + _giant = loc.getWorld().spawn(loc.add(0, 20, 0), Giant.class); } @Override public void finish() { - Bukkit.broadcastMessage("Playing effect win effect titan: " + getName()); + if (_giant != null) + { + _giant.remove(); + _giant = null; + } + } + + @EventHandler + public void onGiantFall(EntityDamageEvent event) + { + if (_giant == null) + return; + + if (event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) + { + if (event.getEntity().equals(_giant)) + { + Set blocks = UtilBlock.getBlocksInRadius(_npc.getEntity().getBukkitEntity().getLocation(), RADIUS, RADIUS); + for (Block block : blocks) + { + MaterialData materialData = MaterialData.of(block.getType(), block.getData()); + block.setType(Material.AIR); + FallingBlock fallingBlock = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), materialData.getMaterial(), materialData.getData()); + fallingBlock.setDropItem(false); + UtilAction.velocity(fallingBlock, UtilAlg.getTrajectory(fallingBlock.getLocation(), _npc.getEntity().getBukkitEntity().getLocation()).multiply(-1), .75, true, 0.8, 0, 1.0, true); + } + ArmorStand armorStand = (ArmorStand) _npc.getEntity().getBukkitEntity(); + armorStand.setHealth(0); + } + } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankUltra.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankUltra.java index 0badbde6f..dc3ccc130 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankUltra.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/rankrooms/rankwineffects/WinEffectRankUltra.java @@ -5,10 +5,10 @@ import java.util.Set; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Creeper; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityExplodeEvent; @@ -17,7 +17,6 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilServer; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.wineffect.rankrooms.WinEffectRankBased; @@ -43,16 +42,11 @@ public class WinEffectRankUltra extends WinEffectRankBased loc.setDirection(_player.getLocation().subtract(loc).toVector().multiply(-1)); loc.setPitch(0); loc.setYaw(0); - _npc = getNPC(getPlayer(), loc); + _npc = getNPC(getPlayer(), loc, true); _creeper = loc.getWorld().spawn(loc.add(loc.getDirection().multiply(-3)), Creeper.class); _creeper.setPowered(true); _creeper.setTarget((LivingEntity) _npc.getEntity().getBukkitEntity()); - - for (Player player : UtilServer.getPlayers()) - { - player.teleport(_npc.getEntity().getBukkitEntity()); - } } @Override @@ -76,6 +70,8 @@ public class WinEffectRankUltra extends WinEffectRankBased fallingBlock.setDropItem(false); UtilAction.velocity(fallingBlock, UtilAlg.getTrajectory(fallingBlock.getLocation(), _npc.getEntity().getBukkitEntity().getLocation()).multiply(-1), .75, true, 0.8, 0, 1.0, true); } + ArmorStand armorStand = (ArmorStand) _npc.getEntity().getBukkitEntity(); + armorStand.setHealth(0); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java index 4a3fb08a1..8edce5e2d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java @@ -339,6 +339,28 @@ public abstract class WinEffectGadget extends Gadget Manager.getDisguiseManager().disguise(disguise); return disguise; } + + /** + * Get a disguised ArmorStand with the skin of the provided player at the provided location. The ArmorStand got 2048 health. + * @param player The player to create the disguise from + * @param loc The location to spawn the ArmorStand at + * @param gravity true if the armorstand should have gravity + * @return Returns a disguised ArmorStand at the given location + */ + public DisguisePlayer getNPC(Player player, Location loc, boolean gravity) { + ArmorStand stand = loc.getWorld().spawn(loc, ArmorStand.class); + + stand.setMaxHealth(2048); + stand.setHealth(2048); + stand.setGravity(gravity); + + GameProfile profile = new GameProfile(UUID.randomUUID(), player.getName()); + profile.getProperties().putAll(((CraftPlayer) player).getHandle().getProfile().getProperties()); + + DisguisePlayer disguise = new DisguisePlayer(stand, profile); + Manager.getDisguiseManager().disguise(disguise); + return disguise; + } /** * Paste a schematic relative to the base location