Search in sources :

Example 11 with ICPlaceholder

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

the class Commands method onTabComplete.

@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
    List<String> tab = new LinkedList<>();
    if (!label.equalsIgnoreCase("interactivechat") && !label.equalsIgnoreCase("ic")) {
        return tab;
    }
    if (sender instanceof Player && args.length > 1 && (("chat".equalsIgnoreCase(args[0]) && sender.hasPermission("interactivechat.chat")) || ("parse".equalsIgnoreCase(args[0]) && sender.hasPermission("interactivechat.parse")))) {
        if (InteractiveChat.version.isLegacy()) {
            for (ICPlaceholder placeholder : InteractiveChat.placeholderList.values()) {
                if (sender.hasPermission(placeholder.getPermission()) || (!placeholder.isBuildIn() && !InteractiveChat.useCustomPlaceholderPermissions)) {
                    String text = placeholder.getName();
                    if (text.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
                        tab.add(text);
                    }
                }
            }
        } else {
            for (ICPlaceholder placeholder : InteractiveChat.placeholderList.values()) {
                if (sender.hasPermission(placeholder.getPermission()) || (!placeholder.isBuildIn() && !InteractiveChat.useCustomPlaceholderPermissions)) {
                    String text = placeholder.getName();
                    if (text.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) {
                        Component component = LegacyComponentSerializer.legacySection().deserialize(placeholder.getDescription());
                        String json = InteractiveChat.version.isLegacyRGB() ? InteractiveChatComponentSerializer.legacyGson().serialize(component) : InteractiveChatComponentSerializer.gson().serialize(component);
                        tab.add(text + "\0" + json);
                    }
                }
            }
        }
        return tab;
    }
    switch(args.length) {
        case 0:
            if (sender.hasPermission("interactivechat.reload")) {
                tab.add("reload");
            }
            if (sender.hasPermission("interactivechat.update")) {
                tab.add("update");
            }
            if (sender.hasPermission("interactivechat.mention.toggle")) {
                tab.add("mentiontoggle");
            }
            if (sender.hasPermission("interactivechat.list")) {
                tab.add("list");
            }
            if (sender.hasPermission("interactivechat.parse")) {
                tab.add("parse");
            }
            if (sender.hasPermission("interactivechat.module.inventory.setlayout")) {
                tab.add("setinvdisplaylayout");
            }
            if (sender.hasPermission("interactivechat.chat")) {
                tab.add("chat");
            }
            return tab;
        case 1:
            if (sender.hasPermission("interactivechat.reload")) {
                if ("reload".startsWith(args[0].toLowerCase())) {
                    tab.add("reload");
                }
            }
            if (sender.hasPermission("interactivechat.update")) {
                if ("update".startsWith(args[0].toLowerCase())) {
                    tab.add("update");
                }
            }
            if (sender.hasPermission("interactivechat.mention.toggle")) {
                if ("mentiontoggle".startsWith(args[0].toLowerCase())) {
                    tab.add("mentiontoggle");
                }
            }
            if (sender.hasPermission("interactivechat.list")) {
                if ("list".startsWith(args[0].toLowerCase())) {
                    tab.add("list");
                }
            }
            if (sender.hasPermission("interactivechat.parse")) {
                if ("parse".startsWith(args[0].toLowerCase())) {
                    tab.add("parse");
                }
            }
            if (sender.hasPermission("interactivechat.module.inventory.setlayout")) {
                if ("setinvdisplaylayout".startsWith(args[0].toLowerCase())) {
                    tab.add("setinvdisplaylayout");
                }
            }
            if (sender.hasPermission("interactivechat.chat")) {
                if ("chat".startsWith(args[0].toLowerCase())) {
                    tab.add("chat");
                }
            }
            return tab;
        case 2:
            if (sender.hasPermission("interactivechat.mention.toggle.others")) {
                if ("mentiontoggle".equalsIgnoreCase(args[0])) {
                    for (Player player : Bukkit.getOnlinePlayers()) {
                        if (player.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
                            tab.add(player.getName());
                        }
                    }
                }
            }
            if (sender.hasPermission("interactivechat.module.inventory.setlayout")) {
                if ("setinvdisplaylayout".equalsIgnoreCase(args[0])) {
                    for (Integer layout : InventoryDisplay.LAYOUTS) {
                        tab.add(layout.toString());
                    }
                }
            }
            return tab;
        case 3:
            if (sender.hasPermission("interactivechat.module.inventory.setlayout.others")) {
                if ("setinvdisplaylayout".equalsIgnoreCase(args[0])) {
                    for (Player player : Bukkit.getOnlinePlayers()) {
                        if (player.getName().toLowerCase().startsWith(args[2].toLowerCase())) {
                            tab.add(player.getName());
                        }
                    }
                }
            }
            return tab;
        default:
            return tab;
    }
}
Also used : Player(org.bukkit.entity.Player) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) Component(net.kyori.adventure.text.Component) LinkedList(java.util.LinkedList)

Example 12 with ICPlaceholder

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

the class ChatEvents method checkChatMessage.

private void checkChatMessage(AsyncPlayerChatEvent event) {
    String message = event.getMessage();
    Player player = event.getPlayer();
    CooldownResult cooldownResult = InteractiveChat.placeholderCooldownManager.checkMessage(event.getPlayer().getUniqueId(), message);
    if (!cooldownResult.getOutcome().isAllowed()) {
        event.setCancelled(true);
        Component cancelmessage;
        switch(cooldownResult.getOutcome()) {
            case DENY_PLACEHOLDER:
                cancelmessage = LegacyComponentSerializer.legacySection().deserialize(ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.placeholderCooldownMessage.replace("{Time}", TimeUtils.getReadableTimeBetween(System.currentTimeMillis(), cooldownResult.getCooldownExpireTime())))));
                cancelmessage = ComponentReplacing.replace(cancelmessage, "\\{Keyword\\}", Component.text(cooldownResult.getPlaceholder().getName()).hoverEvent(HoverEvent.showText(LegacyComponentSerializer.legacySection().deserialize(cooldownResult.getPlaceholder().getDescription()))));
                break;
            case DENY_UNIVERSAL:
                cancelmessage = LegacyComponentSerializer.legacySection().deserialize(ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.universalCooldownMessage.replace("{Time}", TimeUtils.getReadableTimeBetween(System.currentTimeMillis(), cooldownResult.getCooldownExpireTime())))));
                break;
            default:
                cancelmessage = Component.empty();
                break;
        }
        InteractiveChatAPI.sendMessageUnprocessed(player, cancelmessage);
        return;
    }
    int count = 0;
    for (ICPlaceholder icplaceholder : InteractiveChat.placeholderList.values()) {
        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) == '\\')) {
                if (icplaceholder.getKeyword().equals(InteractiveChat.itemPlaceholder) && !InteractiveChat.itemAirAllow && PlayerUtils.getHeldItem(event.getPlayer()).getType().equals(Material.AIR) && PlayerUtils.hasPermission(event.getPlayer().getUniqueId(), "interactivechat.module.item", false, 200)) {
                    event.setCancelled(true);
                    String cancelmessage = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.itemAirErrorMessage));
                    event.getPlayer().sendMessage(cancelmessage);
                    return;
                }
                Matcher matcher1 = icplaceholder.getKeyword().matcher(message);
                while (matcher1.find()) {
                    int startPos = matcher1.start();
                    if ((startPos < 1 || message.charAt(startPos - 1) != '\\') || (startPos > 1 && message.charAt(startPos - 1) == '\\' && message.charAt(startPos - 2) == '\\')) {
                        count++;
                    }
                }
            }
        }
    }
    if (InteractiveChat.maxPlaceholders >= 0 && count > InteractiveChat.maxPlaceholders) {
        event.setCancelled(true);
        String cancelmessage = ChatColorUtils.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(event.getPlayer(), InteractiveChat.limitReachMessage));
        event.getPlayer().sendMessage(cancelmessage);
        return;
    } else {
        if (InteractiveChat.tagEveryIdentifiableMessage) {
            String uuidmatch = " <chat=" + event.getPlayer().getUniqueId() + ">";
            message = message + uuidmatch;
        } else if (count > 0) {
            if (InteractiveChat.useAccurateSenderFinder && !message.startsWith("/") && !Registry.ID_PATTERN.matcher(message).find()) {
                for (ICPlaceholder icplaceholder : InteractiveChat.placeholderList.values()) {
                    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=" + event.getPlayer().getUniqueId() + ":" + Registry.ID_ESCAPE_PATTERN.matcher(message.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
                            message = message.substring(0, matcher.start()) + uuidmatch + message.substring(matcher.end());
                            break;
                        }
                    }
                }
            }
        }
    }
    event.setMessage(message);
    String mapKey = ChatColorUtils.stripColor(ChatColorUtils.translateAlternateColorCodes('&', event.getMessage()));
    InteractiveChat.messages.put(mapKey, player.getUniqueId());
    Bukkit.getScheduler().runTaskLater(InteractiveChat.plugin, () -> InteractiveChat.messages.remove(mapKey), 60);
    if (InteractiveChat.bungeecordMode) {
        try {
            BungeeMessageSender.addMessage(System.currentTimeMillis(), ChatColorUtils.stripColor(ChatColorUtils.translateAlternateColorCodes('&', event.getMessage())), event.getPlayer().getUniqueId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Player(org.bukkit.entity.Player) ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) Matcher(java.util.regex.Matcher) Component(net.kyori.adventure.text.Component) CooldownResult(com.loohp.interactivechat.objectholders.CooldownResult)

Example 13 with ICPlaceholder

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

the class ConfigManager method loadConfig.

@SuppressWarnings("deprecation")
public static void loadConfig() {
    InteractiveChat.commandsEventPriority = EventPriority.valueOf(getConfig().getString("Settings.EventPriorities.Commands").toUpperCase());
    InteractiveChat.chatEventPriority = EventPriority.valueOf(getConfig().getString("Settings.EventPriorities.Chat").toUpperCase());
    InteractiveChat.itemTagMaxLength = getConfig().getInt("Settings.ItemTagMaxLength");
    InteractiveChat.packetStringMaxLength = getConfig().getInt("Settings.PacketStringMaxLength");
    InteractiveChat.parsePAPIOnMainThread = getConfig().getBoolean("Settings.ParsePAPIOnMainThread");
    InteractiveChat.useAccurateSenderFinder = getConfig().getBoolean("Settings.UseAccurateSenderParser");
    InteractiveChat.tagEveryIdentifiableMessage = getConfig().getBoolean("Settings.TagEveryIdentifiableMessage");
    String colorCodeString = getConfig().getString("Chat.TranslateAltColorCode");
    InteractiveChat.chatAltColorCode = colorCodeString.length() == 1 ? Optional.of(colorCodeString.charAt(0)) : Optional.empty();
    InteractiveChat.useCustomPlaceholderPermissions = getConfig().getBoolean("Settings.UseCustomPlaceholderPermissions");
    InteractiveChat.filterUselessColorCodes = getConfig().getBoolean("Settings.FilterUselessColorCodes", true);
    InteractiveChat.allowMention = getConfig().getBoolean("Chat.AllowMention");
    InteractiveChat.disableHere = getConfig().getBoolean("Chat.DisableHere");
    InteractiveChat.disableEveryone = getConfig().getBoolean("Chat.DisableEveryone");
    InteractiveChat.universalCooldown = getConfig().getLong("Settings.UniversalCooldown") * 1000;
    InteractiveChat.noPermissionMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.NoPermission"));
    InteractiveChat.invExpiredMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.InvExpired"));
    InteractiveChat.reloadPluginMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.ReloadPlugin"));
    InteractiveChat.noConsoleMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.PlayerOnlyCommand"));
    InteractiveChat.invalidPlayerMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.InvalidPlayer"));
    InteractiveChat.listPlaceholderHeader = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.ListPlaceholdersHeader"));
    InteractiveChat.listPlaceholderBody = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.ListPlaceholdersBody"));
    InteractiveChat.notEnoughArgs = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.NoEnoughArgs"));
    InteractiveChat.invalidArgs = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.InvalidArgs"));
    InteractiveChat.setInvDisplayLayout = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.SetInventoryDisplayLayout"));
    InteractiveChat.placeholderCooldownMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.PlaceholderCooldown"));
    InteractiveChat.universalCooldownMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.UniversalCooldown"));
    InteractiveChat.useItem = getConfig().getBoolean("ItemDisplay.Item.Enabled");
    InteractiveChat.useInventory = getConfig().getBoolean("ItemDisplay.Inventory.Enabled");
    InteractiveChat.useEnder = getConfig().getBoolean("ItemDisplay.EnderChest.Enabled");
    InteractiveChat.itemMapPreview = getConfig().getBoolean("ItemDisplay.Item.PreviewMaps");
    InteractiveChat.itemPlaceholder = Pattern.compile(getConfig().getString("ItemDisplay.Item.Keyword"));
    InteractiveChat.invPlaceholder = Pattern.compile(getConfig().getString("ItemDisplay.Inventory.Keyword"));
    InteractiveChat.enderPlaceholder = Pattern.compile(getConfig().getString("ItemDisplay.EnderChest.Keyword"));
    InteractiveChat.itemReplaceText = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.Text"));
    InteractiveChat.itemSingularReplaceText = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.SingularText"));
    InteractiveChat.invReplaceText = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Inventory.Text"));
    InteractiveChat.enderReplaceText = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.EnderChest.Text"));
    InteractiveChat.itemAirAllow = getConfig().getBoolean("ItemDisplay.Item.EmptyItemSettings.AllowAir");
    InteractiveChat.itemAirErrorMessage = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.EmptyItemSettings.DisallowMessage"));
    InteractiveChat.itemTitle = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.InventoryTitle"));
    InteractiveChat.invTitle = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Inventory.InventoryTitle"));
    InteractiveChat.enderTitle = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.EnderChest.InventoryTitle"));
    InteractiveChat.itemHover = getConfig().getBoolean("ItemDisplay.Item.HoverEnabled");
    InteractiveChat.itemAlternativeHoverMessage = ChatColorUtils.translateAlternateColorCodes('&', String.join("\n", getConfig().getStringList("ItemDisplay.Item.AlternativeHoverMessage")));
    InteractiveChat.itemGUI = getConfig().getBoolean("ItemDisplay.Item.GUIEnabled");
    InteractiveChat.translateHoverableItems = getConfig().getBoolean("ItemDisplay.Item.HoverableItemsTranslation.Enabled");
    InteractiveChat.hoverableItemTitle = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.HoverableItemsTranslation.InventoryTitle"));
    InteractiveChat.containerViewTitle = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Settings.ContainerViewTitle"));
    try {
        try {
            if (VERSION.isLegacy()) {
                String str = getConfig().getString("ItemDisplay.Item.Frame.Primary");
                Material material = str.contains(":") ? Material.valueOf(str.substring(0, str.lastIndexOf(":"))) : Material.valueOf(str);
                short data = str.contains(":") ? Short.valueOf(str.substring(str.lastIndexOf(":") + 1)) : 0;
                InteractiveChat.itemFrame1 = new ItemStack(material, 1, data);
            } else {
                InteractiveChat.itemFrame1 = new ItemStack(Material.valueOf(getConfig().getString("ItemDisplay.Item.Frame.Primary")), 1);
            }
        } catch (Exception e) {
            InteractiveChat.itemFrame1 = XMaterialUtils.matchXMaterial(getConfig().getString("ItemDisplay.Item.Frame.Primary")).parseItem();
            InteractiveChat.itemFrame1.setAmount(1);
        }
    } catch (Exception e) {
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You have an invalid material name in the config! Please take a look at the Q&A section on the resource page! (ItemDisplay.Item.Frame.Primary)");
        e.printStackTrace();
    }
    try {
        try {
            if (VERSION.isLegacy()) {
                String str = getConfig().getString("ItemDisplay.Item.Frame.Secondary");
                Material material = str.contains(":") ? Material.valueOf(str.substring(0, str.lastIndexOf(":"))) : Material.valueOf(str);
                short data = str.contains(":") ? Short.valueOf(str.substring(str.lastIndexOf(":") + 1)) : 0;
                InteractiveChat.itemFrame2 = new ItemStack(material, 1, data);
            } else {
                InteractiveChat.itemFrame2 = new ItemStack(Material.valueOf(getConfig().getString("ItemDisplay.Item.Frame.Secondary")), 1);
            }
        } catch (Exception e) {
            InteractiveChat.itemFrame2 = XMaterialUtils.matchXMaterial(getConfig().getString("ItemDisplay.Item.Frame.Secondary")).parseItem();
            InteractiveChat.itemFrame2.setAmount(1);
        }
    } catch (Exception e) {
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You have an invalid material name in the config! Please take a look at the Q&A section on the resource page! (ItemDisplay.Item.Frame.Secondary)");
        e.printStackTrace();
    }
    try {
        try {
            if (VERSION.isLegacy()) {
                String str = getConfig().getString("ItemDisplay.Inventory.Frame.Primary");
                Material material = str.contains(":") ? Material.valueOf(str.substring(0, str.lastIndexOf(":"))) : Material.valueOf(str);
                short data = str.contains(":") ? Short.valueOf(str.substring(str.lastIndexOf(":") + 1)) : 0;
                InteractiveChat.invFrame1 = new ItemStack(material, 1, data);
            } else {
                InteractiveChat.invFrame1 = new ItemStack(Material.valueOf(getConfig().getString("ItemDisplay.Inventory.Frame.Primary")), 1);
            }
        } catch (Exception e) {
            InteractiveChat.invFrame1 = XMaterialUtils.matchXMaterial(getConfig().getString("ItemDisplay.Inventory.Frame.Primary")).parseItem();
            InteractiveChat.invFrame1.setAmount(1);
        }
    } catch (Exception e) {
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You have an invalid material name in the config! Please take a look at the Q&A section on the resource page! (ItemDisplay.Inventory.Frame.Primary)");
        e.printStackTrace();
    }
    try {
        try {
            if (VERSION.isLegacy()) {
                String str = getConfig().getString("ItemDisplay.Inventory.Frame.Secondary");
                Material material = str.contains(":") ? Material.valueOf(str.substring(0, str.lastIndexOf(":"))) : Material.valueOf(str);
                short data = str.contains(":") ? Short.valueOf(str.substring(str.lastIndexOf(":") + 1)) : 0;
                InteractiveChat.invFrame2 = new ItemStack(material, 1, data);
            } else {
                InteractiveChat.invFrame2 = new ItemStack(Material.valueOf(getConfig().getString("ItemDisplay.Inventory.Frame.Secondary")), 1);
            }
        } catch (Exception e) {
            InteractiveChat.invFrame2 = XMaterialUtils.matchXMaterial(getConfig().getString("ItemDisplay.Inventory.Frame.Secondary")).parseItem();
            InteractiveChat.invFrame2.setAmount(1);
        }
    } catch (Exception e) {
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You have an invalid material name in the config! Please take a look at the Q&A section on the resource page! (ItemDisplay.Inventory.Frame.Secondary)");
        e.printStackTrace();
    }
    InteractiveChat.invSkullName = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Inventory.SkullDisplayName"));
    InteractiveChat.invDisplayLayout = getConfig().getInt("ItemDisplay.Inventory.Layout");
    InteractiveChat.itemDisplayTimeout = getConfig().getLong("ItemDisplay.Settings.Timeout") * 60 * 1000;
    if (getConfig().contains("Secret.t")) {
        InteractiveChat.t = getConfig().getBoolean("Secret.t");
    }
    InteractiveChat.usePlayerName = getConfig().getBoolean("Player.UsePlayerNameInteraction");
    InteractiveChat.usePlayerNameOverrideHover = getConfig().getBoolean("Player.OverrideOriginal.HoverEvent");
    InteractiveChat.usePlayerNameOverrideClick = getConfig().getBoolean("Player.OverrideOriginal.ClickEvent");
    InteractiveChat.usePlayerNameHoverEnable = getConfig().getBoolean("Player.Hover.Enable");
    List<String> stringList = getConfig().getStringList("Player.Hover.Text");
    InteractiveChat.usePlayerNameHoverText = ChatColorUtils.translateAlternateColorCodes('&', String.join("\n", stringList));
    InteractiveChat.usePlayerNameClickEnable = getConfig().getBoolean("Player.Click.Enable");
    InteractiveChat.usePlayerNameClickAction = getConfig().getString("Player.Click.Action");
    InteractiveChat.usePlayerNameClickValue = getConfig().getString("Player.Click.Value");
    InteractiveChat.usePlayerNameCaseSensitive = getConfig().getBoolean("Player.CaseSensitive");
    InteractiveChat.useTooltipOnTab = getConfig().getBoolean("TabCompletion.PlayerNameToolTip.Enabled");
    InteractiveChat.tabTooltip = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("TabCompletion.PlayerNameToolTip.ToolTip"));
    InteractiveChat.playerNotFoundHoverEnable = getConfig().getBoolean("Settings.PlayerNotFound.Hover.Enable");
    List<String> stringList2 = getConfig().getStringList("Settings.PlayerNotFound.Hover.Text");
    InteractiveChat.playerNotFoundHoverText = ChatColorUtils.translateAlternateColorCodes('&', String.join("\n", stringList2));
    InteractiveChat.playerNotFoundClickEnable = getConfig().getBoolean("Settings.PlayerNotFound.Click.Enable");
    InteractiveChat.playerNotFoundClickAction = getConfig().getString("Settings.PlayerNotFound.Click.Action");
    InteractiveChat.playerNotFoundClickValue = getConfig().getString("Settings.PlayerNotFound.Click.Value");
    InteractiveChat.playerNotFoundReplaceEnable = getConfig().getBoolean("Settings.PlayerNotFound.Replace.Enable");
    InteractiveChat.playerNotFoundReplaceText = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Settings.PlayerNotFound.Replace.ReplaceText"));
    InteractiveChat.placeholderList.clear();
    if (InteractiveChat.useItem) {
        String name = InteractiveChat.itemName = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.Name"));
        String description = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Item.Description"));
        ICPlaceholder itemPlaceholder = new BuiltInPlaceholder(InteractiveChat.itemPlaceholder, name, description, "interactivechat.module.item", getConfig().getLong("ItemDisplay.Item.Cooldown") * 1000);
        InteractiveChat.placeholderList.put(itemPlaceholder.getInternalId(), itemPlaceholder);
    }
    if (InteractiveChat.useInventory) {
        String name = InteractiveChat.invName = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Inventory.Name"));
        String description = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.Inventory.Description"));
        ICPlaceholder invPlaceholder = new BuiltInPlaceholder(InteractiveChat.invPlaceholder, name, description, "interactivechat.module.inventory", getConfig().getLong("ItemDisplay.Inventory.Cooldown") * 1000);
        InteractiveChat.placeholderList.put(invPlaceholder.getInternalId(), invPlaceholder);
    }
    if (InteractiveChat.useEnder) {
        String name = InteractiveChat.enderName = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.EnderChest.Name"));
        String description = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("ItemDisplay.EnderChest.Description"));
        ICPlaceholder enderPlaceholder = new BuiltInPlaceholder(InteractiveChat.enderPlaceholder, name, description, "interactivechat.module.enderchest", getConfig().getLong("ItemDisplay.EnderChest.Cooldown") * 1000);
        InteractiveChat.placeholderList.put(enderPlaceholder.getInternalId(), enderPlaceholder);
    }
    for (int customNo = 1; ConfigManager.getConfig().contains("CustomPlaceholders." + customNo); customNo++) {
        ConfigurationSection s = getConfig().getConfigurationSection("CustomPlaceholders." + customNo);
        ParsePlayer parseplayer = ParsePlayer.fromString(s.getString("ParsePlayer"));
        String placeholder = s.getString("Keyword");
        boolean parseKeyword = s.getBoolean("ParseKeyword");
        long cooldown = s.getLong("Cooldown") * 1000;
        boolean hoverEnabled = s.getBoolean("Hover.Enable");
        String hoverText = ChatColorUtils.translateAlternateColorCodes('&', String.join("\n", s.getStringList("Hover.Text")));
        boolean clickEnabled = s.getBoolean("Click.Enable");
        String clickAction = s.getString("Click.Action").toUpperCase();
        String clickValue = s.getString("Click.Value");
        boolean replaceEnabled = s.getBoolean("Replace.Enable");
        String replaceText = ChatColorUtils.translateAlternateColorCodes('&', s.getString("Replace.ReplaceText"));
        String name = ChatColorUtils.translateAlternateColorCodes('&', s.getString("Name", placeholder.replace("\\", "")));
        String description = ChatColorUtils.translateAlternateColorCodes('&', s.getString("Description", "&7&oDescription missing"));
        ICPlaceholder customPlaceholder = 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.placeholderList.put(customPlaceholder.getInternalId(), customPlaceholder);
    }
    if (InteractiveChat.bungeecordMode) {
        InteractiveChat.queueRemoteUpdate = true;
    }
    InteractiveChat.commandList = getConfig().getStringList("Settings.CommandsToParse");
    InteractiveChat.maxPlaceholders = getConfig().getInt("Settings.MaxPlaceholders");
    InteractiveChat.limitReachMessage = getConfig().getString("Messages.LimitReached");
    InteractiveChat.mentionPrefix = getConfig().getString("Chat.MentionPrefix");
    InteractiveChat.mentionHighlight = getConfig().getString("Chat.MentionHighlight");
    List<String> stringList3 = getConfig().getStringList("Chat.MentionHoverText");
    InteractiveChat.mentionHover = String.join("\n", stringList3);
    InteractiveChat.mentionDuration = getConfig().getDouble("Chat.MentionedTitleDuration");
    InteractiveChat.mentionCooldown = (long) (getConfig().getDouble("Chat.MentionCooldown") * 1000);
    InteractiveChat.mentionEnable = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.EnableMentions"));
    InteractiveChat.mentionDisable = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Messages.DisableMentions"));
    InteractiveChat.mentionTitle = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Chat.MentionedTitle"));
    InteractiveChat.mentionSubtitle = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Chat.KnownPlayerMentionSubtitle"));
    InteractiveChat.mentionActionbar = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Chat.KnownPlayerMentionActionbar"));
    InteractiveChat.mentionToast = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Chat.MentionToast"));
    InteractiveChat.mentionBossBarText = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Chat.MentionBossBar.Text"));
    InteractiveChat.mentionBossBarColorName = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Chat.MentionBossBar.Color"));
    InteractiveChat.mentionBossBarOverlayName = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Chat.MentionBossBar.Overlay"));
    InteractiveChat.mentionSound = getConfig().getString("Chat.MentionedSound");
    InteractiveChat.mentionTitleDuration = (int) Math.round(ConfigManager.getConfig().getDouble("Chat.MentionedTitleDuration") * 20);
    InteractiveChat.mentionBossBarDuration = (int) Math.round(ConfigManager.getConfig().getDouble("Chat.MentionBossBar.Duration") * 20);
    InteractiveChat.mentionBossBarRemoveDelay = (int) Math.round(ConfigManager.getConfig().getDouble("Chat.MentionBossBar.RemoveDelay") * 20);
    InteractiveChat.updaterEnabled = getConfig().getBoolean("Options.Updater");
    InteractiveChat.cancelledMessage = getConfig().getBoolean("Options.ShowCancelledNotice");
    InteractiveChat.clickableCommands = getConfig().getBoolean("Commands.Enabled");
    InteractiveChat.clickableCommandsFormat = getConfig().getString("Commands.Format");
    InteractiveChat.clickableCommandsAction = ClickEvent.Action.valueOf(getConfig().getString("Commands.Action"));
    InteractiveChat.clickableCommandsDisplay = ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Commands.Text"));
    InteractiveChat.clickableCommandsHoverText = ChatColorUtils.translateAlternateColorCodes('&', String.join("\n", getConfig().getStringList("Commands.HoverMessage")));
    InteractiveChat.sendOriginalIfTooLong = getConfig().getBoolean("Settings.SendOriginalMessageIfExceedLengthLimit");
    InteractiveChat.messageToIgnore = new HashSet<>(getConfig().getStringList("Settings.MessagesToIgnore"));
    try {
        try {
            if (VERSION.isLegacy()) {
                String str = getConfig().getString("ItemDisplay.Item.Frame.Secondary");
                Material material = str.contains(":") ? Material.valueOf(str.substring(0, str.lastIndexOf(":"))) : Material.valueOf(str);
                short data = str.contains(":") ? Short.valueOf(str.substring(str.lastIndexOf(":") + 1)) : 0;
                ItemStack unknown = new ItemStack(material, 1, data);
                ItemMeta meta = unknown.getItemMeta();
                meta.setDisplayName(ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Settings.BungeecordUnknownItem.DisplayName")));
                meta.setLore(getConfig().getStringList("Settings.BungeecordUnknownItem.Lore").stream().map(each -> ChatColorUtils.translateAlternateColorCodes('&', each)).collect(Collectors.toList()));
                unknown.setItemMeta(meta);
                InteractiveChat.unknownReplaceItem = unknown;
            } else {
                ItemStack unknown = new ItemStack(Material.valueOf(getConfig().getString("Settings.BungeecordUnknownItem.ReplaceItem").toUpperCase()));
                ItemMeta meta = unknown.getItemMeta();
                meta.setDisplayName(ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Settings.BungeecordUnknownItem.DisplayName")));
                meta.setLore(getConfig().getStringList("Settings.BungeecordUnknownItem.Lore").stream().map(each -> ChatColorUtils.translateAlternateColorCodes('&', each)).collect(Collectors.toList()));
                unknown.setItemMeta(meta);
                InteractiveChat.unknownReplaceItem = unknown;
            }
        } catch (Exception e) {
            ItemStack unknown = XMaterialUtils.matchXMaterial(getConfig().getString("Settings.BungeecordUnknownItem.ReplaceItem")).parseItem();
            unknown.setAmount(1);
            ItemMeta meta = unknown.getItemMeta();
            meta.setDisplayName(ChatColorUtils.translateAlternateColorCodes('&', getConfig().getString("Settings.BungeecordUnknownItem.DisplayName")));
            meta.setLore(getConfig().getStringList("Settings.BungeecordUnknownItem.Lore").stream().map(each -> ChatColorUtils.translateAlternateColorCodes('&', each)).collect(Collectors.toList()));
            unknown.setItemMeta(meta);
            InteractiveChat.unknownReplaceItem = unknown;
        }
    } catch (Exception e) {
        Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "You have an invalid material name in the config! Please take a look at the Q&A section on the resource page! (Settings.BungeecordUnknownItem.ReplaceItem)");
        e.printStackTrace();
    }
    InteractiveChat.useBukkitDisplayName = getConfig().getBoolean("Chat.UseBukkitDisplayName");
    InteractiveChat.useEssentialsNicknames = getConfig().getBoolean("Chat.UseEssentialsNicknames");
    InteractiveChat.rgbTags = getConfig().getBoolean("Settings.FormattingTags.AllowRGBTags");
    InteractiveChat.fontTags = getConfig().getBoolean("Settings.FormattingTags.AllowFontTags");
    InteractiveChat.additionalRGBFormats = getConfig().getStringList("Settings.FormattingTags.AdditionalRGBFormats").stream().map(each -> Pattern.compile(each)).collect(Collectors.toList());
    InteractiveChat.language = getConfig().getString("Settings.Language");
    Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
        LanguageUtils.loadTranslations(InteractiveChat.language);
        if (WebData.getInstance() == null) {
            WebData.newInstance();
        } else {
            WebData.getInstance().reload();
        }
    });
    InteractiveChat.itemDisplay.clearAndSetTimeout(InteractiveChat.itemDisplayTimeout);
    InteractiveChat.inventoryDisplay.clearAndSetTimeout(InteractiveChat.itemDisplayTimeout);
    InteractiveChat.inventoryDisplay1Upper.clearAndSetTimeout(InteractiveChat.itemDisplayTimeout);
    InteractiveChat.inventoryDisplay1Lower.clearAndSetTimeout(InteractiveChat.itemDisplayTimeout);
    InteractiveChat.enderDisplay.clearAndSetTimeout(InteractiveChat.itemDisplayTimeout);
    InteractiveChat.mapDisplay.clearAndSetTimeout(InteractiveChat.itemDisplayTimeout);
    InteractiveChat.upperSharedInventory.clear();
    InteractiveChat.lowerSharedInventory.clear();
}
Also used : MCVersion(com.loohp.interactivechat.utils.MCVersion) ItemMeta(org.bukkit.inventory.meta.ItemMeta) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) WebData(com.loohp.interactivechat.objectholders.WebData) ConfigDataFixer(com.loohp.interactivechat.datafixer.ConfigDataFixer) ConfigurationSection(com.loohp.yamlconfiguration.ConfigurationSection) BuiltInPlaceholder(com.loohp.interactivechat.objectholders.BuiltInPlaceholder) ClickEvent(net.kyori.adventure.text.event.ClickEvent) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) HashSet(java.util.HashSet) LanguageUtils(com.loohp.interactivechat.utils.LanguageUtils) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) Material(org.bukkit.Material) ChatColor(net.md_5.bungee.api.ChatColor) Bukkit(org.bukkit.Bukkit) YamlConfiguration(com.loohp.yamlconfiguration.YamlConfiguration) XMaterialUtils(com.loohp.interactivechat.utils.XMaterialUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) ItemStack(org.bukkit.inventory.ItemStack) InteractiveChat(com.loohp.interactivechat.InteractiveChat) List(java.util.List) ClickEventAction(com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction) EventPriority(org.bukkit.event.EventPriority) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) ChatColorUtils(com.loohp.interactivechat.utils.ChatColorUtils) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) Material(org.bukkit.Material) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) IOException(java.io.IOException) 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) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ConfigurationSection(com.loohp.yamlconfiguration.ConfigurationSection)

Example 14 with ICPlaceholder

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

the class CustomPlaceholderDisplay method process.

public static Component process(Component component, Optional<ICPlayer> optplayer, Player reciever, Collection<ICPlaceholder> placeholderList, long unix) {
    for (ICPlaceholder icplaceholder : placeholderList) {
        if (icplaceholder.isBuildIn()) {
            continue;
        }
        CustomPlaceholder cp = (CustomPlaceholder) icplaceholder;
        ICPlayer parseplayer = (cp.getParsePlayer().equals(ParsePlayer.SENDER) && optplayer.isPresent()) ? optplayer.get() : ICPlayerFactory.getICPlayer(reciever);
        if (InteractiveChat.useCustomPlaceholderPermissions && optplayer.isPresent()) {
            ICPlayer sender = optplayer.get();
            if (!PlayerUtils.hasPermission(sender.getUniqueId(), cp.getPermission(), true, 5)) {
                continue;
            }
        }
        String placeholder = cp.getKeyword().pattern();
        placeholder = (cp.getParseKeyword()) ? PlaceholderParser.parse(parseplayer, placeholder) : placeholder;
        long cooldown = cp.getCooldown();
        boolean hoverEnabled = cp.getHover().isEnabled();
        String hoverText = cp.getHover().getText();
        boolean clickEnabled = cp.getClick().isEnabled();
        ClickEventAction clickAction = cp.getClick().getAction();
        String clickValue = cp.getClick().getValue();
        boolean replaceEnabled = cp.getReplace().isEnabled();
        String replaceText = cp.getReplace().getReplaceText();
        component = processCustomPlaceholder(parseplayer, Pattern.compile(placeholder), cooldown, hoverEnabled, hoverText, clickEnabled, clickAction, clickValue, replaceEnabled, replaceText, component, optplayer, unix);
    }
    if (InteractiveChat.t && WebData.getInstance() != null) {
        for (CustomPlaceholder cp : WebData.getInstance().getSpecialPlaceholders()) {
            ICPlayer parseplayer = (cp.getParsePlayer().equals(ParsePlayer.SENDER) && optplayer.isPresent()) ? optplayer.get() : ICPlayerFactory.getICPlayer(reciever);
            String placeholder = cp.getKeyword().pattern();
            placeholder = (cp.getParseKeyword()) ? PlaceholderParser.parse(parseplayer, placeholder) : placeholder;
            long cooldown = cp.getCooldown();
            boolean hoverEnabled = cp.getHover().isEnabled();
            String hoverText = cp.getHover().getText();
            boolean clickEnabled = cp.getClick().isEnabled();
            ClickEventAction clickAction = cp.getClick().getAction();
            String clickValue = cp.getClick().getValue();
            boolean replaceEnabled = cp.getReplace().isEnabled();
            String replaceText = cp.getReplace().getReplaceText();
            component = processCustomPlaceholder(parseplayer, Pattern.compile(placeholder), cooldown, hoverEnabled, hoverText, clickEnabled, clickAction, clickValue, replaceEnabled, replaceText, component, optplayer, unix);
        }
    }
    return component;
}
Also used : ICPlayer(com.loohp.interactivechat.objectholders.ICPlayer) ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) ClickEventAction(com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction)

Example 15 with ICPlaceholder

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

the class ProxyPlayerCooldownManager method reloadPlaceholders.

public void reloadPlaceholders(Collection<ICPlaceholder> placeholders) {
    List<ICPlaceholder> placeholderList = new ArrayList<>(placeholders);
    Iterator<UUID> itr = placeholderTimestamps.keySet().iterator();
    while (itr.hasNext()) {
        UUID internalId = itr.next();
        if (placeholderList.stream().noneMatch(each -> each.getInternalId().equals(internalId))) {
            itr.remove();
        }
    }
    for (ICPlaceholder keyword : placeholderList) {
        placeholderTimestamps.putIfAbsent(keyword.getInternalId(), new ConcurrentHashMap<>());
    }
}
Also used : ICPlaceholder(com.loohp.interactivechat.objectholders.ICPlaceholder) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

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