mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-28 12:07:38 +01:00
Add data to /npc item
This commit is contained in:
parent
34fc6ab029
commit
0af5422368
@ -265,7 +265,7 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy)
|
||||
: new CommandSenderCreateNPCEvent(sender, copy);
|
||||
: new CommandSenderCreateNPCEvent(sender, copy);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
event.getNPC().destroy();
|
||||
@ -337,7 +337,7 @@ public class NPCCommands {
|
||||
spawnLoc = args.getSenderLocation();
|
||||
}
|
||||
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, npc)
|
||||
: new CommandSenderCreateNPCEvent(sender, npc);
|
||||
: new CommandSenderCreateNPCEvent(sender, npc);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
npc.destroy();
|
||||
@ -566,11 +566,11 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "item [item]",
|
||||
usage = "item [item] (data)",
|
||||
desc = "Sets the NPC's item",
|
||||
modifiers = { "item", },
|
||||
min = 2,
|
||||
max = 2,
|
||||
max = 3,
|
||||
flags = "",
|
||||
permission = "citizens.npc.item")
|
||||
@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);
|
||||
break;
|
||||
case FALLING_BLOCK:
|
||||
((FallingBlockNPC) npc.getEntity()).setType(mat);
|
||||
((FallingBlockNPC) npc.getEntity()).setType(mat, args.argsLength() > 2 ? args.getInteger(2) : 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -969,7 +969,7 @@ public class NPCCommands {
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
|
||||
public void power(CommandContext args, CommandSender sender, NPC npc) {
|
||||
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(
|
||||
|
@ -33,9 +33,11 @@ public class FallingBlockController extends AbstractEntityController {
|
||||
protected Entity createEntity(Location at, NPC npc) {
|
||||
WorldServer ws = ((CraftWorld) at.getWorld()).getHandle();
|
||||
Block id = Blocks.STONE;
|
||||
int data = npc.data().get("falling-block-data", 0);
|
||||
if (npc.data().has("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();
|
||||
}
|
||||
|
||||
@ -56,8 +58,8 @@ public class FallingBlockController extends AbstractEntityController {
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
public EntityFallingBlockNPC(World world, NPC npc, double d0, double d1, double d2, Block block) {
|
||||
super(world, d0, d1, d2, block);
|
||||
public EntityFallingBlockNPC(World world, NPC npc, double d0, double d1, double d2, Block block, int data) {
|
||||
super(world, d0, d1, d2, block, data);
|
||||
this.npc = (CitizensNPC) npc;
|
||||
}
|
||||
|
||||
@ -129,8 +131,9 @@ public class FallingBlockController extends AbstractEntityController {
|
||||
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-data", data);
|
||||
if (npc.isSpawned()) {
|
||||
npc.despawn();
|
||||
npc.spawn(npc.getStoredLocation());
|
||||
|
Loading…
Reference in New Issue
Block a user