mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-06-17 14:21:33 +00:00
make MMOItems getItemTypes synchronous to reduce lag
This commit is contained in:
@@ -42,11 +42,9 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
if (parts.length != 2)
|
if (parts.length != 2)
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
CompletableFuture<ItemStack> future = new CompletableFuture<>();
|
CompletableFuture<ItemStack> future = new CompletableFuture<>();
|
||||||
if (Bukkit.isPrimaryThread()) {
|
Runnable run = () -> future.complete(api().getItem(parts[1], itemId.key()));
|
||||||
future.complete(api().getItem(parts[1], itemId.key()));
|
if (Bukkit.isPrimaryThread()) run.run();
|
||||||
} else {
|
else J.s(run);
|
||||||
J.s(() -> future.complete(api().getItem(parts[1], itemId.key())));
|
|
||||||
}
|
|
||||||
ItemStack item = null;
|
ItemStack item = null;
|
||||||
try {
|
try {
|
||||||
item = future.get();
|
item = future.get();
|
||||||
@@ -73,15 +71,26 @@ public class MMOItemsDataProvider extends ExternalDataProvider {
|
|||||||
@Override
|
@Override
|
||||||
public Identifier[] getItemTypes() {
|
public Identifier[] getItemTypes() {
|
||||||
KList<Identifier> names = new KList<>();
|
KList<Identifier> names = new KList<>();
|
||||||
for (Type type : api().getTypes().getAll()) {
|
Runnable run = () -> {
|
||||||
for (String name : api().getTemplates().getTemplateNames(type)) {
|
for (Type type : api().getTypes().getAll()) {
|
||||||
try {
|
for (String name : api().getTemplates().getTemplateNames(type)) {
|
||||||
Identifier key = new Identifier("mmoitems_" + type.getId(), name);
|
try {
|
||||||
if (getItemStack(key) != null)
|
Identifier key = new Identifier("mmoitems_" + type.getId(), name);
|
||||||
names.add(key);
|
if (getItemStack(key) != null)
|
||||||
} catch (MissingResourceException ignored) {
|
names.add(key);
|
||||||
|
} catch (MissingResourceException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
if (Bukkit.isPrimaryThread()) run.run();
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
J.sfut(run).get();
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
Iris.error("Failed getting MMOItems item types!");
|
||||||
|
Iris.reportError(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return names.toArray(new Identifier[0]);
|
return names.toArray(new Identifier[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user