Added ability to change if a creeper NPC is powered. This address CITIZENS-16.

This commit is contained in:
aPunch 2012-03-11 17:39:18 -05:00
parent 93eaa8059e
commit a02521b5cf
4 changed files with 64 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import net.citizensnpcs.command.exception.CommandException;
import net.citizensnpcs.command.exception.NoPermissionsException;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Paginator;
import net.citizensnpcs.util.StringHelper;
@ -367,4 +368,19 @@ public class NPCCommands {
npc.getTrait(SpawnLocation.class).setLocation(npc.getBukkitEntity().getLocation());
Messaging.send(player, StringHelper.wrap(npc.getName()) + " was teleported to your location.");
}
@Command(
aliases = { "npc" },
usage = "power",
desc = "Toggle a creeper NPC as powered",
modifiers = { "power" },
min = 1,
max = 1,
permission = "npc.power")
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
public void power(CommandContext args, Player player, NPC npc) {
String msg = StringHelper.wrap(npc.getName()) + " will "
+ (npc.getTrait(Powered.class).toggle() ? "now" : "no longer");
Messaging.send(player, msg += " be powered.");
}
}

View File

@ -16,6 +16,7 @@ import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.trait.trait.Spawned;
import net.citizensnpcs.api.trait.trait.SpawnLocation;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.text.Text;
import net.citizensnpcs.trait.waypoint.Waypoints;
@ -29,6 +30,7 @@ public class CitizensTraitManager implements TraitManager {
registerTrait(new TraitFactory(LookClose.class).withName("look-close"));
registerTrait(new TraitFactory(MobType.class).withName("type"));
registerTrait(new TraitFactory(Owner.class).withName("owner"));
registerTrait(new TraitFactory(Powered.class).withName("powered"));
registerTrait(new TraitFactory(Spawned.class).withName("spawned"));
registerTrait(new TraitFactory(SpawnLocation.class).withName("location"));
registerTrait(new TraitFactory(Text.class).withName("text"));

View File

@ -0,0 +1,45 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Creeper;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
public class Powered extends Trait implements Toggleable {
private boolean powered;
private final NPC npc;
public Powered(NPC npc) {
this.npc = npc;
}
@Override
public void load(DataKey key) {
powered = key.getBoolean("");
}
@Override
public void save(DataKey key) {
key.setBoolean("", powered);
}
@Override
public void onNPCSpawn() {
if (npc.getBukkitEntity() instanceof Creeper)
((Creeper) npc.getBukkitEntity()).setPowered(powered);
}
@Override
public boolean toggle() {
powered = !powered;
if (npc.getBukkitEntity() instanceof Creeper)
((Creeper) npc.getBukkitEntity()).setPowered(powered);
return powered;
}
@Override
public String toString() {
return "Powered{" + powered + "}";
}
}

View File

@ -27,6 +27,7 @@ permissions:
citizens.npc.help: true
citizens.npc.list: true
citizens.npc.owner: true
citizens.npc.power: true
citizens.npc.remove: true
citizens.npc.remove.all: true
citizens.npc.rename: true