Search in sources :

Example 6 with CustomPlaceholderClickEvent

use of com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent in project InteractiveChat by LOOHP.

the class InteractiveChatBungee method onReceive.

@EventHandler
public void onReceive(PluginMessageEvent event) {
    if (!event.getTag().equals("interchat:main")) {
        return;
    }
    event.setCancelled(true);
    Server senderServer = (Server) event.getSender();
    SocketAddress senderServerAddress = event.getSender().getSocketAddress();
    byte[] packet = Arrays.copyOf(event.getData(), event.getData().length);
    ByteArrayDataInput in = ByteStreams.newDataInput(packet);
    int packetNumber = in.readInt();
    int packetId = in.readShort();
    if (!Registry.PROXY_PASSTHROUGH_RELAY_PACKETS.contains(packetId)) {
        boolean isEnding = in.readBoolean();
        byte[] data = new byte[packet.length - 7];
        in.readFully(data);
        byte[] chain = incomming.remove(packetNumber);
        if (chain != null) {
            ByteBuffer buff = ByteBuffer.allocate(chain.length + data.length);
            buff.put(chain);
            buff.put(data);
            data = buff.array();
        }
        if (!isEnding) {
            incomming.put(packetNumber, data);
            return;
        }
        byte[] finalData = data;
        pluginMessageHandlingExecutor.submit(() -> {
            try {
                ByteArrayDataInput input = ByteStreams.newDataInput(finalData);
                switch(packetId) {
                    case 0x07:
                        int cooldownType = input.readByte();
                        switch(cooldownType) {
                            case 0:
                                UUID uuid = DataTypeIO.readUUID(input);
                                long time = input.readLong();
                                playerCooldownManager.setPlayerUniversalLastTimestamp(uuid, time);
                                break;
                            case 1:
                                uuid = DataTypeIO.readUUID(input);
                                UUID internalId = DataTypeIO.readUUID(input);
                                time = input.readLong();
                                playerCooldownManager.setPlayerPlaceholderLastTimestamp(uuid, internalId, time);
                                break;
                        }
                        for (ServerInfo server : getProxy().getServers().values()) {
                            if (!server.getSocketAddress().equals(senderServerAddress) && server.getPlayers().size() > 0) {
                                server.sendData("interchat:main", finalData);
                                pluginMessagesCounter.incrementAndGet();
                            }
                        }
                        break;
                    case 0x08:
                        UUID messageId = DataTypeIO.readUUID(input);
                        String component = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        messageForwardingHandler.receivedProcessedMessage(messageId, component);
                        break;
                    case 0x09:
                        loadConfig();
                        break;
                    case 0x0B:
                        int id = input.readInt();
                        boolean permissionValue = input.readBoolean();
                        permissionChecks.put(id, permissionValue);
                        break;
                    case 0x0C:
                        int size1 = input.readInt();
                        List<ICPlaceholder> list = new ArrayList<>(size1);
                        for (int i = 0; i < size1; i++) {
                            boolean isBulitIn = input.readBoolean();
                            if (isBulitIn) {
                                String keyword = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                String name = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                String description = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                String permission = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                long cooldown = input.readLong();
                                list.add(new BuiltInPlaceholder(Pattern.compile(keyword), name, description, permission, cooldown));
                            } else {
                                int customNo = input.readInt();
                                ParsePlayer parseplayer = ParsePlayer.fromOrder(input.readByte());
                                String placeholder = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                boolean parseKeyword = input.readBoolean();
                                long cooldown = input.readLong();
                                boolean hoverEnabled = input.readBoolean();
                                String hoverText = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                boolean clickEnabled = input.readBoolean();
                                String clickAction = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                String clickValue = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                boolean replaceEnabled = input.readBoolean();
                                String replaceText = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                String name = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                String description = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                                list.add(new CustomPlaceholder(customNo, parseplayer, Pattern.compile(placeholder), parseKeyword, cooldown, new CustomPlaceholderHoverEvent(hoverEnabled, hoverText), new CustomPlaceholderClickEvent(clickEnabled, clickEnabled ? ClickEventAction.valueOf(clickAction) : null, clickValue), new CustomPlaceholderReplaceText(replaceEnabled, replaceText), name, description));
                            }
                        }
                        placeholderList.put(senderServer.getInfo().getName(), list);
                        playerCooldownManager.reloadPlaceholders(placeholderList.values().stream().flatMap(each -> each.stream()).distinct().collect(Collectors.toList()));
                        PluginMessageSendingBungee.forwardPlaceholderList(list, senderServer.getInfo());
                        break;
                    case 0x0D:
                        UUID uuid2 = DataTypeIO.readUUID(input);
                        PluginMessageSendingBungee.reloadPlayerData(uuid2, senderServer.getInfo());
                        break;
                    case 0x10:
                        UUID requestUUID = DataTypeIO.readUUID(input);
                        int requestType = input.readByte();
                        switch(requestType) {
                            case 0:
                                PluginMessageSendingBungee.respondPlayerListRequest(requestUUID, senderServer.getInfo());
                                break;
                            default:
                                break;
                        }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    } else {
        pluginMessageHandlingExecutor.submit(() -> {
            for (ServerInfo server : getProxy().getServers().values()) {
                if (!server.getSocketAddress().equals(senderServerAddress) && server.getPlayers().size() > 0) {
                    server.sendData("interchat:main", event.getData());
                    pluginMessagesCounter.incrementAndGet();
                }
            }
        });
    }
}
Also used : Charts(com.loohp.interactivechat.proxy.bungee.metrics.Charts) Arrays(java.util.Arrays) PlayerUtils(com.loohp.interactivechat.utils.PlayerUtils) SocketAddress(java.net.SocketAddress) PostLoginEvent(net.md_5.bungee.api.event.PostLoginEvent) Random(java.util.Random) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) UserConnection(net.md_5.bungee.UserConnection) ByteBuffer(java.nio.ByteBuffer) Via(us.myles.ViaVersion.api.Via) EventPriority(net.md_5.bungee.event.EventPriority) InteractiveChatComponentSerializer(com.loohp.interactivechat.utils.InteractiveChatComponentSerializer) Matcher(java.util.regex.Matcher) ChannelPromise(io.netty.channel.ChannelPromise) Chat(net.md_5.bungee.protocol.packet.Chat) Map(java.util.Map) ThreadFactory(java.util.concurrent.ThreadFactory) Material(org.bukkit.Material) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) Listener(net.md_5.bungee.api.plugin.Listener) CommandSender(net.md_5.bungee.api.CommandSender) Filter(java.util.logging.Filter) SynchronousQueue(java.util.concurrent.SynchronousQueue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ChannelPipeline(io.netty.channel.ChannelPipeline) UUID(java.util.UUID) LogRecord(java.util.logging.LogRecord) Logger(java.util.logging.Logger) PlaceholderAPI(me.clip.placeholderapi.PlaceholderAPI) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) InteractiveChat(com.loohp.interactivechat.InteractiveChat) ChatEvent(net.md_5.bungee.api.event.ChatEvent) ComponentSerializer(net.md_5.bungee.chat.ComponentSerializer) List(java.util.List) ClickEventAction(com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction) Server(net.md_5.bungee.api.connection.Server) ChannelWrapper(net.md_5.bungee.netty.ChannelWrapper) ByteStreams(com.google.common.io.ByteStreams) Entry(java.util.Map.Entry) ServerConnection(net.md_5.bungee.ServerConnection) Plugin(net.md_5.bungee.api.plugin.Plugin) Pattern(java.util.regex.Pattern) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) HoverEvent(net.kyori.adventure.text.event.HoverEvent) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ProxyPlayerCooldownManager(com.loohp.interactivechat.proxy.objectholders.ProxyPlayerCooldownManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) Registry(com.loohp.interactivechat.registry.Registry) Config(com.loohp.interactivechat.config.Config) DataTypeIO(com.loohp.interactivechat.utils.DataTypeIO) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BuiltInPlaceholder(com.loohp.interactivechat.objectholders.BuiltInPlaceholder) ServerInfo(net.md_5.bungee.api.config.ServerInfo) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) ArrayList(java.util.ArrayList) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) LinkedHashMap(java.util.LinkedHashMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Component(net.kyori.adventure.text.Component) ServerConnectedEvent(net.md_5.bungee.api.event.ServerConnectedEvent) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) Metrics(com.loohp.interactivechat.proxy.bungee.metrics.Metrics) PlayerDisconnectEvent(net.md_5.bungee.api.event.PlayerDisconnectEvent) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) ChatColor(net.md_5.bungee.api.ChatColor) Iterator(java.util.Iterator) BackendInteractiveChatData(com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData) PluginMessageEvent(net.md_5.bungee.api.event.PluginMessageEvent) IOException(java.io.IOException) PipelineUtils(net.md_5.bungee.netty.PipelineUtils) ProxyServer(net.md_5.bungee.api.ProxyServer) Field(java.lang.reflect.Field) ServerSwitchEvent(net.md_5.bungee.api.event.ServerSwitchEvent) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) ChatColorUtils(com.loohp.interactivechat.utils.ChatColorUtils) EventHandler(net.md_5.bungee.event.EventHandler) Collections(java.util.Collections) ProxyMessageForwardingHandler(com.loohp.interactivechat.proxy.objectholders.ProxyMessageForwardingHandler) Server(net.md_5.bungee.api.connection.Server) ProxyServer(net.md_5.bungee.api.ProxyServer) ServerInfo(net.md_5.bungee.api.config.ServerInfo) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) ArrayList(java.util.ArrayList) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) IOException(java.io.IOException) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) ByteBuffer(java.nio.ByteBuffer) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) BuiltInPlaceholder(com.loohp.interactivechat.objectholders.BuiltInPlaceholder) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) SocketAddress(java.net.SocketAddress) UUID(java.util.UUID) EventHandler(net.md_5.bungee.event.EventHandler)

Example 7 with CustomPlaceholderClickEvent

use of com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent in project InteractiveChat by LOOHP.

the class PluginMessageSendingBungee method forwardPlaceholderList.

@SuppressWarnings("deprecation")
public static void forwardPlaceholderList(List<ICPlaceholder> serverPlaceholderList, ServerInfo serverFrom) throws IOException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    DataTypeIO.writeString(output, serverFrom.getName(), StandardCharsets.UTF_8);
    output.writeInt(serverPlaceholderList.size());
    for (ICPlaceholder placeholder : serverPlaceholderList) {
        boolean isBuiltIn = placeholder.isBuildIn();
        output.writeBoolean(isBuiltIn);
        if (isBuiltIn) {
            DataTypeIO.writeString(output, placeholder.getKeyword().pattern(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(output, placeholder.getName(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(output, placeholder.getDescription(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(output, placeholder.getPermission(), StandardCharsets.UTF_8);
            output.writeLong(placeholder.getCooldown());
        } else {
            CustomPlaceholder customPlaceholder = (CustomPlaceholder) placeholder;
            output.writeInt(customPlaceholder.getPosition());
            output.writeByte(customPlaceholder.getParsePlayer().getOrder());
            DataTypeIO.writeString(output, customPlaceholder.getKeyword().pattern(), StandardCharsets.UTF_8);
            output.writeBoolean(customPlaceholder.getParseKeyword());
            output.writeLong(customPlaceholder.getCooldown());
            CustomPlaceholderHoverEvent hover = customPlaceholder.getHover();
            output.writeBoolean(hover.isEnabled());
            DataTypeIO.writeString(output, hover.getText(), StandardCharsets.UTF_8);
            CustomPlaceholderClickEvent click = customPlaceholder.getClick();
            output.writeBoolean(click.isEnabled());
            DataTypeIO.writeString(output, click.getAction() == null ? "" : click.getAction().name(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(output, click.getValue(), StandardCharsets.UTF_8);
            CustomPlaceholderReplaceText replace = customPlaceholder.getReplace();
            output.writeBoolean(replace.isEnabled());
            DataTypeIO.writeString(output, replace.getReplaceText(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(output, placeholder.getName(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(output, placeholder.getDescription(), StandardCharsets.UTF_8);
        }
    }
    int packetNumber = InteractiveChatBungee.random.nextInt();
    int packetId = 0x09;
    byte[] data = output.toByteArray();
    byte[][] dataArray = CustomArrayUtils.divideArray(data, 32700);
    for (int i = 0; i < dataArray.length; i++) {
        byte[] chunk = dataArray[i];
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeInt(packetNumber);
        out.writeShort(packetId);
        out.writeBoolean(i == (dataArray.length - 1));
        out.write(chunk);
        for (ServerInfo server : ProxyServer.getInstance().getServers().values()) {
            if (!server.getName().equals(serverFrom.getName())) {
                server.sendData("interchat:main", out.toByteArray());
                InteractiveChatBungee.pluginMessagesCounter.incrementAndGet();
            }
        }
    }
}
Also used : ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) ServerInfo(net.md_5.bungee.api.config.ServerInfo) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)

Example 8 with CustomPlaceholderClickEvent

use of com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent in project InteractiveChat by LOOHP.

the class BungeeMessageListener method onPluginMessageReceived.

@SuppressWarnings("deprecation")
@Override
public void onPluginMessageReceived(String channel, Player pluginMessagingPlayer, byte[] bytes) {
    if (!channel.equals("interchat:main")) {
        return;
    }
    ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
    int packetNumber = in.readInt();
    int packetId = in.readShort();
    boolean isEnding = in.readBoolean();
    byte[] data = new byte[bytes.length - 7];
    in.readFully(data);
    byte[] chain = incoming.remove(packetNumber);
    if (chain != null) {
        ByteBuffer buff = ByteBuffer.allocate(chain.length + data.length);
        buff.put(chain);
        buff.put(data);
        data = buff.array();
    }
    if (!isEnding) {
        incoming.put(packetNumber, data);
        return;
    }
    try {
        ByteArrayDataInput input = ByteStreams.newDataInput(data);
        switch(packetId) {
            case 0x00:
                int playerAmount = input.readInt();
                Set<UUID> localUUID = Bukkit.getOnlinePlayers().stream().map(each -> each.getUniqueId()).collect(Collectors.toSet());
                Set<UUID> current = new HashSet<>(ICPlayerFactory.getRemoteUUIDs());
                Set<UUID> newSet = new HashSet<>();
                for (int i = 0; i < playerAmount; i++) {
                    String server = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                    UUID uuid = DataTypeIO.readUUID(input);
                    String name = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                    ICPlayer player = ICPlayerFactory.getICPlayer(uuid);
                    if (player != null) {
                        if (!player.getRemoteServer().equals(server)) {
                            player.setRemoteServer(server);
                        }
                    }
                    if (!localUUID.contains(uuid) && !ICPlayerFactory.getRemoteUUIDs().contains(uuid)) {
                        ICPlayerFactory.createOrUpdateRemoteICPlayer(server, name, uuid, true, 0, 0, Bukkit.createInventory(null, 45), Bukkit.createInventory(null, 36));
                    }
                    newSet.add(uuid);
                }
                current.removeAll(newSet);
                for (UUID uuid : current) {
                    ICPlayerFactory.removeRemoteICPlayer(uuid);
                }
                for (UUID uuid : localUUID) {
                    ICPlayerFactory.removeRemoteICPlayer(uuid);
                }
                break;
            case 0x01:
                int delay = input.readInt();
                short itemStackScheme = input.readShort();
                short inventoryScheme = input.readShort();
                InteractiveChat.remoteDelay = delay;
                BungeeMessageSender.itemStackScheme = itemStackScheme;
                BungeeMessageSender.inventoryScheme = inventoryScheme;
                break;
            case 0x02:
                UUID sender = DataTypeIO.readUUID(input);
                UUID receiver = DataTypeIO.readUUID(input);
                InteractiveChat.mentionPair.add(new MentionPair(sender, receiver));
                break;
            case 0x03:
                UUID uuid = DataTypeIO.readUUID(input);
                ICPlayer player = ICPlayerFactory.getICPlayer(uuid);
                if (player == null) {
                    break;
                }
                boolean rightHanded = input.readBoolean();
                player.setRemoteRightHanded(rightHanded);
                int selectedSlot = input.readByte();
                player.setRemoteSelectedSlot(selectedSlot);
                int level = input.readInt();
                player.setRemoteExperienceLevel(level);
                int size = input.readByte();
                ItemStack[] equipment = new ItemStack[size];
                for (int i = 0; i < equipment.length; i++) {
                    equipment[i] = DataTypeIO.readItemStack(input, StandardCharsets.UTF_8);
                }
                player.getEquipment().setHelmet(equipment[0]);
                player.getEquipment().setChestplate(equipment[1]);
                player.getEquipment().setLeggings(equipment[2]);
                player.getEquipment().setBoots(equipment[3]);
                if (InteractiveChat.version.isOld()) {
                    player.getEquipment().setItemInHand(equipment[4]);
                } else {
                    player.getEquipment().setItemInMainHand(equipment[4]);
                    player.getEquipment().setItemInOffHand(equipment[5]);
                }
                break;
            case 0x04:
                UUID uuid1 = DataTypeIO.readUUID(input);
                ICPlayer player1 = ICPlayerFactory.getICPlayer(uuid1);
                if (player1 == null) {
                    break;
                }
                boolean rightHanded1 = input.readBoolean();
                player1.setRemoteRightHanded(rightHanded1);
                int selectedSlot1 = input.readByte();
                player1.setRemoteSelectedSlot(selectedSlot1);
                int level1 = input.readInt();
                player1.setRemoteExperienceLevel(level1);
                int type = input.readByte();
                if (type == 0) {
                    player1.setRemoteInventory(DataTypeIO.readInventory(input, StandardCharsets.UTF_8));
                } else {
                    player1.setRemoteEnderChest(DataTypeIO.readInventory(input, StandardCharsets.UTF_8));
                }
                break;
            case 0x05:
                UUID uuid2 = DataTypeIO.readUUID(input);
                ICPlayer player2 = ICPlayerFactory.getICPlayer(uuid2);
                if (player2 == null) {
                    break;
                }
                int size1 = input.readInt();
                for (int i = 0; i < size1; i++) {
                    String placeholder = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                    String text = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                    player2.getRemotePlaceholdersMapping().put(placeholder, text);
                }
                break;
            case 0x06:
                String message = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                UUID uuid3 = DataTypeIO.readUUID(input);
                ICPlayer player3 = ICPlayerFactory.getICPlayer(uuid3);
                if (player3 == null) {
                    break;
                }
                InteractiveChat.messages.put(message, uuid3);
                Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> InteractiveChat.messages.remove(message), 60);
                break;
            case 0x07:
                int cooldownType = input.readByte();
                switch(cooldownType) {
                    case 0:
                        UUID uuid4 = DataTypeIO.readUUID(input);
                        long time = input.readLong();
                        InteractiveChat.placeholderCooldownManager.setPlayerUniversalLastTimestampRaw(uuid4, time);
                        break;
                    case 1:
                        uuid4 = DataTypeIO.readUUID(input);
                        UUID internalId = DataTypeIO.readUUID(input);
                        time = input.readLong();
                        Optional<ICPlaceholder> optPlaceholder = InteractiveChat.placeholderList.values().stream().filter(each -> each.getInternalId().equals(internalId)).findFirst();
                        if (optPlaceholder.isPresent()) {
                            InteractiveChat.placeholderCooldownManager.setPlayerPlaceholderLastTimestampRaw(uuid4, optPlaceholder.get(), time);
                        }
                        break;
                }
                break;
            case 0x08:
                UUID messageId = DataTypeIO.readUUID(input);
                UUID uuid5 = DataTypeIO.readUUID(input);
                Player bukkitplayer1 = Bukkit.getPlayer(uuid5);
                if (bukkitplayer1 == null) {
                    break;
                }
                String component = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
                    try {
                        String processed = ProcessExternalMessage.processAndRespond(bukkitplayer1, component);
                        BungeeMessageSender.respondProcessedMessage(System.currentTimeMillis(), processed, messageId);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
                break;
            case 0x09:
                String server = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                int size2 = input.readInt();
                List<ICPlaceholder> list = new ArrayList<>(size2);
                for (int i = 0; i < size2; i++) {
                    boolean isBulitIn = input.readBoolean();
                    if (isBulitIn) {
                        String keyword = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        String name = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        String description = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        String permission = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        long cooldown = input.readLong();
                        list.add(new BuiltInPlaceholder(Pattern.compile(keyword), name, description, permission, cooldown));
                    } else {
                        int customNo = input.readInt();
                        ParsePlayer parseplayer = ParsePlayer.fromOrder(input.readByte());
                        String placeholder = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        boolean parseKeyword = input.readBoolean();
                        long cooldown = input.readLong();
                        boolean hoverEnabled = input.readBoolean();
                        String hoverText = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        boolean clickEnabled = input.readBoolean();
                        String clickAction = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        String clickValue = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        boolean replaceEnabled = input.readBoolean();
                        String replaceText = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        String name = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        String description = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                        list.add(new CustomPlaceholder(customNo, parseplayer, Pattern.compile(placeholder), parseKeyword, cooldown, new CustomPlaceholderHoverEvent(hoverEnabled, hoverText), new CustomPlaceholderClickEvent(clickEnabled, clickEnabled ? ClickEventAction.valueOf(clickAction) : null, clickValue), new CustomPlaceholderReplaceText(replaceEnabled, replaceText), name, description));
                    }
                }
                InteractiveChat.remotePlaceholderList.put(server, list);
                break;
            case 0x0A:
                BungeeMessageSender.resetAndForwardPlaceholderList(System.currentTimeMillis(), InteractiveChat.placeholderList.values());
                break;
            case 0x0B:
                int id = input.readInt();
                UUID playerUUID = DataTypeIO.readUUID(input);
                String permission = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                Player player5 = Bukkit.getPlayer(playerUUID);
                BungeeMessageSender.permissionCheckResponse(System.currentTimeMillis(), id, player5 != null && player5.hasPermission(permission));
                break;
            case 0x0D:
                UUID playerUUID1 = DataTypeIO.readUUID(input);
                PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(playerUUID1);
                if (pd != null) {
                    pd.reload();
                }
                break;
            case 0x0E:
                SharedType sharedType = SharedType.fromValue(input.readByte());
                String sha1 = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                Inventory inventory = DataTypeIO.readInventory(input, StandardCharsets.UTF_8);
                InteractiveChatAPI.addInventoryToItemShareList(sharedType, sha1, inventory);
                break;
            case 0x0F:
                int requestType = input.readByte();
                UUID playerUUID2 = DataTypeIO.readUUID(input);
                Player player6 = Bukkit.getPlayer(playerUUID2);
                if (player6 != null) {
                    ICPlayer player7 = ICPlayerFactory.getICPlayer(player6);
                    switch(requestType) {
                        case 0:
                            BungeeMessageSender.forwardInventory(System.currentTimeMillis(), player7.getUniqueId(), player7.isRightHanded(), player7.getSelectedSlot(), player7.getExperienceLevel(), null, player7.getInventory());
                            break;
                        case 1:
                            BungeeMessageSender.forwardEnderchest(System.currentTimeMillis(), player7.getUniqueId(), player7.isRightHanded(), player7.getSelectedSlot(), player7.getExperienceLevel(), null, player7.getEnderChest());
                            break;
                    }
                }
                break;
            case 0x10:
                UUID requestUUID = DataTypeIO.readUUID(input);
                int requestType2 = input.readByte();
                // noinspection SwitchStatementWithTooFewBranches
                switch(requestType2) {
                    case 0:
                        List<ValueTrios<UUID, String, Integer>> playerlist = new ArrayList<>();
                        int playerListSize = input.readInt();
                        for (int i = 0; i < playerListSize; i++) {
                            playerlist.add(new ValueTrios<>(DataTypeIO.readUUID(input), DataTypeIO.readString(input, StandardCharsets.UTF_8), input.readInt()));
                        }
                        @SuppressWarnings("unchecked") CompletableFuture<List<ValueTrios<UUID, String, Integer>>> future = (CompletableFuture<List<ValueTrios<UUID, String, Integer>>>) toComplete.remove(requestUUID);
                        if (future != null) {
                            future.complete(playerlist);
                        }
                        break;
                    default:
                        break;
                }
                break;
            case 0x11:
                UUID playerUUID3 = DataTypeIO.readUUID(input);
                int nicknameSize = input.readInt();
                Set<String> remoteNicknames = new HashSet<>();
                for (int i = 0; i < nicknameSize; i++) {
                    remoteNicknames.add(DataTypeIO.readString(input, StandardCharsets.UTF_8));
                }
                ICPlayer icPlayer = ICPlayerFactory.getICPlayer(playerUUID3);
                if (icPlayer != null) {
                    icPlayer.setRemoteNicknames(remoteNicknames);
                }
                break;
            case 0x12:
                UUID playerUUID4 = DataTypeIO.readUUID(input);
                String placeholders = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                ICPlayer icPlayer1 = ICPlayerFactory.getICPlayer(playerUUID4);
                if (icPlayer1 != null && icPlayer1.isLocal()) {
                    PlaceholderParser.parse(icPlayer1, placeholders);
                }
                break;
            case 0xFF:
                String customChannel = DataTypeIO.readString(input, StandardCharsets.UTF_8);
                int dataLength = input.readInt();
                byte[] customData = new byte[dataLength];
                input.readFully(customData);
                ProxyCustomDataRecievedEvent dataEvent = new ProxyCustomDataRecievedEvent(customChannel, customData);
                Bukkit.getPluginManager().callEvent(dataEvent);
                break;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) InteractiveChatAPI(com.loohp.interactivechat.api.InteractiveChatAPI) PlayerData(com.loohp.interactivechat.data.PlayerDataManager.PlayerData) DataTypeIO(com.loohp.interactivechat.utils.DataTypeIO) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BuiltInPlaceholder(com.loohp.interactivechat.objectholders.BuiltInPlaceholder) Player(org.bukkit.entity.Player) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) Inventory(org.bukkit.inventory.Inventory) ByteBuffer(java.nio.ByteBuffer) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) PluginMessageListener(org.bukkit.plugin.messaging.PluginMessageListener) ProcessExternalMessage(com.loohp.interactivechat.modules.ProcessExternalMessage) Map(java.util.Map) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) MentionPair(com.loohp.interactivechat.objectholders.MentionPair) SharedType(com.loohp.interactivechat.api.InteractiveChatAPI.SharedType) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) Bukkit(org.bukkit.Bukkit) ProxyCustomDataRecievedEvent(com.loohp.interactivechat.api.events.ProxyCustomDataRecievedEvent) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ItemStack(org.bukkit.inventory.ItemStack) InteractiveChat(com.loohp.interactivechat.InteractiveChat) List(java.util.List) ValueTrios(com.loohp.interactivechat.objectholders.ValueTrios) ClickEventAction(com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) ICPlayerFactory(com.loohp.interactivechat.objectholders.ICPlayerFactory) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) PlaceholderParser(com.loohp.interactivechat.utils.PlaceholderParser) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) ArrayList(java.util.ArrayList) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) CompletableFuture(java.util.concurrent.CompletableFuture) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) HashSet(java.util.HashSet) Player(org.bukkit.entity.Player) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) ProxyCustomDataRecievedEvent(com.loohp.interactivechat.api.events.ProxyCustomDataRecievedEvent) SharedType(com.loohp.interactivechat.api.InteractiveChatAPI.SharedType) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) ByteBuffer(java.nio.ByteBuffer) TimeoutException(java.util.concurrent.TimeoutException) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) BuiltInPlaceholder(com.loohp.interactivechat.objectholders.BuiltInPlaceholder) MentionPair(com.loohp.interactivechat.objectholders.MentionPair) ItemStack(org.bukkit.inventory.ItemStack) PlayerData(com.loohp.interactivechat.data.PlayerDataManager.PlayerData) Inventory(org.bukkit.inventory.Inventory) ValueTrios(com.loohp.interactivechat.objectholders.ValueTrios)

Example 9 with CustomPlaceholderClickEvent

use of com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent in project InteractiveChat by LOOHP.

the class BungeeMessageSender method resetAndForwardPlaceholderList.

@SuppressWarnings("deprecation")
public static boolean resetAndForwardPlaceholderList(long time, Collection<ICPlaceholder> placeholderList) throws Exception {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeInt(placeholderList.size());
    for (ICPlaceholder placeholder : placeholderList) {
        boolean isBuiltIn = placeholder.isBuildIn();
        out.writeBoolean(isBuiltIn);
        if (isBuiltIn) {
            DataTypeIO.writeString(out, placeholder.getKeyword().pattern(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(out, placeholder.getName(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(out, placeholder.getDescription(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(out, placeholder.getPermission(), StandardCharsets.UTF_8);
            out.writeLong(placeholder.getCooldown());
        } else {
            CustomPlaceholder customPlaceholder = (CustomPlaceholder) placeholder;
            out.writeInt(customPlaceholder.getPosition());
            out.writeByte(customPlaceholder.getParsePlayer().getOrder());
            DataTypeIO.writeString(out, customPlaceholder.getKeyword().pattern(), StandardCharsets.UTF_8);
            out.writeBoolean(customPlaceholder.getParseKeyword());
            out.writeLong(customPlaceholder.getCooldown());
            CustomPlaceholderHoverEvent hover = customPlaceholder.getHover();
            out.writeBoolean(hover.isEnabled());
            DataTypeIO.writeString(out, hover.getText(), StandardCharsets.UTF_8);
            CustomPlaceholderClickEvent click = customPlaceholder.getClick();
            out.writeBoolean(click.isEnabled());
            DataTypeIO.writeString(out, click.getAction() == null ? "" : click.getAction().name(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(out, click.getValue(), StandardCharsets.UTF_8);
            CustomPlaceholderReplaceText replace = customPlaceholder.getReplace();
            out.writeBoolean(replace.isEnabled());
            DataTypeIO.writeString(out, replace.getReplaceText(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(out, placeholder.getName(), StandardCharsets.UTF_8);
            DataTypeIO.writeString(out, placeholder.getDescription(), StandardCharsets.UTF_8);
        }
    }
    return forwardData(time, 0x0C, out.toByteArray());
}
Also used : ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)

Aggregations

CustomPlaceholderClickEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent)9 CustomPlaceholderHoverEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent)9 CustomPlaceholderReplaceText (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)9 CustomPlaceholder (com.loohp.interactivechat.objectholders.CustomPlaceholder)8 ICPlaceholder (com.loohp.interactivechat.objectholders.ICPlaceholder)7 ClickEventAction (com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction)5 ParsePlayer (com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer)5 Pattern (java.util.regex.Pattern)5 Collectors (java.util.stream.Collectors)5 BuiltInPlaceholder (com.loohp.interactivechat.objectholders.BuiltInPlaceholder)4 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)3 ByteStreams (com.google.common.io.ByteStreams)3 InteractiveChat (com.loohp.interactivechat.InteractiveChat)3 ChatColorUtils (com.loohp.interactivechat.utils.ChatColorUtils)3 DataTypeIO (com.loohp.interactivechat.utils.DataTypeIO)3 List (java.util.List)3