inventories now use the full name of an NPC

This commit is contained in:
aPunch 2012-02-07 02:31:28 -06:00
parent b8bc6df251
commit 13ebcb54cc
6 changed files with 12 additions and 12 deletions

Binary file not shown.

View File

@ -171,11 +171,10 @@ public class Citizens extends JavaPlugin {
config.load(); config.load();
// NPC storage // NPC storage
if (Setting.USE_DATABASE.asBoolean()) { if (Setting.USE_DATABASE.asBoolean())
saves = new DatabaseStorage(); saves = new DatabaseStorage();
} else { else
saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml"); saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml");
}
// Register API managers // Register API managers
npcManager = new CitizensNPCManager(saves); npcManager = new CitizensNPCManager(saves);

View File

@ -8,6 +8,7 @@ import net.citizensnpcs.api.npc.trait.trait.Spawned;
import net.citizensnpcs.npc.ai.CitizensAI; import net.citizensnpcs.npc.ai.CitizensAI;
import net.citizensnpcs.trait.Inventory; import net.citizensnpcs.trait.Inventory;
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;

View File

@ -1,5 +1,6 @@
package net.citizensnpcs.npc; package net.citizensnpcs.npc;
import net.citizensnpcs.util.StringHelper;
import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityHuman;
import net.minecraft.server.IInventory; import net.minecraft.server.IInventory;
import net.minecraft.server.ItemStack; import net.minecraft.server.ItemStack;
@ -19,7 +20,7 @@ public class NPCInventory implements IInventory {
public NPCInventory(CitizensNPC npc) { public NPCInventory(CitizensNPC npc) {
this.npc = npc; this.npc = npc;
name = npc.getName(); name = StringHelper.parseColors(npc.getFullName());
contents = new ItemStack[size]; contents = new ItemStack[size];
} }

View File

@ -55,4 +55,4 @@ public class CommandContextTest {
private static CommandContext getContext(String cmd) { private static CommandContext getContext(String cmd) {
return new CommandContext("dummy " + cmd); return new CommandContext("dummy " + cmd);
} }
} }

View File

@ -39,21 +39,20 @@ public class Inventory implements Trait {
@Override @Override
public void save(DataKey key) { public void save(DataKey key) {
int index = 0; int slot = 0;
for (ItemStack item : contents) { for (ItemStack item : contents) {
// Clear previous items to avoid conflicts // Clear previous items to avoid conflicts
key.removeKey(String.valueOf(index)); key.removeKey(String.valueOf(slot));
if (item != null) if (item != null)
saveItem(item, key.getRelative(String.valueOf(index))); saveItem(item, key.getRelative(String.valueOf(slot)));
index++; slot++;
} }
} }
private ItemStack[] parseContents(DataKey key) throws NPCLoadException { private ItemStack[] parseContents(DataKey key) throws NPCLoadException {
ItemStack[] contents = new ItemStack[36]; ItemStack[] contents = new ItemStack[36];
for (DataKey slotKey : key.getIntegerSubKeys()) { for (DataKey slotKey : key.getIntegerSubKeys())
contents[Integer.parseInt(slotKey.name())] = getItemStack(slotKey); contents[Integer.parseInt(slotKey.name())] = getItemStack(slotKey);
}
return contents; return contents;
} }
@ -91,6 +90,6 @@ public class Inventory implements Trait {
@Override @Override
public String toString() { public String toString() {
return "Inventory{contents:" + contents + "}"; return "Inventory{" + contents + "}";
} }
} }