mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-04 14:38:46 +00:00
source generation + fixes
This commit is contained in:
1 parent
814a065d38
commit
435dc297c8
7 files changed
+53
-2
No files matched your search
@@ -112,6 +112,21 @@
|
|||||||
<filtering>true</filtering> <!-- this is the important part, it's what replaces, filters, all placeholders in the resources folder (such as ${project.version} in plugin.yml) -->
|
<filtering>true</filtering> <!-- this is the important part, it's what replaces, filters, all placeholders in the resources folder (such as ${project.version} in plugin.yml) -->
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -36,7 +36,7 @@ public class ConfigValue<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <T> ConfigValue<T> create(@NotNull String path,
|
private static <T> ConfigValue<T> create(@NotNull String path,
|
||||||
@NotNull Reader<T> reader,
|
@NotNull Reader<T> reader,
|
||||||
@NotNull Writer<T> writer,
|
@NotNull Writer<T> writer,
|
||||||
@NotNull T defaultValue,
|
@NotNull T defaultValue,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package su.nightexpress.nightcore.core;
|
package su.nightexpress.nightcore.core;
|
||||||
|
|
||||||
import su.nightexpress.nightcore.config.ConfigValue;
|
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.NightMessage;
|
||||||
import su.nightexpress.nightcore.util.text.tag.impl.ColorTag;
|
import su.nightexpress.nightcore.util.text.tag.impl.ColorTag;
|
||||||
import su.nightexpress.nightcore.util.wrapper.UniFormatter;
|
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.",
|
"This will improve database performance when checking if user exists, but will increase memory usage.",
|
||||||
"[Default is true]");
|
"[Default is true]");
|
||||||
|
|
||||||
|
public static final ConfigValue<Boolean> 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<Boolean> RESPECT_PLAYER_DISPLAYNAME = ConfigValue.create("Engine.Respect_Player_DisplayName",
|
public static final ConfigValue<Boolean> RESPECT_PLAYER_DISPLAYNAME = ConfigValue.create("Engine.Respect_Player_DisplayName",
|
||||||
false,
|
false,
|
||||||
"Sets whether or not 'Player#getDisplayName' can be used to find & get players in addition to regular 'Player#getName'.",
|
"Sets whether or not 'Player#getDisplayName' can be used to find & get players in addition to regular 'Player#getName'.",
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class LangMessage {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.defaultText = defaultText;
|
this.defaultText = defaultText;
|
||||||
this.options = options;
|
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()) {
|
if (CoreConfig.MODERN_TEXT_PRECOMPILE_LANG.get()) {
|
||||||
this.message.compile();
|
this.message.compile();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ import org.bukkit.entity.EntityType;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BukkitThing {
|
public class BukkitThing {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -20,11 +23,21 @@ public class BukkitThing {
|
|||||||
return registry.get(namespacedKey);
|
return registry.get(namespacedKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <T extends Keyed> Set<T> allFromRegistry(@NotNull Registry<T> registry) {
|
||||||
|
return registry.stream().collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Material getMaterial(@NotNull String name) {
|
public static Material getMaterial(@NotNull String name) {
|
||||||
return fromRegistry(Registry.MATERIAL, name);
|
return fromRegistry(Registry.MATERIAL, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Set<Enchantment> getEnchantments() {
|
||||||
|
return allFromRegistry(Registry.ENCHANTMENT);
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Enchantment getEnchantment(@NotNull String name) {
|
public static Enchantment getEnchantment(@NotNull String name) {
|
||||||
if (Version.isBehind(Version.V1_19_R3)) {
|
if (Version.isBehind(Version.V1_19_R3)) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.stream.Collectors;
|
|||||||
public class Colorizer {
|
public class Colorizer {
|
||||||
|
|
||||||
public static final Pattern PATTERN_HEX = Pattern.compile("#([A-Fa-f0-9]{6})");
|
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("<gradient:" + PATTERN_HEX.pattern() + ">(.*?)</gradient:" + PATTERN_HEX.pattern() + ">");
|
public static final Pattern PATTERN_GRADIENT = Pattern.compile("<gradient:" + PATTERN_HEX.pattern() + ">(.*?)</gradient:" + PATTERN_HEX.pattern() + ">");
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -5,8 +5,11 @@ import net.md_5.bungee.api.chat.ComponentBuilder;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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.Pair;
|
||||||
import su.nightexpress.nightcore.util.Placeholders;
|
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.decoration.*;
|
||||||
import su.nightexpress.nightcore.util.text.tag.*;
|
import su.nightexpress.nightcore.util.text.tag.*;
|
||||||
import su.nightexpress.nightcore.util.text.tag.api.DynamicTag;
|
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) {
|
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<WrappedText> parts = new ArrayList<>();
|
List<WrappedText> parts = new ArrayList<>();
|
||||||
|
|
||||||
WrappedText currentText = new WrappedText();
|
WrappedText currentText = new WrappedText();
|
||||||
@@ -236,6 +247,9 @@ public class NightMessage {
|
|||||||
|
|
||||||
ComponentBuilder builder = new ComponentBuilder();
|
ComponentBuilder builder = new ComponentBuilder();
|
||||||
for (WrappedText wrappedText : parts) {
|
for (WrappedText wrappedText : parts) {
|
||||||
|
if (CoreConfig.LEGACY_COLOR_SUPPORT.get()) {
|
||||||
|
wrappedText.setText(Colorizer.apply(wrappedText.getText()));
|
||||||
|
}
|
||||||
builder.append(wrappedText.toComponent(), ComponentBuilder.FormatRetention.NONE);
|
builder.append(wrappedText.toComponent(), ComponentBuilder.FormatRetention.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user