Add gravity and slime size traits

This commit is contained in:
fullwall 2012-10-15 13:45:00 +08:00
parent 1bab619840
commit f04bad6d92
8 changed files with 118 additions and 3 deletions

View File

@ -31,9 +31,11 @@ import net.citizensnpcs.trait.Anchors;
import net.citizensnpcs.trait.Behaviour;
import net.citizensnpcs.trait.Controllable;
import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.SlimeSize;
import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.util.Anchor;
import net.citizensnpcs.util.Messages;
@ -237,7 +239,7 @@ public class NPCCommands {
}
Messaging.sendTr(sender, Messages.NPC_COPIED, npc.getName());
selector.select(sender, npc);
selector.select(sender, copy);
}
@Command(
@ -367,6 +369,20 @@ public class NPCCommands {
Messaging.sendTr(sender, Messages.NPC_DESPAWNED, npc.getName());
}
@Command(
aliases = { "npc" },
usage = "gravity",
desc = "Toggles gravity",
modifiers = { "gravity" },
min = 1,
max = 1,
permission = "npc.gravity")
public void gravity(CommandContext args, CommandSender sender, NPC npc) {
boolean enabled = npc.getTrait(Gravity.class).toggle();
String key = enabled ? Messages.GRAVITY_ENABLED : Messages.GRAVITY_DISABLED;
Messaging.sendTr(sender, key, npc.getName());
}
@Command(
aliases = { "npc" },
usage = "list (page) ((-a) --owner (owner) --type (type) --char (char))",
@ -743,6 +759,26 @@ public class NPCCommands {
Messaging.sendWithNPC(sender, Setting.SELECTION_MESSAGE.asString(), toSelect);
}
@Command(
aliases = { "npc" },
usage = "size [size]",
desc = "Sets the NPC's size",
modifiers = { "size" },
min = 1,
max = 2,
permission = "npc.size")
@Requirements(selected = true, ownership = true, types = { EntityType.MAGMA_CUBE, EntityType.SLIME })
public void slimeSize(CommandContext args, CommandSender sender, NPC npc) {
SlimeSize trait = npc.getTrait(SlimeSize.class);
if (args.argsLength() <= 1) {
trait.describe(sender);
return;
}
int size = Math.max(1, args.getInteger(1));
trait.setSize(size);
Messaging.sendTr(sender, Messages.SIZE_SET, npc.getName(), size);
}
@Command(
aliases = { "npc" },
usage = "spawn [id]",

View File

@ -20,11 +20,13 @@ import net.citizensnpcs.trait.Anchors;
import net.citizensnpcs.trait.Behaviour;
import net.citizensnpcs.trait.Controllable;
import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.Gravity;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.trait.Sheared;
import net.citizensnpcs.trait.SlimeSize;
import net.citizensnpcs.trait.VillagerProfession;
import net.citizensnpcs.trait.WoolColor;
import net.citizensnpcs.trait.text.Text;
@ -43,6 +45,8 @@ public class CitizensTraitFactory implements TraitFactory {
registerTrait(TraitInfo.create(Equipment.class).withName("equipment"));
registerTrait(TraitInfo.create(Inventory.class).withName("inventory"));
registerTrait(TraitInfo.create(LookClose.class).withName("lookclose"));
registerTrait(TraitInfo.create(Gravity.class).withName("gravity"));
registerTrait(TraitInfo.create(SlimeSize.class).withName("slimesize"));
registerTrait(TraitInfo.create(MobType.class).withName("type"));
registerTrait(TraitInfo.create(Owner.class).withName("owner"));
registerTrait(TraitInfo.create(Powered.class).withName("powered"));

View File

@ -197,6 +197,5 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
}
private static final float EPSILON = 0.005F;
private static final float STEP_HEIGHT = 1F;
}

View File

@ -0,0 +1,29 @@
package net.citizensnpcs.trait;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import org.bukkit.util.Vector;
public class Gravity extends Trait implements Toggleable {
@Persist
private boolean enabled;
public Gravity(String name) {
super("gravity");
}
@Override
public void run() {
if (!npc.isSpawned() || !enabled)
return;
Vector velocity = npc.getBukkitEntity().getVelocity();
velocity.setY(Math.max(velocity.getY(), 0));
npc.getBukkitEntity().setVelocity(velocity);
}
@Override
public boolean toggle() {
return enabled = !enabled;
}
}

View File

@ -0,0 +1,39 @@
package net.citizensnpcs.trait;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Slime;
public class SlimeSize extends Trait {
@Persist
private int size = 3;
private boolean slime;
protected SlimeSize(String name) {
super("slimesize");
}
public void describe(CommandSender sender) {
Messaging.sendTr(sender, Messages.SIZE_DESCRIPTION, npc.getName(), size);
}
@Override
public void onSpawn() {
if (!(npc.getBukkitEntity() instanceof Slime)) {
slime = false;
return;
}
((Slime) npc.getBukkitEntity()).setSize(size);
slime = true;
}
public void setSize(int size) {
this.size = size;
if (slime)
((Slime) npc.getBukkitEntity()).setSize(size);
}
}

View File

@ -63,6 +63,8 @@ public class Messages {
public static final String FAILED_LOAD_SAVES = "citizens.saves.load-failed";
public static final String FAILED_TO_MOUNT_NPC = "citizens.commands.npc.mount.failed";
public static final String FAILED_TO_REMOVE = "citizens.commands.trait.failed-to-remove";
public static final String GRAVITY_DISABLED = "citizens.commands.npc.gravity.disabled";
public static final String GRAVITY_ENABLED = "citizens.commands.npc.gravity.enabled";
public static final String INVALID_AGE = "citizens.commands.npc.age.invalid-age";
public static final String INVALID_ANCHOR_NAME = "citizens.commands.npc.anchor.invalid-name";
public static final String INVALID_POSE_NAME = "citizens.commands.npc.pose.invalid-name";
@ -129,6 +131,8 @@ public class Messages {
public static final String SELECTION_PROMPT = "citizens.editors.selection.start-prompt";
public static final String SHEARED_SET = "citizens.editors.equipment.sheared-set";
public static final String SHEARED_STOPPED = "citizens.editors.equipment.sheared-stopped";
public static final String SIZE_DESCRIPTION = "citizens.commands.npc.size.description";
public static final String SIZE_SET = "citizens.commands.npc.size.set";
public static final String SKIPPING_BROKEN_TRAIT = "citizens.notifications.skipping-broken-trait";
public static final String SKIPPING_INVALID_ANCHOR = "citizens.notifications.skipping-invalid-anchor";
public static final String SKIPPING_INVALID_POSE = "citizens.notifications.skipping-invalid-pose";

View File

@ -62,7 +62,7 @@ public class NMS {
}
public static void clearGoals(PathfinderGoalSelector... goalSelectors) {
if (NMS.GOAL_FIELD == null || goalSelectors == null)
if (GOAL_FIELD == null || goalSelectors == null)
return;
for (PathfinderGoalSelector selector : goalSelectors) {
try {

View File

@ -16,6 +16,10 @@ citizens.commands.npc.age.set-normal=[[{0}]] is now age [[{1}]].
citizens.commands.npc.age.set=[[{0}]] is now [[{1}]].
citizens.commands.npc.age.unlocked=Age unlocked.
citizens.commands.npc.anchor.added=Anchor added.
citizens.commands.npc.size.set={0}'s size set to [[{1}]].
citizens.commands.npc.gravity.disabled=Gravity [[disabled]].
citizens.commands.npc.gravity.enabled=Gravity [[enabled]].
citizens.commands.npc.size.description={0}'s size is [[{1}]].
citizens.commands.npc.anchor.already-exists=The anchor '{0}' already exists.
citizens.commands.npc.anchor.invalid-name=Invalid anchor name.
citizens.commands.npc.anchor.missing=The anchor '{1}' does not exist.