Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge pull request #1193 from creeper123123321/master
Cleanup ConnectionData#update and fix doors
Dieser Commit ist enthalten in:
Commit
876839348c
@ -9,7 +9,12 @@ import java.util.Map;
|
|||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum BlockFace {
|
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<>();
|
private static Map<BlockFace, BlockFace> opposites = new HashMap<>();
|
||||||
|
|
||||||
|
@ -27,25 +27,23 @@ public class ConnectionData {
|
|||||||
static Set<Integer> occludingStates = new HashSet<>();
|
static Set<Integer> occludingStates = new HashSet<>();
|
||||||
|
|
||||||
public static void update(UserConnection user, Position position) {
|
public static void update(UserConnection user, Position position) {
|
||||||
for (int x = -1; x <= 1; x++) {
|
for (BlockFace face : BlockFace.values()) {
|
||||||
for (int z = -1; z <= 1; z++) {
|
Position pos = new Position(
|
||||||
for (int y = -1; y <= 1; y++) {
|
position.getX() + face.getModX(),
|
||||||
if (Math.abs(x) + Math.abs(y) + Math.abs(z) != 1) continue;
|
position.getY() + face.getModY(),
|
||||||
Position pos = new Position(position.getX() + x, position.getY() + y, position.getZ() + z);
|
position.getZ() + face.getModZ()
|
||||||
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
|
);
|
||||||
if (!connects(blockState)) continue;
|
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
|
||||||
int newBlockState = connect(user, pos, blockState);
|
if (!connects(blockState)) continue;
|
||||||
if (newBlockState == blockState) continue;
|
int newBlockState = connect(user, pos, blockState);
|
||||||
|
|
||||||
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
|
PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
|
||||||
blockUpdatePacket.write(Type.POSITION, pos);
|
blockUpdatePacket.write(Type.POSITION, pos);
|
||||||
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
|
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
|
||||||
try {
|
try {
|
||||||
blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
|
blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,25 @@ import io.netty.channel.ChannelInitializer;
|
|||||||
import us.myles.ViaVersion.VelocityPlugin;
|
import us.myles.ViaVersion.VelocityPlugin;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.platform.ViaInjector;
|
import us.myles.ViaVersion.api.platform.ViaInjector;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
import us.myles.ViaVersion.util.ReflectionUtil;
|
import us.myles.ViaVersion.util.ReflectionUtil;
|
||||||
import us.myles.ViaVersion.velocity.handlers.VelocityChannelInitializer;
|
import us.myles.ViaVersion.velocity.handlers.VelocityChannelInitializer;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
|
||||||
public class VelocityViaInjector implements ViaInjector {
|
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
|
@Override
|
||||||
public void inject() throws Exception {
|
public void inject() throws Exception {
|
||||||
Object connectionManager = ReflectionUtil.get(VelocityPlugin.PROXY, "cm", Object.class);
|
Object connectionManager = ReflectionUtil.get(VelocityPlugin.PROXY, "cm", Object.class);
|
||||||
@ -30,6 +44,12 @@ public class VelocityViaInjector implements ViaInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getLowestSupportedProtocolVersion() {
|
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();
|
return com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION.getProtocol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package us.myles.ViaVersion.velocity.providers;
|
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.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
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.protocols.base.VersionProvider;
|
||||||
import us.myles.ViaVersion.velocity.platform.VelocityViaInjector;
|
import us.myles.ViaVersion.velocity.platform.VelocityViaInjector;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class VelocityVersionProvider extends VersionProvider {
|
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
|
@Override
|
||||||
public int getServerProtocol(UserConnection user) throws Exception {
|
public int getServerProtocol(UserConnection user) throws Exception {
|
||||||
int playerVersion = user.get(ProtocolInfo.class).getProtocolVersion();
|
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
|
// Bungee supports it
|
||||||
if (Collections.binarySearch(VELOCITY_PROTOCOLS, playerVersion) >= 0)
|
if (Arrays.binarySearch(compatibleProtocols, playerVersion) >= 0)
|
||||||
return playerVersion;
|
return playerVersion;
|
||||||
|
|
||||||
// Older than bungee supports, get the lowest version
|
// Older than bungee supports, get the lowest version
|
||||||
if (playerVersion < VELOCITY_PROTOCOLS.get(0)) {
|
if (playerVersion < compatibleProtocols[0]) {
|
||||||
return VelocityViaInjector.getLowestSupportedProtocolVersion();
|
return compatibleProtocols[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through all protocols to get the closest protocol id that bungee supports (and that viaversion does too)
|
// 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.
|
// 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.
|
// 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))
|
if (playerVersion > protocol && ProtocolVersion.isRegistered(protocol))
|
||||||
return protocol;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren