From 51d55ac6262000919eb93b0ab9bd73479940da2b Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Mon, 28 Mar 2022 10:04:31 -0400 Subject: [PATCH] Delay loading of bungee data --- .../listeners/BungeePlayerListener.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bungee/src/main/java/me/blackvein/quests/listeners/BungeePlayerListener.java b/bungee/src/main/java/me/blackvein/quests/listeners/BungeePlayerListener.java index 769c1da13..594072e20 100644 --- a/bungee/src/main/java/me/blackvein/quests/listeners/BungeePlayerListener.java +++ b/bungee/src/main/java/me/blackvein/quests/listeners/BungeePlayerListener.java @@ -1,6 +1,7 @@ package me.blackvein.quests.listeners; import me.blackvein.quests.QuestsBungee; +import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.ServerSwitchEvent; @@ -10,6 +11,7 @@ import net.md_5.bungee.event.EventHandler; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.util.concurrent.TimeUnit; public class BungeePlayerListener implements Listener { private static final String CHANNEL = "quests:update"; @@ -33,14 +35,17 @@ public class BungeePlayerListener implements Listener { dispatchMessage(byteArrayOutputStream.toByteArray()); } - final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); - try { - dataOutputStream.writeUTF("LoadData:" + evt.getPlayer().getUniqueId()); - } catch (IOException e) { - e.printStackTrace(); - } - dispatchMessage(byteArrayOutputStream.toByteArray()); + ProxyServer.getInstance().getScheduler().schedule(plugin, () -> { + final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); + try { + dataOutputStream.writeUTF("LoadData:" + evt.getPlayer().getUniqueId()); + } catch (IOException e) { + e.printStackTrace(); + } + dispatchMessage(byteArrayOutputStream.toByteArray()); + }, 1, TimeUnit.SECONDS); + } @EventHandler