Skip to content

Commit

Permalink
ParticlesTrait added, /npc effect --name effect_name (NONE, SMOKE, FL…
Browse files Browse the repository at this point in the history
…AME, ENDER, POTBREAK )

Still really rough, needs attention.
  • Loading branch information
Jeebiss committed Mar 21, 2013
1 parent da5d843 commit 5080b1c
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/main/java/net/aufdemrand/denizen/CommandHandler.java
Expand Up @@ -4,7 +4,6 @@

import net.aufdemrand.denizen.listeners.AbstractListener;
import net.aufdemrand.denizen.npc.traits.*;
// import net.aufdemrand.denizen.npc.traits.SleepingTrait;
import net.aufdemrand.denizen.scripts.ScriptHelper;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
Expand Down Expand Up @@ -524,6 +523,41 @@ public void stopFishing(CommandContext args, CommandSender sender, NPC npc) thro
npc.removeTrait(FishingTrait.class);
}

/*
* Effect
*/
@Command(
aliases = { "npc" }, usage = "effect --name effect_name",
desc = "Sets the NPC particle effect.", modifiers = { "effect" },
min = 1, max = 3, permission = "npc.effect")
@Requirements(selected = true, ownership = true)
public void playEffect(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if (!npc.hasTrait(ParticlesTrait.class)) npc.addTrait(ParticlesTrait.class);
ParticlesTrait trait = npc.getTrait(ParticlesTrait.class);

if (args.hasValueFlag("name")) {
String name = args.getFlag("name");
if (!npc.hasTrait(ParticlesTrait.class)) npc.addTrait(ParticlesTrait.class);

if (name.equalsIgnoreCase("none")) {
trait.setEffect("NONE");
} else if (name.equalsIgnoreCase("flame")) {
trait.setEffect("FLAME");
} else if (name.equalsIgnoreCase("ender")) {
trait.setEffect("ENDER");
} else if (name.equalsIgnoreCase("smoke")) {
trait.setEffect("SMOKE");
} else if (name.equalsIgnoreCase("potbreak")) {
trait.setEffect("POTBREAK");
} else if (name.equalsIgnoreCase("potion")) {
trait.setEffect("POTION");
} else Messaging.send(sender, ChatColor.RED + "Not a valid effect name!");

} else Messaging.send(sender, ChatColor.RED + "Please specify an effect name!");

}


/*
* HEALTH
*/
Expand Down
132 changes: 132 additions & 0 deletions src/main/java/net/aufdemrand/denizen/npc/traits/ParticlesTrait.java
@@ -0,0 +1,132 @@
package net.aufdemrand.denizen.npc.traits;

import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.trait.Trait;
import net.minecraft.server.v1_5_R1.DataWatcher;
import net.minecraft.server.v1_5_R1.EntityLiving;

import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_5_R1.entity.CraftLivingEntity;

public class ParticlesTrait extends Trait {

public enum EffectType { NONE, SMOKE, FLAME, ENDER, POTBREAK, POTION }

//DataWatcher dw;
//EntityLiving el;

Denizen denizen = DenizenAPI.getCurrentInstance();
World world;

EffectType effectType = EffectType.NONE;

int wait = 10;
int counter = 0;
//int c = 0;
//int tempcounter = 0;

@Override
public void run() {
if (world == null) {
return;
}

counter++;

switch (effectType) {
case NONE:
break;
case FLAME:
if (counter > wait) {
playFlameEffect();
//dB.log("playing flame");
counter = 0;
}
break;
case ENDER:
if (counter > wait) {
playEnderEffect();
//dB.log("playing ender");
counter = 0;
}
case SMOKE:
if (counter > wait) {
playSmokeEffect();
//dB.log("playing smoke");
counter = 0;
}
case POTBREAK:
if (counter > wait) {
playPotionBreakEffect();
//dB.log("playing potion break");
counter = 0;
}
break;
case POTION:
/*
if (!el.effects.isEmpty()) {
c = net.minecraft.server.v1_5_R1.PotionBrewer.a(el.effects.values());
}
dw.watch(8, Integer.valueOf(c));
*/
}


}

@Override
public void onSpawn() {
//el = ((CraftLivingEntity)npc.getBukkitEntity()).getHandle();
//dw = el.getDataWatcher();
world = npc.getBukkitEntity().getWorld();
}

public void playFlameEffect() {
Location location = npc.getBukkitEntity().getLocation();
world.playEffect(location, Effect.MOBSPAWNER_FLAMES, 0);
}

public void playEnderEffect() {
Location location = npc.getBukkitEntity().getLocation();
world.playEffect(location, Effect.ENDER_SIGNAL, 0);
}

public void playPotionEffect() {
//dw.watch(8, Integer.valueOf(2));
}

public void playPotionBreakEffect() {
Location location = npc.getBukkitEntity().getLocation();
world.playEffect(location, Effect.POTION_BREAK, 0);
}

public void playSmokeEffect() {
Location location = npc.getBukkitEntity().getLocation();
world.playEffect(location, Effect.SMOKE, 0);
world.playEffect(location, Effect.SMOKE, 1);
world.playEffect(location, Effect.SMOKE, 2);
world.playEffect(location, Effect.SMOKE, 3);
world.playEffect(location, Effect.SMOKE, 4);
world.playEffect(location, Effect.SMOKE, 5);
world.playEffect(location, Effect.SMOKE, 6);
world.playEffect(location, Effect.SMOKE, 7);
world.playEffect(location, Effect.SMOKE, 8);
}

public void setEffect(String effectType) {
this.effectType = EffectType.valueOf(effectType.toUpperCase());
}

public void setWait(Integer ticks) {
wait = ticks;
}

public ParticlesTrait() {
super("particles");
}

}

0 comments on commit 5080b1c

Please sign in to comment.