📦 Update minecraft-extras for Adventure 4.0.0

This commit is contained in:
jmp 2020-10-13 23:56:46 -07:00 • committed by Alexander Söderberg
parent 79bb017fd3
commit 6f0940ebd4
No known key found for this signature in database
GPG key ID: FACEA5B0F4C1BF80
4 changed files with 24 additions and 14 deletions

View file

@ -1,4 +1,4 @@
dependencies {
api project(':cloud-core')
api 'net.kyori:adventure-api:4.0.0-SNAPSHOT'
api 'net.kyori:adventure-api:4.0.0'
}

View file

@ -29,6 +29,7 @@ import cloud.commandframework.exceptions.InvalidCommandSenderException;
import cloud.commandframework.exceptions.InvalidSyntaxException;
import cloud.commandframework.exceptions.NoPermissionException;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.checkerframework.checker.nullness.qual.NonNull;
@ -186,6 +187,7 @@ public final class MinecraftExceptionHandler<C> {
manager.registerExceptionHandler(
InvalidSyntaxException.class,
(c, e) -> audienceMapper.apply(c).sendMessage(
Identity.nil(),
this.decorator.apply(this.componentBuilders.get(ExceptionType.INVALID_SYNTAX).apply(e))
)
);
@ -194,6 +196,7 @@ public final class MinecraftExceptionHandler<C> {
manager.registerExceptionHandler(
InvalidCommandSenderException.class,
(c, e) -> audienceMapper.apply(c).sendMessage(
Identity.nil(),
this.decorator.apply(this.componentBuilders.get(ExceptionType.INVALID_SENDER).apply(e))
)
);
@ -202,6 +205,7 @@ public final class MinecraftExceptionHandler<C> {
manager.registerExceptionHandler(
NoPermissionException.class,
(c, e) -> audienceMapper.apply(c).sendMessage(
Identity.nil(),
this.decorator.apply(this.componentBuilders.get(ExceptionType.NO_PERMISSION).apply(e))
)
);
@ -210,6 +214,7 @@ public final class MinecraftExceptionHandler<C> {
manager.registerExceptionHandler(
ArgumentParseException.class,
(c, e) -> audienceMapper.apply(c).sendMessage(
Identity.nil(),
this.decorator.apply(this.componentBuilders.get(ExceptionType.ARGUMENT_PARSING).apply(e))
)
);

View file

@ -27,6 +27,7 @@ import cloud.commandframework.CommandHelpHandler;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.CommandArgument;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.ClickEvent;
@ -268,14 +269,14 @@ public final class MinecraftHelp<C> {
) {
final Audience audience = this.getAudience(sender);
if (helpTopic.isEmpty()) {
audience.sendMessage(this.basicHeader(sender));
audience.sendMessage(Component.text(
audience.sendMessage(Identity.nil(), this.basicHeader(sender));
audience.sendMessage(Identity.nil(), Component.text(
this.messageProvider.apply(sender, MESSAGE_NO_RESULTS_FOR_QUERY) + ": \"",
this.colors.text
)
.append(this.highlight(Component.text("/" + query, this.colors.highlight)))
.append(Component.text("\"", this.colors.text)));
audience.sendMessage(this.footer(sender));
audience.sendMessage(Identity.nil(), this.footer(sender));
return;
}
new Pagination<CommandHelpHandler.VerboseHelpEntry<C>>(
@ -309,7 +310,8 @@ public final class MinecraftHelp<C> {
},
(currentPage, maxPages) -> this.paginatedFooter(sender, currentPage, maxPages, query),
(attemptedPage, maxPages) -> this.pageOutOfRange(sender, attemptedPage, maxPages)
).render(helpTopic.getEntries(), page, this.maxResultsPerPage).forEach(audience::sendMessage);
).render(helpTopic.getEntries(), page, this.maxResultsPerPage).forEach(line ->
audience.sendMessage(Identity.nil(), line));
}
private void printMultiHelpTopic(
@ -344,7 +346,8 @@ public final class MinecraftHelp<C> {
},
(currentPage, maxPages) -> this.paginatedFooter(sender, currentPage, maxPages, query),
(attemptedPage, maxPages) -> this.pageOutOfRange(sender, attemptedPage, maxPages)
).render(helpTopic.getChildSuggestions(), page, this.maxResultsPerPage).forEach(audience::sendMessage);
).render(helpTopic.getChildSuggestions(), page, this.maxResultsPerPage).forEach(line ->
audience.sendMessage(Identity.nil(), line));
}
private void printVerboseHelpTopic(
@ -353,12 +356,12 @@ public final class MinecraftHelp<C> {
final CommandHelpHandler.@NonNull VerboseHelpTopic<C> helpTopic
) {
final Audience audience = this.getAudience(sender);
audience.sendMessage(this.basicHeader(sender));
audience.sendMessage(this.showingResults(sender, query));
audience.sendMessage(Identity.nil(), this.basicHeader(sender));
audience.sendMessage(Identity.nil(), this.showingResults(sender, query));
final String command = this.commandManager.getCommandSyntaxFormatter()
.apply(helpTopic.getCommand().getArguments(), null);
audience.sendMessage(
this.lastBranch()
Identity.nil(), this.lastBranch()
.append(Component.text(
" " + this.messageProvider.apply(sender, MESSAGE_COMMAND) + ": ",
this.colors.primary
@ -370,7 +373,7 @@ public final class MinecraftHelp<C> {
: helpTopic.getDescription();
final boolean hasArguments = helpTopic.getCommand().getArguments().size() > 1;
audience.sendMessage(
Component.text(" ")
Identity.nil(), Component.text(" ")
.append(hasArguments ? this.branch() : this.lastBranch())
.append(Component.text(
" " + this.messageProvider.apply(sender, MESSAGE_DESCRIPTION) + ": ",
@ -380,7 +383,7 @@ public final class MinecraftHelp<C> {
);
if (hasArguments) {
audience.sendMessage(
Component.text(" ")
Identity.nil(), Component.text(" ")
.append(this.lastBranch())
.append(Component.text(
" " + this.messageProvider.apply(sender, MESSAGE_ARGUMENTS) + ":",
@ -415,10 +418,10 @@ public final class MinecraftHelp<C> {
.append(Component.text(description, this.colors.text));
}
audience.sendMessage(component);
audience.sendMessage(Identity.nil(), component);
}
}
audience.sendMessage(this.footer(sender));
audience.sendMessage(Identity.nil(), this.footer(sender));
}
private @NonNull Component showingResults(

View file

@ -64,6 +64,7 @@ import cloud.commandframework.paper.PaperCommandManager;
import cloud.commandframework.types.tuples.Triplet;
import com.google.common.collect.ImmutableList;
import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -438,7 +439,7 @@ public final class ExamplePlugin extends JavaPlugin {
private void commandClear(final @NonNull Player player) {
player.getInventory().clear();
this.bukkitAudiences.player(player)
.sendMessage(Component.text("Your inventory has been cleared", NamedTextColor.GOLD));
.sendMessage(Identity.nil(), Component.text("Your inventory has been cleared", NamedTextColor.GOLD));
}
@CommandMethod("example give <material> <amount>")
@ -481,6 +482,7 @@ public final class ExamplePlugin extends JavaPlugin {
failureCaption = "regex.money") String money
) {
bukkitAudiences.sender(sender).sendMessage(
Identity.nil(),
Component.text().append(Component.text("You have been given ", NamedTextColor.AQUA))
.append(Component.text(money, NamedTextColor.GOLD))
);