diff --git a/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitUniform.java b/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitUniform.java index 4bd5eee..693c0ea 100644 --- a/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitUniform.java +++ b/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitUniform.java @@ -22,9 +22,9 @@ package net.william278.uniform.bukkit; import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.william278.uniform.BaseCommand; import net.william278.uniform.Command; import net.william278.uniform.Uniform; -import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import space.arim.morepaperlib.MorePaperLib; @@ -39,7 +39,7 @@ import java.util.Locale; * @since 1.0 */ @SuppressWarnings("unused") -public final class BukkitUniform implements Uniform { +public final class BukkitUniform implements Uniform { private static BukkitUniform INSTANCE; private static BukkitAudiences AUDIENCES; @@ -69,16 +69,19 @@ public final class BukkitUniform implements Uniform The command source type + * @param The command type * @since 1.0 */ + @SafeVarargs @Override - public void register(@NotNull BukkitCommand... commands) { + public final > void register(T... commands) { registrar.getServerCommandMap().registerAll( PLUGIN.getName().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_]", ""), - Arrays.stream(commands).map(c -> (org.bukkit.command.Command) c.getImpl()).toList() + Arrays.stream(commands).map(c -> (org.bukkit.command.Command) ((BukkitCommand) c).getImpl()).toList() ); } diff --git a/common/src/main/java/net/william278/uniform/Uniform.java b/common/src/main/java/net/william278/uniform/Uniform.java index 32d5007..d0883ba 100644 --- a/common/src/main/java/net/william278/uniform/Uniform.java +++ b/common/src/main/java/net/william278/uniform/Uniform.java @@ -21,11 +21,11 @@ package net.william278.uniform; -public interface Uniform> { +public interface Uniform { void register(Command... commands); @SuppressWarnings("unchecked") - void register(T... commands); + > void register(T... commands); } 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 266d9c1..c5ef156 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 @@ -21,16 +21,14 @@ package net.william278.uniform.fabric; - import com.google.common.collect.Sets; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.minecraft.server.command.ServerCommandSource; +import net.william278.uniform.BaseCommand; import net.william278.uniform.Command; import net.william278.uniform.Uniform; import org.jetbrains.annotations.NotNull; import java.util.Arrays; -import java.util.Collections; import java.util.Set; /** @@ -38,7 +36,8 @@ import java.util.Set; * * @since 1.0 */ -public final class FabricUniform implements Uniform { +@SuppressWarnings("unused") +public final class FabricUniform implements Uniform { private static FabricUniform INSTANCE; @@ -62,24 +61,27 @@ public final class FabricUniform implements Uniform The command source type + * @param The command type * @since 1.0 */ + @SafeVarargs @Override - public void register(@NotNull FabricCommand... commands) { - Collections.addAll(this.commands, commands); + public final > void register(T... commands) { + Arrays.stream(commands).map(c -> (FabricCommand) c).forEach(this.commands::add); } /** - * Register a command to be added to the server's command manager + * Register a command with the server's command manager * * @param commands The commands to register * @since 1.0 */ @Override - public void register(@NotNull Command... commands) { + public void register(Command... commands) { register(Arrays.stream(commands).map(FabricCommand::new).toArray(FabricCommand[]::new)); } 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 7c19a94..4f4c9a3 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 @@ -21,16 +21,14 @@ package net.william278.uniform.fabric; - import com.google.common.collect.Sets; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.minecraft.server.command.ServerCommandSource; +import net.william278.uniform.BaseCommand; import net.william278.uniform.Command; import net.william278.uniform.Uniform; import org.jetbrains.annotations.NotNull; import java.util.Arrays; -import java.util.Collections; import java.util.Set; /** @@ -38,7 +36,8 @@ import java.util.Set; * * @since 1.0 */ -public final class FabricUniform implements Uniform { +@SuppressWarnings("unused") +public final class FabricUniform implements Uniform { private static FabricUniform INSTANCE; @@ -46,7 +45,7 @@ public final class FabricUniform implements Uniform - commands.forEach(command -> dispatcher.register(command.createBuilder())) + commands.forEach(command -> dispatcher.register(command.createBuilder())) ); } @@ -62,24 +61,27 @@ public final class FabricUniform implements Uniform The command source type + * @param The command type * @since 1.0 */ + @SafeVarargs @Override - public void register(@NotNull FabricCommand... commands) { - Collections.addAll(this.commands, commands); + public final > void register(T... commands) { + Arrays.stream(commands).map(c -> (FabricCommand) c).forEach(this.commands::add); } /** - * Register a command to be added to the server's command manager + * Register a command with the server's command manager * * @param commands The commands to register * @since 1.0 */ @Override - public void register(@NotNull Command... commands) { + public void register(Command... commands) { register(Arrays.stream(commands).map(FabricCommand::new).toArray(FabricCommand[]::new)); } diff --git a/paper/src/main/java/net/william278/uniform/paper/PaperUniform.java b/paper/src/main/java/net/william278/uniform/paper/PaperUniform.java index 1a712de..8924ea3 100644 --- a/paper/src/main/java/net/william278/uniform/paper/PaperUniform.java +++ b/paper/src/main/java/net/william278/uniform/paper/PaperUniform.java @@ -22,12 +22,13 @@ package net.william278.uniform.paper; import com.google.common.collect.Sets; +import net.william278.uniform.BaseCommand; import net.william278.uniform.Command; +import net.william278.uniform.Uniform; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; import java.util.Arrays; -import java.util.Collections; import java.util.Set; /** @@ -35,7 +36,7 @@ import java.util.Set; * * @since 1.0 */ -public final class PaperUniform { +public final class PaperUniform implements Uniform { private static PaperUniform INSTANCE; @@ -73,24 +74,26 @@ public final class PaperUniform { return INSTANCE != null ? INSTANCE : (INSTANCE = new PaperUniform(plugin)); } - /** - * Register a command to be added to the server's command manager - * - * @param commands The commands to register - * @since 1.0 - */ - public void register(PaperCommand... commands) { - Collections.addAll(this.commands, commands); - } /** - * Register a command to be added to the server's command manager + * Register a command with the server's command manager * * @param commands The commands to register + * @param The command source type + * @param The command type * @since 1.0 */ - public void register(LegacyPaperCommand... commands) { - Collections.addAll(this.legacyCommands, commands); + @SafeVarargs + @Override + public final > void register(T... commands) { + Arrays.stream(commands).forEach(c -> { + if (c instanceof PaperCommand paper) { + this.commands.add(paper); + } else if (c instanceof LegacyPaperCommand legacy) { + this.legacyCommands.add(legacy); + } + throw new IllegalArgumentException("Command type not supported"); + }); } /** diff --git a/velocity/src/main/java/net/william278/uniform/velocity/VelocityUniform.java b/velocity/src/main/java/net/william278/uniform/velocity/VelocityUniform.java index fc9b83b..41bb503 100644 --- a/velocity/src/main/java/net/william278/uniform/velocity/VelocityUniform.java +++ b/velocity/src/main/java/net/william278/uniform/velocity/VelocityUniform.java @@ -22,8 +22,8 @@ package net.william278.uniform.velocity; import com.velocitypowered.api.command.BrigadierCommand; -import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.ProxyServer; +import net.william278.uniform.BaseCommand; import net.william278.uniform.Command; import net.william278.uniform.Uniform; import org.jetbrains.annotations.NotNull; @@ -36,7 +36,7 @@ import java.util.Arrays; * @since 1.0 */ @SuppressWarnings("unused") -public final class VelocityUniform implements Uniform { +public final class VelocityUniform implements Uniform { private static VelocityUniform INSTANCE; @@ -62,11 +62,15 @@ public final class VelocityUniform implements Uniform The command source type + * @param The command type * @since 1.0 */ + @SafeVarargs @Override - public void register(@NotNull VelocityCommand... commands) { - Arrays.stream(commands).forEach(cmd -> server.getCommandManager().register(new BrigadierCommand(cmd.build()))); + public final > void register(T... commands) { + Arrays.stream(commands).map(c -> (VelocityCommand) c).forEach(c -> server.getCommandManager() + .register(c.getName(), new BrigadierCommand(c.build()))); } /** @@ -76,7 +80,7 @@ public final class VelocityUniform implements Uniform