Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +01:00
Trying to fix main hand on bungee, handle left handed on 1.8 using 0x80
Dieser Commit ist enthalten in:
Ursprung
05d01e70b7
Commit
12b45d95e0
@ -249,4 +249,9 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig {
|
||||
public int get1_13TabCompleteDelay() {
|
||||
return getInt("1_13-tab-complete-delay", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeftHandedHandling() {
|
||||
return getBoolean("left-handed-handling", true);
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
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 (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerConnect(ServerConnectEvent event) {
|
||||
// Ignore if it doesn't exist (Like BungeeCord 1.8)
|
||||
if (setMainHand == null || getSettings == null)
|
||||
return;
|
||||
|
||||
UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId());
|
||||
if (user == null) return;
|
||||
|
||||
try {
|
||||
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
|
||||
Object settings = getSettings.invoke(event.getPlayer());
|
||||
if (settings != null) {
|
||||
if (user.has(EntityTracker.class)) {
|
||||
setMainHand.invoke(settings, user.get(EntityTracker.class).getMainHand());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -302,4 +302,9 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig {
|
||||
public int get1_13TabCompleteDelay() {
|
||||
return getInt("1_13-tab-complete-delay", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeftHandedHandling() {
|
||||
return getBoolean("left-handed-handling", true);
|
||||
}
|
||||
}
|
||||
|
@ -8,16 +8,13 @@ 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.ElytraPatch;
|
||||
import us.myles.ViaVersion.bungee.listeners.MainHandPatch;
|
||||
import us.myles.ViaVersion.bungee.listeners.UpdateListener;
|
||||
import us.myles.ViaVersion.bungee.providers.BungeeBossBarProvider;
|
||||
import us.myles.ViaVersion.bungee.providers.BungeeEntityIdProvider;
|
||||
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
|
||||
import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider;
|
||||
import us.myles.ViaVersion.bungee.providers.*;
|
||||
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MainHandProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -45,7 +42,6 @@ public class BungeeViaLoader implements ViaPlatformLoader {
|
||||
registerListener(plugin);
|
||||
registerListener(new UpdateListener());
|
||||
registerListener(new BungeeServerHandler());
|
||||
registerListener(new MainHandPatch());
|
||||
registerListener(new ElytraPatch());
|
||||
|
||||
// Providers
|
||||
@ -53,6 +49,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
|
||||
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
|
||||
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
|
||||
Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider());
|
||||
|
||||
if (plugin.getConf().getBungeePingInterval() > 0) {
|
||||
tasks.add(plugin.getProxy().getScheduler().schedule(
|
||||
|
@ -0,0 +1,42 @@
|
||||
package us.myles.ViaVersion.bungee.providers;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MainHandProvider;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
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 BungeeMainHandProvider extends MainHandProvider {
|
||||
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 (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMainHand(UserConnection user, int hand) {
|
||||
ProtocolInfo info = user.get(ProtocolInfo.class);
|
||||
if (info == null || info.getUuid() == null) return;
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(info.getUuid());
|
||||
if (player == null) return;
|
||||
try {
|
||||
Object settings = getSettings.invoke(player);
|
||||
if (settings != null) {
|
||||
setMainHand.invoke(settings, hand);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -308,4 +308,9 @@ public interface ViaVersionConfig {
|
||||
* @return the delay in ticks
|
||||
*/
|
||||
int get1_13TabCompleteDelay();
|
||||
|
||||
/**
|
||||
* Handles left handed info by using unused bit 7 on Client Settings packet
|
||||
*/
|
||||
boolean isLeftHandedHandling();
|
||||
}
|
||||
|
@ -95,6 +95,7 @@ public class Protocol1_9TO1_8 extends Protocol {
|
||||
providers.register(CommandBlockProvider.class, new CommandBlockProvider());
|
||||
providers.register(EntityIdProvider.class, new EntityIdProvider());
|
||||
providers.register(BossBarProvider.class, new BossBarProvider());
|
||||
providers.register(MainHandProvider.class, new MainHandProvider());
|
||||
providers.require(MovementTransmitterProvider.class);
|
||||
if (Via.getConfig().isStimulatePlayerTick()) {
|
||||
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
|
||||
|
@ -283,7 +283,7 @@ public class EntityPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
if (!Via.getConfig().isMinimizeCooldown()) return;
|
||||
if (wrapper.get(Type.VAR_INT, 0) != wrapper.user().get(EntityTracker.class).getEntityID()) {
|
||||
if (wrapper.get(Type.VAR_INT, 0) != wrapper.user().get(EntityTracker.class).getProvidedEntityId()) {
|
||||
return;
|
||||
}
|
||||
int propertiesToRead = wrapper.read(Type.INT);
|
||||
|
@ -19,6 +19,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MainHandProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
|
||||
|
||||
@ -458,8 +459,15 @@ public class PlayerPackets {
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int hand = wrapper.read(Type.VAR_INT);
|
||||
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
tracker.setMainHand(hand);
|
||||
if (Via.getConfig().isLeftHandedHandling()) {
|
||||
// Add 0x80 if left handed
|
||||
if (hand == 0) wrapper.set(Type.UNSIGNED_BYTE, 0,
|
||||
(short) (wrapper.get(Type.UNSIGNED_BYTE, 0).intValue() | 0x80)
|
||||
);
|
||||
}
|
||||
wrapper.sendToServer(Protocol1_9TO1_8.class, true, true);
|
||||
wrapper.cancel();
|
||||
Via.getManager().getProviders().get(MainHandProvider.class).setMainHand(wrapper.user(), hand);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.platform.providers.Provider;
|
||||
|
||||
public class MainHandProvider implements Provider {
|
||||
public void setMainHand(UserConnection user, int hand) {
|
||||
}
|
||||
}
|
@ -52,8 +52,6 @@ public class EntityTracker extends StoredObject {
|
||||
@Setter
|
||||
private GameMode gameMode;
|
||||
@Setter
|
||||
private int mainHand;
|
||||
@Setter
|
||||
private String currentTeam;
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
@ -170,6 +168,13 @@ public class EntityTracker extends StoredObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (metadata.getId() == 12 && Via.getConfig().isLeftHandedHandling()) { // Player model
|
||||
metadataList.add(new Metadata(
|
||||
13, // Main hand
|
||||
MetaType1_9.Byte,
|
||||
(byte) (((((byte) metadata.getValue()) & 0x80) != 0) ? 0 : 1)
|
||||
));
|
||||
}
|
||||
}
|
||||
if (type == Entity1_10Types.EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
|
||||
if (metadata.getId() == 0 && getMetaByIndex(metadataList, 10) != null) {
|
||||
|
@ -166,3 +166,5 @@ replacement-piston-id: 0
|
||||
force-json-transform: false
|
||||
# Minimize the cooldown animation in 1.8 servers
|
||||
minimize-cooldown: true
|
||||
# Left handed handling on 1.8 servers
|
||||
left-handed-handling: true
|
@ -255,4 +255,9 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig {
|
||||
public int get1_13TabCompleteDelay() {
|
||||
return getInt("1_13-tab-complete-delay", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeftHandedHandling() {
|
||||
return getBoolean("left-handed-handling", true);
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
package us.myles.ViaVersion.velocity.listeners;
|
||||
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||
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 us.myles.ViaVersion.util.ReflectionUtil;
|
||||
|
||||
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 {
|
||||
private static Method setSettings;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class clientSettings = Class.forName("com.velocitypowered.proxy.protocol.packet.ClientSettings");
|
||||
setSettings = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer").getDeclaredMethod("setPlayerSettings", clientSettings);
|
||||
setSettings.setAccessible(true);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onServerConnect(ServerConnectedEvent event) {
|
||||
UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId());
|
||||
if (user == null || setSettings == null) return;
|
||||
|
||||
try {
|
||||
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
|
||||
PlayerSettings settings = event.getPlayer().getPlayerSettings();
|
||||
if (user.has(EntityTracker.class)) {
|
||||
Object clientSettings = ReflectionUtil.get(settings, "settings", Object.class);
|
||||
ReflectionUtil.set(clientSettings, "mainHand", user.get(EntityTracker.class).getMainHand());
|
||||
setSettings.invoke(event.getPlayer(), clientSettings);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -307,4 +307,9 @@ public class VelocityViaConfig extends Config implements ViaVersionConfig {
|
||||
public int get1_13TabCompleteDelay() {
|
||||
return getInt("1_13-tab-complete-delay", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeftHandedHandling() {
|
||||
return getBoolean("left-handed-handling", true);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
import us.myles.ViaVersion.velocity.handlers.VelocityServerHandler;
|
||||
import us.myles.ViaVersion.velocity.listeners.ElytraPatch;
|
||||
import us.myles.ViaVersion.velocity.listeners.MainHandPatch;
|
||||
import us.myles.ViaVersion.velocity.listeners.UpdateListener;
|
||||
import us.myles.ViaVersion.velocity.providers.VelocityBossBarProvider;
|
||||
import us.myles.ViaVersion.velocity.providers.VelocityMovementTransmitter;
|
||||
@ -26,10 +25,10 @@ public class VelocityViaLoader implements ViaPlatformLoader {
|
||||
Via.getManager().getProviders().use(BossBarProvider.class, new VelocityBossBarProvider());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new VelocityVersionProvider());
|
||||
// We probably don't need a EntityIdProvider because velocity sends a Join packet on server change
|
||||
// We don't need main hand patch because Join Game packet makes client send hand data again
|
||||
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new UpdateListener());
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler());
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new MainHandPatch());
|
||||
VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch());
|
||||
|
||||
int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren