Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Merge branch 'dev/1.1.0' into dev/2.0.0
# Conflicts: # build.gradle # native/src/main/java/com/velocitypowered/natives/compression/Java11VelocityCompressor.java
Dieser Commit ist enthalten in:
Commit
5bd7b66bda
@ -8,6 +8,11 @@ apply from: '../gradle/checkstyle.gradle'
|
|||||||
apply from: '../gradle/publish.gradle'
|
apply from: '../gradle/publish.gradle'
|
||||||
apply plugin: 'com.github.johnrengelman.shadow'
|
apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
ap {
|
ap {
|
||||||
compileClasspath += main.compileClasspath + main.output
|
compileClasspath += main.compileClasspath + main.output
|
||||||
@ -31,7 +36,7 @@ dependencies {
|
|||||||
api "org.slf4j:slf4j-api:${slf4jVersion}"
|
api "org.slf4j:slf4j-api:${slf4jVersion}"
|
||||||
api 'com.google.inject:guice:4.2.3'
|
api 'com.google.inject:guice:4.2.3'
|
||||||
api "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
|
api "org.checkerframework:checker-qual:${checkerFrameworkVersion}"
|
||||||
api 'com.mojang:brigadier:1.0.17'
|
api 'com.velocitypowered:velocity-brigadier:1.0.0-SNAPSHOT'
|
||||||
|
|
||||||
api "org.spongepowered:configurate-hocon:${configurateVersion}"
|
api "org.spongepowered:configurate-hocon:${configurateVersion}"
|
||||||
api "org.spongepowered:configurate-yaml:${configurateVersion}"
|
api "org.spongepowered:configurate-yaml:${configurateVersion}"
|
||||||
|
@ -55,9 +55,9 @@ allprojects {
|
|||||||
url 'https://oss.sonatype.org/content/groups/public/'
|
url 'https://oss.sonatype.org/content/groups/public/'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Brigadier
|
// Velocity repo
|
||||||
maven {
|
maven {
|
||||||
url "https://libraries.minecraft.net"
|
url "https://nexus.velocitypowered.com/repository/maven-public/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,11 @@ plugins {
|
|||||||
apply from: '../gradle/checkstyle.gradle'
|
apply from: '../gradle/checkstyle.gradle'
|
||||||
apply from: '../gradle/publish.gradle'
|
apply from: '../gradle/publish.gradle'
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.google.guava:guava:${guavaVersion}"
|
implementation "com.google.guava:guava:${guavaVersion}"
|
||||||
implementation "io.netty:netty-handler:${nettyVersion}"
|
implementation "io.netty:netty-handler:${nettyVersion}"
|
||||||
|
@ -8,6 +8,11 @@ plugins {
|
|||||||
apply from: '../gradle/checkstyle.gradle'
|
apply from: '../gradle/checkstyle.gradle'
|
||||||
apply plugin: 'com.github.johnrengelman.shadow'
|
apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
def buildNumber = System.getenv("BUILD_NUMBER") ?: "unknown"
|
def buildNumber = System.getenv("BUILD_NUMBER") ?: "unknown"
|
||||||
|
@ -99,11 +99,7 @@ public class VelocityCommandManager implements CommandManager {
|
|||||||
@Override
|
@Override
|
||||||
public void unregister(final String alias) {
|
public void unregister(final String alias) {
|
||||||
Preconditions.checkNotNull(alias, "alias");
|
Preconditions.checkNotNull(alias, "alias");
|
||||||
CommandNode<CommandSource> node =
|
dispatcher.getRoot().removeChildByName(alias.toLowerCase(Locale.ENGLISH));
|
||||||
dispatcher.getRoot().getChild(alias.toLowerCase(Locale.ENGLISH));
|
|
||||||
if (node != null) {
|
|
||||||
dispatcher.getRoot().getChildren().remove(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,8 +225,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
backendConn.write(packet.retain());
|
backendConn.write(packet.retain());
|
||||||
} else {
|
} else {
|
||||||
byte[] copy = ByteBufUtil.getBytes(packet.content());
|
byte[] copy = ByteBufUtil.getBytes(packet.content());
|
||||||
PluginMessageEvent event = new PluginMessageEvent(player, serverConn, id,
|
PluginMessageEvent event = new PluginMessageEvent(player, serverConn, id, copy);
|
||||||
ByteBufUtil.getBytes(packet.content()));
|
|
||||||
server.getEventManager().fire(event).thenAcceptAsync(pme -> {
|
server.getEventManager().fire(event).thenAcceptAsync(pme -> {
|
||||||
if (pme.getResult().isAllowed()) {
|
if (pme.getResult().isAllowed()) {
|
||||||
PluginMessagePacket message = new PluginMessagePacket(packet.getChannel(),
|
PluginMessagePacket message = new PluginMessagePacket(packet.getChannel(),
|
||||||
|
@ -39,31 +39,25 @@ class LegacyForgeUtil {
|
|||||||
*/
|
*/
|
||||||
static List<ModInfo.Mod> readModList(PluginMessagePacket message) {
|
static List<ModInfo.Mod> readModList(PluginMessagePacket message) {
|
||||||
Preconditions.checkNotNull(message, "message");
|
Preconditions.checkNotNull(message, "message");
|
||||||
Preconditions
|
Preconditions.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL),
|
||||||
.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL),
|
|
||||||
"message is not a FML HS plugin message");
|
"message is not a FML HS plugin message");
|
||||||
|
|
||||||
ByteBuf byteBuf = message.content().retainedSlice();
|
ByteBuf contents = message.content().slice();
|
||||||
try {
|
byte discriminator = contents.readByte();
|
||||||
byte discriminator = byteBuf.readByte();
|
if (discriminator == MOD_LIST_DISCRIMINATOR) {
|
||||||
|
ImmutableList.Builder<ModInfo.Mod> mods = ImmutableList.builder();
|
||||||
|
int modCount = ProtocolUtils.readVarInt(contents);
|
||||||
|
|
||||||
if (discriminator == MOD_LIST_DISCRIMINATOR) {
|
for (int index = 0; index < modCount; index++) {
|
||||||
ImmutableList.Builder<ModInfo.Mod> mods = ImmutableList.builder();
|
String id = ProtocolUtils.readString(contents);
|
||||||
int modCount = ProtocolUtils.readVarInt(byteBuf);
|
String version = ProtocolUtils.readString(contents);
|
||||||
|
mods.add(new ModInfo.Mod(id, version));
|
||||||
for (int index = 0; index < modCount; index++) {
|
|
||||||
String id = ProtocolUtils.readString(byteBuf);
|
|
||||||
String version = ProtocolUtils.readString(byteBuf);
|
|
||||||
mods.add(new ModInfo.Mod(id, version));
|
|
||||||
}
|
|
||||||
|
|
||||||
return mods.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ImmutableList.of();
|
return mods.build();
|
||||||
} finally {
|
|
||||||
byteBuf.release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,9 +175,12 @@ public class VelocityPluginManager implements PluginManager {
|
|||||||
public void addToClasspath(Object plugin, Path path) {
|
public void addToClasspath(Object plugin, Path path) {
|
||||||
checkNotNull(plugin, "instance");
|
checkNotNull(plugin, "instance");
|
||||||
checkNotNull(path, "path");
|
checkNotNull(path, "path");
|
||||||
checkArgument(pluginInstances.containsKey(plugin), "plugin is not loaded");
|
Optional<PluginContainer> optContainer = fromInstance(plugin);
|
||||||
|
checkArgument(optContainer.isPresent(), "plugin is not loaded");
|
||||||
|
Optional<?> optInstance = optContainer.get().getInstance();
|
||||||
|
checkArgument(optInstance.isPresent(), "plugin has no instance");
|
||||||
|
|
||||||
ClassLoader pluginClassloader = plugin.getClass().getClassLoader();
|
ClassLoader pluginClassloader = optInstance.get().getClass().getClassLoader();
|
||||||
if (pluginClassloader instanceof PluginClassLoader) {
|
if (pluginClassloader instanceof PluginClassLoader) {
|
||||||
((PluginClassLoader) pluginClassloader).addPath(path);
|
((PluginClassLoader) pluginClassloader).addPath(path);
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,6 +5,7 @@ import static com.velocitypowered.proxy.protocol.packet.brigadier.EmptyArgumentP
|
|||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.FloatArgumentPropertySerializer.FLOAT;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.FloatArgumentPropertySerializer.FLOAT;
|
||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.INTEGER;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.INTEGER;
|
||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.LongArgumentPropertySerializer.LONG;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.LongArgumentPropertySerializer.LONG;
|
||||||
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.ModArgumentPropertySerializer.MOD;
|
||||||
import static com.velocitypowered.proxy.protocol.packet.brigadier.StringArgumentPropertySerializer.STRING;
|
import static com.velocitypowered.proxy.protocol.packet.brigadier.StringArgumentPropertySerializer.STRING;
|
||||||
|
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
@ -76,6 +77,10 @@ public class ArgumentPropertyRegistry {
|
|||||||
if (property.getResult() != null) {
|
if (property.getResult() != null) {
|
||||||
property.getSerializer().serialize(property.getResult(), buf);
|
property.getSerializer().serialize(property.getResult(), buf);
|
||||||
}
|
}
|
||||||
|
} else if (type instanceof ModArgumentProperty) {
|
||||||
|
ModArgumentProperty property = (ModArgumentProperty) type;
|
||||||
|
ProtocolUtils.writeString(buf, property.getIdentifier());
|
||||||
|
buf.writeBytes(property.getData());
|
||||||
} else {
|
} else {
|
||||||
ArgumentPropertySerializer serializer = byClass.get(type.getClass());
|
ArgumentPropertySerializer serializer = byClass.get(type.getClass());
|
||||||
String id = classToId.get(type.getClass());
|
String id = classToId.get(type.getClass());
|
||||||
@ -98,6 +103,9 @@ public class ArgumentPropertyRegistry {
|
|||||||
GenericArgumentPropertySerializer.create(BoolArgumentType::bool));
|
GenericArgumentPropertySerializer.create(BoolArgumentType::bool));
|
||||||
register("brigadier:long", LongArgumentType.class, LONG);
|
register("brigadier:long", LongArgumentType.class, LONG);
|
||||||
|
|
||||||
|
// Crossstitch support
|
||||||
|
register("crossstitch:mod_argument", ModArgumentProperty.class, MOD);
|
||||||
|
|
||||||
// Minecraft argument types with extra properties
|
// Minecraft argument types with extra properties
|
||||||
empty("minecraft:entity", ByteArgumentPropertySerializer.BYTE);
|
empty("minecraft:entity", ByteArgumentPropertySerializer.BYTE);
|
||||||
empty("minecraft:score_holder", ByteArgumentPropertySerializer.BYTE);
|
empty("minecraft:score_holder", ByteArgumentPropertySerializer.BYTE);
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package com.velocitypowered.proxy.protocol.packet.brigadier;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.StringReader;
|
||||||
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class ModArgumentProperty implements ArgumentType<ByteBuf> {
|
||||||
|
|
||||||
|
private final String identifier;
|
||||||
|
private final ByteBuf data;
|
||||||
|
|
||||||
|
public ModArgumentProperty(String identifier, ByteBuf data) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.data = Unpooled.unreleasableBuffer(data.asReadOnly());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteBuf getData() {
|
||||||
|
return data.slice();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ByteBuf parse(StringReader reader) throws CommandSyntaxException {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context,
|
||||||
|
SuggestionsBuilder builder) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getExamples() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.velocitypowered.proxy.protocol.packet.brigadier;
|
||||||
|
|
||||||
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
class ModArgumentPropertySerializer implements ArgumentPropertySerializer<ModArgumentProperty> {
|
||||||
|
static final ModArgumentPropertySerializer MOD = new ModArgumentPropertySerializer();
|
||||||
|
|
||||||
|
private ModArgumentPropertySerializer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ModArgumentProperty deserialize(ByteBuf buf) {
|
||||||
|
String identifier = ProtocolUtils.readString(buf);
|
||||||
|
byte[] extraData = ProtocolUtils.readByteArray(buf);
|
||||||
|
return new ModArgumentProperty(identifier, Unpooled.wrappedBuffer(extraData));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(ModArgumentProperty object, ByteBuf buf) {
|
||||||
|
// This is special-cased by ArgumentPropertyRegistry
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,8 @@ import io.netty.channel.ChannelInitializer;
|
|||||||
import io.netty.channel.EventLoop;
|
import io.netty.channel.EventLoop;
|
||||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -45,7 +46,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
|||||||
|
|
||||||
private final @Nullable VelocityServer server;
|
private final @Nullable VelocityServer server;
|
||||||
private final ServerInfo serverInfo;
|
private final ServerInfo serverInfo;
|
||||||
private final Set<ConnectedPlayer> players = ConcurrentHashMap.newKeySet();
|
private final Map<UUID, ConnectedPlayer> players = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public VelocityRegisteredServer(@Nullable VelocityServer server, ServerInfo serverInfo) {
|
public VelocityRegisteredServer(@Nullable VelocityServer server, ServerInfo serverInfo) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
@ -59,7 +60,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Player> getPlayersConnected() {
|
public Collection<Player> getPlayersConnected() {
|
||||||
return ImmutableList.copyOf(players);
|
return ImmutableList.copyOf(players.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -111,11 +112,11 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(ConnectedPlayer player) {
|
public void addPlayer(ConnectedPlayer player) {
|
||||||
players.add(player);
|
players.put(player.getUniqueId(), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePlayer(ConnectedPlayer player) {
|
public void removePlayer(ConnectedPlayer player) {
|
||||||
players.remove(player);
|
players.remove(player.getUniqueId(), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -130,7 +131,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
|
|||||||
* @return whether or not the message was sent
|
* @return whether or not the message was sent
|
||||||
*/
|
*/
|
||||||
public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) {
|
public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) {
|
||||||
for (ConnectedPlayer player : players) {
|
for (ConnectedPlayer player : players.values()) {
|
||||||
VelocityServerConnection connection = player.getConnectedServer();
|
VelocityServerConnection connection = player.getConnectedServer();
|
||||||
if (connection != null && connection.getServerInfo().equals(serverInfo)) {
|
if (connection != null && connection.getServerInfo().equals(serverInfo)) {
|
||||||
return connection.sendPluginMessage(identifier, data);
|
return connection.sendPluginMessage(identifier, data);
|
||||||
|
@ -10,6 +10,8 @@ import java.net.SocketAddress;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
public final class AddressUtil {
|
public final class AddressUtil {
|
||||||
|
private static final int DEFAULT_MINECRAFT_PORT = 25565;
|
||||||
|
|
||||||
private AddressUtil() {
|
private AddressUtil() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@ -26,11 +28,16 @@ public final class AddressUtil {
|
|||||||
return new DomainSocketAddress(ip.substring("unix://".length()));
|
return new DomainSocketAddress(ip.substring("unix://".length()));
|
||||||
}
|
}
|
||||||
URI uri = URI.create("tcp://" + ip);
|
URI uri = URI.create("tcp://" + ip);
|
||||||
|
if (uri.getHost() == null) {
|
||||||
|
throw new IllegalStateException("Invalid hostname/IP " + ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
int port = uri.getPort() == -1 ? DEFAULT_MINECRAFT_PORT : uri.getPort();
|
||||||
try {
|
try {
|
||||||
InetAddress ia = InetAddresses.forUriString(uri.getHost());
|
InetAddress ia = InetAddresses.forUriString(uri.getHost());
|
||||||
return new InetSocketAddress(ia, uri.getPort());
|
return new InetSocketAddress(ia, port);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
|
return InetSocketAddress.createUnresolved(uri.getHost(), port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +54,11 @@ public final class AddressUtil {
|
|||||||
}
|
}
|
||||||
Preconditions.checkNotNull(ip, "ip");
|
Preconditions.checkNotNull(ip, "ip");
|
||||||
URI uri = URI.create("tcp://" + ip);
|
URI uri = URI.create("tcp://" + ip);
|
||||||
return new InetSocketAddress(uri.getHost(), uri.getPort());
|
if (uri.getHost() == null) {
|
||||||
|
throw new IllegalStateException("Invalid hostname/IP " + ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
int port = uri.getPort() == -1 ? DEFAULT_MINECRAFT_PORT : uri.getPort();
|
||||||
|
return new InetSocketAddress(uri.getHost(), port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ public class CommandManagerTests {
|
|||||||
assertTrue(manager.hasCommand("foO"));
|
assertTrue(manager.hasCommand("foO"));
|
||||||
manager.unregister("fOo");
|
manager.unregister("fOo");
|
||||||
assertFalse(manager.hasCommand("foo"));
|
assertFalse(manager.hasCommand("foo"));
|
||||||
|
assertFalse(manager.execute(MockCommandSource.INSTANCE, "foo"));
|
||||||
|
|
||||||
manager.register("foo", command, "bAr", "BAZ");
|
manager.register("foo", command, "bAr", "BAZ");
|
||||||
assertTrue(manager.hasCommand("bar"));
|
assertTrue(manager.hasCommand("bar"));
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren