geforkt von Mirrors/Velocity
Use sealed types in command interfaces (#1239)
* Use sealed types in command interfaces * Some minor code fixes
Dieser Commit ist enthalten in:
Ursprung
6f7f722bfb
Commit
7bff6b19eb
@ -29,5 +29,5 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
*
|
*
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public interface Command {
|
public sealed interface Command permits BrigadierCommand, InvocableCommand {
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
*
|
*
|
||||||
* @param <I> the type of the command invocation object
|
* @param <I> the type of the command invocation object
|
||||||
*/
|
*/
|
||||||
public interface InvocableCommand<I extends CommandInvocation<?>> extends Command {
|
public sealed interface InvocableCommand<I extends CommandInvocation<?>> extends Command
|
||||||
|
permits RawCommand, SimpleCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the command for the specified invocation.
|
* Executes the command for the specified invocation.
|
||||||
|
@ -12,7 +12,7 @@ package com.velocitypowered.api.command;
|
|||||||
* the command and its arguments directly without further processing.
|
* the command and its arguments directly without further processing.
|
||||||
* This is useful for bolting on external command frameworks to Velocity.
|
* This is useful for bolting on external command frameworks to Velocity.
|
||||||
*/
|
*/
|
||||||
public interface RawCommand extends InvocableCommand<RawCommand.Invocation> {
|
public non-sealed interface RawCommand extends InvocableCommand<RawCommand.Invocation> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the invocation data for a raw command.
|
* Contains the invocation data for a raw command.
|
||||||
|
@ -16,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
* <p>Prefer using {@link BrigadierCommand}, which is also
|
* <p>Prefer using {@link BrigadierCommand}, which is also
|
||||||
* backwards-compatible with older clients.
|
* backwards-compatible with older clients.
|
||||||
*/
|
*/
|
||||||
public interface SimpleCommand extends InvocableCommand<SimpleCommand.Invocation> {
|
public non-sealed interface SimpleCommand extends InvocableCommand<SimpleCommand.Invocation> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the invocation data for a simple command.
|
* Contains the invocation data for a simple command.
|
||||||
|
@ -93,6 +93,7 @@ import java.util.concurrent.TimeoutException;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.IntFunction;
|
import java.util.function.IntFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.audience.ForwardingAudience;
|
import net.kyori.adventure.audience.ForwardingAudience;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
@ -143,7 +144,6 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
|||||||
|
|
||||||
private final ConnectionManager cm;
|
private final ConnectionManager cm;
|
||||||
private final ProxyOptions options;
|
private final ProxyOptions options;
|
||||||
private final HttpClient httpClient;
|
|
||||||
private @MonotonicNonNull VelocityConfiguration configuration;
|
private @MonotonicNonNull VelocityConfiguration configuration;
|
||||||
private @MonotonicNonNull KeyPair serverKeyPair;
|
private @MonotonicNonNull KeyPair serverKeyPair;
|
||||||
private final ServerMap servers;
|
private final ServerMap servers;
|
||||||
@ -159,7 +159,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
|||||||
private final VelocityEventManager eventManager;
|
private final VelocityEventManager eventManager;
|
||||||
private final VelocityScheduler scheduler;
|
private final VelocityScheduler scheduler;
|
||||||
private final VelocityChannelRegistrar channelRegistrar = new VelocityChannelRegistrar();
|
private final VelocityChannelRegistrar channelRegistrar = new VelocityChannelRegistrar();
|
||||||
private ServerListPingHandler serverListPingHandler;
|
private final ServerListPingHandler serverListPingHandler;
|
||||||
|
|
||||||
VelocityServer(final ProxyOptions options) {
|
VelocityServer(final ProxyOptions options) {
|
||||||
pluginManager = new VelocityPluginManager(this);
|
pluginManager = new VelocityPluginManager(this);
|
||||||
@ -168,7 +168,6 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
|||||||
scheduler = new VelocityScheduler(pluginManager);
|
scheduler = new VelocityScheduler(pluginManager);
|
||||||
console = new VelocityConsole(this);
|
console = new VelocityConsole(this);
|
||||||
cm = new ConnectionManager(this);
|
cm = new ConnectionManager(this);
|
||||||
httpClient = HttpClient.newHttpClient();
|
|
||||||
servers = new ServerMap(this);
|
servers = new ServerMap(this);
|
||||||
serverListPingHandler = new ServerListPingHandler(this);
|
serverListPingHandler = new ServerListPingHandler(this);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -282,40 +281,39 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
|||||||
try {
|
try {
|
||||||
if (!Files.exists(langPath)) {
|
if (!Files.exists(langPath)) {
|
||||||
Files.createDirectory(langPath);
|
Files.createDirectory(langPath);
|
||||||
Files.walk(path).forEach(file -> {
|
try (final Stream<Path> files = Files.walk(path)) {
|
||||||
if (!Files.isRegularFile(file)) {
|
files.filter(Files::isRegularFile).forEach(file -> {
|
||||||
return;
|
try {
|
||||||
}
|
final Path langFile = langPath.resolve(file.getFileName().toString());
|
||||||
try {
|
if (!Files.exists(langFile)) {
|
||||||
Path langFile = langPath.resolve(file.getFileName().toString());
|
try (final InputStream is = Files.newInputStream(file)) {
|
||||||
if (!Files.exists(langFile)) {
|
Files.copy(is, langFile);
|
||||||
try (InputStream is = Files.newInputStream(file)) {
|
}
|
||||||
Files.copy(is, langFile);
|
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Encountered an I/O error whilst loading translations", e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
});
|
||||||
logger.error("Encountered an I/O error whilst loading translations", e);
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
try (final Stream<Path> files = Files.walk(langPath)) {
|
||||||
|
files.filter(Files::isRegularFile).forEach(file -> {
|
||||||
|
final String filename = com.google.common.io.Files
|
||||||
|
.getNameWithoutExtension(file.getFileName().toString());
|
||||||
|
final String localeName = filename.replace("messages_", "")
|
||||||
|
.replace("messages", "")
|
||||||
|
.replace('_', '-');
|
||||||
|
final Locale locale = localeName.isBlank()
|
||||||
|
? Locale.US
|
||||||
|
: Locale.forLanguageTag(localeName);
|
||||||
|
|
||||||
|
translationRegistry.registerAll(locale, file, false);
|
||||||
|
ClosestLocaleMatcher.INSTANCE.registerKnown(locale);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Files.walk(langPath).forEach(file -> {
|
|
||||||
if (!Files.isRegularFile(file)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String filename = com.google.common.io.Files
|
|
||||||
.getNameWithoutExtension(file.getFileName().toString());
|
|
||||||
String localeName = filename.replace("messages_", "")
|
|
||||||
.replace("messages", "")
|
|
||||||
.replace('_', '-');
|
|
||||||
Locale locale = localeName.isBlank()
|
|
||||||
? Locale.US
|
|
||||||
: Locale.forLanguageTag(localeName);
|
|
||||||
|
|
||||||
translationRegistry.registerAll(locale, file, false);
|
|
||||||
ClosestLocaleMatcher.INSTANCE.registerKnown(locale);
|
|
||||||
});
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Encountered an I/O error whilst loading translations", e);
|
logger.error("Encountered an I/O error whilst loading translations", e);
|
||||||
}
|
}
|
||||||
@ -419,10 +417,9 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
|||||||
// move back to a fallback server.
|
// move back to a fallback server.
|
||||||
Collection<ConnectedPlayer> evacuate = new ArrayList<>();
|
Collection<ConnectedPlayer> evacuate = new ArrayList<>();
|
||||||
for (Map.Entry<String, String> entry : newConfiguration.getServers().entrySet()) {
|
for (Map.Entry<String, String> entry : newConfiguration.getServers().entrySet()) {
|
||||||
ServerInfo newInfo =
|
ServerInfo newInfo = new ServerInfo(entry.getKey(), AddressUtil.parseAddress(entry.getValue()));
|
||||||
new ServerInfo(entry.getKey(), AddressUtil.parseAddress(entry.getValue()));
|
|
||||||
Optional<RegisteredServer> rs = servers.getServer(entry.getKey());
|
Optional<RegisteredServer> rs = servers.getServer(entry.getKey());
|
||||||
if (!rs.isPresent()) {
|
if (rs.isEmpty()) {
|
||||||
servers.register(newInfo);
|
servers.register(newInfo);
|
||||||
} else if (!rs.get().getServerInfo().equals(newInfo)) {
|
} else if (!rs.get().getServerInfo().equals(newInfo)) {
|
||||||
for (Player player : rs.get().getPlayersConnected()) {
|
for (Player player : rs.get().getPlayersConnected()) {
|
||||||
|
@ -84,14 +84,14 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(HandshakePacket handshake) {
|
public boolean handle(final HandshakePacket handshake) {
|
||||||
final InitialInboundConnection ic = new InitialInboundConnection(connection,
|
|
||||||
cleanVhost(handshake.getServerAddress()), handshake);
|
|
||||||
final StateRegistry nextState = getStateForProtocol(handshake.getNextStatus());
|
final StateRegistry nextState = getStateForProtocol(handshake.getNextStatus());
|
||||||
if (nextState == null) {
|
if (nextState == null) {
|
||||||
LOGGER.error("{} provided invalid protocol {}", ic, handshake.getNextStatus());
|
LOGGER.error("{} provided invalid protocol {}", this, handshake.getNextStatus());
|
||||||
connection.close(true);
|
connection.close(true);
|
||||||
} else {
|
} else {
|
||||||
|
final InitialInboundConnection ic = new InitialInboundConnection(connection,
|
||||||
|
cleanVhost(handshake.getServerAddress()), handshake);
|
||||||
connection.setProtocolVersion(handshake.getProtocolVersion());
|
connection.setProtocolVersion(handshake.getProtocolVersion());
|
||||||
connection.setAssociation(ic);
|
connection.setAssociation(ic);
|
||||||
|
|
||||||
@ -208,6 +208,16 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
|||||||
connection.close(true);
|
connection.close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
final boolean isPlayerAddressLoggingEnabled = connection.server.getConfiguration()
|
||||||
|
.isPlayerAddressLoggingEnabled();
|
||||||
|
final String playerIp =
|
||||||
|
isPlayerAddressLoggingEnabled
|
||||||
|
? this.connection.getRemoteAddress().toString() : "<ip address withheld>";
|
||||||
|
return "[initial connection] " + playerIp;
|
||||||
|
}
|
||||||
|
|
||||||
private record LegacyInboundConnection(
|
private record LegacyInboundConnection(
|
||||||
MinecraftConnection connection,
|
MinecraftConnection connection,
|
||||||
LegacyPingPacket ping
|
LegacyPingPacket ping
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren