3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Trying to fix main hand on bungee, handle left handed on 1.8 using 0x80

Dieser Commit ist enthalten in:
creeper123123321 2019-03-05 19:47:44 -03:00
Ursprung 05d01e70b7
Commit 12b45d95e0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
16 geänderte Dateien mit 102 neuen und 114 gelöschten Zeilen

Datei anzeigen

@ -249,4 +249,9 @@ public class BukkitViaConfig extends Config implements ViaVersionConfig {
public int get1_13TabCompleteDelay() { public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0); return getInt("1_13-tab-complete-delay", 0);
} }
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
} }

Datei anzeigen

@ -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();
}
}
}

Datei anzeigen

@ -302,4 +302,9 @@ public class BungeeViaConfig extends Config implements ViaVersionConfig {
public int get1_13TabCompleteDelay() { public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0); return getInt("1_13-tab-complete-delay", 0);
} }
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
} }

Datei anzeigen

@ -8,16 +8,13 @@ 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.ElytraPatch; 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.listeners.UpdateListener;
import us.myles.ViaVersion.bungee.providers.BungeeBossBarProvider; import us.myles.ViaVersion.bungee.providers.*;
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.service.ProtocolDetectorService; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
import us.myles.ViaVersion.protocols.base.VersionProvider; 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.BossBarProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider; 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 us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import java.util.HashSet; import java.util.HashSet;
@ -45,7 +42,6 @@ public class BungeeViaLoader implements ViaPlatformLoader {
registerListener(plugin); registerListener(plugin);
registerListener(new UpdateListener()); registerListener(new UpdateListener());
registerListener(new BungeeServerHandler()); registerListener(new BungeeServerHandler());
registerListener(new MainHandPatch());
registerListener(new ElytraPatch()); registerListener(new ElytraPatch());
// Providers // Providers
@ -53,6 +49,7 @@ public class BungeeViaLoader implements ViaPlatformLoader {
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider()); Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider()); Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider()); Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
Via.getManager().getProviders().use(MainHandProvider.class, new BungeeMainHandProvider());
if (plugin.getConf().getBungeePingInterval() > 0) { if (plugin.getConf().getBungeePingInterval() > 0) {
tasks.add(plugin.getProxy().getScheduler().schedule( tasks.add(plugin.getProxy().getScheduler().schedule(

Datei anzeigen

@ -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();
}
}
}

Datei anzeigen

@ -308,4 +308,9 @@ public interface ViaVersionConfig {
* @return the delay in ticks * @return the delay in ticks
*/ */
int get1_13TabCompleteDelay(); int get1_13TabCompleteDelay();
/**
* Handles left handed info by using unused bit 7 on Client Settings packet
*/
boolean isLeftHandedHandling();
} }

Datei anzeigen

@ -95,6 +95,7 @@ public class Protocol1_9TO1_8 extends Protocol {
providers.register(CommandBlockProvider.class, new CommandBlockProvider()); providers.register(CommandBlockProvider.class, new CommandBlockProvider());
providers.register(EntityIdProvider.class, new EntityIdProvider()); providers.register(EntityIdProvider.class, new EntityIdProvider());
providers.register(BossBarProvider.class, new BossBarProvider()); providers.register(BossBarProvider.class, new BossBarProvider());
providers.register(MainHandProvider.class, new MainHandProvider());
providers.require(MovementTransmitterProvider.class); providers.require(MovementTransmitterProvider.class);
if (Via.getConfig().isStimulatePlayerTick()) { if (Via.getConfig().isStimulatePlayerTick()) {
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L); Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);

Datei anzeigen

@ -283,7 +283,7 @@ public class EntityPackets {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
if (!Via.getConfig().isMinimizeCooldown()) return; 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; return;
} }
int propertiesToRead = wrapper.read(Type.INT); int propertiesToRead = wrapper.read(Type.INT);

Datei anzeigen

@ -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.ChatRewriter;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode; 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.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.ClientChunks;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker;
@ -458,8 +459,15 @@ public class PlayerPackets {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int hand = wrapper.read(Type.VAR_INT); int hand = wrapper.read(Type.VAR_INT);
EntityTracker tracker = wrapper.user().get(EntityTracker.class); if (Via.getConfig().isLeftHandedHandling()) {
tracker.setMainHand(hand); // 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);
} }
}); });
} }

Datei anzeigen

@ -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) {
}
}

Datei anzeigen

@ -52,8 +52,6 @@ public class EntityTracker extends StoredObject {
@Setter @Setter
private GameMode gameMode; private GameMode gameMode;
@Setter @Setter
private int mainHand;
@Setter
private String currentTeam; private String currentTeam;
public EntityTracker(UserConnection user) { 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 (type == Entity1_10Types.EntityType.ARMOR_STAND && Via.getConfig().isHologramPatch()) {
if (metadata.getId() == 0 && getMetaByIndex(metadataList, 10) != null) { if (metadata.getId() == 0 && getMetaByIndex(metadataList, 10) != null) {

Datei anzeigen

@ -166,3 +166,5 @@ replacement-piston-id: 0
force-json-transform: false force-json-transform: false
# Minimize the cooldown animation in 1.8 servers # Minimize the cooldown animation in 1.8 servers
minimize-cooldown: true minimize-cooldown: true
# Left handed handling on 1.8 servers
left-handed-handling: true

Datei anzeigen

@ -255,4 +255,9 @@ public class SpongeViaConfig extends Config implements ViaVersionConfig {
public int get1_13TabCompleteDelay() { public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0); return getInt("1_13-tab-complete-delay", 0);
} }
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
} }

Datei anzeigen

@ -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();
}
}
}

Datei anzeigen

@ -307,4 +307,9 @@ public class VelocityViaConfig extends Config implements ViaVersionConfig {
public int get1_13TabCompleteDelay() { public int get1_13TabCompleteDelay() {
return getInt("1_13-tab-complete-delay", 0); return getInt("1_13-tab-complete-delay", 0);
} }
@Override
public boolean isLeftHandedHandling() {
return getBoolean("left-handed-handling", true);
}
} }

Datei anzeigen

@ -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.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import us.myles.ViaVersion.velocity.handlers.VelocityServerHandler; import us.myles.ViaVersion.velocity.handlers.VelocityServerHandler;
import us.myles.ViaVersion.velocity.listeners.ElytraPatch; 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.listeners.UpdateListener;
import us.myles.ViaVersion.velocity.providers.VelocityBossBarProvider; import us.myles.ViaVersion.velocity.providers.VelocityBossBarProvider;
import us.myles.ViaVersion.velocity.providers.VelocityMovementTransmitter; 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(BossBarProvider.class, new VelocityBossBarProvider());
Via.getManager().getProviders().use(VersionProvider.class, new VelocityVersionProvider()); 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 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 UpdateListener());
VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler()); VelocityPlugin.PROXY.getEventManager().register(plugin, new VelocityServerHandler());
VelocityPlugin.PROXY.getEventManager().register(plugin, new MainHandPatch());
VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch()); VelocityPlugin.PROXY.getEventManager().register(plugin, new ElytraPatch());
int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval(); int pingInterval = ((VelocityViaConfig) Via.getPlatform().getConf()).getVelocityPingInterval();