mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-29 23:57:42 +02:00
Changes to inventories
This commit is contained in:
parent
659b1c7dde
commit
ffe0fecc9b
@ -9,7 +9,6 @@ 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;
|
||||||
@ -20,13 +19,14 @@ 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 EntityLiving mcEntity;
|
|
||||||
protected final NPCInventory inventory;
|
protected final NPCInventory inventory;
|
||||||
|
protected EntityLiving mcEntity;
|
||||||
|
|
||||||
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;
|
||||||
inventory = new NPCInventory(this);
|
this.inventory = new NPCInventory(this);
|
||||||
|
addTrait(new Inventory(inventory.asInventory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -110,7 +110,6 @@ 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,19 +8,16 @@ 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];
|
||||||
}
|
}
|
||||||
@ -79,16 +76,6 @@ 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