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);
}
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;
}
Aggregations