mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Reintroduce GeyserDefineCommandsEvent and cleanup a few things
This commit is contained in:
parent
c07c7b9337
commit
e5337b6298
22 changed files with 355 additions and 107 deletions
|
@ -1,4 +1,7 @@
|
|||
dependencies {
|
||||
api("org.geysermc.cumulus", "cumulus", Versions.cumulusVersion)
|
||||
api("org.geysermc.event", "events", Versions.eventsVersion)
|
||||
}
|
||||
api("org.geysermc.event", "events", Versions.eventsVersion) {
|
||||
exclude(group = "com.google.guava", module = "guava")
|
||||
exclude(group = "org.lanternpowered", module = "lmbda")
|
||||
}
|
||||
}
|
|
@ -69,7 +69,7 @@ public class Geyser {
|
|||
|
||||
/**
|
||||
* Registers the given api type. The api cannot be
|
||||
* registered if {@link #registered()} is true as
|
||||
* registered if {@link #isRegistered()} is true as
|
||||
* an api has already been specified.
|
||||
*
|
||||
* @param api the api
|
||||
|
@ -88,7 +88,7 @@ public class Geyser {
|
|||
*
|
||||
* @return if the api has been registered
|
||||
*/
|
||||
public static boolean registered() {
|
||||
public static boolean isRegistered() {
|
||||
return api != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.geysermc.api.Geyser;
|
||||
import org.geysermc.api.GeyserApiBase;
|
||||
import org.geysermc.geyser.api.command.CommandManager;
|
||||
import org.geysermc.geyser.api.connection.GeyserConnection;
|
||||
import org.geysermc.geyser.api.event.EventBus;
|
||||
import org.geysermc.geyser.api.extension.ExtensionManager;
|
||||
|
@ -66,15 +65,9 @@ public interface GeyserApi extends GeyserApiBase {
|
|||
*
|
||||
* @return the extension manager
|
||||
*/
|
||||
@NonNull
|
||||
ExtensionManager extensionManager();
|
||||
|
||||
/**
|
||||
* Gets the {@link CommandManager}.
|
||||
*
|
||||
* @return the command manager
|
||||
*/
|
||||
CommandManager commandManager();
|
||||
|
||||
/**
|
||||
* Provides an implementation for the specified API type.
|
||||
*
|
||||
|
@ -92,6 +85,7 @@ public interface GeyserApi extends GeyserApiBase {
|
|||
*
|
||||
* @return the event bus
|
||||
*/
|
||||
@NonNull
|
||||
EventBus eventBus();
|
||||
|
||||
/**
|
||||
|
@ -100,6 +94,7 @@ public interface GeyserApi extends GeyserApiBase {
|
|||
*
|
||||
* @return the default remote server used within Geyser
|
||||
*/
|
||||
@NonNull
|
||||
RemoteServer defaultRemoteServer();
|
||||
|
||||
/**
|
||||
|
@ -108,6 +103,7 @@ public interface GeyserApi extends GeyserApiBase {
|
|||
*
|
||||
* @return the listener used for Bedrock client connectins
|
||||
*/
|
||||
@NonNull
|
||||
BedrockListener bedrockListener();
|
||||
|
||||
/**
|
||||
|
@ -115,6 +111,7 @@ public interface GeyserApi extends GeyserApiBase {
|
|||
*
|
||||
* @return the current geyser api instance
|
||||
*/
|
||||
@NonNull
|
||||
static GeyserApi api() {
|
||||
return Geyser.api(GeyserApi.class);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ package org.geysermc.geyser.api.command;
|
|||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.api.GeyserApi;
|
||||
import org.geysermc.geyser.api.connection.GeyserConnection;
|
||||
import org.geysermc.geyser.api.extension.Extension;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -104,19 +106,39 @@ public interface Command {
|
|||
return false;
|
||||
}
|
||||
|
||||
static <T extends CommandSource> Command.Builder<T> builder(Class<T> sourceType) {
|
||||
return GeyserApi.api().provider(Builder.class, sourceType);
|
||||
/**
|
||||
* Creates a new {@link Command.Builder} used to construct commands.
|
||||
*
|
||||
* @param extension the extension
|
||||
* @param <T> the source type
|
||||
* @return a new command builder used to construct commands
|
||||
*/
|
||||
static <T extends CommandSource> Command.Builder<T> builder(@NonNull Extension extension) {
|
||||
return GeyserApi.api().provider(Builder.class, extension);
|
||||
}
|
||||
|
||||
interface Builder<T extends CommandSource> {
|
||||
|
||||
/**
|
||||
* Defines the source type to use for this command.
|
||||
* <p>
|
||||
* Command source types can be anything that extend
|
||||
* {@link CommandSource}, such as {@link GeyserConnection}.
|
||||
* This will guarantee that the source used in the executor
|
||||
* is an instance of this source.
|
||||
*
|
||||
* @param sourceType the source type
|
||||
* @return the builder
|
||||
*/
|
||||
Builder<T> source(@NonNull Class<? extends T> sourceType);
|
||||
|
||||
/**
|
||||
* Sets the command name.
|
||||
*
|
||||
* @param name the command name
|
||||
* @return the builder
|
||||
*/
|
||||
Builder<T> name(String name);
|
||||
Builder<T> name(@NonNull String name);
|
||||
|
||||
/**
|
||||
* Sets the command description.
|
||||
|
@ -124,7 +146,7 @@ public interface Command {
|
|||
* @param description the command description
|
||||
* @return the builder
|
||||
*/
|
||||
Builder<T> description(String description);
|
||||
Builder<T> description(@NonNull String description);
|
||||
|
||||
/**
|
||||
* Sets the permission node.
|
||||
|
@ -132,7 +154,7 @@ public interface Command {
|
|||
* @param permission the permission node
|
||||
* @return the builder
|
||||
*/
|
||||
Builder<T> permission(String permission);
|
||||
Builder<T> permission(@NonNull String permission);
|
||||
|
||||
/**
|
||||
* Sets the aliases.
|
||||
|
@ -140,7 +162,7 @@ public interface Command {
|
|||
* @param aliases the aliases
|
||||
* @return the builder
|
||||
*/
|
||||
Builder<T> aliases(List<String> aliases);
|
||||
Builder<T> aliases(@NonNull List<String> aliases);
|
||||
|
||||
/**
|
||||
* Sets if this command is designed to be used only by server operators.
|
||||
|
@ -164,7 +186,7 @@ public interface Command {
|
|||
* @param subCommands the subcommands
|
||||
* @return the builder
|
||||
*/
|
||||
Builder<T> subCommands(List<String> subCommands);
|
||||
Builder<T> subCommands(@NonNull List<String> subCommands);
|
||||
|
||||
/**
|
||||
* Sets if this command is bedrock only.
|
||||
|
@ -180,13 +202,14 @@ public interface Command {
|
|||
* @param executor the command executor
|
||||
* @return the builder
|
||||
*/
|
||||
Builder<T> executor(CommandExecutor<T> executor);
|
||||
Builder<T> executor(@NonNull CommandExecutor<T> executor);
|
||||
|
||||
/**
|
||||
* Builds the command.
|
||||
*
|
||||
* @return the command
|
||||
*/
|
||||
@NonNull
|
||||
Command build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,36 +23,35 @@
|
|||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.api.command;
|
||||
package org.geysermc.geyser.api.event.lifecycle;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.geyser.api.command.Command;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Manages Bedrock commands within Geyser.
|
||||
* Called when commands are defined within Geyser.
|
||||
*
|
||||
* This event allows you to register new commands using the {@link #register(Command)}
|
||||
* method and retrieve the default commands defined.
|
||||
*/
|
||||
public abstract class CommandManager {
|
||||
public interface GeyserDefineCommandsEvent extends Event {
|
||||
|
||||
/**
|
||||
* Registers the given {@link Command}.
|
||||
* Registers the given {@link Command} into the Geyser
|
||||
* command manager.
|
||||
*
|
||||
* @param command the command to register
|
||||
*/
|
||||
public abstract void register(@NonNull Command command);
|
||||
void register(@NonNull Command command);
|
||||
|
||||
/**
|
||||
* Unregisters the given {@link Command}.
|
||||
* Gets all the registered built-in {@link Command}s.
|
||||
*
|
||||
* @param command the command to unregister
|
||||
*/
|
||||
public abstract void unregister(@NonNull Command command);
|
||||
|
||||
/**
|
||||
* Gets all the registered {@link Command}s.
|
||||
*
|
||||
* @return all the registered commands
|
||||
* @return all the registered built-in commands
|
||||
*/
|
||||
@NonNull
|
||||
public abstract Map<String, Command> commands();
|
||||
Map<String, Command> commands();
|
||||
}
|
|
@ -27,12 +27,11 @@ package org.geysermc.geyser.api.event.lifecycle;
|
|||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.geyser.api.command.CommandManager;
|
||||
import org.geysermc.geyser.api.event.EventBus;
|
||||
import org.geysermc.geyser.api.extension.ExtensionManager;
|
||||
|
||||
/**
|
||||
* Called when Geyser is shutting down.
|
||||
*/
|
||||
public record GeyserShutdownEvent(@NonNull ExtensionManager extensionManager, @NonNull CommandManager commandManager, @NonNull EventBus eventBus) implements Event {
|
||||
public record GeyserShutdownEvent(@NonNull ExtensionManager extensionManager, @NonNull EventBus eventBus) implements Event {
|
||||
}
|
||||
|
|
|
@ -30,12 +30,20 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is the Geyser extension description
|
||||
* Represents the description of an {@link Extension}.
|
||||
*/
|
||||
public interface ExtensionDescription {
|
||||
|
||||
/**
|
||||
* Gets the extension's name
|
||||
* Gets the extension's id.
|
||||
*
|
||||
* @return the extension's id
|
||||
*/
|
||||
@NonNull
|
||||
String id();
|
||||
|
||||
/**
|
||||
* Gets the extension's name.
|
||||
*
|
||||
* @return the extension's name
|
||||
*/
|
||||
|
@ -43,7 +51,7 @@ public interface ExtensionDescription {
|
|||
String name();
|
||||
|
||||
/**
|
||||
* Gets the extension's main class
|
||||
* Gets the extension's main class.
|
||||
*
|
||||
* @return the extension's main class
|
||||
*/
|
||||
|
@ -51,7 +59,7 @@ public interface ExtensionDescription {
|
|||
String main();
|
||||
|
||||
/**
|
||||
* Gets the extension's api version
|
||||
* Gets the extension's api version.
|
||||
*
|
||||
* @return the extension's api version
|
||||
*/
|
||||
|
@ -59,7 +67,7 @@ public interface ExtensionDescription {
|
|||
String apiVersion();
|
||||
|
||||
/**
|
||||
* Gets the extension's description
|
||||
* Gets the extension's description.
|
||||
*
|
||||
* @return the extension's description
|
||||
*/
|
||||
|
@ -67,7 +75,7 @@ public interface ExtensionDescription {
|
|||
String version();
|
||||
|
||||
/**
|
||||
* Gets the extension's authors
|
||||
* Gets the extension's authors.
|
||||
*
|
||||
* @return the extension's authors
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue