Search in sources :

Example 1 with ConfigurationSection

use of com.loohp.yamlconfiguration.ConfigurationSection in project InteractiveChat by LOOHP.

the class ConfigDataFixer method update.

public static void update(Config config) {
    String versionString = config.getConfiguration().getString("ConfigVersion");
    if (versionString == null) {
        versionString = BASE_PLUGIN_VERSION;
        config.getConfiguration().set("ConfigVersion", versionString);
    }
    Version configVersion = new Version(versionString);
    boolean backup = false;
    if (configVersion.compareTo(new Version("4.1.1.9")) < 0) {
        if (!backup) {
            config.save(new File(config.getFile().getParent(), config.getFile().getName() + "." + versionString + ".bak"));
        }
        backup = true;
        // Regex placeholder
        boolean itemCase = config.getConfiguration().getBoolean("ItemDisplay.Item.CaseSensitive", false);
        config.getConfiguration().set("ItemDisplay.Item.CaseSensitive", null);
        config.getConfiguration().set("ItemDisplay.Item.Aliases", null);
        config.getConfiguration().set("ItemDisplay.Item.Name", config.getConfiguration().getString("ItemDisplay.Item.Keyword"));
        config.getConfiguration().set("ItemDisplay.Item.Keyword", (itemCase ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(config.getConfiguration().getString("ItemDisplay.Item.Keyword")));
        boolean invCase = config.getConfiguration().getBoolean("ItemDisplay.Inventory.CaseSensitive", false);
        config.getConfiguration().set("ItemDisplay.Inventory.CaseSensitive", null);
        config.getConfiguration().set("ItemDisplay.Inventory.Aliases", null);
        config.getConfiguration().set("ItemDisplay.Inventory.Name", config.getConfiguration().getString("ItemDisplay.Inventory.Keyword"));
        config.getConfiguration().set("ItemDisplay.Inventory.Keyword", (invCase ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(config.getConfiguration().getString("ItemDisplay.Inventory.Keyword")));
        boolean enderCase = config.getConfiguration().getBoolean("ItemDisplay.EnderChest.CaseSensitive", false);
        config.getConfiguration().set("ItemDisplay.EnderChest.CaseSensitive", null);
        config.getConfiguration().set("ItemDisplay.EnderChest.Aliases", null);
        config.getConfiguration().set("ItemDisplay.EnderChest.Name", config.getConfiguration().getString("ItemDisplay.EnderChest.Keyword"));
        config.getConfiguration().set("ItemDisplay.EnderChest.Keyword", (enderCase ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(config.getConfiguration().getString("ItemDisplay.EnderChest.Keyword")));
        for (int customNo = 1; config.getConfiguration().contains("CustomPlaceholders." + customNo); customNo++) {
            ConfigurationSection s = config.getConfiguration().getConfigurationSection("CustomPlaceholders." + customNo);
            String text = s.getString("Text");
            s.set("Text", null);
            boolean caseSensitive = s.getBoolean("CaseSensitive", false);
            s.set("CaseSensitive", null);
            s.set("Keyword", (caseSensitive ? "" : "(?i)") + CustomStringUtils.escapeMetaCharacters(text));
            s.set("Name", text);
            s.set("Aliases", null);
        }
    }
    if (configVersion.compareTo(new Version("4.1.1.13")) < 0) {
        if (!backup) {
            config.save(new File(config.getFile().getParent(), config.getFile().getName() + "." + versionString + ".bak"));
        }
        backup = true;
        config.getConfiguration().set("Settings.FormattingTags.AdditionalRGBFormats", Collections.singletonList("#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])"));
    }
    if (configVersion.compareTo(new Version("4.1.2.14")) < 0) {
        if (!backup) {
            config.save(new File(config.getFile().getParent(), config.getFile().getName() + "." + versionString + ".bak"));
        }
        backup = true;
        config.getConfiguration().set("Settings.ChatListeningPlugins", null);
    }
    config.getConfiguration().set("ConfigVersion", InteractiveChat.plugin.getDescription().getVersion());
    config.save();
}
Also used : Version(com.loohp.interactivechat.updater.Version) File(java.io.File) ConfigurationSection(com.loohp.yamlconfiguration.ConfigurationSection)

Example 2 with ConfigurationSection

use of com.loohp.yamlconfiguration.ConfigurationSection in project InteractiveChat by LOOHP.

the class CustomPlaceholderCreator method loadFromYaml.

public void loadFromYaml(ConfigurationSection yaml) {
    JPanel panel = new JPanel();
    JLabel label = GUIMain.createLabel("Select Placeholder: ", 13);
    panel.add(label);
    JComboBox<String> options = new JComboBox<>();
    for (String key : yaml.getConfigurationSection("CustomPlaceholders").getKeys(false)) {
        options.addItem(key + ". " + yaml.getString("CustomPlaceholders." + key + ".Name"));
    }
    panel.add(options);
    int result = JOptionPane.showOptionDialog(null, panel, title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, icon, null, null);
    if (result < 0) {
        return;
    }
    ConfigurationSection section = yaml.getConfigurationSection("CustomPlaceholders." + (options.getSelectedIndex() + 1));
    spinnerIndex.setValue(options.getSelectedIndex() + 1);
    textFieldName.setText(section.getString("Name"));
    textFieldDescription.setText(section.getString("Description"));
    boxParsePlayer.setSelectedItem(ParsePlayer.fromString(section.getString("ParsePlayer")));
    textFieldKeyword.setText(section.getString("Keyword"));
    checkBoxParseKeyword.setSelected(section.getBoolean("ParseKeyword"));
    textFieldCooldown.setText(section.getLong("Cooldown") + "");
    checkBoxHover.setSelected(section.getBoolean("Hover.Enable"));
    textAreaHover.setText(String.join("\n", section.getStringList("Hover.Text")));
    checkBoxClick.setSelected(section.getBoolean("Click.Enable"));
    try {
        boxClickAction.setSelectedItem(ClickEventAction.valueOf(section.getString("Click.Action")));
    } catch (Throwable e) {
        boxClickAction.setSelectedIndex(0);
    }
    textFieldClickValue.setText(section.getString("Click.Value"));
    checkBoxReplace.setSelected(section.getBoolean("Replace.Enable"));
    textFieldReplaceText.setText(section.getString("Replace.ReplaceText"));
    regexCheckBox.setSelected(true);
    labelKeywordComma.setVisible(false);
    SwingUtilities.invokeLater(() -> {
        scrollHoverText.getHorizontalScrollBar().setValue(0);
        scrollHoverText.getVerticalScrollBar().setValue(0);
        scrollReplaceText.getHorizontalScrollBar().setValue(0);
        scrollReplaceText.getVerticalScrollBar().setValue(0);
    });
    updateConfigOutput(toCustomPlaceholder());
}
Also used : JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) ConfigurationSection(com.loohp.yamlconfiguration.ConfigurationSection)

Example 3 with ConfigurationSection

use of com.loohp.yamlconfiguration.ConfigurationSection in project InteractiveChat by LOOHP.

the class CustomPlaceholderCreator method updateConfigOutput.

public void updateConfigOutput(CustomPlaceholder customPlaceholder) {
    if (regexCheckBox.isSelected()) {
        PatternSyntaxException error = validRegex(textFieldKeyword.getText());
        if (error != null) {
            textAreaConfigOutput.setForeground(Color.RED);
            textAreaConfigOutput.setText("Invalid Keyword Regex!!\nDetails:\n\n" + error.getClass().getName() + ":\n" + error.getLocalizedMessage());
            return;
        }
    }
    textAreaConfigOutput.setForeground(Color.BLACK);
    String pos = String.valueOf(customPlaceholder.getPosition());
    ConfigurationSection config = ConfigurationSection.newConfigurationSection();
    config.set(pos + ".Name", customPlaceholder.getName());
    config.set(pos + ".Description", customPlaceholder.getDescription());
    config.set(pos + ".ParsePlayer", customPlaceholder.getParsePlayer().toString());
    config.set(pos + ".Keyword", customPlaceholder.getKeyword().pattern());
    config.set(pos + ".ParseKeyword", customPlaceholder.getParseKeyword());
    config.set(pos + ".Cooldown", customPlaceholder.getCooldown());
    config.set(pos + ".Hover.Enable", customPlaceholder.getHover().isEnabled());
    config.set(pos + ".Hover.Text", Arrays.asList(customPlaceholder.getHover().getText().split("\\R")));
    config.set(pos + ".Click.Enable", customPlaceholder.getClick().isEnabled());
    config.set(pos + ".Click.Action", customPlaceholder.getClick().getAction().toString());
    config.set(pos + ".Click.Value", customPlaceholder.getClick().getValue());
    config.set(pos + ".Replace.Enable", customPlaceholder.getReplace().isEnabled());
    config.set(pos + ".Replace.ReplaceText", customPlaceholder.getReplace().getReplaceText());
    textAreaConfigOutput.setText(config.saveToString());
    SwingUtilities.invokeLater(() -> {
        scrollPaneConfigOutput.getHorizontalScrollBar().setValue(0);
        scrollPaneConfigOutput.getVerticalScrollBar().setValue(0);
    });
}
Also used : PatternSyntaxException(java.util.regex.PatternSyntaxException) ConfigurationSection(com.loohp.yamlconfiguration.ConfigurationSection)

Example 4 with ConfigurationSection

use of com.loohp.yamlconfiguration.ConfigurationSection 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)

Aggregations

ConfigurationSection (com.loohp.yamlconfiguration.ConfigurationSection)4 File (java.io.File)2 InteractiveChat (com.loohp.interactivechat.InteractiveChat)1 ConfigDataFixer (com.loohp.interactivechat.datafixer.ConfigDataFixer)1 BuiltInPlaceholder (com.loohp.interactivechat.objectholders.BuiltInPlaceholder)1 CustomPlaceholder (com.loohp.interactivechat.objectholders.CustomPlaceholder)1 ClickEventAction (com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction)1 CustomPlaceholderClickEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent)1 CustomPlaceholderHoverEvent (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent)1 CustomPlaceholderReplaceText (com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)1 ParsePlayer (com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer)1 ICPlaceholder (com.loohp.interactivechat.objectholders.ICPlaceholder)1 WebData (com.loohp.interactivechat.objectholders.WebData)1 Version (com.loohp.interactivechat.updater.Version)1 ChatColorUtils (com.loohp.interactivechat.utils.ChatColorUtils)1 LanguageUtils (com.loohp.interactivechat.utils.LanguageUtils)1 MCVersion (com.loohp.interactivechat.utils.MCVersion)1 XMaterialUtils (com.loohp.interactivechat.utils.XMaterialUtils)1 YamlConfiguration (com.loohp.yamlconfiguration.YamlConfiguration)1 IOException (java.io.IOException)1