mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 19:16:34 +01:00
Added ability to change if a creeper NPC is powered. This address CITIZENS-16.
This commit is contained in:
parent
bd6f2ec49a
commit
0cbf0d8d74
@ -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.");
|
||||
}
|
||||
}
|
@ -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"));
|
||||
|
45
src/main/java/net/citizensnpcs/trait/Powered.java
Normal file
45
src/main/java/net/citizensnpcs/trait/Powered.java
Normal 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 + "}";
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user