use of com.sk89q.worldedit.util.formatting.text.format.TextColor in project WorldGuard by EngineHub.
the class FlagHelperBox method appendValueChoices.
private <V> void appendValueChoices(TextComponent.Builder builder, Flag<V> flag, Iterator<V> choices, @Nullable String suggestChoice) {
V defVal = flag.getDefault();
V currVal = region.getFlag(flag);
boolean inherited = false;
if (currVal == null) {
currVal = getInheritedValue(region, flag);
if (currVal != null) {
inherited = true;
}
}
while (choices.hasNext()) {
V choice = choices.next();
boolean isExplicitSet = currVal == choice && !inherited;
boolean maySet = perms.maySetFlag(region, flag, isExplicitSet ? null : String.valueOf(choice));
TextColor col = isExplicitSet ? TextColor.WHITE : inherited && currVal == choice ? TextColor.GRAY : TextColor.DARK_GRAY;
Set<TextDecoration> styles = choice == defVal ? ImmutableSet.of(TextDecoration.UNDERLINED) : Collections.emptySet();
Component choiceComponent = TextComponent.empty().append(TextComponent.of(capitalize(String.valueOf(choice)), col, styles));
List<Component> hoverTexts = new ArrayList<>();
if (maySet) {
if (isExplicitSet) {
hoverTexts.add(TextComponent.of("Click to unset", TextColor.GOLD));
} else if (DANGER_ZONE.contains(flag) && !(ProtectedRegion.GLOBAL_REGION.equals(region.getId()) && flag == Flags.PASSTHROUGH)) {
hoverTexts.add(TextComponent.of("Setting this flag may have unintended consequences.", TextColor.RED).append(TextComponent.newline()).append(TextComponent.of("Please read the documentation and set this flag manually if you really intend to.").append(TextComponent.newline()).append(TextComponent.of("(Hint: You do not need to set this to protect the region!)"))));
} else {
hoverTexts.add(TextComponent.of("Click to set", TextColor.GOLD));
}
}
Component valType = getToolTipHint(defVal, choice, inherited);
if (valType != null) {
hoverTexts.add(valType);
}
if (!hoverTexts.isEmpty()) {
TextComponent.Builder hoverBuilder = TextComponent.builder("");
for (Iterator<Component> hovIt = hoverTexts.iterator(); hovIt.hasNext(); ) {
hoverBuilder.append(hovIt.next());
if (hovIt.hasNext()) {
hoverBuilder.append(TextComponent.newline());
}
}
choiceComponent = choiceComponent.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, hoverBuilder.build()));
}
if (maySet && (isExplicitSet || !DANGER_ZONE.contains(flag))) {
builder.append(choiceComponent.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, makeCommand(flag, isExplicitSet ? "" : choice))));
} else {
builder.append(choiceComponent);
}
builder.append(TextComponent.space());
}
if (suggestChoice != null && perms.maySetFlag(region, flag)) {
builder.append(TextComponent.of(suggestChoice, TextColor.DARK_GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to set custom value", TextColor.GOLD))).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, makeCommand(flag, ""))));
}
}
use of com.sk89q.worldedit.util.formatting.text.format.TextColor in project WorldGuard by EngineHub.
the class FlagHelperBox method appendValueText.
private <V> void appendValueText(TextComponent.Builder builder, Flag<V> flag, String display, @Nullable Component hover) {
V defVal = flag.getDefault();
V currVal = region.getFlag(flag);
boolean inherited = false;
if (currVal == null) {
currVal = getInheritedValue(region, flag);
if (currVal != null) {
inherited = true;
}
}
boolean isExplicitSet = currVal != null && !inherited;
boolean maySet = !(flag instanceof UnknownFlag) && perms.maySetFlag(region, flag);
TextColor col = isExplicitSet ? TextColor.WHITE : inherited ? TextColor.GRAY : TextColor.DARK_GRAY;
Set<TextDecoration> styles = currVal == defVal ? ImmutableSet.of(TextDecoration.UNDERLINED) : Collections.emptySet();
Component displayComponent = TextComponent.empty().append(TextComponent.of(display, col, styles));
List<Component> hoverTexts = new ArrayList<>();
if (maySet) {
if (isExplicitSet) {
hoverTexts.add(TextComponent.of("Click to change", TextColor.GOLD));
} else {
hoverTexts.add(TextComponent.of("Click to set", TextColor.GOLD));
}
}
Component valType = getToolTipHint(defVal, currVal, inherited);
if (valType != null) {
hoverTexts.add(valType);
}
if (!hoverTexts.isEmpty()) {
TextComponent.Builder hoverBuilder = TextComponent.builder("");
for (Iterator<Component> hovIt = hoverTexts.iterator(); hovIt.hasNext(); ) {
hoverBuilder.append(hovIt.next());
if (hovIt.hasNext()) {
hoverBuilder.append(TextComponent.newline());
}
}
if (hover != null) {
hoverBuilder.append(TextComponent.newline());
hoverBuilder.append(hover);
}
displayComponent = displayComponent.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, hoverBuilder.build()));
}
if (maySet) {
builder.append(displayComponent.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, makeCommand(flag, ""))));
} else {
builder.append(displayComponent);
}
builder.append(TextComponent.space());
}
use of com.sk89q.worldedit.util.formatting.text.format.TextColor in project WorldGuard by EngineHub.
the class RegionPrintoutBuilder method appendFlagsList.
/**
* Append just the list of flags (without "Flags:"), including colors.
*
* @param useColors true to use colors
*/
public void appendFlagsList(boolean useColors) {
boolean hasFlags = false;
for (Flag<?> flag : WorldGuard.getInstance().getFlagRegistry()) {
Object val = region.getFlag(flag);
// No value
if (val == null) {
continue;
}
if (hasFlags) {
builder.append(TextComponent.of(", "));
}
RegionGroupFlag groupFlag = flag.getRegionGroupFlag();
Object group = null;
if (groupFlag != null) {
group = region.getFlag(groupFlag);
}
String flagString;
if (group == null) {
flagString = flag.getName() + ": ";
} else {
flagString = flag.getName() + " -g " + group + ": ";
}
TextColor flagColor = TextColor.WHITE;
if (useColors) {
// passthrough is ok on global
if (FlagHelperBox.DANGER_ZONE.contains(flag) && !(region.getId().equals(ProtectedRegion.GLOBAL_REGION) && flag == Flags.PASSTHROUGH)) {
flagColor = TextColor.DARK_RED;
} else if (Flags.INBUILT_FLAGS.contains(flag.getName())) {
flagColor = TextColor.GOLD;
} else if (flag instanceof UnknownFlag) {
flagColor = TextColor.GRAY;
} else {
flagColor = TextColor.LIGHT_PURPLE;
}
}
TextComponent flagText = TextComponent.of(flagString, flagColor).append(TextComponent.of(String.valueOf(val), useColors ? TextColor.YELLOW : TextColor.WHITE));
if (perms != null && perms.maySetFlag(region, flag)) {
flagText = flagText.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to set flag"))).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/rg flag -w \"" + world + "\" " + region.getId() + " " + flag.getName() + " "));
}
builder.append(flagText);
hasFlags = true;
}
if (!hasFlags) {
TextComponent noFlags = TextComponent.of("(none)", useColors ? TextColor.RED : TextColor.WHITE);
builder.append(noFlags);
}
if (perms != null && perms.maySetFlag(region)) {
builder.append(TextComponent.space()).append(TextComponent.of("[Flags]", useColors ? TextColor.GREEN : TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to set a flag"))).clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/rg flags -w \"" + world + "\" " + region.getId())));
}
}
Aggregations