package com.initianovamc.rysingdragon.landprotect.commands;

import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.service.pagination.PaginationList;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

import java.util.ArrayList;
import java.util.List;

public class HelpCommand implements CommandExecutor{

	@Override
	public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
			
		PaginationList.Builder paginationBuilder = PaginationList.builder();
		List<Text> helpText = new ArrayList<>();
		
		for (List<String> aliases : CommandRegistry.getSubCommands().keySet()) {
			CommandSpec spec = CommandRegistry.getSubCommands().get(aliases);
			Text helpCommand = Text.builder()
					.append(Text.of(TextColors.DARK_AQUA, "Command: ", TextColors.GOLD, aliases.toString(), "\n"))
					.append(Text.of(TextColors.DARK_AQUA, "Info: ", TextColors.GOLD, spec.getShortDescription(src).get(), "\n"))
					.append(Text.of(TextColors.DARK_AQUA, "Usage: ", TextColors.GOLD, "/", aliases.get(0), " ", spec.getUsage(src), "\n"))
					.append(Text.of(TextColors.DARK_AQUA, "Permission: ", TextColors.GOLD, spec.toString().substring(spec.toString().lastIndexOf("permission") +11, spec.toString().indexOf("argumentParser") -2), "\n")).color(TextColors.DARK_AQUA)
					.append(Text.of(TextColors.DARK_AQUA, "Access: ", TextColors.GOLD, spec.testPermission(src), " \n")).color(TextColors.DARK_AQUA)
					.build();
			helpText.add(helpCommand);
		}
		
		paginationBuilder.title(Text.of("LandProtect Help Menu")).contents(helpText).padding(Text.of("-")).linesPerPage(10).sendTo(src);
		return CommandResult.success();
	}
	
}

@@ -418,41 +418,143 @@
 api.
-service.pagination.PaginationList
+entity.living.player.Player;%0Aimport org.spongepowered.api.service.pagination.PaginationList;%0Aimport org.spongepowered.api.text.BookView
 ;%0Aim
@@ -868,124 +868,236 @@
 %09%0A%09%09
-PaginationList.Builder paginationBuilder = PaginationList.builder();%0A%09%09List%3CText%3E helpText = new ArrayList%3C%3E(
+if (src instanceof Player) %7B%0A%09%09%09%0A%09%09%09Player player = (Player)src;%0A%09%09%09BookView.Builder helpBook = BookView.builder().author(Text.of(TextColors.DARK_BLUE, %22LandProtect%22)).title(Text.of(TextColors.GOLD, %22LandProtect Help Book%22)
 );%0A%09%09
-%0A%09
 %09for
@@ -1166,16 +1166,17 @@
 et()) %7B%0A
+%09
 %09%09%09Comma
@@ -1239,16 +1239,17 @@
 es);%0A%09%09%09
+%09
 Text hel
@@ -1274,16 +1274,17 @@
 ilder()%0A
+%09
 %09%09%09%09%09.ap
@@ -1367,32 +1367,33 @@
 tring(), %22%5Cn%22))%0A
+%09
 %09%09%09%09%09.append(Tex
@@ -1487,32 +1487,33 @@
 (), %22%5Cn%22))%0A%09%09%09%09%09
+%09
 .append(Text.of(
@@ -1611,24 +1611,25 @@
 rc), %22%5Cn%22))%0A
+%09
 %09%09%09%09%09.append
@@ -1848,24 +1848,25 @@
 _AQUA)%0A%09%09%09%09%09
+%09
 .append(Text
@@ -1978,24 +1978,25 @@
 .DARK_AQUA)%0A
+%09
 %09%09%09%09%09.build(
@@ -2005,20 +2005,25 @@
 %0A%09%09%09
+%09
 help
-Text.add
+Book.addPage
 (hel
@@ -2039,143 +2039,159 @@
 ;%0A%09%09
+%09
 %7D%0A%09%09
-%0A%09
 %09p
-aginationBuilder.title(Text.of(%22LandProtect Help Menu%22)).contents(helpText).padding(Text.of(%22-%22)).linesPerPage(10).sendTo(src);
+layer.sendBookView(helpBook.build());%0A%09%09%7D else %7B%0A%09%09%09src.sendMessage(Text.of(TextColors.RED, %22You must be a player to use this command%22));%0A%09%09%7D%0A%09%09
 %0A%09%09r

make help command send a BookView instead of PaginatedList