- 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

+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);
}
}
@@ -0,0 +1,183 @@
package su.nightexpress.nightcore.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Reflex {
@Nullable
public static Class<?> getClass(@NotNull String path, @NotNull String name) {
return getClass(path + "." + name);
}
@Nullable
public static Class<?> getInnerClass(@NotNull String path, @NotNull String name) {
return getClass(path + "$" + name);
}
@Nullable
public static Class<?> getNMSClass(@NotNull String path, @NotNull String realName) {
return getNMSClass(path, realName, null);
}
@Nullable
public static Class<?> getNMSClass(@NotNull String path, @NotNull String realName, @Nullable String obfName) {
Class<?> byRealName = getClass(path + "." + realName, false);
if (byRealName != null) {
return byRealName;
}
if (obfName != null) {
return getClass(path + "." + obfName, false);
}
return null;
}
private static Class<?> getClass(@NotNull String path) {
return getClass(path, true);
}
private static Class<?> getClass(@NotNull String path, boolean printError) {
try {
return Class.forName(path);
}
catch (ClassNotFoundException exception) {
if (printError) exception.printStackTrace();
return null;
}
}
public static Constructor<?> getConstructor(@NotNull Class<?> source, Class<?>... types) {
try {
Constructor<?> constructor = source.getDeclaredConstructor(types);
constructor.setAccessible(true);
return constructor;
}
catch (ReflectiveOperationException exception) {
exception.printStackTrace();
}
return null;
}
public static Object invokeConstructor(@NotNull Constructor<?> constructor, Object... obj) {
try {
return constructor.newInstance(obj);
}
catch (ReflectiveOperationException exception) {
exception.printStackTrace();
}
return null;
}
@NotNull
public static <T> List<T> getFields(@NotNull Class<?> source, @NotNull Class<T> type) {
List<T> list = new ArrayList<>();
for (Field field : Reflex.getFields(source)) {
if (!field.getDeclaringClass().equals(source)) continue;
//if (!field.canAccess(null)) continue;
if (!Modifier.isStatic(field.getModifiers())) continue;
if (!Modifier.isFinal(field.getModifiers())) continue;
if (!type.isAssignableFrom(field.getType())) continue;
if (!field.trySetAccessible()) continue;
try {
list.add(type.cast(field.get(null)));
}
catch (IllegalArgumentException | IllegalAccessException exception) {
exception.printStackTrace();
}
}
return list;
}
@NotNull
public static List<Field> getFields(@NotNull Class<?> source) {
List<Field> result = new ArrayList<>();
Class<?> clazz = source;
while (clazz != null && clazz != Object.class) {
if (!result.isEmpty()) {
result.addAll(0, Arrays.asList(clazz.getDeclaredFields()));
}
else {
Collections.addAll(result, clazz.getDeclaredFields());
}
clazz = clazz.getSuperclass();
}
return result;
}
public static Field getField(@NotNull Class<?> source, @NotNull String name) {
try {
return source.getDeclaredField(name);
}
catch (NoSuchFieldException exception) {
Class<?> superClass = source.getSuperclass();
return superClass == null ? null : getField(superClass, name);
}
}
public static Object getFieldValue(@NotNull Object source, @NotNull String name) {
try {
Class<?> clazz = source instanceof Class<?> ? (Class<?>) source : source.getClass();
Field field = getField(clazz, name);
if (field == null) return null;
field.setAccessible(true);
return field.get(source);
}
catch (IllegalAccessException exception) {
exception.printStackTrace();
}
return null;
}
public static boolean setFieldValue(@NotNull Object source, @NotNull String name, @Nullable Object value) {
try {
boolean isStatic = source instanceof Class;
Class<?> clazz = isStatic ? (Class<?>) source : source.getClass();
Field field = getField(clazz, name);
if (field == null) return false;
field.setAccessible(true);
field.set(isStatic ? null : source, value);
return true;
}
catch (IllegalAccessException exception) {
exception.printStackTrace();
}
return false;
}
public static Method getMethod(@NotNull Class<?> source, @NotNull String name, @NotNull Class<?>... params) {
try {
return source.getDeclaredMethod(name, params);
}
catch (NoSuchMethodException exception) {
Class<?> superClass = source.getSuperclass();
return superClass == null ? null : getMethod(superClass, name);
}
}
public static Object invokeMethod(@NotNull Method method, @Nullable Object by, @Nullable Object... param) {
method.setAccessible(true);
try {
return method.invoke(by, param);
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
exception.printStackTrace();
}
return null;
}
}
@@ -0,0 +1,135 @@
package su.nightexpress.nightcore.util;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.util.Comparator;
import java.util.stream.Stream;
public enum Version {
V1_19_R3("1.19.4", 3337, Status.DROPPED),
V1_20_R1("1.20.1", 3465, Status.OUTDATED),
V1_20_R2("1.20.2", 3578, Status.OUTDATED),
V1_20_R3("1.20.4", 3700, Status.OUTDATED),
MC_1_20_6("1.20.6", 3839, Status.OUTDATED),
MC_1_21_0("1.21", 3953, Status.OUTDATED),
MC_1_21("1.21.1", 3955),
MC_1_21_2("1.21.2", 4080, Status.OUTDATED),
MC_1_21_3("1.21.3", 4082),
MC_1_21_4("1.21.4", 4189),
MC_1_21_5("1.21.5", 4325),
UNKNOWN("Unknown", 0),
;
private static Version current;
private static boolean isPaper;
private final Status status;
private final int dataVersion;
private final String localized;
Version(@NotNull String localized, int dataVersion) {
this(localized, dataVersion, Status.SUPPORTED);
}
Version(@NotNull String localized, int dataVersion, @NotNull Status status) {
this.localized = localized;
this.dataVersion = dataVersion;
this.status = status;
}
public enum Status {
SUPPORTED,
OUTDATED,
DROPPED
}
@NotNull
public static Version detect() {
String bukkitVersion = Bukkit.getServer().getBukkitVersion();
String exact = bukkitVersion.split("-")[0];
current = Stream.of(values()).sorted(Comparator.reverseOrder()).filter(version -> exact.equalsIgnoreCase(version.getLocalized())).findFirst().orElse(UNKNOWN);
isPaper = checkPaper();
return current;
}
@NotNull
public static Version getCurrent() {
return current;
}
public static boolean isSpigot() {
return !isPaper;
}
public static boolean isPaper() {
return isPaper;
}
public boolean isDeprecated() {
return this.status == Status.OUTDATED;
}
public boolean isDropped() {
return this.status == Status.DROPPED;
}
public boolean isSupported() {
return this.status == Status.SUPPORTED;
}
@NotNull
public Status getStatus() {
return this.status;
}
public int getDataVersion() {
return this.dataVersion;
}
@NotNull
public String getLocalized() {
return this.localized;
}
public boolean isLower(@NotNull Version version) {
return this.ordinal() < version.ordinal();
}
public boolean isHigher(@NotNull Version version) {
return this.ordinal() > version.ordinal();
}
public static boolean isAtLeast(@NotNull Version version) {
return version.isCurrent() || getCurrent().isHigher(version);
}
public static boolean isAbove(@NotNull Version version) {
return getCurrent().isHigher(version);
}
public static boolean isBehind(@NotNull Version version) {
return getCurrent().isLower(version);
}
public static boolean isBehindOrEqual(@NotNull Version version){
return getCurrent().isLower(version) || getCurrent() == version;
}
public boolean isCurrent() {
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);
}
@@ -0,0 +1,11 @@
package su.nightexpress.nightcore.util.bridge.wrapper;
public enum ClickEventType {
OPEN_URL,
OPEN_FILE,
RUN_COMMAND,
SUGGEST_COMMAND,
CHANGE_PAGE,
COPY_TO_CLIPBOARD
}
@@ -0,0 +1,8 @@
package su.nightexpress.nightcore.util.bridge.wrapper;
import org.jetbrains.annotations.NotNull;
public interface ComponentBuildable {
@NotNull NightComponent toComponent();
}
@@ -0,0 +1,8 @@
package su.nightexpress.nightcore.util.bridge.wrapper;
public enum HoverEventType {
SHOW_TEXT,
SHOW_ITEM
//SHOW_ENTITY,
}
@@ -0,0 +1,58 @@
package su.nightexpress.nightcore.util.bridge.wrapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
import java.util.List;
public interface NightComponent {
@NotNull NightComponent duplicate();
@NotNull String toJson();
@NotNull String toLegacy();
void send(@NotNull CommandSender sender);
void sendActionBar(@NotNull Player player);
boolean isEmpty();
boolean isText();
@NotNull String getText();
@NotNull List<? extends NightComponent> getChildrens();
void setChildrens(@NotNull List<NightComponent> childrens);
void addChildren(@NotNull NightComponent other);
void setText(@NotNull String text);
void setColor(@NotNull Color color);
void setClickEvent(@NotNull ClickEventType 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 setBold(boolean bold);
void setItalic(boolean italic);
void setObfuscated(boolean obfuscated);
void setUnderlined(boolean underlined);
void setStrikethrough(boolean strikethrough);
}