/** * Sets the click event for the current part. * * @param clickEvent the click event * @return this ComponentBuilder for chaining */ public ComponentBuilder event(ClickEvent clickEvent) { current.setClickEvent( clickEvent ); return this; }
component.setClickEvent( new ClickEvent( ClickEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase( Locale.ROOT ) ), event.get( "value" ).getAsString() ) );
/** * Retains only the specified formatting. * * @param retention the formatting to retain */ public void retain(FormatRetention retention) { if ( retention == FormatRetention.FORMATTING || retention == FormatRetention.NONE ) { setClickEvent( null ); setHoverEvent( null ); } if ( retention == FormatRetention.EVENTS || retention == FormatRetention.NONE ) { setColor( null ); setBold( null ); setItalic( null ); setUnderlined( null ); setStrikethrough( null ); setObfuscated( null ); setInsertion( null ); } }
setClickEvent( component.getClickEvent() );
component.setClickEvent( new ClickEvent( ClickEvent.Action.valueOf( event.get( "action" ).getAsString().toUpperCase() ), event.get( "value" ).getAsString() ) );
@Override public BaseComponent button(ButtonType type, Translatable label, @Nullable Translatable tooltip, String command, boolean execute) { BaseComponent builder = tr(label); ChatColor textColor; switch (type) { case POSITIVE: textColor = ChatColor.GREEN; break; case NEGATIVE: textColor = ChatColor.RED; break; case NEUTRAL: textColor = ChatColor.AQUA; break; default: throw new IllegalArgumentException("Provided with unknown ButtonType " + type); } builder.setColor(textColor); if (tooltip != null) { builder.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{tr(tooltip)})); } builder.setClickEvent(new ClickEvent(execute ? ClickEvent.Action.RUN_COMMAND : ClickEvent.Action.SUGGEST_COMMAND, command)); return builder; }
@Override public BaseComponent subject(Map.Entry<String, String> subject) { String name; try { name = pex.getManager().getSubjects(subject.getKey()).persistentData().getData(subject.getValue(), null).get().getOptions(PermissionsEx.GLOBAL_CONTEXT).get("name"); } catch (ExecutionException | InterruptedException e) { throw new RuntimeException(e); } BaseComponent nameText; if (name != null) { nameText = new TextComponent(""); final BaseComponent child = new TextComponent(subject.getValue()); child.setColor(ChatColor.GRAY); nameText.addExtra(child); nameText.addExtra("/"); nameText.addExtra(name); } else { nameText = new TextComponent(subject.getValue()); } // <bold>{type}>/bold>:{identifier}/{name} (on click: /pex {type} {identifier} BaseComponent ret = new TextComponent(""); BaseComponent typeComponent = new TextComponent(subject.getKey()); typeComponent.setBold(true); ret.addExtra(typeComponent); ret.addExtra(" "); ret.addExtra(nameText); ret.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{tr(t("Click to view more info"))})); ret.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/pex " + subject.getKey() + " " + subject.getValue() + " info")); return ret; }
@Override public BaseComponent ladder(RankLadder ladder) { BaseComponent ret = new TextComponent(ladder.getName()); ret.setBold(true); ret.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{tr(t("click here to view more info"))})); ret.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/pex rank " + ladder.getName())); return ret; }
public BaseComponent getComponent() { BaseComponent msg = new TextComponent(getDisplayName()); msg.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/rpgitem " + getName())); HoverEvent hover = new HoverEvent(HoverEvent.Action.SHOW_ITEM, new BaseComponent[]{new TextComponent(ItemStackUtils.itemToJson(toItemStack()))}); msg.setHoverEvent(hover); return msg; }
BaseComponent(BaseComponent old) { setColor( old.getColorRaw() ); setBold( old.isBoldRaw() ); setItalic( old.isItalicRaw() ); setUnderlined( old.isUnderlinedRaw() ); setStrikethrough( old.isStrikethroughRaw() ); setObfuscated( old.isObfuscatedRaw() ); setInsertion( old.getInsertion() ); setClickEvent( old.getClickEvent() ); setHoverEvent( old.getHoverEvent() ); if ( old.getExtra() != null ) { for ( BaseComponent component : old.getExtra() ) { addExtra( component.duplicate() ); } } }