Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Run Velocity server change logic on event loop
Dieser Commit ist enthalten in:
Ursprung
14532bfa9a
Commit
f8def524aa
@ -36,7 +36,6 @@ public class UserConnection {
|
||||
// Used for handling warnings (over time)
|
||||
private int secondsObserved = 0;
|
||||
private int warnings = 0;
|
||||
private ReadWriteLock velocityLock = new ReentrantReadWriteLock();
|
||||
|
||||
public UserConnection(Channel channel) {
|
||||
this.channel = channel;
|
||||
|
@ -35,7 +35,6 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
|
||||
if (info.handlePPS())
|
||||
return;
|
||||
}
|
||||
info.getVelocityLock().readLock().lock();
|
||||
if (info.isActive()) {
|
||||
// Handle ID
|
||||
int id = Type.VAR_INT.read(bytebuf);
|
||||
@ -58,13 +57,11 @@ public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
|
||||
bytebuf.clear();
|
||||
// Release Packet, be free!
|
||||
newPacket.release();
|
||||
info.getVelocityLock().readLock().unlock();
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
bytebuf.retain();
|
||||
}
|
||||
info.getVelocityLock().readLock().unlock();
|
||||
|
||||
out.add(bytebuf);
|
||||
}
|
||||
|
@ -25,7 +25,9 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class VelocityServerHandler {
|
||||
private static Method setProtocolVersion;
|
||||
@ -75,27 +77,20 @@ public class VelocityServerHandler {
|
||||
|
||||
@Subscribe(order = PostOrder.LATE)
|
||||
public void connectedEvent(ServerConnectedEvent e) {
|
||||
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
checkServerChange(e, Via.getManager().getConnection(e.getPlayer().getUniqueId()));
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}, user.getChannel().eventLoop()).join();
|
||||
}
|
||||
|
||||
public void checkServerChange(ServerConnectedEvent e, UserConnection user) throws Exception {
|
||||
if (user == null) return;
|
||||
// Handle server/version change
|
||||
if (user.has(VelocityStorage.class)) {
|
||||
// Wait all the scheduled packets be sent
|
||||
Semaphore semaphore = new Semaphore(1);
|
||||
semaphore.acquireUninterruptibly();
|
||||
user.getChannel().eventLoop().submit((Runnable) semaphore::release);
|
||||
semaphore.acquireUninterruptibly();
|
||||
semaphore.release();
|
||||
|
||||
user.getVelocityLock().writeLock().lock();
|
||||
|
||||
try {
|
||||
VelocityStorage storage = user.get(VelocityStorage.class);
|
||||
|
||||
if (e.getServer() != null) {
|
||||
@ -180,9 +175,6 @@ public class VelocityServerHandler {
|
||||
setProtocolVersion.invoke(connection, version);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
user.getVelocityLock().writeLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren