Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ModdedCommandManager shared parent for modded managers #66

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,8 +51,8 @@
* @see FabricServerCommandManager for server commands
* @since 1.5.0
*/
public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider> extends CommandManager<C> implements
BrigadierManagerHolder<C, S>, SenderMapperHolder<S, C> {
@DefaultQualifier(NonNull.class)
public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider> extends ModdedCommandManager<C, S> {

private final SenderMapper<S, C> senderMapper;
private final CloudBrigadierManager<C, S> brigadierManager;
Expand All @@ -78,9 +77,9 @@ public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider
@API(status = API.Status.STABLE, since = "2.0.0")
@SuppressWarnings("unchecked")
FabricCommandManager(
final @NonNull ExecutionCoordinator<C> commandExecutionCoordinator,
final @NonNull SenderMapper<S, C> senderMapper,
final @NonNull FabricCommandRegistrationHandler<C, S> registrationHandler
final ExecutionCoordinator<C> commandExecutionCoordinator,
final SenderMapper<S, C> senderMapper,
final FabricCommandRegistrationHandler<C, S> registrationHandler
) {
super(commandExecutionCoordinator, registrationHandler);
this.senderMapper = senderMapper;
Expand All @@ -100,29 +99,15 @@ public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider
}

@Override
public final @NonNull SenderMapper<S, C> senderMapper() {
public final SenderMapper<S, C> senderMapper() {
return this.senderMapper;
}

@Override
public final @NonNull SuggestionFactory<C, ? extends TooltipSuggestion> suggestionFactory() {
public final SuggestionFactory<C, ? extends TooltipSuggestion> suggestionFactory() {
return this.suggestionFactory;
}

/**
* {@inheritDoc}
*
* <p>This will always return true for {@link FabricCommandManager}s.</p>
*
* @return {@code true}
* @since 2.0.0
*/
@API(status = API.Status.STABLE, since = "2.0.0")
@Override
public final boolean hasBrigadierManager() {
return true;
}

/**
* {@inheritDoc}
*
Expand All @@ -132,7 +117,7 @@ public final boolean hasBrigadierManager() {
*/
@API(status = API.Status.STABLE, since = "2.0.0")
@Override
public final @NonNull CloudBrigadierManager<C, S> brigadierManager() {
public final CloudBrigadierManager<C, S> brigadierManager() {
return this.brigadierManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<C, S extends SharedSuggestionProvider> extends CommandManager<C> implements
BrigadierManagerHolder<C, S>, SenderMapperHolder<S, C> {

/**
* 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<C> executionCoordinator, final CommandRegistrationHandler<C> commandRegistrationHandler) {
super(executionCoordinator, commandRegistrationHandler);
}

/**
* {@inheritDoc}
*
* <p>This will always return true for {@link ModdedCommandManager}s.</p>
*
* @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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,8 +44,7 @@
import org.incendo.cloud.suggestion.SuggestionFactory;

@DefaultQualifier(NonNull.class)
public abstract class NeoForgeCommandManager<C> extends CommandManager<C>
implements BrigadierManagerHolder<C, CommandSourceStack>, SenderMapperHolder<CommandSourceStack, C> {
public abstract class NeoForgeCommandManager<C> extends ModdedCommandManager<C, CommandSourceStack> {

static final Set<NeoForgeCommandManager<?>> INSTANCES = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));

Expand Down Expand Up @@ -89,11 +86,6 @@ public final CloudBrigadierManager<C, CommandSourceStack> brigadierManager() {
return this.brigadierManager;
}

@Override
public final boolean hasBrigadierManager() {
return true;
}

@Override
public final @NonNull SuggestionFactory<C, ? extends TooltipSuggestion> suggestionFactory() {
return this.suggestionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading