mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-25 12:45:35 +01:00
Send dummy respawn on same dimension switch
This commit is contained in:
parent
7638d678bb
commit
a59c384884
@ -10,59 +10,18 @@
|
||||
|
||||
package nl.matsv.viabackwards;
|
||||
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
|
||||
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||
|
||||
public class BungeePlugin extends Plugin implements ViaBackwardsPlatform, Listener {
|
||||
public class BungeePlugin extends Plugin implements ViaBackwardsPlatform {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Via.getManager().addEnableListener(() -> this.init(getDataFolder()));
|
||||
getProxy().getPluginManager().registerListener(this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
}
|
||||
|
||||
@EventHandler(priority = -110) // Slightly later than VV
|
||||
public void serverConnected(ServerConnectedEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
if (player.getServer() == null) return;
|
||||
|
||||
UserConnection connection = Via.getManager().getConnection(player.getUniqueId());
|
||||
if (connection == null) return;
|
||||
|
||||
ProtocolInfo info = connection.getProtocolInfo();
|
||||
if (info == null || !info.getPipeline().contains(Protocol1_15_2To1_16.class)) return;
|
||||
|
||||
// Need to send a dummy respawn with a different dimension before the actual respawn
|
||||
// We also don't know what dimension it's sent to, so just send 2 dummies :>
|
||||
sendRespawn(connection, -1);
|
||||
sendRespawn(connection, 0);
|
||||
}
|
||||
|
||||
private void sendRespawn(UserConnection connection, int dimension) {
|
||||
PacketWrapper packet = new PacketWrapper(ClientboundPackets1_15.RESPAWN.ordinal(), null, connection);
|
||||
packet.write(Type.INT, dimension);
|
||||
packet.write(Type.LONG, 0L);
|
||||
packet.write(Type.UNSIGNED_BYTE, (short) 0);
|
||||
packet.write(Type.STRING, "default");
|
||||
try {
|
||||
packet.send(Protocol1_15_2To1_16.class, true, true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.api.type.types.Particle;
|
||||
import us.myles.ViaVersion.api.type.types.version.Types1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
|
||||
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
@ -57,7 +58,19 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
|
||||
map(Type.BYTE, Type.NOTHING); // Previous gamemode
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
clientWorld.setEnvironment(wrapper.get(Type.INT, 0));
|
||||
int dimension = wrapper.get(Type.INT, 0);
|
||||
|
||||
// Send a dummy respawn with a different dimension if the previous one is equal to the new
|
||||
if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().getId()) {
|
||||
PacketWrapper packet = wrapper.create(ClientboundPackets1_15.RESPAWN.ordinal());
|
||||
packet.write(Type.INT, dimension == 0 ? -1 : 0);
|
||||
packet.write(Type.LONG, 0L);
|
||||
packet.write(Type.UNSIGNED_BYTE, (short) 0);
|
||||
packet.write(Type.STRING, "default");
|
||||
packet.send(Protocol1_15_2To1_16.class, true, true);
|
||||
}
|
||||
|
||||
clientWorld.setEnvironment(dimension);
|
||||
|
||||
wrapper.write(Type.STRING, "default"); // Level type
|
||||
wrapper.read(Type.BOOLEAN); // Debug
|
||||
|
Loading…
Reference in New Issue
Block a user