Move over some discord things

This commit is contained in:
Josh Roy 2023-03-30 13:28:41 -04:00
parent 9a5ac3cad8
commit 4ff9286a79
No known key found for this signature in database
GPG Key ID: 64C8142336ED1F69
2 changed files with 6 additions and 6 deletions

View File

@ -25,7 +25,7 @@ public class DiscordCommandDispatcher extends ListenerAdapter {
}
final String command = event.getMessage().getContentRaw();
Bukkit.getScheduler().runTask(jda.getPlugin(), () -> {
jda.getPlugin().getEss().scheduleGlobalDelayedTask(() -> {
try {
Bukkit.dispatchCommand(new DiscordCommandSender(jda, Bukkit.getConsoleSender(), message ->
event.getMessage().reply(message).queue()).getSender(), command);

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.utils.FormatUtil;
import com.google.common.base.Splitter;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.utils.TimeFormat;
import net.ess3.provider.SchedulingProvider;
import net.essentialsx.discord.EssentialsDiscord;
import net.essentialsx.discord.JDADiscordService;
import org.apache.logging.log4j.LogManager;
@ -11,7 +12,6 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.bukkit.Bukkit;
import java.time.Instant;
import java.util.concurrent.BlockingQueue;
@ -26,14 +26,14 @@ public class ConsoleInjector extends AbstractAppender {
private final JDADiscordService jda;
private final BlockingQueue<String> messageQueue = new LinkedBlockingQueue<>();
private final int taskId;
private final SchedulingProvider.EssentialsTask task;
private boolean removed = false;
public ConsoleInjector(JDADiscordService jda) {
super("EssentialsX-ConsoleInjector", null, null, false);
this.jda = jda;
((Logger) LogManager.getRootLogger()).addAppender(this);
taskId = Bukkit.getScheduler().runTaskTimerAsynchronously(jda.getPlugin(), () -> {
task = jda.getPlugin().getEss().runTaskTimerAsynchronously(() -> {
final StringBuilder buffer = new StringBuilder();
String curLine;
while ((curLine = messageQueue.peek()) != null) {
@ -47,7 +47,7 @@ public class ConsoleInjector extends AbstractAppender {
if (buffer.length() != 0) {
sendMessage(buffer.toString());
}
}, 20, 40).getTaskId();
}, 20, 40);
}
private void sendMessage(String content) {
@ -92,7 +92,7 @@ public class ConsoleInjector extends AbstractAppender {
public void remove() {
((Logger) LogManager.getRootLogger()).removeAppender(this);
Bukkit.getScheduler().cancelTask(taskId);
task.cancel();
messageQueue.clear();
removed = true;
}