refactor: ensure all modules implement Uniform

dependabot/gradle/org.projectlombok-lombok-1.18.34
William 5 months ago
parent 665389482c
commit 823fcf9874
No known key found for this signature in database

@ -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<CommandSender, BukkitCommand> {
public final class BukkitUniform implements Uniform {
private static BukkitUniform INSTANCE;
private static BukkitAudiences AUDIENCES;
@ -69,16 +69,19 @@ public final class BukkitUniform implements Uniform<CommandSender, BukkitCommand
}
/**
* Register a command to be added to the server's command map
* Register a command with the server's command manager
*
* @param commands The commands to register
* @param <S> The command source type
* @param <T> The command type
* @since 1.0
*/
@SafeVarargs
@Override
public void register(@NotNull BukkitCommand... commands) {
public final <S, T extends BaseCommand<S>> 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()
);
}

@ -21,11 +21,11 @@
package net.william278.uniform;
public interface Uniform<S, T extends BaseCommand<S>> {
public interface Uniform {
void register(Command... commands);
@SuppressWarnings("unchecked")
void register(T... commands);
<S, T extends BaseCommand<S>> void register(T... commands);
}

@ -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<ServerCommandSource, FabricCommand> {
@SuppressWarnings("unused")
public final class FabricUniform implements Uniform {
private static FabricUniform INSTANCE;
@ -62,24 +61,27 @@ public final class FabricUniform implements Uniform<ServerCommandSource, FabricC
}
/**
* 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 <S> The command source type
* @param <T> The command type
* @since 1.0
*/
@SafeVarargs
@Override
public void register(@NotNull FabricCommand... commands) {
Collections.addAll(this.commands, commands);
public final <S, T extends BaseCommand<S>> 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));
}

@ -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<ServerCommandSource, FabricCommand> {
@SuppressWarnings("unused")
public final class FabricUniform implements Uniform {
private static FabricUniform INSTANCE;
@ -46,7 +45,7 @@ public final class FabricUniform implements Uniform<ServerCommandSource, FabricC
private FabricUniform() {
CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) ->
commands.forEach(command -> dispatcher.register(command.createBuilder()))
commands.forEach(command -> dispatcher.register(command.createBuilder()))
);
}
@ -62,24 +61,27 @@ public final class FabricUniform implements Uniform<ServerCommandSource, FabricC
}
/**
* 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 <S> The command source type
* @param <T> The command type
* @since 1.0
*/
@SafeVarargs
@Override
public void register(@NotNull FabricCommand... commands) {
Collections.addAll(this.commands, commands);
public final <S, T extends BaseCommand<S>> 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));
}

@ -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 <S> The command source type
* @param <T> The command type
* @since 1.0
*/
public void register(LegacyPaperCommand... commands) {
Collections.addAll(this.legacyCommands, commands);
@SafeVarargs
@Override
public final <S, T extends BaseCommand<S>> 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");
});
}
/**

@ -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<CommandSource, VelocityCommand> {
public final class VelocityUniform implements Uniform {
private static VelocityUniform INSTANCE;
@ -62,11 +62,15 @@ public final class VelocityUniform implements Uniform<CommandSource, VelocityCom
* Register a command with the server's command manager
*
* @param commands The commands to register
* @param <S> The command source type
* @param <T> 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 <S, T extends BaseCommand<S>> 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<CommandSource, VelocityCom
* @since 1.0
*/
@Override
public void register(@NotNull Command... commands) {
public void register(Command... commands) {
register(Arrays.stream(commands).map(VelocityCommand::new).toArray(VelocityCommand[]::new));
}

Loading…
Cancel
Save