From c5ac3c9b3d77cdf679360fabcc8bf32993765040 Mon Sep 17 00:00:00 2001 From: Myles Date: Sun, 6 Mar 2016 13:49:33 +0000 Subject: [PATCH] Don't freeze current thread when sending chunks --- .../java/us/myles/ViaVersion/ViaVersionPlugin.java | 10 +++++++--- .../us/myles/ViaVersion/handlers/ViaEncodeHandler.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java index a85c23f9d..ccd2d7fb0 100644 --- a/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java +++ b/src/main/java/us/myles/ViaVersion/ViaVersionPlugin.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { @@ -158,15 +159,18 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { } } - public void run(final Runnable runnable) { + public void run(final Runnable runnable, boolean wait) { try { - Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable() { + Future f = Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable() { @Override public Boolean call() throws Exception { runnable.run(); return true; } - }).get(10, TimeUnit.SECONDS); + }); + if(wait){ + f.get(10, TimeUnit.SECONDS); + } } catch (Exception e) { System.out.println("Failed to run task."); e.printStackTrace(); diff --git a/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java b/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java index 5c26ef5a8..7ee679bb5 100644 --- a/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java +++ b/src/main/java/us/myles/ViaVersion/handlers/ViaEncodeHandler.java @@ -68,7 +68,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder { }; // Synced allows timings to work properly. if (ViaVersion.getInstance().isSyncedChunks()) { - ((ViaVersionPlugin) ViaVersion.getInstance()).run(chunks); + ((ViaVersionPlugin) ViaVersion.getInstance()).run(chunks, false); } else { chunks.run(); }