Skip to content

Commit

Permalink
Allow dynamic sizes for inventory scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Dec 29, 2014
1 parent 6a6211f commit f923e81
Showing 1 changed file with 12 additions and 11 deletions.
Expand Up @@ -74,11 +74,6 @@ public InventoryScriptContainer(YamlConfiguration configurationSection, String s

public Map<String, dItem> definitions = new HashMap<String, dItem>();

public int getSize() {
InventoryType invType = getInventoryType();
return aH.getIntegerFrom(getString("SIZE", String.valueOf(invType.getDefaultSize())));
}

public InventoryType getInventoryType() {
String typeStr = getString("inventory", "CHEST");

Expand Down Expand Up @@ -110,16 +105,17 @@ public dInventory getInventoryFrom(dPlayer player, dNPC npc) {
dB.echoError("Invalid inventory type specified. Assuming \"CHEST\"");
}
}
int size = 0;
if (contains("SIZE")) {
if (inventory != null && !getInventoryType().name().equalsIgnoreCase("CHEST")) {
dB.echoError("You can only set the size of chest inventories!");
}
else {
int size = aH.getIntegerFrom(getString("SIZE"));
size = aH.getIntegerFrom(TagManager.tag(getString("SIZE"),
new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this))));

if (size == 0) {
size = 27;
dB.echoError("Inventory size can't be 0. Assuming default of 27...");
dB.echoError("Inventory size can't be 0. Assuming default of inventory type...");
}
if (size % 9 != 0) {
size = (int) Math.ceil(size/9)*9;
Expand All @@ -136,11 +132,16 @@ public dInventory getInventoryFrom(dPlayer player, dNPC npc) {
inventory.setIdentifiers("script", getName());
}
}
if (size == 0) {
size = getInventoryType().getDefaultSize();
}
if (contains("SLOTS")) {
ItemStack[] finalItems = new ItemStack[getSize()];
ItemStack[] finalItems = new ItemStack[size];
int itemsAdded = 0;
for (String items : getStringList("SLOTS")) {
items = TagManager.tag(items, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
items = TagManager.tag(items, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this))).trim();
if (items.isEmpty())
continue;
String[] itemsInLine = items.split(" ");
for (String item : itemsInLine) {
Matcher m = fromPattern.matcher(item);
Expand Down Expand Up @@ -171,7 +172,7 @@ else if (dItem.matches(m.group(2))) {
}
}
if (inventory == null) {
int size = finalItems.length%9==0?finalItems.length:Math.round(finalItems.length/9)*9;
size = finalItems.length%9==0?finalItems.length:Math.round(finalItems.length/9)*9;
inventory = new dInventory(size==0?9:size,
contains("TITLE") ? TagManager.tag(getString("TITLE"),
new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this))) : "Chest");
Expand Down

0 comments on commit f923e81

Please sign in to comment.