3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Don't freeze current thread when sending chunks

Dieser Commit ist enthalten in:
Myles 2016-03-06 13:49:33 +00:00
Ursprung 0ea32b3318
Commit c5ac3c9b3d
2 geänderte Dateien mit 8 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class ViaVersionPlugin extends JavaPlugin implements ViaVersionAPI { 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 { try {
Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Boolean>() { Future f = Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Boolean>() {
@Override @Override
public Boolean call() throws Exception { public Boolean call() throws Exception {
runnable.run(); runnable.run();
return true; return true;
} }
}).get(10, TimeUnit.SECONDS); });
if(wait){
f.get(10, TimeUnit.SECONDS);
}
} catch (Exception e) { } catch (Exception e) {
System.out.println("Failed to run task."); System.out.println("Failed to run task.");
e.printStackTrace(); e.printStackTrace();

Datei anzeigen

@ -68,7 +68,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
}; };
// Synced allows timings to work properly. // Synced allows timings to work properly.
if (ViaVersion.getInstance().isSyncedChunks()) { if (ViaVersion.getInstance().isSyncedChunks()) {
((ViaVersionPlugin) ViaVersion.getInstance()).run(chunks); ((ViaVersionPlugin) ViaVersion.getInstance()).run(chunks, false);
} else { } else {
chunks.run(); chunks.run();
} }