Skip to content

Commit

Permalink
Add IItemDb#isReady to check if item database is available
Browse files Browse the repository at this point in the history
  • Loading branch information
mdcfe committed Jan 12, 2019
1 parent d24b061 commit 32540c2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Essentials/src/com/earth2me/essentials/api/IItemDb.java
Expand Up @@ -153,4 +153,11 @@ default Material getFromLegacy(String item) {
default Material getFromLegacy(final int id, final byte damage) {
return MaterialUtil.convertFromLegacy(id, damage);
}

/**
* Check whether the item database is loaded and ready for use.
*
* @return Whether items have finished loading
*/
boolean isReady();
}
Expand Up @@ -27,6 +27,8 @@

public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {

protected boolean ready = false;

@Override
public List<ItemStack> getMatching(User user, String[] args) throws Exception {
List<ItemStack> is = new ArrayList<>();
Expand Down Expand Up @@ -224,4 +226,9 @@ public String serialize(ItemStack is) {

return sb.toString().trim().replaceAll("§", "&");
}

@Override
public boolean isReady() {
return ready;
}
}
3 changes: 3 additions & 0 deletions Essentials/src/com/earth2me/essentials/items/FlatItemDb.java
Expand Up @@ -59,9 +59,12 @@ private void rebuild() {
.collect(Collectors.joining());

this.loadJSON(String.join("\n", json));

ready = true;
}

private void reset() {
ready = false;
items.clear();
itemAliases.clear();
allAliases.clear();
Expand Down
Expand Up @@ -44,6 +44,7 @@ public void reloadConfig() {
return;
}

ready = false;
durabilities.clear();
items.clear();
names.clear();
Expand Down Expand Up @@ -115,6 +116,8 @@ public void reloadConfig() {
}

LOGGER.info(String.format("Loaded %s items from items.csv.", listNames().size()));

ready = true;
}

@Override
Expand Down

0 comments on commit 32540c2

Please sign in to comment.