use of com.sk89q.worldedit.util.formatting.component.TextComponentProducer in project FastAsyncWorldEdit by IntellectualSites.
the class SelectionCommands method select.
@Command(name = "/sel", aliases = { ";", "/desel", "/deselect" }, desc = "Choose a region selector")
// FAWE start
@CommandPermissions("worldedit.analysis.sel")
public // FAWE end
void select(Actor actor, World world, LocalSession session, @Arg(desc = "Selector to switch to", def = "") SelectorChoice selector, @Switch(name = 'd', desc = "Set default selector") boolean setDefaultSelector) throws WorldEditException {
if (selector == null) {
session.getRegionSelector(world).clear();
session.dispatchCUISelection(actor);
actor.print(Caption.of("worldedit.select.cleared"));
return;
}
final RegionSelector oldSelector = session.getRegionSelector(world);
final RegionSelector newSelector;
switch(selector) {
case CUBOID:
newSelector = new CuboidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.cuboid.message"));
break;
case EXTEND:
newSelector = new ExtendingCuboidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.extend.message"));
break;
case POLY:
{
newSelector = new Polygonal2DRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.poly.message"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolygonVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.poly.limit-message", TextComponent.of(integer))));
break;
}
case ELLIPSOID:
newSelector = new EllipsoidRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.ellipsoid.message"));
break;
case SPHERE:
newSelector = new SphereRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.sphere.message"));
break;
case CYL:
newSelector = new CylinderRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.cyl.message"));
break;
case CONVEX:
case HULL:
case POLYHEDRON:
{
newSelector = new ConvexPolyhedralRegionSelector(oldSelector);
actor.print(Caption.of("worldedit.select.convex.message"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("worldedit.select.convex.limit-message", TextComponent.of(integer))));
break;
}
// FAWE start
case POLYHEDRAL:
newSelector = new PolyhedralRegionSelector(world);
actor.print(Caption.of("fawe.selection.sel.convex.polyhedral"));
Optional<Integer> limit = ActorSelectorLimits.forActor(actor).getPolyhedronVertexLimit();
limit.ifPresent(integer -> actor.print(Caption.of("fawe.selection.sel.max", integer)));
actor.print(Caption.of("fawe.selection.sel.list"));
break;
case FUZZY:
case MAGIC:
Mask maskOpt = new IdMask(world);
newSelector = new FuzzyRegionSelector(actor, world, maskOpt);
actor.print(Caption.of("fawe.selection.sel.fuzzy"));
actor.print(Caption.of("fawe.selection.sel.list"));
break;
// FAWE end
case LIST:
default:
CommandListBox box = new CommandListBox("Selection modes", null, null);
box.setHidingHelp(true);
TextComponentProducer contents = box.getContents();
contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
box.appendCommand("cuboid", Caption.of("worldedit.select.cuboid.description"), "//sel cuboid");
box.appendCommand("extend", Caption.of("worldedit.select.extend.description"), "//sel extend");
box.appendCommand("poly", Caption.of("worldedit.select.poly.description"), "//sel poly");
box.appendCommand("ellipsoid", Caption.of("worldedit.select.ellipsoid.description"), "//sel ellipsoid");
box.appendCommand("sphere", Caption.of("worldedit.select.sphere.description"), "//sel sphere");
box.appendCommand("cyl", Caption.of("worldedit.select.cyl.description"), "//sel cyl");
box.appendCommand("convex", Caption.of("worldedit.select.convex.description"), "//sel convex");
// FAWE start
box.appendCommand("polyhedral", Caption.of("fawe.selection.sel.polyhedral"), "//sel polyhedral");
box.appendCommand("fuzzy[=<mask>]", Caption.of("fawe.selection.sel.fuzzy-instruction"), "//sel fuzzy[=<mask>]");
box.setComponentsPerPage(box.getComponentsSize());
// FAWE end
actor.print(box.create(1));
return;
}
if (setDefaultSelector) {
RegionSelectorType found = null;
for (RegionSelectorType type : RegionSelectorType.values()) {
if (type.getSelectorClass() == newSelector.getClass()) {
found = type;
break;
}
}
if (found != null) {
session.setDefaultRegionSelector(found);
actor.print(Caption.of("worldedit.select.default-set", TextComponent.of(found.name())));
} else {
throw new RuntimeException("Something unexpected happened. Please report this.");
}
}
session.setRegionSelector(world, newSelector);
session.dispatchCUISelection(actor);
}
use of com.sk89q.worldedit.util.formatting.component.TextComponentProducer in project FastAsyncWorldEdit by IntellectualSites.
the class SchematicCommands method list.
@Command(name = "list", aliases = { "all", "ls" }, desc = "List saved schematics", descFooter = "Note: Format is not fully verified until loading.")
@CommandPermissions("worldedit.schematic.list")
public void list(Actor actor, LocalSession session, @ArgFlag(name = 'p', desc = "Page to view.", def = "1") int page, @Switch(name = 'd', desc = "Sort by date, oldest first") boolean oldFirst, @Switch(name = 'n', desc = "Sort by date, newest first") boolean newFirst, @ArgFlag(name = 'f', desc = "Restricts by format.", def = "") String formatName, @Arg(name = "filter", desc = "Filter for schematics", def = "all") String filter, Arguments arguments) throws WorldEditException {
if (oldFirst && newFirst) {
throw new StopExecutionException(Caption.of("worldedit.schematic.sorting-old-new"));
}
// FAWE start
String pageCommand = "/" + arguments.get();
LocalConfiguration config = worldEdit.getConfiguration();
File dir = worldEdit.getWorkingDirectoryPath(config.saveDir).toFile();
String schemCmd = "//schematic";
String loadSingle = schemCmd + " load";
String loadMulti = schemCmd + " loadall";
String unload = schemCmd + " unload";
String delete = schemCmd + " delete";
String list = schemCmd + " list";
String showCmd = schemCmd + " show";
List<String> args = filter.isEmpty() ? Collections.emptyList() : Arrays.asList(filter.split(" "));
URIClipboardHolder multi = as(URIClipboardHolder.class, session.getExistingClipboard());
final boolean hasShow = false;
// If player forgot -p argument
boolean playerFolder = Settings.settings().PATHS.PER_PLAYER_SCHEMATICS;
UUID uuid = playerFolder ? actor.getUniqueId() : null;
List<File> files = UtilityCommands.getFiles(dir, actor, args, formatName, playerFolder, oldFirst, newFirst);
List<Map.Entry<URI, String>> entries = UtilityCommands.filesToEntry(dir, files, uuid);
Function<URI, Boolean> isLoaded = multi == null ? f -> false : multi::contains;
List<Component> components = UtilityCommands.entryToComponent(dir, entries, isLoaded, (name, path, type, loaded) -> {
TextComponentProducer msg = new TextComponentProducer();
msg.append(Caption.of("worldedit.schematic.dash.symbol"));
if (loaded) {
msg.append(Caption.of("worldedit.schematic.minus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.unload"))));
} else {
msg.append(Caption.of("worldedit.schematic.plus.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.clipboard"))));
}
if (type != UtilityCommands.URIType.DIRECTORY) {
msg.append(Caption.of("worldedit.schematic.x.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.delete"))));
} else if (hasShow) {
msg.append(Caption.of("worldedit.schematic.0.symbol").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path)).hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.visualize"))));
}
TextComponent msgElem = TextComponent.of(name);
if (type != UtilityCommands.URIType.DIRECTORY) {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path));
msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.load")));
} else {
msgElem = msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path));
msgElem = msgElem.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, Caption.of("worldedit.schematic.list")));
}
msg.append(msgElem);
if (type == UtilityCommands.URIType.FILE) {
long filesize = 0;
try {
filesize = Files.size(Paths.get(dir.getAbsolutePath() + File.separator + (playerFolder ? (uuid.toString() + File.separator) : "") + path));
} catch (IOException e) {
e.printStackTrace();
}
TextComponent sizeElem = TextComponent.of(String.format(" (%.1f kb)", filesize / 1000.0), TextColor.GRAY);
msg.append(sizeElem);
}
return msg.create();
});
long totalBytes = 0;
File parentDir = new File(dir.getAbsolutePath() + (playerFolder ? File.separator + uuid.toString() : ""));
try {
List<File> toAddUp = getFiles(parentDir, null, null);
if (toAddUp != null && toAddUp.size() != 0) {
for (File schem : toAddUp) {
if (schem.getName().endsWith(".schem") || schem.getName().endsWith(".schematic")) {
totalBytes += Files.size(Paths.get(schem.getAbsolutePath()));
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
String headerBytesElem = String.format("%.1fkb", totalBytes / 1000.0);
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT > -1) {
headerBytesElem += String.format(" / %dkb", Settings.settings().EXPERIMENTAL.PER_PLAYER_FILE_SIZE_LIMIT);
}
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS) {
String fullHeader = "| My Schematics: " + headerBytesElem + " |";
PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
actor.print(paginationBox.create(page));
} else {
String fullHeader = "| Schematics: " + headerBytesElem + " |";
PaginationBox paginationBox = PaginationBox.fromComponents(fullHeader, pageCommand, components);
actor.print(paginationBox.create(page));
}
// FAWE end
}
use of com.sk89q.worldedit.util.formatting.component.TextComponentProducer in project FastAsyncWorldEdit by IntellectualSites.
the class HistorySubCommands method summary.
@Command(name = "info", aliases = { "summary", "summarize" }, desc = "Summarize an edit")
@CommandPermissions("worldedit.history.info")
public synchronized void summary(Player player, RollbackDatabase database, Arguments arguments, @Arg(desc = "Player uuid/name") UUID other, @Arg(desc = "edit index") Integer index) throws WorldEditException, ExecutionException, InterruptedException {
RollbackOptimizedHistory edit = database.getEdit(other, index).get();
if (edit == null) {
player.print(Caption.of("fawe.worldedit.schematic.schematic.none"));
return;
}
Location origin = player.getLocation();
String name = Fawe.platform().getName(edit.getUUID());
String cmd = edit.getCommand();
BlockVector3 pos1 = edit.getMinimumPoint();
BlockVector3 pos2 = edit.getMaximumPoint();
double distanceX = Math.min(Math.abs(pos1.getX() - origin.getX()), Math.abs(pos2.getX() - origin.getX()));
double distanceZ = Math.min(Math.abs(pos1.getZ() - origin.getZ()), Math.abs(pos2.getZ() - origin.getZ()));
int distance = (int) Math.sqrt(distanceX * distanceX + distanceZ * distanceZ);
BlockVector2 dirVec = BlockVector2.at(edit.getOriginX() - origin.getX(), edit.getOriginZ() - origin.getZ());
Direction direction = Direction.findClosest(dirVec.toVector3(), Direction.Flag.ALL);
long seconds = (System.currentTimeMillis() - edit.getBDFile().lastModified()) / 1000;
String timeStr = MainUtil.secToTime(seconds);
int size = edit.size();
boolean biomes = edit.getBioFile().exists();
boolean createdEnts = edit.getEnttFile().exists();
boolean removedEnts = edit.getEntfFile().exists();
boolean createdTiles = edit.getNbttFile().exists();
boolean removedTiles = edit.getNbtfFile().exists();
TranslatableComponent header = Caption.of("fawe.worldedit.history.find.element", name, timeStr, distance, direction.name(), cmd);
String sizeStr = StringMan.humanReadableByteCountBin(edit.getSizeOnDisk());
String extra = "";
if (biomes) {
extra += "biomes, ";
}
if (createdEnts) {
extra += "+entity, ";
}
if (removedEnts) {
extra += "-entity, ";
}
if (createdTiles) {
extra += "+tile, ";
}
if (removedTiles) {
extra += "-tile, ";
}
TranslatableComponent body = Caption.of("fawe.worldedit.history.find.element.more", size, edit.getMinimumPoint(), edit.getMaximumPoint(), extra.trim(), sizeStr);
Component distr = TextComponent.of("/history distr").clickEvent(ClickEvent.suggestCommand("//history distr " + other + " " + index));
TextComponentProducer content = new TextComponentProducer().append(header).newline().append(body).newline().append(distr);
player.print(content.create());
}
use of com.sk89q.worldedit.util.formatting.component.TextComponentProducer in project WorldGuard by EngineHub.
the class WorldGuardCommands method listRunningTasks.
@Command(aliases = { "running", "queue" }, desc = "List running tasks", max = 0)
@CommandPermissions("worldguard.running")
public void listRunningTasks(CommandContext args, Actor sender) throws CommandException {
List<Task<?>> tasks = WorldGuard.getInstance().getSupervisor().getTasks();
if (tasks.isEmpty()) {
sender.print("There are currently no running tasks.");
} else {
tasks.sort(new TaskStateComparator());
MessageBox builder = new MessageBox("Running Tasks", new TextComponentProducer());
builder.append(TextComponent.of("Note: Some 'running' tasks may be waiting to be start.", TextColor.GRAY));
for (Task<?> task : tasks) {
builder.append(TextComponent.newline());
builder.append(TextComponent.of("(" + task.getState().name() + ") ", TextColor.BLUE));
builder.append(TextComponent.of(CommandUtils.getOwnerName(task.getOwner()) + ": ", TextColor.YELLOW));
builder.append(TextComponent.of(task.getName(), TextColor.WHITE));
}
sender.print(builder.create());
}
}
Aggregations