Revert "Changes to inventories"

This reverts commit bca4ed1979.
This commit is contained in:
fullwall 2012-02-14 19:38:44 +08:00
parent bca4ed1979
commit 7d8f0fb9bb
2 changed files with 17 additions and 3 deletions

View File

@ -9,6 +9,7 @@ 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;
@ -19,14 +20,13 @@ import org.bukkit.entity.Player;
public abstract class CitizensNPC extends AbstractNPC {
protected final CitizensNPCManager manager;
protected final CitizensAI ai = new CitizensAI(this);
protected final NPCInventory inventory;
protected EntityLiving mcEntity;
protected final NPCInventory inventory;
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
super(id, name);
this.manager = manager;
this.inventory = new NPCInventory(this);
addTrait(new Inventory(inventory.asInventory()));
inventory = new NPCInventory(this);
}
@Override
@ -110,6 +110,7 @@ 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,16 +8,19 @@ 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];
}
@ -76,6 +79,16 @@ 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