@ -26,13 +26,11 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestion ;
import com.mojang.brigadier.suggestion.Suggestion ;
import net.kyori.adventure.text.Component ;
import net.kyori.adventure.text.Component ;
import net.kyori.adventure.text.format.NamedTextColor ;
import net.kyori.adventure.text.format.NamedTextColor ;
import net.william278.uniform.BaseCommand ;
import net.william278.uniform.* ;
import net.william278.uniform.Command ;
import net.william278.uniform.CommandUser ;
import net.william278.uniform.Uniform ;
import org.bukkit.command.CommandException ;
import org.bukkit.command.CommandException ;
import org.bukkit.command.CommandSender ;
import org.bukkit.command.CommandSender ;
import org.jetbrains.annotations.NotNull ;
import org.jetbrains.annotations.NotNull ;
import org.jetbrains.annotations.Nullable ;
import java.util.List ;
import java.util.List ;
import java.util.function.Function ;
import java.util.function.Function ;
@ -40,12 +38,15 @@ import java.util.function.Function;
@SuppressWarnings ( "unused" )
@SuppressWarnings ( "unused" )
public class LegacyPaperCommand extends BaseCommand < CommandSender > {
public class LegacyPaperCommand extends BaseCommand < CommandSender > {
private @Nullable Permission permission ;
static final Function < Object , CommandUser > USER_SUPPLIER = ( user ) - > new LegacyPaperCommandUser (
static final Function < Object , CommandUser > USER_SUPPLIER = ( user ) - > new LegacyPaperCommandUser (
( CommandSender ) user
( CommandSender ) user
) ;
) ;
public LegacyPaperCommand ( @NotNull Command command ) {
public LegacyPaperCommand ( @NotNull Command command ) {
super ( command ) ;
super ( command ) ;
this . permission = command . getPermission ( ) . orElse ( null ) ;
}
}
public LegacyPaperCommand ( @NotNull String name , @NotNull String description , @NotNull List < String > aliases ) {
public LegacyPaperCommand ( @NotNull String name , @NotNull String description , @NotNull List < String > aliases ) {
@ -61,17 +62,30 @@ public class LegacyPaperCommand extends BaseCommand<CommandSender> {
return new Impl ( uniform , this ) ;
return new Impl ( uniform , this ) ;
}
}
@Override
public void setPermission ( @NotNull Permission permission ) {
this . permission = permission ;
super . setPermission ( permission ) ;
}
static final class Impl extends org . bukkit . command . Command {
static final class Impl extends org . bukkit . command . Command {
private static final int COMMAND_SUCCESS = com . mojang . brigadier . Command . SINGLE_SUCCESS ;
private static final int COMMAND_SUCCESS = com . mojang . brigadier . Command . SINGLE_SUCCESS ;
private final CommandDispatcher < CommandSender > dispatcher = new CommandDispatcher < > ( ) ;
private final CommandDispatcher < CommandSender > dispatcher = new CommandDispatcher < > ( ) ;
private final @Nullable Permission permission ;
public Impl ( @NotNull Uniform uniform , @NotNull LegacyPaperCommand command ) {
public Impl ( @NotNull Uniform uniform , @NotNull LegacyPaperCommand command ) {
super ( command . getName ( ) ) ;
super ( command . getName ( ) ) ;
this . dispatcher . register ( command . createBuilder ( ) ) ;
this . dispatcher . register ( command . createBuilder ( ) ) ;
this . permission = command . permission ;
// Setup command properties
this . setDescription ( command . getDescription ( ) ) ;
this . setDescription ( command . getDescription ( ) ) ;
this . setAliases ( command . getAliases ( ) ) ;
this . setAliases ( command . getAliases ( ) ) ;
if ( permission ! = null ) {
this . setPermission ( permission . node ( ) ) ;
}
}
}
@SuppressWarnings ( "deprecation" )
@SuppressWarnings ( "deprecation" )
@ -107,6 +121,14 @@ public class LegacyPaperCommand extends BaseCommand<CommandSender> {
. join ( ) ;
. join ( ) ;
}
}
@Override
public boolean testPermissionSilent ( @NotNull CommandSender target ) {
if ( permission = = null | | permission . node ( ) . isBlank ( ) ) {
return true ;
}
return new LegacyPaperCommandUser ( target ) . checkPermission ( permission ) ;
}
@NotNull
@NotNull
private String getInput ( @NotNull String [ ] args ) {
private String getInput ( @NotNull String [ ] args ) {
return args . length = = 0 ? getName ( ) : "%s %s" . formatted ( getName ( ) , String . join ( " " , args ) ) ;
return args . length = = 0 ? getName ( ) : "%s %s" . formatted ( getName ( ) , String . join ( " " , args ) ) ;