mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-28 03:57:35 +01:00
Persistence for item NPC ids and item frame NPC ids
This commit is contained in:
parent
81afd8bada
commit
960b54d7d3
@ -33,6 +33,8 @@ import net.citizensnpcs.npc.EntityControllers;
|
|||||||
import net.citizensnpcs.npc.NPCSelector;
|
import net.citizensnpcs.npc.NPCSelector;
|
||||||
import net.citizensnpcs.npc.Template;
|
import net.citizensnpcs.npc.Template;
|
||||||
import net.citizensnpcs.npc.entity.nonliving.FallingBlockController.FallingBlockNPC;
|
import net.citizensnpcs.npc.entity.nonliving.FallingBlockController.FallingBlockNPC;
|
||||||
|
import net.citizensnpcs.npc.entity.nonliving.ItemController.ItemNPC;
|
||||||
|
import net.citizensnpcs.npc.entity.nonliving.ItemFrameController.ItemFrameNPC;
|
||||||
import net.citizensnpcs.trait.Age;
|
import net.citizensnpcs.trait.Age;
|
||||||
import net.citizensnpcs.trait.Anchors;
|
import net.citizensnpcs.trait.Anchors;
|
||||||
import net.citizensnpcs.trait.Controllable;
|
import net.citizensnpcs.trait.Controllable;
|
||||||
@ -584,15 +586,18 @@ public class NPCCommands {
|
|||||||
Material mat = Material.matchMaterial(args.getString(1));
|
Material mat = Material.matchMaterial(args.getString(1));
|
||||||
if (mat == null)
|
if (mat == null)
|
||||||
throw new CommandException(Messages.UNKNOWN_MATERIAL);
|
throw new CommandException(Messages.UNKNOWN_MATERIAL);
|
||||||
|
int data = args.getInteger(2, 0);
|
||||||
switch (npc.getEntity().getType()) {
|
switch (npc.getEntity().getType()) {
|
||||||
case DROPPED_ITEM:
|
case DROPPED_ITEM:
|
||||||
((org.bukkit.entity.Item) npc.getEntity()).getItemStack().setType(mat);
|
((org.bukkit.entity.Item) npc.getEntity()).getItemStack().setType(mat);
|
||||||
|
((ItemNPC) npc.getEntity()).setType(mat, data);
|
||||||
break;
|
break;
|
||||||
case ITEM_FRAME:
|
case ITEM_FRAME:
|
||||||
((ItemFrame) npc.getEntity()).getItem().setType(mat);
|
((ItemFrame) npc.getEntity()).getItem().setType(mat);
|
||||||
|
((ItemFrameNPC) npc.getEntity()).setType(mat, data);
|
||||||
break;
|
break;
|
||||||
case FALLING_BLOCK:
|
case FALLING_BLOCK:
|
||||||
((FallingBlockNPC) npc.getEntity()).setType(mat, args.argsLength() > 2 ? args.getInteger(2) : 0);
|
((FallingBlockNPC) npc.getEntity()).setType(mat, data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -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);
|
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||||
if (npc.data().has("falling-block-id"))
|
if (npc.data().has("falling-block-id") || npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||||
id = CraftMagicNumbers.getBlock(Material.getMaterial(npc.data().<String> get("falling-block-id")));
|
id = CraftMagicNumbers.getBlock(Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA,
|
||||||
|
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);
|
data);
|
||||||
return handle.getBukkitEntity();
|
return handle.getBukkitEntity();
|
||||||
@ -140,8 +142,8 @@ public class FallingBlockController extends AbstractEntityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setType(Material material, int data) {
|
public void setType(Material material, int data) {
|
||||||
npc.data().setPersistent("falling-block-id", material.name());
|
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
|
||||||
npc.data().setPersistent("falling-block-data", data);
|
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
|
||||||
if (npc.isSpawned()) {
|
if (npc.isSpawned()) {
|
||||||
npc.despawn();
|
npc.despawn();
|
||||||
npc.spawn(npc.getStoredLocation());
|
npc.spawn(npc.getStoredLocation());
|
||||||
|
@ -32,8 +32,13 @@ public class ItemController extends AbstractEntityController {
|
|||||||
@Override
|
@Override
|
||||||
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();
|
||||||
|
Material id = Material.STONE;
|
||||||
|
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||||
|
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||||
|
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||||
|
}
|
||||||
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
final EntityItemNPC handle = new EntityItemNPC(ws, npc, at.getX(), at.getY(), at.getZ(),
|
||||||
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.STONE)));
|
CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(id, 1, (short) data)));
|
||||||
return handle.getBukkitEntity();
|
return handle.getBukkitEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,5 +134,14 @@ public class ItemController extends AbstractEntityController {
|
|||||||
public NPC getNPC() {
|
public NPC getNPC() {
|
||||||
return npc;
|
return npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setType(Material material, int data) {
|
||||||
|
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
|
||||||
|
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
|
||||||
|
if (npc.isSpawned()) {
|
||||||
|
npc.despawn();
|
||||||
|
npc.spawn(npc.getStoredLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ import net.minecraft.server.v1_7_R2.EntityItemFrame;
|
|||||||
import net.minecraft.server.v1_7_R2.World;
|
import net.minecraft.server.v1_7_R2.World;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
|
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftItemFrame;
|
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftItemFrame;
|
||||||
@ -107,11 +108,27 @@ public class ItemFrameController extends MobEntityController {
|
|||||||
public ItemFrameNPC(EntityItemFrameNPC entity) {
|
public ItemFrameNPC(EntityItemFrameNPC entity) {
|
||||||
super((CraftServer) Bukkit.getServer(), entity);
|
super((CraftServer) Bukkit.getServer(), entity);
|
||||||
this.npc = entity.npc;
|
this.npc = entity.npc;
|
||||||
|
Material id = Material.STONE;
|
||||||
|
int data = npc.data().get(NPC.ITEM_DATA_METADATA, npc.data().get("falling-block-data", 0));
|
||||||
|
if (npc.data().has(NPC.ITEM_ID_METADATA)) {
|
||||||
|
id = Material.getMaterial(npc.data().<String> get(NPC.ITEM_ID_METADATA));
|
||||||
|
}
|
||||||
|
getItem().setType(id);
|
||||||
|
getItem().setDurability((short) data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NPC getNPC() {
|
public NPC getNPC() {
|
||||||
return npc;
|
return npc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setType(Material material, int data) {
|
||||||
|
npc.data().setPersistent(NPC.ITEM_ID_METADATA, material.name());
|
||||||
|
npc.data().setPersistent(NPC.ITEM_DATA_METADATA, data);
|
||||||
|
if (npc.isSpawned()) {
|
||||||
|
npc.despawn();
|
||||||
|
npc.spawn(npc.getStoredLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user