Changes to inventories

This commit is contained in:
fullwall 2012-02-14 18:52:22 +08:00
parent 659b1c7dde
commit ffe0fecc9b
2 changed files with 3 additions and 17 deletions

View File

@ -9,7 +9,6 @@ import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.api.npc.trait.trait.Spawned;
import net.citizensnpcs.npc.ai.CitizensAI;
import net.citizensnpcs.util.Messaging;
import net.minecraft.server.EntityLiving;
import org.bukkit.Bukkit;
@ -20,13 +19,14 @@ import org.bukkit.entity.Player;
public abstract class CitizensNPC extends AbstractNPC {
protected final CitizensNPCManager manager;
protected final CitizensAI ai = new CitizensAI(this);
protected EntityLiving mcEntity;
protected final NPCInventory inventory;
protected EntityLiving mcEntity;
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
super(id, name);
this.manager = manager;
inventory = new NPCInventory(this);
this.inventory = new NPCInventory(this);
addTrait(new Inventory(inventory.asInventory()));
}
@Override
@ -110,7 +110,6 @@ public abstract class CitizensNPC extends AbstractNPC {
public boolean openInventory(Player player) {
if (!isSpawned())
return false;
getInventory().setContents(getTrait(Inventory.class).getContents());
inventory.show(player);
return true;
}

View File

@ -8,19 +8,16 @@ import net.minecraft.server.ItemStack;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.inventory.CraftInventory;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
public class NPCInventory implements IInventory {
private final int size = 36;
private final NPC npc;
private final ItemStack[] contents;
private final Inventory inventory = new CraftInventory(this);
private String name;
public NPCInventory(NPC npc) {
this.npc = npc;
name = StringHelper.parseColors(npc.getFullName());
contents = new ItemStack[size];
}
@ -79,16 +76,6 @@ public class NPCInventory implements IInventory {
@Override
public void g() {
// close
org.bukkit.inventory.ItemStack[] bukkitItems = new org.bukkit.inventory.ItemStack[size];
int index = 0;
for (ItemStack item : contents) {
if (item != null)
bukkitItems[index] = new CraftItemStack(item);
index++;
}
npc.getTrait(net.citizensnpcs.api.npc.trait.trait.Inventory.class).setContents(bukkitItems);
}
@Override