mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-09-30 07:37:31 +02:00
Workaround colors on newlines of string flags issue in text lib.
Also fix newline lookbehind replacement, and only replace color macros in string flags.
This commit is contained in:
parent
d410e1f84e
commit
e792dd6f98
@ -24,7 +24,9 @@
|
|||||||
import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer;
|
import com.sk89q.worldedit.util.formatting.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command-related utility methods.
|
* Command-related utility methods.
|
||||||
@ -76,7 +78,12 @@ public static String replaceColorMacros(String str) {
|
|||||||
str = str.replace("`x", "&r");
|
str = str.replace("`x", "&r");
|
||||||
|
|
||||||
// MC classic
|
// MC classic
|
||||||
str = LegacyComponentSerializer.INSTANCE.serialize(LegacyComponentSerializer.INSTANCE.deserialize(str, '&'));
|
// FIXME: workaround for https://github.com/KyoriPowered/text/issues/50
|
||||||
|
// remove when fixed upstream and updated in WorldEdit
|
||||||
|
str = Arrays.stream(str.split("\n")).map(line -> {
|
||||||
|
TextComponent comp = LegacyComponentSerializer.INSTANCE.deserialize(line, '&');
|
||||||
|
return LegacyComponentSerializer.INSTANCE.serialize(comp);
|
||||||
|
}).collect(Collectors.joining("\n"));
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -500,11 +500,6 @@ public void flag(CommandContext args, Actor sender) throws CommandException {
|
|||||||
value = "";
|
value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add color codes
|
|
||||||
if (value != null) {
|
|
||||||
value = CommandUtils.replaceColorMacros(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lookup the existing region
|
// Lookup the existing region
|
||||||
RegionManager manager = checkRegionManager(world);
|
RegionManager manager = checkRegionManager(world);
|
||||||
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
|
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
|
||||||
@ -572,7 +567,7 @@ public void flag(CommandContext args, Actor sender) throws CommandException {
|
|||||||
if (value != null) {
|
if (value != null) {
|
||||||
// Set the flag if [value] was given even if [-g group] was given as well
|
// Set the flag if [value] was given even if [-g group] was given as well
|
||||||
try {
|
try {
|
||||||
setFlag(existing, foundFlag, sender, value);
|
value = setFlag(existing, foundFlag, sender, value).toString();
|
||||||
} catch (InvalidFlagFormat e) {
|
} catch (InvalidFlagFormat e) {
|
||||||
throw new CommandException(e.getMessage());
|
throw new CommandException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -392,8 +392,10 @@ protected static void setPlayerSelection(LocalPlayer player, ProtectedRegion reg
|
|||||||
* @param value the value
|
* @param value the value
|
||||||
* @throws InvalidFlagFormat thrown if the value is invalid
|
* @throws InvalidFlagFormat thrown if the value is invalid
|
||||||
*/
|
*/
|
||||||
protected static <V> void setFlag(ProtectedRegion region, Flag<V> flag, Actor sender, String value) throws InvalidFlagFormat {
|
protected static <V> V setFlag(ProtectedRegion region, Flag<V> flag, Actor sender, String value) throws InvalidFlagFormat {
|
||||||
region.setFlag(flag, flag.parseInput(FlagContext.create().setSender(sender).setInput(value).setObject("region", region).build()));
|
V val = flag.parseInput(FlagContext.create().setSender(sender).setInput(value).setObject("region", region).build());
|
||||||
|
region.setFlag(flag, val);
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection.flags;
|
package com.sk89q.worldguard.protection.flags;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.commands.CommandUtils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +58,10 @@ public String getDefault() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String parseInput(FlagContext context) throws InvalidFlagFormat {
|
public String parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||||
return context.getUserInput().replaceAll("(?!<\\\\)\\\\n", "\n").replaceAll("\\\\\\\\n", "\\n");
|
String lines = context.getUserInput().replaceAll("(?<!\\\\)\\\\n", "\n").replaceAll("\\\\\\\\n", "\\\\n");
|
||||||
|
// Add color codes
|
||||||
|
lines = CommandUtils.replaceColorMacros(lines);
|
||||||
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user