Search in sources :

Example 16 with ICPlaceholder

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

the class InteractiveChatVelocity method handleChat.

private void handleChat(PlayerChatEvent event) {
    if (!event.getResult().isAllowed()) {
        return;
    }
    try {
        Field messageField = event.getClass().getDeclaredField("message");
        messageField.setAccessible(true);
        messageField.set(event, Registry.ID_PATTERN.matcher(event.getMessage()).replaceAll(""));
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
    Player player = event.getPlayer();
    UUID uuid = player.getUniqueId();
    String message = event.getMessage();
    if (!player.getCurrentServer().isPresent()) {
        return;
    }
    String newMessage = event.getMessage();
    boolean hasInteractiveChat = false;
    BackendInteractiveChatData data = serverInteractiveChatInfo.get(player.getCurrentServer().get().getServerInfo().getName());
    if (data != null) {
        hasInteractiveChat = data.hasInteractiveChat();
    }
    boolean usage = false;
    outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
        for (ICPlaceholder icplaceholder : serverPlaceholders) {
            if (icplaceholder.getKeyword().matcher(message).find()) {
                usage = true;
                break outer;
            }
        }
    }
    if (newMessage.startsWith("/")) {
        if (usage && hasInteractiveChat) {
            for (String parsecommand : InteractiveChatVelocity.parseCommands) {
                if (newMessage.matches(parsecommand)) {
                    String command = newMessage.trim();
                    outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
                        for (ICPlaceholder icplaceholder : serverPlaceholders) {
                            Pattern placeholder = icplaceholder.getKeyword();
                            Matcher matcher = placeholder.matcher(command);
                            if (matcher.find()) {
                                String uuidmatch = "<cmd=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(command.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
                                command = command.substring(0, matcher.start()) + uuidmatch + command.substring(matcher.end());
                                if (command.length() > 256) {
                                    command = command.substring(0, 256);
                                }
                                event.setResult(ChatResult.message(command));
                                break outer;
                            }
                        }
                    }
                    break;
                }
            }
        }
    } else {
        if (usage && InteractiveChatVelocity.useAccurateSenderFinder && hasInteractiveChat) {
            outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
                for (ICPlaceholder icplaceholder : serverPlaceholders) {
                    Pattern placeholder = icplaceholder.getKeyword();
                    Matcher matcher = placeholder.matcher(message);
                    if (matcher.find()) {
                        String uuidmatch = "<chat=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(message.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
                        message = message.substring(0, matcher.start()) + uuidmatch + message.substring(matcher.end());
                        if (message.length() > 256) {
                            message = message.substring(0, 256);
                        }
                        event.setResult(ChatResult.message(message));
                        break outer;
                    }
                }
            }
        }
        try {
            Field messageField = event.getClass().getDeclaredField("message");
            messageField.setAccessible(true);
            messageField.set(event, message);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        proxyServer.getScheduler().buildTask(plugin, () -> {
            Map<String, Long> messages = forwardedMessages.get(uuid);
            if (messages != null && messages.remove(newMessage) != null) {
                try {
                    PluginMessageSendingVelocity.sendMessagePair(uuid, newMessage);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).delay(100, TimeUnit.MILLISECONDS).schedule();
    }
}
Also used : Pattern(java.util.regex.Pattern) ConnectedPlayer(com.velocitypowered.proxy.connection.client.ConnectedPlayer) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) Player(com.velocitypowered.api.proxy.Player) Matcher(java.util.regex.Matcher) BackendInteractiveChatData(com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData) IOException(java.io.IOException) Field(java.lang.reflect.Field) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 17 with ICPlaceholder

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

the class PluginMessageSendingVelocity method forwardPlaceholderList.

@SuppressWarnings("deprecation")
public static void forwardPlaceholderList(List<ICPlaceholder> serverPlaceholderList, RegisteredServer serverFrom) throws IOException {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    DataTypeIO.writeString(output, serverFrom.getServerInfo().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 = InteractiveChatVelocity.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 (RegisteredServer server : getServer().getAllServers()) {
            if (!server.getServerInfo().getName().equals(serverFrom.getServerInfo().getName())) {
                server.sendPluginMessage(ICChannelIdentifier.INSTANCE, out.toByteArray());
                InteractiveChatVelocity.pluginMessagesCounter.incrementAndGet();
            }
        }
    }
}
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) RegisteredServer(com.velocitypowered.api.proxy.server.RegisteredServer) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)

Example 18 with ICPlaceholder

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

the class ProcessExternalMessage method processAndRespond0.

public String processAndRespond0(Player receiver, String json) throws Exception {
    Component component = InteractiveChatComponentSerializer.gson().deserialize(json);
    Component originalComponent = component;
    try {
        if (LegacyComponentSerializer.legacySection().serialize(component).isEmpty()) {
            return json;
        }
    } catch (Exception e) {
        return json;
    }
    if ((InteractiveChat.version.isOld()) && JsonUtils.containsKey(InteractiveChatComponentSerializer.gson().serialize(component), "translate")) {
        return json;
    }
    Optional<ICPlayer> sender = Optional.empty();
    String rawMessageKey = InteractiveChatComponentSerializer.plainText().serializeOr(component, "");
    InteractiveChat.keyTime.putIfAbsent(rawMessageKey, System.currentTimeMillis());
    Long timeKey = InteractiveChat.keyTime.get(rawMessageKey);
    long unix = timeKey == null ? System.currentTimeMillis() : timeKey;
    ProcessSenderResult commandSender = ProcessCommands.process(component);
    if (commandSender.getSender() != null) {
        sender = Optional.ofNullable(ICPlayerFactory.getICPlayer(commandSender.getSender()));
    }
    ProcessSenderResult chatSender = null;
    if (!sender.isPresent()) {
        if (InteractiveChat.useAccurateSenderFinder) {
            chatSender = ProcessAccurateSender.process(component);
            if (chatSender.getSender() != null) {
                sender = Optional.ofNullable(ICPlayerFactory.getICPlayer(chatSender.getSender()));
            }
        }
    }
    if (!sender.isPresent() && !InteractiveChat.useAccurateSenderFinder) {
        sender = SenderFinder.getSender(component, rawMessageKey);
    }
    component = commandSender.getComponent();
    if (chatSender != null) {
        component = chatSender.getComponent();
    }
    String text = LegacyComponentSerializer.legacySection().serialize(component);
    if (InteractiveChat.messageToIgnore.stream().anyMatch(each -> text.matches(each))) {
        return json;
    }
    if (sender.isPresent()) {
        InteractiveChat.keyPlayer.put(rawMessageKey, sender.get());
    }
    String server;
    if (sender.isPresent() && !sender.get().isLocal()) {
        try {
            TimeUnit.MILLISECONDS.sleep(InteractiveChat.remoteDelay);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        server = sender.get().getServer();
    } else {
        server = ICPlayer.LOCAL_SERVER_REPRESENTATION;
    }
    component = ComponentModernizing.modernize(component);
    component = ComponentReplacing.replace(component, Registry.ID_PATTERN.pattern(), Component.empty());
    if (InteractiveChat.usePlayerName) {
        component = PlayernameDisplay.process(component, sender, receiver, unix);
    }
    if (InteractiveChat.allowMention && sender.isPresent()) {
        PlayerData data = InteractiveChat.playerDataManager.getPlayerData(receiver);
        if (data == null || !data.isMentionDisabled()) {
            component = MentionDisplay.process(component, receiver, sender.get(), unix, !Bukkit.isPrimaryThread());
        }
    }
    component = ComponentReplacing.replace(component, Registry.MENTION_TAG_CONVERTER.getReversePattern().pattern(), true, (result, components) -> {
        return LegacyComponentSerializer.legacySection().deserialize(result.group(2));
    });
    Collection<ICPlaceholder> serverPlaceholderList = InteractiveChat.remotePlaceholderList.get(server);
    if (server.equals(ICPlayer.LOCAL_SERVER_REPRESENTATION) || serverPlaceholderList == null) {
        serverPlaceholderList = InteractiveChat.placeholderList.values();
    }
    component = CustomPlaceholderDisplay.process(component, sender, receiver, serverPlaceholderList, unix);
    if (InteractiveChat.useItem) {
        component = ItemDisplay.process(component, sender, receiver, unix);
    }
    if (InteractiveChat.useInventory) {
        component = InventoryDisplay.process(component, sender, receiver, unix);
    }
    if (InteractiveChat.useEnder) {
        component = EnderchestDisplay.process(component, sender, receiver, unix);
    }
    if (InteractiveChat.clickableCommands) {
        component = CommandsDisplay.process(component);
    }
    if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_16) && InteractiveChat.fontTags) {
        if (!sender.isPresent() || (sender.isPresent() && PlayerUtils.hasPermission(sender.get().getUniqueId(), "interactivechat.customfont.translate", true, 5))) {
            component = ComponentFont.parseFont(component);
        }
    }
    Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> {
        InteractiveChat.keyTime.remove(rawMessageKey);
        InteractiveChat.keyPlayer.remove(rawMessageKey);
    }, 5);
    String newJson = InteractiveChatComponentSerializer.gson().serialize(component);
    if (InteractiveChat.sendOriginalIfTooLong && newJson.length() > InteractiveChat.packetStringMaxLength) {
        String originalJson = InteractiveChatComponentSerializer.gson().serialize(originalComponent);
        if (originalJson.length() > InteractiveChat.packetStringMaxLength) {
            return "{\"text\":\"\"}";
        } else {
            return originalJson;
        }
    }
    return newJson;
}
Also used : Plugin(org.bukkit.plugin.Plugin) ComponentReplacing(com.loohp.interactivechat.utils.ComponentReplacing) MCVersion(com.loohp.interactivechat.utils.MCVersion) PlayerUtils(com.loohp.interactivechat.utils.PlayerUtils) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) InteractiveChatAPI(com.loohp.interactivechat.api.InteractiveChatAPI) PlayerData(com.loohp.interactivechat.data.PlayerDataManager.PlayerData) WebData(com.loohp.interactivechat.objectholders.WebData) Registry(com.loohp.interactivechat.registry.Registry) JsonUtils(com.loohp.interactivechat.utils.JsonUtils) Player(org.bukkit.entity.Player) ComponentModernizing(com.loohp.interactivechat.utils.ComponentModernizing) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) ComponentFont(com.loohp.interactivechat.utils.ComponentFont) InteractiveChatComponentSerializer(com.loohp.interactivechat.utils.InteractiveChatComponentSerializer) Matcher(java.util.regex.Matcher) Component(net.kyori.adventure.text.Component) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Method(java.lang.reflect.Method) ItemStackUtils(com.loohp.interactivechat.utils.ItemStackUtils) Material(org.bukkit.Material) ChatColor(net.md_5.bungee.api.ChatColor) Bukkit(org.bukkit.Bukkit) Collection(java.util.Collection) RarityUtils(com.loohp.interactivechat.utils.RarityUtils) UUID(java.util.UUID) Field(java.lang.reflect.Field) ItemStack(org.bukkit.inventory.ItemStack) InteractiveChat(com.loohp.interactivechat.InteractiveChat) TimeUnit(java.util.concurrent.TimeUnit) ICPlayerFactory(com.loohp.interactivechat.objectholders.ICPlayerFactory) ChatColorUtils(com.loohp.interactivechat.utils.ChatColorUtils) CustomStringUtils(com.loohp.interactivechat.utils.CustomStringUtils) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) PlaceholderParser(com.loohp.interactivechat.utils.PlaceholderParser) ProcessSenderResult(com.loohp.interactivechat.objectholders.ProcessSenderResult) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) ProcessSenderResult(com.loohp.interactivechat.objectholders.ProcessSenderResult) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) Component(net.kyori.adventure.text.Component) PlayerData(com.loohp.interactivechat.data.PlayerDataManager.PlayerData)

Example 19 with ICPlaceholder

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

the class InteractiveChatBungee method handleChat.

private void handleChat(ChatEvent event) {
    if (event.isCancelled()) {
        return;
    }
    event.setMessage(Registry.ID_PATTERN.matcher(event.getMessage()).replaceAll(""));
    ProxiedPlayer player = (ProxiedPlayer) event.getSender();
    UUID uuid = player.getUniqueId();
    String message = event.getMessage();
    String newMessage = event.getMessage();
    boolean hasInteractiveChat = false;
    Server server = player.getServer();
    if (server != null) {
        BackendInteractiveChatData data = serverInteractiveChatInfo.get(server.getInfo().getName());
        if (data != null) {
            hasInteractiveChat = data.hasInteractiveChat();
        }
    }
    boolean usage = false;
    outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
        for (ICPlaceholder icplaceholder : serverPlaceholders) {
            Matcher matcher = icplaceholder.getKeyword().matcher(message);
            if (matcher.find()) {
                int start = matcher.start();
                if ((start < 1 || message.charAt(start - 1) != '\\') || (start > 1 && message.charAt(start - 1) == '\\' && message.charAt(start - 2) == '\\')) {
                    usage = true;
                    break outer;
                }
            }
        }
    }
    if (newMessage.startsWith("/")) {
        if (usage && hasInteractiveChat) {
            for (String parsecommand : InteractiveChatBungee.parseCommands) {
                if (newMessage.matches(parsecommand)) {
                    String command = newMessage.trim();
                    if (tagEveryIdentifiableMessage) {
                        String uuidmatch = " <cmd=" + uuid + ">";
                        if (command.length() > 256 - uuidmatch.length()) {
                            command = command.substring(0, 256 - uuidmatch.length());
                        }
                        command = command + uuidmatch;
                        event.setMessage(command);
                    } else {
                        outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
                            for (ICPlaceholder icplaceholder : serverPlaceholders) {
                                Pattern placeholder = icplaceholder.getKeyword();
                                Matcher matcher = placeholder.matcher(command);
                                if (matcher.find()) {
                                    int start = matcher.start();
                                    if ((start < 1 || command.charAt(start - 1) != '\\') || (start > 1 && command.charAt(start - 1) == '\\' && command.charAt(start - 2) == '\\')) {
                                        String uuidmatch = "<cmd=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(command.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
                                        command = command.substring(0, matcher.start()) + uuidmatch + command.substring(matcher.end());
                                        if (command.length() > 256) {
                                            command = command.substring(0, 256);
                                        }
                                        event.setMessage(command);
                                        break outer;
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }
    } else {
        if (usage && useAccurateSenderFinder && hasInteractiveChat) {
            if (tagEveryIdentifiableMessage) {
                String uuidmatch = " <cmd=" + uuid + ">";
                if (message.length() > 256 - uuidmatch.length()) {
                    message = message.substring(0, 256 - uuidmatch.length());
                }
                message = message + uuidmatch;
                event.setMessage(message);
            } else {
                outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
                    for (ICPlaceholder icplaceholder : serverPlaceholders) {
                        Pattern placeholder = icplaceholder.getKeyword();
                        Matcher matcher = placeholder.matcher(message);
                        if (matcher.find()) {
                            int start = matcher.start();
                            if ((start < 1 || message.charAt(start - 1) != '\\') || (start > 1 && message.charAt(start - 1) == '\\' && message.charAt(start - 2) == '\\')) {
                                String uuidmatch = "<chat=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(message.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
                                message = message.substring(0, matcher.start()) + uuidmatch + message.substring(matcher.end());
                                if (message.length() > 256) {
                                    message = message.substring(0, 256);
                                }
                                event.setMessage(message);
                                break outer;
                            }
                        }
                    }
                }
            }
        }
        ProxyServer.getInstance().getScheduler().schedule(plugin, () -> {
            Map<String, Long> messages = forwardedMessages.get(uuid);
            if (messages != null && messages.remove(newMessage) != null) {
                try {
                    PluginMessageSendingBungee.sendMessagePair(uuid, newMessage);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }, 100, TimeUnit.MILLISECONDS);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Pattern(java.util.regex.Pattern) Server(net.md_5.bungee.api.connection.Server) ProxyServer(net.md_5.bungee.api.ProxyServer) Matcher(java.util.regex.Matcher) BackendInteractiveChatData(com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData) IOException(java.io.IOException) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 20 with ICPlaceholder

use of com.loohp.interactivechat.objectholders.ICPlaceholder 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)

Aggregations

ICPlaceholder (com.loohp.interactivechat.objectholders.ICPlaceholder)26 UUID (java.util.UUID)15 Pattern (java.util.regex.Pattern)13 IOException (java.io.IOException)12 Matcher (java.util.regex.Matcher)12 CustomPlaceholder (com.loohp.interactivechat.objectholders.CustomPlaceholder)11 ArrayList (java.util.ArrayList)11 List (java.util.List)10 ICPlayer (com.loohp.interactivechat.objectholders.ICPlayer)9 ParsePlayer (com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer)8 Component (net.kyori.adventure.text.Component)8 Player (org.bukkit.entity.Player)8 InteractiveChat (com.loohp.interactivechat.InteractiveChat)7 ItemStack (org.bukkit.inventory.ItemStack)7 CustomPlaceholderClickEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent)6 CustomPlaceholderHoverEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent)6 CustomPlaceholderReplaceText (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)6 BackendInteractiveChatData (com.loohp.interactivechat.proxy.objectholders.BackendInteractiveChatData)6 ChatColorUtils (com.loohp.interactivechat.utils.ChatColorUtils)6 Field (java.lang.reflect.Field)6