diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java index 8c4b3df54a..bfb8af1f80 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java @@ -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:] [(:)] (radius:<#>) (height:<#>) (depth:<#>)", 2); registerCoreMember(NameplateCommand.class, - "NAMEPLATE", "nameplate [set:text|chat_color] (target:player_name)", 1); + "NAMEPLATE", "nameplate [set:text|chat_color] (target:)", 1); registerCoreMember(NarrateCommand.class, - "NARRATE", "narrate [\"narration text\"] (player:name) (format:name)", 1); + "NARRATE", "narrate [\"narration text\"] (player:) (format:)", 1); registerCoreMember(NewCommand.class, - "NEW", "new itemstack [item:material] (qty:#)", 2); + "NEW", "new itemstack [item:] (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:] [effect:] (volume:<#>) (pitch:<#>)", 2); registerCoreMember(PlaySoundCommand.class, - "PLAYSOUND", "playsound [location:x,y,z,world] [sound:name] (volume:#) (pitch:#)", 2); + "PLAYSOUND", "playsound [location:] [sound:] (volume:<#>) (pitch:<#>)", 2); registerCoreMember(PermissionCommand.class, - "PERMISSION", "permission [add|remove] [permission] (player:name) (group:name) (world:name)", 2); + "PERMISSION", "permission [add|remove] [permission] (player:) (group:) (world:)", 2); registerCoreMember(PoseCommand.class, - "POSE", "pose (player) [id:name]", 1); + "POSE", "pose (player) [id:]", 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:{}) [clear|pause|resume|delay:<#>]", 1); registerCoreMember(RandomCommand.class, "RANDOM", "random [#]", 1); diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/PlayEffectCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/PlayEffectCommand.java new file mode 100644 index 0000000000..074f14d5ad --- /dev/null +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/PlayEffectCommand.java @@ -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:] [effect:] (data:<#>) (radius:<#>)*/ + +/* + * Arguments: [] - Required, () - Optional + * [location:] specifies location of the effect + * [effect:] 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: 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); + } + +} diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/PlaySoundCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/PlaySoundCommand.java index 41d5d29993..b05e8fbce5 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/core/PlaySoundCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/core/PlaySoundCommand.java @@ -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);