Use sealed types in command interfaces (#1239)

* Use sealed types in command interfaces

* Some minor code fixes
This commit is contained in:
Adrian
2024-02-09 14:15:53 -05:00
committed by GitHub
parent 6f7f722bfb
commit 7bff6b19eb
6 changed files with 51 additions and 43 deletions

View File

@@ -29,5 +29,5 @@ import com.velocitypowered.api.proxy.Player;
*
* </ul>
*/
public interface Command {
public sealed interface Command permits BrigadierCommand, InvocableCommand {
}

View File

@@ -21,7 +21,8 @@ import java.util.concurrent.CompletableFuture;
*
* @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.

View File

@@ -12,7 +12,7 @@ package com.velocitypowered.api.command;
* the command and its arguments directly without further processing.
* 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.

View File

@@ -16,7 +16,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
* <p>Prefer using {@link BrigadierCommand}, which is also
* 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.