Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Use only one task for tab completing
Dieser Commit ist enthalten in:
Ursprung
bce3593110
Commit
63b743f85b
@ -857,27 +857,9 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
|||||||
wrapper.write(Type.OPTIONAL_POSITION, null);
|
wrapper.write(Type.OPTIONAL_POSITION, null);
|
||||||
if (!wrapper.isCancelled() && Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
if (!wrapper.isCancelled() && Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
||||||
TabCompleteTracker tracker = wrapper.user().get(TabCompleteTracker.class);
|
TabCompleteTracker tracker = wrapper.user().get(TabCompleteTracker.class);
|
||||||
if (tracker.getLastTabCompleteTask() != null) {
|
|
||||||
Via.getPlatform().cancelTask(tracker.getLastTabCompleteTask());
|
|
||||||
}
|
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
wrapper.resetReader();
|
tracker.setTimeToSend(System.currentTimeMillis() + Via.getConfig().get1_13TabCompleteDelay() * 50);
|
||||||
final PacketWrapper delayedPacket = wrapper.create(0x1);
|
tracker.setLastTabComplete(wrapper.get(Type.STRING, 0));
|
||||||
delayedPacket.write(Type.STRING, wrapper.read(Type.STRING));
|
|
||||||
delayedPacket.write(Type.BOOLEAN, false);
|
|
||||||
delayedPacket.write(Type.OPTIONAL_POSITION, null);
|
|
||||||
tracker.setLastTabCompleteTask(
|
|
||||||
Via.getPlatform().runSync(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
delayedPacket.sendToServer(Protocol1_13To1_12_2.class);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, (long) Via.getConfig().get1_13TabCompleteDelay())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1164,6 +1146,9 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
|||||||
userConnection.put(new BlockConnectionStorage(userConnection));
|
userConnection.put(new BlockConnectionStorage(userConnection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Via.getConfig().get1_13TabCompleteDelay() > 0) {
|
||||||
|
Via.getPlatform().runRepeatingSync(new TabCompleteThread(), 1L);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2;
|
||||||
|
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker;
|
||||||
|
|
||||||
|
public class TabCompleteThread implements Runnable {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (UserConnection info : Via.getManager().getPortedPlayers().values()) {
|
||||||
|
if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_13To1_12_2.class)) {
|
||||||
|
if (info.getChannel().isOpen()) {
|
||||||
|
info.get(TabCompleteTracker.class).sendPacketToServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,18 +2,35 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.data.StoredObject;
|
import us.myles.ViaVersion.api.data.StoredObject;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.platform.TaskId;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class TabCompleteTracker extends StoredObject {
|
public class TabCompleteTracker extends StoredObject {
|
||||||
private int transactionId;
|
private int transactionId;
|
||||||
private String input;
|
private String input;
|
||||||
private TaskId lastTabCompleteTask;
|
private String lastTabComplete;
|
||||||
|
private long timeToSend;
|
||||||
|
|
||||||
public TabCompleteTracker(UserConnection user) {
|
public TabCompleteTracker(UserConnection user) {
|
||||||
super(user);
|
super(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendPacketToServer() {
|
||||||
|
if (lastTabComplete == null || timeToSend > System.currentTimeMillis()) return;
|
||||||
|
PacketWrapper wrapper = new PacketWrapper(0x01, null, getUser());
|
||||||
|
wrapper.write(Type.STRING, lastTabComplete);
|
||||||
|
wrapper.write(Type.BOOLEAN, false);
|
||||||
|
wrapper.write(Type.OPTIONAL_POSITION, null);
|
||||||
|
try {
|
||||||
|
wrapper.sendToServer(Protocol1_13To1_12_2.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
lastTabComplete = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren