geforkt von Mirrors/Velocity
Mix of Checkstyle and SonarLint.
Dieser Commit ist enthalten in:
Ursprung
9806d57a13
Commit
1310cd2c53
@ -2,7 +2,6 @@ package com.velocitypowered.api.plugin.ap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
@ -66,7 +65,7 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
|
||||
}
|
||||
|
||||
Plugin plugin = element.getAnnotation(Plugin.class);
|
||||
if (!PluginDescription.ID_PATTERN.matcher(plugin.id()).matches()) {
|
||||
if (!SerializedPluginDescription.ID_PATTERN.matcher(plugin.id()).matches()) {
|
||||
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Invalid ID for plugin "
|
||||
+ qualifiedName
|
||||
+ ". IDs must start alphabetically, have alphanumeric characters, and can "
|
||||
|
@ -8,11 +8,14 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class SerializedPluginDescription {
|
||||
|
||||
public static final Pattern ID_PATTERN = Pattern.compile("[a-z][a-z0-9-_]{0,63}");
|
||||
|
||||
// @Nullable is used here to make GSON skip these in the serialized file
|
||||
private final String id;
|
||||
private final @Nullable String name;
|
||||
@ -26,7 +29,9 @@ public class SerializedPluginDescription {
|
||||
private SerializedPluginDescription(String id, String name, String version, String description,
|
||||
String url,
|
||||
List<String> authors, List<Dependency> dependencies, String main) {
|
||||
this.id = Preconditions.checkNotNull(id, "id");
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
Preconditions.checkArgument(ID_PATTERN.matcher(id).matches(), "id is not valid");
|
||||
this.id = id;
|
||||
this.name = Strings.emptyToNull(name);
|
||||
this.version = Strings.emptyToNull(version);
|
||||
this.description = Strings.emptyToNull(description);
|
||||
|
@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.proxy.InboundConnection;
|
||||
|
||||
/**
|
||||
* This event is fired when a handshake is established between a client and Velocity.
|
||||
* This event is fired when a handshake is established between a client and the proxy.
|
||||
*/
|
||||
public final class ConnectionHandshakeEvent {
|
||||
|
||||
|
@ -14,7 +14,8 @@ public @interface Plugin {
|
||||
|
||||
/**
|
||||
* The ID of the plugin. This ID should be unique as to not conflict with other plugins. The
|
||||
* plugin ID must match the {@link PluginDescription#ID_PATTERN}.
|
||||
* plugin ID may contain alphanumeric characters, dashes, and underscores, and be a maximum
|
||||
* of 64 characters long.
|
||||
*
|
||||
* @return the ID for this plugin
|
||||
*/
|
||||
|
@ -186,21 +186,23 @@ public final class TextTitle implements Title {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder stay(int ticks) {
|
||||
private int checkTicks(int ticks) {
|
||||
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
|
||||
this.stay = ticks;
|
||||
return ticks;
|
||||
}
|
||||
|
||||
public Builder stay(int ticks) {
|
||||
this.stay = checkTicks(ticks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder fadeIn(int ticks) {
|
||||
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
|
||||
this.fadeIn = ticks;
|
||||
this.fadeIn = checkTicks(ticks);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder fadeOut(int ticks) {
|
||||
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
|
||||
this.fadeOut = ticks;
|
||||
this.fadeOut = checkTicks(ticks);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.velocitypowered.natives;
|
||||
|
||||
public class NativeSetupException extends RuntimeException {
|
||||
|
||||
public NativeSetupException() {
|
||||
}
|
||||
|
||||
public NativeSetupException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NativeSetupException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public NativeSetupException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public NativeSetupException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.velocitypowered.natives.compression;
|
||||
|
||||
import static com.velocitypowered.natives.util.NativeConstants.ZLIB_BUFFER_SIZE;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.zip.DataFormatException;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.velocitypowered.natives.compression;
|
||||
|
||||
import static com.velocitypowered.natives.util.NativeConstants.ZLIB_BUFFER_SIZE;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.zip.DataFormatException;
|
||||
|
@ -8,12 +8,6 @@ import java.util.zip.DataFormatException;
|
||||
* Provides an interface to inflate and deflate {@link ByteBuf}s using zlib.
|
||||
*/
|
||||
public interface VelocityCompressor extends Disposable {
|
||||
|
||||
/**
|
||||
* The default preferred output buffer size for zlib.
|
||||
*/
|
||||
int ZLIB_BUFFER_SIZE = 8192;
|
||||
|
||||
void inflate(ByteBuf source, ByteBuf destination) throws DataFormatException;
|
||||
|
||||
void deflate(ByteBuf source, ByteBuf destination) throws DataFormatException;
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.velocitypowered.natives.util;
|
||||
|
||||
public class NativeConstants {
|
||||
/**
|
||||
* The default preferred output buffer size for zlib.
|
||||
*/
|
||||
public static final int ZLIB_BUFFER_SIZE = 8192;
|
||||
|
||||
private NativeConstants() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.velocitypowered.natives.util;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.natives.NativeSetupException;
|
||||
import com.velocitypowered.natives.compression.JavaVelocityCompressor;
|
||||
import com.velocitypowered.natives.compression.NativeVelocityCompressor;
|
||||
import com.velocitypowered.natives.compression.VelocityCompressorFactory;
|
||||
@ -37,7 +38,7 @@ public class Natives {
|
||||
}));
|
||||
System.load(tempFile.toAbsolutePath().toString());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new NativeSetupException("Unable to copy natives", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -57,12 +58,12 @@ public class Natives {
|
||||
|
||||
public static final NativeCodeLoader<VelocityCipherFactory> cipher = new NativeCodeLoader<>(
|
||||
ImmutableList.of(
|
||||
/*new NativeCodeLoader.Variant<>(NativeCodeLoader.MACOS,
|
||||
copyAndLoadNative("/macosx/velocity-cipher.dylib"), "mbed TLS (macOS)",
|
||||
NativeVelocityCipher.FACTORY),
|
||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.LINUX,
|
||||
copyAndLoadNative("/linux_x64/velocity-cipher.so"), "mbed TLS (Linux amd64)",
|
||||
NativeVelocityCipher.FACTORY),*/
|
||||
/*new NativeCodeLoader.Variant<>(NativeCodeLoader.MACOS,
|
||||
copyAndLoadNative("/macosx/velocity-cipher.dylib"), "mbed TLS (macOS)",
|
||||
NativeVelocityCipher.FACTORY),
|
||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.LINUX,
|
||||
copyAndLoadNative("/linux_x64/velocity-cipher.so"), "mbed TLS (Linux amd64)",
|
||||
NativeVelocityCipher.FACTORY),*/
|
||||
new NativeCodeLoader.Variant<>(NativeCodeLoader.ALWAYS, () -> {
|
||||
}, "Java", JavaVelocityCipher.FACTORY)
|
||||
)
|
||||
|
@ -91,6 +91,15 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(Chat packet) {
|
||||
VelocityServerConnection serverConnection = player.getConnectedServer();
|
||||
if (serverConnection == null) {
|
||||
return true;
|
||||
}
|
||||
MinecraftConnection smc = serverConnection.getConnection();
|
||||
if (smc == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String msg = packet.getMessage();
|
||||
if (msg.startsWith("/")) {
|
||||
try {
|
||||
@ -106,14 +115,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
VelocityServerConnection serverConnection = player.getConnectedServer();
|
||||
if (serverConnection == null) {
|
||||
return true;
|
||||
}
|
||||
MinecraftConnection smc = serverConnection.getConnection();
|
||||
if (smc == null) {
|
||||
return true;
|
||||
}
|
||||
PlayerChatEvent event = new PlayerChatEvent(player, msg);
|
||||
server.getEventManager().fire(event)
|
||||
.thenAcceptAsync(pme -> {
|
||||
|
@ -43,9 +43,8 @@ public class JavaPluginLoader implements PluginLoader {
|
||||
}
|
||||
|
||||
SerializedPluginDescription pd = serialized.get();
|
||||
if (!PluginDescription.ID_PATTERN.matcher(pd.getId()).matches()) {
|
||||
throw new InvalidPluginException("Plugin ID '" + pd.getId() + "' must match pattern " +
|
||||
PluginDescription.ID_PATTERN.pattern());
|
||||
if (!SerializedPluginDescription.ID_PATTERN.matcher(pd.getId()).matches()) {
|
||||
throw new InvalidPluginException("Plugin ID '" + pd.getId() + "' is invalid.");
|
||||
}
|
||||
|
||||
PluginClassLoader loader = new PluginClassLoader(
|
||||
|
@ -69,6 +69,25 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
private QueryResponse createInitialResponse() {
|
||||
return QueryResponse.builder()
|
||||
.hostname(ComponentSerializers.PLAIN
|
||||
.serialize(server.getConfiguration().getMotdComponent()))
|
||||
.gameVersion(ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING)
|
||||
.map(server.getConfiguration().getQueryMap())
|
||||
.currentPlayers(server.getPlayerCount())
|
||||
.maxPlayers(server.getConfiguration().getShowMaxPlayers())
|
||||
.proxyPort(server.getConfiguration().getBind().getPort())
|
||||
.proxyHost(server.getConfiguration().getBind().getHostString())
|
||||
.players(server.getAllPlayers().stream().map(Player::getUsername)
|
||||
.collect(Collectors.toList()))
|
||||
.proxyVersion("Velocity")
|
||||
.plugins(
|
||||
server.getConfiguration().shouldQueryShowPlugins() ? getRealPluginInformation()
|
||||
: Collections.emptyList())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
|
||||
ByteBuf queryMessage = msg.content();
|
||||
@ -117,22 +136,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
}
|
||||
|
||||
// Build query response
|
||||
QueryResponse response = QueryResponse.builder()
|
||||
.hostname(ComponentSerializers.PLAIN
|
||||
.serialize(server.getConfiguration().getMotdComponent()))
|
||||
.gameVersion(ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING)
|
||||
.map(server.getConfiguration().getQueryMap())
|
||||
.currentPlayers(server.getPlayerCount())
|
||||
.maxPlayers(server.getConfiguration().getShowMaxPlayers())
|
||||
.proxyPort(server.getConfiguration().getBind().getPort())
|
||||
.proxyHost(server.getConfiguration().getBind().getHostString())
|
||||
.players(server.getAllPlayers().stream().map(Player::getUsername)
|
||||
.collect(Collectors.toList()))
|
||||
.proxyVersion("Velocity")
|
||||
.plugins(
|
||||
server.getConfiguration().shouldQueryShowPlugins() ? getRealPluginInformation()
|
||||
: Collections.emptyList())
|
||||
.build();
|
||||
QueryResponse response = createInitialResponse();
|
||||
|
||||
boolean isBasic = queryMessage.readableBytes() == 0;
|
||||
|
||||
|
@ -50,14 +50,13 @@ public class PlayerListItem implements MinecraftPacket {
|
||||
Item item = new Item(ProtocolUtils.readUuid(buf));
|
||||
items.add(item);
|
||||
switch (action) {
|
||||
case ADD_PLAYER: {
|
||||
case ADD_PLAYER:
|
||||
item.setName(ProtocolUtils.readString(buf));
|
||||
item.setProperties(ProtocolUtils.readProperties(buf));
|
||||
item.setGameMode(ProtocolUtils.readVarInt(buf));
|
||||
item.setLatency(ProtocolUtils.readVarInt(buf));
|
||||
item.setDisplayName(readOptionalComponent(buf));
|
||||
break;
|
||||
}
|
||||
case UPDATE_GAMEMODE:
|
||||
item.setGameMode(ProtocolUtils.readVarInt(buf));
|
||||
break;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren