mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-01 13:01:41 +01:00
Add IItemDb#isReady to check if item database is available
This commit is contained in:
parent
d24b0616f8
commit
32540c23ab
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user