From dd44b982f9e46fc2d4b45d8b1ae024c7e9611b85 Mon Sep 17 00:00:00 2001 From: Chiss Date: Sat, 31 Aug 2013 19:51:59 +1000 Subject: [PATCH] Added hub dragon --- .../Mineplex.Hub/src/mineplex/hub/Dragon.java | 181 ++++++++++++++++++ .../src/mineplex/hub/HubManager.java | 8 + 2 files changed, 189 insertions(+) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/Dragon.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Dragon.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Dragon.java new file mode 100644 index 000000000..2e459c940 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Dragon.java @@ -0,0 +1,181 @@ +package mineplex.hub; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.EnderDragon; +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +import org.bukkit.util.Vector; + +public class Dragon extends MiniPlugin +{ + HubManager Manager; + + public EnderDragon Dragon = null; + + public Entity TargetEntity = null; + + public Location Target = null; + public Location Location = null; + + public float Pitch = 0; + public Vector Velocity = new Vector(0,0,0); + + public double RangeBest = 1000; + public long RangeTime = 0; + + public Dragon(HubManager manager) + { + super("Dragon Manager", manager.GetPlugin()); + + Manager = manager; + } + + public void Spawn() + { + if (Dragon != null) + Dragon.remove(); + + if (!Manager.GetSpawn().getWorld().isChunkLoaded(Manager.GetSpawn().getChunk())) + { + return; + } + + Dragon = Manager.GetSpawn().getWorld().spawn(Manager.GetSpawn().add(0, 50, 0), EnderDragon.class); + UtilEnt.Vegetate(Dragon); + + Dragon.setCustomName(C.cGreen + C.Bold + "The Mineplex Dragon"); + + Velocity = Dragon.getLocation().getDirection().setY(0).normalize(); + Pitch = UtilAlg.GetPitch(Dragon.getLocation().getDirection()); + + Location = Dragon.getLocation(); + + TargetSky(); + } + + @EventHandler + public void MoveUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + if (Dragon == null || !Dragon.isValid()) + { + Spawn(); + return; + } + + Turn(); + + Location.add(Velocity); + Location.add(0, -Pitch, 0); + + Location.setPitch(-1 * Pitch); + Location.setYaw(180 + UtilAlg.GetYaw(Velocity)); + + Dragon.teleport(Location); + } + + @EventHandler + public void ColorEvent(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST) + return; + + if (Dragon == null || !Dragon.isValid()) + return; + + ChatColor color = ChatColor.RED; + double r = Math.random(); + if (r > 0.83) color = ChatColor.GOLD; + else if (r > 0.66) color = ChatColor.YELLOW; + else if (r > 0.49) color = ChatColor.GREEN; + else if (r > 0.32) color = ChatColor.AQUA; + else if (r > 0.16) color = ChatColor.LIGHT_PURPLE; + + Dragon.setCustomName(color + C.Bold + "Welcome to Mineplex - Home of the highest quality Minecraft Plugins"); + } + + private void Turn() + { + //Pitch + float desiredPitch = UtilAlg.GetPitch(UtilAlg.getTrajectory(Location, Target)); + if (desiredPitch < Pitch) Pitch = (float)(Pitch - 0.05); + if (desiredPitch > Pitch) Pitch = (float)(Pitch + 0.05); + if (Pitch > 0.5) Pitch = 0.5f; + if (Pitch < -0.5) Pitch = -0.5f; + + //Flat + Vector desired = UtilAlg.getTrajectory2d(Location, Target); + desired.subtract(UtilAlg.Normalize(new Vector(Velocity.getX(), 0, Velocity.getZ()))); + desired.multiply(0.075); + + Velocity.add(desired); + + //Speed + UtilAlg.Normalize(Velocity); + } + + public void Target() + { + if (TargetEntity != null) + { + if (!TargetEntity.isValid()) + { + TargetEntity = null; + } + else + { + Target = TargetEntity.getLocation().subtract(0, 8, 0); + } + + return; + } + + if (Target == null) + { + TargetSky(); + } + + if (UtilMath.offset(Location, Target) < 10) + { + TargetSky(); + } + + TargetTimeout(); + } + + public void TargetTimeout() + { + if (UtilMath.offset(Location, Target)+1 < RangeBest) + { + RangeTime = System.currentTimeMillis(); + RangeBest = UtilMath.offset(Location, Target); + } + else + { + if (UtilTime.elapsed(RangeTime, 10000)) + { + TargetSky(); + } + } + } + + public void TargetSky() + { + RangeBest = 9000; + RangeTime = System.currentTimeMillis(); + + Target = Manager.GetSpawn().add(100 - UtilMath.r(200), 50 + UtilMath.r(50), 100 - UtilMath.r(200)); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index a25a1b790..8591cb8a7 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -23,6 +23,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerDropItemEvent; @@ -79,6 +80,7 @@ public class HubManager extends MiniClientPlugin _spawn = new Location(UtilWorld.getWorld("world"), 0.5, 74, 0.5); new TextCreator(this); + new Dragon(this); } @EventHandler @@ -520,4 +522,10 @@ public class HubManager extends MiniClientPlugin else if (r > 0.25) _mobs.add(loc.getWorld().spawn(loc, Sheep.class)); else _mobs.add(loc.getWorld().spawn(loc, Chicken.class)); } + + @EventHandler(priority = EventPriority.LOWEST) + public void Explosion(EntityExplodeEvent event) + { + event.blockList().clear(); + } }