Load amount of legacy items

This commit is contained in:
PikaMug 2023-12-11 21:21:47 -05:00
parent f565a6d263
commit a587a0c1c0
2 changed files with 24 additions and 9 deletions

View File

@ -225,12 +225,17 @@ public class BukkitActionYamlStorage implements ActionStorageImpl {
for (final Object item : itemList) { for (final Object item : itemList) {
final String stack = (String) item; final String stack = (String) item;
if (stack != null) { if (stack != null) {
final String itemName = stack.substring(5, stack.indexOf(':')); final String[] result = stack.split(":");
if (result.length < 1) {
throw new ActionFormatException("'items' has invalid length", actionKey);
}
final String itemName = result[0].replace("name-", "");
final Material itemMat = Material.matchMaterial(itemName); final Material itemMat = Material.matchMaterial(itemName);
final int itemAmt = Integer.parseInt(result[1].replace("amount-", ""));
if (itemMat != null) { if (itemMat != null) {
temp.add(new ItemStack(itemMat, 1)); temp.add(new ItemStack(itemMat, itemAmt));
} else { } else {
throw new ActionFormatException("'items' has invalid name" + itemName, actionKey); throw new ActionFormatException("'items' has invalid name " + itemName, actionKey);
} }
} }
} }

View File

@ -348,12 +348,17 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
for (final Object item : itemList) { for (final Object item : itemList) {
final String stack = (String) item; final String stack = (String) item;
if (stack != null) { if (stack != null) {
final String itemName = stack.substring(5, stack.indexOf(':')); final String[] result = stack.split(":");
if (result.length < 1) {
throw new QuestFormatException("Reward 'items' has invalid length", questKey);
}
final String itemName = result[0].replace("name-", "");
final Material itemMat = Material.matchMaterial(itemName); final Material itemMat = Material.matchMaterial(itemName);
final int itemAmt = Integer.parseInt(result[1].replace("amount-", ""));
if (itemMat != null) { if (itemMat != null) {
temp.add(new ItemStack(itemMat, 1)); temp.add(new ItemStack(itemMat, itemAmt));
} else { } else {
throw new QuestFormatException("Reward 'items' has invalid name" + itemName, questKey); throw new QuestFormatException("Reward 'items' has invalid name " + itemName, questKey);
} }
} }
} }
@ -534,12 +539,17 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl {
for (final Object item : itemList) { for (final Object item : itemList) {
final String stack = (String) item; final String stack = (String) item;
if (stack != null) { if (stack != null) {
final String itemName = stack.substring(5, stack.indexOf(':')); final String[] result = stack.split(":");
if (result.length < 1) {
throw new QuestFormatException("Requirement 'items' has invalid length", questKey);
}
final String itemName = result[0].replace("name-", "");
final Material itemMat = Material.matchMaterial(itemName); final Material itemMat = Material.matchMaterial(itemName);
final int itemAmt = Integer.parseInt(result[1].replace("amount-", ""));
if (itemMat != null) { if (itemMat != null) {
temp.add(new ItemStack(itemMat, 1)); temp.add(new ItemStack(itemMat, itemAmt));
} else { } else {
throw new QuestFormatException("Requirement 'items' has invalid name" + itemName, questKey); throw new QuestFormatException("Requirement 'items' has invalid name " + itemName, questKey);
} }
} }
} }