diff --git a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricClientCommandManager.java b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricClientCommandManager.java index c0f49d1a..2bb5555e 100644 --- a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricClientCommandManager.java +++ b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricClientCommandManager.java @@ -106,4 +106,9 @@ public FabricClientCommandManager( public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) { return true; } + + @Override + public boolean isClientCommandManager() { + return true; + } } diff --git a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricCommandManager.java b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricCommandManager.java index 08007a3e..dd526807 100644 --- a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricCommandManager.java +++ b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricCommandManager.java @@ -26,13 +26,12 @@ import net.minecraft.commands.SharedSuggestionProvider; import org.apiguardian.api.API; import org.checkerframework.checker.nullness.qual.NonNull; -import org.incendo.cloud.CommandManager; +import org.checkerframework.framework.qual.DefaultQualifier; import org.incendo.cloud.SenderMapper; -import org.incendo.cloud.SenderMapperHolder; -import org.incendo.cloud.brigadier.BrigadierManagerHolder; import org.incendo.cloud.brigadier.CloudBrigadierManager; import org.incendo.cloud.brigadier.suggestion.TooltipSuggestion; import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.minecraft.modded.ModdedCommandManager; import org.incendo.cloud.minecraft.modded.caption.ModdedDefaultCaptionsProvider; import org.incendo.cloud.minecraft.modded.internal.ModdedParserMappings; import org.incendo.cloud.minecraft.modded.internal.ModdedPreprocessor; @@ -52,8 +51,8 @@ * @see FabricServerCommandManager for server commands * @since 1.5.0 */ -public abstract class FabricCommandManager extends CommandManager implements - BrigadierManagerHolder, SenderMapperHolder { +@DefaultQualifier(NonNull.class) +public abstract class FabricCommandManager extends ModdedCommandManager { private final SenderMapper senderMapper; private final CloudBrigadierManager brigadierManager; @@ -78,9 +77,9 @@ public abstract class FabricCommandManager commandExecutionCoordinator, - final @NonNull SenderMapper senderMapper, - final @NonNull FabricCommandRegistrationHandler registrationHandler + final ExecutionCoordinator commandExecutionCoordinator, + final SenderMapper senderMapper, + final FabricCommandRegistrationHandler registrationHandler ) { super(commandExecutionCoordinator, registrationHandler); this.senderMapper = senderMapper; @@ -100,29 +99,15 @@ public abstract class FabricCommandManager senderMapper() { + public final SenderMapper senderMapper() { return this.senderMapper; } @Override - public final @NonNull SuggestionFactory suggestionFactory() { + public final SuggestionFactory suggestionFactory() { return this.suggestionFactory; } - /** - * {@inheritDoc} - * - *

This will always return true for {@link FabricCommandManager}s.

- * - * @return {@code true} - * @since 2.0.0 - */ - @API(status = API.Status.STABLE, since = "2.0.0") - @Override - public final boolean hasBrigadierManager() { - return true; - } - /** * {@inheritDoc} * @@ -132,7 +117,7 @@ public final boolean hasBrigadierManager() { */ @API(status = API.Status.STABLE, since = "2.0.0") @Override - public final @NonNull CloudBrigadierManager brigadierManager() { + public final CloudBrigadierManager brigadierManager() { return this.brigadierManager; } diff --git a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java index 06b077af..e28aa134 100644 --- a/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java +++ b/cloud-fabric/src/main/java/org/incendo/cloud/fabric/FabricServerCommandManager.java @@ -121,4 +121,9 @@ public boolean hasPermission(final @NonNull C sender, final @NonNull String perm } return source.hasPermission(source.getServer().getOperatorUserPermissionLevel()); } + + @Override + public boolean isClientCommandManager() { + return false; + } } diff --git a/cloud-minecraft-modded-common/src/main/java/org/incendo/cloud/minecraft/modded/ModdedCommandManager.java b/cloud-minecraft-modded-common/src/main/java/org/incendo/cloud/minecraft/modded/ModdedCommandManager.java new file mode 100644 index 00000000..7fac207d --- /dev/null +++ b/cloud-minecraft-modded-common/src/main/java/org/incendo/cloud/minecraft/modded/ModdedCommandManager.java @@ -0,0 +1,72 @@ +// +// MIT License +// +// Copyright (c) 2024 Incendo +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +package org.incendo.cloud.minecraft.modded; + +import net.minecraft.commands.SharedSuggestionProvider; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.SenderMapperHolder; +import org.incendo.cloud.brigadier.BrigadierManagerHolder; +import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.internal.CommandRegistrationHandler; + +@DefaultQualifier(NonNull.class) +public abstract class ModdedCommandManager extends CommandManager implements + BrigadierManagerHolder, SenderMapperHolder { + + /** + * Create a new command manager instance. + * + * @param executionCoordinator Execution coordinator instance. When choosing the appropriate coordinator for your + * project, be sure to consider any limitations noted by the platform documentation. + * @param commandRegistrationHandler Command registration handler. This will get called every time a new command is + * registered to the command manager. This may be used to forward command registration + * to the platform. + */ + protected ModdedCommandManager(final ExecutionCoordinator executionCoordinator, final CommandRegistrationHandler commandRegistrationHandler) { + super(executionCoordinator, commandRegistrationHandler); + } + + /** + * {@inheritDoc} + * + *

This will always return true for {@link ModdedCommandManager}s.

+ * + * @return {@code true} + * @since 2.0.0 + */ + @Override + public final boolean hasBrigadierManager() { + return true; + } + + /** + * Returns whether this is a client command manager. + * + * @return whether this is a client command manager + * @since 2.0.0 + */ + public abstract boolean isClientCommandManager(); +} diff --git a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeClientCommandManager.java b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeClientCommandManager.java index be36ebea..a1d5c0de 100644 --- a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeClientCommandManager.java +++ b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeClientCommandManager.java @@ -87,4 +87,9 @@ private void registerParsers() { public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) { return true; } + + @Override + public boolean isClientCommandManager() { + return true; + } } diff --git a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java index f2251f91..82cbc124 100644 --- a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java +++ b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeCommandManager.java @@ -29,15 +29,13 @@ import net.minecraft.commands.CommandSourceStack; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.framework.qual.DefaultQualifier; -import org.incendo.cloud.CommandManager; import org.incendo.cloud.SenderMapper; -import org.incendo.cloud.SenderMapperHolder; -import org.incendo.cloud.brigadier.BrigadierManagerHolder; import org.incendo.cloud.brigadier.CloudBrigadierManager; import org.incendo.cloud.brigadier.suggestion.TooltipSuggestion; import org.incendo.cloud.execution.ExecutionCoordinator; import org.incendo.cloud.meta.CommandMeta; import org.incendo.cloud.meta.SimpleCommandMeta; +import org.incendo.cloud.minecraft.modded.ModdedCommandManager; import org.incendo.cloud.minecraft.modded.caption.MinecraftCaptionFormatter; import org.incendo.cloud.minecraft.modded.caption.ModdedDefaultCaptionsProvider; import org.incendo.cloud.minecraft.modded.internal.ModdedExceptionHandler; @@ -46,8 +44,7 @@ import org.incendo.cloud.suggestion.SuggestionFactory; @DefaultQualifier(NonNull.class) -public abstract class NeoForgeCommandManager extends CommandManager - implements BrigadierManagerHolder, SenderMapperHolder { +public abstract class NeoForgeCommandManager extends ModdedCommandManager { static final Set> INSTANCES = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>())); @@ -89,11 +86,6 @@ public final CloudBrigadierManager brigadierManager() { return this.brigadierManager; } - @Override - public final boolean hasBrigadierManager() { - return true; - } - @Override public final @NonNull SuggestionFactory suggestionFactory() { return this.suggestionFactory; diff --git a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeServerCommandManager.java b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeServerCommandManager.java index 884fbd05..34089d30 100644 --- a/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeServerCommandManager.java +++ b/cloud-neoforge/src/main/java/org/incendo/cloud/neoforge/NeoForgeServerCommandManager.java @@ -113,4 +113,9 @@ public boolean hasPermission(final @NonNull C sender, final @NonNull String perm } return source.hasPermission(source.getServer().getOperatorUserPermissionLevel()); } + + @Override + public boolean isClientCommandManager() { + return false; + } }