Extra check when loading MMOItemTriggers

This commit is contained in:
Aria Sangarin 2020-02-26 19:18:40 +01:00
parent 3f5ad1a883
commit ddb7468db1
2 changed files with 7 additions and 2 deletions

View File

@ -25,9 +25,9 @@ public class MMOItemTrigger extends Trigger {
Validate.isTrue(MMOItems.plugin.getTypes().has(format), "Could not find item type " + format);
type = MMOItems.plugin.getTypes().get(format);
id = config.getString("id");
id = config.getString("id").replace("-", "_").toUpperCase();
amount = config.args().length > 0 ? Math.max(1, Integer.parseInt(config.args()[0])) : 1;
Validate.isTrue(MMOItems.plugin.getItems().getItem(type, id) != null, "Could not find item id " + id);
Validate.isTrue(MMOItems.plugin.getItems().exists(type, id), "Could not find item id " + id);
}
@Override

View File

@ -71,6 +71,11 @@ public class ItemManager extends BukkitRunnable {
return item == null ? null : item.newBuilder().build();
}
public boolean exists(Type type, String id) {
if(type == null) return false;
return type.getConfigFile().getConfig().contains(id.replace("-", "_").toUpperCase());
}
/*
* every two minutes, loops through any loaded item and uncaches any if they
* have not been generated for more than 5 minutes.