// Path: ChatUILib/src/main/java/com/simon816/chatui/lib/PlayerChatView.java
// public interface PlayerChatView {
// 
//     public Player getPlayer();
// 
//     public TopWindow getWindow();
// 
//     public boolean showWindow(TopWindow window);
// 
//     public boolean removeShownWindow();
// 
//     public void update();
// 
//     public boolean handleIncoming(Text message);
// 
//     public Optional<Text> transformOutgoing(CommandSource sender, Text originalOutgoing, ChatType type);
// 
//     public boolean handleCommand(String[] args);
// 
//     public void onRemove();
// 
//     public void initialize();
// 
// }
// 
// Path: ChatUILib/src/main/java/com/simon816/chatui/lib/PlayerContext.java
// public class PlayerContext {
// 
//     public final int height;
//     public final int width;
//     public final boolean forceUnicode;
// 
//     private final UUID playerUUID;
//     private final TextUtils utils;
// 
//     public PlayerContext(Player player, int width, int height, boolean forceUnicode, FontData fontData) {
//         this(player.getUniqueId(), width, height, forceUnicode, new TextUtils(fontData, forceUnicode, player.getUniqueId()));
//         checkArgument(height >= 1, "Height must be at least one");
//         checkArgument(width >= 1, "Width must be at least one");
//     }
// 
//     private PlayerContext(UUID playerUuid, int width, int height, boolean forceUnicode, TextUtils utils) {
//         this.playerUUID = playerUuid;
//         this.width = width;
//         this.height = height;
//         this.forceUnicode = forceUnicode;
//         this.utils = utils;
//     }
// 
//     public Player getPlayer() {
//         return Sponge.getServer().getPlayer(this.playerUUID).get();
//     }
// 
//     public TextUtils utils() {
//         return this.utils;
//     }
// 
//     public PlayerContext withHeight(int height) {
//         checkArgument(height >= 1, "Height must be at least one");
//         if (height == this.height) {
//             return this;
//         }
//         return new PlayerContext(this.playerUUID, this.width, height, this.forceUnicode, this.utils);
//     }
// 
//     public PlayerContext withWidth(int width) {
//         checkArgument(width >= 1, "Width must be at least one");
//         if (width == this.width) {
//             return this;
//         }
//         return new PlayerContext(this.playerUUID, width, this.height, this.forceUnicode, this.utils);
//     }
// 
//     public PlayerContext withUnicode(boolean forceUnicode) {
//         if (forceUnicode == this.forceUnicode) {
//             return this;
//         }
//         return new PlayerContext(this.playerUUID, this.width, this.height, forceUnicode,
//                 new TextUtils(this.utils.getFontData(), forceUnicode, this.playerUUID));
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//                 .add("player", this.getPlayer())
//                 .add("width", this.width)
//                 .add("height", this.height)
//                 .add("forceUnicode", this.forceUnicode)
//                 .toString();
//     }
// 
// }
// 
// Path: ChatUILib/src/main/java/com/simon816/chatui/lib/internal/ClickCallback.java
// public class ClickCallback {
// 
//     private static final Cache<UUID, Consumer<PlayerChatView>> callbackCache = CacheBuilder.newBuilder()
//             .expireAfterAccess(5, TimeUnit.MINUTES)
//             .build();
// 
//     public static CommandSpec createCommand() {
//         return CommandSpec.builder()
//                 .arguments(GenericArguments.string(Text.of("uuid")))
//                 .executor((src, args) -> {
//                     UUID uuid = UUID.fromString(args.<String>getOne("uuid").get());
//                     Consumer<PlayerChatView> consumer = callbackCache.getIfPresent(uuid);
//                     if (consumer == null) {
//                         throw new CommandException(Text.of("Callback expired"));
//                     }
//                     consumer.accept(ChatUILib.getView(src));
//                     return CommandResult.success();
//                 }).build();
//     }
// 
//     public static String generateCommand(Consumer<PlayerChatView> handler) {
//         UUID uuid = UUID.randomUUID();
//         callbackCache.put(uuid, handler);
//         return "/chatui exec " + uuid;
//     }
// 
// }


import com.google.common.base.Utf8;
import com.simon816.chatui.lib.PlayerChatView;
import com.simon816.chatui.lib.PlayerContext;
import com.simon816.chatui.lib.internal.ClickCallback;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.source.ProxySource;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.action.ClickAction;
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.serializer.TextSerializers;
import java.util.List;
import java.util.function.Consumer;

package com.simon816.chatui.util;



public class Utils {

    public static CommandSource getRealSource(CommandSource source) {
        while (source instanceof ProxySource) {
            source = ((ProxySource) source).getOriginalSource();
        }
        return source;
    }

    public static ClickAction<?> execClick(Consumer<PlayerChatView> handler) {
        return TextActions.runCommand(ClickCallback.generateCommand(handler));
    }

    public static ClickAction<?> execClick(Runnable action) {
        return execClick(view -> {
            action.run();
            view.update();
        });
    }


// Path: ChatUILib/src/main/java/com/simon816/chatui/lib/PlayerChatView.java
// public interface PlayerChatView {
// 
//     public Player getPlayer();
// 
//     public TopWindow getWindow();
// 
//     public boolean showWindow(TopWindow window);
// 
//     public boolean removeShownWindow();
// 
//     public void update();
// 
//     public boolean handleIncoming(Text message);
// 
//     public Optional<Text> transformOutgoing(CommandSource sender, Text originalOutgoing, ChatType type);
// 
//     public boolean handleCommand(String[] args);
// 
//     public void onRemove();
// 
//     public void initialize();
// 
// }
// 
// Path: ChatUILib/src/main/java/com/simon816/chatui/lib/PlayerContext.java
// public class PlayerContext {
// 
//     public final int height;
//     public final int width;
//     public final boolean forceUnicode;
// 
//     private final UUID playerUUID;
//     private final TextUtils utils;
// 
//     public PlayerContext(Player player, int width, int height, boolean forceUnicode, FontData fontData) {
//         this(player.getUniqueId(), width, height, forceUnicode, new TextUtils(fontData, forceUnicode, player.getUniqueId()));
//         checkArgument(height >= 1, "Height must be at least one");
//         checkArgument(width >= 1, "Width must be at least one");
//     }
// 
//     private PlayerContext(UUID playerUuid, int width, int height, boolean forceUnicode, TextUtils utils) {
//         this.playerUUID = playerUuid;
//         this.width = width;
//         this.height = height;
//         this.forceUnicode = forceUnicode;
//         this.utils = utils;
//     }
// 
//     public Player getPlayer() {
//         return Sponge.getServer().getPlayer(this.playerUUID).get();
//     }
// 
//     public TextUtils utils() {
//         return this.utils;
//     }
// 
//     public PlayerContext withHeight(int height) {
//         checkArgument(height >= 1, "Height must be at least one");
//         if (height == this.height) {
//             return this;
//         }
//         return new PlayerContext(this.playerUUID, this.width, height, this.forceUnicode, this.utils);
//     }
// 
//     public PlayerContext withWidth(int width) {
//         checkArgument(width >= 1, "Width must be at least one");
//         if (width == this.width) {
//             return this;
//         }
//         return new PlayerContext(this.playerUUID, width, this.height, this.forceUnicode, this.utils);
//     }
// 
//     public PlayerContext withUnicode(boolean forceUnicode) {
//         if (forceUnicode == this.forceUnicode) {
//             return this;
//         }
//         return new PlayerContext(this.playerUUID, this.width, this.height, forceUnicode,
//                 new TextUtils(this.utils.getFontData(), forceUnicode, this.playerUUID));
//     }
// 
//     @Override
//     public String toString() {
//         return MoreObjects.toStringHelper(this)
//                 .add("player", this.getPlayer())
//                 .add("width", this.width)
//                 .add("height", this.height)
//                 .add("forceUnicode", this.forceUnicode)
//                 .toString();
//     }
// 
// }
// 
// Path: ChatUILib/src/main/java/com/simon816/chatui/lib/internal/ClickCallback.java
// public class ClickCallback {
// 
//     private static final Cache<UUID, Consumer<PlayerChatView>> callbackCache = CacheBuilder.newBuilder()
//             .expireAfterAccess(5, TimeUnit.MINUTES)
//             .build();
// 
//     public static CommandSpec createCommand() {
//         return CommandSpec.builder()
//                 .arguments(GenericArguments.string(Text.of("uuid")))
//                 .executor((src, args) -> {
//                     UUID uuid = UUID.fromString(args.<String>getOne("uuid").get());
//                     Consumer<PlayerChatView> consumer = callbackCache.getIfPresent(uuid);
//                     if (consumer == null) {
//                         throw new CommandException(Text.of("Callback expired"));
//                     }
//                     consumer.accept(ChatUILib.getView(src));
//                     return CommandResult.success();
//                 }).build();
//     }
// 
//     public static String generateCommand(Consumer<PlayerChatView> handler) {
//         UUID uuid = UUID.randomUUID();
//         callbackCache.put(uuid, handler);
//         return "/chatui exec " + uuid;
//     }
// 
// }


// Path: ChatUILib/src/main/java/com/simon816/chatui/util/Utils.java
import com.google.common.base.Utf8;
import com.simon816.chatui.lib.PlayerChatView;
import com.simon816.chatui.lib.PlayerContext;
import com.simon816.chatui.lib.internal.ClickCallback;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.source.ProxySource;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.action.ClickAction;
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.serializer.TextSerializers;
import java.util.List;
import java.util.function.Consumer;

package com.simon816.chatui.util;



public class Utils {

    public static CommandSource getRealSource(CommandSource source) {
        while (source instanceof ProxySource) {
            source = ((ProxySource) source).getOriginalSource();
        }
        return source;
    }

    public static ClickAction<?> execClick(Consumer<PlayerChatView> handler) {
        return TextActions.runCommand(ClickCallback.generateCommand(handler));
    }

    public static ClickAction<?> execClick(Runnable action) {
        return execClick(view -> {
            action.run();
            view.update();
        });
    }


    public static void sendMessageSplitLarge(PlayerContext ctx, Text text) {
