mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-27 02:47:55 +01:00
Merge pull request #1193 from creeper123123321/master
Cleanup ConnectionData#update and fix doors
This commit is contained in:
commit
876839348c
@ -9,7 +9,12 @@ import java.util.Map;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BlockFace {
|
||||
NORTH(0, 0, -1, EnumAxis.Z), SOUTH(0, 0, 1, EnumAxis.Z), EAST(1, 0, 0, EnumAxis.X), WEST(-1, 0, 0, EnumAxis.X), TOP(0, 1, 0, EnumAxis.Y), BOTTOM(0, -1, 0, EnumAxis.Y);
|
||||
NORTH(0, 0, -1, EnumAxis.Z),
|
||||
SOUTH(0, 0, 1, EnumAxis.Z),
|
||||
EAST(1, 0, 0, EnumAxis.X),
|
||||
WEST(-1, 0, 0, EnumAxis.X),
|
||||
TOP(0, 1, 0, EnumAxis.Y),
|
||||
BOTTOM(0, -1, 0, EnumAxis.Y);
|
||||
|
||||
private static Map<BlockFace, BlockFace> opposites = new HashMap<>();
|
||||
|
||||
|
@ -27,25 +27,23 @@ public class ConnectionData {
|
||||
static Set<Integer> occludingStates = new HashSet<>();
|
||||
|
||||
public static void update(UserConnection user, Position position) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
if (Math.abs(x) + Math.abs(y) + Math.abs(z) != 1) continue;
|
||||
Position pos = new Position(position.getX() + x, position.getY() + y, position.getZ() + z);
|
||||
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
|
||||
if (!connects(blockState)) continue;
|
||||
int newBlockState = connect(user, pos, blockState);
|
||||
if (newBlockState == blockState) continue;
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
Position pos = new Position(
|
||||
position.getX() + face.getModX(),
|
||||
position.getY() + face.getModY(),
|
||||
position.getZ() + face.getModZ()
|
||||
);
|
||||
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
|
||||
if (!connects(blockState)) continue;
|
||||
int newBlockState = connect(user, pos, blockState);
|
||||
|
||||
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
|
||||
blockUpdatePacket.write(Type.POSITION, pos);
|
||||
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
|
||||
try {
|
||||
blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
|
||||
blockUpdatePacket.write(Type.POSITION, pos);
|
||||
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
|
||||
try {
|
||||
blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,25 @@ import io.netty.channel.ChannelInitializer;
|
||||
import us.myles.ViaVersion.VelocityPlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.platform.ViaInjector;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||
import us.myles.ViaVersion.velocity.handlers.VelocityChannelInitializer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
public class VelocityViaInjector implements ViaInjector {
|
||||
public static Method getPlayerInfoForwardingMode;
|
||||
|
||||
static {
|
||||
try {
|
||||
getPlayerInfoForwardingMode = Class.forName("com.velocitypowered.proxy.config.VelocityConfiguration").getMethod("getPlayerInfoForwardingMode");
|
||||
} catch (NoSuchMethodException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject() throws Exception {
|
||||
Object connectionManager = ReflectionUtil.get(VelocityPlugin.PROXY, "cm", Object.class);
|
||||
@ -30,6 +44,12 @@ public class VelocityViaInjector implements ViaInjector {
|
||||
}
|
||||
|
||||
public static int getLowestSupportedProtocolVersion() {
|
||||
try {
|
||||
if (getPlayerInfoForwardingMode != null
|
||||
&& ((Enum<?>) getPlayerInfoForwardingMode.invoke(VelocityPlugin.PROXY.getConfiguration()))
|
||||
.name().equals("MODERN")) return ProtocolVersion.v1_13.getId();
|
||||
} catch (IllegalAccessException | InvocationTargetException ignored) {
|
||||
}
|
||||
return com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION.getProtocol();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package us.myles.ViaVersion.velocity.providers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import us.myles.ViaVersion.VelocityPlugin;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
@ -8,32 +8,41 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||
import us.myles.ViaVersion.velocity.platform.VelocityViaInjector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class VelocityVersionProvider extends VersionProvider {
|
||||
private static final List<Integer> VELOCITY_PROTOCOLS = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream()
|
||||
.map(com.velocitypowered.api.network.ProtocolVersion::getProtocol)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@Override
|
||||
public int getServerProtocol(UserConnection user) throws Exception {
|
||||
int playerVersion = user.get(ProtocolInfo.class).getProtocolVersion();
|
||||
|
||||
IntStream versions = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream()
|
||||
.mapToInt(com.velocitypowered.api.network.ProtocolVersion::getProtocol);
|
||||
|
||||
// Modern forwarding mode needs 1.13 Login plugin message
|
||||
if (VelocityViaInjector.getPlayerInfoForwardingMode != null
|
||||
&& ((Enum<?>) VelocityViaInjector.getPlayerInfoForwardingMode.invoke(VelocityPlugin.PROXY.getConfiguration()))
|
||||
.name().equals("MODERN")) {
|
||||
versions = versions.filter(ver -> ver >= ProtocolVersion.v1_13.getId());
|
||||
}
|
||||
int[] compatibleProtocols = versions.toArray();
|
||||
|
||||
// Bungee supports it
|
||||
if (Collections.binarySearch(VELOCITY_PROTOCOLS, playerVersion) >= 0)
|
||||
if (Arrays.binarySearch(compatibleProtocols, playerVersion) >= 0)
|
||||
return playerVersion;
|
||||
|
||||
// Older than bungee supports, get the lowest version
|
||||
if (playerVersion < VELOCITY_PROTOCOLS.get(0)) {
|
||||
return VelocityViaInjector.getLowestSupportedProtocolVersion();
|
||||
if (playerVersion < compatibleProtocols[0]) {
|
||||
return compatibleProtocols[0];
|
||||
}
|
||||
|
||||
// Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too)
|
||||
|
||||
// TODO: This needs a better fix, i.e checking ProtocolRegistry to see if it would work.
|
||||
// This is more of a workaround for snapshot support by bungee.
|
||||
for (Integer protocol : Lists.reverse(VELOCITY_PROTOCOLS)) {
|
||||
for (int i = compatibleProtocols.length - 1; i >= 0; i--) {
|
||||
int protocol = compatibleProtocols[i];
|
||||
if (playerVersion > protocol && ProtocolVersion.isRegistered(protocol))
|
||||
return protocol;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user