mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 11:35:18 +01:00
Store the mainHand and change it on serverChange for Bungee, fixes #536
This commit is contained in:
parent
7e837ef9db
commit
9b7f68a888
@ -47,7 +47,7 @@ public class BungeeServerHandler implements Listener {
|
||||
|
||||
// Set the handshake version every time someone connects to any server
|
||||
@EventHandler
|
||||
public void onServerConnect(ServerConnectEvent e) throws NoSuchFieldException, IllegalAccessException {
|
||||
public void onServerConnect(ServerConnectEvent e) {
|
||||
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
||||
if (!user.has(BungeeStorage.class)) {
|
||||
user.put(new BungeeStorage(user, e.getPlayer()));
|
||||
@ -61,7 +61,7 @@ public class BungeeServerHandler implements Listener {
|
||||
Object pendingConnection = getPendingConnection.invoke(e.getPlayer());
|
||||
Object handshake = getHandshake.invoke(pendingConnection);
|
||||
setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId);
|
||||
} catch (InvocationTargetException e1) {
|
||||
} catch (InvocationTargetException | IllegalAccessException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
package us.myles.ViaVersion.bungee.listeners;
|
||||
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
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_9to1_8.Protocol1_9TO1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/*
|
||||
This solves the wrong mainhand issue when you join with BungeeCord on a 1.8 server, and switch to a 1.9 or higher.
|
||||
*/
|
||||
public class MainHandPatch implements Listener {
|
||||
private static Method getSettings = null;
|
||||
private static Method setMainHand = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
getSettings = Class.forName("net.md_5.bungee.UserConnection").getDeclaredMethod("getSettings");
|
||||
setMainHand = Class.forName("net.md_5.bungee.protocol.packet.ClientSettings").getDeclaredMethod("setMainHand", int.class);
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerConnect(ServerConnectEvent event) {
|
||||
UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId());
|
||||
|
||||
try {
|
||||
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
|
||||
Object settings = getSettings.invoke(event.getPlayer());
|
||||
setMainHand.invoke(settings, user.get(EntityTracker.class).getMainHand());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import us.myles.ViaVersion.BungeePlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||
import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler;
|
||||
import us.myles.ViaVersion.bungee.listeners.MainHandPatch;
|
||||
import us.myles.ViaVersion.bungee.listeners.UpdateListener;
|
||||
import us.myles.ViaVersion.bungee.providers.BungeeEntityIdProvider;
|
||||
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
|
||||
@ -27,6 +28,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, plugin);
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new UpdateListener());
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new BungeeServerHandler());
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new MainHandPatch());
|
||||
|
||||
// Providers
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
|
@ -433,7 +433,16 @@ public class PlayerPackets {
|
||||
map(Type.VAR_INT, Type.BYTE); // 2 - Chat Mode
|
||||
map(Type.BOOLEAN); // 3 - If Chat Colours on
|
||||
map(Type.UNSIGNED_BYTE); // 4 - Skin Parts
|
||||
map(Type.VAR_INT, Type.NOTHING); // 5 - Main Hand
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int hand = wrapper.read(Type.VAR_INT);
|
||||
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
tracker.setMainHand(hand);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -51,6 +51,8 @@ public class EntityTracker extends StoredObject {
|
||||
private boolean teamExists = false;
|
||||
@Setter
|
||||
private GameMode gameMode;
|
||||
@Setter
|
||||
private int mainHand;
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
|
Loading…
Reference in New Issue
Block a user