♻️ Reformat + Update .editorconfig
This commit is contained in:
parent
8bdec87a74
commit
2aac3980d5
169 changed files with 4261 additions and 2448 deletions
|
|
@ -50,82 +50,88 @@ final class CloudburstCommand<C> extends PluginCommand<Plugin> {
|
|||
private final CloudburstCommandManager<C> manager;
|
||||
private final Command<C> cloudCommand;
|
||||
|
||||
CloudburstCommand(final @NonNull String label,
|
||||
final @NonNull List<@NonNull String> aliases,
|
||||
final @NonNull Command<C> cloudCommand,
|
||||
final @NonNull CommandArgument<C, ?> command,
|
||||
final @NonNull CloudburstCommandManager<C> manager) {
|
||||
CloudburstCommand(
|
||||
final @NonNull String label,
|
||||
final @NonNull List<@NonNull String> aliases,
|
||||
final @NonNull Command<C> cloudCommand,
|
||||
final @NonNull CommandArgument<C, ?> command,
|
||||
final @NonNull CloudburstCommandManager<C> manager
|
||||
) {
|
||||
super(manager.getOwningPlugin(), CommandData.builder(label)
|
||||
.addAliases(aliases.toArray(new String[0]))
|
||||
.addPermission(cloudCommand.getCommandPermission().toString())
|
||||
.setDescription(cloudCommand.getCommandMeta().getOrDefault("description", ""))
|
||||
.build());
|
||||
.addAliases(aliases.toArray(new String[0]))
|
||||
.addPermission(cloudCommand.getCommandPermission().toString())
|
||||
.setDescription(cloudCommand.getCommandMeta().getOrDefault("description", ""))
|
||||
.build());
|
||||
this.command = command;
|
||||
this.manager = manager;
|
||||
this.cloudCommand = cloudCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final CommandSender commandSender,
|
||||
final String commandLabel,
|
||||
final String[] strings) {
|
||||
public boolean execute(
|
||||
final CommandSender commandSender,
|
||||
final String commandLabel,
|
||||
final String[] strings
|
||||
) {
|
||||
/* Join input */
|
||||
final StringBuilder builder = new StringBuilder(this.command.getName());
|
||||
for (final String string : strings) {
|
||||
builder.append(" ").append(string);
|
||||
}
|
||||
final C sender = this.manager.getCommandSenderMapper().apply(commandSender);
|
||||
this.manager.executeCommand(sender,
|
||||
builder.toString())
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof CompletionException) {
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
final Throwable finalThrowable = throwable;
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidSyntaxException.class,
|
||||
(InvalidSyntaxException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
"Invalid Command Syntax. "
|
||||
+ "Correct command syntax is: "
|
||||
+ "/"
|
||||
+ ((InvalidSyntaxException) finalThrowable)
|
||||
.getCorrectSyntax())
|
||||
);
|
||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidCommandSenderException.class,
|
||||
(InvalidCommandSenderException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(finalThrowable.getMessage())
|
||||
);
|
||||
} else if (throwable instanceof NoPermissionException) {
|
||||
this.manager.handleException(sender,
|
||||
NoPermissionException.class,
|
||||
(NoPermissionException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_NO_PERMS)
|
||||
);
|
||||
} else if (throwable instanceof NoSuchCommandException) {
|
||||
this.manager.handleException(sender,
|
||||
NoSuchCommandException.class,
|
||||
(NoSuchCommandException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND)
|
||||
);
|
||||
} else if (throwable instanceof ArgumentParseException) {
|
||||
this.manager.handleException(sender,
|
||||
ArgumentParseException.class,
|
||||
(ArgumentParseException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
"Invalid Command Argument: "
|
||||
+ finalThrowable.getCause().getMessage())
|
||||
);
|
||||
} else {
|
||||
commandSender.sendMessage(throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
this.manager.executeCommand(
|
||||
sender,
|
||||
builder.toString()
|
||||
)
|
||||
.whenComplete(((commandResult, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof CompletionException) {
|
||||
throwable = throwable.getCause();
|
||||
}
|
||||
}));
|
||||
final Throwable finalThrowable = throwable;
|
||||
if (throwable instanceof InvalidSyntaxException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidSyntaxException.class,
|
||||
(InvalidSyntaxException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
"Invalid Command Syntax. "
|
||||
+ "Correct command syntax is: "
|
||||
+ "/"
|
||||
+ ((InvalidSyntaxException) finalThrowable)
|
||||
.getCorrectSyntax())
|
||||
);
|
||||
} else if (throwable instanceof InvalidCommandSenderException) {
|
||||
this.manager.handleException(sender,
|
||||
InvalidCommandSenderException.class,
|
||||
(InvalidCommandSenderException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(finalThrowable.getMessage())
|
||||
);
|
||||
} else if (throwable instanceof NoPermissionException) {
|
||||
this.manager.handleException(sender,
|
||||
NoPermissionException.class,
|
||||
(NoPermissionException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_NO_PERMS)
|
||||
);
|
||||
} else if (throwable instanceof NoSuchCommandException) {
|
||||
this.manager.handleException(sender,
|
||||
NoSuchCommandException.class,
|
||||
(NoSuchCommandException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(MESSAGE_UNKNOWN_COMMAND)
|
||||
);
|
||||
} else if (throwable instanceof ArgumentParseException) {
|
||||
this.manager.handleException(sender,
|
||||
ArgumentParseException.class,
|
||||
(ArgumentParseException) throwable, (c, e) ->
|
||||
commandSender.sendMessage(
|
||||
"Invalid Command Argument: "
|
||||
+ finalThrowable.getCause().getMessage())
|
||||
);
|
||||
} else {
|
||||
commandSender.sendMessage(throwable.getMessage());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,11 +54,13 @@ public class CloudburstCommandManager<C> extends CommandManager<C> {
|
|||
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
||||
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||
*/
|
||||
public CloudburstCommandManager(final @NonNull Plugin owningPlugin,
|
||||
final @NonNull Function<@NonNull CommandTree<C>,
|
||||
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
|
||||
final @NonNull Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper) {
|
||||
public CloudburstCommandManager(
|
||||
final @NonNull Plugin owningPlugin,
|
||||
final @NonNull Function<@NonNull CommandTree<C>,
|
||||
@NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||
final @NonNull Function<@NonNull CommandSender, @NonNull C> commandSenderMapper,
|
||||
final @NonNull Function<@NonNull C, @NonNull CommandSender> backwardsCommandSenderMapper
|
||||
) {
|
||||
super(commandExecutionCoordinator, new CloudburstPluginRegistrationHandler<>());
|
||||
((CloudburstPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||
this.commandSenderMapper = commandSenderMapper;
|
||||
|
|
@ -67,8 +69,10 @@ public class CloudburstCommandManager<C> extends CommandManager<C> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasPermission(final @NonNull C sender,
|
||||
final @NonNull String permission) {
|
||||
public final boolean hasPermission(
|
||||
final @NonNull C sender,
|
||||
final @NonNull String permission
|
||||
) {
|
||||
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue