Skip to content

Commit

Permalink
Complete rename
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Nov 17, 2023
1 parent fc3d685 commit 3cd3989
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 66 deletions.
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
group=cloud.commandframework
version=1.0.0+1.20.2-SNAPSHOT
description=Cloud Command Framework on NeoForge

loom.platform=neoforge
org.gradle.jvmargs=-Xmx2G
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import cloud.commandframework.Command;
import cloud.commandframework.CommandTree;
Expand Down Expand Up @@ -51,12 +51,12 @@
import org.checkerframework.checker.nullness.qual.Nullable;

@Mod("cloud")
public final class CloudForgeEntrypoint {
public final class CloudNeoForgeEntrypoint {
private static boolean serverStartingCalled;

public CloudForgeEntrypoint() {
public CloudNeoForgeEntrypoint() {
NeoForge.EVENT_BUS.addListener(EventPriority.HIGHEST, (ServerStartingEvent event) -> serverStartingCalled = true);
NeoForge.EVENT_BUS.addListener(EventPriority.LOW, CloudForgeEntrypoint::registerPermissions);
NeoForge.EVENT_BUS.addListener(EventPriority.LOW, CloudNeoForgeEntrypoint::registerPermissions);

if (Boolean.getBoolean("cloud.test_commands")) {
testServerManager();
Expand All @@ -73,14 +73,14 @@ private static void registerPermissions(final PermissionGatherEvent.Nodes event)
"cloud",
"hover-stacktrace",
PermissionTypes.BOOLEAN,
CloudForgeEntrypoint::defaultPermissionHandler
CloudNeoForgeEntrypoint::defaultPermissionHandler
));
for (final ForgeCommandManager<?> manager : ForgeServerCommandManager.INSTANCES) {
for (final NeoForgeCommandManager<?> manager : NeoForgeServerCommandManager.INSTANCES) {
registerPermissionsForManager(event, manager);
}
}

private static void registerPermissionsForManager(final PermissionGatherEvent.Nodes event, final ForgeCommandManager<?> manager) {
private static void registerPermissionsForManager(final PermissionGatherEvent.Nodes event, final NeoForgeCommandManager<?> manager) {
final Set<String> permissions = new HashSet<>();
collectPermissions(permissions, manager.commandTree().getRootNodes());
permissions.stream()
Expand All @@ -91,7 +91,7 @@ private static void registerPermissionsForManager(final PermissionGatherEvent.No
permissionString.substring(0, i),
permissionString.substring(i + 1),
PermissionTypes.BOOLEAN,
CloudForgeEntrypoint::defaultPermissionHandler
CloudNeoForgeEntrypoint::defaultPermissionHandler
);
})
.forEach(event::addNodes);
Expand Down Expand Up @@ -130,7 +130,7 @@ private static Boolean defaultPermissionHandler(final @Nullable ServerPlayer pla
}

private static void testClientManager() {
final ForgeClientCommandManager<CommandSourceStack> manager = ForgeClientCommandManager.createNative(CommandExecutionCoordinator.simpleCoordinator());
final NeoForgeClientCommandManager<CommandSourceStack> manager = NeoForgeClientCommandManager.createNative(CommandExecutionCoordinator.simpleCoordinator());
manager.brigadierManager().setNativeNumberSuggestions(false);
manager.command(manager.commandBuilder("cloud_client")
.literal("forge")
Expand All @@ -139,7 +139,7 @@ private static void testClientManager() {
}

private static void testServerManager() {
final ForgeServerCommandManager<CommandSourceStack> manager = ForgeServerCommandManager.createNative(CommandExecutionCoordinator.simpleCoordinator());
final NeoForgeServerCommandManager<CommandSourceStack> manager = NeoForgeServerCommandManager.createNative(CommandExecutionCoordinator.simpleCoordinator());
manager.brigadierManager().setNativeNumberSuggestions(false);
manager.command(manager.commandBuilder("cloud")
.literal("forge")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import com.mojang.brigadier.arguments.ArgumentType;
import java.util.Collections;
Expand All @@ -37,7 +37,7 @@
public final class ContextualArgumentTypeProvider<V> implements Supplier<ArgumentType<V>> {

private static final ThreadLocal<ThreadLocalContext> CONTEXT = new ThreadLocal<>();
private static final Map<ForgeCommandManager<?>, Set<ContextualArgumentTypeProvider<?>>> INSTANCES = new WeakHashMap<>();
private static final Map<NeoForgeCommandManager<?>, Set<ContextualArgumentTypeProvider<?>>> INSTANCES = new WeakHashMap<>();

private final Function<CommandBuildContext, ArgumentType<V>> provider;
private volatile ArgumentType<V> provided;
Expand All @@ -51,7 +51,7 @@ public final class ContextualArgumentTypeProvider<V> implements Supplier<Argumen
* @param action an action to perform while the context is exposed
*/
public static void withBuildContext(
final ForgeCommandManager<?> commandManager,
final NeoForgeCommandManager<?> commandManager,
final CommandBuildContext ctx,
final boolean resetExisting,
final Runnable action
Expand All @@ -75,7 +75,7 @@ public static void withBuildContext(
}

private record ThreadLocalContext(
ForgeCommandManager<?> commandManager,
NeoForgeCommandManager<?> commandManager,
CommandBuildContext commandBuildContext
) {
private Set<ContextualArgumentTypeProvider<?>> instances() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import cloud.commandframework.CommandTree;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
Expand All @@ -46,19 +46,19 @@
*
* @param <C> the command sender type
*/
public final class ForgeClientCommandManager<C> extends ForgeCommandManager<C> {
public final class NeoForgeClientCommandManager<C> extends NeoForgeCommandManager<C> {

/**
* Create a command manager using native source types.
*
* @param execCoordinator Execution coordinator instance.
* @return a new command manager
* @see #ForgeClientCommandManager(Function, Function, Function) for a more thorough explanation
* @see #NeoForgeClientCommandManager(Function, Function, Function) for a more thorough explanation
*/
public static ForgeClientCommandManager<CommandSourceStack> createNative(
public static NeoForgeClientCommandManager<CommandSourceStack> createNative(
final Function<CommandTree<CommandSourceStack>, CommandExecutionCoordinator<CommandSourceStack>> execCoordinator
) {
return new ForgeClientCommandManager<>(execCoordinator, Function.identity(), Function.identity());
return new NeoForgeClientCommandManager<>(execCoordinator, Function.identity(), Function.identity());
}

/**
Expand All @@ -75,7 +75,7 @@ public static ForgeClientCommandManager<CommandSourceStack> createNative(
* @param commandSourceMapper Function that maps {@link CommandSourceStack} to the command sender type
* @param backwardsCommandSourceMapper Function that maps the command sender type to {@link CommandSourceStack}
*/
public ForgeClientCommandManager(
public NeoForgeClientCommandManager(
final Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final Function<CommandSourceStack, C> commandSourceMapper,
final Function<C, CommandSourceStack> backwardsCommandSourceMapper
Expand All @@ -84,7 +84,7 @@ public ForgeClientCommandManager(
commandExecutionCoordinator,
commandSourceMapper,
backwardsCommandSourceMapper,
new ForgeCommandRegistrationHandler.Client<>(),
new NeoForgeCommandRegistrationHandler.Client<>(),
() -> new ClientCommandSourceStack(
CommandSource.NULL,
Vec3.ZERO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import cloud.commandframework.keys.CloudKey;
import cloud.commandframework.keys.SimpleCloudKey;
import io.leangen.geantyref.TypeToken;
import net.minecraft.commands.CommandSourceStack;

public final class ForgeCommandContextKeys {
public final class NeoForgeCommandContextKeys {

private ForgeCommandContextKeys() {
private NeoForgeCommandContextKeys() {
}

public static final CloudKey<CommandSourceStack> NATIVE_COMMAND_SOURCE = SimpleCloudKey.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import cloud.commandframework.CommandManager;
import cloud.commandframework.CommandTree;
Expand All @@ -42,19 +42,19 @@
import org.checkerframework.framework.qual.DefaultQualifier;

@DefaultQualifier(NonNull.class)
public abstract class ForgeCommandManager<C>
public abstract class NeoForgeCommandManager<C>
extends CommandManager<C> implements BrigadierManagerHolder<C> {
static final Set<ForgeCommandManager<?>> INSTANCES = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
static final Set<NeoForgeCommandManager<?>> INSTANCES = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));

private final Function<CommandSourceStack, C> commandSourceMapper;
private final Function<C, CommandSourceStack> backwardsCommandSourceMapper;
private final CloudBrigadierManager<C, CommandSourceStack> brigadierManager;

protected ForgeCommandManager(
protected NeoForgeCommandManager(
final Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
final Function<CommandSourceStack, C> commandSourceMapper,
final Function<C, CommandSourceStack> backwardsCommandSourceMapper,
final ForgeCommandRegistrationHandler<C> registrationHandler,
final NeoForgeCommandRegistrationHandler<C> registrationHandler,
final Supplier<CommandSourceStack> dummyCommandSourceProvider
) {
super(commandExecutionCoordinator, registrationHandler);
Expand All @@ -67,7 +67,7 @@ protected ForgeCommandManager(
));
this.brigadierManager.backwardsBrigadierSenderMapper(this.backwardsCommandSourceMapper);
this.brigadierManager.brigadierSenderMapper(this.commandSourceMapper);
this.registerCommandPreProcessor(new ForgeCommandPreprocessor<>(this));
this.registerCommandPreProcessor(new NeoForgeCommandPreprocessor<>(this));
this.commandSuggestionProcessor(new FilteringCommandSuggestionProcessor<>(
FilteringCommandSuggestionProcessor.Filter.<C>startsWith(true).andTrimBeforeLastSpace()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
import cloud.commandframework.execution.preprocessor.CommandPreprocessor;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;

@DefaultQualifier(NonNull.class)
final class ForgeCommandPreprocessor<C> implements CommandPreprocessor<C> {
final class NeoForgeCommandPreprocessor<C> implements CommandPreprocessor<C> {

private final ForgeCommandManager<C> manager;
private final NeoForgeCommandManager<C> manager;

ForgeCommandPreprocessor(final ForgeCommandManager<C> manager) {
NeoForgeCommandPreprocessor(final NeoForgeCommandManager<C> manager) {
this.manager = manager;
}

@Override
public void accept(final CommandPreprocessingContext<C> context) {
context.getCommandContext().store(
ForgeCommandContextKeys.NATIVE_COMMAND_SOURCE,
NeoForgeCommandContextKeys.NATIVE_COMMAND_SOURCE,
this.manager.backwardsCommandSourceMapper().apply(context.getCommandContext().getSender())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import cloud.commandframework.Command;
import cloud.commandframework.arguments.StaticArgument;
Expand All @@ -47,21 +47,21 @@
import org.checkerframework.checker.nullness.qual.NonNull;

/**
* A registration handler for Minecraft Forge.
* A registration handler for NeoForge.
*
* <p>Subtypes exist for client and server commands.</p>
*
* @param <C> command sender type
*/
abstract class ForgeCommandRegistrationHandler<C> implements CommandRegistrationHandler {
abstract class NeoForgeCommandRegistrationHandler<C> implements CommandRegistrationHandler {

private @MonotonicNonNull ForgeCommandManager<C> commandManager;
private @MonotonicNonNull NeoForgeCommandManager<C> commandManager;

void initialize(final ForgeCommandManager<C> manager) {
void initialize(final NeoForgeCommandManager<C> manager) {
this.commandManager = manager;
}

ForgeCommandManager<C> commandManager() {
NeoForgeCommandManager<C> commandManager() {
return this.commandManager;
}

Expand All @@ -79,7 +79,7 @@ protected final void registerCommand(final Command<C> command, final CommandDisp
perm
),
true,
new ForgeExecutor<>(this.commandManager())
new NeoForgeExecutor<>(this.commandManager())
);

rootNode.addChild(baseNode);
Expand Down Expand Up @@ -124,13 +124,13 @@ private static <S> LiteralCommandNode<S> buildRedirect(
return builder.build();
}

static class Client<C> extends ForgeCommandRegistrationHandler<C> {
static class Client<C> extends NeoForgeCommandRegistrationHandler<C> {

private final Set<Command<C>> registeredCommands = ConcurrentHashMap.newKeySet();
private volatile boolean registerEventFired = false;

@Override
void initialize(final ForgeCommandManager<C> manager) {
void initialize(final NeoForgeCommandManager<C> manager) {
super.initialize(manager);
NeoForge.EVENT_BUS.addListener(this::registerCommands);
NeoForge.EVENT_BUS.addListener((ClientPlayerNetworkEvent.LoggingOut event) -> this.registerEventFired = false);
Expand Down Expand Up @@ -174,12 +174,12 @@ public void registerCommands(final RegisterClientCommandsEvent event) {
}
}

static class Server<C> extends ForgeCommandRegistrationHandler<C> {
static class Server<C> extends NeoForgeCommandRegistrationHandler<C> {

private final Set<Command<C>> registeredCommands = ConcurrentHashMap.newKeySet();

@Override
void initialize(final ForgeCommandManager<C> manager) {
void initialize(final NeoForgeCommandManager<C> manager) {
super.initialize(manager);
NeoForge.EVENT_BUS.addListener(this::registerAllCommands);
}
Expand All @@ -200,7 +200,7 @@ private void registerAllCommands(final RegisterCommandsEvent event) {
for (final Command<C> command : this.registeredCommands) {
/* Only register commands in the declared environment */
final Commands.CommandSelection env = command.getCommandMeta().getOrDefault(
ForgeServerCommandManager.META_REGISTRATION_ENVIRONMENT,
NeoForgeServerCommandManager.META_REGISTRATION_ENVIRONMENT,
Commands.CommandSelection.ALL
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package cloud.commandframework.forge;
package cloud.commandframework.neoforge;

import cloud.commandframework.exceptions.ArgumentParseException;
import cloud.commandframework.exceptions.CommandExecutionException;
Expand All @@ -47,7 +47,7 @@
import net.minecraft.network.chat.MutableComponent;
import org.slf4j.Logger;

final class ForgeExecutor<C> implements Command<CommandSourceStack> {
final class NeoForgeExecutor<C> implements Command<CommandSourceStack> {

private static final Logger LOGGER = LogUtils.getLogger();

Expand All @@ -58,18 +58,18 @@ final class ForgeExecutor<C> implements Command<CommandSourceStack> {
+ "Please contact the server administrators if you believe that this is in error.";
private static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command. Type \"/help\" for help.";

private final ForgeCommandManager<C> manager;
private final NeoForgeCommandManager<C> manager;
private final Function<CommandSourceStack, String> getName;
private final BiConsumer<CommandSourceStack, Component> sendError;

ForgeExecutor(
final ForgeCommandManager<C> manager
NeoForgeExecutor(
final NeoForgeCommandManager<C> manager
) {
this(manager, CommandSourceStack::getTextName, CommandSourceStack::sendFailure);
}

ForgeExecutor(
final ForgeCommandManager<C> manager,
NeoForgeExecutor(
final NeoForgeCommandManager<C> manager,
final Function<CommandSourceStack, String> getName,
final BiConsumer<CommandSourceStack, Component> sendError
) {
Expand Down
Loading

0 comments on commit 3cd3989

Please sign in to comment.