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.google.gson.Gson;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.plugin.PluginDescription;
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
@ -66,7 +65,7 @@ public class PluginAnnotationProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Plugin plugin = element.getAnnotation(Plugin.class);
|
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 "
|
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Invalid ID for plugin "
|
||||||
+ qualifiedName
|
+ qualifiedName
|
||||||
+ ". IDs must start alphabetically, have alphanumeric characters, and can "
|
+ ". IDs must start alphabetically, have alphanumeric characters, and can "
|
||||||
|
@ -8,11 +8,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class SerializedPluginDescription {
|
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
|
// @Nullable is used here to make GSON skip these in the serialized file
|
||||||
private final String id;
|
private final String id;
|
||||||
private final @Nullable String name;
|
private final @Nullable String name;
|
||||||
@ -26,7 +29,9 @@ public class SerializedPluginDescription {
|
|||||||
private SerializedPluginDescription(String id, String name, String version, String description,
|
private SerializedPluginDescription(String id, String name, String version, String description,
|
||||||
String url,
|
String url,
|
||||||
List<String> authors, List<Dependency> dependencies, String main) {
|
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.name = Strings.emptyToNull(name);
|
||||||
this.version = Strings.emptyToNull(version);
|
this.version = Strings.emptyToNull(version);
|
||||||
this.description = Strings.emptyToNull(description);
|
this.description = Strings.emptyToNull(description);
|
||||||
|
@ -4,7 +4,7 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.velocitypowered.api.proxy.InboundConnection;
|
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 {
|
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
|
* 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
|
* @return the ID for this plugin
|
||||||
*/
|
*/
|
||||||
|
@ -186,21 +186,23 @@ public final class TextTitle implements Title {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder stay(int ticks) {
|
private int checkTicks(int ticks) {
|
||||||
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", 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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fadeIn(int ticks) {
|
public Builder fadeIn(int ticks) {
|
||||||
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
|
this.fadeIn = checkTicks(ticks);
|
||||||
this.fadeIn = ticks;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fadeOut(int ticks) {
|
public Builder fadeOut(int ticks) {
|
||||||
Preconditions.checkArgument(ticks >= 0, "ticks value %s is negative", ticks);
|
this.fadeOut = checkTicks(ticks);
|
||||||
this.fadeOut = ticks;
|
|
||||||
return this;
|
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;
|
package com.velocitypowered.natives.compression;
|
||||||
|
|
||||||
|
import static com.velocitypowered.natives.util.NativeConstants.ZLIB_BUFFER_SIZE;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.velocitypowered.natives.compression;
|
package com.velocitypowered.natives.compression;
|
||||||
|
|
||||||
|
import static com.velocitypowered.natives.util.NativeConstants.ZLIB_BUFFER_SIZE;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.util.zip.DataFormatException;
|
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.
|
* Provides an interface to inflate and deflate {@link ByteBuf}s using zlib.
|
||||||
*/
|
*/
|
||||||
public interface VelocityCompressor extends Disposable {
|
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 inflate(ByteBuf source, ByteBuf destination) throws DataFormatException;
|
||||||
|
|
||||||
void deflate(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;
|
package com.velocitypowered.natives.util;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.velocitypowered.natives.NativeSetupException;
|
||||||
import com.velocitypowered.natives.compression.JavaVelocityCompressor;
|
import com.velocitypowered.natives.compression.JavaVelocityCompressor;
|
||||||
import com.velocitypowered.natives.compression.NativeVelocityCompressor;
|
import com.velocitypowered.natives.compression.NativeVelocityCompressor;
|
||||||
import com.velocitypowered.natives.compression.VelocityCompressorFactory;
|
import com.velocitypowered.natives.compression.VelocityCompressorFactory;
|
||||||
@ -37,7 +38,7 @@ public class Natives {
|
|||||||
}));
|
}));
|
||||||
System.load(tempFile.toAbsolutePath().toString());
|
System.load(tempFile.toAbsolutePath().toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new NativeSetupException("Unable to copy natives", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,15 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(Chat packet) {
|
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();
|
String msg = packet.getMessage();
|
||||||
if (msg.startsWith("/")) {
|
if (msg.startsWith("/")) {
|
||||||
try {
|
try {
|
||||||
@ -106,14 +115,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
PlayerChatEvent event = new PlayerChatEvent(player, msg);
|
||||||
server.getEventManager().fire(event)
|
server.getEventManager().fire(event)
|
||||||
.thenAcceptAsync(pme -> {
|
.thenAcceptAsync(pme -> {
|
||||||
|
@ -43,9 +43,8 @@ public class JavaPluginLoader implements PluginLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SerializedPluginDescription pd = serialized.get();
|
SerializedPluginDescription pd = serialized.get();
|
||||||
if (!PluginDescription.ID_PATTERN.matcher(pd.getId()).matches()) {
|
if (!SerializedPluginDescription.ID_PATTERN.matcher(pd.getId()).matches()) {
|
||||||
throw new InvalidPluginException("Plugin ID '" + pd.getId() + "' must match pattern " +
|
throw new InvalidPluginException("Plugin ID '" + pd.getId() + "' is invalid.");
|
||||||
PluginDescription.ID_PATTERN.pattern());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginClassLoader loader = new PluginClassLoader(
|
PluginClassLoader loader = new PluginClassLoader(
|
||||||
|
@ -69,6 +69,25 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|||||||
this.server = server;
|
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
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
|
||||||
ByteBuf queryMessage = msg.content();
|
ByteBuf queryMessage = msg.content();
|
||||||
@ -117,22 +136,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build query response
|
// Build query response
|
||||||
QueryResponse response = QueryResponse.builder()
|
QueryResponse response = createInitialResponse();
|
||||||
.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();
|
|
||||||
|
|
||||||
boolean isBasic = queryMessage.readableBytes() == 0;
|
boolean isBasic = queryMessage.readableBytes() == 0;
|
||||||
|
|
||||||
|
@ -50,14 +50,13 @@ public class PlayerListItem implements MinecraftPacket {
|
|||||||
Item item = new Item(ProtocolUtils.readUuid(buf));
|
Item item = new Item(ProtocolUtils.readUuid(buf));
|
||||||
items.add(item);
|
items.add(item);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ADD_PLAYER: {
|
case ADD_PLAYER:
|
||||||
item.setName(ProtocolUtils.readString(buf));
|
item.setName(ProtocolUtils.readString(buf));
|
||||||
item.setProperties(ProtocolUtils.readProperties(buf));
|
item.setProperties(ProtocolUtils.readProperties(buf));
|
||||||
item.setGameMode(ProtocolUtils.readVarInt(buf));
|
item.setGameMode(ProtocolUtils.readVarInt(buf));
|
||||||
item.setLatency(ProtocolUtils.readVarInt(buf));
|
item.setLatency(ProtocolUtils.readVarInt(buf));
|
||||||
item.setDisplayName(readOptionalComponent(buf));
|
item.setDisplayName(readOptionalComponent(buf));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case UPDATE_GAMEMODE:
|
case UPDATE_GAMEMODE:
|
||||||
item.setGameMode(ProtocolUtils.readVarInt(buf));
|
item.setGameMode(ProtocolUtils.readVarInt(buf));
|
||||||
break;
|
break;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren