- Add support for the 'fallback' argument of the Translatable tag.
- Apply PlaceholderAPI for menu titles if enabled in the menu config.
- Split 'spigot' and 'paper' bridge into modules.
- Full reload support for the nightcore plugin.
This commit is contained in:
nulli0n committed 2025-05-30 20:45:33 +05:00
1 parent 84addd3454
commit 12a85ce198
326 files changed
+3586 -1534

No files matched your search

+11 -1
View File
@@ -1,3 +1,13 @@
/.idea/ /.idea/
/pom.xml.versionsBackup /pom.xml.versionsBackup
/target/ /target/
/utils/target/
/utils/pom.xml.versionsBackup
/spigot/target/
/spigot/pom.xml.versionsBackup
/paper/target/
/paper/pom.xml.versionsBackup
/main/target/
/main/pom.xml.versionsBackup
/bridge/pom.xml.versionsBackup
/bridge/target/
+42
View File
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>nightcore</artifactId>
<version>2.7.6</version>
</parent>
<artifactId>bridge</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>utils</artifactId>
<version>2.7.6</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,26 @@
package su.nightexpress.nightcore.bridge.wrap;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerTextures;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface NightProfile {
void apply(@NotNull SkullMeta meta);
@Nullable UUID getId();
@Nullable String getName();
@NotNull PlayerTextures getTextures();
void setTextures(@Nullable PlayerTextures textures);
boolean isComplete();
@NotNull CompletableFuture<NightProfile> update();
}
@@ -0,0 +1,289 @@
package su.nightexpress.nightcore.util;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.BlockType;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.generator.WorldInfo;
import org.bukkit.inventory.ItemType;
import org.bukkit.inventory.MenuType;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.util.bridge.RegistryType;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class BukkitThing {
public static final char DEFAULT_SEPARATOR = ':';
@NotNull
public static List<String> worldNames() {
return Bukkit.getServer().getWorlds().stream().map(WorldInfo::getName).toList();
}
private static boolean isValidNamespaceChar(char c) {
return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '_' || c == '-';
}
private static boolean isValidKeyChar(char c) {
return isValidNamespaceChar(c) || c == '/';
}
@NotNull
private static String validateNamespaceOrValue(@NotNull String str, @NotNull Predicate<Character> predicate) {
char[] chars = str.toLowerCase().toCharArray();
StringBuilder builder = new StringBuilder();
for (char letter : chars) {
if (Character.isWhitespace(letter)) {
builder.append("_");
continue;
}
if (!predicate.test(letter)) {
continue;
}
builder.append(Character.toLowerCase(letter));
}
return builder.toString();
}
@NotNull
public static String validateNamespace(@NotNull String namespace) {
return validateNamespaceOrValue(namespace, BukkitThing::isValidNamespaceChar);
}
@NotNull
public static String validateValue(@NotNull String value) {
return validateNamespaceOrValue(value, BukkitThing::isValidKeyChar);
}
@NotNull
public static NamespacedKey parseKey(@NotNull String string) {
int index = string.indexOf(DEFAULT_SEPARATOR);
String namespace = index >= 1 ? string.substring(0, index) : NamespacedKey.MINECRAFT;
String value = index >= 0 ? string.substring(index + 1) : string;
return parseKey(namespace, value);
}
@NotNull
public static NamespacedKey parseKey(@NotNull String namespace, @NotNull String value) {
namespace = BukkitThing.validateNamespace(namespace);
value = BukkitThing.validateValue(value);
return new NamespacedKey(namespace, value);
}
@Nullable
@Deprecated
public static <T extends Keyed> T fromRegistry(@NotNull Registry<@NotNull T> registry, @NotNull String key) {
return registry.get(parseKey(key));
//return fromRegistry(registry, NamespacedKey.MINECRAFT, key);
}
@Nullable
@Deprecated
public static <T extends Keyed> T fromRegistry(@NotNull Registry<@NotNull T> registry, @NotNull String namespace, @NotNull String key) {
return registry.get(parseKey(namespace, key));
// try {
// NamespacedKey namespacedKey = new NamespacedKey(namespace.toLowerCase(), key.toLowerCase());
// return registry.get(namespacedKey);
// }
// catch (IllegalArgumentException exception) {
// return null;
// }
}
@NotNull
@Deprecated
public static <T extends Keyed> Set<T> allFromRegistry(@NotNull Registry<@NotNull T> registry) {
if (Version.isBehind(Version.V1_20_R2)) {
return StreamSupport.stream(registry.spliterator(), false).collect(Collectors.toSet());
}
return registry.stream().collect(Collectors.toSet());
}
@NotNull
@Deprecated
public static <T extends Keyed> List<String> getNames(@NotNull Registry<@NotNull T> registry) {
if (Version.isBehind(Version.V1_20_R2)) {
return StreamSupport.stream(registry.spliterator(), false).map(BukkitThing::toString).toList();
}
return registry.stream().map(BukkitThing::toString).toList();
}
@NotNull
@Deprecated
public static String toString(@NotNull Keyed keyed) {
return keyed.getKey().getKey();
}
@Nullable
public static <T extends Keyed> T getByString(@NotNull RegistryType<T> registryKey, @NotNull String string) {
return getByKey(registryKey, BukkitThing.parseKey(string));
}
@Nullable
public static <T extends Keyed> T getByNamespaceValue(@NotNull RegistryType<T> registryKey, @NotNull String namespace, @NotNull String value) {
return getByKey(registryKey, BukkitThing.parseKey(namespace, value));
}
@Nullable
public static <T extends Keyed> T getByKey(@NotNull RegistryType<T> registryType, @NotNull NamespacedKey key) {
return registryType.getRegistry().get(key);
}
@NotNull
public static <T extends Keyed> Set<T> getAll(@NotNull RegistryType<T> registryType) {
if (Version.isBehind(Version.V1_20_R2)) {
return StreamSupport.stream(registryType.getRegistry().spliterator(), false).collect(Collectors.toSet());
}
return registryType.getRegistry().stream().collect(Collectors.toSet());
}
@NotNull
public static <T extends Keyed> List<NamespacedKey> getKeys(@NotNull RegistryType<T> registryType) {
var registry = registryType.getRegistry();
return Version.isPaper() ? registry.keyStream().toList() : registry.stream().map(Keyed::getKey).toList();
}
@NotNull
public static <T extends Keyed> List<String> getValues(@NotNull RegistryType<T> registryType) {
return registryType.getRegistry().stream().map(BukkitThing::getValue).toList();
}
@NotNull
public static <T extends Keyed> List<String> getAsStrings(@NotNull RegistryType<T> registryType) {
return getKeys(registryType).stream().map(BukkitThing::getAsString).toList();
}
@NotNull
public static String getNamespace(@NotNull Keyed keyed) {
return keyed.getKey().getNamespace();
}
@NotNull
public static String getValue(@NotNull Keyed keyed) {
return keyed.getKey().getKey();
}
@NotNull
public static String getAsString(@NotNull Keyed keyed) {
return getAsString(keyed.getKey());
}
@NotNull
public static String getAsString(@NotNull NamespacedKey key) {
return Version.isPaper() ? key.asString() : key.getNamespace() + DEFAULT_SEPARATOR + key.getKey();
}
@NotNull
public static Set<Material> getMaterials() {
return getAll(RegistryType.MATERIAL);
}
@NotNull
public static Set<Enchantment> getEnchantments() {
return getAll(RegistryType.ENCHANTMENT);
}
@NotNull
public static Set<Attribute> getAttributes() {
return getAll(RegistryType.ATTRIBUTE);
}
@NotNull
public static Set<ItemType> getItemTypes() {
return getAll(RegistryType.MC_1_21.ITEM);
}
@NotNull
public static Set<BlockType> getBlockTypes() {
return getAll(RegistryType.MC_1_21.BLOCK);
}
@NotNull
public static Set<PotionEffectType> getEffectTypes() {
if (Version.isBehind(Version.V1_20_R2)) {
return Stream.of(PotionEffectType.values()).collect(Collectors.toSet());
}
return getAll(RegistryType.MOB_EFFECT);
}
@Nullable
public static Material getMaterial(@NotNull String name) {
return getByString(RegistryType.MATERIAL, name);
}
@Nullable
public static ItemType getItemType(@NotNull String name) {
return getByString(RegistryType.MC_1_21.ITEM, name);
}
@Nullable
public static BlockType getBlockType(@NotNull String name) {
return getByString(RegistryType.MC_1_21.BLOCK, name);
}
@Nullable
public static Enchantment getEnchantment(@NotNull String name) {
return getByString(RegistryType.ENCHANTMENT, name);
}
@Nullable
public static EntityType getEntityType(@NotNull String name) {
return getByString(RegistryType.ENTITY_TYPE, name);
}
@Nullable
public static Attribute getAttribute(@NotNull String name) {
return getByString(RegistryType.ATTRIBUTE, name);
}
@Nullable
public static PotionEffectType getPotionEffect(@NotNull String name) {
return getByString(RegistryType.MOB_EFFECT, name);
}
@Nullable
public static PotionType getPotionType(@NotNull String name) {
return getByString(RegistryType.POTION, name);
}
@Nullable
public static Sound getSound(@NotNull String name) {
// if (Version.isBehind(Version.MC_1_21_3)) {
// return Sound.valueOf(name.toUpperCase());
// }
return getByString(RegistryType.SOUND, name);
}
@Nullable
public static Particle getParticle(@NotNull String name) {
return getByString(RegistryType.PARTICLE_TYPE, name);
}
@Nullable
public static MenuType getMenuType(@NotNull String name) {
return getByString(RegistryType.MC_1_21.MENU, name);
}
}
@@ -2,7 +2,6 @@ package su.nightexpress.nightcore.util;
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.CoreLogger;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.ArrayList; import java.util.ArrayList;
@@ -31,19 +30,13 @@ public class Reflex {
public static Class<?> getNMSClass(@NotNull String path, @NotNull String realName, @Nullable String obfName) { public static Class<?> getNMSClass(@NotNull String path, @NotNull String realName, @Nullable String obfName) {
Class<?> byRealName = getClass(path + "." + realName, false); Class<?> byRealName = getClass(path + "." + realName, false);
if (byRealName != null) { if (byRealName != null) {
//CoreLogger.info("Class found by real name: " + path + "." + realName);
return byRealName; return byRealName;
} }
if (obfName != null) { if (obfName != null) {
Class<?> byObfName = getClass(path + "." + obfName, false); return getClass(path + "." + obfName, false);
if (byObfName != null) {
//CoreLogger.info("Class found by obfuscated name: " + path + "." + obfName);
return byObfName;
}
} }
CoreLogger.warn("NMS class not found: " + path + "[" + realName + " / " + obfName + "]");
return null; return null;
} }
@@ -2,18 +2,13 @@ package su.nightexpress.nightcore.util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.NightCore;
import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.util.bridge.paper.PaperBridge;
import su.nightexpress.nightcore.util.bridge.Software;
import su.nightexpress.nightcore.util.bridge.spigot.SpigotBridge;
import java.util.Comparator; import java.util.Comparator;
import java.util.stream.Stream; import java.util.stream.Stream;
public enum Version { public enum Version {
V1_19_R3("1.19.4", 3337, Status.OUTDATED), V1_19_R3("1.19.4", 3337, Status.DROPPED),
V1_20_R1("1.20.1", 3465, Status.OUTDATED), V1_20_R1("1.20.1", 3465, Status.OUTDATED),
V1_20_R2("1.20.2", 3578, Status.OUTDATED), V1_20_R2("1.20.2", 3578, Status.OUTDATED),
V1_20_R3("1.20.4", 3700, Status.OUTDATED), V1_20_R3("1.20.4", 3700, Status.OUTDATED),
@@ -27,13 +22,11 @@ public enum Version {
UNKNOWN("Unknown", 0), UNKNOWN("Unknown", 0),
; ;
public static final String CRAFTBUKKIT_PACKAGE = Bukkit.getServer().getClass().getPackage().getName();
private static Version current; private static Version current;
private static Software software; private static boolean isPaper;
private final Status status; private final Status status;
private final int dataVersion; private final int dataVersion;
private final String localized; private final String localized;
Version(@NotNull String localized, int dataVersion) { Version(@NotNull String localized, int dataVersion) {
@@ -52,47 +45,15 @@ public enum Version {
DROPPED DROPPED
} }
public static void load(@NotNull NightCore core) { @NotNull
String bukkitVersion = core.getServer().getBukkitVersion(); public static Version detect() {
String bukkitName = core.getServer().getName(); String bukkitVersion = Bukkit.getServer().getBukkitVersion();
String exact = bukkitVersion.split("-")[0]; String exact = bukkitVersion.split("-")[0];
boolean isSpigot = bukkitName.equalsIgnoreCase("Spigot") || bukkitName.equalsIgnoreCase("CraftBukkit");
current = Stream.of(values()).sorted(Comparator.reverseOrder()).filter(version -> exact.equalsIgnoreCase(version.getLocalized())).findFirst().orElse(UNKNOWN); current = Stream.of(values()).sorted(Comparator.reverseOrder()).filter(version -> exact.equalsIgnoreCase(version.getLocalized())).findFirst().orElse(UNKNOWN);
software = isSpigot ? new SpigotBridge() : new PaperBridge(); isPaper = checkPaper();
software.initialize(core);
core.info("Server version detected as " + bukkitName + " " + current.getLocalized() + ". Using " + software().getName() + ".");
ItemNbt.load(core); return current;
}
public static void printCaution(@NotNull NightCorePlugin plugin) {
if (current != UNKNOWN && current.isSupported()) return;
plugin.warn("=".repeat(35));
if (current == Version.UNKNOWN) {
plugin.warn("WARNING: This plugin is not supposed to run on this server version!");
plugin.warn("If server version is newer than " + values()[values().length - 1] + ", then wait for an update please.");
plugin.warn("Otherwise this plugin will not work properly or even load.");
}
else if (current.isDeprecated()) {
plugin.warn("WARNING: You're running an outdated server version (" + current.getLocalized() + ")!");
plugin.warn("This version will no longer be supported in future relases.");
plugin.warn("Please upgrade your server to " + Lists.next(current, (Version::isSupported)).getLocalized() + ".");
}
else if (current.isDropped()) {
plugin.error("ERROR: You're running an unsupported server version (" + current.getLocalized() + ")!");
plugin.error("Please upgrade your server to " + Lists.next(current, (Version::isSupported)).getLocalized() + ".");
}
plugin.warn("ABSOLUTELY NO DISCORD SUPPORT WILL BE PROVIDED");
plugin.warn("=".repeat(35));
}
@NotNull
public static Software software() {
return software;
} }
@NotNull @NotNull
@@ -101,11 +62,11 @@ public enum Version {
} }
public static boolean isSpigot() { public static boolean isSpigot() {
return software.isSpigot(); return !isPaper;
} }
public static boolean isPaper() { public static boolean isPaper() {
return software.isPaper(); return isPaper;
} }
public boolean isDeprecated() { public boolean isDeprecated() {
@@ -161,4 +122,14 @@ public enum Version {
public boolean isCurrent() { public boolean isCurrent() {
return this == Version.getCurrent(); return this == Version.getCurrent();
} }
public static boolean checkPaper() {
try {
Class.forName("com.destroystokyo.paper.ParticleBuilder");
return true;
}
catch (ClassNotFoundException e) {
return false;
}
}
} }
@@ -0,0 +1,95 @@
package su.nightexpress.nightcore.util.bridge;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.block.Biome;
import org.bukkit.block.BlockType;
import org.bukkit.block.banner.PatternType;
import org.bukkit.damage.DamageType;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.entity.memory.MemoryKey;
import org.bukkit.generator.structure.Structure;
import org.bukkit.generator.structure.StructureType;
import org.bukkit.inventory.ItemType;
import org.bukkit.inventory.MenuType;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.bukkit.map.MapCursor;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.util.Version;
import java.util.function.Function;
public interface RegistryType<T extends Keyed> {
RegistryType<Material> MATERIAL = type(isSpigot -> Registry.MATERIAL);
RegistryType<Enchantment> ENCHANTMENT = type(isSpigot -> isSpigot ? forSpigot(Enchantment.class) : forPaper(RegistryKey.ENCHANTMENT));
RegistryType<GameEvent> GAME_EVENT = type(isSpigot -> isSpigot ? Registry.GAME_EVENT : forPaper(RegistryKey.GAME_EVENT));
RegistryType<StructureType> STRUCTURE_TYPE = type(isSpigot -> isSpigot ? Registry.STRUCTURE_TYPE : forPaper(RegistryKey.STRUCTURE_TYPE));
RegistryType<PotionEffectType> MOB_EFFECT = type(isSpigot -> isSpigot ? Registry.EFFECT : forPaper(RegistryKey.MOB_EFFECT));
RegistryType<Villager.Profession> VILLAGER_PROFESSION = type(isSpigot -> isSpigot ? Registry.VILLAGER_PROFESSION : forPaper(RegistryKey.VILLAGER_PROFESSION));
RegistryType<Villager.Type> VILLAGER_TYPE = type(isSpigot -> isSpigot ? Registry.VILLAGER_TYPE : forPaper(RegistryKey.VILLAGER_TYPE));
RegistryType<Attribute> ATTRIBUTE = type(isSpigot -> isSpigot ? Registry.ATTRIBUTE : forPaper(RegistryKey.ATTRIBUTE));
RegistryType<Fluid> FLUID = type(isSpigot -> isSpigot ? Registry.FLUID : forPaper(RegistryKey.FLUID));
RegistryType<Sound> SOUND = type(isSpigot -> isSpigot ? Registry.SOUNDS : forPaper(RegistryKey.SOUND_EVENT));
RegistryType<Biome> BIOME = type(isSpigot -> isSpigot ? forSpigot(Biome.class) : forPaper(RegistryKey.BIOME));
RegistryType<Structure> STRUCTURE = type(isSpigot -> isSpigot ? forSpigot(Structure.class) : forPaper(RegistryKey.STRUCTURE));
RegistryType<TrimMaterial> TRIM_MATERIAL = type(isSpigot -> isSpigot ? forSpigot(TrimMaterial.class) : forPaper(RegistryKey.TRIM_MATERIAL));
RegistryType<TrimPattern> TRIM_PATTERN = type(isSpigot -> isSpigot ? forSpigot(TrimPattern.class) : forPaper(RegistryKey.TRIM_PATTERN));
RegistryType<DamageType> DAMAGE_TYPE = type(isSpigot -> isSpigot ? forSpigot(DamageType.class) : forPaper(RegistryKey.DAMAGE_TYPE));
RegistryType<PatternType> BANNER_PATTERN = type(isSpigot -> isSpigot ? forSpigot(PatternType.class) : forPaper(RegistryKey.BANNER_PATTERN));
RegistryType<Art> PAINTING_VARIANT = type(isSpigot -> isSpigot ? forSpigot(Art.class) : forPaper(RegistryKey.PAINTING_VARIANT));
RegistryType<MusicInstrument> INSTRUMENT = type(isSpigot -> isSpigot ? forSpigot(MusicInstrument.class) : forPaper(RegistryKey.INSTRUMENT));
RegistryType<Cat.Type> CAT_VARIANT = type(isSpigot -> isSpigot ? forSpigot(Cat.Type.class) : forPaper(RegistryKey.CAT_VARIANT));
RegistryType<Frog.Variant> FROG_VARIANT = type(isSpigot -> isSpigot ? forSpigot(Frog.Variant.class) : forPaper(RegistryKey.FROG_VARIANT));
RegistryType<EntityType> ENTITY_TYPE = type(isSpigot -> isSpigot ? Registry.ENTITY_TYPE : forPaper(RegistryKey.ENTITY_TYPE));
RegistryType<Particle> PARTICLE_TYPE = type(isSpigot -> isSpigot ? Registry.PARTICLE_TYPE : forPaper(RegistryKey.PARTICLE_TYPE));
RegistryType<PotionType> POTION = type(isSpigot -> isSpigot ? Registry.POTION : forPaper(RegistryKey.POTION));
class MC_1_21 {
public static final RegistryType<BlockType> BLOCK = type(isSpigot -> isSpigot ? Registry.BLOCK : forPaper(RegistryKey.BLOCK));
public static final RegistryType<ItemType> ITEM = type(isSpigot -> isSpigot ? Registry.ITEM : forPaper(RegistryKey.ITEM));
public static final RegistryType<JukeboxSong> JUKEBOX_SONG = type(isSpigot -> isSpigot ? forSpigot(JukeboxSong.class) : forPaper(RegistryKey.JUKEBOX_SONG));
public static final RegistryType<MapCursor.Type> MAP_DECORATION_TYPE = type(isSpigot -> isSpigot ? Registry.MAP_DECORATION_TYPE : forPaper(RegistryKey.MAP_DECORATION_TYPE));
public static final RegistryType<Wolf.Variant> WOLF_VARIANT = type(isSpigot -> isSpigot ? forSpigot(Wolf.Variant.class) : forPaper(RegistryKey.WOLF_VARIANT));
public static final RegistryType<MenuType> MENU = type(isSpigot -> isSpigot ? Registry.MENU : forPaper(RegistryKey.MENU));
}
class MC_1_21_5 {
public static final RegistryType<Chicken.Variant> CHICKEN_VARIANT = type(isSpigot -> isSpigot ? forSpigot(Chicken.Variant.class) : forPaper(RegistryKey.CHICKEN_VARIANT));
public static final RegistryType<Cow.Variant> COW_VARIANT = type(isSpigot -> isSpigot ? forSpigot(Cow.Variant.class) : forPaper(RegistryKey.COW_VARIANT));
public static final RegistryType<Pig.Variant> PIG_VARIANT = type(isSpigot -> isSpigot ? forSpigot(Pig.Variant.class) : forPaper(RegistryKey.PIG_VARIANT));
}
class Paper {
public static final RegistryType<DataComponentType> DATA_COMPONENT_TYPE = type(isSpigot -> forPaper(RegistryKey.DATA_COMPONENT_TYPE));
public static final RegistryType<Wolf.SoundVariant> WOLF_SOUND_VARIANT = type(isSpigot -> forPaper(RegistryKey.WOLF_SOUND_VARIANT));
public static final RegistryType<MemoryKey<?>> MEMORY_MODULE_TYPE = type(isSpigot -> forPaper(RegistryKey.MEMORY_MODULE_TYPE));
}
@NotNull Registry<@NotNull T> getRegistry();
private static <T extends Keyed> RegistryType<T> type(@NotNull Function<Boolean, Registry<@NotNull T>> function) {
var registry = function.apply(Version.isSpigot() || Version.isBehind(Version.MC_1_21));
return () -> registry;
}
@SuppressWarnings("deprecation")
private static <T extends Keyed> Registry<@NotNull T> forSpigot(@NotNull Class<T> clazz) {
return Bukkit.getRegistry(clazz);
}
private static <T extends Keyed> Registry<@NotNull T> forPaper(@NotNull RegistryKey<T> key) {
return RegistryAccess.registryAccess().getRegistry(key);
}
}
@@ -0,0 +1,106 @@
package su.nightexpress.nightcore.util.bridge;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MenuType;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.bridge.wrap.NightProfile;
import su.nightexpress.nightcore.util.bridge.wrapper.ComponentBuildable;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
public interface Software {
boolean initialize();
@NotNull String getName();
boolean isPaper();
int nextEntityId();
@NotNull SimpleCommandMap getCommandMap();
@NotNull Map<String, Command> getKnownCommands(@NotNull SimpleCommandMap commandMap);
@NotNull NightComponent textComponent(@NotNull String text);
@NotNull NightComponent translateComponent(@NotNull String key);
@NotNull NightComponent translateComponent(@NotNull String key, @Nullable String fallback);
@NotNull NightComponent buildComponent(@NotNull List<ComponentBuildable> childrens);
@NotNull InventoryView createView(@NotNull MenuType menuType, @NotNull NightComponent title, @NotNull Player player);
@NotNull NightProfile createProfile(@NotNull UUID uuid);
@NotNull NightProfile createProfile(@NotNull String name);
@NotNull NightProfile createProfile(@Nullable UUID uuid, @Nullable String name);
@NotNull NightProfile getProfile(@NotNull OfflinePlayer player);
void sendTitles(@NotNull Player player, @NotNull NightComponent title, @NotNull NightComponent subtitle, int fadeIn, int stay, int fadeOut);
@NotNull Set<String> getCommonComponentsToHide();
@NotNull Set<String> getHiddenComponents(@NotNull ItemStack itemStack);
@NotNull String getTranslationKey(@NotNull Material material);
@NotNull String getTranslationKey(@NotNull Attribute attribute);
@NotNull String getTranslationKey(@NotNull Enchantment enchantment);
@NotNull String getTranslationKey(@NotNull EntityType entityType);
@NotNull String getTranslationKey(@NotNull PotionEffectType effectType);
@NotNull ItemStack setType(@NotNull ItemStack itemStack, @NotNull Material material);
void editMeta(@NotNull ItemStack itemStack, @NotNull Consumer<ItemMeta> consumer);
<T extends ItemMeta> void editMeta(@NotNull ItemStack itemStack, @NotNull Class<T> clazz, @NotNull Consumer<T> consumer);
@Nullable String getCustomName(@NotNull ItemMeta meta);
void setCustomName(@NotNull ItemMeta meta, @NotNull NightComponent name);
@Nullable String getItemName(@NotNull ItemMeta meta);
void setItemName(@NotNull ItemMeta meta, @NotNull NightComponent name);
@Nullable List<String> getLore(@NotNull ItemMeta meta);
void setLore(@NotNull ItemMeta meta, @NotNull List<NightComponent> lore);
@Nullable NightProfile getOwnerProfile(@NotNull ItemStack itemStack);
//void setOwnerProfile(@NotNull SkullMeta meta, @NotNull NightProfile profile);
void hideComponents(@NotNull ItemStack itemStack);
void hideComponents(@NotNull ItemStack itemStack, @NotNull Set<String> componentNames);
}
@@ -1,7 +1,6 @@
package su.nightexpress.nightcore.util.text; package su.nightexpress.nightcore.util.bridge.wrapper;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
public interface ComponentBuildable { public interface ComponentBuildable {
@@ -2,6 +2,7 @@ package su.nightexpress.nightcore.util.bridge.wrapper;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.awt.*; import java.awt.*;
@@ -37,7 +38,11 @@ public interface NightComponent {
void setClickEvent(@NotNull ClickEventType type, @NotNull String value); void setClickEvent(@NotNull ClickEventType type, @NotNull String value);
void setHoverEvent(@NotNull HoverEventType type, @NotNull String value); //void setHoverEvent(@NotNull HoverEventType type, @NotNull String value);
void setHoverEvent(@NotNull NightComponent text);
void setHoverEvent(@NotNull ItemStack itemStack);
void setFont(@NotNull String font); void setFont(@NotNull String font);
+175
View File
@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>nightcore</artifactId>
<version>2.7.6</version>
</parent>
<artifactId>main</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>opencollab-snapshot</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
</repository>
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>bridge</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>utils</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>paper</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>su.nightexpress.nightcore</groupId>
<artifactId>spigot</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>datafixerupper</artifactId>
<version>8.0.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.47.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil-core</artifactId>
<version>8.5.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc.floodgate</groupId>
<artifactId>api</artifactId>
<version>2.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory> <!-- (your resources folder location) -->
<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>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>${project.parent.basedir}\target\${project.parent.name}-${project.version}.jar
</outputFile>
<artifactSet>
<includes>
<include>su.nightexpress.nightcore:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,142 @@
package su.nightexpress.nightcore;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.integration.VaultHook;
import su.nightexpress.nightcore.integration.permission.PermissionProvider;
import su.nightexpress.nightcore.integration.permission.impl.LuckPermissionProvider;
import su.nightexpress.nightcore.integration.permission.impl.VaultPermissionProvider;
import su.nightexpress.nightcore.util.ItemNbt;
import su.nightexpress.nightcore.util.Lists;
import su.nightexpress.nightcore.util.Plugins;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.bridge.Software;
import su.nightexpress.nightcore.bridge.paper.PaperBridge;
import su.nightexpress.nightcore.bridge.spigot.SpigotBridge;
import java.util.HashSet;
import java.util.Set;
public class Engine {
private static final Set<NightPlugin> CHILDRENS = new HashSet<>();
private static NightCore core;
private static Software software;
private static PermissionProvider permissions;
@NotNull
public static Set<NightPlugin> getChildrens() {
return CHILDRENS;
}
@NotNull
public static NightCore core() {
if (core == null) throw new IllegalStateException("NightCore is not initialized!");
return core;
}
@NotNull
public static Software software() {
if (software == null) throw new IllegalStateException("Software is not initialized!");
return software;
}
@Nullable
public static PermissionProvider getPermissions() {
return permissions;
}
public static boolean hasPermissions() {
return permissions != null;
}
public static void clear() {
if (Plugins.hasVault()) {
VaultHook.shutdown();
}
CHILDRENS.clear();
permissions = null;
core = null;
}
private static void init(@NotNull NightCore instance) {
core = instance;
Version version = Version.detect();
if (version.isDropped()) return;
software = Version.isPaper() ? new PaperBridge() : new SpigotBridge();
software.initialize();
core.info("Server version detected as " + version.getLocalized() + ". Using " + software.getName() + ".");
ItemNbt.load(core);
loadPermissionsProvider();
Plugins.detectPlugins();
if (Plugins.hasVault()) {
VaultHook.load();
}
}
private static void loadPermissionsProvider() {
if (Plugins.isInstalled(Plugins.LUCK_PERMS)) {
permissions = new LuckPermissionProvider();
}
else if (Plugins.isInstalled(Plugins.VAULT)) {
permissions = new VaultPermissionProvider();
}
else return;
core.info("Found permissions provider: " + permissions.getName());
core.runTask(task -> permissions.setup()); // Run after the server load to setup Vault services properly.
}
public static boolean handleEnable(@NotNull NightPlugin plugin) {
if (plugin instanceof NightCore nightCore) {
init(nightCore);
}
else {
CHILDRENS.add(plugin);
plugin.info("Powered by " + core.getName());
}
return checkVersion(plugin);
}
public static boolean checkVersion(@NotNull NightCorePlugin plugin) {
Version current = Version.getCurrent();
if (current != Version.UNKNOWN && current.isSupported()) return true;
plugin.warn("=".repeat(35));
if (current == Version.UNKNOWN) {
plugin.warn("WARNING: This plugin is not supposed to run on this server version!");
plugin.warn("If server version is newer than " + Version.values()[Version.values().length - 1] + ", then wait for an update please.");
plugin.warn("Otherwise this plugin will not work properly or even load.");
}
else if (current.isDeprecated()) {
plugin.warn("WARNING: You're running an outdated server version (" + current.getLocalized() + ")!");
plugin.warn("This version will no longer be supported in future relases.");
plugin.warn("Please upgrade your server to " + Lists.next(current, (Version::isSupported)).getLocalized() + ".");
}
else if (current.isDropped()) {
plugin.error("ERROR: You're running an unsupported server version (" + current.getLocalized() + ")!");
plugin.error("Please upgrade your server to " + Lists.next(current, (Version::isSupported)).getLocalized() + ".");
}
plugin.warn("ABSOLUTELY NO DISCORD SUPPORT WILL BE PROVIDED");
plugin.warn("=".repeat(35));
if (current.isDropped()) {
plugin.getPluginManager().disablePlugin(plugin);
return false;
}
return true;
}
}
@@ -8,30 +8,15 @@ import su.nightexpress.nightcore.core.CoreLang;
import su.nightexpress.nightcore.core.CoreManager; import su.nightexpress.nightcore.core.CoreManager;
import su.nightexpress.nightcore.core.CorePerms; import su.nightexpress.nightcore.core.CorePerms;
import su.nightexpress.nightcore.core.command.CoreCommands; import su.nightexpress.nightcore.core.command.CoreCommands;
import su.nightexpress.nightcore.integration.VaultHook;
import su.nightexpress.nightcore.language.LangAssets; import su.nightexpress.nightcore.language.LangAssets;
import su.nightexpress.nightcore.ui.UIUtils; import su.nightexpress.nightcore.ui.UIUtils;
import su.nightexpress.nightcore.util.Plugins;
import su.nightexpress.nightcore.util.TimeUtil; import su.nightexpress.nightcore.util.TimeUtil;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker; import su.nightexpress.nightcore.util.blocktracker.PlayerBlockTracker;
import su.nightexpress.nightcore.util.text.tag.Tags; import su.nightexpress.nightcore.util.text.tag.Tags;
import java.util.HashSet;
import java.util.Set;
public class NightCore extends NightPlugin implements ImprovedCommands { public class NightCore extends NightPlugin implements ImprovedCommands {
private final Set<NightPlugin> childrens; private CoreManager coreManager;
private final CoreManager coreManager;
public NightCore() {
Plugins.load(this);
Version.load(this);
this.childrens = new HashSet<>();
this.coreManager = new CoreManager(this);
}
@Override @Override
@NotNull @NotNull
@@ -47,44 +32,29 @@ public class NightCore extends NightPlugin implements ImprovedCommands {
Tags.loadColorsFromFile(this); Tags.loadColorsFromFile(this);
LangAssets.load(this); LangAssets.load(this);
UIUtils.load(this); UIUtils.load(this);
this.loadIntegrations();
this.loadCommands(); this.loadCommands();
this.info("Time zone set as " + TimeUtil.getTimeZone().getID()); this.info("Time zone set as " + TimeUtil.getTimeZone().getID());
this.coreManager = new CoreManager(this);
this.coreManager.setup(); this.coreManager.setup();
} }
@Override @Override
public void disable() { public void disable() {
this.coreManager.shutdown(); if (this.coreManager != null) this.coreManager.shutdown();
if (Plugins.hasVault()) {
VaultHook.shutdown();
}
UIUtils.clear(); UIUtils.clear();
PlayerBlockTracker.shutdown();
LangAssets.shutdown(); LangAssets.shutdown();
} }
@Override
public void onDisable() {
super.onDisable();
PlayerBlockTracker.shutdown();
Engine.clear();
}
private void loadCommands() { private void loadCommands() {
CoreCommands.load(this); CoreCommands.load(this);
} }
private void loadIntegrations() {
Plugins.detectPlugins();
if (Plugins.hasVault()) {
VaultHook.load(this);
}
}
void addChildren(@NotNull NightPlugin child) {
this.childrens.add(child);
child.info("Powered by " + this.getName());
}
@NotNull
public Set<NightPlugin> getChildrens() {
return new HashSet<>(this.childrens);
}
} }
@@ -4,7 +4,6 @@ import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.bootstrap.PluginBootstrap; import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@SuppressWarnings("UnstableApiUsage")
public class NightCoreBootstrap implements PluginBootstrap { public class NightCoreBootstrap implements PluginBootstrap {
@Override @Override
@@ -7,7 +7,6 @@ import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.Dependency; import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RemoteRepository;
@SuppressWarnings("UnstableApiUsage")
public class NightCoreLoader implements PluginLoader { public class NightCoreLoader implements PluginLoader {
@Override @Override
@@ -31,22 +31,12 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
protected FileConfig config; protected FileConfig config;
protected PluginDetails details; protected PluginDetails details;
private boolean isCore() {
return this instanceof NightCore;
}
@Override @Override
public void onEnable() { public void onEnable() {
Version.printCaution(this); if (!Engine.handleEnable(this)) {
if (Version.getCurrent().isDropped()) {
this.getPluginManager().disablePlugin(this);
return; return;
} }
if (!this.isCore()) {
Plugins.getCore().addChildren(this);
}
long loadTook = System.currentTimeMillis(); long loadTook = System.currentTimeMillis();
this.loadManagers(); this.loadManagers();
this.info("Plugin loaded in " + (System.currentTimeMillis() - loadTook) + " ms!"); this.info("Plugin loaded in " + (System.currentTimeMillis() - loadTook) + " ms!");
@@ -57,12 +47,7 @@ public abstract class NightPlugin extends JavaPlugin implements NightCorePlugin
this.unloadManagers(); this.unloadManagers();
} }
public final void reload() { public void reload() {
if (this.isCore()) {
this.setupConfig();
this.setupLanguage();
return;
}
this.unloadManagers(); this.unloadManagers();
this.loadManagers(); this.loadManagers();
} }
@@ -3,8 +3,10 @@ package su.nightexpress.nightcore.command.experimental.argument;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockType;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.command.experimental.builder.ArgumentBuilder; import su.nightexpress.nightcore.command.experimental.builder.ArgumentBuilder;
import su.nightexpress.nightcore.core.CoreLang; import su.nightexpress.nightcore.core.CoreLang;
@@ -26,7 +28,7 @@ public class ArgumentTypes {
public static final ArgumentParser<Double> DOUBLE_COMPACT_ABS = (string, context) -> NumberUtil.parseCompact(string).map(Math::abs).orElse(null); public static final ArgumentParser<Double> DOUBLE_COMPACT_ABS = (string, context) -> NumberUtil.parseCompact(string).map(Math::abs).orElse(null);
public static final ArgumentParser<Player> PLAYER = (string, context) -> Players.getPlayer(string); public static final ArgumentParser<Player> PLAYER = (string, context) -> Players.getPlayer(string);
public static final ArgumentParser<World> WORLD = (string, context) -> Bukkit.getWorld(string); public static final ArgumentParser<World> WORLD = (string, context) -> Bukkit.getWorld(string);
public static final ArgumentParser<Material> MATERIAL = (string, context) -> BukkitThing.getMaterial(string); @Deprecated public static final ArgumentParser<Material> MATERIAL = (string, context) -> BukkitThing.getMaterial(string);
public static final ArgumentParser<Material> ITEM_MATERIAL = (string, context) -> { public static final ArgumentParser<Material> ITEM_MATERIAL = (string, context) -> {
Material material = BukkitThing.getMaterial(string); Material material = BukkitThing.getMaterial(string);
@@ -143,6 +145,20 @@ public class ArgumentTypes {
.customFailure(CoreLang.ERROR_COMMAND_INVALID_MATERIAL_ARGUMENT); .customFailure(CoreLang.ERROR_COMMAND_INVALID_MATERIAL_ARGUMENT);
} }
@NotNull
public static ArgumentBuilder<ItemType> itemType(@NotNull String name) {
return CommandArgument.builder(name, (string, context) -> BukkitThing.getItemType(string))
.localized(CoreLang.COMMAND_ARGUMENT_NAME_ITEM_MATERIAL)
.customFailure(CoreLang.ERROR_COMMAND_INVALID_MATERIAL_ARGUMENT);
}
@NotNull
public static ArgumentBuilder<BlockType> blockType(@NotNull String name) {
return CommandArgument.builder(name, (string, context) -> BukkitThing.getBlockType(string))
.localized(CoreLang.COMMAND_ARGUMENT_NAME_BLOCK_MATERIAL)
.customFailure(CoreLang.ERROR_COMMAND_INVALID_MATERIAL_ARGUMENT);
}
@NotNull @NotNull
public static ArgumentBuilder<Enchantment> enchantment(@NotNull String name) { public static ArgumentBuilder<Enchantment> enchantment(@NotNull String name) {
return CommandArgument.builder(name, ENCHANTMENT) return CommandArgument.builder(name, ENCHANTMENT)
@@ -176,7 +176,7 @@ public class ConfigValue<T> {
// Reader<NightSound> reader = NightSound::read; // Reader<NightSound> reader = NightSound::read;
// Writer<NightSound> writer = (cfg, writePath, sound) -> sound.write(cfg, writePath); // Writer<NightSound> writer = (cfg, writePath, sound) -> sound.write(cfg, writePath);
return create(path, FileConfig::getSound, FileConfig::setSound, defaultValue, description); return create(path, FileConfig::getSound, FileConfig::set, defaultValue, description);
} }
@NotNull @NotNull
@@ -289,9 +289,6 @@ public class ConfigValue<T> {
return map; return map;
}; };
forMap("a", s -> s, s -> s, (cfg, path2) -> null, map -> {});
forMap("a", s -> s, s -> s, (cfg, path2, id) -> null, map -> {});
return create(path, reader, writer, defaultValue, description); return create(path, reader, writer, defaultValue, description);
} }
@@ -334,63 +331,16 @@ public class ConfigValue<T> {
@NotNull Function<String, K> keyReadFun, @NotNull Function<String, K> keyReadFun,
@NotNull Function<K, String> keyWriteFun, @NotNull Function<K, String> keyWriteFun,
@NotNull BiFunction<FileConfig, String, V> valReadFun, @NotNull BiFunction<FileConfig, String, V> valReadFun,
//@NotNull Supplier<Map<K, V>> mapSupplier,
@NotNull Consumer<Map<K, V>> defaultValue, @NotNull Consumer<Map<K, V>> defaultValue,
@Nullable String... description) { @Nullable String... description) {
return forMap(path,keyReadFun, keyWriteFun, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description); return forMap(path,keyReadFun, keyWriteFun, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description);
// Reader<Map<K, V>> reader = (cfg, readPath, def) -> {
// var map = new HashMap<K, V>();//mapSupplier.get();
// for (String keyRaw : cfg.getSection(readPath)) {
// K key = keyReadFun.apply(keyRaw);
// V val = valReadFun.apply(cfg, readPath + "." + keyRaw);
// if (key == null || val == null) continue;
//
// map.put(key, val);
// }
// return map;
// };
//
// Writer<Map<K, V>> writer = (cfg, writePath, map) -> {
// map.forEach((key, value) -> {
// String keyRaw = keyWriteFun.apply(key);
// value.write(cfg, writePath + "." + keyRaw);
// });
// };
//
// // Linked map used only to preserve the order of default values when writing it in the config.
// Map<K, V> defaultMap = new LinkedHashMap<>();
// defaultValue.accept(defaultMap);
//
// return create(path, reader, writer, defaultMap, description);
} }
// @NotNull
// public static <K, V extends Writeable> ConfigValue<HashMap<K, V>> forHashMap(@NotNull String path,
// @NotNull Function<String, K> keyReadFun,
// @NotNull Function<K, String> keyWriteFun,
// @NotNull BiFunction<FileConfig, String, V> valReadFun,
// @NotNull Consumer<HashMap<K, V>> defaultValue,
// @Nullable String... description) {
// return forMap(path, keyReadFun, keyWriteFun, valReadFun, HashMap::new, defaultValue, description);
// }
// @NotNull
// public static <V> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
// @NotNull Loader<V> valReadFun,
// @NotNull Consumer<Map<String, V>> defaultValue,
// @Nullable String... description) {
// //return forMap(path, String::toLowerCase, key -> key, valReadFun, defaultValue, description);
//
// return forMapById(path, (cfg, path2, id) -> valReadFun.read(cfg, path2 + "." + id), defaultValue, description);
// }
@NotNull @NotNull
public static <V> ConfigValue<Map<String, V>> forMapById(@NotNull String path, public static <V> ConfigValue<Map<String, V>> forMapById(@NotNull String path,
@NotNull BiFunction<FileConfig, String, V> valReadFun, @NotNull BiFunction<FileConfig, String, V> valReadFun,
@NotNull Consumer<Map<String, V>> defaultValue, @NotNull Consumer<Map<String, V>> defaultValue,
@Nullable String... description) { @Nullable String... description) {
//return forMap(path, String::toLowerCase, key -> key, valReadFun, defaultValue, description);
return forMapById(path, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description); return forMapById(path, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description);
} }
@@ -408,8 +358,6 @@ public class ConfigValue<T> {
@NotNull BiFunction<FileConfig, String, V> valReadFun, @NotNull BiFunction<FileConfig, String, V> valReadFun,
@NotNull Consumer<Map<E, V>> defaultValue, @NotNull Consumer<Map<E, V>> defaultValue,
@Nullable String... description) { @Nullable String... description) {
//return forMap(path, str -> StringUtil.getEnum(str, clazz).orElse(null), Enum::name, valReadFun, defaultValue, description);
return forMapByEnum(path, clazz, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description); return forMapByEnum(path, clazz, (cfg, path2, id) -> valReadFun.apply(cfg, path2), defaultValue, description);
} }
@@ -19,9 +19,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import su.nightexpress.nightcore.NightCorePlugin; import su.nightexpress.nightcore.NightCorePlugin;
import su.nightexpress.nightcore.util.*; import su.nightexpress.nightcore.util.*;
import su.nightexpress.nightcore.util.bukkit.NightItem;
import su.nightexpress.nightcore.util.bukkit.NightSound; import su.nightexpress.nightcore.util.bukkit.NightSound;
import su.nightexpress.nightcore.util.text.NightMessage; import su.nightexpress.nightcore.util.text.NightMessage;
import su.nightexpress.nightcore.util.bukkit.NightItem;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -54,6 +54,11 @@ public class FileConfig extends YamlConfiguration {
return file.getName().endsWith(EXTENSION); return file.getName().endsWith(EXTENSION);
} }
@NotNull
public static String withExtension(@NotNull String fileName) {
return fileName + EXTENSION;
}
@NotNull @NotNull
public static String getName(@NotNull File file) { public static String getName(@NotNull File file) {
String name = file.getName(); String name = file.getName();
@@ -158,11 +163,11 @@ public class FileConfig extends YamlConfiguration {
return; return;
} }
else if (value instanceof String str) { else if (value instanceof String str) {
value = Colorizer.plain(str); value = LegacyColors.plainColors(str);
} }
else if (value instanceof Collection<?> collection) { else if (value instanceof Collection<?> collection) {
List<Object> list = new ArrayList<>(collection); List<Object> list = new ArrayList<>(collection);
list.replaceAll(obj -> obj instanceof String str ? Colorizer.plain(str) : obj); list.replaceAll(obj -> obj instanceof String str ? LegacyColors.plainColors(str) : obj);
value = list; value = list;
} }
else if (value instanceof Location location) { else if (value instanceof Location location) {
@@ -274,17 +279,17 @@ public class FileConfig extends YamlConfiguration {
@Nullable @Nullable
public <T extends Enum<T>> T getEnum(@NotNull String path, @NotNull Class<T> clazz) { public <T extends Enum<T>> T getEnum(@NotNull String path, @NotNull Class<T> clazz) {
return StringUtil.getEnum(this.getString(path), clazz).orElse(null); return Enums.get(this.getString(path), clazz);
} }
@NotNull @NotNull
public <T extends Enum<T>> T getEnum(@NotNull String path, @NotNull Class<T> clazz, @NotNull T def) { public <T extends Enum<T>> T getEnum(@NotNull String path, @NotNull Class<T> clazz, @NotNull T def) {
return StringUtil.getEnum(this.getString(path), clazz).orElse(def); return Enums.parse(this.getString(path), clazz).orElse(def);
} }
@NotNull @NotNull
public <T extends Enum<T>> List<T> getEnumList(@NotNull String path, @NotNull Class<T> clazz) { public <T extends Enum<T>> List<T> getEnumList(@NotNull String path, @NotNull Class<T> clazz) {
return this.getStringSet(path).stream().map(str -> StringUtil.getEnum(str, clazz).orElse(null)) return this.getStringSet(path).stream().map(str -> Enums.parse(str, clazz).orElse(null))
.filter(Objects::nonNull).toList(); .filter(Objects::nonNull).toList();
} }
@@ -329,14 +334,16 @@ public class FileConfig extends YamlConfiguration {
@NotNull @NotNull
public NightSound getSound(@NotNull String path) { public NightSound getSound(@NotNull String path) {
if (this.contains(path + ".Name")) { return NightSound.read(this, path); // Update
return NightSound.read(this, path); // Update // if (this.contains(path + ".Name")) {
} // return NightSound.read(this, path); // Update
return NightSound.deserialize(this.getString(path, "null")); // }
// return NightSound.deserialize(this.getString(path, "null"));
} }
@Deprecated
public void setSound(@NotNull String path, @NotNull NightSound sound) { public void setSound(@NotNull String path, @NotNull NightSound sound) {
this.set(path, sound.serialize()); this.set(path, sound);
} }
@NotNull @NotNull
@@ -380,7 +387,7 @@ public class FileConfig extends YamlConfiguration {
String headSkin = this.getString(path + "SkinURL"); String headSkin = this.getString(path + "SkinURL");
if (headSkin != null) { if (headSkin != null) {
ItemUtil.setHeadSkin(item, headSkin); ItemUtil.setProfileBySkinURL(item, headSkin);
} }
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@@ -446,7 +453,7 @@ public class FileConfig extends YamlConfiguration {
Material material = item.getType(); Material material = item.getType();
this.set(path + "Material", material.name()); this.set(path + "Material", material.name());
this.set(path + "Amount", item.getAmount() <= 1 ? null : item.getAmount()); this.set(path + "Amount", item.getAmount() <= 1 ? null : item.getAmount());
this.set(path + "SkinURL", ItemUtil.getHeadSkin(item)); this.set(path + "SkinURL", ItemUtil.getProfileSkinURL(item));
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
if (meta == null) return; if (meta == null) return;
@@ -482,6 +489,7 @@ public class FileConfig extends YamlConfiguration {
} }
@Nullable @Nullable
@Deprecated
public ItemStack getItemEncoded(@NotNull String path) { public ItemStack getItemEncoded(@NotNull String path) {
String compressed = this.getString(path); String compressed = this.getString(path);
if (compressed == null) return null; if (compressed == null) return null;
@@ -489,15 +497,18 @@ public class FileConfig extends YamlConfiguration {
return ItemNbt.decompress(compressed); return ItemNbt.decompress(compressed);
} }
@Deprecated
public void setItemEncoded(@NotNull String path, @Nullable ItemStack item) { public void setItemEncoded(@NotNull String path, @Nullable ItemStack item) {
this.set(path, item == null ? null : ItemNbt.compress(item)); this.set(path, item == null ? null : ItemNbt.compress(item));
} }
@NotNull @NotNull
@Deprecated
public ItemStack[] getItemsEncoded(@NotNull String path) { public ItemStack[] getItemsEncoded(@NotNull String path) {
return ItemNbt.decompress(this.getStringList(path)); return ItemNbt.decompress(this.getStringList(path));
} }
@Deprecated
public void setItemsEncoded(@NotNull String path, @NotNull List<ItemStack> item) { public void setItemsEncoded(@NotNull String path, @NotNull List<ItemStack> item) {
this.set(path, ItemNbt.compress(item)); this.set(path, ItemNbt.compress(item));
} }
@@ -1,10 +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.*;
import su.nightexpress.nightcore.util.StringUtil;
import su.nightexpress.nightcore.util.TimeUtil;
import su.nightexpress.nightcore.util.Version;
import su.nightexpress.nightcore.util.number.NumberShortcut; import su.nightexpress.nightcore.util.number.NumberShortcut;
import su.nightexpress.nightcore.util.wrapper.UniFormatter; import su.nightexpress.nightcore.util.wrapper.UniFormatter;
@@ -53,7 +50,7 @@ public class CoreConfig {
UniFormatter::read, UniFormatter::read,
UniFormatter.of("#,###.###", RoundingMode.HALF_EVEN), UniFormatter.of("#,###.###", RoundingMode.HALF_EVEN),
"Control over how numerical data is formatted and rounded.", "Control over how numerical data is formatted and rounded.",
"Allowed modes: " + StringUtil.inlineEnum(RoundingMode.class, ", "), "Allowed modes: " + Enums.inline(RoundingMode.class),
"A tutorial can be found here: https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html" "A tutorial can be found here: https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html"
); );
@@ -1,19 +1,20 @@
package su.nightexpress.nightcore.core; package su.nightexpress.nightcore.core;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.nightcore.util.Plugins; import su.nightexpress.nightcore.Engine;
@Deprecated
public class CoreLogger { public class CoreLogger {
public static void info(@NotNull String text) { public static void info(@NotNull String text) {
Plugins.getCore().info(text); Engine.core().info(text);
} }
public static void warn(@NotNull String text) { public static void warn(@NotNull String text) {
Plugins.getCore().warn(text); Engine.core().warn(text);
} }
public static void error(@NotNull String text) { public static void error(@NotNull String text) {
Plugins.getCore().error(text); Engine.core().error(text);
} }
} }
@@ -12,9 +12,9 @@ import su.nightexpress.nightcore.command.experimental.node.ChainedNode;
import su.nightexpress.nightcore.command.experimental.node.DirectNode; import su.nightexpress.nightcore.command.experimental.node.DirectNode;
import su.nightexpress.nightcore.core.CoreLang; import su.nightexpress.nightcore.core.CoreLang;
import su.nightexpress.nightcore.core.CorePerms; import su.nightexpress.nightcore.core.CorePerms;
import su.nightexpress.nightcore.integration.VaultHook;
import su.nightexpress.nightcore.util.Colorizer;
import su.nightexpress.nightcore.util.ItemNbt; import su.nightexpress.nightcore.util.ItemNbt;
import su.nightexpress.nightcore.util.ItemTag;
import su.nightexpress.nightcore.util.Players;
import su.nightexpress.nightcore.util.Plugins; import su.nightexpress.nightcore.util.Plugins;
import su.nightexpress.nightcore.util.text.NightMessage; import su.nightexpress.nightcore.util.text.NightMessage;
@@ -30,7 +30,7 @@ public class CoreCommands {
public static void load(@NotNull NightCore core) { public static void load(@NotNull NightCore core) {
ChainedNode root = core.getRootNode(); ChainedNode root = core.getRootNode();
if (Plugins.hasVault()) { if (Plugins.hasPermissionsProvider()) {
root.addChildren(DirectNode.builder(core, CMD_CHECKPERM) root.addChildren(DirectNode.builder(core, CMD_CHECKPERM)
.permission(CorePerms.COMMAND_CHECK_PERM) .permission(CorePerms.COMMAND_CHECK_PERM)
.description(CoreLang.COMMAND_CHECKPERM_DESC) .description(CoreLang.COMMAND_CHECKPERM_DESC)
@@ -52,15 +52,15 @@ public class CoreCommands {
private static boolean checkPermissions(@NotNull CommandContext context, @NotNull ParsedArguments arguments) { private static boolean checkPermissions(@NotNull CommandContext context, @NotNull ParsedArguments arguments) {
Player player = arguments.getPlayerArgument(ARG_PLAYER); Player player = arguments.getPlayerArgument(ARG_PLAYER);
String builder = String builder =
BOLD.enclose(LIGHT_YELLOW.enclose("Permissions report for ") + LIGHT_ORANGE.enclose(player.getName() + ":")) + BOLD.wrap(LIGHT_YELLOW.wrap("Permissions report for ") + LIGHT_ORANGE.wrap(player.getName() + ":")) +
TAG_LINE_BREAK + TAG_LINE_BREAK +
LIGHT_ORANGE.enclose("▪ " + LIGHT_YELLOW.enclose("Primary Group: ") + Colorizer.plain(VaultHook.getPermissionGroup(player))) + LIGHT_ORANGE.wrap("▪ " + LIGHT_YELLOW.wrap("Primary Group: ") + Players.getPrimaryGroup(player)) +
TAG_LINE_BREAK + TAG_LINE_BREAK +
LIGHT_ORANGE.enclose("▪ " + LIGHT_YELLOW.enclose("All Groups: ") + Colorizer.plain(String.join(", ", VaultHook.getPermissionGroups(player)))) + LIGHT_ORANGE.wrap("▪ " + LIGHT_YELLOW.wrap("All Groups: ") + String.join(", ", Players.getInheritanceGroups(player))) +
TAG_LINE_BREAK + TAG_LINE_BREAK +
LIGHT_ORANGE.enclose("▪ " + LIGHT_YELLOW.enclose("Prefix: ") + VaultHook.getPrefix(player)) + LIGHT_ORANGE.wrap("▪ " + LIGHT_YELLOW.wrap("Prefix: ") + Players.getRawPrefix(player)) +
TAG_LINE_BREAK + TAG_LINE_BREAK +
LIGHT_ORANGE.enclose("▪ " + LIGHT_YELLOW.enclose("Suffix: ") + VaultHook.getSuffix(player)); LIGHT_ORANGE.wrap("▪ " + LIGHT_YELLOW.wrap("Suffix: ") + Players.getRawSuffix(player));
NightMessage.create(builder).send(context.getSender()); NightMessage.create(builder).send(context.getSender());
return true; return true;
} }
@@ -68,8 +68,10 @@ public class CoreCommands {
private static boolean dumpItem(@NotNull CommandContext context, @NotNull ParsedArguments arguments) { private static boolean dumpItem(@NotNull CommandContext context, @NotNull ParsedArguments arguments) {
Player player = context.getPlayerOrThrow(); Player player = context.getPlayerOrThrow();
ItemStack itemStack = player.getInventory().getItemInMainHand(); ItemStack itemStack = player.getInventory().getItemInMainHand();
ItemTag tag = ItemNbt.getTag(itemStack);
player.sendMessage("=".repeat(10) + " DUMP ITEM " + "=".repeat(10)); player.sendMessage("=".repeat(10) + " DUMP ITEM " + "=".repeat(10));
player.sendMessage(String.valueOf(ItemNbt.getTagString(itemStack))); player.sendMessage(tag == null ? "null": tag.getTag());
return true; return true;
} }
@@ -24,6 +24,8 @@ public class MySQLConnector extends AbstractConnector {
@Override @Override
protected void setupConfig(@NotNull DatabaseConfig config) { protected void setupConfig(@NotNull DatabaseConfig config) {
this.config.setUsername(config.getUsername()); this.config.setUsername(config.getUsername());
this.config.setPassword(config.getPassword()); if (!config.getPassword().isBlank()) {
this.config.setPassword(config.getPassword());
}
} }
} }
Loaded 100 of 326 files, more files were not shown because too many files have changed in this diff. Show more