Merge branch '2.x' into build/junit-results-actions
This commit is contained in:
commit
8907317041
|
@ -16,18 +16,18 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Checkout Git repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2
|
||||
uses: gradle/gradle-build-action@v3
|
||||
|
||||
- name: Build with Gradle
|
||||
run: |
|
||||
|
@ -41,7 +41,7 @@ jobs:
|
|||
report_paths: '**/build/test-results/test*/TEST-*.xml'
|
||||
|
||||
- name: Archive plugin jars on GitHub
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: EssentialsX plugin jars
|
||||
path: jars/
|
||||
|
@ -67,7 +67,7 @@ jobs:
|
|||
cp -r EssentialsXMPP/build/docs/javadoc/ javadocs/EssentialsXMPP/
|
||||
|
||||
- name: Archive Javadocs
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: javadocs
|
||||
path: javadocs/
|
||||
|
@ -80,12 +80,12 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v3
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 16
|
||||
|
||||
- name: Download Javadocs
|
||||
uses: actions/download-artifact@v3
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: javadocs
|
||||
path: javadocs/
|
||||
|
|
|
@ -18,18 +18,18 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Checkout Git repo
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v2
|
||||
uses: gradle/gradle-build-action@v3
|
||||
|
||||
- name: Build with Gradle
|
||||
run: |
|
||||
|
@ -43,7 +43,7 @@ jobs:
|
|||
report_paths: '**/build/test-results/test*/TEST-*.xml'
|
||||
|
||||
- name: Archive plugin jars on GitHub
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: EssentialsX plugin jars
|
||||
path: jars/
|
||||
|
|
|
@ -657,6 +657,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||
final PluginManager pm = getServer().getPluginManager();
|
||||
registerListeners(pm);
|
||||
|
||||
AdventureUtil.setEss(this);
|
||||
bukkitAudience = BukkitAudiences.create(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -182,8 +182,10 @@ public class I18n implements net.ess3.api.II18n {
|
|||
}
|
||||
|
||||
final Object[] processedArgs = mutateArgs(objects, arg -> {
|
||||
final String str = arg instanceof AdventureUtil.ParsedPlaceholder ? arg.toString() : AdventureUtil.miniMessage().escapeTags(arg.toString());
|
||||
return AdventureUtil.legacyToMini(str);
|
||||
if (arg instanceof AdventureUtil.ParsedPlaceholder) {
|
||||
return arg.toString();
|
||||
}
|
||||
return AdventureUtil.legacyToMini(AdventureUtil.miniMessage().escapeTags(arg.toString()));
|
||||
});
|
||||
|
||||
return messageFormat.format(processedArgs).replace(' ', ' '); // replace nbsp with a space
|
||||
|
|
|
@ -53,6 +53,8 @@ import static com.earth2me.essentials.I18n.tlLiteral;
|
|||
public class Settings implements net.ess3.api.ISettings {
|
||||
private static final BigDecimal DEFAULT_MAX_MONEY = new BigDecimal("10000000000000");
|
||||
private static final BigDecimal DEFAULT_MIN_MONEY = new BigDecimal("-10000000000000");
|
||||
private static final Tag DEFAULT_PRIMARY_COLOR = Tag.styling(NamedTextColor.GOLD);
|
||||
private static final Tag DEFAULT_SECONDARY_COLOR = Tag.styling(NamedTextColor.RED);
|
||||
private final transient EssentialsConfiguration config;
|
||||
private final transient IEssentials ess;
|
||||
private final transient AtomicInteger reloadCount = new AtomicInteger(0);
|
||||
|
@ -141,8 +143,8 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
private double maxProjectileSpeed;
|
||||
private boolean removeEffectsOnHeal;
|
||||
private Map<String, String> worldAliases;
|
||||
private Tag primaryColor = Tag.styling(NamedTextColor.GOLD);
|
||||
private Tag secondaryColor = Tag.styling(NamedTextColor.RED);
|
||||
private Tag primaryColor = DEFAULT_PRIMARY_COLOR;
|
||||
private Tag secondaryColor = DEFAULT_SECONDARY_COLOR;
|
||||
|
||||
public Settings(final IEssentials ess) {
|
||||
this.ess = ess;
|
||||
|
@ -1970,7 +1972,8 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
|
||||
private Tag _getPrimaryColor() {
|
||||
final String color = config.getString("message-colors.primary", "#ffaa00");
|
||||
return Tag.styling(_getTagColor(color, NamedTextColor.GOLD));
|
||||
final TextColor textColor = _getTagColor(color);
|
||||
return textColor != null ? Tag.styling(textColor) : DEFAULT_PRIMARY_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1980,24 +1983,23 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
|
||||
private Tag _getSecondaryColor() {
|
||||
final String color = config.getString("message-colors.secondary", "#ff5555");
|
||||
return Tag.styling(_getTagColor(color, NamedTextColor.RED));
|
||||
final TextColor textColor = _getTagColor(color);
|
||||
return textColor != null ? Tag.styling(textColor) : DEFAULT_SECONDARY_COLOR;
|
||||
}
|
||||
|
||||
private TextColor _getTagColor(final String color, final TextColor def) {
|
||||
private TextColor _getTagColor(final String color) {
|
||||
try {
|
||||
if (color.startsWith("#") && color.length() == 7 && NumberUtil.isNumeric(color.substring(1))) {
|
||||
if (color.startsWith("#") && color.length() == 7 && NumberUtil.isHexadecimal(color.substring(1))) {
|
||||
return TextColor.color(Color.fromRGB(Integer.decode(color)).asRGB());
|
||||
}
|
||||
|
||||
if (color.length() == 1) {
|
||||
final NamedTextColor named = AdventureUtil.fromChar(color.charAt(0));
|
||||
return named != null ? named : def;
|
||||
return AdventureUtil.fromChar(color.charAt(0));
|
||||
}
|
||||
|
||||
final NamedTextColor named = NamedTextColor.NAMES.value(color.toLowerCase(Locale.ENGLISH));
|
||||
return named != null ? named : def;
|
||||
return NamedTextColor.NAMES.value(color.toLowerCase(Locale.ENGLISH));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
return def;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ public class Commandbroadcastworld extends EssentialsCommand {
|
|||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length == 0) {
|
||||
if (args.length < 2) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
World world = user.getWorld();
|
||||
String message = getFinalArg(args, 0);
|
||||
if (args.length > 1 && ess.getSettings().isAllowWorldInBroadcastworld()) {
|
||||
if (ess.getSettings().isAllowWorldInBroadcastworld()) {
|
||||
final World argWorld = ess.getWorld(args[0]);
|
||||
if (argWorld != null) {
|
||||
world = argWorld;
|
||||
|
@ -53,7 +53,7 @@ public class Commandbroadcastworld extends EssentialsCommand {
|
|||
if (message.isEmpty()) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
ess.broadcastTl(null, u -> u.getBase().getWorld().equals(world), true, "broadcast", message, AdventureUtil.parsed(AdventureUtil.legacyToMini(name)));
|
||||
ess.broadcastTl(null, u -> !u.getBase().getWorld().equals(world), true, "broadcast", message, AdventureUtil.parsed(AdventureUtil.legacyToMini(name)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,8 +17,6 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
|
||||
public class Commandme extends EssentialsCommand {
|
||||
public Commandme() {
|
||||
super("me");
|
||||
|
@ -109,7 +107,7 @@ public class Commandme extends EssentialsCommand {
|
|||
String message = getFinalArg(args, 0);
|
||||
message = FormatUtil.replaceFormat(message);
|
||||
|
||||
ess.getServer().broadcastMessage(tlLiteral("action", "@", message));
|
||||
ess.broadcastTl("action", "@", message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,20 +8,14 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
|||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class AdventureUtil {
|
||||
private static final LegacyComponentSerializer LEGACY_SERIALIZER;
|
||||
private static final MiniMessage MINI_MESSAGE_INSTANCE;
|
||||
private static IEssentials ess;
|
||||
private static final Pattern NAMED_PATTERN = Pattern.compile(ChatColor.COLOR_CHAR + "[0-9a-fk-orA-FK-OR]");
|
||||
private static final Pattern HEX_PATTERN = Pattern.compile(ChatColor.COLOR_CHAR + "x((?:" + ChatColor.COLOR_CHAR + "[0-9a-fA-F]){6})");
|
||||
private static final MiniMessage MINI_MESSAGE_NO_TAGS;
|
||||
private static final String LOOKUP = "0123456789abcdefklmnor";
|
||||
private static final String[] MINI_TAGS = new String[] {"black", "dark_blue", "dark_green", "dark_aqua", "dark_red", "dark_purple", "gold", "gray", "dark_gray", "blue", "green", "aqua", "red", "light_purple", "yellow", "white", "obf", "b", "st", "u", "i", "reset"};
|
||||
private static final NamedTextColor[] COLORS = new NamedTextColor[] {NamedTextColor.BLACK, NamedTextColor.DARK_BLUE, NamedTextColor.DARK_GREEN, NamedTextColor.DARK_AQUA, NamedTextColor.DARK_RED, NamedTextColor.DARK_PURPLE, NamedTextColor.GOLD, NamedTextColor.GRAY, NamedTextColor.DARK_GRAY, NamedTextColor.BLUE, NamedTextColor.GREEN, NamedTextColor.AQUA, NamedTextColor.RED, NamedTextColor.LIGHT_PURPLE, NamedTextColor.YELLOW, NamedTextColor.WHITE};
|
||||
private static final NamedTextColor[] COLORS = new NamedTextColor[]{NamedTextColor.BLACK, NamedTextColor.DARK_BLUE, NamedTextColor.DARK_GREEN, NamedTextColor.DARK_AQUA, NamedTextColor.DARK_RED, NamedTextColor.DARK_PURPLE, NamedTextColor.GOLD, NamedTextColor.GRAY, NamedTextColor.DARK_GRAY, NamedTextColor.BLUE, NamedTextColor.GREEN, NamedTextColor.AQUA, NamedTextColor.RED, NamedTextColor.LIGHT_PURPLE, NamedTextColor.YELLOW, NamedTextColor.WHITE};
|
||||
private static IEssentials ess;
|
||||
private static MiniMessage miniMessageInstance;
|
||||
|
||||
static {
|
||||
final LegacyComponentSerializer.Builder builder = LegacyComponentSerializer.builder().flattener(ComponentFlattener.basic()).useUnusualXRepeatedCharacterHexFormat();
|
||||
|
@ -30,14 +24,9 @@ public final class AdventureUtil {
|
|||
}
|
||||
LEGACY_SERIALIZER = builder.build();
|
||||
|
||||
MINI_MESSAGE_INSTANCE = MiniMessage.builder()
|
||||
.tags(TagResolver.builder()
|
||||
.resolvers(TagResolver.standard())
|
||||
.resolver(TagResolver.resolver("primary", supplyTag(true)))
|
||||
.resolver(TagResolver.resolver("secondary", supplyTag(false)))
|
||||
.build())
|
||||
.build();
|
||||
MINI_MESSAGE_NO_TAGS = MiniMessage.miniMessage();
|
||||
|
||||
miniMessageInstance = createMiniMessageInstance();
|
||||
}
|
||||
|
||||
private AdventureUtil() {
|
||||
|
@ -45,10 +34,21 @@ public final class AdventureUtil {
|
|||
|
||||
public static void setEss(final IEssentials ess) {
|
||||
AdventureUtil.ess = ess;
|
||||
miniMessageInstance = createMiniMessageInstance();
|
||||
}
|
||||
|
||||
private static MiniMessage createMiniMessageInstance() {
|
||||
return MiniMessage.builder()
|
||||
.tags(TagResolver.builder()
|
||||
.resolvers(TagResolver.standard())
|
||||
.resolver(TagResolver.resolver("primary", supplyTag(true)))
|
||||
.resolver(TagResolver.resolver("secondary", supplyTag(false)))
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static MiniMessage miniMessage() {
|
||||
return MINI_MESSAGE_INSTANCE;
|
||||
return miniMessageInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,37 +81,16 @@ public final class AdventureUtil {
|
|||
|
||||
/**
|
||||
* Converts a section sign legacy string to a MiniMessage string.
|
||||
*
|
||||
* @param useCustomTags true if gold and red colors should use primary and secondary tags instead.
|
||||
*/
|
||||
public static String legacyToMini(String text, boolean useCustomTags) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Matcher matcher = HEX_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
final String code = matcher.group(1).replace(String.valueOf(ChatColor.COLOR_CHAR), "");
|
||||
matcher.appendReplacement(buffer, "<#" + code + ">");
|
||||
final Component deserializedText = LEGACY_SERIALIZER.deserialize(text);
|
||||
if (useCustomTags) {
|
||||
return miniMessageInstance.serialize(deserializedText);
|
||||
} else {
|
||||
return MINI_MESSAGE_NO_TAGS.serialize(deserializedText);
|
||||
}
|
||||
matcher.appendTail(buffer);
|
||||
|
||||
matcher = NAMED_PATTERN.matcher(buffer.toString());
|
||||
buffer = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
final int format = LOOKUP.indexOf(Character.toLowerCase(matcher.group().charAt(1)));
|
||||
if (format != -1) {
|
||||
String tagName = MINI_TAGS[format];
|
||||
if (useCustomTags) {
|
||||
if (tagName.equals("gold")) {
|
||||
tagName = "primary";
|
||||
} else if (tagName.equals("red")) {
|
||||
tagName = "secondary";
|
||||
}
|
||||
}
|
||||
|
||||
matcher.appendReplacement(buffer, "<" + tagName + ">");
|
||||
}
|
||||
}
|
||||
matcher.appendTail(buffer);
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,6 +40,13 @@ public final class FormatUtil {
|
|||
return ChatColor.stripColor(input);
|
||||
}
|
||||
|
||||
public static String stripMiniFormat(final String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
return AdventureUtil.miniMessage().stripTags(input);
|
||||
}
|
||||
|
||||
//This method is used to simply strip the & convention colour codes
|
||||
public static String stripEssentialsFormat(final String input) {
|
||||
if (input == null) {
|
||||
|
|
|
@ -129,6 +129,15 @@ public final class NumberUtil {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean isHexadecimal(final String sNum) {
|
||||
try {
|
||||
Integer.parseInt(sNum, 16);
|
||||
return true;
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Backport from Guava.
|
||||
*/
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.essentialsx.discord.interactions.commands;
|
|||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.PlayerList;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionCommandArgument;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionCommandArgumentType;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
||||
|
@ -45,8 +46,8 @@ public class ListCommand extends InteractionCommandImpl {
|
|||
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
for (final String str : output) {
|
||||
stringBuilder.append(str).append("\n");
|
||||
stringBuilder.append(FormatUtil.stripMiniFormat(str)).append("\n");
|
||||
}
|
||||
event.reply(MessageUtil.sanitizeDiscordMarkdown(stringBuilder.substring(0, stringBuilder.length() - 2)));
|
||||
event.reply(MessageUtil.sanitizeDiscordMarkdown(stringBuilder.substring(0, stringBuilder.length() - 1)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue