From b3fea81135372ed4df417a1fb9173678375583fa Mon Sep 17 00:00:00 2001 From: Draycia Date: Wed, 2 Dec 2020 20:23:20 -0800 Subject: [PATCH] Handle failed player list gathering --- .../carbon/bukkit/CarbonChatBukkit.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/CarbonChatBukkit.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/CarbonChatBukkit.java index a12329e8..8aa62c21 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/CarbonChatBukkit.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/bukkit/CarbonChatBukkit.java @@ -68,6 +68,8 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.plugin.messaging.ChannelNotRegisteredException; +import org.bukkit.scheduler.BukkitRunnable; import org.checkerframework.checker.nullness.qual.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -145,12 +147,23 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat { this.messageManager = new MessageManager(this, messageService); - Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> { - if (Bukkit.getOnlinePlayers().size() > 0) { - BungeeChannelApi.of(this).getPlayerList("ALL") - .thenAccept(value -> this.proxyPlayerNames = value); + new BukkitRunnable() { + @Override + public void run() { + try { + if (Bukkit.getOnlinePlayers().size() > 0) { + BungeeChannelApi.of(CarbonChatBukkit.this).getPlayerList("ALL") + .thenAccept(value -> CarbonChatBukkit.this.proxyPlayerNames = value); + } + } catch (final ChannelNotRegisteredException exception) { + CarbonChatBukkit.this.logger().info("Exception thrown when gathering proxy player list!"); + CarbonChatBukkit.this.logger().info("Aborting attempts to communicate to the proxy."); + CarbonChatBukkit.this.logger().info("This is merely for command completions, don't worry."); + + this.cancel(); + } } - }, 1, 5 * 20); // 5 seconds * 20 ticks per second + }.runTaskTimer(this, 1, 5*20); // Handle storage service final StorageType storageType = this.carbonSettings().storageType();