Search in sources :

Example 1 with ClickEventAction

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

the class CustomPlaceholderCreator method toCustomPlaceholder.

public CustomPlaceholder toCustomPlaceholder() {
    String name = textFieldName.getText();
    String description = textFieldDescription.getText();
    ParsePlayer parsePlayer = (ParsePlayer) boxParsePlayer.getSelectedItem();
    Pattern keyword;
    if (regexCheckBox.isSelected()) {
        keyword = validRegex(textFieldKeyword.getText()) == null ? Pattern.compile(textFieldKeyword.getText()) : IMPOSSIBLE_PATTERN;
    } else {
        String joined = Stream.of(textFieldKeyword.getText().split(",")).map(each -> CustomStringUtils.escapeMetaCharacters(each)).collect(Collectors.joining("|"));
        keyword = Pattern.compile(joined);
    }
    boolean parseKeyword = checkBoxParseKeyword.isSelected();
    long cooldown = validLong(textFieldCooldown.getText()) == null ? Long.parseLong(textFieldCooldown.getText()) : 0;
    CustomPlaceholderHoverEvent hoverEvent = new CustomPlaceholderHoverEvent(checkBoxHover.isSelected(), textAreaHover.getText());
    CustomPlaceholderClickEvent clickEvent = new CustomPlaceholderClickEvent(checkBoxClick.isSelected(), (ClickEventAction) boxClickAction.getSelectedItem(), textFieldClickValue.getText());
    CustomPlaceholderReplaceText replaceText = new CustomPlaceholderReplaceText(checkBoxReplace.isSelected(), textFieldReplaceText.getText());
    return new CustomPlaceholder((int) spinnerIndex.getValue(), parsePlayer, keyword, parseKeyword, cooldown, hoverEvent, clickEvent, replaceText, name, description);
}
Also used : Color(java.awt.Color) ComponentReplacing(com.loohp.interactivechat.utils.ComponentReplacing) Arrays(java.util.Arrays) ConfigurationSection(com.loohp.yamlconfiguration.ConfigurationSection) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) ChangeListener(javax.swing.event.ChangeListener) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) AttributeSet(javax.swing.text.AttributeSet) ChangeEvent(javax.swing.event.ChangeEvent) PatternSyntaxException(java.util.regex.PatternSyntaxException) YamlConfiguration(com.loohp.yamlconfiguration.YamlConfiguration) BufferedImage(java.awt.image.BufferedImage) Action(net.kyori.adventure.text.event.HoverEvent.Action) BorderFactory(javax.swing.BorderFactory) Icon(javax.swing.Icon) BadLocationException(javax.swing.text.BadLocationException) PlainDocument(javax.swing.text.PlainDocument) KeyEvent(java.awt.event.KeyEvent) Collectors(java.util.stream.Collectors) Dimension(java.awt.Dimension) Stream(java.util.stream.Stream) ClickEventAction(com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction) CustomStringUtils(com.loohp.interactivechat.utils.CustomStringUtils) JCheckBox(javax.swing.JCheckBox) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Document(javax.swing.text.Document) Pattern(java.util.regex.Pattern) Spacer(com.intellij.uiDesigner.core.Spacer) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) HoverEvent(net.kyori.adventure.text.event.HoverEvent) JPanel(javax.swing.JPanel) Toolkit(java.awt.Toolkit) Insets(java.awt.Insets) KeyListener(java.awt.event.KeyListener) ActionListener(java.awt.event.ActionListener) JTextField(javax.swing.JTextField) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) SpinnerNumberModel(javax.swing.SpinnerNumberModel) DefaultEditor(javax.swing.JSpinner.DefaultEditor) ClickEvent(net.kyori.adventure.text.event.ClickEvent) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) SwingUtilities(javax.swing.SwingUtilities) Component(net.kyori.adventure.text.Component) LegacyComponentSerializer(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JSpinner(javax.swing.JSpinner) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) JScrollPane(javax.swing.JScrollPane) DocumentFilter(javax.swing.text.DocumentFilter) PlainTextComponentSerializer(net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer) JLabel(javax.swing.JLabel) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) ChatColorUtils(com.loohp.interactivechat.utils.ChatColorUtils) JTextArea(javax.swing.JTextArea) Collections(java.util.Collections) ParsePlayer(com.loohp.interactivechat.objectholders.CustomPlaceholder.ParsePlayer) Pattern(java.util.regex.Pattern) CustomPlaceholderHoverEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderHoverEvent) CustomPlaceholder(com.loohp.interactivechat.objectholders.CustomPlaceholder) CustomPlaceholderClickEvent(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderClickEvent) CustomPlaceholderReplaceText(com.loohp.interactivechat.objectholders.CustomPlaceholder.CustomPlaceholderReplaceText)

Example 2 with ClickEventAction

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

Aggregations

CustomPlaceholder (com.loohp.interactivechat.objectholders.CustomPlaceholder)2 ClickEventAction (com.loohp.interactivechat.objectholders.CustomPlaceholder.ClickEventAction)2 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)1 Spacer (com.intellij.uiDesigner.core.Spacer)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 ICPlayer (com.loohp.interactivechat.objectholders.ICPlayer)1 ChatColorUtils (com.loohp.interactivechat.utils.ChatColorUtils)1 ComponentReplacing (com.loohp.interactivechat.utils.ComponentReplacing)1 CustomStringUtils (com.loohp.interactivechat.utils.CustomStringUtils)1 ConfigurationSection (com.loohp.yamlconfiguration.ConfigurationSection)1 YamlConfiguration (com.loohp.yamlconfiguration.YamlConfiguration)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Insets (java.awt.Insets)1 Toolkit (java.awt.Toolkit)1