Add IItemDb#isReady to check if item database is available

This commit is contained in:
md678685 2019-01-12 20:44:02 +00:00
parent d24b0616f8
commit 32540c23ab
4 changed files with 20 additions and 0 deletions

View file

@ -153,4 +153,11 @@ public interface IItemDb {
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();
}

View file

@ -27,6 +27,8 @@ import static com.earth2me.essentials.I18n.tl;
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<>();
@ -224,4 +226,9 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
return sb.toString().trim().replaceAll("§", "&");
}
@Override
public boolean isReady() {
return ready;
}
}

View file

@ -59,9 +59,12 @@ public class FlatItemDb extends AbstractItemDb {
.collect(Collectors.joining());
this.loadJSON(String.join("\n", json));
ready = true;
}
private void reset() {
ready = false;
items.clear();
itemAliases.clear();
allAliases.clear();

View file

@ -44,6 +44,7 @@ public class LegacyItemDb extends AbstractItemDb {
return;
}
ready = false;
durabilities.clear();
items.clear();
names.clear();
@ -115,6 +116,8 @@ public class LegacyItemDb extends AbstractItemDb {
}
LOGGER.info(String.format("Loaded %s items from items.csv.", listNames().size()));
ready = true;
}
@Override