mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 20:25:19 +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.api.npc.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.npc.ai.CitizensAI;
|
import net.citizensnpcs.npc.ai.CitizensAI;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
|
|
||||||
import net.minecraft.server.EntityLiving;
|
import net.minecraft.server.EntityLiving;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -19,14 +20,13 @@ import org.bukkit.entity.Player;
|
|||||||
public abstract class CitizensNPC extends AbstractNPC {
|
public abstract class CitizensNPC extends AbstractNPC {
|
||||||
protected final CitizensNPCManager manager;
|
protected final CitizensNPCManager manager;
|
||||||
protected final CitizensAI ai = new CitizensAI(this);
|
protected final CitizensAI ai = new CitizensAI(this);
|
||||||
protected final NPCInventory inventory;
|
|
||||||
protected EntityLiving mcEntity;
|
protected EntityLiving mcEntity;
|
||||||
|
protected final NPCInventory inventory;
|
||||||
|
|
||||||
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.inventory = new NPCInventory(this);
|
inventory = new NPCInventory(this);
|
||||||
addTrait(new Inventory(inventory.asInventory()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -110,6 +110,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
public boolean openInventory(Player player) {
|
public boolean openInventory(Player player) {
|
||||||
if (!isSpawned())
|
if (!isSpawned())
|
||||||
return false;
|
return false;
|
||||||
|
getInventory().setContents(getTrait(Inventory.class).getContents());
|
||||||
inventory.show(player);
|
inventory.show(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,16 +8,19 @@ import net.minecraft.server.ItemStack;
|
|||||||
|
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
public class NPCInventory implements IInventory {
|
public class NPCInventory implements IInventory {
|
||||||
private final int size = 36;
|
private final int size = 36;
|
||||||
|
private final NPC npc;
|
||||||
private final ItemStack[] contents;
|
private final ItemStack[] contents;
|
||||||
private final Inventory inventory = new CraftInventory(this);
|
private final Inventory inventory = new CraftInventory(this);
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public NPCInventory(NPC npc) {
|
public NPCInventory(NPC npc) {
|
||||||
|
this.npc = npc;
|
||||||
name = StringHelper.parseColors(npc.getFullName());
|
name = StringHelper.parseColors(npc.getFullName());
|
||||||
contents = new ItemStack[size];
|
contents = new ItemStack[size];
|
||||||
}
|
}
|
||||||
@ -76,6 +79,16 @@ public class NPCInventory implements IInventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void g() {
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user