run it in an executor service
This commit is contained in:
parent
c2894c64d2
commit
69a64eae28
1 changed files with 153 additions and 155 deletions
|
@ -53,6 +53,7 @@ public class MailCommand extends Command {
|
||||||
|
|
||||||
// kinda messy ngl
|
// kinda messy ngl
|
||||||
|
|
||||||
|
bot.executorService().submit(() -> {
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "send" -> {
|
case "send" -> {
|
||||||
int senderMailsSentTotal = 0;
|
int senderMailsSentTotal = 0;
|
||||||
|
@ -65,7 +66,7 @@ public class MailCommand extends Command {
|
||||||
senderMailsSentTotal++;
|
senderMailsSentTotal++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (senderMailsSentTotal > 256) return Component.text("You are sending too much mails!").color(NamedTextColor.RED);
|
if (senderMailsSentTotal > 256) context.sendOutput(Component.text("You are sending too much mails!").color(NamedTextColor.RED));
|
||||||
|
|
||||||
bot.mail().send(
|
bot.mail().send(
|
||||||
new Mail(
|
new Mail(
|
||||||
|
@ -77,7 +78,7 @@ public class MailCommand extends Command {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return Component.text("Mail sent!").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor()));
|
context.sendOutput(Component.text("Mail sent!").color(ColorUtilities.getColorByString(bot.config().colorPalette().defaultColor())));
|
||||||
}
|
}
|
||||||
case "sendselecteditem" -> {
|
case "sendselecteditem" -> {
|
||||||
int senderMailsSentTotal = 0;
|
int senderMailsSentTotal = 0;
|
||||||
|
@ -88,7 +89,7 @@ public class MailCommand extends Command {
|
||||||
senderMailsSentTotal++;
|
senderMailsSentTotal++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (senderMailsSentTotal > 256) return Component.text("You are sending too much mails!").color(NamedTextColor.RED);
|
if (senderMailsSentTotal > 256) context.sendOutput(Component.text("You are sending too much mails!").color(NamedTextColor.RED));
|
||||||
|
|
||||||
final CompletableFuture<CompoundTag> future = bot.core().runTracked(
|
final CompletableFuture<CompoundTag> future = bot.core().runTracked(
|
||||||
"minecraft:data get entity " +
|
"minecraft:data get entity " +
|
||||||
|
@ -96,7 +97,7 @@ public class MailCommand extends Command {
|
||||||
" SelectedItem.tag.message"
|
" SelectedItem.tag.message"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (future == null) return Component.text("There was an error while sending your mail").color(NamedTextColor.RED);
|
if (future == null) context.sendOutput(Component.text("There was an error while sending your mail").color(NamedTextColor.RED));
|
||||||
|
|
||||||
future.thenApply(tags -> {
|
future.thenApply(tags -> {
|
||||||
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
if (!tags.contains("LastOutput") || !(tags.get("LastOutput") instanceof StringTag)) return tags;
|
||||||
|
@ -138,8 +139,6 @@ public class MailCommand extends Command {
|
||||||
|
|
||||||
return tags;
|
return tags;
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
case "read" -> {
|
case "read" -> {
|
||||||
// TODO: use less for loops?
|
// TODO: use less for loops?
|
||||||
|
@ -152,7 +151,7 @@ public class MailCommand extends Command {
|
||||||
senderMailSize++;
|
senderMailSize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (senderMailSize == 0) return Component.text("You have no new mails").color(NamedTextColor.RED);
|
if (senderMailSize == 0) context.sendOutput(Component.text("You have no new mails").color(NamedTextColor.RED));
|
||||||
|
|
||||||
final List<Component> mailsComponent = new ArrayList<>();
|
final List<Component> mailsComponent = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -220,12 +219,11 @@ public class MailCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataUtilities.put("mails", MailPlugin.mails());
|
PersistentDataUtilities.put("mails", MailPlugin.mails());
|
||||||
|
}
|
||||||
|
default -> context.sendOutput(Component.text("Invalid argument").color(NamedTextColor.RED));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
default -> {
|
|
||||||
return Component.text("Invalid argument").color(NamedTextColor.RED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue