Minestom/demo/src/main/java/net/minestom/demo/commands/BookCommand.java

32 lines
1.1 KiB
Java
Raw Normal View History

2022-01-01 18:27:52 +01:00
package net.minestom.demo.commands;
2021-01-09 03:40:22 +01:00
2021-03-04 14:41:41 +01:00
import net.kyori.adventure.inventory.Book;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
2021-01-09 03:40:22 +01:00
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
import net.minestom.server.command.builder.condition.Conditions;
2021-01-09 03:40:22 +01:00
import net.minestom.server.entity.Player;
public class BookCommand extends Command {
public BookCommand() {
super("book");
setCondition(Conditions::playerOnly);
2021-01-09 03:40:22 +01:00
setDefaultExecutor(this::execute);
}
private void execute(CommandSender sender, CommandContext context) {
Player player = (Player) sender;
2021-01-09 03:40:22 +01:00
2021-03-04 14:41:41 +01:00
player.openBook(Book.builder()
.author(Component.text(player.getUsername()))
.title(Component.text(player.getUsername() + "'s Book"))
.pages(Component.text("Page one", NamedTextColor.RED),
Component.text("Page two", NamedTextColor.GREEN),
Component.text("Page three", NamedTextColor.BLUE)));
2021-01-09 03:40:22 +01:00
}
}