Skip to content

Commit

Permalink
Resolve most theological disputes between the Denizen of the East and…
Browse files Browse the repository at this point in the history
… the Denizen of the West.
  • Loading branch information
davidcernat committed Jun 25, 2013
1 parent 7e4a084 commit 5b736f5
Show file tree
Hide file tree
Showing 27 changed files with 1,490 additions and 424 deletions.
Expand Up @@ -100,17 +100,20 @@ public void registerCoreMembers() {
"ENGAGE", "engage (duration:#) (npcid:#)", 0);

registerCoreMember(EngraveCommand.class,
"ENGRAVE", "engrave (SET|REMOVE) (TARGET:player_name)", 0);
"ENGRAVE", "engrave (set|remove) (target:player_name)", 0);

registerCoreMember(EquipCommand.class,
"EQUIP", "equip ({HAND}|BOOTS|LEGS|CHEST|HEAD) [item:#(:#)|item:material(:#)]", 1);
"EQUIP", "equip (hand:[#|material](:#)) (head:[#|material](:#)) (chest:[#|material](:#)) (legs:[#|material](:#)) (boots:[#|material](:#))", 1);

registerCoreMember(ExecuteCommand.class,
"EXECUTE", "execute [as_player|as_op|as_npc|as_server] [\"Bukkit command\"]", 2);

registerCoreMember(ExperienceCommand.class,
"EXPERIENCE", "experience [{set}|give|take] (level) [#] (player:player_name)", 2);

registerCoreMember(ExplodeCommand.class,
"EXPLODE", "explode (power:#) (location:x,y,z,world) (fire) (breakblocks)", 0);

registerCoreMember(FailCommand.class,
"FAIL", "fail (script:name{attached script}) (player:player_name)", 0);

Expand All @@ -120,27 +123,42 @@ public void registerCoreMembers() {
registerCoreMember(FinishCommand.class,
"FINISH", "finish (script:name{attached script}) (player:player_name)", 0);

registerCoreMember(FireworkCommand.class,
"FIREWORK", "firework (location:x,y,z,world) (power:#) (type:name|random) (primary:color1|color2|...) (fade:color1|color2|...) (flicker) (trail)", 0);

registerCoreMember(FishCommand.class,
"FISH", "fish (catchfish) (stop) (location:x,y,z,world)", 1);
"FISH", "fish (catchfish) (stop) (location:x,y,z,world) (catchpercent:#{65})", 1);

registerCoreMember(FlagCommand.class,
"FLAG", "flag ({player}|npc|global) [name([#])](:action)[:value] (duration:#)", 1);

registerCoreMember(FlyCommand.class,
"FLY", "fly [entities:e@name|...] (origin:x,y,z,world) (destination(s):x,y,z,world|...)", 1);

registerCoreMember(FollowCommand.class,
"FOLLOW", "follow (stop)", 0);

registerCoreMember(ForEachCommand.class,
"FOREACH", "foreach [location:x,y,z,world|x,y,z,world] ['script_to_run']", 0);

registerCoreMember(GiveCommand.class,
"GIVE", "give [money|item:#(:#)|item:material(:#)] (qty:#) (engrave)", 1);

registerCoreMember(GroupCommand.class,
"GROUP", "group [add|remove] [group] (player:player_name) (world:world_name)", 2);

registerCoreMember(HeadCommand.class,
"HEAD", "head (player) [skin:name]", 0);

registerCoreMember(HealCommand.class,
"HEAL", "heal (amt:#) (target:npc|{player})", 0);

registerCoreMember(HealthCommand.class,
"HEALTH", "health (toggle:true|false|toggle) (set_max:#)", 1);

registerCoreMember(HurtCommand.class,
"HURT", "hurt (amt:#) (target:npc|{player})", 0);

registerCoreMember(IfCommand.class,
"IF", "if [comparable] (!)(operator) (compared_to) (bridge) (...) [command] (else) (command) +--> see documentation.", 2);

Expand All @@ -150,38 +168,53 @@ public void registerCoreMembers() {
registerCoreMember(ListenCommand.class,
"LISTEN", "listen [listener_type] [id:listener_id] (...) +--> see documentation - http://bit.ly/XJlKwm", 2);

registerCoreMember(LogCommand.class,
"LOG", "log [\"message\"] (type:severe|info|warning|fine|finer|finest) [file:filename]", 2);

registerCoreMember(LookCommand.class,
"LOOK", "look (player) [location:x,y,z,world]", 1);

registerCoreMember(LookcloseCommand.class,
"LOOKCLOSE", "lookclose [toggle:true|false]", 1);

registerCoreMember(MidiCommand.class,
"MIDI", "midi [file:<name>] (listener(s):[p@<name>|...])|(location:<x,y,z,world>) (tempo:<#.#>)", 1);

registerCoreMember(MountCommand.class,
"MOUNT", "mount (cancel) (location:<x,y,z,world>) (target(s):[n@#]|[p@name]|[e@name])", 0);

registerCoreMember(ModifyBlockCommand.class,
"MODIFYBLOCK", "modifyblock [location:x,y,z,world] [material:data] (radius:#) (height:#) (depth:#)", 2);
"MODIFYBLOCK", "modifyblock [location:<x,y,z,world>] [<material>(:<data>)] (radius:<#>) (height:<#>) (depth:<#>)", 2);

registerCoreMember(NameplateCommand.class,
"NAMEPLATE", "nameplate [set:text|chat_color] (target:player_name)", 1);
"NAMEPLATE", "nameplate [set:text|chat_color] (target:<name>)", 1);

registerCoreMember(NarrateCommand.class,
"NARRATE", "narrate [\"narration text\"] (player:name) (format:format)", 1);
"NARRATE", "narrate [\"narration text\"] (target(s):p@<name>|...) (format:<name>)", 1);

registerCoreMember(NewCommand.class,
"NEW", "new itemstack [item:material] (qty:#)", 2);
"NEW", "new itemstack [item:<material>] (qty:<#>)", 2);

registerCoreMember(OxygenCommand.class,
"OXYGEN", "oxygen (type:maximum|remaining) (mode:set|add|remove) [qty:<#>]", 1);

registerCoreMember(PlayEffectCommand.class,
"PLAYEFFECT", "playeffect [location:<x,y,z,world>] [effect:<name>] (volume:<#>) (pitch:<#>)", 2);

registerCoreMember(PlaySoundCommand.class,
"PLAYSOUND", "playsound [location:x,y,z,world] [sound:name] (volume:#) (pitch:#)", 2);
"PLAYSOUND", "playsound [location:<x,y,z,world>] [sound:<name>] (volume:<#>) (pitch:<#>)", 2);

registerCoreMember(PermissionCommand.class,
"PERMISSION", "permission [add|remove] [permission] (player:player_name) (group:group_name) (world:world_name)", 2);
"PERMISSION", "permission [add|remove] [permission] (player:<name>) (group:<name>) (world:<name>)", 2);

registerCoreMember(PoseCommand.class,
"POSE", "pose (player) [id:name]", 1);
"POSE", "pose (player) [id:<name>]", 1);

registerCoreMember(PauseCommand.class,
"PAUSE", "pause [waypoints|navigation]", 1);

registerCoreMember(QueueCommand.class,
"QUEUE", "queue (queue:id{residing_queue}) [clear|pause|resume|delay:#]", 1);
"QUEUE", "queue (queue:<id>{<residing_queue>}) [clear|pause|resume|delay:<#>]", 1);

registerCoreMember(RandomCommand.class,
"RANDOM", "random [#]", 1);
Expand All @@ -202,11 +235,14 @@ public void registerCoreMembers() {
"SCRIBE", "scribe [script:book_script] (give|{drop}|equip) (location:x,y,z,world) OR scribe [item:id.name] [script:book_script]", 1);

registerCoreMember(ShootCommand.class,
"SHOOT", "shoot [entity:name] (ride) (burn) (explosion:#) (location:x,y,z,world) (script:name)", 1);
"SHOOT", "shoot (player) [entity:name] (ride) (burn) (location:x,y,z,world) (script:name)", 1);

registerCoreMember(SitCommand.class,
"SIT", "sit (location:x,y,z,world)", 0);

registerCoreMember(SpawnCommand.class,
"SPAWN", "spawn [entity:name] (location:x,y,z,world) (target:[n@#]|[p@name])", 1);

registerCoreMember(StandCommand.class,
"STAND", "stand", 0);

Expand All @@ -220,7 +256,7 @@ public void registerCoreMembers() {
"TAKE", "take [money|iteminhand|item:#(:#)|item:material(:#)] (qty:#)", 1);

registerCoreMember(TeleportCommand.class,
"TELEPORT", "teleport (npc) [location:x,y,z,world] (target(s):[npc.#]|[player.name])", 1);
"TELEPORT", "teleport (npc) [location:x,y,z,world] (target(s):[n@#]|[p@name])", 1);

registerCoreMember(TriggerCommand.class,
"TRIGGER", "trigger [name:trigger_name] [(toggle:true|false)|(cooldown:#.#)|(radius:#)]", 2);
Expand Down
@@ -0,0 +1,118 @@
package net.aufdemrand.denizen.scripts.commands.core;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.ScriptQueue;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.scripts.containers.core.TaskScriptContainer;
import net.aufdemrand.denizen.utilities.debugging.dB;

import java.util.HashMap;
import java.util.Map;

/**
* @author aufdemrand
*
*/
public class ForEachCommand extends AbstractCommand {

// - foreach location:0,0,0,world|3,3,3,world 'fill_it'

enum Type {LOCATION, LIST_ITEM}

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

Type type = null;
dScript script = null;
dLocation location_1 = null;
dLocation location_2 = null;

// Parse Arguments
for (String arg : scriptEntry.getArguments()) {

if (aH.matchesValueArg("LOCATION, ITEM_IN_LIST", arg, aH.ArgumentType.Custom)) {
type = Type.valueOf(arg.split(":")[0].toUpperCase());

if (type == Type.LOCATION) {
location_1 = dLocation.valueOf(aH.getStringFrom(arg).split("\\|")[0]);
location_2 = dLocation.valueOf(aH.getStringFrom(arg).split("\\|")[1]);
}
}

else {
if (ScriptRegistry.containsScript(aH.getStringFrom(arg), TaskScriptContainer.class))
script = aH.getScriptFrom(arg);
else dB.echoError("'" + aH.getStringFrom(arg) + "' is not valid! Must specify a TASK-type script.");
}
}

if (type == null) throw new InvalidArgumentsException("Must specify a 'foreach' type!");

if (type == Type.LOCATION && (location_1 == null || location_2 == null))
throw new InvalidArgumentsException("Invalid locations have been specified!");

scriptEntry.addObject("loc_1", location_1)
.addObject("loc_2", location_2)
.addObject("type", type)
.addObject("script", script);

}

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

// Get objects
Type type = (Type) scriptEntry.getObject("type");
dLocation loc_1 = (dLocation) scriptEntry.getObject("loc_1");
dLocation loc_2 = (dLocation) scriptEntry.getObject("loc_2");
dScript script = (dScript) scriptEntry.getObject("script");

// Report to dB
dB.report(getName(),
aH.debugObj("Type", type.toString())
+ (type == Type.LOCATION ? loc_1.debug() + loc_2.debug() : "")
+ script.debug());

if (type == Type.LOCATION) {

int x_inc = -1;
int y_inc = -1;
int z_inc = -1;

if (loc_1.getBlockX() <= loc_2.getBlockX()) x_inc = 1;
if (loc_1.getBlockY() <= loc_2.getBlockY()) y_inc = 1;
if (loc_1.getBlockZ() <= loc_2.getBlockZ()) z_inc = 1;

int x_amt = Math.abs(loc_1.getBlockX() - loc_2.getBlockX());
int y_amt = Math.abs(loc_1.getBlockY() - loc_2.getBlockY());
int z_amt = Math.abs(loc_1.getBlockZ() - loc_2.getBlockZ());

for (int x = 0; x != x_amt + 1; x++) {
for (int y = 0; y != y_amt + 1; y++) {
for (int z = 0; z != z_amt + 1; z++) {
dLocation loc = new dLocation(loc_1.clone().add((double) x * x_inc, (double) y * y_inc, (double) z * z_inc));

dB.echoDebug("location: " + loc.identify());

Map<String, String> context = new HashMap<String, String>();
context.put("1", loc.identify());

((TaskScriptContainer) script.getContainer()).setSpeed(Duration.valueOf("0"))
.runTaskScript(ScriptQueue._getNextId(),
scriptEntry.getPlayer(),
scriptEntry.getNPC(),
context);
}
}
}
}
}

}
@@ -0,0 +1,113 @@
package net.aufdemrand.denizen.scripts.commands.core;

import java.io.File;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.DebugLog;
import net.aufdemrand.denizen.utilities.debugging.dB;

/**
* Lets script authors create their own debug logs to check Denizen actions.
* Useful for scripts that sometimes need checking the actions.
*
* <b>Logs are getting stored inside the <code>denizen/log</code> folder.</b>
*
* Usage: <code>log "message" (type:severe|info|warning|fine|finer|finest) [file:filename]</code>
*
* @author spaceemotion
*/
public class LogCommand extends AbstractCommand {
protected static File logDirectory;
public enum Type { SEVERE, INFO, WARNING, FINE, FINER, FINEST };

public LogCommand() {
if(logDirectory == null) return;

logDirectory = new File(DenizenAPI.getCurrentInstance().getDataFolder(), "logs");
logDirectory.mkdirs();
}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
String message = null, fileName = "";
Type type = Type.INFO;

if(scriptEntry.getArguments().size() < 2) {
throw new InvalidArgumentsException("Needs at least 2 arguments (message and file)!");
}

for(String arg : scriptEntry.getArguments()) {
if(aH.matchesValueArg("type", arg, aH.ArgumentType.String)) {
try {
type = Type.valueOf(aH.getStringFrom(arg));
dB.echoDebug("Set type to " + type.name() + "!");
} catch(Exception e) {
dB.echoError("Invalid type: " + e.getMessage());
}
} else if(aH.matchesValueArg("file", arg, aH.ArgumentType.String)) {
fileName = aH.getStringFrom(arg);
dB.echoDebug("Appending to '" + fileName + "' log file");
} else {
message = arg;
}
}

if(message == null)
throw new InvalidArgumentsException("Must specify a message.");

if(fileName.isEmpty())
throw new InvalidArgumentsException("Must specify a file.");

File file = new File(logDirectory, fileName);
DebugLog log = new DebugLog("Denizen-ScriptLog-" + fileName, file.getAbsolutePath());

scriptEntry.addObject("message", message);
scriptEntry.addObject("name", fileName); // Just for debugging
scriptEntry.addObject("type", type);
scriptEntry.addObject("log", log);
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
String message = (String) scriptEntry.getObject("message");
String fileName = (String) scriptEntry.getObject("name");
Type type = (Type) scriptEntry.getObject("type");
DebugLog log = (DebugLog) scriptEntry.getObject("log");

dB.report(getName(),
aH.debugObj("Type", type) + aH.debugObj("Filename", fileName)
+ aH.debugObj("Message", message));

switch(type) {
case SEVERE:
log.severe(message);
break;

case INFO:
log.info(message);
break;

case WARNING:
log.warning(message);
break;

case FINE:
log.fine(message);
break;

case FINER:
log.finer(message);
break;

case FINEST:
log.finest(message);
}

log.close();
}

}

0 comments on commit 5b736f5

Please sign in to comment.