Skip to content

Commit

Permalink
Add fully-featured Playeffect command. Example usage: - playeffect lo…
Browse files Browse the repository at this point in the history
…cation:<npc.location> effect:record_play data:2259 radius:7
  • Loading branch information
davidcernat committed Jun 14, 2013
1 parent 91c18ba commit 2b25f42
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 13 deletions.
Expand Up @@ -176,34 +176,37 @@ public void registerCoreMembers() {
"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:name)", 1);
"NARRATE", "narrate [\"narration text\"] (player:<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);
"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:name) (group:name) (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 Down
@@ -0,0 +1,96 @@
package net.aufdemrand.denizen.scripts.commands.core;

import org.bukkit.Effect;
import org.bukkit.Location;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.arguments.aH;
import net.aufdemrand.denizen.utilities.arguments.aH.ArgumentType;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

/* playeffect [location:<x,y,z,world>] [effect:<name>] (data:<#>) (radius:<#>)*/

/*
* Arguments: [] - Required, () - Optional
* [location:<x,y,z,world>] specifies location of the effect
* [effect:<name>] sets the name of effect to be played
* (data:<#>) sets the special data value of the effect
* (radius:<#>) adjusts the radius within which players will observe the effect
*
* Example Usage:
* playeffect location:123,65,765,world effect:record_play data:2259 radius:7
* playeffect location:<npc.location> e:smoke r:3
*/

public class PlayEffectCommand extends AbstractCommand {

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

// Initialize fields
Effect effect = null;
int radius = 3;
int data = 0;
Location location = null;

// Iterate through arguments
for (String arg : scriptEntry.getArguments()){
if (aH.matchesLocation(arg))
location = aH.getLocationFrom(arg);

else if (aH.matchesValueArg("effect, e", arg, ArgumentType.Custom)) {
try {
effect = Effect.valueOf(aH.getStringFrom(arg).toUpperCase());
} catch (Exception e) {
dB.echoError("Invalid effect!");
}
}

else if (aH.matchesValueArg("radius, r", arg, ArgumentType.Float))
radius = aH.getIntegerFrom(arg);

else if (aH.matchesValueArg("data, d", arg, ArgumentType.Float))
data = aH.getIntegerFrom(arg);

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

// Check required args
if (effect == null)
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "EFFECT");
if (location == null)
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "LOCATION");

// Stash args in ScriptEntry for use in execute()
scriptEntry.addObject("location", location);
scriptEntry.addObject("effect", effect);
scriptEntry.addObject("radius", radius);
scriptEntry.addObject("data", data);
}

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

// Extract objects from ScriptEntry
Location location = (Location) scriptEntry.getObject("location");
Effect effect = (Effect) scriptEntry.getObject("effect");
int radius = (Integer) scriptEntry.getObject("radius");
int data = (Integer) scriptEntry.getObject("data");

// Debugger
dB.echoApproval("Executing '" + getName() + "': "
+ "Location='" + location.getX() + "," + location.getY()
+ "," + location.getZ() + "," + location.getWorld().getName() + "', "
+ "Effect='" + effect.toString() + ", "
+ "Data='" + data + ", "
+ "Radius='" + radius + "'");

// Play the sound
location.getWorld().playEffect(location, effect, data, radius);
}

}
Expand Up @@ -43,18 +43,18 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
if (aH.matchesLocation(arg))
location = aH.getLocationFrom(arg);

else if (aH.matchesValueArg("SOUND", arg, ArgumentType.Custom) || aH.matchesValueArg("S", arg, ArgumentType.Custom)) {
else if (aH.matchesValueArg("sound, s", arg, ArgumentType.Custom)) {
try {
sound = Sound.valueOf(aH.getStringFrom(arg).toUpperCase());
} catch (Exception e) {
dB.echoError("Invalid SOUND!");
dB.echoError("Invalid sound!");
}
}

else if (aH.matchesValueArg("VOLUME, V", arg, ArgumentType.Float))
else if (aH.matchesValueArg("volume, v", arg, ArgumentType.Float))
volume = aH.getFloatFrom(arg);

else if (aH.matchesValueArg("PITCH, P", arg, ArgumentType.Float))
else if (aH.matchesValueArg("pitch, p", arg, ArgumentType.Float))
pitch = aH.getFloatFrom(arg);

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

0 comments on commit 2b25f42

Please sign in to comment.