Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 22:02:50 +02:00
Store the mainHand and change it on serverChange for Bungee, fixes #536
Dieser Commit ist enthalten in:
Ursprung
7e837ef9db
Commit
9b7f68a888
@ -47,7 +47,7 @@ public class BungeeServerHandler implements Listener {
|
|||||||
|
|
||||||
// Set the handshake version every time someone connects to any server
|
// Set the handshake version every time someone connects to any server
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onServerConnect(ServerConnectEvent e) throws NoSuchFieldException, IllegalAccessException {
|
public void onServerConnect(ServerConnectEvent e) {
|
||||||
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
UserConnection user = Via.getManager().getConnection(e.getPlayer().getUniqueId());
|
||||||
if (!user.has(BungeeStorage.class)) {
|
if (!user.has(BungeeStorage.class)) {
|
||||||
user.put(new BungeeStorage(user, e.getPlayer()));
|
user.put(new BungeeStorage(user, e.getPlayer()));
|
||||||
@ -61,7 +61,7 @@ public class BungeeServerHandler implements Listener {
|
|||||||
Object pendingConnection = getPendingConnection.invoke(e.getPlayer());
|
Object pendingConnection = getPendingConnection.invoke(e.getPlayer());
|
||||||
Object handshake = getHandshake.invoke(pendingConnection);
|
Object handshake = getHandshake.invoke(pendingConnection);
|
||||||
setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId);
|
setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId);
|
||||||
} catch (InvocationTargetException e1) {
|
} catch (InvocationTargetException | IllegalAccessException e1) {
|
||||||
e1.printStackTrace();
|
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.Via;
|
||||||
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||||
import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler;
|
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.listeners.UpdateListener;
|
||||||
import us.myles.ViaVersion.bungee.providers.BungeeEntityIdProvider;
|
import us.myles.ViaVersion.bungee.providers.BungeeEntityIdProvider;
|
||||||
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
|
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, plugin);
|
||||||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new UpdateListener());
|
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new UpdateListener());
|
||||||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new BungeeServerHandler());
|
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new BungeeServerHandler());
|
||||||
|
ProxyServer.getInstance().getPluginManager().registerListener(plugin, new MainHandPatch());
|
||||||
|
|
||||||
// Providers
|
// Providers
|
||||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
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.VAR_INT, Type.BYTE); // 2 - Chat Mode
|
||||||
map(Type.BOOLEAN); // 3 - If Chat Colours on
|
map(Type.BOOLEAN); // 3 - If Chat Colours on
|
||||||
map(Type.UNSIGNED_BYTE); // 4 - Skin Parts
|
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;
|
private boolean teamExists = false;
|
||||||
@Setter
|
@Setter
|
||||||
private GameMode gameMode;
|
private GameMode gameMode;
|
||||||
|
@Setter
|
||||||
|
private int mainHand;
|
||||||
|
|
||||||
public EntityTracker(UserConnection user) {
|
public EntityTracker(UserConnection user) {
|
||||||
super(user);
|
super(user);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren