Add /npc shulker

This commit is contained in:
fullwall 2017-09-04 19:16:49 +08:00
parent 640c182502
commit 15569c529f
10 changed files with 91 additions and 6 deletions

View File

@ -82,6 +82,7 @@ import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.RabbitType;
import net.citizensnpcs.trait.ScriptTrait;
import net.citizensnpcs.trait.SheepTrait;
import net.citizensnpcs.trait.ShulkerTrait;
import net.citizensnpcs.trait.SkinLayers;
import net.citizensnpcs.trait.SkinLayers.Layer;
import net.citizensnpcs.trait.SlimeSize;
@ -1441,10 +1442,33 @@ public class NPCCommands {
}
}
@Command(
aliases = { "npc" },
usage = "shulker (--peek [peek])",
desc = "Sets shulker modifiers.",
modifiers = { "shulker" },
min = 1,
max = 1,
permission = "citizens.npc.shulker")
@Requirements(selected = true, ownership = true, types = { EntityType.SHULKER })
public void shulker(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
ShulkerTrait trait = npc.getTrait(ShulkerTrait.class);
boolean hasArg = false;
if (args.hasValueFlag("peek")) {
int peek = (byte) args.getFlagInteger("peek");
trait.setPeek(peek);
Messaging.sendTr(sender, Messages.SHULKER_PEEK_SET, npc.getName(), peek);
hasArg = true;
}
if (!hasArg) {
throw new CommandException();
}
}
@Command(
aliases = { "npc" },
usage = "skin (-c -p -f) [name]",
desc = "Sets an NPC's skin name, Use -p to save a skin snapshot that won't change",
desc = "Sets an NPC's skin name. Use -p to save a skin snapshot that won't change",
modifiers = { "skin" },
min = 1,
max = 2,

View File

@ -39,6 +39,7 @@ import net.citizensnpcs.trait.RabbitType;
import net.citizensnpcs.trait.Saddle;
import net.citizensnpcs.trait.ScriptTrait;
import net.citizensnpcs.trait.SheepTrait;
import net.citizensnpcs.trait.ShulkerTrait;
import net.citizensnpcs.trait.SkinLayers;
import net.citizensnpcs.trait.SlimeSize;
import net.citizensnpcs.trait.VillagerProfession;
@ -72,6 +73,7 @@ public class CitizensTraitFactory implements TraitFactory {
registerTrait(TraitInfo.create(Saddle.class));
registerTrait(TraitInfo.create(ScriptTrait.class));
registerTrait(TraitInfo.create(SheepTrait.class));
registerTrait(TraitInfo.create(ShulkerTrait.class));
registerTrait(TraitInfo.create(SkinLayers.class));
registerTrait(TraitInfo.create(MountTrait.class));
registerTrait(TraitInfo.create(SlimeSize.class));

View File

@ -0,0 +1,33 @@
package net.citizensnpcs.trait;
import org.bukkit.entity.Shulker;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.util.NMS;
@TraitName("shulkertrait")
public class ShulkerTrait extends Trait {
@Persist("peek")
private int peek = 0;
public ShulkerTrait() {
super("shulkertrait");
}
@Override
public void onSpawn() {
}
@Override
public void run() {
if (npc.getEntity() instanceof Shulker) {
NMS.setShulkerPeek((Shulker) npc.getEntity(), peek);
}
}
public void setPeek(int peek) {
this.peek = peek;
}
}

View File

@ -204,6 +204,7 @@ public class Messages {
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 SHEEP_COLOR_SET = "citizens.commands.npc.sheep.color-set";
public static final String SHULKER_PEEK_SET = "citizens.commands.npc.shulker.peek-set";
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 SKELETON_TYPE_SET = "citizens.commands.npc.skeletontype.set";

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
@ -261,6 +262,10 @@ public class NMS {
BRIDGE.setShouldJump(entity);
}
public static void setShulkerPeek(Shulker shulker, int peek) {
BRIDGE.setShulkerPeek(shulker, peek);
}
public static void setSitting(Tameable tameable, boolean sitting) {
BRIDGE.setSitting(tameable, sitting);
}
@ -306,6 +311,5 @@ public class NMS {
}
private static NMSBridge BRIDGE;
private static Field MODIFIERS_FIELD = NMS.getField(Field.class, "modifiers");
}

View File

@ -12,6 +12,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
@ -125,6 +126,8 @@ public interface NMSBridge {
public void setShouldJump(Entity entity);
public void setShulkerPeek(Shulker shulker, int peek);
public void setSitting(Tameable tameable, boolean sitting);
public void setStepHeight(Entity entity, float height);

View File

@ -110,6 +110,7 @@ citizens.commands.npc.respawn.describe=Respawn delay is currently [[{0}]].
citizens.commands.npc.select.already-selected=You already have that NPC selected.
citizens.commands.npc.script.invalid-file=Unknown or unavailable script ''[[{0}]]''.
citizens.commands.npc.script.current-scripts=[[{0}]]''s current scripts are [[{1}]].
citizens.commands.npc.shulker.peek-set=[[{0}]]''s peek amount set to [[{1}]].
citizens.commands.npc.skin.set=[[{0}]]''s skin name set to [[{1}]].
citizens.commands.npc.skin.cleared=[[{0}]]''s skin name was cleared.
citizens.commands.npc.skin.layers-set=[[{0}]]''s skin layers: cape - [[{1}]], hat - [[{2}]], jacket - [[{3}]], sleeves - [[{4}]], pants - [[{5}]].

View File

@ -35,6 +35,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
@ -168,6 +169,7 @@ import net.minecraft.server.v1_10_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.EntityPolarBear;
import net.minecraft.server.v1_10_R1.EntityRabbit;
import net.minecraft.server.v1_10_R1.EntityShulker;
import net.minecraft.server.v1_10_R1.EntityTameableAnimal;
import net.minecraft.server.v1_10_R1.EntityTracker;
import net.minecraft.server.v1_10_R1.EntityTrackerEntry;
@ -876,6 +878,11 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setShulkerPeek(Shulker shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);
}
@Override
public void setSitting(Tameable tameable, boolean sitting) {
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);

View File

@ -35,6 +35,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
@ -188,6 +189,7 @@ import net.minecraft.server.v1_11_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_11_R1.EntityPlayer;
import net.minecraft.server.v1_11_R1.EntityPolarBear;
import net.minecraft.server.v1_11_R1.EntityRabbit;
import net.minecraft.server.v1_11_R1.EntityShulker;
import net.minecraft.server.v1_11_R1.EntityTameableAnimal;
import net.minecraft.server.v1_11_R1.EntityTracker;
import net.minecraft.server.v1_11_R1.EntityTrackerEntry;
@ -937,6 +939,11 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setShulkerPeek(Shulker shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);
}
@Override
public void setSitting(Tameable tameable, boolean sitting) {
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);
@ -1486,13 +1493,9 @@ public class NMSImpl implements NMSBridge {
public static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0);
private static Field PATHFINDING_RANGE = NMS.getField(NavigationAbstract.class, "f");
private static final Field RABBIT_FIELD = NMS.getField(EntityRabbit.class, "bw");
private static final Random RANDOM = Util.getFastRandom();
private static Field SKULL_PROFILE_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bF");
static {

View File

@ -35,6 +35,7 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Shulker;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
@ -192,6 +193,7 @@ import net.minecraft.server.v1_12_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_12_R1.EntityPlayer;
import net.minecraft.server.v1_12_R1.EntityPolarBear;
import net.minecraft.server.v1_12_R1.EntityRabbit;
import net.minecraft.server.v1_12_R1.EntityShulker;
import net.minecraft.server.v1_12_R1.EntityTameableAnimal;
import net.minecraft.server.v1_12_R1.EntityTracker;
import net.minecraft.server.v1_12_R1.EntityTrackerEntry;
@ -952,6 +954,11 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setShulkerPeek(Shulker shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);
}
@Override
public void setSitting(Tameable tameable, boolean sitting) {
((EntityTameableAnimal) NMSImpl.getHandle((LivingEntity) tameable)).setSitting(sitting);