mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 12:15:53 +01:00
parent
ffe0fecc9b
commit
cfb7bfe1e0
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user