Update text for WorldEdit changes (#401)

* Update for text in WE

* Properly write the legacy converter

* Made the text less thicc

* Update for new text API in WE
This commit is contained in:
Matthew Miller 2019-04-25 19:40:01 +10:00 committed by GitHub
parent abfe3a2eb9
commit 50e62bd0e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 267 additions and 244 deletions

View File

@ -19,9 +19,9 @@
package com.sk89q.worldguard.blacklist;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.blacklist.action.Action;
import com.sk89q.worldguard.blacklist.action.ActionType;
@ -30,10 +30,8 @@ import com.sk89q.worldguard.blacklist.event.EventType;
import com.sk89q.worldguard.blacklist.target.TargetMatcher;
import com.sk89q.worldguard.blacklist.target.TargetMatcherParseException;
import com.sk89q.worldguard.blacklist.target.TargetMatcherParser;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldguard.commands.CommandUtils;
import com.sk89q.worldguard.util.formatting.component.BlacklistNotify;
import java.io.BufferedReader;
import java.io.File;
@ -264,20 +262,7 @@ public class Blacklist {
public void notify(BlacklistEvent event, String comment) {
lastEvent = event;
StyledFragment fragment = new StyledFragment().append(new StyledFragment(Style.GRAY).append("WG: "))
.append(new StyledFragment(Style.PURPLE).append(event.getCauseName()))
.append(new StyledFragment(Style.YELLOW_DARK).append(" (" + event.getDescription() + ") "))
.append(new StyledFragment(Style.WHITE).append(event.getTarget().getFriendlyName() + (comment != null ? " (" + comment + ")" : "") + "."));
broadcastNotification(ColorCodeBuilder.asColorCodes(fragment));
}
/**
* Sends a notification to all subscribing users.
*
* @param msg The message to broadcast
*/
public void broadcastNotification(String msg) {
WorldGuard.getInstance().getPlatform().broadcastNotification(msg);
WorldGuard.getInstance().getPlatform().broadcastNotification(new BlacklistNotify(event, comment).create());
}
public LoadingCache<String, TrackedEvent> getRepeatingEventCache() {

View File

@ -21,7 +21,8 @@ package com.sk89q.worldguard.commands;
import com.google.common.base.Function;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer;
import javax.annotation.Nullable;
@ -42,40 +43,40 @@ public final class CommandUtils {
public static String replaceColorMacros(String str) {
// TODO: Make this more efficient
str = str.replace("`r", Style.RED.toString());
str = str.replace("`R", Style.RED_DARK.toString());
str = str.replace("`r", "&c");
str = str.replace("`R", "&4");
str = str.replace("`y", Style.YELLOW.toString());
str = str.replace("`Y", Style.YELLOW_DARK.toString());
str = str.replace("`y", "&e");
str = str.replace("`Y", "&6");
str = str.replace("`g", Style.GREEN.toString());
str = str.replace("`G", Style.GREEN_DARK.toString());
str = str.replace("`g", "&a");
str = str.replace("`G", "&2");
str = str.replace("`c", Style.CYAN.toString());
str = str.replace("`C", Style.CYAN_DARK.toString());
str = str.replace("`c", "&b");
str = str.replace("`C", "&3");
str = str.replace("`b", Style.BLUE.toString());
str = str.replace("`B", Style.BLUE_DARK.toString());
str = str.replace("`b", "&9");
str = str.replace("`B", "&1");
str = str.replace("`p", Style.PURPLE.toString());
str = str.replace("`P", Style.PURPLE_DARK.toString());
str = str.replace("`p", "&d");
str = str.replace("`P", "&5");
str = str.replace("`0", Style.BLACK.toString());
str = str.replace("`1", Style.GRAY_DARK.toString());
str = str.replace("`2", Style.GRAY.toString());
str = str.replace("`w", Style.WHITE.toString());
str = str.replace("`0", "&0");
str = str.replace("`1", "&8");
str = str.replace("`2", "&7");
str = str.replace("`w", "&F");
str = str.replace("`k", Style.RANDOMIZE.toString());
str = str.replace("`k", "&k");
str = str.replace("`l", Style.BOLD.toString());
str = str.replace("`m", Style.STRIKETHROUGH.toString());
str = str.replace("`n", Style.UNDERLINE.toString());
str = str.replace("`o", Style.ITALIC.toString());
str = str.replace("`l", "&l");
str = str.replace("`m", "&m");
str = str.replace("`n", "&n");
str = str.replace("`o", "&o");
str = str.replace("`x", Style.RESET.toString());
str = str.replace("`x", "&r");
// MC classic
str = Style.translateAlternateColorCodes('&', str);
str = LegacyComponentSerializer.INSTANCE.serialize(LegacyComponentSerializer.INSTANCE.deserialize(str, '&'));
return str;
}
@ -111,4 +112,18 @@ public final class CommandUtils {
};
}
/**
* Return a function that accepts a TextComponent to send a message to the
* given sender.
*
* @param sender the sender
* @return a function
*/
public static java.util.function.Function<TextComponent, ?> messageComponentFunction(final Actor sender) {
return (Function<TextComponent, Object>) s -> {
sender.print(s);
return null;
};
}
}

View File

@ -27,7 +27,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.component.LabelFormat;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
@ -59,9 +59,8 @@ public class ToggleCommands {
if (!wcfg.fireSpreadDisableToggle) {
worldGuard.getPlatform().broadcastNotification(
Style.YELLOW
+ "Fire spread has been globally disabled for '" + world.getName() + "' by "
+ sender.getDisplayName() + ".");
LabelFormat.wrap("Fire spread has been globally disabled for '" + world.getName() + "' by "
+ sender.getDisplayName() + "."));
} else {
sender.print("Fire spread was already globally disabled.");
}
@ -85,9 +84,8 @@ public class ToggleCommands {
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
if (wcfg.fireSpreadDisableToggle) {
worldGuard.getPlatform().broadcastNotification(Style.YELLOW
+ "Fire spread has been globally for '" + world.getName() + "' re-enabled by "
+ sender.getDisplayName() + ".");
worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("Fire spread has been globally for '" + world.getName() + "' re-enabled by "
+ sender.getDisplayName() + "."));
} else {
sender.print("Fire spread was already globally enabled.");
}
@ -117,9 +115,7 @@ public class ToggleCommands {
}
if (!args.hasFlag('s')) {
worldGuard.getPlatform().broadcastNotification(Style.YELLOW
+ "ALL intensive server activity halted by "
+ sender.getDisplayName() + ".");
worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity halted by " + sender.getDisplayName() + "."));
} else {
sender.print("(Silent) ALL intensive server activity halted by " + sender.getDisplayName() + ".");
}
@ -141,8 +137,7 @@ public class ToggleCommands {
}
} else {
if (!args.hasFlag('s')) {
worldGuard.getPlatform().broadcastNotification(Style.YELLOW
+ "ALL intensive server activity is now allowed.");
worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("ALL intensive server activity is now allowed."));
if (!(sender instanceof LocalPlayer)) {
sender.print("ALL intensive server activity is now allowed.");

View File

@ -33,7 +33,7 @@ import com.sk89q.worldedit.command.util.AsyncCommandHelper;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.paste.ActorCallbackPaste;
import com.sk89q.worldedit.util.report.ReportList;
import com.sk89q.worldedit.util.report.SystemInfoReport;
@ -266,18 +266,18 @@ public class WorldGuardCommands {
if (!tasks.isEmpty()) {
tasks.sort(new TaskStateComparator());
StringBuilder builder = new StringBuilder();
builder.append(Style.GRAY);
builder.append(TextColor.GRAY);
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
builder.append(" Running tasks ");
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
builder.append("\n").append(Style.GRAY).append("Note: Some 'running' tasks may be waiting to be start.");
builder.append("\n").append(TextColor.GRAY).append("Note: Some 'running' tasks may be waiting to be start.");
for (Task task : tasks) {
builder.append("\n");
builder.append(Style.BLUE).append("(").append(task.getState().name()).append(") ");
builder.append(Style.YELLOW);
builder.append(TextColor.BLUE).append("(").append(task.getState().name()).append(") ");
builder.append(TextColor.YELLOW);
builder.append(CommandUtils.getOwnerName(task.getOwner()));
builder.append(": ");
builder.append(Style.WHITE);
builder.append(TextColor.WHITE);
builder.append(task.getName());
}
sender.printRaw(builder.toString());

View File

@ -34,7 +34,11 @@ import com.sk89q.worldedit.command.util.MessageFutureCallback.Builder;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
import com.sk89q.worldedit.util.formatting.component.LabelFormat;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
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.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
@ -376,7 +380,7 @@ public final class RegionCommands extends RegionCommandsBase {
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(existing, args.hasFlag('u') ? null : WorldGuard.getInstance().getProfileCache());
ListenableFuture<?> future = Futures.transform(
WorldGuard.getInstance().getExecutorService().submit(printout),
CommandUtils.messageFunction(sender)::apply);
CommandUtils.messageComponentFunction(sender)::apply);
// If it takes too long...
FutureProgressListener.addProgressListener(
@ -513,20 +517,14 @@ public final class RegionCommands extends RegionCommandsBase {
for (int i = 0; i < flagList.size(); i++) {
String flag = flagList.get(i);
if (i % 2 == 0) {
list.append(Style.GRAY);
} else {
list.append(Style.WHITE);
}
list.append(flag);
list.append(TextComponent.of(flag, i % 2 == 0 ? TextColor.GRAY : TextColor.WHITE));
if ((i + 1) < flagList.size()) {
list.append(", ");
}
}
sender.printError("Unknown flag specified: " + flagName);
sender.print(Style.YELLOW + "Available flags: " + list);
sender.print("Available flags: " + list);
return;
}
@ -567,7 +565,7 @@ public final class RegionCommands extends RegionCommandsBase {
throw new CommandException(e.getMessage());
}
sender.print("Region flag " + foundFlag.getName() + " set on '" + existing.getId() + "' to '" + Style.stripColor(value) + "'.");
sender.print("Region flag " + foundFlag.getName() + " set on '" + existing.getId() + "' to '" + value + "'.");
// No value? Clear the flag, if -g isn't specified
} else if (!args.hasFlag('g')) {
@ -599,10 +597,9 @@ public final class RegionCommands extends RegionCommandsBase {
// Print region information
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(existing, null);
printout.append(Style.GRAY);
printout.append("(Current flags: ");
printout.append(SubtleFormat.wrap("(Current flags: "));
printout.appendFlagsList(false);
printout.append(")");
printout.append(SubtleFormat.wrap(")"));
printout.send(sender);
}
@ -678,29 +675,23 @@ public final class RegionCommands extends RegionCommandsBase {
} catch (CircularInheritanceException e) {
// Tell the user what's wrong
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(parent, null);
printout.append(Style.RED);
assert parent != null;
printout.append("Uh oh! Setting '" + parent.getId() + "' to be the parent " +
"of '" + child.getId() + "' would cause circular inheritance.\n");
printout.append(Style.GRAY);
printout.append("(Current inheritance on '" + parent.getId() + "':\n");
printout.append(ErrorFormat.wrap("Uh oh! Setting '", parent.getId(), "' to be the parent of '", child.getId(),
"' would cause circular inheritance.")).newline();
printout.append(SubtleFormat.wrap("(Current inheritance on '", parent.getId(), "':")).newline();
printout.appendParentTree(true);
printout.append(Style.GRAY);
printout.append(")");
printout.append(SubtleFormat.wrap(")"));
printout.send(sender);
return;
}
// Tell the user the current inheritance
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(child, null);
printout.append(Style.YELLOW);
printout.append("Inheritance set for region '" + child.getId() + "'.\n");
printout.append(LabelFormat.wrap("Inheritance set for region '", child.getId(), "'.")).newline();
if (parent != null) {
printout.append(Style.GRAY);
printout.append("(Current inheritance:\n");
printout.append(SubtleFormat.wrap("(Current inheritance:")).newline();
printout.appendParentTree(true);
printout.append(Style.GRAY);
printout.append(")");
printout.append(SubtleFormat.wrap(")"));
}
printout.send(sender);
}

View File

@ -32,7 +32,9 @@ import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
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.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
@ -298,9 +300,8 @@ class RegionCommandsBase {
if (failures.size() > 0) {
String failingList = Joiner.on(", ").join(failures.stream().map(regionManager -> "'" + regionManager.getName() + "'").collect(Collectors.toList()));
sender.printRaw(Style.YELLOW_DARK +
"(Warning: The background saving of region data is failing for these worlds: " + failingList + ". " +
"Your changes are getting lost. See the server log for more information.)");
sender.print(TextComponent.of("(Warning: The background saving of region data is failing for these worlds: " + failingList + ". " +
"Your changes are getting lost. See the server log for more information.)", TextColor.GOLD));
}
}
@ -326,11 +327,9 @@ class RegionCommandsBase {
*/
protected static void informNewUser(Actor sender, RegionManager manager, ProtectedRegion region) {
if (manager.getRegions().size() <= 2) {
sender.printRaw(Style.GRAY +
"(This region is NOW PROTECTED from modification from others. " +
"Don't want that? Use " +
Style.CYAN + "/rg flag " + region.getId() + " passthrough allow" +
Style.GRAY + ")");
sender.print(SubtleFormat.wrap("(This region is NOW PROTECTED from modification from others. Don't want that? Use ")
.append(TextComponent.of("/rg flag " + region.getId() + " passthrough allow", TextColor.AQUA))
.append(TextComponent.of(")", TextColor.GRAY)));
}
}

View File

@ -22,7 +22,13 @@ package com.sk89q.worldguard.commands.region;
import com.sk89q.squirrelid.cache.ProfileCache;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
import com.sk89q.worldedit.util.formatting.component.LabelFormat;
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.worldguard.WorldGuard;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.Flag;
@ -40,12 +46,12 @@ import javax.annotation.Nullable;
* Create a region printout, as used in /region info to show information about
* a region.
*/
public class RegionPrintoutBuilder implements Callable<String> {
public class RegionPrintoutBuilder implements Callable<TextComponent> {
private final ProtectedRegion region;
@Nullable
private final ProfileCache cache;
private final StringBuilder builder = new StringBuilder();
private final TextComponentProducer builder = new TextComponentProducer();
/**
* Create a new instance with a region to report on.
@ -62,26 +68,22 @@ public class RegionPrintoutBuilder implements Callable<String> {
* Add a new line.
*/
private void newLine() {
builder.append("\n");
builder.append(Component.newline());
}
/**
* Add region name, type, and priority.
*/
public void appendBasics() {
builder.append(Style.BLUE);
builder.append("Region: ");
builder.append(Style.YELLOW);
builder.append(region.getId());
builder.append(TextComponent.of("Region: ", TextColor.BLUE));
builder.append(TextComponent.of(region.getId(), TextColor.YELLOW));
builder.append(Style.GRAY);
builder.append(" (type=");
builder.append(region.getType().getName());
builder.append(TextComponent.of(" (type=", TextColor.GRAY));
builder.append(TextComponent.of(region.getType().getName()));
builder.append(Style.GRAY);
builder.append(", priority=");
builder.append(region.getPriority());
builder.append(")");
builder.append(TextComponent.of(", priority=", TextColor.GRAY));
builder.append(TextComponent.of(String.valueOf(region.getPriority())));
builder.append(TextComponent.of(")", TextColor.GRAY));
newLine();
}
@ -90,8 +92,7 @@ public class RegionPrintoutBuilder implements Callable<String> {
* Add information about flags.
*/
public void appendFlags() {
builder.append(Style.BLUE);
builder.append("Flags: ");
builder.append(TextComponent.of("Flags: ", TextColor.BLUE));
appendFlagsList(true);
@ -115,11 +116,7 @@ public class RegionPrintoutBuilder implements Callable<String> {
}
if (hasFlags) {
builder.append(", ");
} else {
if (useColors) {
builder.append(Style.YELLOW);
}
builder.append(TextComponent.of(", "));
}
RegionGroupFlag groupFlag = flag.getRegionGroupFlag();
@ -127,23 +124,21 @@ public class RegionPrintoutBuilder implements Callable<String> {
group = region.getFlag(groupFlag);
}
String flagString;
if (group == null) {
builder.append(flag.getName()).append(": ")
.append(Style.stripColor(String.valueOf(val)));
flagString = flag.getName() + ": " + val;
} else {
builder.append(flag.getName()).append(" -g ")
.append(group).append(": ")
.append(Style.stripColor(String.valueOf(val)));
flagString = flag.getName() + " -g "+ group + ": " + val;
}
builder.append(TextComponent.of(flagString, !(hasFlags && useColors) ? TextColor.YELLOW : TextColor.WHITE));
hasFlags = true;
}
if (!hasFlags) {
if (useColors) {
builder.append(Style.RED);
}
builder.append("(none)");
builder.append(TextComponent.of("(none)", useColors ? TextColor.RED : TextColor.WHITE));
}
}
@ -179,27 +174,24 @@ public class RegionPrintoutBuilder implements Callable<String> {
int indent = 0;
while (it.hasPrevious()) {
ProtectedRegion cur = it.previous();
if (useColors) {
builder.append(Style.GREEN);
}
StringBuilder nameString = new StringBuilder();
// Put symbol for child
if (indent != 0) {
for (int i = 0; i < indent; i++) {
builder.append(" ");
nameString.append(" ");
}
builder.append("\u2517");
nameString.append("\u2517");
}
// Put name
builder.append(cur.getId());
nameString.append(cur.getId());
builder.append(TextComponent.of(nameString.toString(), useColors ? TextColor.GREEN : TextColor.WHITE));
// Put (parent)
if (!cur.equals(region)) {
if (useColors) {
builder.append(Style.GRAY);
}
builder.append(" (parent, priority=").append(cur.getPriority()).append(")");
builder.append(TextComponent.of(" (parent, priority=" + cur.getPriority() + ")", useColors ? TextColor.GRAY : TextColor.WHITE));
}
indent++;
@ -211,24 +203,20 @@ public class RegionPrintoutBuilder implements Callable<String> {
* Add information about members.
*/
public void appendDomain() {
builder.append(Style.BLUE);
builder.append("Owners: ");
builder.append(TextComponent.of("Owners: ", TextColor.BLUE));
addDomainString(region.getOwners());
newLine();
builder.append(Style.BLUE);
builder.append("Members: ");
builder.append(TextComponent.of("Members: ", TextColor.BLUE));
addDomainString(region.getMembers());
newLine();
}
private void addDomainString(DefaultDomain domain) {
if (domain.size() != 0) {
builder.append(Style.YELLOW);
builder.append(domain.toUserFriendlyString(cache));
builder.append(LabelFormat.wrap(domain.toUserFriendlyString(cache)));
} else {
builder.append(Style.RED);
builder.append("(none)");
builder.append(ErrorFormat.wrap("(none)"));
}
}
@ -238,20 +226,20 @@ public class RegionPrintoutBuilder implements Callable<String> {
public void appendBounds() {
BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint();
builder.append(Style.BLUE);
builder.append("Bounds:");
builder.append(Style.YELLOW);
builder.append(" (").append(min.getBlockX()).append(",").append(min.getBlockY()).append(",").append(min.getBlockZ()).append(")");
builder.append(" -> (").append(max.getBlockX()).append(",").append(max.getBlockY()).append(",").append(max.getBlockZ()).append(")");
builder.append(TextComponent.of("Bounds:", TextColor.BLUE));
builder.append(TextComponent.of(" (" + min.getBlockX() + "," + min.getBlockY() + "," + min.getBlockZ() + ")"
+ " -> (" + max.getBlockX() + "," + max.getBlockY() + "," + max.getBlockZ() + ")", TextColor.YELLOW));
newLine();
}
private void appendRegionInformation() {
builder.append(Style.GRAY);
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
builder.append(" Region Info ");
builder.append("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
TextComponent format = SubtleFormat.wrap(
"\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550",
" Region Info ",
"\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"
);
builder.append(format);
newLine();
appendBasics();
appendFlags();
@ -260,15 +248,15 @@ public class RegionPrintoutBuilder implements Callable<String> {
appendBounds();
if (cache != null) {
builder.append(Style.GRAY).append("Any names suffixed by * are 'last seen names' and may not be up to date.");
builder.append(SubtleFormat.wrap("Any names suffixed by * are 'last seen names' and may not be up to date."));
newLine();
}
}
@Override
public String call() throws Exception {
public TextComponent call() throws Exception {
appendRegionInformation();
return builder.toString();
return toComponent();
}
/**
@ -277,65 +265,21 @@ public class RegionPrintoutBuilder implements Callable<String> {
* @param sender the recipient
*/
public void send(Actor sender) {
sender.printRaw(toString());
sender.print(toComponent());
}
public StringBuilder append(boolean b) {
return builder.append(b);
public TextComponentProducer append(String str) {
return builder.append(TextComponent.of(str));
}
public StringBuilder append(char c) {
return builder.append(c);
public TextComponentProducer append(TextComponent component) {
return builder.append(component);
}
public StringBuilder append(char[] str, int offset, int len) {
return builder.append(str, offset, len);
public TextComponent toComponent() {
return builder.create();
}
public StringBuilder append(char[] str) {
return builder.append(str);
}
public StringBuilder append(CharSequence s, int start, int end) {
return builder.append(s, start, end);
}
public StringBuilder append(CharSequence s) {
return builder.append(s);
}
public StringBuilder append(double d) {
return builder.append(d);
}
public StringBuilder append(float f) {
return builder.append(f);
}
public StringBuilder append(int i) {
return builder.append(i);
}
public StringBuilder append(long lng) {
return builder.append(lng);
}
public StringBuilder append(Object obj) {
return builder.append(obj);
}
public StringBuilder append(String str) {
return builder.append(str);
}
public StringBuilder append(StringBuffer sb) {
return builder.append(sb);
}
public StringBuilder appendCodePoint(int codePoint) {
return builder.appendCodePoint(codePoint);
}
@Override
public String toString() {
return builder.toString().trim();

View File

@ -19,6 +19,7 @@
package com.sk89q.worldguard.internal.platform;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.report.ReportList;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldguard.LocalPlayer;
@ -87,6 +88,15 @@ public interface WorldGuardPlatform {
*/
void broadcastNotification(String message);
/**
* Notifies all with the worldguard.notify permission.
* This will check both superperms and WEPIF,
* but makes sure WEPIF checks don't result in duplicate notifications
*
* @param component The notification to broadcast
*/
void broadcastNotification(TextComponent component);
/**
* Load the platform
*/

View File

@ -19,9 +19,11 @@
package com.sk89q.worldguard.protection.flags;
import com.sk89q.worldedit.util.formatting.ColorCodeBuilder;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.StyledFragment;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration;
import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.weather.WeatherType;
@ -155,14 +157,17 @@ public final class Flags {
// deny messages
public static final StringFlag DENY_MESSAGE = register(new StringFlag("deny-message",
ColorCodeBuilder.asColorCodes(new StyledFragment().append(new StyledFragment(Style.RED, Style.BOLD).append("Hey!"))
.append(new StyledFragment(Style.GRAY).append(" Sorry, but you can't %what% here.")))));
LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of("").append(TextComponent.of("Hey!",
TextColor.RED, Sets.newHashSet(TextDecoration.BOLD)))
.append(TextComponent.of(" Sorry, but you can't %what% here.", TextColor.GRAY)))));
public static final StringFlag ENTRY_DENY_MESSAGE = register(new StringFlag("entry-deny-message",
ColorCodeBuilder.asColorCodes(new StyledFragment().append(new StyledFragment(Style.RED, Style.BOLD).append("Hey!"))
.append(new StyledFragment(Style.GRAY).append(" You are not permitted to enter this area.")))));
LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of("").append(TextComponent.of("Hey!",
TextColor.RED, Sets.newHashSet(TextDecoration.BOLD)))
.append(TextComponent.of(" You are not permitted to enter this area.", TextColor.GRAY)))));
public static final StringFlag EXIT_DENY_MESSAGE = register(new StringFlag("exit-deny-message",
ColorCodeBuilder.asColorCodes(new StyledFragment().append(new StyledFragment(Style.RED, Style.BOLD).append("Hey!"))
.append(new StyledFragment(Style.GRAY).append(" You are not permitted to leave this area.")))));
LegacyComponentSerializer.INSTANCE.serialize(TextComponent.of("").append(TextComponent.of("Hey!",
TextColor.RED, Sets.newHashSet(TextDecoration.BOLD)))
.append(TextComponent.of(" You are not permitted to leave this area.", TextColor.GRAY)))));
private Flags() {
}
@ -196,5 +201,6 @@ public final class Flags {
/**
* Dummy method to call that initialises the class.
*/
public static void registerAll() {}
public static void registerAll() {
}
}

View File

@ -20,9 +20,6 @@
package com.sk89q.worldguard.session.handler;
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.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
@ -30,6 +27,7 @@ import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.util.formatting.component.Notify;
public class NotifyEntryFlag extends FlagValueChangeHandler<Boolean> {
@ -62,11 +60,7 @@ public class NotifyEntryFlag extends FlagValueChangeHandler<Boolean> {
regionList.append(region.getId());
}
WorldGuard.getInstance().getPlatform().broadcastNotification(
ColorCodeBuilder.asColorCodes(new StyledFragment().append(new StyledFragment(Style.GRAY).append("WG: "))
.append(new StyledFragment(Style.PURPLE).append(player.getName()))
.append(new StyledFragment(Style.YELLOW_DARK).append(" entered NOTIFY region: " + regionList)))
);
WorldGuard.getInstance().getPlatform().broadcastNotification(new Notify(player.getName(), " entered NOTIFY region: " + regionList).create());
return true;
}

View File

@ -20,15 +20,13 @@
package com.sk89q.worldguard.session.handler;
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.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.util.formatting.component.Notify;
public class NotifyExitFlag extends FlagValueChangeHandler<Boolean> {
@ -58,11 +56,7 @@ public class NotifyExitFlag extends FlagValueChangeHandler<Boolean> {
@Override
protected boolean onAbsentValue(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, Boolean lastValue, MoveType moveType) {
WorldGuard.getInstance().getPlatform().broadcastNotification(
ColorCodeBuilder.asColorCodes(new StyledFragment().append(new StyledFragment(Style.GRAY).append("WG: "))
.append(new StyledFragment(Style.PURPLE).append(player.getName()))
.append(new StyledFragment(Style.YELLOW_DARK).append(" left NOTIFY region")))
);
WorldGuard.getInstance().getPlatform().broadcastNotification(new Notify(player.getName(), " left NOTIFY region").create());
return true;
}
}

View File

@ -0,0 +1,31 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.formatting.component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldguard.blacklist.event.BlacklistEvent;
public class BlacklistNotify extends Notify {
public BlacklistNotify(BlacklistEvent event, String comment) {
super(event.getCauseName(), " (" + event.getDescription() + ") ");
append(TextComponent.of(event.getTarget().getFriendlyName() + (comment != null ? " (" + comment + ")" : "") + ".", TextColor.WHITE));
}
}

View File

@ -0,0 +1,32 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util.formatting.component;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
public class Notify extends TextComponentProducer {
public Notify(String cause, String description) {
append(TextComponent.of("WG: ", TextColor.GRAY));
append(TextComponent.of(cause, TextColor.LIGHT_PURPLE));
append(TextComponent.of(description, TextColor.GOLD));
}
}

View File

@ -20,7 +20,9 @@
package com.sk89q.worldguard.util.logging;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import java.util.logging.Formatter;
import java.util.logging.Handler;
@ -70,6 +72,6 @@ public class LoggerToChatHandler extends Handler {
*/
@Override
public void publish(LogRecord record) {
player.printDebug(record.getLevel().getName() + ": " + Style.WHITE + formatter.format(record));
player.print(SubtleFormat.wrap(record.getLevel().getName() + ": ").append(TextComponent.of(formatter.format(record), TextColor.WHITE)));
}
}

View File

@ -27,6 +27,7 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.weather.WeatherType;
@ -191,6 +192,11 @@ public class TestPlayer extends AbstractPlayerActor implements LocalPlayer {
}
@Override
public void print(TextComponent component) {
}
@Override
public String[] getGroups() {
return groups.toArray(new String[groups.size()]);

View File

@ -23,7 +23,8 @@ import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.Style;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.paste.ActorCallbackPaste;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
@ -191,7 +192,7 @@ public class BukkitDebugHandler implements DebugHandler {
Player bukkitTarget = BukkitAdapter.adapt(target);
Block block = traceBlock(bukkitSender, bukkitTarget, fromTarget);
sender.printRaw(Style.CYAN + "Testing BLOCK BREAK at " + Style.CYAN_DARK + block);
sender.print(TextComponent.of("Testing BLOCK BREAK at ", TextColor.AQUA).append(TextComponent.of(block.toString(), TextColor.DARK_AQUA)));
LoggingBlockBreakEvent event = new LoggingBlockBreakEvent(block, bukkitTarget);
testEvent(bukkitSender, bukkitTarget, event, stackTraceMode);
}
@ -202,7 +203,7 @@ public class BukkitDebugHandler implements DebugHandler {
Player bukkitTarget = BukkitAdapter.adapt(target);
Block block = traceBlock(bukkitSender, bukkitTarget, fromTarget);
sender.printRaw(Style.CYAN + "Testing BLOCK PLACE at " + Style.CYAN_DARK + block);
sender.print(TextComponent.of("Testing BLOCK PLACE at ", TextColor.AQUA).append(TextComponent.of(block.toString(), TextColor.DARK_AQUA)));
LoggingBlockPlaceEvent event = new LoggingBlockPlaceEvent(block, block.getState(), block.getRelative(BlockFace.DOWN), bukkitTarget.getItemInHand(), bukkitTarget, true);
testEvent(bukkitSender, bukkitTarget, event, stackTraceMode);
}
@ -213,7 +214,7 @@ public class BukkitDebugHandler implements DebugHandler {
Player bukkitTarget = BukkitAdapter.adapt(target);
Block block = traceBlock(bukkitSender, bukkitTarget, fromTarget);
sender.printRaw(Style.CYAN + "Testing BLOCK INTERACT at " + Style.CYAN_DARK + block);
sender.print(TextComponent.of("Testing BLOCK INTERACT at ", TextColor.AQUA).append(TextComponent.of(block.toString(), TextColor.DARK_AQUA)));
LoggingPlayerInteractEvent event = new LoggingPlayerInteractEvent(bukkitTarget, Action.RIGHT_CLICK_BLOCK, bukkitTarget.getItemInHand(), block, BlockFace.SOUTH);
testEvent(bukkitSender, bukkitTarget, event, stackTraceMode);
}
@ -223,7 +224,7 @@ public class BukkitDebugHandler implements DebugHandler {
CommandSender bukkitSender = plugin.unwrapActor(sender);
Player bukkitTarget = BukkitAdapter.adapt(target);
Entity entity = traceEntity(bukkitSender, bukkitTarget, fromTarget);
sender.printRaw(Style.CYAN + "Testing ENTITY DAMAGE on " + Style.CYAN_DARK + entity);
sender.print(TextComponent.of("Testing ENTITY DAMAGE at ", TextColor.AQUA).append(TextComponent.of(entity.toString(), TextColor.DARK_AQUA)));
LoggingEntityDamageByEntityEvent event = new LoggingEntityDamageByEntityEvent(bukkitTarget, entity, EntityDamageEvent.DamageCause.ENTITY_ATTACK, 1);
testEvent(bukkitSender, bukkitTarget, event, stackTraceMode);
}

View File

@ -19,6 +19,9 @@
package com.sk89q.worldguard.bukkit;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.report.ReportList;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
@ -44,7 +47,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permissible;
import java.nio.file.Path;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class BukkitWorldGuardPlatform implements WorldGuardPlatform {
@ -100,6 +105,19 @@ public class BukkitWorldGuardPlatform implements WorldGuardPlatform {
WorldGuard.logger.info(message);
}
@Override
public void broadcastNotification(TextComponent component) {
List<LocalPlayer>
wgPlayers = Bukkit.getServer().getOnlinePlayers().stream().map(player -> WorldGuardPlugin.inst().wrapPlayer(player)).collect(
Collectors.toList());
for (LocalPlayer player : wgPlayers) {
if (player.hasPermission("worldguard.notify")) {
player.print(component);
}
}
}
@Override
public void load() {
stringMatcher = new BukkitStringMatcher();