use of com.sk89q.worldedit.util.formatting.text.Component in project FastAsyncWorldEdit by IntellectualSites.
the class GeneralCommands method limit.
@Command(name = "/limit", desc = "Modify block change limit")
@CommandPermissions("worldedit.limit")
public void limit(Actor actor, LocalSession session, @Arg(desc = "The limit to set", def = "") Integer limit) {
LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = actor.hasPermission("worldedit.limit.unrestricted");
limit = limit == null ? config.defaultChangeLimit : Math.max(-1, limit);
if (!mayDisable && config.maxChangeLimit > -1) {
if (limit > config.maxChangeLimit) {
actor.print(Caption.of("worldedit.limit.too-high", TextComponent.of(config.maxChangeLimit)));
return;
}
}
session.setBlockChangeLimit(limit);
Component component = TextComponent.empty().append(Caption.of("worldedit.limit.set", TextComponent.of(limit)));
if (limit != config.defaultChangeLimit) {
component.append(TextComponent.space()).append(Caption.of("worldedit.limit.return-to-default"));
}
actor.print(component);
}
use of com.sk89q.worldedit.util.formatting.text.Component 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.Component in project WorldGuard by EngineHub.
the class RegionCommands method flag.
/**
* Set a flag.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "flag", "f" }, usage = "<id> <flag> [-w world] [-g group] [value]", flags = "g:w:eh:", desc = "Set flags", min = 2)
public void flag(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
String flagName = args.getString(1);
String value = args.argsLength() >= 3 ? args.getJoinedStrings(2) : null;
RegionGroup groupValue = null;
FlagRegistry flagRegistry = WorldGuard.getInstance().getFlagRegistry();
RegionPermissionModel permModel = getPermissionModel(sender);
if (args.hasFlag('e')) {
if (value != null) {
throw new CommandException("You cannot use -e(mpty) with a flag value.");
}
value = "";
}
// Lookup the existing region
RegionManager manager = checkRegionManager(world);
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
// Check permissions
if (!permModel.maySetFlag(existing)) {
throw new CommandPermissionsException();
}
String regionId = existing.getId();
Flag<?> foundFlag = Flags.fuzzyMatchFlag(flagRegistry, flagName);
// can use, and do nothing afterwards
if (foundFlag == null) {
AsyncCommandBuilder.wrap(new FlagListBuilder(flagRegistry, permModel, existing, world, regionId, sender, flagName), sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Flag list for invalid flag command.").onSuccess((Component) null, sender::print).onFailure((Component) null, WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
return;
} else if (value != null) {
if (foundFlag == Flags.BUILD || foundFlag == Flags.BLOCK_BREAK || foundFlag == Flags.BLOCK_PLACE) {
sender.print(buildFlagWarning);
if (!sender.isPlayer()) {
sender.printRaw("https://worldguard.enginehub.org/en/latest/regions/flags/#protection-related");
}
} else if (foundFlag == Flags.PASSTHROUGH) {
sender.print(passthroughFlagWarning);
if (!sender.isPlayer()) {
sender.printRaw("https://worldguard.enginehub.org/en/latest/regions/flags/#overrides");
}
}
}
// but not here -- in the model
if (!permModel.maySetFlag(existing, foundFlag, value)) {
throw new CommandPermissionsException();
}
// -g for group flag
if (args.hasFlag('g')) {
String group = args.getFlag('g');
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
if (groupFlag == null) {
throw new CommandException("Region flag '" + foundFlag.getName() + "' does not have a group flag!");
}
// the [value] part throws an error.
try {
groupValue = groupFlag.parseInput(FlagContext.create().setSender(sender).setInput(group).setObject("region", existing).build());
} catch (InvalidFlagFormat e) {
throw new CommandException(e.getMessage());
}
}
// Set the flag value if a value was set
if (value != null) {
// Set the flag if [value] was given even if [-g group] was given as well
try {
value = setFlag(existing, foundFlag, sender, value).toString();
} catch (InvalidFlagFormat e) {
throw new CommandException(e.getMessage());
}
if (!args.hasFlag('h')) {
sender.print("Region flag " + foundFlag.getName() + " set on '" + regionId + "' to '" + value + "'.");
}
// No value? Clear the flag, if -g isn't specified
} else if (!args.hasFlag('g')) {
// Clear the flag only if neither [value] nor [-g group] was given
existing.setFlag(foundFlag, null);
// Also clear the associated group flag if one exists
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
if (groupFlag != null) {
existing.setFlag(groupFlag, null);
}
if (!args.hasFlag('h')) {
sender.print("Region flag " + foundFlag.getName() + " removed from '" + regionId + "'. (Any -g(roups) were also removed.)");
}
}
// Now set the group
if (groupValue != null) {
RegionGroupFlag groupFlag = foundFlag.getRegionGroupFlag();
// If group set to the default, then clear the group flag
if (groupValue == groupFlag.getDefault()) {
existing.setFlag(groupFlag, null);
sender.print("Region group flag for '" + foundFlag.getName() + "' reset to default.");
} else {
existing.setFlag(groupFlag, groupValue);
sender.print("Region group flag for '" + foundFlag.getName() + "' set.");
}
}
// Print region information
if (args.hasFlag('h')) {
int page = args.getFlagInteger('h');
sendFlagHelper(sender, world, existing, permModel, page);
} else {
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), existing, null, sender);
printout.append(SubtleFormat.wrap("(Current flags: "));
printout.appendFlagsList(false);
printout.append(SubtleFormat.wrap(")"));
printout.send(sender);
checkSpawnOverlap(sender, world, existing);
}
}
Aggregations