Search in sources :

Example 1 with Component

use of com.sk89q.worldedit.util.formatting.text.Component in project FastAsyncWorldEdit by IntellectualSites.

the class EllipsoidRegionSelector method getSelectionInfoLines.

@Override
public List<Component> getSelectionInfoLines() {
    final List<Component> lines = new ArrayList<>();
    final Vector3 center = region.getCenter();
    if (center.lengthSq() > 0) {
        lines.add(Caption.of("worldedit.selection.ellipsoid.info.center", TextComponent.of(center.toString()).clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, center.toParserString())).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy")))));
    }
    final Vector3 radius = region.getRadius();
    if (radius.lengthSq() > 0) {
        lines.add(Caption.of("worldedit.selection.ellipsoid.info.radius", TextComponent.of(radius.toString())));
    }
    return lines;
}
Also used : ArrayList(java.util.ArrayList) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Component(com.sk89q.worldedit.util.formatting.text.Component)

Example 2 with Component

use of com.sk89q.worldedit.util.formatting.text.Component in project FastAsyncWorldEdit by IntellectualSites.

the class CylinderRegionSelector method getSelectionInfoLines.

@Override
public List<Component> getSelectionInfoLines() {
    final List<Component> lines = new ArrayList<>();
    if (!region.getCenter().equals(Vector3.ZERO)) {
        Vector3 center = region.getCenter();
        lines.add(Caption.of("worldedit.selection.cylinder.info.center", TextComponent.of(center.toString()).clickEvent(ClickEvent.of(ClickEvent.Action.COPY_TO_CLIPBOARD, center.toParserString())).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to copy")))));
    }
    if (!region.getRadius().equals(Vector2.ZERO)) {
        lines.add(Caption.of("worldedit.selection.cylinder.info.radius", TextComponent.of(region.getRadius().toString())));
    }
    return lines;
}
Also used : ArrayList(java.util.ArrayList) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent)

Example 3 with Component

use of com.sk89q.worldedit.util.formatting.text.Component in project FastAsyncWorldEdit by IntellectualSites.

the class ClipboardCommands method paste.

// FAWE end
@Command(name = "/paste", aliases = { "/p", "/pa" }, desc = "Paste the clipboard's contents")
@CommandPermissions("worldedit.clipboard.paste")
@Logging(PLACEMENT)
public void paste(Actor actor, World world, LocalSession session, EditSession editSession, @Switch(name = 'a', desc = "Skip air blocks") boolean ignoreAirBlocks, @Switch(name = 'o', desc = "Paste at the original position") boolean atOrigin, @Switch(name = 's', desc = "Select the region after pasting") boolean selectPasted, @Switch(name = 'n', desc = "No paste, select only. (Implies -s)") boolean onlySelect, @Switch(name = 'e', desc = "Paste entities if available") boolean pasteEntities, @Switch(name = 'b', desc = "Paste biomes if available") boolean pasteBiomes, @ArgFlag(name = 'm', desc = "Only paste blocks matching this mask") @ClipboardMask Mask sourceMask) throws WorldEditException {
    ClipboardHolder holder = session.getClipboard();
    if (holder.getTransform().isIdentity() && editSession.getSourceMask() == null) {
        // FAWE start - use place
        place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted, pasteEntities, pasteBiomes);
        // FAWE end
        return;
    }
    Clipboard clipboard = holder.getClipboard();
    Region region = clipboard.getRegion();
    List<Component> messages = Lists.newArrayList();
    BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(actor);
    // FAWE start
    checkPaste(actor, editSession, to, holder, clipboard);
    if (!onlySelect) {
        Operation operation = holder.createPaste(editSession).to(to).ignoreAirBlocks(ignoreAirBlocks).copyBiomes(pasteBiomes).copyEntities(pasteEntities).maskSource(sourceMask).build();
        Operations.completeLegacy(operation);
        messages.addAll(Lists.newArrayList(operation.getStatusMessages()));
    }
    if (selectPasted || onlySelect) {
        BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
        Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
        Vector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()));
        RegionSelector selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
        session.setRegionSelector(world, selector);
        selector.learnChanges();
        selector.explainRegionAdjust(actor, session);
    }
    if (onlySelect) {
        actor.print(Caption.of("worldedit.paste.selected"));
    } else {
        actor.print(Caption.of("worldedit.paste.pasted", TextComponent.of(to.toString())));
    }
    messages.forEach(actor::print);
}
Also used : RegionSelector(com.sk89q.worldedit.regions.RegionSelector) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) MultiClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder) URIClipboardHolder(com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) NullRegion(com.sk89q.worldedit.regions.NullRegion) Region(com.sk89q.worldedit.regions.Region) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) DiskOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) BlockArrayClipboard(com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard) ReadOnlyClipboard(com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard) Operation(com.sk89q.worldedit.function.operation.Operation) CuboidRegionSelector(com.sk89q.worldedit.regions.selector.CuboidRegionSelector) Component(com.sk89q.worldedit.util.formatting.text.Component) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Logging(com.sk89q.worldedit.command.util.Logging) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 4 with Component

use of com.sk89q.worldedit.util.formatting.text.Component in project FastAsyncWorldEdit by IntellectualSites.

the class GeneralCommands method timeout.

@Command(name = "/timeout", desc = "Modify evaluation timeout time.")
@CommandPermissions("worldedit.timeout")
public void timeout(Actor actor, LocalSession session, @Arg(desc = "The timeout time to set", def = "") Integer limit) {
    LocalConfiguration config = worldEdit.getConfiguration();
    boolean mayDisable = actor.hasPermission("worldedit.timeout.unrestricted");
    limit = limit == null ? config.calculationTimeout : Math.max(-1, limit);
    if (!mayDisable && config.maxCalculationTimeout > -1) {
        if (limit > config.maxCalculationTimeout) {
            actor.print(Caption.of("worldedit.timeout.too-high", TextComponent.of(config.maxCalculationTimeout)));
            return;
        }
    }
    session.setTimeout(limit);
    Component component = TextComponent.empty().append(Caption.of("worldedit.timeout.set", TextComponent.of(limit)));
    if (limit != config.calculationTimeout) {
        component.append(Caption.of("worldedit.timeout.return-to-default"));
    }
    actor.print(component);
}
Also used : Component(com.sk89q.worldedit.util.formatting.text.Component) TranslatableComponent(com.sk89q.worldedit.util.formatting.text.TranslatableComponent) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) LocalConfiguration(com.sk89q.worldedit.LocalConfiguration) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 5 with Component

use of com.sk89q.worldedit.util.formatting.text.Component in project WorldGuard by EngineHub.

the class DefaultDomain method toPlayersComponent.

private Component toPlayersComponent(ProfileCache cache) {
    List<String> uuids = Lists.newArrayList();
    Map<String, UUID> profileMap = Maps.newHashMap();
    for (String name : playerDomain.getPlayers()) {
        profileMap.put(name, null);
    }
    if (cache != null) {
        ImmutableMap<UUID, Profile> results = cache.getAllPresent(playerDomain.getUniqueIds());
        for (UUID uuid : playerDomain.getUniqueIds()) {
            Profile profile = results.get(uuid);
            if (profile != null) {
                profileMap.put(profile.getName(), uuid);
            } else {
                uuids.add(uuid.toString());
            }
        }
    } else {
        for (UUID uuid : playerDomain.getUniqueIds()) {
            uuids.add(uuid.toString());
        }
    }
    final TextComponent.Builder builder = TextComponent.builder("");
    final Iterator<TextComponent> profiles = profileMap.keySet().stream().sorted().map(name -> {
        final UUID uuid = profileMap.get(name);
        final TextComponent component = TextComponent.of(name, TextColor.YELLOW).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, uuid == null ? TextComponent.of("Name only", TextColor.GRAY) : TextComponent.of("Last known name of uuid: ", TextColor.GRAY).append(TextComponent.of(uuid.toString(), TextColor.WHITE))));
        if (uuid == null) {
            return component;
        }
        return component.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, uuid.toString()));
    }).iterator();
    while (profiles.hasNext()) {
        builder.append(profiles.next());
        if (profiles.hasNext() || !uuids.isEmpty()) {
            builder.append(TextComponent.of(", "));
        }
    }
    if (!uuids.isEmpty()) {
        builder.append(TextComponent.of(uuids.size() + " unknown uuid" + (uuids.size() == 1 ? "" : "s"), TextColor.GRAY).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(String.join("\n", uuids)).append(TextComponent.newline().append(TextComponent.of("Click to select"))))).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, String.join(",", uuids))));
    }
    return builder.build();
}
Also used : TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) TextComponent(com.sk89q.worldedit.util.formatting.text.TextComponent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) LocalPlayer(com.sk89q.worldguard.LocalPlayer) UUID(java.util.UUID) HoverEvent(com.sk89q.worldedit.util.formatting.text.event.HoverEvent) Maps(com.google.common.collect.Maps) Component(com.sk89q.worldedit.util.formatting.text.Component) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) TextColor(com.sk89q.worldedit.util.formatting.text.format.TextColor) ClickEvent(com.sk89q.worldedit.util.formatting.text.event.ClickEvent) Map(java.util.Map) Profile(com.sk89q.worldguard.util.profile.Profile) ChangeTracked(com.sk89q.worldguard.util.ChangeTracked) ProfileCache(com.sk89q.worldguard.util.profile.cache.ProfileCache) Nullable(javax.annotation.Nullable) UUID(java.util.UUID) Profile(com.sk89q.worldguard.util.profile.Profile)

Aggregations

Component (com.sk89q.worldedit.util.formatting.text.Component)18 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)18 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)8 Command (org.enginehub.piston.annotation.Command)8 TranslatableComponent (com.sk89q.worldedit.util.formatting.text.TranslatableComponent)7 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 ArrayList (java.util.ArrayList)6 URIClipboardHolder (com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder)3 LocalConfiguration (com.sk89q.worldedit.LocalConfiguration)3 Vector3 (com.sk89q.worldedit.math.Vector3)3 Region (com.sk89q.worldedit.regions.Region)3 List (java.util.List)3 EditSession (com.sk89q.worldedit.EditSession)2 Logging (com.sk89q.worldedit.command.util.Logging)2 Location (com.sk89q.worldedit.util.Location)2 PaginationBox (com.sk89q.worldedit.util.formatting.component.PaginationBox)2 TextComponentProducer (com.sk89q.worldedit.util.formatting.component.TextComponentProducer)2 TextColor (com.sk89q.worldedit.util.formatting.text.format.TextColor)2 World (com.sk89q.worldedit.world.World)2 File (java.io.File)2