mirror of
https://github.com/darksaid98/nightcore-spigot.git
synced 2026-12-04 14:38:46 +00:00
v2.7.6
- 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:
1 parent
84addd3454
commit
12a85ce198
326 files changed
+3586
-1534
No files matched your search
@@ -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>spigot</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>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>su.nightexpress.nightcore</groupId>
|
||||
<artifactId>bridge</artifactId>
|
||||
<version>2.7.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,349 @@
|
||||
package su.nightexpress.nightcore.bridge.spigot;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Translatable;
|
||||
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.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MenuType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.bridge.wrap.NightProfile;
|
||||
import su.nightexpress.nightcore.util.*;
|
||||
import su.nightexpress.nightcore.util.bridge.Software;
|
||||
import su.nightexpress.nightcore.util.bridge.wrapper.ComponentBuildable;
|
||||
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SpigotBridge implements Software {
|
||||
|
||||
private static final String FIELD_COMMAND_MAP = "commandMap";
|
||||
private static final String FIELD_KNOWN_COMMANDS = "knownCommands";
|
||||
|
||||
private static SimpleCommandMap commandMap;
|
||||
private static AtomicInteger entityCounter;
|
||||
|
||||
private Set<ItemFlag> commonFlagsToHide;
|
||||
|
||||
@Override
|
||||
public boolean initialize() {
|
||||
loadCommandMap();
|
||||
loadEntityCounter();
|
||||
|
||||
if (Version.isAtLeast(Version.MC_1_21_5)) {
|
||||
this.commonFlagsToHide = Lists.newSet(
|
||||
ItemFlag.HIDE_ATTRIBUTES,
|
||||
ItemFlag.HIDE_UNBREAKABLE,
|
||||
ItemFlag.HIDE_ENCHANTS,
|
||||
ItemFlag.HIDE_PLACED_ON,
|
||||
ItemFlag.HIDE_DESTROYS,
|
||||
ItemFlag.HIDE_DYE,
|
||||
ItemFlag.HIDE_ARMOR_TRIM,
|
||||
ItemFlag.HIDE_ADDITIONAL_TOOLTIP
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void loadCommandMap() {
|
||||
commandMap = (SimpleCommandMap) Reflex.getFieldValue(Bukkit.getServer(), FIELD_COMMAND_MAP);
|
||||
}
|
||||
|
||||
private static void loadEntityCounter() {
|
||||
Class<?> entityClass = Reflex.getClass("net.minecraft.world.entity", "Entity");
|
||||
if (entityClass == null) return;
|
||||
|
||||
String fieldName = Version.isBehind(Version.MC_1_20_6) ? "d" : "c";
|
||||
|
||||
Object object = Reflex.getFieldValue(entityClass, fieldName);
|
||||
if (!(object instanceof AtomicInteger atomicInteger)) return;
|
||||
|
||||
entityCounter = atomicInteger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return "spigot-bridge";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaper() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextEntityId() {
|
||||
return entityCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SimpleCommandMap getCommandMap() {
|
||||
if (commandMap == null) throw new IllegalStateException("Command map is null!");
|
||||
|
||||
return commandMap;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@NotNull
|
||||
public Map<String, Command> getKnownCommands(@NotNull SimpleCommandMap commandMap) {
|
||||
Map<String, Command> knownCommands = (Map<String, Command>) Reflex.getFieldValue(commandMap, FIELD_KNOWN_COMMANDS);
|
||||
return knownCommands == null ? Collections.emptyMap() : knownCommands;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightComponent textComponent(@NotNull String text) {
|
||||
return SpigotComponent.text(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightComponent translateComponent(@NotNull String key) {
|
||||
return SpigotComponent.translate(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightComponent translateComponent(@NotNull String key, @Nullable String fallback) {
|
||||
return SpigotComponent.translate(key, fallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightComponent buildComponent(@NotNull List<ComponentBuildable> childrens) {
|
||||
return SpigotComponent.builder(childrens);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightProfile createProfile(@NotNull UUID uuid) {
|
||||
return new SpigotProfile(Bukkit.createPlayerProfile(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightProfile createProfile(@NotNull String name) {
|
||||
return new SpigotProfile(Bukkit.createPlayerProfile(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
|
||||
return new SpigotProfile(Bukkit.createPlayerProfile(uuid, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightProfile getProfile(@NotNull OfflinePlayer player) {
|
||||
return new SpigotProfile(player.getPlayerProfile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitles(@NotNull Player player, @NotNull NightComponent title, @NotNull NightComponent subtitle, int fadeIn, int stay, int fadeOut) {
|
||||
//title = NightMessage.asLegacy(title);
|
||||
//subtitle = NightMessage.asLegacy(subtitle);
|
||||
|
||||
player.sendTitle(title.toLegacy(), subtitle.toLegacy(), fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public InventoryView createView(@NotNull MenuType menuType, @NotNull NightComponent title, @NotNull Player player) {
|
||||
String legacy = title.toLegacy();//NightMessage.asLegacy(title);
|
||||
|
||||
if (Version.isAtLeast(Version.MC_1_21_4)) {
|
||||
var builder = menuType.typed().builder();
|
||||
Reflex.setFieldValue(builder, "title", legacy);
|
||||
return builder.build(player);
|
||||
}
|
||||
else {
|
||||
return menuType.typed().create(player, legacy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getTranslationKey(@NotNull Material material) {
|
||||
return getTranslation(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getTranslationKey(@NotNull Attribute attribute) {
|
||||
return getTranslation(attribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getTranslationKey(@NotNull EntityType entityType) {
|
||||
return getTranslation(entityType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getTranslationKey(@NotNull Enchantment enchantment) {
|
||||
return getTranslation(enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getTranslationKey(@NotNull PotionEffectType effectType) {
|
||||
return getTranslation(effectType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getTranslation(@NotNull Translatable translatable) {
|
||||
return translatable.getTranslationKey();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ItemStack setType(@NotNull ItemStack itemStack, @NotNull Material material) {
|
||||
itemStack.setType(material);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public void editMeta(@NotNull ItemStack item, @NotNull Consumer<ItemMeta> consumer) {
|
||||
editItemMeta(item, ItemMeta.class, consumer);
|
||||
}
|
||||
|
||||
public <T extends ItemMeta> void editMeta(@NotNull ItemStack item, @NotNull Class<T> clazz, @NotNull Consumer<T> consumer) {
|
||||
editItemMeta(item, clazz, consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getCustomName(@NotNull ItemMeta meta) {
|
||||
return meta.hasDisplayName() ? LegacyColors.plainColors(meta.getDisplayName()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(@NotNull ItemMeta meta, @NotNull NightComponent name) {
|
||||
//meta.setDisplayName(NightMessage.asLegacy(name));
|
||||
meta.setDisplayName(name.toLegacy());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getItemName(@NotNull ItemMeta meta) {
|
||||
return meta.hasItemName() ? LegacyColors.plainColors(meta.getItemName()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemName(@NotNull ItemMeta meta, @NotNull NightComponent name) {
|
||||
//meta.setItemName(NightMessage.asLegacy(name));
|
||||
meta.setItemName(name.toLegacy());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<String> getLore(@NotNull ItemMeta meta) {
|
||||
List<String> lore = meta.getLore();
|
||||
return lore == null ? null : Lists.modify(lore, LegacyColors::plainColors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLore(@NotNull ItemMeta meta, @NotNull List<NightComponent> lore) {
|
||||
//meta.setLore(NightMessage.asLegacy(lore));
|
||||
meta.setLore(lore.stream().map(NightComponent::toLegacy).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public NightProfile getOwnerProfile(@NotNull ItemStack itemStack) {
|
||||
if (!(itemStack.getItemMeta() instanceof SkullMeta meta)) return null;
|
||||
|
||||
PlayerProfile profile = meta.getOwnerProfile();
|
||||
return profile == null ? null : new SpigotProfile(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<String> getCommonComponentsToHide() {
|
||||
if (this.commonFlagsToHide == null) return new HashSet<>(); // Fix for <= 1.21.4
|
||||
|
||||
return this.commonFlagsToHide.stream().map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<String> getHiddenComponents(@NotNull ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.hasItemMeta() ? itemStack.getItemMeta() : null;
|
||||
if (meta == null) return Collections.emptySet();
|
||||
|
||||
return meta.getItemFlags().stream().map(Enum::name).map(String::toLowerCase).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideComponents(@NotNull ItemStack itemStack) {
|
||||
// ItemUtil.editMeta(itemStack, meta -> {
|
||||
// meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
// meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
// meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
// meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
|
||||
// meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
|
||||
// meta.addItemFlags(ItemFlag.HIDE_DYE);
|
||||
// meta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM);
|
||||
// meta.addItemFlags(ItemFlag.valueOf("HIDE_ADDITIONAL_TOOLTIP"));
|
||||
// });
|
||||
|
||||
if (commonFlagsToHide == null) return;
|
||||
|
||||
hideSpigotComponents(itemStack, this.commonFlagsToHide);
|
||||
}
|
||||
|
||||
public void hideComponents(@NotNull ItemStack itemStack, @NotNull Set<String> componentNames) {
|
||||
hideComponentsByName(itemStack, componentNames);
|
||||
}
|
||||
|
||||
public static void hideComponentsByName(@NotNull ItemStack itemStack, @NotNull Set<String> componentNames) {
|
||||
Set<ItemFlag> componentTypes = componentNames.stream().map(name -> Enums.parse(name, ItemFlag.class).orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
hideSpigotComponents(itemStack, componentTypes);
|
||||
}
|
||||
|
||||
public static void hideSpigotComponents(@NotNull ItemStack itemStack, @NotNull Set<ItemFlag> componentTypes) {
|
||||
editItemMeta(itemStack, meta -> componentTypes.forEach(meta::addItemFlags));
|
||||
}
|
||||
|
||||
private static void editItemMeta(@NotNull ItemStack item, @NotNull Consumer<ItemMeta> consumer) {
|
||||
editItemMeta(item, ItemMeta.class, consumer);
|
||||
}
|
||||
|
||||
private static <T extends ItemMeta> void editItemMeta(@NotNull ItemStack item, @NotNull Class<T> clazz, @NotNull Consumer<T> consumer) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return;
|
||||
if (!clazz.isAssignableFrom(meta.getClass())) return;
|
||||
|
||||
T specific = clazz.cast(meta);
|
||||
|
||||
consumer.accept(specific);
|
||||
item.setItemMeta(specific);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package su.nightexpress.nightcore.bridge.spigot;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.*;
|
||||
import net.md_5.bungee.api.chat.hover.content.Item;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.util.BukkitThing;
|
||||
import su.nightexpress.nightcore.util.Version;
|
||||
import su.nightexpress.nightcore.util.bridge.wrapper.ClickEventType;
|
||||
import su.nightexpress.nightcore.util.bridge.wrapper.ComponentBuildable;
|
||||
import su.nightexpress.nightcore.util.bridge.wrapper.NightComponent;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotComponent implements NightComponent {
|
||||
|
||||
private final BaseComponent parent;
|
||||
|
||||
public SpigotComponent(BaseComponent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SpigotComponent text(@NotNull String text) {
|
||||
return new SpigotComponent(new TextComponent(text));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SpigotComponent translate(@NotNull String key) {
|
||||
return new SpigotComponent(new TranslatableComponent(key));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SpigotComponent translate(@NotNull String key, @Nullable String fallback) {
|
||||
TranslatableComponent component = new TranslatableComponent(key);
|
||||
component.setFallback(fallback);
|
||||
|
||||
return new SpigotComponent(component);
|
||||
}
|
||||
|
||||
public static SpigotComponent builder(@NotNull List<ComponentBuildable> childrens) {
|
||||
ComponentBuilder builder = new ComponentBuilder();
|
||||
|
||||
childrens.forEach(child -> {
|
||||
SpigotComponent childComponent = (SpigotComponent) child.toComponent();
|
||||
builder.append(childComponent.parent);
|
||||
});
|
||||
|
||||
return new SpigotComponent(build(builder));
|
||||
}
|
||||
|
||||
private static BaseComponent build(@NotNull ComponentBuilder builder) {
|
||||
if (Version.isAtLeast(Version.MC_1_20_6)) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
TextComponent base = new TextComponent();
|
||||
if (!builder.getParts().isEmpty()) {
|
||||
List<BaseComponent> cloned = new ArrayList<>(builder.getParts());
|
||||
cloned.replaceAll(BaseComponent::duplicate);
|
||||
base.setExtra(cloned);
|
||||
}
|
||||
return base;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BaseComponent getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NightComponent duplicate() {
|
||||
return new SpigotComponent(this.parent.duplicate());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toJson() {
|
||||
return ComponentSerializer.toString(this.parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toLegacy() {
|
||||
return TextComponent.toLegacyText(this.parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(@NotNull CommandSender sender) {
|
||||
sender.spigot().sendMessage(this.parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionBar(@NotNull Player player) {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, this.parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.parent instanceof TextComponent textComponent && textComponent.getText().isBlank() && textComponent.getExtra() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isText() {
|
||||
return this.parent instanceof TextComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return this.parent instanceof TextComponent textComponent ? textComponent.getText() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<SpigotComponent> getChildrens() {
|
||||
return this.parent.getExtra().stream().map(SpigotComponent::new).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChildrens(@NotNull List<NightComponent> childrens) {
|
||||
this.parent.setExtra(childrens.stream().map(child -> ((SpigotComponent)child).parent).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChildren(@NotNull NightComponent other) {
|
||||
if (other instanceof SpigotComponent spigotComponent) {
|
||||
this.parent.addExtra(spigotComponent.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(@NotNull String text) {
|
||||
if (this.parent instanceof TextComponent textComponent) {
|
||||
textComponent.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(@NotNull Color color) {
|
||||
this.parent.setColor(ChatColor.of(color));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClickEvent(@NotNull ClickEventType type, @NotNull String value) {
|
||||
ClickEvent.Action action = switch (type) {
|
||||
case ClickEventType.OPEN_URL -> ClickEvent.Action.OPEN_URL;
|
||||
case ClickEventType.OPEN_FILE -> ClickEvent.Action.OPEN_FILE;
|
||||
case ClickEventType.CHANGE_PAGE -> ClickEvent.Action.CHANGE_PAGE;
|
||||
case ClickEventType.RUN_COMMAND -> ClickEvent.Action.RUN_COMMAND;
|
||||
case ClickEventType.SUGGEST_COMMAND -> ClickEvent.Action.SUGGEST_COMMAND;
|
||||
case ClickEventType.COPY_TO_CLIPBOARD -> ClickEvent.Action.COPY_TO_CLIPBOARD;
|
||||
};
|
||||
|
||||
this.parent.setClickEvent(new ClickEvent(action, value));
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void setHoverEvent(@NotNull HoverEventType type, @NotNull String value) {
|
||||
// switch (type) {
|
||||
// case HoverEventType.SHOW_TEXT -> {
|
||||
// SpigotComponent component = (SpigotComponent) NightMessage.parse(value);
|
||||
//
|
||||
// Text text;
|
||||
// if (Version.isAtLeast(Version.MC_1_20_6)) {
|
||||
// text = new Text(component.parent);
|
||||
// }
|
||||
// else {
|
||||
// text = new Text(new ComponentBuilder().append(component.parent).create());
|
||||
// }
|
||||
//
|
||||
// this.parent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, text));
|
||||
// }
|
||||
// case HoverEventType.SHOW_ITEM -> {
|
||||
// ItemStack itemStack = ItemNbt.getHoverEventItem(value);
|
||||
// if (itemStack == null) return;
|
||||
//
|
||||
// String key = BukkitThing.toString(itemStack.getType());
|
||||
// ItemMeta meta = itemStack.getItemMeta();
|
||||
// String nbt = meta == null ? "{}" : meta.getAsString();
|
||||
//
|
||||
// Item item = new Item(key, itemStack.getAmount(), ItemTag.ofNbt(nbt));
|
||||
// this.parent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, item));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void setHoverEvent(@NotNull NightComponent hoverText) {
|
||||
SpigotComponent component = (SpigotComponent) hoverText;
|
||||
|
||||
Text text;
|
||||
if (Version.isAtLeast(Version.MC_1_20_6)) {
|
||||
text = new Text(component.parent);
|
||||
}
|
||||
else {
|
||||
text = new Text(new ComponentBuilder().append(component.parent).create());
|
||||
}
|
||||
|
||||
this.parent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoverEvent(@NotNull ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) return;
|
||||
|
||||
String nbt = meta.getAsString();
|
||||
String key = BukkitThing.getAsString(itemStack.getType());
|
||||
|
||||
Item item = new Item(key, itemStack.getAmount(), ItemTag.ofNbt(nbt));
|
||||
this.parent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFont(@NotNull String font) {
|
||||
this.parent.setFont(font);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBold(boolean bold) {
|
||||
this.parent.setBold(bold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItalic(boolean italic) {
|
||||
this.parent.setItalic(italic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObfuscated(boolean obfuscated) {
|
||||
this.parent.setObfuscated(obfuscated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnderlined(boolean underlined) {
|
||||
this.parent.setUnderlined(underlined);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStrikethrough(boolean strikethrough) {
|
||||
this.parent.setStrikethrough(strikethrough);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package su.nightexpress.nightcore.bridge.spigot;
|
||||
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.bukkit.profile.PlayerTextures;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.nightexpress.nightcore.bridge.wrap.NightProfile;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SpigotProfile implements NightProfile {
|
||||
|
||||
private final PlayerProfile backend;
|
||||
|
||||
public SpigotProfile(PlayerProfile backend) {
|
||||
this.backend = backend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull SkullMeta meta) {
|
||||
meta.setOwnerProfile(this.backend);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public UUID getId() {
|
||||
return this.backend.getUniqueId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getName() {
|
||||
return this.backend.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public PlayerTextures getTextures() {
|
||||
return this.backend.getTextures();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextures(@Nullable PlayerTextures textures) {
|
||||
this.backend.setTextures(textures);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComplete() {
|
||||
return this.backend.isComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CompletableFuture<NightProfile> update() {
|
||||
return this.backend.update().thenApplyAsync(SpigotProfile::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SpigotProfile{" +
|
||||
"backend=" + backend +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user