Merge pull request #462 from EngineHub/feature/expanded-styleset

feat(text): added modern text formatting to worldedit, and switch a few things over to it
This commit is contained in:
Matthew Miller
2019-04-25 19:39:26 +10:00
committed by GitHub
30 changed files with 466 additions and 1156 deletions

View File

@ -55,15 +55,15 @@ import com.sk89q.worldedit.regions.selector.SphereRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.storage.ChunkStore;
import com.sk89q.worldedit.util.formatting.text.Component;
import java.util.ArrayList;
import java.util.List;
@ -76,7 +76,7 @@ import java.util.Set;
public class SelectionCommands {
private final WorldEdit we;
public SelectionCommands(WorldEdit we) {
this.we = we;
}
@ -295,7 +295,7 @@ public class SelectionCommands {
)
@CommandPermissions("worldedit.wand.toggle")
public void toggleWand(Player player, LocalSession session, CommandContext args) throws WorldEditException {
session.setToolControl(!session.isToolControlEnabled());
if (session.isToolControlEnabled()) {
@ -394,7 +394,7 @@ public class SelectionCommands {
session.getRegionSelector(player.getWorld()).learnChanges();
int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
player.print("Region expanded " + (newSize - oldSize) + " blocks.");
@ -465,7 +465,7 @@ public class SelectionCommands {
}
session.getRegionSelector(player.getWorld()).learnChanges();
int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
@ -754,19 +754,18 @@ public class SelectionCommands {
limit.ifPresent(integer -> player.print(integer + " points maximum."));
} else {
CommandListBox box = new CommandListBox("Selection modes");
StyledFragment contents = box.getContents();
StyledFragment tip = contents.createFragment(Style.RED);
tip.append("Select one of the modes below:").newLine();
TextComponentProducer contents = box.getContents();
contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline();
box.appendCommand("cuboid", "Select two corners of a cuboid");
box.appendCommand("extend", "Fast cuboid selection mode");
box.appendCommand("poly", "Select a 2D polygon with height");
box.appendCommand("ellipsoid", "Select an ellipsoid");
box.appendCommand("sphere", "Select a sphere");
box.appendCommand("cyl", "Select a cylinder");
box.appendCommand("convex", "Select a convex polyhedral");
box.appendCommand("cuboid", "Select two corners of a cuboid", "//sel cuboid");
box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend");
box.appendCommand("poly", "Select a 2D polygon with height", "//sel poly");
box.appendCommand("ellipsoid", "Select an ellipsoid", "//sel ellipsoid");
box.appendCommand("sphere", "Select a sphere", "//sel sphere");
box.appendCommand("cyl", "Select a cylinder", "//sel cyl");
box.appendCommand("convex", "Select a convex polyhedral", "//sel convex");
player.printRaw(ColorCodeBuilder.asColorCodes(box));
player.print(box.create());
return;
}

View File

@ -58,12 +58,15 @@ import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.PrimaryAliasComparator;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.sk89q.worldedit.util.formatting.component.Code;
import com.sk89q.worldedit.util.formatting.component.CodeFormat;
import com.sk89q.worldedit.util.formatting.component.CommandListBox;
import com.sk89q.worldedit.util.formatting.component.CommandUsageBox;
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -206,7 +209,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.removeabove")
@Logging(PLACEMENT)
public void removeAbove(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1;
we.checkMaxRadius(size);
World world = player.getWorld();
@ -274,7 +277,7 @@ public class UtilityCommands {
@CommandPermissions("worldedit.replacenear")
@Logging(PLACEMENT)
public void replaceNear(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
int size = Math.max(1, args.getInteger(0));
we.checkMaxRadius(size);
int affected;
@ -669,17 +672,19 @@ public class UtilityCommands {
// Box
CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal));
StyledFragment contents = box.getContents();
StyledFragment tip = contents.createFragment(Style.GRAY);
TextComponentProducer tip = new TextComponentProducer();
tip.getBuilder().content("").color(TextColor.GRAY);
TextComponentProducer contents = box.getContents();
if (offset >= aliases.size()) {
tip.createFragment(Style.RED).append(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).newLine();
tip.append(ErrorFormat.wrap(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal))).newline();
} else {
List<CommandMapping> list = aliases.subList(offset, Math.min(offset + perPage, aliases.size()));
tip.append("Type ");
tip.append(new Code().append("//help ").append("<command> [<page>]"));
tip.append(" for more information.").newLine();
tip.append(CodeFormat.wrap("//help "));
tip.append("<command> [<page>] for more information.");
tip.newline();
// Add each command
for (CommandMapping mapping : list) {
@ -696,10 +701,11 @@ public class UtilityCommands {
}
}
actor.printRaw(ColorCodeBuilder.asColorCodes(box));
contents.append(tip.create());
actor.print(box.create());
} else {
CommandUsageBox box = new CommandUsageBox(callable, Joiner.on(" ").join(visited));
actor.printRaw(ColorCodeBuilder.asColorCodes(box));
actor.print(box.create());
}
}