diff --git a/pom.xml b/pom.xml
index d10d7d0..35451a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -112,6 +112,21 @@
true
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.3.0
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/su/nightexpress/nightcore/config/ConfigValue.java b/src/main/java/su/nightexpress/nightcore/config/ConfigValue.java
index e61b682..7977177 100644
--- a/src/main/java/su/nightexpress/nightcore/config/ConfigValue.java
+++ b/src/main/java/su/nightexpress/nightcore/config/ConfigValue.java
@@ -36,7 +36,7 @@ public class ConfigValue {
}
@NotNull
- public static ConfigValue create(@NotNull String path,
+ private static ConfigValue create(@NotNull String path,
@NotNull Reader reader,
@NotNull Writer writer,
@NotNull T defaultValue,
diff --git a/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java b/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java
index 0c322d7..e16dd06 100644
--- a/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java
+++ b/src/main/java/su/nightexpress/nightcore/core/CoreConfig.java
@@ -1,6 +1,7 @@
package su.nightexpress.nightcore.core;
import su.nightexpress.nightcore.config.ConfigValue;
+import su.nightexpress.nightcore.util.Placeholders;
import su.nightexpress.nightcore.util.text.NightMessage;
import su.nightexpress.nightcore.util.text.tag.impl.ColorTag;
import su.nightexpress.nightcore.util.wrapper.UniFormatter;
@@ -66,6 +67,13 @@ public class CoreConfig {
"This will improve database performance when checking if user exists, but will increase memory usage.",
"[Default is true]");
+ public static final ConfigValue LEGACY_COLOR_SUPPORT = ConfigValue.create("Engine.Legacy_Color_Support",
+ false,
+ "Allows to use legacy color codes (such as '&7', '&l', etc.) in plugin configurations.",
+ "This setting exist for backwards compatibility only! There are NO GUARANTEES that it will persist for future updates!",
+ "You should NOT use it unless you need to add support for your custom language configurations & translations with legacy codes.",
+ "You should migrate to new text format as soon as possible: " + Placeholders.WIKI_TEXT_URL);
+
public static final ConfigValue RESPECT_PLAYER_DISPLAYNAME = ConfigValue.create("Engine.Respect_Player_DisplayName",
false,
"Sets whether or not 'Player#getDisplayName' can be used to find & get players in addition to regular 'Player#getName'.",
diff --git a/src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java b/src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java
index add940e..ebd123d 100644
--- a/src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java
+++ b/src/main/java/su/nightexpress/nightcore/language/message/LangMessage.java
@@ -40,7 +40,7 @@ public class LangMessage {
this.plugin = plugin;
this.defaultText = defaultText;
this.options = options;
- this.message = NightMessage.from(prefix == null ? defaultText : prefix + defaultText);
+ this.message = NightMessage.from(prefix == null || !options.hasPrefix() ? defaultText : prefix + defaultText);
if (CoreConfig.MODERN_TEXT_PRECOMPILE_LANG.get()) {
this.message.compile();
}
diff --git a/src/main/java/su/nightexpress/nightcore/util/BukkitThing.java b/src/main/java/su/nightexpress/nightcore/util/BukkitThing.java
index 29bf3ff..714a717 100644
--- a/src/main/java/su/nightexpress/nightcore/util/BukkitThing.java
+++ b/src/main/java/su/nightexpress/nightcore/util/BukkitThing.java
@@ -10,6 +10,9 @@ import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.Set;
+import java.util.stream.Collectors;
+
public class BukkitThing {
@Nullable
@@ -20,11 +23,21 @@ public class BukkitThing {
return registry.get(namespacedKey);
}
+ @NotNull
+ public static Set allFromRegistry(@NotNull Registry registry) {
+ return registry.stream().collect(Collectors.toSet());
+ }
+
@Nullable
public static Material getMaterial(@NotNull String name) {
return fromRegistry(Registry.MATERIAL, name);
}
+ @NotNull
+ public static Set getEnchantments() {
+ return allFromRegistry(Registry.ENCHANTMENT);
+ }
+
@Nullable
public static Enchantment getEnchantment(@NotNull String name) {
if (Version.isBehind(Version.V1_19_R3)) {
diff --git a/src/main/java/su/nightexpress/nightcore/util/Colorizer.java b/src/main/java/su/nightexpress/nightcore/util/Colorizer.java
index d66abf3..ebdcebc 100644
--- a/src/main/java/su/nightexpress/nightcore/util/Colorizer.java
+++ b/src/main/java/su/nightexpress/nightcore/util/Colorizer.java
@@ -13,6 +13,7 @@ import java.util.stream.Collectors;
public class Colorizer {
public static final Pattern PATTERN_HEX = Pattern.compile("#([A-Fa-f0-9]{6})");
+ public static final Pattern PATTERN_HEX_LEGACY = Pattern.compile("(?:^|[^<])(#[A-Fa-f0-9]{6})(?:$|[^>])");
public static final Pattern PATTERN_GRADIENT = Pattern.compile("(.*?)");
@NotNull
diff --git a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java b/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
index e19fc88..45c89c5 100644
--- a/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
+++ b/src/main/java/su/nightexpress/nightcore/util/text/NightMessage.java
@@ -5,8 +5,11 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import su.nightexpress.nightcore.core.CoreConfig;
+import su.nightexpress.nightcore.util.Colorizer;
import su.nightexpress.nightcore.util.Pair;
import su.nightexpress.nightcore.util.Placeholders;
+import su.nightexpress.nightcore.util.regex.TimedMatcher;
import su.nightexpress.nightcore.util.text.decoration.*;
import su.nightexpress.nightcore.util.text.tag.*;
import su.nightexpress.nightcore.util.text.tag.api.DynamicTag;
@@ -112,6 +115,14 @@ public class NightMessage {
}
public static BaseComponent[] parse(@NotNull String string, @NotNull TagPool tagPool) {
+ if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) {
+ TimedMatcher timedMatcher = TimedMatcher.create(Colorizer.PATTERN_HEX_LEGACY, string);
+ while (timedMatcher.find()) {
+ String hex = timedMatcher.getMatcher().group(1);
+ string = string.replace(hex, Tag.brackets(hex));
+ }
+ }
+
List parts = new ArrayList<>();
WrappedText currentText = new WrappedText();
@@ -236,6 +247,9 @@ public class NightMessage {
ComponentBuilder builder = new ComponentBuilder();
for (WrappedText wrappedText : parts) {
+ if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) {
+ wrappedText.setText(Colorizer.apply(wrappedText.getText()));
+ }
builder.append(wrappedText.toComponent(), ComponentBuilder.FormatRetention.NONE);
}