3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 15:20:35 +01:00

Small code cleanups

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-09-01 03:25:15 -04:00
Ursprung 5a26b4e03d
Commit 5d287306c2
31 geänderte Dateien mit 42 neuen und 93 gelöschten Zeilen

Datei anzeigen

@ -5,6 +5,6 @@ package com.velocitypowered.api.event;
*/
public enum PostOrder {
FIRST, EARLY, NORMAL, LATE, LAST;
FIRST, EARLY, NORMAL, LATE, LAST
}

Datei anzeigen

@ -2,7 +2,6 @@ package com.velocitypowered.api.event.connection;
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.CANCELLED_BY_PROXY;
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.CONFLICTING_LOGIN;
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.PRE_SERVER_JOIN;
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN;
import com.google.common.base.Preconditions;

Datei anzeigen

@ -58,7 +58,7 @@ public interface ProxyServer extends Audience {
* Broadcasts a message to all players currently online.
*
* @param component the message to send
* @deprecated Use {@link #sendMessage(Component)} instead
* @deprecated Use {@link #sendMessage(net.kyori.adventure.text.Component)} instead
*/
@Deprecated
void broadcast(net.kyori.text.Component component);

Datei anzeigen

@ -24,6 +24,7 @@
package com.velocitypowered.api.util;
import java.util.Arrays;
import java.util.UUID;
/**
@ -41,9 +42,7 @@ class FastUuidSansHyphens {
private static final long[] HEX_VALUES = new long[128];
static {
for (int i = 0; i < HEX_VALUES.length; i++) {
HEX_VALUES[i] = -1;
}
Arrays.fill(HEX_VALUES, -1);
HEX_VALUES['0'] = 0x0;
HEX_VALUES['1'] = 0x1;

Datei anzeigen

@ -13,5 +13,5 @@ public enum BossBarColor {
GREEN,
YELLOW,
PURPLE,
WHITE;
WHITE
}

Datei anzeigen

@ -3,8 +3,6 @@ package com.velocitypowered.natives.encryption;
import com.google.common.base.Preconditions;
import com.velocitypowered.natives.util.BufferPreference;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import java.security.GeneralSecurityException;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;

Datei anzeigen

@ -3,8 +3,6 @@ package com.velocitypowered.natives.encryption;
import com.velocitypowered.natives.Disposable;
import com.velocitypowered.natives.Native;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import javax.crypto.ShortBufferException;
public interface VelocityCipher extends Disposable, Native {
void process(ByteBuf source);

Datei anzeigen

@ -27,19 +27,14 @@ public class NativeConstraints {
static final BooleanSupplier NATIVE_BASE = () -> NATIVES_ENABLED && CAN_GET_MEMORYADDRESS;
static final BooleanSupplier LINUX_X86_64 = () -> {
return NATIVE_BASE.getAsBoolean()
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux")
&& IS_AMD64;
};
static final BooleanSupplier LINUX_X86_64 = () -> NATIVE_BASE.getAsBoolean()
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux")
&& IS_AMD64;
static final BooleanSupplier LINUX_AARCH64 = () -> {
return NATIVE_BASE.getAsBoolean()
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux")
&& IS_AARCH64;
};
static final BooleanSupplier LINUX_AARCH64 = () -> NATIVE_BASE.getAsBoolean()
&& System.getProperty("os.name", "").equalsIgnoreCase("Linux")
&& IS_AARCH64;
static final BooleanSupplier JAVA_11 = () -> {
return Double.parseDouble(System.getProperty("java.specification.version")) >= 11;
};
static final BooleanSupplier JAVA_11 = () -> Double.parseDouble(
System.getProperty("java.specification.version")) >= 11;
}

Datei anzeigen

@ -23,7 +23,7 @@ import org.junit.jupiter.api.condition.JRE;
class VelocityCompressorTest {
private static byte[] TEST_DATA = new byte[1 << 14];
private static final byte[] TEST_DATA = new byte[1 << 14];
@BeforeAll
static void checkNatives() throws IOException {

Datei anzeigen

@ -225,8 +225,6 @@ public class Metrics {
)
) {
VelocityServer.GENERAL_GSON.toJson(object, writer);
} catch (IOException e) {
throw e;
}
return os.toByteArray();
}

Datei anzeigen

@ -22,11 +22,10 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.UUID;
@ -73,13 +72,15 @@ public class VelocityConfiguration implements ProxyConfig {
}
private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode,
boolean announceForge, PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
boolean preventClientProxyConnections, boolean announceForge,
PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret,
boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough, Servers servers,
ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics, Messages messages) {
this.bind = bind;
this.motd = motd;
this.showMaxPlayers = showMaxPlayers;
this.onlineMode = onlineMode;
this.preventClientProxyConnections = preventClientProxyConnections;
this.announceForge = announceForge;
this.playerInfoForwardingMode = playerInfoForwardingMode;
this.forwardingSecret = forwardingSecret;
@ -460,6 +461,8 @@ public class VelocityConfiguration implements ProxyConfig {
int maxPlayers = config.getIntOrElse("show-max-players", 500);
Boolean onlineMode = config.getOrElse("online-mode", true);
Boolean announceForge = config.getOrElse("announce-forge", true);
Boolean preventClientProxyConnections = config.getOrElse("prevent-client-proxy-connections",
true);
Boolean kickExisting = config.getOrElse("kick-existing-players", false);
return new VelocityConfiguration(
@ -468,6 +471,7 @@ public class VelocityConfiguration implements ProxyConfig {
maxPlayers,
onlineMode,
announceForge,
preventClientProxyConnections,
forwardingMode,
forwardingSecret,
kickExisting,
@ -484,7 +488,7 @@ public class VelocityConfiguration implements ProxyConfig {
private static String generateRandomString(int length) {
String chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";
StringBuilder builder = new StringBuilder();
Random rnd = new Random();
Random rnd = new SecureRandom();
for (int i = 0; i < length; i++) {
builder.append(chars.charAt(rnd.nextInt(chars.length())));
}
@ -502,7 +506,7 @@ public class VelocityConfiguration implements ProxyConfig {
"factions", "127.0.0.1:30067",
"minigames", "127.0.0.1:30068"
);
private List<String> attemptConnectionOrder = Arrays.asList("lobby");
private List<String> attemptConnectionOrder = ImmutableList.of("lobby");
private Servers() {
}

Datei anzeigen

@ -27,7 +27,6 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.packet.Handshake;
import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;

Datei anzeigen

@ -173,6 +173,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
RootCommandNode<CommandSource> dispatcherRootNode =
(RootCommandNode<CommandSource>)
filterNode(server.getCommandManager().getDispatcher().getRoot());
assert dispatcherRootNode != null : "Filtering root node returned null.";
Collection<CommandNode<CommandSource>> proxyNodes = dispatcherRootNode.getChildren();
for (CommandNode<CommandSource> node : proxyNodes) {
CommandNode<CommandSource> existingServerChild = rootNode.getChild(node.getName());

Datei anzeigen

@ -19,7 +19,6 @@ import io.netty.buffer.Unpooled;
import java.util.Optional;
import java.util.StringJoiner;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@ -158,9 +157,7 @@ class BungeeCordMessageResponder {
if (target.equals("ALL")) {
proxy.sendMessage(messageComponent);
} else {
proxy.getPlayer(target).ifPresent(player -> {
player.sendMessage(messageComponent);
});
proxy.getPlayer(target).ifPresent(player -> player.sendMessage(messageComponent));
}
}

Datei anzeigen

@ -91,7 +91,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
return;
}
// Strap on the ClientPlaySessionHandler if required.
// Change the client to use the ClientPlaySessionHandler if required.
ClientPlaySessionHandler playHandler;
if (serverConn.getPlayer().getConnection().getSessionHandler()
instanceof ClientPlaySessionHandler) {

Datei anzeigen

@ -14,7 +14,6 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Disconnect;
import com.velocitypowered.proxy.protocol.packet.Handshake;
import com.velocitypowered.proxy.protocol.packet.LegacyDisconnect;
import com.velocitypowered.proxy.protocol.packet.LegacyHandshake;
@ -23,7 +22,6 @@ import io.netty.buffer.ByteBuf;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Optional;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.format.NamedTextColor;

Datei anzeigen

@ -42,7 +42,6 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import net.kyori.adventure.text.Component;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Datei anzeigen

@ -161,10 +161,9 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
this.pingReceived = true;
getInitialPing()
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
.thenAcceptAsync(event -> {
connection.closeWith(LegacyDisconnect.fromServerPing(event.getPing(),
packet.getVersion()));
}, connection.eventLoop());
.thenAcceptAsync(event -> connection.closeWith(
LegacyDisconnect.fromServerPing(event.getPing(), packet.getVersion())),
connection.eventLoop());
return true;
}

Datei anzeigen

@ -17,7 +17,6 @@ import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription;
import java.io.BufferedInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

Datei anzeigen

@ -276,8 +276,8 @@ public enum ProtocolUtils {
return;
}
writeVarInt(buf, stringArray.length);
for (int i = 0; i < stringArray.length; i++) {
writeString(buf, stringArray[i]);
for (String s : stringArray) {
writeString(buf, s);
}
}

Datei anzeigen

@ -2,7 +2,6 @@ package com.velocitypowered.proxy.protocol.netty;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.util.ReferenceCountUtil;
import java.util.ArrayDeque;
import java.util.Queue;

Datei anzeigen

@ -15,8 +15,8 @@ public class HeaderAndFooter implements MinecraftPacket {
private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}";
private static final HeaderAndFooter RESET = new HeaderAndFooter();
private String header;
private String footer;
private final String header;
private final String footer;
public HeaderAndFooter() {
this(EMPTY_COMPONENT, EMPTY_COMPONENT);

Datei anzeigen

@ -246,8 +246,7 @@ public class JoinGame implements MinecraftPacket {
}
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
buf.writeByte(previousGamemode);
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray(
new String[dimensionRegistry.getLevelNames().size()]));
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray(new String[0]));
CompoundBinaryTag.Builder registryContainer = CompoundBinaryTag.builder();
ListBinaryTag encodedDimensionRegistry = dimensionRegistry.encodeRegistry(version);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {

Datei anzeigen

@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -13,7 +12,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;

Datei anzeigen

@ -9,7 +9,7 @@ import io.netty.buffer.ByteBuf;
class FloatArgumentPropertySerializer implements ArgumentPropertySerializer<FloatArgumentType> {
static FloatArgumentPropertySerializer FLOAT = new FloatArgumentPropertySerializer();
static final FloatArgumentPropertySerializer FLOAT = new FloatArgumentPropertySerializer();
private FloatArgumentPropertySerializer() {

Datei anzeigen

@ -2,7 +2,6 @@ package com.velocitypowered.proxy.protocol.util;
import com.google.common.io.ByteArrayDataInput;
import io.netty.buffer.ByteBuf;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;

Datei anzeigen

@ -3,7 +3,6 @@ package com.velocitypowered.proxy.protocol.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.util.ProxyVersion;

Datei anzeigen

@ -27,7 +27,6 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoop;
@ -39,7 +38,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -100,16 +98,13 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
}
})
.connect(serverInfo.getAddress())
.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
MinecraftConnection conn = future.channel().pipeline().get(MinecraftConnection.class);
conn.setSessionHandler(new PingSessionHandler(
pingFuture, VelocityRegisteredServer.this, conn, version));
} else {
pingFuture.completeExceptionally(future.cause());
}
.addListener((ChannelFutureListener) future -> {
if (future.isSuccess()) {
MinecraftConnection conn = future.channel().pipeline().get(MinecraftConnection.class);
conn.setSessionHandler(new PingSessionHandler(
pingFuture, VelocityRegisteredServer.this, conn, version));
} else {
pingFuture.completeExceptionally(future.cause());
}
});
return pingFuture;

Datei anzeigen

@ -1,9 +1,6 @@
package com.velocitypowered.proxy.tablist;
import static com.google.common.base.Verify.verify;
import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile;

Datei anzeigen

@ -127,25 +127,6 @@ public final class BrigadierUtils {
return command.toLowerCase(Locale.ENGLISH);
}
/**
* Prepares the given command node prior for hinting metadata to
* a {@link com.velocitypowered.api.command.Command}.
*
* @param node the command node to be wrapped
* @param command the command to execute
* @return the wrapped command node
*/
public static CommandNode<CommandSource> wrapForHinting(
final CommandNode<CommandSource> node, final @Nullable Command<CommandSource> command) {
Preconditions.checkNotNull(node, "node");
ArgumentBuilder<CommandSource, ?> builder = node.createBuilder();
builder.executes(command);
for (CommandNode<CommandSource> child : node.getChildren()) {
builder.then(wrapForHinting(child, command));
}
return builder.build();
}
private BrigadierUtils() {
throw new AssertionError();
}

Datei anzeigen

@ -8,7 +8,6 @@ import com.velocitypowered.api.plugin.PluginDescription;
import com.velocitypowered.api.plugin.meta.PluginDependency;
import com.velocitypowered.proxy.plugin.loader.VelocityPluginDescription;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.junit.jupiter.api.Test;