Add data to /npc item

This commit is contained in:
fullwall 2014-01-09 17:13:27 +08:00
parent 34fc6ab029
commit 0af5422368
2 changed files with 13 additions and 10 deletions

View File

@ -265,7 +265,7 @@ public class NPCCommands {
} }
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy) CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy)
: new CommandSenderCreateNPCEvent(sender, copy); : new CommandSenderCreateNPCEvent(sender, copy);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
event.getNPC().destroy(); event.getNPC().destroy();
@ -337,7 +337,7 @@ public class NPCCommands {
spawnLoc = args.getSenderLocation(); spawnLoc = args.getSenderLocation();
} }
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, npc) CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, npc)
: new CommandSenderCreateNPCEvent(sender, npc); : new CommandSenderCreateNPCEvent(sender, npc);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
npc.destroy(); npc.destroy();
@ -566,11 +566,11 @@ public class NPCCommands {
@Command( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "item [item]", usage = "item [item] (data)",
desc = "Sets the NPC's item", desc = "Sets the NPC's item",
modifiers = { "item", }, modifiers = { "item", },
min = 2, min = 2,
max = 2, max = 3,
flags = "", flags = "",
permission = "citizens.npc.item") permission = "citizens.npc.item")
@Requirements(selected = true, ownership = true, types = { EntityType.DROPPED_ITEM, EntityType.ITEM_FRAME, @Requirements(selected = true, ownership = true, types = { EntityType.DROPPED_ITEM, EntityType.ITEM_FRAME,
@ -587,7 +587,7 @@ public class NPCCommands {
((ItemFrame) npc.getEntity()).getItem().setType(mat); ((ItemFrame) npc.getEntity()).getItem().setType(mat);
break; break;
case FALLING_BLOCK: case FALLING_BLOCK:
((FallingBlockNPC) npc.getEntity()).setType(mat); ((FallingBlockNPC) npc.getEntity()).setType(mat, args.argsLength() > 2 ? args.getInteger(2) : 0);
break; break;
default: default:
break; break;
@ -969,7 +969,7 @@ public class NPCCommands {
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER }) @Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
public void power(CommandContext args, CommandSender sender, NPC npc) { public void power(CommandContext args, CommandSender sender, NPC npc) {
Messaging Messaging
.sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED); .sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED);
} }
@Command( @Command(

View File

@ -33,9 +33,11 @@ public class FallingBlockController extends AbstractEntityController {
protected Entity createEntity(Location at, NPC npc) { protected Entity createEntity(Location at, NPC npc) {
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle(); WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
Block id = Blocks.STONE; Block id = Blocks.STONE;
int data = npc.data().get("falling-block-data", 0);
if (npc.data().has("falling-block-id")) if (npc.data().has("falling-block-id"))
id = CraftMagicNumbers.getBlock(Material.getMaterial(npc.data().<String> get("falling-block-id"))); id = CraftMagicNumbers.getBlock(Material.getMaterial(npc.data().<String> get("falling-block-id")));
final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), id); final EntityFallingBlockNPC handle = new EntityFallingBlockNPC(ws, npc, at.getX(), at.getY(), at.getZ(), id,
data);
return handle.getBukkitEntity(); return handle.getBukkitEntity();
} }
@ -56,8 +58,8 @@ public class FallingBlockController extends AbstractEntityController {
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
} }
public EntityFallingBlockNPC(World world, NPC npc, double d0, double d1, double d2, Block block) { public EntityFallingBlockNPC(World world, NPC npc, double d0, double d1, double d2, Block block, int data) {
super(world, d0, d1, d2, block); super(world, d0, d1, d2, block, data);
this.npc = (CitizensNPC) npc; this.npc = (CitizensNPC) npc;
} }
@ -129,8 +131,9 @@ public class FallingBlockController extends AbstractEntityController {
return npc; return npc;
} }
public void setType(Material material) { public void setType(Material material, int data) {
npc.data().setPersistent("falling-block-id", material.name()); npc.data().setPersistent("falling-block-id", material.name());
npc.data().setPersistent("falling-block-data", data);
if (npc.isSpawned()) { if (npc.isSpawned()) {
npc.despawn(); npc.despawn();
npc.spawn(npc.getStoredLocation()); npc.spawn(npc.getStoredLocation());