Merge branch 'master' of ssh://dev1.mineplex.com:7999/min/master

This commit is contained in:
Jonathan Williams 2013-08-31 02:57:12 -07:00
commit 2174c958d9
2 changed files with 189 additions and 0 deletions

View File

@ -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));
}
}

View File

@ -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<HubClient>
_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<HubClient>
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();
}
}