Skip to content

Commit

Permalink
Add ParticleEffect library. Allow all of its particles to be used by …
Browse files Browse the repository at this point in the history
…the Playeffect command.
  • Loading branch information
davidcernat committed Jul 11, 2013
1 parent a57b85b commit 054299d
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 29 deletions.
6 changes: 2 additions & 4 deletions src/main/java/net/aufdemrand/denizen/objects/aH.java
Expand Up @@ -487,8 +487,7 @@ public static String getStringFrom(String arg) {

@Deprecated
public static Duration getDurationFrom(String arg) {
if (arg.split(":").length > 1)
arg = arg.split(":")[1];
arg = arg.replace("duration:", "").replace("delay:", "");
return Duration.valueOf(arg);
}

Expand All @@ -498,8 +497,7 @@ public static boolean matchesDouble(String arg) {

@Deprecated
public static boolean matchesDuration(String arg) {
if (arg.split(":").length > 1)
arg = arg.split(":")[1];
arg = arg.replace("duration:", "").replace("delay:", "");
return Duration.matches(arg);
}

Expand Down
@@ -1,9 +1,6 @@
package net.aufdemrand.denizen.scripts.commands.world;

import org.bukkit.Effect;
import org.bukkit.EntityEffect;
import org.bukkit.craftbukkit.v1_6_R2.entity.CraftWolf;
import org.bukkit.entity.Wolf;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
Expand All @@ -14,10 +11,14 @@
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.aufdemrand.denizen.utilities.ParticleEffect;

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

/**
* Lets you play a Bukkit effect or a ParticleEffect from the
* ParticleEffect Library at a certain location.
*
* Arguments: [] - Required, () - Optional
* [location:<x,y,z,world>] specifies location of the effect
* [effect:<name>] sets the name of effect to be played
Expand All @@ -33,9 +34,6 @@

public class PlayEffectCommand extends AbstractCommand {

// Implement some special effects that are not in Bukkit's Effect class
private enum SpecialEffect { HEARTS, EXPLOSION }

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

Expand All @@ -54,14 +52,14 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
if (arg.matchesEnum(Effect.values())) {
scriptEntry.addObject("effect", Effect.valueOf(arg.getValue().toUpperCase()));
}
else if (arg.matchesEnum(SpecialEffect.values())) {
scriptEntry.addObject("specialeffect", SpecialEffect.valueOf(arg.getValue().toUpperCase()));
else if (arg.matchesEnum(ParticleEffect.values())) {
scriptEntry.addObject("specialeffect", ParticleEffect.valueOf(arg.getValue().toUpperCase()));
}
}

else if (!scriptEntry.hasObject("radius")
&& arg.matchesPrimitive(aH.PrimitiveType.Integer)
&& arg.matchesPrefix("radius, r")) {
&& arg.matchesPrimitive(aH.PrimitiveType.Double)
&& arg.matchesPrefix("range, radius, r")) {
// Add value
scriptEntry.addObject("radius", arg.asElement());
}
Expand Down Expand Up @@ -99,15 +97,15 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Extract objects from ScriptEntry
dLocation location = (dLocation) scriptEntry.getObject("location");
Effect effect = (Effect) scriptEntry.getObject("effect");
SpecialEffect specialEffect = (SpecialEffect) scriptEntry.getObject("specialeffect");
ParticleEffect particleEffect = (ParticleEffect) scriptEntry.getObject("specialeffect");
Element radius = (Element) scriptEntry.getObject("radius");
Element data = (Element) scriptEntry.getObject("data");

// Report to dB
dB.report(getName(),
(effect != null ?
aH.debugObj("effect", effect.name()) :
aH.debugObj("special effect", specialEffect.name())) +
aH.debugObj("special effect", particleEffect.name())) +
aH.debugObj("location", location.toString() +
aH.debugObj("radius", radius) +
aH.debugObj("data", data)));
Expand All @@ -118,18 +116,9 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
}
// Play one of the special effects
else {
if (specialEffect.equals(SpecialEffect.HEARTS)) {

Wolf wolf = (Wolf) location.getWorld().spawn(location, Wolf.class);
((CraftWolf) wolf).getHandle().setInvisible(true);
wolf.playEffect(EntityEffect.WOLF_HEARTS);
wolf.remove();
}
else if (specialEffect.equals(SpecialEffect.EXPLOSION)) {

location.getWorld().createExplosion(location, 0);
}
ParticleEffect.fromName(particleEffect.name())
.play(location, radius.asDouble(),
1.0F, 1.0F, 1.0F, 1.0F, 3);
}
}

}
Expand Up @@ -487,6 +487,8 @@ public void entityExplode(EntityExplodeEvent event) {
Map<String, Object> context = new HashMap<String, Object>();
Entity entity = event.getEntity();

if (entity == null) return;

context.put("entity", new dEntity(entity));
context.put("location", new dLocation(event.getLocation()));

Expand Down Expand Up @@ -1079,11 +1081,12 @@ public void playerMoveEvent(PlayerMoveEvent event) {

if (name != null) {
Map<String, Object> context = new HashMap<String, Object>();
context.put("notable_name", new Element(name));
context.put("notable", new Element(name));

String determination = doEvents(Arrays.asList
("player walks over notable",
"player walks over " + name,
"walked over notable",
"walked over " + name),
null, event.getPlayer(), context);

Expand Down

0 comments on commit 054299d

Please sign in to comment.