diff --git a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java index afdf7a9..17a278e 100644 --- a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java +++ b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java @@ -22,6 +22,7 @@ package net.william278.uniform.fabric; import com.google.common.collect.Sets; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import lombok.Getter; import lombok.Setter; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; @@ -33,6 +34,7 @@ import net.william278.uniform.Uniform; import org.jetbrains.annotations.NotNull; import java.util.Arrays; +import java.util.Locale; import java.util.Set; import java.util.function.Function; @@ -47,14 +49,29 @@ public final class FabricUniform implements Uniform { static FabricUniform INSTANCE; private final Set commands = Sets.newHashSet(); + @Getter + private final String modId; @Getter @Setter Function commandUserSupplier = (user) -> new FabricCommandUser((ServerCommandSource) user); - private FabricUniform() { + private FabricUniform(@NotNull String modId) { + this.modId = modId.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_-]", ""); CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) -> - commands.forEach(command -> dispatcher.register(command.createBuilder())) + commands.forEach(command -> { + final LiteralArgumentBuilder builder = command.createBuilder(); + dispatcher.register(builder); + + final Set aliases = Sets.newHashSet(command.getAliases()); + command.getAliases().forEach(a -> aliases.add(modId + ":" + a)); + aliases.add(modId + ":" + command.getName()); + aliases.forEach(alias -> dispatcher.register( + LiteralArgumentBuilder.literal(alias) + .requires(builder.getRequirement()).executes(builder.getCommand()) + .redirect(builder.build()) + )); + }) ); } @@ -65,8 +82,8 @@ public final class FabricUniform implements Uniform { * @since 1.0 */ @NotNull - public static FabricUniform getInstance() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform()); + public static FabricUniform getInstance(@NotNull String modId) { + return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform(modId)); } /** diff --git a/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java index 17b0961..85abdf7 100644 --- a/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java +++ b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java @@ -22,6 +22,7 @@ package net.william278.uniform.fabric; import com.google.common.collect.Sets; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import lombok.Getter; import lombok.Setter; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; @@ -33,6 +34,7 @@ import net.william278.uniform.Uniform; import org.jetbrains.annotations.NotNull; import java.util.Arrays; +import java.util.Locale; import java.util.Set; import java.util.function.Function; @@ -47,14 +49,29 @@ public final class FabricUniform implements Uniform { static FabricUniform INSTANCE; private final Set commands = Sets.newHashSet(); + @Getter + private final String modId; @Getter @Setter Function commandUserSupplier = (user) -> new FabricCommandUser((ServerCommandSource) user); - private FabricUniform() { + private FabricUniform(@NotNull String modId) { + this.modId = modId.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_-]", ""); CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) -> - commands.forEach(command -> dispatcher.register(command.createBuilder())) + commands.forEach(command -> { + final LiteralArgumentBuilder builder = command.createBuilder(); + dispatcher.register(builder); + + final Set aliases = Sets.newHashSet(command.getAliases()); + command.getAliases().forEach(a -> aliases.add(modId + ":" + a)); + aliases.add(modId + ":" + command.getName()); + aliases.forEach(alias -> dispatcher.register( + LiteralArgumentBuilder.literal(alias) + .requires(builder.getRequirement()).executes(builder.getCommand()) + .redirect(builder.build()) + )); + }) ); } @@ -65,8 +82,8 @@ public final class FabricUniform implements Uniform { * @since 1.0 */ @NotNull - public static FabricUniform getInstance() { - return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform()); + public static FabricUniform getInstance(@NotNull String modId) { + return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform(modId)); } /** diff --git a/gradle.properties b/gradle.properties index ffc383c..cedcc50 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,6 @@ javaVersion=17 org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.daemon=true -library_version=1.1.3 +library_version=1.1.4 library_archive=uniform library_description=Cross-platform wrapper for making Brigadier commands, based on BrigadierWrapper by Tofaa2, itself inspired by emortalmcs command system. \ No newline at end of file