Skip to content

Commit

Permalink
More formatting
Browse files Browse the repository at this point in the history
For the good of newlineumanity!
  • Loading branch information
mcmonkey4eva committed Sep 3, 2013
1 parent 2accd5f commit c0d5792
Show file tree
Hide file tree
Showing 36 changed files with 334 additions and 335 deletions.
Expand Up @@ -33,184 +33,184 @@
*/

public class FlyCommand extends AbstractCommand {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

// Initialize necessary fields

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("cancel")
&& arg.matches("cancel")) {

scriptEntry.addObject("cancel", "");
}

else if (!scriptEntry.hasObject("destinations")
&& arg.matchesPrefix("destination, destinations, d")) {
// Entity arg
scriptEntry.addObject("destinations", ((dList) arg.asType(dList.class)).filter(dLocation.class));
}

else if (!scriptEntry.hasObject("origin")
&& arg.matchesArgumentType(dLocation.class)) {
// Location arg
scriptEntry.addObject("origin", arg.asType(dLocation.class).setPrefix("origin"));
}

else if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentList(dEntity.class)) {
// Entity arg
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else if (!scriptEntry.hasObject("speed")
&& arg.matchesPrimitive(aH.PrimitiveType.Double)) {
// Add value
scriptEntry.addObject("speed", arg.asElement());
}
}

// Use the NPC or player's locations as the location if one is not specified

scriptEntry.defaultObject("origin",
scriptEntry.hasPlayer() ? scriptEntry.getPlayer().getLocation() : null,
scriptEntry.hasNPC() ? scriptEntry.getNPC().getLocation() : null);

// Use a default speed of 1.2 if one is not specified

scriptEntry.defaultObject("speed", new Element(1.2));

// Check to make sure required arguments have been filled

if (!scriptEntry.hasObject("entities"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ENTITIES");
if (!scriptEntry.hasObject("origin"))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ORIGIN");
}

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects

dLocation origin = (dLocation) scriptEntry.getObject("origin");
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
final List<dLocation> destinations = scriptEntry.hasObject("destinations") ?
(List<dLocation>) scriptEntry.getObject("destinations") :
new ArrayList<dLocation>();

final Element speed = (Element) scriptEntry.getObject("speed");
Boolean cancel = scriptEntry.hasObject("cancel");

// Report to dB
dB.report(getName(), (cancel == true ? aH.debugObj("cancel", cancel) : "") +
aH.debugObj("origin", origin) +
aH.debugObj("entities", entities.toString()) +
aH.debugObj("speed", speed) +
(destinations.size() > 0 ? aH.debugObj("destinations", destinations.toString()) : ""));

// Mount or dismount all of the entities
if (cancel.equals(false)) {

// Go through all the entities, spawning/teleporting them
for (dEntity entity : entities) {

if (!entity.isSpawned()) {
entity.spawnAt(origin);
}
else {
entity.teleport(origin);
}
}

Position.mount(Conversion.convert(entities));
}
else {
Position.dismount(Conversion.convert(entities));

// Go no further if we are dismounting entities
return;

}

// Get the last entity on the list
final Entity entity = entities.get(entities.size() - 1).getBukkitEntity();

// Get the attached player
final Player player = scriptEntry.getPlayer().getPlayerEntity();

// Set freeflight to true only if there are no destinations
final boolean freeflight = destinations.size() > 0;

BukkitRunnable task = new BukkitRunnable() {

Location location = null;
Boolean flying = true;

public void run() {

if (freeflight) {

location = player.getEyeLocation()
.add(player.getEyeLocation().getDirection()
.multiply(30));
}
else {

// If freelight is not on, keep flying only as long
// as there are destinations left

if (destinations.size() > 0) {

location = destinations.get(0);
}
else {

flying = false;
}
}

if (flying &&
entity.isValid() &&
(!entity.isEmpty())) {

// To avoid excessive turbulence, only have the entity rotate
// when it really needs to
if (!Rotation.isFacingLocation(entity, location, 50)) {

Rotation.faceLocation(entity, location);
}

Vector v1 = entity.getLocation().toVector();
Vector v2 = location.toVector();
Vector v3 = v2.clone().subtract(v1).normalize().multiply(speed.asDouble());

entity.setVelocity(v3);

// If freeflight is off, check if the entity has reached its
// destination, and remove the destination if that happens
// to be the case

if (!freeflight) {

if (Math.abs(v2.getX() - v1.getX()) < 2 && Math.abs(v2.getY() - v1.getY()) < 2
&& Math.abs(v2.getZ() - v1.getZ()) < 2) {

destinations.remove(0);
}
}
}
else {

flying = false;
this.cancel();
}
}
};
task.runTaskTimer(denizen, 0, 3);

task.runTaskTimer(denizen, 0, 3);
}

}
}
Expand Up @@ -26,33 +26,33 @@
public class HeadCommand extends AbstractCommand {

private enum TargetType { NPC, PLAYER }

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

TargetType targetType = TargetType.NPC;
Integer duration = null;
String skin = null;

for (String arg : scriptEntry.getArguments()) {
// If argument is a duration
if (aH.matchesDuration(arg)) {
duration = aH.getIntegerFrom(arg);
dB.echoDebug("...head duration set to '%s'.", arg);
}

else if (aH.matchesArg("PLAYER", arg)) {
targetType = TargetType.PLAYER;
dB.echoDebug("...will affect the player!");
}

else if (aH.matchesValueArg("skin", arg, ArgumentType.String)) {
skin = aH.getStringFrom(arg);
dB.echoDebug("...will have " + skin + "'s head");

} else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}

// If TARGET is NPC/PLAYER and no NPC/PLAYER available, throw exception.
if (targetType == TargetType.PLAYER && scriptEntry.getPlayer() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_PLAYER);
else if (targetType == TargetType.NPC && scriptEntry.getNPC() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
Expand All @@ -63,19 +63,19 @@ else if (aH.matchesValueArg("skin", arg, ArgumentType.String)) {

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

TargetType target = (TargetType) scriptEntry.getObject("target");
String skin = (String) scriptEntry.getObject("skin");

// Create head item with chosen skin
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ItemMeta itemMeta = item.getItemMeta();
((SkullMeta) itemMeta).setOwner(skin);
item.setItemMeta(itemMeta);

if (target.name().equals("NPC")) {
NPC npc = scriptEntry.getNPC().getCitizen();

if (!npc.hasTrait(Equipment.class)) npc.addTrait(Equipment.class);
Equipment trait = npc.getTrait(Equipment.class);
trait.set(1, item);
Expand All @@ -87,4 +87,4 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

}

}
}
Expand Up @@ -85,4 +85,4 @@ else if (action.asString().equalsIgnoreCase("false"))
}


}
}
Expand Up @@ -88,14 +88,14 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
break;

case PLAYER:

if (scriptEntry.getPlayer() != null) {

Player player = scriptEntry.getPlayer().getPlayerEntity();
PotionEffect invis = new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1);

switch (action) {

case FALSE:
player.removePotionEffect(PotionEffectType.INVISIBILITY);
break;
Expand All @@ -107,7 +107,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
case TOGGLE:
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
player.removePotionEffect(PotionEffectType.INVISIBILITY);
else
else
invis.apply(player);

break;
Expand All @@ -116,4 +116,4 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
}

}
}
}

0 comments on commit c0d5792

Please sign in to comment.