3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 00:22:51 +01:00

Queue tasks & Fix PPS

Dieser Commit ist enthalten in:
Myles 2016-09-25 21:02:12 +01:00
Ursprung 0fe9ccf4a8
Commit a1fbca11f0
3 geänderte Dateien mit 31 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -23,9 +23,6 @@ import us.myles.ViaVersion.util.ReflectionUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
@ -38,6 +35,8 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
private ViaConfig conf; private ViaConfig conf;
@Getter @Getter
private ViaAPI<Player> api = new BukkitViaAPI(this); private ViaAPI<Player> api = new BukkitViaAPI(this);
private List<Runnable> queuedTasks = new ArrayList<>();
private List<Runnable> asyncQueuedTasks = new ArrayList<>();
public ViaVersionPlugin() { public ViaVersionPlugin() {
// Config magic // Config magic
@ -106,6 +105,18 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
if (conf.isAntiXRay() && !spigot) { if (conf.isAntiXRay() && !spigot) {
getLogger().info("You have anti-xray on in your config, since you're not using spigot it won't fix xray!"); getLogger().info("You have anti-xray on in your config, since you're not using spigot it won't fix xray!");
} }
// Run queued tasks
for (Runnable r : queuedTasks) {
Bukkit.getScheduler().runTask(this, r);
}
queuedTasks.clear();
// Run async queued tasks
for (Runnable r : asyncQueuedTasks) {
Bukkit.getScheduler().runTaskAsynchronously(this, r);
}
asyncQueuedTasks.clear();
} }
@Override @Override
@ -122,25 +133,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
return this.spigot; return this.spigot;
} }
public void run(final Runnable runnable, boolean wait) {
try {
Future f = Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
runnable.run();
return true;
}
});
if (wait) {
f.get(10, TimeUnit.SECONDS);
}
} catch (Exception e) {
System.out.println("Failed to run task: " + e.getClass().getName());
if (ViaVersion.getInstance().isDebug())
e.printStackTrace();
}
}
public boolean isProtocolSupport() { public boolean isProtocolSupport() {
return protocolSupport; return protocolSupport;
} }
@ -187,12 +179,22 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
@Override @Override
public int runAsync(Runnable runnable) { public int runAsync(Runnable runnable) {
return getServer().getScheduler().runTaskAsynchronously(this, runnable).getTaskId(); if (isPluginEnabled()) {
return getServer().getScheduler().runTaskAsynchronously(this, runnable).getTaskId();
} else {
asyncQueuedTasks.add(runnable);
return -1;
}
} }
@Override @Override
public int runSync(Runnable runnable) { public int runSync(Runnable runnable) {
return getServer().getScheduler().runTask(this, runnable).getTaskId(); if (isPluginEnabled()) {
return getServer().getScheduler().runTask(this, runnable).getTaskId();
} else {
queuedTasks.add(runnable);
return -1;
}
} }
@Override @Override

Datei anzeigen

@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -38,7 +39,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
boolean second = info.incrementReceived(); boolean second = info.incrementReceived();
// Check PPS // Check PPS
if (second) { if (second) {
if (((ViaVersionPlugin) ViaVersion.getInstance()).handlePPS(info)) if (((ViaVersionPlugin) Via.getPlatform()).handlePPS(info))
return; return;
} }

Datei anzeigen

@ -3,7 +3,9 @@ package us.myles.ViaVersion.handlers;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@ -27,7 +29,7 @@ public class ViaEncodeHandler extends MessageToByteEncoder {
@Override @Override
protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception { protected void encode(final ChannelHandlerContext ctx, Object o, final ByteBuf bytebuf) throws Exception {
if (ViaVersion.getInstance().isCompatSpigotBuild()) { if (((ViaVersionPlugin) Via.getPlatform()).isCompatSpigotBuild()) {
Field ver = minecraftEncoder.getClass().getDeclaredField("version"); Field ver = minecraftEncoder.getClass().getDeclaredField("version");
ver.setAccessible(true); ver.setAccessible(true);
ver.set(minecraftEncoder, ver.get(this)); ver.set(minecraftEncoder, ver.get(this));