From 844e53ff1ad3635de438554d795cc44bbc786a02 Mon Sep 17 00:00:00 2001 From: XiaoMoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Sun, 6 Oct 2024 01:25:48 +0800 Subject: [PATCH] API --- api/build.gradle.kts | 4 - .../api/AbstractCNPlayer.java | 42 +- .../customnameplates/api/CNPlayer.java | 371 +++++++++++++++--- .../customnameplates/api/ConfigManager.java | 2 +- .../api/CustomNameplates.java | 170 ++++++-- .../customnameplates/api/MainTask.java | 35 +- .../customnameplates/api/Platform.java | 148 +++++++ .../api/event/DataLoadEvent.java | 12 +- .../api/event/NameplatesReloadEvent.java | 6 +- .../api/feature/AdaptiveImage.java | 24 ++ .../api/feature/CarouselText.java | 38 +- .../feature/{pack => }/CharacterArranger.java | 26 +- .../api/feature/ChatListener.java | 11 + .../api/feature/ConfiguredCharacter.java | 74 +++- .../api/feature/DynamicText.java | 26 ++ .../customnameplates/api/feature/Feature.java | 26 +- .../api/feature/JoinQuitListener.java | 13 + .../api/feature/RelationalFeature.java | 10 + .../api/feature/TickStampData.java | 67 +++- .../feature/actionbar/ActionBarConfig.java | 46 +++ .../feature/actionbar/ActionBarManager.java | 30 +- .../api/feature/advance/AdvanceManager.java | 51 ++- .../advance/CharacterFontAdvanceData.java | 60 ++- .../advance/CharacterFontAdvanceDataImpl.java | 5 - .../advance/ConfigurableFontAdvanceData.java | 57 +++ .../api/feature/background/Background.java | 137 +++++++ .../feature/background/BackgroundManager.java | 13 +- .../api/feature/bossbar/BossBar.java | 21 + .../api/feature/bossbar/BossBarConfig.java | 97 ++++- .../api/feature/bossbar/BossBarManager.java | 22 +- .../api/feature/bubble/Bubble.java | 68 ++++ .../api/feature/bubble/BubbleConfig.java | 112 ++++++ .../api/feature/bubble/BubbleManager.java | 102 ++++- .../chat/AbstractChatMessageProvider.java | 18 +- .../{bubble => }/chat/ChatManager.java | 38 +- .../chat/ChatMessageProvider.java | 26 +- .../{bubble => chat}/emoji/EmojiProvider.java | 15 +- .../api/feature/image/Image.java | 58 +++ .../api/feature/image/ImageManager.java | 15 +- .../api/feature/nameplate/Nameplate.java | 70 +++- .../feature/nameplate/NameplateManager.java | 38 +- .../api/feature/pack/ResourcePackManager.java | 3 + .../api/feature/tag/AbstractTag.java | 14 +- .../api/feature/tag/NameTagConfig.java | 212 ++++++++++ .../customnameplates/api/feature/tag/Tag.java | 139 ++++++- .../api/feature/tag/TagRenderer.java | 49 +++ .../api/feature/tag/UnlimitedTagManager.java | 68 +++- .../api/helper/AdventureHelper.java | 32 ++ .../api/network/PacketEvent.java | 35 +- .../api/network/PacketSender.java | 15 + .../api/network/PipelineInjector.java | 27 +- .../customnameplates/api/network/Tracker.java | 13 +- .../api/placeholder/AbstractPlaceholder.java | 59 ++- .../api/placeholder/DummyPlaceholder.java | 53 ++- .../api/placeholder/Placeholder.java | 34 +- .../api/placeholder/PlaceholderCounter.java | 11 + .../api/placeholder/PlaceholderManager.java | 126 ++++-- .../api/placeholder/PlayerPlaceholder.java | 11 +- .../placeholder/RelationalPlaceholder.java | 10 + .../api/placeholder/SharedPlaceholder.java | 16 + .../internal/AdaptiveImageText.java | 2 + .../api/placeholder/internal/ShiftText.java | 2 + .../api/placeholder/internal/StaticText.java | 2 + .../api/placeholder/internal/VanillaHud.java | 2 + .../api/requirement/EmptyRequirement.java | 30 ++ .../api/requirement/Requirement.java | 33 +- .../api/requirement/RequirementFactory.java | 9 +- .../api/requirement/RequirementManager.java | 56 ++- .../api/storage/DataStorageProvider.java | 29 +- .../api/storage/StorageManager.java | 45 ++- .../api/storage/data/JsonData.java | 27 ++ .../api/storage/data/PlayerData.java | 67 +++- backend/build.gradle.kts | 6 + .../actionbar/ActionBarManagerImpl.java | 13 +- .../feature/actionbar/ActionBarSender.java | 10 +- .../feature/advance/AdvanceManagerImpl.java | 25 +- .../feature/advance/SizeOverrides.java | 3 +- .../background/BackgroundManagerImpl.java | 6 +- .../bossbar/BossBarDisplayController.java | 6 +- .../feature/bossbar/BossBarManagerImpl.java | 9 +- .../feature/bossbar/BossBarSender.java | 4 +- .../feature/bubble/BubbleManagerImpl.java | 23 +- .../backend}/feature/bubble/BubbleTag.java | 6 +- .../feature}/chat/AbstractChatManager.java | 7 +- .../feature/image/ImageManagerImpl.java | 8 +- .../nameplate/NameplateManagerImpl.java | 10 +- .../feature/pack/ResourcePackManagerImpl.java | 11 +- .../backend}/feature/tag/NameTag.java | 5 +- .../backend}/feature/tag/TagRendererImpl.java | 16 +- .../feature/tag/UnlimitedTagManagerImpl.java | 9 +- .../placeholder/PlaceholderManagerImpl.java | 51 +-- .../placeholder/PlayerPlaceholderImpl.java | 5 +- .../RelationalPlaceholderImpl.java | 5 +- .../placeholder/SharedPlaceholderImpl.java | 6 +- .../requirement/AbstractRequirement.java | 4 +- .../AbstractRequirementManager.java | 7 +- .../requirement/builtin/AndRequirement.java | 4 +- .../builtin/ContainsRequirement.java | 2 +- .../builtin/EndWithRequirement.java | 2 +- .../builtin/EqualsRequirement.java | 2 +- .../builtin/HasBubbleRequirement.java | 4 +- .../builtin/HasNameplateRequirement.java | 4 +- .../builtin/InListRequirement.java | 2 +- .../builtin/NotContainsRequirement.java | 2 +- .../builtin/NotEndWithRequirement.java | 2 +- .../builtin/NotEqualsRequirement.java | 2 +- .../builtin/NotInListRequirement.java | 2 +- .../builtin/NotStartWithRequirement.java | 2 +- .../builtin/NumberEqualsRequirement.java | 2 +- .../builtin/NumberGreaterRequirement.java | 2 +- .../builtin/NumberLessRequirement.java | 2 +- .../builtin/NumberNoGreaterRequirement.java | 2 +- .../builtin/NumberNoLessRequirement.java | 2 +- .../builtin/NumberNotEqualsRequirement.java | 2 +- .../requirement/builtin/OrRequirement.java | 4 +- .../builtin/PlaceholderRequirement.java | 4 +- .../builtin/PlaceholdersRequirement.java | 4 +- .../requirement/builtin/RegexRequirement.java | 2 +- .../builtin/StartWithRequirement.java | 2 +- .../backend/storage/StorageManagerImpl.java | 13 +- .../backend/storage/method/DummyStorage.java | 2 +- .../database/nosql/MongoDBProvider.java | 2 +- .../method/database/nosql/RedisManager.java | 2 +- .../database/sql/AbstractHikariDatabase.java | 8 +- .../database/sql/AbstractSQLDatabase.java | 2 +- .../method/database/sql/H2Provider.java | 2 +- .../method/database/sql/MariaDBProvider.java | 2 +- .../method/database/sql/MySQLProvider.java | 2 +- .../method/database/sql/SQLiteProvider.java | 2 +- .../storage/method/file/JsonProvider.java | 4 +- .../storage/method/file/YAMLProvider.java | 2 +- .../bukkit/BukkitChatManager.java | 2 +- .../bukkit/BukkitCustomNameplates.java | 37 +- .../bukkit/BukkitPlatform.java | 2 +- .../command/feature/BubblesEquipCommand.java | 10 +- .../feature/BubblesForceEquipCommand.java | 12 +- .../feature/BubblesForceUnEquipCommand.java | 8 +- .../feature/BubblesUnEquipCommand.java | 8 +- .../feature/NameplatesEquipCommand.java | 10 +- .../feature/NameplatesForceEquipCommand.java | 12 +- .../NameplatesForcePreviewCommand.java | 2 +- .../NameplatesForceUnEquipCommand.java | 8 +- .../feature/NameplatesUnEquipCommand.java | 8 +- .../requirement/BukkitRequirementManager.java | 2 +- .../builtin/BedrockPlayerRequirement.java | 2 +- .../requirement/builtin/BiomeRequirement.java | 2 +- .../builtin/CooldownRequirement.java | 2 +- .../requirement/builtin/DateRequirement.java | 2 +- .../builtin/DisguiseRequirement.java | 4 +- .../builtin/DisguiseTypeRequirement.java | 2 +- .../builtin/EnvironmentRequirement.java | 2 +- .../builtin/FloodGateRequirement.java | 2 +- .../builtin/GameModeRequirement.java | 2 +- .../builtin/GeyserRequirement.java | 2 +- .../requirement/builtin/LevelRequirement.java | 2 +- .../builtin/NotBiomeRequirement.java | 2 +- .../builtin/NotDisguiseTypeRequirement.java | 2 +- .../builtin/NotEnvironmentRequirement.java | 2 +- .../builtin/NotGameModeRequirement.java | 2 +- .../builtin/NotPermissionRequirement.java | 2 +- .../builtin/NotWorldRequirement.java | 2 +- .../builtin/PermissionRequirement.java | 2 +- .../builtin/PotionEffectRequirement.java | 2 +- .../builtin/RandomRequirement.java | 2 +- .../requirement/builtin/TimeRequirement.java | 2 +- .../builtin/WeatherRequirement.java | 2 +- .../requirement/builtin/WorldRequirement.java | 2 +- .../requirement/builtin/YRequirement.java | 2 +- .../chat/AdvancedChatProvider.java | 4 +- .../compatibility/chat/AsyncChatProvider.java | 4 +- .../chat/CarbonChatProvider.java | 4 +- .../chat/EssentialsChatProvider.java | 4 +- .../compatibility/chat/HuskChatProvider.java | 4 +- .../compatibility/chat/TrChatProvider.java | 4 +- .../chat/VentureChatProvider.java | 4 +- .../emoji/ItemsAdderEmojiProvider.java | 2 +- .../emoji/OraxenEmojiProvider.java | 2 +- gradle.properties | 12 +- 178 files changed, 3460 insertions(+), 546 deletions(-) rename api/src/main/java/net/momirealms/customnameplates/api/feature/{pack => }/CharacterArranger.java (64%) rename api/src/main/java/net/momirealms/customnameplates/api/feature/{bubble => }/chat/AbstractChatMessageProvider.java (64%) rename api/src/main/java/net/momirealms/customnameplates/api/feature/{bubble => }/chat/ChatManager.java (50%) rename api/src/main/java/net/momirealms/customnameplates/api/feature/{bubble => }/chat/ChatMessageProvider.java (50%) rename api/src/main/java/net/momirealms/customnameplates/api/feature/{bubble => chat}/emoji/EmojiProvider.java (60%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/actionbar/ActionBarManagerImpl.java (91%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/actionbar/ActionBarSender.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/advance/AdvanceManagerImpl.java (98%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/advance/SizeOverrides.java (92%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/background/BackgroundManagerImpl.java (95%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/bossbar/BossBarDisplayController.java (90%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/bossbar/BossBarManagerImpl.java (93%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/bossbar/BossBarSender.java (96%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/bubble/BubbleManagerImpl.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/bubble/BubbleTag.java (97%) rename {api/src/main/java/net/momirealms/customnameplates/api/feature/bubble => backend/src/main/java/net/momirealms/customnameplates/backend/feature}/chat/AbstractChatManager.java (90%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/image/ImageManagerImpl.java (91%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/nameplate/NameplateManagerImpl.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/pack/ResourcePackManagerImpl.java (99%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/tag/NameTag.java (96%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/tag/TagRendererImpl.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/feature/tag/UnlimitedTagManagerImpl.java (95%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/placeholder/PlaceholderManagerImpl.java (95%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/placeholder/PlayerPlaceholderImpl.java (81%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/placeholder/RelationalPlaceholderImpl.java (81%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/placeholder/SharedPlaceholderImpl.java (82%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/AbstractRequirement.java (88%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/AbstractRequirementManager.java (97%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/AndRequirement.java (93%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/ContainsRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/EndWithRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/EqualsRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/HasBubbleRequirement.java (92%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/HasNameplateRequirement.java (92%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/InListRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NotContainsRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NotEndWithRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NotEqualsRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NotInListRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NotStartWithRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NumberEqualsRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NumberGreaterRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NumberLessRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NumberNoGreaterRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NumberNoLessRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/NumberNotEqualsRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/OrRequirement.java (93%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/PlaceholderRequirement.java (92%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/PlaceholdersRequirement.java (93%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/RegexRequirement.java (94%) rename {api/src/main/java/net/momirealms/customnameplates/api => backend/src/main/java/net/momirealms/customnameplates/backend}/requirement/builtin/StartWithRequirement.java (94%) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 5eed195..a9762e7 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -17,10 +17,6 @@ dependencies { compileOnly("com.github.ben-manes.caffeine:caffeine:${rootProject.properties["caffeine_version"]}") // Netty compileOnly("io.netty:netty-all:4.1.113.Final") - // FOP - compileOnly("org.apache.pdfbox:fontbox:${rootProject.properties["fontbox_version"]}") - // COMMONS IO - compileOnly("commons-io:commons-io:${rootProject.properties["commons_io_version"]}") // GSON compileOnly("com.google.code.gson:gson:${rootProject.properties["gson_version"]}") } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/AbstractCNPlayer.java b/api/src/main/java/net/momirealms/customnameplates/api/AbstractCNPlayer.java index 5d626c7..c71044f 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/AbstractCNPlayer.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/AbstractCNPlayer.java @@ -25,6 +25,8 @@ import net.momirealms.customnameplates.api.placeholder.PlayerPlaceholder; import net.momirealms.customnameplates.api.placeholder.RelationalPlaceholder; import net.momirealms.customnameplates.api.placeholder.SharedPlaceholder; import net.momirealms.customnameplates.api.requirement.Requirement; +import net.momirealms.customnameplates.api.storage.data.PlayerData; +import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -42,22 +44,12 @@ public abstract class AbstractCNPlayer implements CNPlayer { private String equippedNameplate; private String equippedBubble; - /** - * 此处缓存了所有解析过的变量,Relational则是缓存了与某个玩家的关系变量,仅更新当前处于active状态的变量。 - */ private final Map> cachedValues = new ConcurrentHashMap<>(); private final Map>> cachedRelationalValues = new ConcurrentHashMap<>(); - /** - * 此处缓存了所有解析过的条件,Relational则是缓存了与某个玩家的关系条件 - */ private final Map> cachedRequirements = new ConcurrentHashMap<>(); private final Map>> cachedRelationalRequirements = new ConcurrentHashMap<>(); - /* - * 这里维护了一个双向的Map以方便更新对应的Feature。 - * 插件会先获取当前处于活跃状态的变量(由Feature提供),根据变量的更新情况,判断是否需要反馈到对应的Feature以便只在必要的时刻进行更新 - */ private final Set activeFeatures = new CopyOnWriteArraySet<>(); private final Map> placeholder2Features = new ConcurrentHashMap<>(); private final Map> feature2Placeholders = new ConcurrentHashMap<>(); @@ -75,7 +67,7 @@ public abstract class AbstractCNPlayer implements CNPlayer { * @return 更新任务 */ @Override - public List getRefreshValueTask() { + public List activePlaceholdersToRefresh() { Placeholder[] activePlaceholders = activePlaceholders(); List placeholderWithChildren = new ArrayList<>(); for (Placeholder placeholder : activePlaceholders) { @@ -167,13 +159,15 @@ public abstract class AbstractCNPlayer implements CNPlayer { public void reload() { cachedValues.clear(); cachedRelationalValues.clear(); + cachedRequirements.clear(); + cachedRelationalRequirements.clear(); activeFeatures.clear(); placeholder2Features.clear(); feature2Placeholders.clear(); } @Override - public Set getUsedFeatures(Placeholder placeholder) { + public Set activeFeatures(Placeholder placeholder) { return placeholder2Features.getOrDefault(placeholder, Collections.emptySet()); } @@ -286,7 +280,7 @@ public abstract class AbstractCNPlayer implements CNPlayer { } @Override - public String getData(Placeholder placeholder) { + public @NotNull String getData(Placeholder placeholder) { return Optional.ofNullable(cachedValues.get(placeholder.countId())).map(TickStampData::data).orElse(placeholder.id()); } @@ -296,10 +290,10 @@ public abstract class AbstractCNPlayer implements CNPlayer { } @Override - public String getRelationalData(Placeholder placeholder, CNPlayer another) { + public @NotNull String getRelationalData(Placeholder placeholder, CNPlayer another) { WeakHashMap> map = cachedRelationalValues.get(placeholder.countId()); if (map == null) { - return null; + return placeholder.id(); } return Optional.ofNullable(map.get(another)).map(TickStampData::data).orElse(placeholder.id()); } @@ -442,11 +436,12 @@ public abstract class AbstractCNPlayer implements CNPlayer { } @Override - public void equippedBubble(String equippedBubble) { + public boolean equippedBubble(String equippedBubble) { + if (!isLoaded()) return false; if (!equippedBubble.equals(this.equippedBubble)) { this.equippedBubble = equippedBubble; - // TODO 更新变量 } + return true; } @Override @@ -456,11 +451,22 @@ public abstract class AbstractCNPlayer implements CNPlayer { } @Override - public void equippedNameplate(String equippedNameplate) { + public boolean equippedNameplate(String equippedNameplate) { + if (!isLoaded()) return false; if (!equippedNameplate.equals(this.equippedNameplate)) { this.equippedNameplate = equippedNameplate; // TODO 更新变量 } + return true; + } + + @Override + public void save() { + plugin.getStorageManager().dataSource().updatePlayerData(PlayerData.builder() + .uuid(uuid()) + .nameplate(equippedNameplate()) + .bubble(equippedBubble()) + .build(), plugin.getScheduler().async()); } @Override diff --git a/api/src/main/java/net/momirealms/customnameplates/api/CNPlayer.java b/api/src/main/java/net/momirealms/customnameplates/api/CNPlayer.java index 3f74c7e..d512fdf 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/CNPlayer.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/CNPlayer.java @@ -23,6 +23,8 @@ import net.momirealms.customnameplates.api.network.Tracker; import net.momirealms.customnameplates.api.placeholder.Placeholder; import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.util.Vector3; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Set; @@ -30,89 +32,342 @@ import java.util.UUID; public interface CNPlayer { + /** + * Returns the player's name. + * + * @return the player's name + */ String name(); + /** + * Returns the UUID of the player. + * + * @return the player's UUID + */ UUID uuid(); - int entityID(); - - Vector3 position(); - - String world(); - - void forceUpdate(Set placeholders, Set another); - - Set getUsedFeatures(Placeholder placeholder); - + /** + * Returns the underlying player object (server-side representation). + * + * @return the player object + */ Object player(); - double scale(); + /** + * Returns the entity ID of the player. + * + * @return the entity ID + */ + int entityID(); - boolean isCrouching(); + /** + * Returns the player's current position as a {@link Vector3}. + * + * @return the player's position + */ + Vector3 position(); - boolean isLoaded(); - - boolean isPreviewing(); - - boolean hasPermission(String permission); - - long playerTime(); - - List getRefreshValueTask(); - - Placeholder[] activePlaceholders(); + /** + * Returns the name of the world the player is in. + * + * @return the world name + */ + String world(); + /** + * Checks if the player is currently online. + * + * @return true if the player is online, false otherwise + */ boolean isOnline(); - String getData(Placeholder placeholder); + /** + * Returns the scale of the player. + * + * @return the player's scale + */ + double scale(); - TickStampData getValue(Placeholder placeholder); + /** + * Checks if the player is crouching. + * + * @return true if the player is crouching, false otherwise + */ + boolean isCrouching(); - String getRelationalData(Placeholder placeholder, CNPlayer another); + /** + * Checks if the player has been fully loaded into the system. + * + * @return true if the player is loaded, false otherwise + */ + boolean isLoaded(); - TickStampData getRelationalValue(Placeholder placeholder, CNPlayer another); + /** + * Checks if the player is currently previewing + * + * @return true if the player is previewing, false otherwise + */ + boolean isPreviewing(); - void setValue(Placeholder placeholder, TickStampData value); + /** + * Checks if the player has the specified permission. + * + * @param permission the permission to check + * @return true if the player has the permission, false otherwise + */ + boolean hasPermission(String permission); - boolean setValue(Placeholder placeholder, String value); - - void setRelationalValue(Placeholder placeholder, CNPlayer another, TickStampData value); - - boolean setRelationalValue(Placeholder placeholder, CNPlayer another, String value); - - void addFeature(Feature feature); - - void removeFeature(Feature feature); - - boolean isMet(Requirement[] requirements); - - boolean isMet(CNPlayer another, Requirement[] requirements); - - Tracker addPlayerToTracker(CNPlayer another); - - void removePlayerFromTracker(CNPlayer another); - - Set nearbyPlayers(); - - void trackPassengers(CNPlayer another, int... passengers); - - void untrackPassengers(CNPlayer another, int... passengers); - - Set getTrackedPassengerIds(CNPlayer another); - - Set passengers(); + /** + * Returns the player's current time + * + * @return the player's time + */ + long playerTime(); + /** + * Checks if the player is flying. + * + * @return true if the player is flying, false otherwise + */ boolean isFlying(); + /** + * Returns the remaining air level for the player. + * + * @return the player's remaining air + */ + int remainingAir(); + + /** + * Retrieves the set of features that are actively using the specified placeholder. + * + * @param placeholder the placeholder to check + * @return the set of active features using the placeholder + */ + Set activeFeatures(Placeholder placeholder); + + /** + * Returns the placeholders that are actively used by the player's features. + * + * @return an array of active placeholders + */ + Placeholder[] activePlaceholders(); + + /** + * Retrieves the list of placeholders that need to be refreshed based on their refresh intervals. + * + * @return a list of placeholders to refresh + */ + List activePlaceholdersToRefresh(); + + /** + * Forces an update for the specified placeholders and relational placeholders with another player. + * + * @param placeholders the placeholders to update + * @param another the players related to the placeholders + */ + void forceUpdate(Set placeholders, Set another); + + /** + * Retrieves the cached data for a given placeholder. + * + * @param placeholder the placeholder to retrieve data for + * @return the cached data as a string + */ + @NotNull + String getData(Placeholder placeholder); + + /** + * Retrieves the cached {@link TickStampData} for a given placeholder. + * + * @param placeholder the placeholder to retrieve data for + * @return the cached TickStampData, or null if none exists + */ + @Nullable + TickStampData getValue(Placeholder placeholder); + + /** + * Retrieves the cached relational data between this player and another for a given placeholder. + * + * @param placeholder the relational placeholder + * @param another the other player + * @return the relational data as a string + */ + @NotNull + String getRelationalData(Placeholder placeholder, CNPlayer another); + + /** + * Retrieves the cached relational {@link TickStampData} for a given placeholder. + * + * @param placeholder the relational placeholder + * @param another the other player + * @return the cached relational TickStampData, or null if none exists + */ + @Nullable + TickStampData getRelationalValue(Placeholder placeholder, CNPlayer another); + + /** + * Caches the specified {@link TickStampData} for the given placeholder. + * + * @param placeholder the placeholder to cache + * @param value the value to cache + */ + void setValue(Placeholder placeholder, TickStampData value); + + /** + * Caches the specified value for the given placeholder. + * + * @param placeholder the placeholder to cache + * @param value the value to cache + * @return true if the value was changed, false otherwise + */ + boolean setValue(Placeholder placeholder, String value); + + /** + * Caches the specified relational {@link TickStampData} for a given placeholder and player. + * + * @param placeholder the relational placeholder + * @param another the other player + * @param value the value to cache + */ + void setRelationalValue(Placeholder placeholder, CNPlayer another, TickStampData value); + + /** + * Caches the specified relational value for a given placeholder and player. + * + * @param placeholder the relational placeholder + * @param another the other player + * @param value the value to cache + * @return true if the value was changed, false otherwise + */ + boolean setRelationalValue(Placeholder placeholder, CNPlayer another, String value); + + /** + * Adds a feature to the player + * + * @param feature the feature to add + */ + void addFeature(Feature feature); + + /** + * Removes a feature from the player. + * + * @param feature the feature to remove + */ + void removeFeature(Feature feature); + + /** + * Checks if the player meets the specified requirements. + * + * @param requirements the requirements to check + * @return true if all requirements are met, false otherwise + */ + boolean isMet(Requirement[] requirements); + + /** + * Checks if the player meets the specified relational requirements with another player. + * + * @param another the other player + * @param requirements the relational requirements to check + * @return true if all requirements are met, false otherwise + */ + boolean isMet(CNPlayer another, Requirement[] requirements); + + /** + * Adds a player to be track this player, creating a tracker for relational placeholders. + * + * @param another the player + * @return the tracker instance + */ + Tracker addPlayerToTracker(CNPlayer another); + + /** + * Removes a player from tracking this player. + * + * @param another the player to stop tracking + */ + void removePlayerFromTracker(CNPlayer another); + + /** + * Retrieves the set of nearby players tracking this player. + * + * @return the set of nearby players + */ + Set nearbyPlayers(); + + /** + * Adds passenger entities to the tracker for another player. + * + * @param another the player whose passengers to track + * @param passengers the IDs of the passenger entities + */ + void trackPassengers(CNPlayer another, int... passengers); + + /** + * Removes passenger entities from the tracker for another player. + * + * @param another the player whose passengers to stop tracking + * @param passengers the IDs of the passenger entities + */ + void untrackPassengers(CNPlayer another, int... passengers); + + /** + * Retrieves the IDs of tracked passenger entities for another player. + * + * @param another the viewer + * @return the set of passenger entity IDs + */ + Set getTrackedPassengerIds(CNPlayer another); + + /** + * Retrieves the IDs of all passenger entities currently associated with this player. + * + * @return the set of passenger entity IDs + */ + Set passengers(); + + /** + * Retrieves the tracker instance for another player. + * + * @param another the viewer + * @return the tracker instance, or null if none exists + */ Tracker getTracker(CNPlayer another); + /** + * Returns the ID of the currently equipped bubble for the player. + * + * @return the ID of the equipped bubble + */ String equippedBubble(); - void equippedBubble(String equippedBubble); + /** + * Sets the equipped bubble for the player. + * Operation would fail if player is not loaded. + * + * @param equippedBubble the new bubble ID to equip + * @return success or not + */ + boolean equippedBubble(String equippedBubble); + /** + * Returns the ID of the currently equipped nameplate for the player. + * + * @return the ID of the equipped nameplate + */ String equippedNameplate(); - void equippedNameplate(String equippedNameplate); + /** + * Sets the equipped nameplate for the player. + * Operation would fail if player is not loaded. + * + * @param equippedNameplate the new nameplate ID to equip + * @return success or not + */ + boolean equippedNameplate(String equippedNameplate); - int remainingAir(); + /** + * Save the player's current nameplate/bubble to database + */ + void save(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/ConfigManager.java b/api/src/main/java/net/momirealms/customnameplates/api/ConfigManager.java index 58f88f8..488616f 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/ConfigManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/ConfigManager.java @@ -26,8 +26,8 @@ import dev.dejvokep.boostedyaml.settings.general.GeneralSettings; import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; import dev.dejvokep.boostedyaml.utils.format.NodeRole; +import net.momirealms.customnameplates.api.feature.CharacterArranger; import net.momirealms.customnameplates.api.feature.bossbar.BossBar; -import net.momirealms.customnameplates.api.feature.pack.CharacterArranger; import net.momirealms.customnameplates.api.helper.AdventureHelper; import net.momirealms.customnameplates.common.locale.TranslationManager; import net.momirealms.customnameplates.common.plugin.CustomNameplatesProperties; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/CustomNameplates.java b/api/src/main/java/net/momirealms/customnameplates/api/CustomNameplates.java index 0ce3f33..01f0b4d 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/CustomNameplates.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/CustomNameplates.java @@ -22,7 +22,7 @@ import net.momirealms.customnameplates.api.feature.advance.AdvanceManager; import net.momirealms.customnameplates.api.feature.background.BackgroundManager; import net.momirealms.customnameplates.api.feature.bossbar.BossBarManager; import net.momirealms.customnameplates.api.feature.bubble.BubbleManager; -import net.momirealms.customnameplates.api.feature.bubble.chat.ChatManager; +import net.momirealms.customnameplates.api.feature.chat.ChatManager; import net.momirealms.customnameplates.api.feature.image.ImageManager; import net.momirealms.customnameplates.api.feature.nameplate.NameplateManager; import net.momirealms.customnameplates.api.feature.pack.ResourcePackManager; @@ -43,10 +43,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Supplier; +/** + * Abstract class representing the core plugin management of CustomNameplates. + * Provides access to managers for various features. + */ public abstract class CustomNameplates implements NameplatesPlugin { private static CustomNameplates instance; @@ -81,110 +84,227 @@ public abstract class CustomNameplates implements NameplatesPlugin { instance = this; } + /** + * Reloads the plugin + */ @Override - public void reload() { - if (scheduledMainTask != null) - scheduledMainTask.cancel(); - scheduledMainTask = getScheduler().asyncRepeating(mainTask, 50, 50, TimeUnit.MILLISECONDS); - } + public abstract void reload(); + /** + * Disables the plugin, canceling any scheduled tasks. + */ @Override - public void disable() { - if (this.scheduledMainTask != null) this.scheduledMainTask.cancel(); - } - - @Override - public DependencyManager getDependencyManager() { - return dependencyManager; - } - - @Override - public TranslationManager getTranslationManager() { - return translationManager; - } - - @Override - public ConfigManager getConfigManager() { - return configManager; - } + public abstract void disable(); + /** + * Logs debug messages through the provided supplier. + * + * @param supplier a supplier that provides debug messages + */ @Override public void debug(Supplier supplier) { this.debugger.accept(supplier); } + /** + * Returns the dependency manager for managing external dependencies. + * + * @return the {@link DependencyManager} instance + */ + @Override + public DependencyManager getDependencyManager() { + return dependencyManager; + } + + /** + * Returns the translation manager for managing language translations. + * + * @return the {@link TranslationManager} instance + */ + @Override + public TranslationManager getTranslationManager() { + return translationManager; + } + + /** + * Returns the configuration manager for managing plugin configurations. + * + * @return the {@link ConfigManager} instance + */ + @Override + public ConfigManager getConfigManager() { + return configManager; + } + + /** + * Returns the manager responsible for handling placeholders. + * + * @return the {@link PlaceholderManager} instance + */ public PlaceholderManager getPlaceholderManager() { return placeholderManager; } + /** + * Returns the packet sender responsible for sending network packets to players. + * + * @return the {@link PacketSender} instance + */ public PacketSender getPacketSender() { return packetSender; } + /** + * Returns the requirement manager responsible for managing requirements. + * + * @return the {@link RequirementManager} instance + */ public RequirementManager getRequirementManager() { return requirementManager; } + /** + * Returns the action bar manager responsible for managing action bar displays. + * + * @return the {@link ActionBarManager} instance + */ public ActionBarManager getActionBarManager() { return actionBarManager; } + /** + * Returns the manager responsible for handling unlimited tags. + * + * @return the {@link UnlimitedTagManager} instance + */ public UnlimitedTagManager getUnlimitedTagManager() { return unlimitedTagManager; } + /** + * Returns the manager responsible for handling font advances. + * + * @return the {@link AdvanceManager} instance + */ public AdvanceManager getAdvanceManager() { return advanceManager; } + /** + * Returns the background manager responsible for handling background images. + * + * @return the {@link BackgroundManager} instance + */ public BackgroundManager getBackgroundManager() { return backgroundManager; } + /** + * Returns the event manager responsible for managing events. + * + * @return the {@link EventManager} instance + */ public EventManager getEventManager() { return eventManager; } + /** + * Returns the storage manager responsible for handling data storage. + * + * @return the {@link StorageManager} instance + */ public StorageManager getStorageManager() { return storageManager; } + /** + * Returns the nameplate manager responsible for managing nameplate images. + * + * @return the {@link NameplateManager} instance + */ public NameplateManager getNameplateManager() { return nameplateManager; } + /** + * Returns the image manager responsible for handling images used within the plugin. + * + * @return the {@link ImageManager} instance + */ public ImageManager getImageManager() { return imageManager; } + /** + * Returns the bubble manager responsible for managing chat bubbles. + * + * @return the {@link BubbleManager} instance + */ public BubbleManager getBubbleManager() { return bubbleManager; } + /** + * Returns the chat manager responsible for managing chat-related features. + * + * @return the {@link ChatManager} instance + */ public ChatManager getChatManager() { return chatManager; } + /** + * Returns the resource pack manager responsible for managing custom resource packs. + * + * @return the {@link ResourcePackManager} instance + */ public ResourcePackManager getResourcePackManager() { return resourcePackManager; } + /** + * Returns the platform object for accessing platform-specific functionality. + * + * @return the {@link Platform} instance + */ public Platform getPlatform() { return platform; } + /** + * Returns a collection of all currently online players. + * + * @return a collection of {@link CNPlayer} instances + */ public Collection getOnlinePlayers() { return new HashSet<>(onlinePlayerMap.values()); } + /** + * Retrieves a player by their UUID. + * + * @param uuid the UUID of the player + * @return the {@link CNPlayer} instance, or null if not found + */ public CNPlayer getPlayer(UUID uuid) { return onlinePlayerMap.get(uuid); } + /** + * Retrieves a player by their entity ID. + * + * @param entityID the entity ID of the player + * @return the {@link CNPlayer} instance, or null if not found + */ public CNPlayer getPlayer(int entityID) { return entityIDFastLookup.get(entityID); } + /** + * Returns the singleton instance of CustomNameplates. + * + * @return the {@link CustomNameplates} instance + */ public static CustomNameplates getInstance() { return instance; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/MainTask.java b/api/src/main/java/net/momirealms/customnameplates/api/MainTask.java index 12de0f7..9612792 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/MainTask.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/MainTask.java @@ -25,11 +25,10 @@ import java.util.concurrent.ConcurrentHashMap; public class MainTask implements Runnable { - // The system would break if a server hasn't stopped for 3 years - private static int TICKS = 0; + private static int RUN_TICKS = 0; - private static final Map TIME_1 = new ConcurrentHashMap<>(2048, 1F); - private static final Map TIME_2 = new ConcurrentHashMap<>(2048, 1F); + private static final Map TIME_1 = new ConcurrentHashMap<>(2048); + private static final Map TIME_2 = new ConcurrentHashMap<>(2048); private static final Set requestedSharedPlaceholders = Collections.synchronizedSet(new HashSet<>()); private int timer; @@ -40,18 +39,20 @@ public class MainTask implements Runnable { } public static int getTicks() { - return TICKS; + return RUN_TICKS; } public static boolean hasRequested(int countId) { - boolean result = requestedSharedPlaceholders.contains(countId); - if (!result) requestedSharedPlaceholders.add(countId); - return result; + return !requestedSharedPlaceholders.add(countId); + } + + public static void reset() { + RUN_TICKS = 0; } @Override public void run() { - TICKS++; + RUN_TICKS++; requestedSharedPlaceholders.clear(); long time1 = System.nanoTime(); plugin.actionBarManager.refreshConditions(); @@ -67,20 +68,20 @@ public class MainTask implements Runnable { TIME_2.put(timer, diff2); timer++; if (timer >= 1200) timer = 0; + if (RUN_TICKS < 0) { + CustomNameplates.getInstance().reload(); + } } public static HealthyProfile getHealthyProfile() { - long total1 = 0; - long total2 = 0; - for (int value : TIME_1.values()) { - total1 += value; - } - for (int value : TIME_2.values()) { - total2 += value; - } + long total1 = TIME_1.values().stream().mapToLong(Integer::longValue).sum(); + long total2 = TIME_2.values().stream().mapToLong(Integer::longValue).sum(); + long total = total1 + total2; double size = TIME_1.size(); + double load = total / size / 50_000_000; + return new HealthyProfile( load, (long) (total / size), diff --git a/api/src/main/java/net/momirealms/customnameplates/api/Platform.java b/api/src/main/java/net/momirealms/customnameplates/api/Platform.java index 4e4d088..9bc976c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/Platform.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/Platform.java @@ -27,26 +27,118 @@ import java.util.List; import java.util.UUID; import java.util.function.Consumer; +/** + * Platform interface to abstract platform-specific operations for Minecraft components, packets, and placeholders. + */ public interface Platform { + /** + * Converts a JSON string to a Minecraft component. + * + * @param json the JSON string + * @return the Minecraft component object + */ Object jsonToMinecraftComponent(String json); + /** + * Converts a Minecraft component to a JSON string. + * + * @param component the Minecraft component + * @return the JSON string representation + */ String minecraftComponentToJson(Object component); + /** + * Creates a vector object from the specified coordinates. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param z the Z coordinate + * @return a vector object + */ Object vec3(double x, double y, double z); + /** + * Registers a platform-specific placeholder. + * + * @param id the placeholder ID + * @return the registered {@link Placeholder} object + */ Placeholder registerPlatformPlaceholder(String id); + /** + * Handles an event triggered when a packet is sent to a player. + * + * @param player the player receiving the packet + * @param event the packet event + */ void onPacketSend(CNPlayer player, PacketEvent event); + /** + * Creates an action bar text packet for displaying a message in the action bar. + * + * @param component the component containing the text + * @return the action bar packet object + */ Object setActionBarTextPacket(Object component); + /** + * Creates a boss bar packet for displaying a boss bar to a player. + * + * @param uuid the UUID of the boss bar + * @param component the component containing the boss bar text + * @param progress the boss bar progress (0.0 to 1.0) + * @param overlay the boss bar overlay style + * @param color the boss bar color + * @return the boss bar packet object + */ Object createBossBarPacket(UUID uuid, Object component, float progress, BossBar.Overlay overlay, BossBar.Color color); + /** + * Creates a packet to remove a boss bar. + * + * @param uuid the UUID of the boss bar to remove + * @return the remove boss bar packet object + */ Object removeBossBarPacket(UUID uuid); + /** + * Creates a packet to update the name of a boss bar. + * + * @param uuid the UUID of the boss bar + * @param component the component containing the new name + * @return the update boss bar name packet object + */ Object updateBossBarNamePacket(UUID uuid, Object component); + /** + * Creates packets to display text on a custom text display entity. + * + * @param entityID the entity ID + * @param uuid the entity UUID + * @param position the position of the text + * @param pitch the pitch of the entity + * @param yaw the yaw of the entity + * @param headYaw the head yaw of the entity + * @param interpolationDelay the interpolation delay + * @param transformationInterpolationDuration the transformation interpolation duration + * @param positionRotationInterpolationDuration the position and rotation interpolation duration + * @param component the component containing the text + * @param backgroundColor the background color + * @param opacity the opacity of the text + * @param hasShadow whether the text has a shadow + * @param isSeeThrough whether the text is see-through + * @param useDefaultBackgroundColor whether the default background color is used + * @param alignment the alignment of the text + * @param viewRange the view range of the text + * @param shadowRadius the shadow radius + * @param shadowStrength the shadow strength + * @param scale the scale of the text + * @param translation the translation of the text + * @param lineWidth the width of the text line + * @param isCrouching whether the entity is crouching + * @return a list of packets for creating the text display + */ List createTextDisplayPacket( int entityID, UUID uuid, Vector3 position, float pitch, float yaw, double headYaw, @@ -57,21 +149,77 @@ public interface Platform { Vector3 scale, Vector3 translation, int lineWidth, boolean isCrouching ); + /** + * Creates a modifier for interpolation delay. + * + * @param delay the interpolation delay + * @return a consumer that applies the modifier to a list of packets + */ Consumer> createInterpolationDelayModifier(int delay); + /** + * Creates a modifier for transformation interpolation duration. + * + * @param duration the transformation interpolation duration + * @return a consumer that applies the modifier to a list of packets + */ Consumer> createTransformationInterpolationDurationModifier(int duration); + /** + * Creates a modifier to change the text component of a packet. + * + * @param component the new text component + * @return a consumer that applies the modifier to a list of packets + */ Consumer> createTextComponentModifier(Object component); + /** + * Creates a modifier to change the scale of a text display. + * + * @param scale the new scale + * @return a consumer that applies the modifier to a list of packets + */ Consumer> createScaleModifier(Vector3 scale); + /** + * Creates a modifier to change the translation of a text display. + * + * @param translation the new translation + * @return a consumer that applies the modifier to a list of packets + */ Consumer> createTranslationModifier(Vector3 translation); + /** + * Creates a modifier to change the opacity of a text display. + * + * @param opacity the new opacity + * @return a consumer that applies the modifier to a list of packets + */ Consumer> createOpacityModifier(byte opacity); + /** + * Updates an existing text display entity with modifiers. + * + * @param entityID the entity ID of the text display + * @param modifiers the list of modifiers to apply + * @return the update text display packet object + */ Object updateTextDisplayPacket(int entityID, List>> modifiers); + /** + * Creates a packet to set passengers for a vehicle entity. + * + * @param vehicle the vehicle entity ID + * @param passengers the passenger entity IDs + * @return the set passengers packet object + */ Object setPassengersPacket(int vehicle, int[] passengers); + /** + * Creates a packet to remove entities from the game world. + * + * @param entityID the entity IDs to remove + * @return the remove entity packet object + */ Object removeEntityPacket(int... entityID); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/event/DataLoadEvent.java b/api/src/main/java/net/momirealms/customnameplates/api/event/DataLoadEvent.java index c14908e..68164dc 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/event/DataLoadEvent.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/event/DataLoadEvent.java @@ -18,10 +18,20 @@ package net.momirealms.customnameplates.api.event; import net.momirealms.customnameplates.api.storage.data.PlayerData; +import net.momirealms.customnameplates.common.event.NameplatesEvent; import net.momirealms.customnameplates.common.event.Param; -public interface DataLoadEvent { +/** + * Represents an event that is triggered when player data is loaded. + * This event provides access to the {@link PlayerData} for further processing. + */ +public interface DataLoadEvent extends NameplatesEvent { + /** + * Returns the {@link PlayerData} associated with this event. + * + * @return the loaded player data + */ @Param(0) PlayerData data(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/event/NameplatesReloadEvent.java b/api/src/main/java/net/momirealms/customnameplates/api/event/NameplatesReloadEvent.java index 1c233f2..e81cee7 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/event/NameplatesReloadEvent.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/event/NameplatesReloadEvent.java @@ -17,8 +17,10 @@ package net.momirealms.customnameplates.api.event; -import net.momirealms.customnameplates.common.event.Cancellable; import net.momirealms.customnameplates.common.event.NameplatesEvent; -public interface NameplatesReloadEvent extends NameplatesEvent, Cancellable { +/** + * Represents an event that is triggered when the nameplates configuration is reloaded. + */ +public interface NameplatesReloadEvent extends NameplatesEvent { } \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/AdaptiveImage.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/AdaptiveImage.java index 4c0eae5..df90e31 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/AdaptiveImage.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/AdaptiveImage.java @@ -19,9 +19,33 @@ package net.momirealms.customnameplates.api.feature; public interface AdaptiveImage { + /** + * Creates the prefix for the image with the specified advance and margins. + * + * @param advance the advance for the image + * @param leftMargin the left margin for the image + * @param rightMargin the right margin for the image + * @return the generated image prefix + */ String createImagePrefix(float advance, float leftMargin, float rightMargin); + /** + * Creates the suffix for the image with the specified advance and margins. + * + * @param advance the advance for the image + * @param leftMargin the left margin for the image + * @param rightMargin the right margin for the image + * @return the generated image suffix + */ String createImageSuffix(float advance, float leftMargin, float rightMargin); + /** + * Creates the full image string with the specified advance and margins. + * + * @param advance the advance for the image + * @param leftMargin the left margin for the image + * @param rightMargin the right margin for the image + * @return the generated image string + */ String createImage(float advance, float leftMargin, float rightMargin); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/CarouselText.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/CarouselText.java index 79e69c4..ce1ffa8 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/CarouselText.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/CarouselText.java @@ -19,6 +19,9 @@ package net.momirealms.customnameplates.api.feature; import net.momirealms.customnameplates.api.requirement.Requirement; +/** + * Represents a piece of carousel text, which cycles through a series of texts with associated requirements and duration. + */ public class CarouselText { private final int duration; @@ -27,6 +30,14 @@ public class CarouselText { private final PreParsedDynamicText preParsedDynamicText; private final boolean updateOnDisplay; + /** + * Constructs a new CarouselText instance. + * + * @param duration the duration (in ticks) for how long this text is displayed + * @param requirements the requirements for displaying this text + * @param rawText the raw text content + * @param updateOnDisplay whether the text should be updated when displayed + */ public CarouselText(int duration, Requirement[] requirements, String rawText, boolean updateOnDisplay) { this.duration = duration; this.requirements = requirements; @@ -36,23 +47,48 @@ public class CarouselText { this.updateOnDisplay = updateOnDisplay; } + /** + * Returns the duration (in ticks) for how long this text will be displayed. + * + * @return the display duration + */ public int duration() { return duration; } + /** + * Returns the requirements that must be met to display this text. + * + * @return an array of requirements + */ public Requirement[] requirements() { return requirements; } + /** + * Returns the raw text content. + * + * @return the raw text + */ public String text() { return rawText; } + /** + * Returns the pre-parsed dynamic text, which processes placeholders or dynamic content. + * + * @return the pre-parsed dynamic text + */ public PreParsedDynamicText preParsedDynamicText() { return preParsedDynamicText; } + /** + * Checks if the text should be updated each time it is displayed. + * + * @return true if the text updates on display, false otherwise + */ public boolean updateOnDisplay() { return updateOnDisplay; } -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/CharacterArranger.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/CharacterArranger.java similarity index 64% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/pack/CharacterArranger.java rename to api/src/main/java/net/momirealms/customnameplates/api/feature/CharacterArranger.java index 1c41204..b0aeb3b 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/CharacterArranger.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/CharacterArranger.java @@ -15,20 +15,30 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.pack; +package net.momirealms.customnameplates.api.feature; +/** + * Utility class for automatically arranging characters. + * Provides methods to increase, retrieve, and reset the current character. + */ public class CharacterArranger { + /** + * The current character being managed by the arranger. + */ public static char currentChar; + /** + * Increases the current character by 1. + */ public static void increase() { currentChar = (char) (currentChar + '\u0001'); } /** - * Get and increase the char arranged automatically by the plugin + * Retrieves the current character and then increases it. * - * @return char + * @return the current character before increase */ public static char getAndIncrease() { char temp = currentChar; @@ -37,9 +47,9 @@ public class CharacterArranger { } /** - * Increase and get the char arranged automatically by the plugin + * Increases the current character and then retrieves it. * - * @return char + * @return the current character after increase */ public static char increaseAndGet() { increase(); @@ -47,11 +57,11 @@ public class CharacterArranger { } /** - * Reset the initial char + * Resets the current character to the specified value. * - * @param c char + * @param c the character to reset to */ public static void reset(char c) { currentChar = c; } -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/ChatListener.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/ChatListener.java index 6e6e31e..6401508 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/ChatListener.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/ChatListener.java @@ -19,7 +19,18 @@ package net.momirealms.customnameplates.api.feature; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Represents a listener for player chat events, providing a callback method + * when a player sends a message in a specific channel. + */ public interface ChatListener { + /** + * Called when a player sends a chat message in a specified channel. + * + * @param player the player who sent the message + * @param message the content of the message + * @param channel the channel where the message was sent + */ void onPlayerChat(CNPlayer player, String message, String channel); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/ConfiguredCharacter.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/ConfiguredCharacter.java index 3f18eaf..51eed04 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/ConfiguredCharacter.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/ConfiguredCharacter.java @@ -18,31 +18,57 @@ package net.momirealms.customnameplates.api.feature; import net.momirealms.customnameplates.api.CustomNameplates; -import net.momirealms.customnameplates.api.feature.pack.CharacterArranger; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +/** + * Represents a configured character with associated image, dimensions, and advance (spacing). + */ public class ConfiguredCharacter { private final char character; private final File imageFile; - private final int height; private final int ascent; - private final float advance; + /** + * Creates a new ConfiguredCharacter instance using an automatically assigned character. + * + * @param imageFile the image file associated with this character + * @param ascent the ascent value (distance from the baseline to the top of the character) + * @param height the height of the character + * @return a new ConfiguredCharacter instance + */ public static ConfiguredCharacter create(File imageFile, int ascent, int height) { return new ConfiguredCharacter(CharacterArranger.getAndIncrease(), imageFile, ascent, height); } + /** + * Creates a new ConfiguredCharacter instance using an automatically assigned character and a specified advance value. + * + * @param imageFile the image file associated with this character + * @param ascent the ascent value (distance from the baseline to the top of the character) + * @param height the height of the character + * @param advance the advance (spacing) for this character + * @return a new ConfiguredCharacter instance + */ public static ConfiguredCharacter create(File imageFile, int ascent, int height, float advance) { return new ConfiguredCharacter(CharacterArranger.getAndIncrease(), imageFile, ascent, height, advance); } + /** + * Constructs a new ConfiguredCharacter instance with specified character, image, ascent, height, and advance values. + * + * @param character the character to associate + * @param imageFile the image file + * @param ascent the ascent value + * @param height the height of the character + * @param advance the advance (spacing) for the character + */ public ConfiguredCharacter(char character, File imageFile, int ascent, int height, float advance) { this.character = character; this.imageFile = imageFile; @@ -51,20 +77,31 @@ public class ConfiguredCharacter { this.advance = advance; } + /** + * Constructs a new ConfiguredCharacter instance with automatic advance calculation. + * + * @param character the character to associate + * @param imageFile the image file + * @param ascent the ascent value + * @param height the height of the character + */ public ConfiguredCharacter(char character, File imageFile, int ascent, int height) { this.character = character; this.imageFile = imageFile; this.ascent = ascent; this.height = height; + if (this.ascent > this.height) { - CustomNameplates.getInstance().getPluginLogger().severe(String.format("Found an issue in the image config. Ascent(%s) is higher than height(%s). " + imageFile.getAbsolutePath(), ascent, height)); + CustomNameplates.getInstance().getPluginLogger().severe(String.format( + "Found an issue in the image config. Ascent(%s) is higher than height(%s). %s", ascent, height, imageFile.getAbsolutePath())); } + try { BufferedImage bufferedImage = ImageIO.read(imageFile); int imageHeight = bufferedImage.getHeight(); int imageWidth = bufferedImage.getWidth(); - float scale = (float) height / (float) imageHeight; + float scale = (float) height / imageHeight; int i; outer: for (i = imageWidth - 1; i >= 0; --i) { @@ -76,28 +113,53 @@ public class ConfiguredCharacter { } } } - advance = (int) (0.5 + (double) ((i+1f) * scale)) + 1f; + advance = (float) Math.round((i + 1) * scale) + 1f; } catch (IOException e) { throw new RuntimeException(e); } } + /** + * Returns the character associated with this ConfiguredCharacter. + * + * @return the character + */ public char character() { return character; } + /** + * Returns the ascent value of this character. + * + * @return the ascent value + */ public int ascent() { return ascent; } + /** + * Returns the advance (spacing) of this character. + * + * @return the advance value + */ public float advance() { return advance; } + /** + * Returns the height of this character. + * + * @return the character height + */ public int height() { return height; } + /** + * Returns the image file associated with this character. + * + * @return the image file + */ public File imageFile() { return imageFile; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/DynamicText.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/DynamicText.java index 4715d22..7c88c6f 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/DynamicText.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/DynamicText.java @@ -24,22 +24,43 @@ import java.util.List; import java.util.Set; import java.util.function.Function; +/** + * Represents dynamic text that can be rendered for a specific player, with support for placeholders and custom text functions. + */ public class DynamicText { private final String text; private final List> texts; private final Set placeholders; + /** + * Constructs a new DynamicText instance. + * + * @param text the raw text string + * @param texts a list of functions that generate text dynamically based on the player + * @param placeholders a set of placeholders used in the text + */ public DynamicText(String text, List> texts, Set placeholders) { this.text = text; this.texts = texts; this.placeholders = placeholders; } + /** + * Returns the set of placeholders associated with this dynamic text. + * + * @return a set of placeholders + */ public Set placeholders() { return placeholders; } + /** + * Renders the dynamic text for the specified player by applying the text functions. + * + * @param viewer the player for whom the text is being rendered + * @return the rendered text + */ public String render(CNPlayer viewer) { StringBuilder builder = new StringBuilder(); for (Function function : texts) { @@ -48,6 +69,11 @@ public class DynamicText { return builder.toString(); } + /** + * Returns the raw text string. + * + * @return the raw text + */ public String text() { return text; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/Feature.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/Feature.java index 1e5751c..a86f4e5 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/Feature.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/Feature.java @@ -22,13 +22,37 @@ import net.momirealms.customnameplates.api.placeholder.Placeholder; import java.util.Set; +/** + * Represents a feature that can utilize placeholders and manage updates based on player interaction. + */ public interface Feature { + /** + * Returns the name of the feature. + * + * @return the feature name + */ String name(); + /** + * Returns the set of placeholders that are currently active within this feature. + * + * @return a set of active placeholders + */ Set activePlaceholders(); + /** + * Returns the set of all placeholders that this feature can use. + * + * @return a set of all possible placeholders + */ Set allPlaceholders(); + /** + * Notifies the feature that placeholders for the specified player have been updated. + * + * @param p1 the player whose placeholders have been updated + * @param force if true, forces an update even if no changes are detected + */ void notifyPlaceholderUpdates(CNPlayer p1, boolean force); -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/JoinQuitListener.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/JoinQuitListener.java index bde9df2..ae23c33 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/JoinQuitListener.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/JoinQuitListener.java @@ -19,9 +19,22 @@ package net.momirealms.customnameplates.api.feature; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Listener for handling player join and quit events. + */ public interface JoinQuitListener { + /** + * Called when a player joins the server. + * + * @param player the player who joined + */ void onPlayerJoin(CNPlayer player); + /** + * Called when a player quits the server. + * + * @param player the player who quit + */ void onPlayerQuit(CNPlayer player); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/RelationalFeature.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/RelationalFeature.java index 6364327..b94c7d1 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/RelationalFeature.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/RelationalFeature.java @@ -19,7 +19,17 @@ package net.momirealms.customnameplates.api.feature; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Represents a feature that involves relationships between two players and supports placeholder updates for both players. + */ public interface RelationalFeature extends Feature { + /** + * Notifies the feature that placeholders for the relationship between two players have been updated. + * + * @param p1 the first player + * @param p2 the second player + * @param force if true, forces an update even if no changes are detected + */ void notifyPlaceholderUpdates(CNPlayer p1, CNPlayer p2, boolean force); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/TickStampData.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/TickStampData.java index d05b9e0..e7472a4 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/TickStampData.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/TickStampData.java @@ -19,47 +19,104 @@ package net.momirealms.customnameplates.api.feature; import net.momirealms.customnameplates.api.MainTask; +/** + * Represents a data structure that stores an object and tracks when it was last updated, + * using packed ticks and a boolean flag to indicate changes. + * + * @param the type of data being stored + */ public class TickStampData { private D data; private int packedTicks; + /** + * Constructs a new TickStampData instance. + * + * @param data the data to store + * @param ticks the number of ticks to store + * @param changed whether the value has changed + */ public TickStampData(D data, int ticks, boolean changed) { this.data = data; this.packedTicks = packBooleanAndTicks(changed, ticks); } + /** + * Updates the stored data. + * + * @param data the new data + */ public void data(D data) { this.data = data; } + /** + * Updates the packed ticks and change status. + * + * @param changed whether the value has changed + */ public void updateTicks(boolean changed) { this.packedTicks = packBooleanAndTicks(changed, MainTask.getTicks()); } + /** + * Returns the stored data. + * + * @return the data + */ public D data() { return data; } + /** + * Checks if the value has changed since the last update. + * + * @return true if the value has changed, false otherwise + */ public boolean hasValueChanged() { return unpackBoolean(packedTicks); } + /** + * Returns the stored number of ticks. + * + * @return the number of ticks + */ public int ticks() { return unpackTicks(packedTicks); } + /** + * Packs the boolean change flag and ticks into a single integer. + * + * @param hasValueChanged whether the value has changed + * @param ticks the number of ticks + * @return the packed integer + */ public static int packBooleanAndTicks(boolean hasValueChanged, int ticks) { - int numberMasked = ticks & 0x7FFFFFFF; - int booleanBit = hasValueChanged ? 1 << 31 : 0; + int numberMasked = ticks & 0x7FFFFFFF; // Mask for 31 bits + int booleanBit = hasValueChanged ? 1 << 31 : 0; // Set the highest bit for the boolean flag return booleanBit | numberMasked; } + /** + * Unpacks the number of ticks from the packed integer. + * + * @param packed the packed integer + * @return the number of ticks + */ public static int unpackTicks(int packed) { - return packed & 0x7FFFFFFF; + return packed & 0x7FFFFFFF; // Extract the lower 31 bits for ticks } + /** + * Unpacks the boolean change flag from the packed integer. + * + * @param packed the packed integer + * @return true if the value has changed, false otherwise + */ public static boolean unpackBoolean(int packed) { - return (packed & 0x80000000) != 0; + return (packed & 0x80000000) != 0; // Check the highest bit for the boolean flag } -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarConfig.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarConfig.java index d1d1319..9709df1 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarConfig.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarConfig.java @@ -22,24 +22,70 @@ import net.momirealms.customnameplates.api.requirement.Requirement; public interface ActionBarConfig { + /** + * Returns the unique ID of the ActionBar configuration. + * + * @return the configuration ID + */ String id(); + /** + * Returns the list of requirements for the ActionBar. + * + * @return an array of requirements + */ Requirement[] requirements(); + /** + * Returns the carousel texts used in the ActionBar. + * + * @return an array of carousel texts + */ CarouselText[] carouselTexts(); + /** + * Creates a new builder for constructing an ActionBarConfig. + * + * @return a new builder instance + */ static Builder builder() { return new ActionBarConfigImpl.BuilderImpl(); } + /** + * Builder for creating an ActionBarConfig. + */ interface Builder { + /** + * Sets the unique ID for the ActionBar configuration. + * + * @param id the configuration ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets the requirements for the ActionBar. + * + * @param requirements an array of requirements + * @return the builder instance + */ Builder requirement(Requirement[] requirements); + /** + * Sets the carousel texts for the ActionBar. + * + * @param carouselTexts an array of carousel texts + * @return the builder instance + */ Builder carouselText(CarouselText[] carouselTexts); + /** + * Builds and returns the ActionBarConfig. + * + * @return the constructed ActionBarConfig + */ ActionBarConfig build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarManager.java index 49b051c..1397751 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarManager.java @@ -19,16 +19,42 @@ package net.momirealms.customnameplates.api.feature.actionbar; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.common.plugin.feature.Reloadable; +import org.jetbrains.annotations.Nullable; public interface ActionBarManager extends Reloadable { + /** + * Refreshes the conditions of all ActionBars. + */ void refreshConditions(); + /** + * Checks heartbeats for any necessary updates or actions related to ActionBars. + */ void checkHeartBeats(); - ActionBarConfig getConfig(String name); + /** + * Retrieves the ActionBar configuration by its name. + * + * @param name the name of the ActionBar configuration + * @return the corresponding ActionBarConfig, or null if not found + */ + @Nullable + ActionBarConfig configById(String name); - ActionBarConfig[] allConfigs(); + /** + * Returns all available ActionBar configurations. + * + * @return an array of all ActionBarConfig instances + */ + ActionBarConfig[] actionBarConfigs(); + /** + * Gets the external ActionBar for a specific player. + * + * @param player the player + * @return the external ActionBar string for the player + */ + @Nullable String getExternalActionBar(CNPlayer player); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/AdvanceManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/AdvanceManager.java index 6e832e7..640e897 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/AdvanceManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/AdvanceManager.java @@ -20,22 +20,65 @@ package net.momirealms.customnameplates.api.feature.advance; import net.kyori.adventure.key.Key; import net.momirealms.customnameplates.common.plugin.feature.Reloadable; import net.momirealms.customnameplates.common.util.Tuple; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.List; public interface AdvanceManager extends Reloadable { - void loadTemplates(); + /** + * Retrieves custom font advance data by its ID. + * + * @param id the ID of the custom font + * @return the custom font advance data + */ + @Nullable + ConfigurableFontAdvanceData customFontDataById(String id); - ConfigurableFontAdvanceData getCustomFontData(String id); - - CharacterFontAdvanceData getCharacterFontData(String id); + /** + * Retrieves character font advance data by its ID. + * + * @param id the ID of the character font + * @return the character font advance data + */ + @Nullable + CharacterFontAdvanceData templateFontDataById(String id); + /** + * Calculates the total advance (width) for a line of text. + * + * @param text the text to calculate the advance for + * @return the total line advance + */ float getLineAdvance(String text); + /** + * Calculates the advance (width) for a series of characters with a specific font and style. + * + * @param chars the array of characters + * @param font the font key + * @param bold whether the text is bold + * @return the total character advance + */ float getCharAdvance(char[] chars, Key font, boolean bold); + /** + * Calculates the number of lines needed to fit the text within a specified width. + * + * @param text the text to calculate the number of lines for + * @param width the maximum width of each line + * @return the number of lines required + */ int getLines(String text, int width); + /** + * Converts a MiniMessage-formatted string into an iterable list of tuples. + * Each tuple contains text, its corresponding font key, and whether it is bold. + * + * @param text the MiniMessage-formatted string + * @return a list of tuples representing the iterable text parts + */ + @ApiStatus.Internal List> miniMessageToIterable(String text); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceData.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceData.java index 1b42cb3..f71c9ee 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceData.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceData.java @@ -25,30 +25,86 @@ import java.util.function.Function; public interface CharacterFontAdvanceData { + /** + * Returns the size of the character font advance data, typically the number of characters. + * + * @return the size of the data + */ int size(); + /** + * Retrieves the advance (width) for a specific character code point. + * + * @param codePoint the code point of the character + * @return the advance value for the character, or null if not found + */ Float getAdvance(int codePoint); + /** + * Returns the map containing the character code points and their corresponding advance values. + * + * @return a map of character code points and their advances + */ Map data(); + /** + * Returns the unique identifier for this font advance data. + * + * @return the font advance data ID + */ String id(); + /** + * Generates a list of font provider configurations based on the provided properties. + * + * @param properties a map of properties for font provider configuration + * @return a list of JSON objects representing the font providers + */ List fontProvider(Map properties); + /** + * Creates a new builder for constructing CharacterFontAdvanceData. + * + * @return a new builder instance + */ static Builder builder() { return new CharacterFontAdvanceDataImpl.BuilderImpl(); } - void close(); - + /** + * Builder for creating CharacterFontAdvanceData. + */ interface Builder { + /** + * Sets the advance data for the characters. + * + * @param data a map of character code points and their advance values + * @return the builder instance + */ Builder advance(Map data); + /** + * Sets the unique ID for the font advance data. + * + * @param id the ID of the font advance data + * @return the builder instance + */ Builder id(String id); + /** + * Sets a function to provide the font provider configuration. + * + * @param function a function that takes properties and returns a list of JSON objects representing font providers + * @return the builder instance + */ Builder fontProviderFunction(Function, List> function); + /** + * Builds and returns the CharacterFontAdvanceData instance. + * + * @return the constructed CharacterFontAdvanceData + */ CharacterFontAdvanceData build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceDataImpl.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceDataImpl.java index c71e4fc..b1b4032 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceDataImpl.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/CharacterFontAdvanceDataImpl.java @@ -63,11 +63,6 @@ public class CharacterFontAdvanceDataImpl implements CharacterFontAdvanceData { return fontProviderFunction.apply(properties); } - @Override - public void close() { - data.clear(); - } - public static class BuilderImpl implements Builder { private final HashMap data = new HashMap<>(); diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/ConfigurableFontAdvanceData.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/ConfigurableFontAdvanceData.java index 63b2dae..7d0711c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/ConfigurableFontAdvanceData.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/ConfigurableFontAdvanceData.java @@ -19,28 +19,85 @@ package net.momirealms.customnameplates.api.feature.advance; import java.util.List; +/** + * Represents configurable font advance data, including default advance values and per-character advances. + */ public interface ConfigurableFontAdvanceData { + /** + * Returns the default advance (width) used when no specific value is defined for a character. + * + * @return the default advance width + */ float defaultAdvance(); + /** + * Retrieves the advance (width) for a specific character code point. + * + * @param codePoint the code point of the character + * @return the advance value for the character, or the default advance if not defined + */ float getAdvance(int codePoint); + /** + * Returns the unique identifier for this configurable font advance data. + * + * @return the font advance data ID + */ String id(); + /** + * Creates a new builder for constructing ConfigurableFontAdvanceData. + * + * @return a new builder instance + */ static Builder builder() { return new ConfigurableFontAdvanceDataImpl.BuilderImpl(); } + /** + * Builder for creating ConfigurableFontAdvanceData. + */ interface Builder { + /** + * Sets the unique ID for the configurable font advance data. + * + * @param id the ID of the font advance data + * @return the builder instance + */ Builder id(String id); + /** + * Sets the default advance (width) for characters that do not have specific advances. + * + * @param width the default advance width + * @return the builder instance + */ Builder defaultAdvance(float width); + /** + * Sets the advance (width) for a specific character code point. + * + * @param codePoint the code point of the character + * @param width the advance width for the character + * @return the builder instance + */ Builder advance(int codePoint, float width); + /** + * Sets the parent fonts used by this configurable font advance data. + * + * @param font a list of parent fonts + * @return the builder instance + */ Builder parentFont(List font); + /** + * Builds and returns the ConfigurableFontAdvanceData instance. + * + * @return the constructed ConfigurableFontAdvanceData + */ ConfigurableFontAdvanceData build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/background/Background.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/background/Background.java index 5bb6fbe..a7db1f8 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/background/Background.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/background/Background.java @@ -20,58 +20,195 @@ package net.momirealms.customnameplates.api.feature.background; import net.momirealms.customnameplates.api.feature.AdaptiveImage; import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; +/** + * Represents a background configuration + */ public interface Background extends AdaptiveImage { + /** + * Returns the unique ID of the background configuration. + * + * @return the background ID + */ String id(); + /** + * Returns the configured character for the left side of the background. + * + * @return the left-side configured character + */ ConfiguredCharacter left(); + /** + * Returns the configured character for width 1. + * + * @return the configured character for width 1 + */ ConfiguredCharacter width_1(); + /** + * Returns the configured character for width 2. + * + * @return the configured character for width 2 + */ ConfiguredCharacter width_2(); + /** + * Returns the configured character for width 4. + * + * @return the configured character for width 4 + */ ConfiguredCharacter width_4(); + /** + * Returns the configured character for width 8. + * + * @return the configured character for width 8 + */ ConfiguredCharacter width_8(); + /** + * Returns the configured character for width 16. + * + * @return the configured character for width 16 + */ ConfiguredCharacter width_16(); + /** + * Returns the configured character for width 32. + * + * @return the configured character for width 32 + */ ConfiguredCharacter width_32(); + /** + * Returns the configured character for width 64. + * + * @return the configured character for width 64 + */ ConfiguredCharacter width_64(); + /** + * Returns the configured character for width 128. + * + * @return the configured character for width 128 + */ ConfiguredCharacter width_128(); + /** + * Returns the configured character for the right side of the background. + * + * @return the right-side configured character + */ ConfiguredCharacter right(); + /** + * Creates a new builder for constructing a Background configuration. + * + * @return a new builder instance + */ static Builder builder() { return new BackgroundImpl.BuilderImpl(); } + /** + * Builder for constructing Background configurations. + */ interface Builder { + /** + * Sets the unique ID for the background. + * + * @param id the background ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets the configured character for the left side of the background. + * + * @param character the configured character for the left side + * @return the builder instance + */ Builder left(ConfiguredCharacter character); + /** + * Sets the configured character for width 1. + * + * @param character the configured character for width 1 + * @return the builder instance + */ Builder width_1(ConfiguredCharacter character); + /** + * Sets the configured character for width 2. + * + * @param character the configured character for width 2 + * @return the builder instance + */ Builder width_2(ConfiguredCharacter character); + /** + * Sets the configured character for width 4. + * + * @param character the configured character for width 4 + * @return the builder instance + */ Builder width_4(ConfiguredCharacter character); + /** + * Sets the configured character for width 8. + * + * @param character the configured character for width 8 + * @return the builder instance + */ Builder width_8(ConfiguredCharacter character); + /** + * Sets the configured character for width 16. + * + * @param character the configured character for width 16 + * @return the builder instance + */ Builder width_16(ConfiguredCharacter character); + /** + * Sets the configured character for width 32. + * + * @param character the configured character for width 32 + * @return the builder instance + */ Builder width_32(ConfiguredCharacter character); + /** + * Sets the configured character for width 64. + * + * @param character the configured character for width 64 + * @return the builder instance + */ Builder width_64(ConfiguredCharacter character); + /** + * Sets the configured character for width 128. + * + * @param character the configured character for width 128 + * @return the builder instance + */ Builder width_128(ConfiguredCharacter character); + /** + * Sets the configured character for the right side of the background. + * + * @param character the configured character for the right side + * @return the builder instance + */ Builder right(ConfiguredCharacter character); + /** + * Builds and returns the configured Background instance. + * + * @return the constructed Background + */ Background build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/background/BackgroundManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/background/BackgroundManager.java index 764aa0f..40f8574 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/background/BackgroundManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/background/BackgroundManager.java @@ -24,8 +24,19 @@ import java.util.Collection; public interface BackgroundManager extends Reloadable { + /** + * Retrieves a Background configuration by its unique ID. + * + * @param id the unique ID of the background + * @return the corresponding Background, or null if not found + */ @Nullable - Background getBackground(String id); + Background backgroundById(String id); + /** + * Returns a collection of all available Background configurations. + * + * @return a collection of Background instances + */ Collection getBackgrounds(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBar.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBar.java index c17b06c..46ccb79 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBar.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBar.java @@ -21,12 +21,33 @@ import java.util.UUID; public interface BossBar { + /** + * Returns the unique UUID of the BossBar. + * + * @return the UUID of the BossBar + */ UUID uuid(); + /** + * Returns the progress value of the BossBar. + * The value should be between 0.0 (empty) and 1.0 (full). + * + * @return the progress value of the BossBar + */ float progress(); + /** + * Returns the color of the BossBar. + * + * @return the color of the BossBar + */ Color color(); + /** + * Returns the overlay style of the BossBar, defining how the bar is divided. + * + * @return the overlay style of the BossBar + */ Overlay overlay(); enum Overlay { diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarConfig.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarConfig.java index 9754f64..c910a45 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarConfig.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarConfig.java @@ -21,40 +21,127 @@ import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.requirement.Requirement; public interface BossBarConfig { - + + /** + * The default overlay style for the BossBar. + */ BossBar.Overlay DEFAULT_OVERLAY = BossBar.Overlay.PROGRESS; + + /** + * The default color for the BossBar. + */ BossBar.Color DEFAULT_COLOR = BossBar.Color.YELLOW; + /** + * Returns the unique ID for the BossBar configuration. + * + * @return the configuration ID + */ String id(); + /** + * Returns the requirements for the BossBar. + * + * @return an array of requirements + */ Requirement[] requirements(); + /** + * Returns the carousel texts used in the BossBar. + * + * @return an array of carousel texts + */ CarouselText[] carouselTexts(); - + + /** + * Returns the overlay style for the BossBar. + * + * @return the overlay style + */ BossBar.Overlay overlay(); - + + /** + * Returns the color of the BossBar. + * + * @return the BossBar color + */ BossBar.Color color(); + /** + * Returns the progress value of the BossBar. + * The value should be between 0.0 (empty) and 1.0 (full). + * + * @return the progress value + */ float progress(); + /** + * Creates a new builder for constructing a BossBarConfig. + * + * @return a new builder instance + */ static BossBarConfig.Builder builder() { return new BossBarConfigImpl.BuilderImpl(); } + /** + * Builder for constructing BossBarConfig instances. + */ interface Builder { + /** + * Sets the unique ID for the BossBar configuration. + * + * @param id the configuration ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets the requirements for the BossBar. + * + * @param requirements an array of requirements + * @return the builder instance + */ Builder requirement(Requirement[] requirements); + /** + * Sets the carousel texts for the BossBar. + * + * @param carouselTexts an array of carousel texts + * @return the builder instance + */ Builder carouselText(CarouselText[] carouselTexts); - + + /** + * Sets the overlay style for the BossBar. + * + * @param overlay the overlay style + * @return the builder instance + */ Builder overlay(BossBar.Overlay overlay); - + + /** + * Sets the color for the BossBar. + * + * @param color the BossBar color + * @return the builder instance + */ Builder color(BossBar.Color color); + /** + * Sets the progress value for the BossBar. + * + * @param progress the progress value + * @return the builder instance + */ Builder progress(float progress); + /** + * Builds and returns the configured BossBarConfig instance. + * + * @return the constructed BossBarConfig + */ BossBarConfig build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarManager.java index ebe71ca..beeffd3 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarManager.java @@ -21,9 +21,23 @@ import net.momirealms.customnameplates.common.plugin.feature.Reloadable; public interface BossBarManager extends Reloadable { + /** + * Retrieves the BossBar configuration by its id. + * + * @param id the name of the BossBar configuration + * @return the corresponding BossBarConfig, or null if not found + */ + BossBarConfig configById(String id); + + /** + * Returns all available BossBar configurations. + * + * @return an array of all BossBarConfig instances + */ + BossBarConfig[] bossBarConfigs(); + + /** + * Called on every server tick to update the state of BossBars. + */ void onTick(); - - BossBarConfig getConfig(String name); - - BossBarConfig[] allConfigs(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/Bubble.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/Bubble.java index 0417303..e1336f4 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/Bubble.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/Bubble.java @@ -22,32 +22,100 @@ import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; public interface Bubble extends AdaptiveImage { + /** + * Returns the unique ID of the Bubble configuration. + * + * @return the Bubble ID + */ String id(); + /** + * Returns the configured character for the left side of the Bubble. + * + * @return the left-side configured character + */ ConfiguredCharacter left(); + /** + * Returns the configured character for the right side of the Bubble. + * + * @return the right-side configured character + */ ConfiguredCharacter right(); + /** + * Returns the configured character for the middle section of the Bubble. + * + * @return the middle configured character + */ ConfiguredCharacter middle(); + /** + * Returns the configured character for the tail section of the Bubble. + * + * @return the tail configured character + */ ConfiguredCharacter tail(); + /** + * Creates a new builder for constructing a Bubble configuration. + * + * @return a new builder instance + */ static Builder builder() { return new BubbleImpl.BuilderImpl(); } + /** + * Builder for constructing Bubble configurations. + */ interface Builder { + /** + * Sets the unique ID for the Bubble configuration. + * + * @param id the Bubble ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets the configured character for the left side of the Bubble. + * + * @param left the left-side configured character + * @return the builder instance + */ Builder left(ConfiguredCharacter left); + /** + * Sets the configured character for the right side of the Bubble. + * + * @param right the right-side configured character + * @return the builder instance + */ Builder right(ConfiguredCharacter right); + /** + * Sets the configured character for the middle section of the Bubble. + * + * @param middle the middle configured character + * @return the builder instance + */ Builder middle(ConfiguredCharacter middle); + /** + * Sets the configured character for the tail section of the Bubble. + * + * @param tail the tail configured character + * @return the builder instance + */ Builder tail(ConfiguredCharacter tail); + /** + * Builds and returns the constructed Bubble instance. + * + * @return the constructed Bubble + */ Bubble build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleConfig.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleConfig.java index b428373..5d5d668 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleConfig.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleConfig.java @@ -21,48 +21,160 @@ import net.momirealms.customnameplates.api.util.Vector3; public interface BubbleConfig { + /** + * Returns the unique ID of the Bubble configuration. + * + * @return the configuration ID + */ String id(); + /** + * Returns the background color of the Bubble text. + * + * @return the background color (ARGB) as an integer + */ int backgroundColor(); + /** + * Returns the line width for the Bubble text. + * + * @return the line width + */ int lineWidth(); + /** + * Returns the maximum number of lines for the Bubble text. + * + * @return the maximum number of lines + */ int maxLines(); + /** + * Returns the bubbles used in this configuration. + * + * @return an array of Bubble instances + */ Bubble[] bubbles(); + /** + * Returns the text prefix to be applied before the Bubble content. + * + * @return the text prefix + */ String textPrefix(); + /** + * Returns the text suffix to be applied after the Bubble content. + * + * @return the text suffix + */ String textSuffix(); + /** + * Returns the display name of the Bubble. + * + * @return the display name + */ String displayName(); + /** + * Returns the scale vector for the Bubble. + * + * @return the scale as a Vector3 + */ Vector3 scale(); + /** + * Creates a new builder for constructing a BubbleConfig. + * + * @return a new builder instance + */ static Builder builder() { return new BubbleConfigImpl.BuilderImpl(); } + /** + * Builder for constructing BubbleConfig instances. + */ interface Builder { + /** + * Sets the unique ID for the BubbleConfig. + * + * @param id the configuration ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets the display name for the BubbleConfig. + * + * @param displayName the display name + * @return the builder instance + */ Builder displayName(String displayName); + /** + * Sets the background color for the BubbleConfig. + * + * @param backgroundColor the background color + * @return the builder instance + */ Builder backgroundColor(int backgroundColor); + /** + * Sets the line width for the Bubble text. + * + * @param lineWidth the line width + * @return the builder instance + */ Builder lineWidth(int lineWidth); + /** + * Sets the maximum number of lines for the Bubble text. + * + * @param maxLines the maximum number of lines + * @return the builder instance + */ Builder maxLines(int maxLines); + /** + * Sets the bubbles used in this configuration. + * + * @param bubbles an array of Bubble instances + * @return the builder instance + */ Builder bubbles(Bubble[] bubbles); + /** + * Sets the text prefix for the BubbleConfig. + * + * @param textPrefix the text prefix + * @return the builder instance + */ Builder textPrefix(String textPrefix); + /** + * Sets the text suffix for the BubbleConfig. + * + * @param textSuffix the text suffix + * @return the builder instance + */ Builder textSuffix(String textSuffix); + /** + * Sets the scale for the BubbleConfig. + * + * @param scale the scale as a Vector3 + * @return the builder instance + */ Builder scale(Vector3 scale); + /** + * Builds and returns the configured BubbleConfig instance. + * + * @return the constructed BubbleConfig + */ BubbleConfig build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleManager.java index 2a59a84..867fc06 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleManager.java @@ -27,38 +27,122 @@ import java.util.Set; public interface BubbleManager extends Reloadable { - Collection getBubbleConfigs(); + /** + * Returns a collection of all available Bubble instances. + * + * @return a collection of Bubble instances + */ + Collection bubbles(); + /** + * Returns a collection of all Bubble configurations. + * + * @return a collection of BubbleConfig instances + */ + Collection bubbleConfigs(); + + /** + * Retrieves a Bubble by its unique ID. + * + * @param id the Bubble ID + * @return the Bubble instance, or null if not found + */ @Nullable - Bubble getBubble(String id); + Bubble bubbleById(String id); - @Nullable BubbleConfig getBubbleConfig(String id); - - Collection getBubbles(); + /** + * Retrieves a Bubble configuration by its unique ID. + * + * @param id the BubbleConfig ID + * @return the BubbleConfig instance, or null if not found + */ + @Nullable + BubbleConfig bubbleConfigById(String id); + /** + * Checks if a player has access to a specific Bubble by its ID. + * + * @param player the player to check + * @param id the Bubble ID + * @return true if the player has the Bubble, false otherwise + */ boolean hasBubble(CNPlayer player, String id); + /** + * Returns a collection of available Bubbles for the player. + * + * @param player the player to check + * @return a collection of available BubbleConfig instances + */ Collection availableBubbles(CNPlayer player); + /** + * Returns the set of channels that are blacklisted from displaying Bubbles. + * + * @return a set of blacklisted channel names + */ Set blacklistChannels(); + /** + * Returns the current mode for Bubble channels. + * + * @return the ChannelMode in use + */ + ChannelMode channelMode(); + + /** + * Returns the default Bubble ID used when no specific Bubble is set. + * + * @return the default Bubble ID + */ String defaultBubbleId(); + /** + * Returns the requirements to send a Bubble. + * + * @return an array of send Bubble requirements + */ Requirement[] sendBubbleRequirements(); + /** + * Returns the requirements to view a Bubble. + * + * @return an array of view Bubble requirements + */ Requirement[] viewBubbleRequirements(); - String omittedText(); - + /** + * Returns the vertical offset for Bubble display. + * + * @return the vertical offset as a double + */ double verticalOffset(); + /** + * Returns the duration (in ticks) for which the Bubble remains visible. + * + * @return the stay duration in ticks + */ int stayDuration(); + /** + * Returns the duration (in ticks) for the Bubble to appear. + * + * @return the appear duration in ticks + */ int appearDuration(); + /** + * Returns the duration (in ticks) for the Bubble to disappear. + * + * @return the disappear duration in ticks + */ int disappearDuration(); + /** + * Returns the view range for Bubbles. + * + * @return the view range as a float + */ float viewRange(); - - ChannelMode channelMode(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/AbstractChatMessageProvider.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/AbstractChatMessageProvider.java similarity index 64% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/AbstractChatMessageProvider.java rename to api/src/main/java/net/momirealms/customnameplates/api/feature/chat/AbstractChatMessageProvider.java index d341a34..e1cb7a9 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/AbstractChatMessageProvider.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/AbstractChatMessageProvider.java @@ -15,23 +15,39 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bubble.chat; +package net.momirealms.customnameplates.api.feature.chat; import net.momirealms.customnameplates.api.CustomNameplates; +/** + * Abstract base class for chat message providers, providing common functionality + * for managing the plugin and chat manager. + */ public abstract class AbstractChatMessageProvider implements ChatMessageProvider { protected CustomNameplates plugin; protected ChatManager manager; + /** + * Constructs a new AbstractChatMessageProvider. + * + * @param plugin the CustomNameplates plugin instance + * @param manager the ChatManager instance to handle chat-related operations + */ public AbstractChatMessageProvider(CustomNameplates plugin, ChatManager manager) { this.plugin = plugin; this.manager = manager; } + /** + * Registers the chat message provider. Intended to be overridden by subclasses if needed. + */ public void register() { } + /** + * Unregisters the chat message provider. Intended to be overridden by subclasses if needed. + */ public void unregister() { } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/ChatManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/ChatManager.java similarity index 50% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/ChatManager.java rename to api/src/main/java/net/momirealms/customnameplates/api/feature/chat/ChatManager.java index a479a15..6bf1120 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/ChatManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/ChatManager.java @@ -15,23 +15,59 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bubble.chat; +package net.momirealms.customnameplates.api.feature.chat; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.feature.ChatListener; import net.momirealms.customnameplates.common.plugin.feature.Reloadable; +/** + * Manages chat-related functionality, including handling custom chat providers, listeners, and chat events. + */ public interface ChatManager extends Reloadable { + /** + * Sets a custom chat message provider. + * + * @param provider the custom ChatMessageProvider to set + * @return true if the provider was successfully set, false otherwise + */ boolean setCustomChatProvider(ChatMessageProvider provider); + /** + * Removes the currently set custom chat message provider. + * + * @return true if the provider was successfully removed, false otherwise + */ boolean removeCustomChatProvider(); + /** + * Registers a chat listener to receive chat events. + * + * @param listener the ChatListener to register + */ void registerListener(ChatListener listener); + /** + * Unregisters a chat listener, stopping it from receiving chat events. + * + * @param listener the ChatListener to unregister + */ void unregisterListener(ChatListener listener); + /** + * Returns the current chat message provider. + * + * @return the currently set ChatMessageProvider, or null if none is set + */ ChatMessageProvider chatProvider(); + /** + * Handles a chat message event for the specified player and channel. + * + * @param player the player who sent the message + * @param message the chat message content + * @param channel the chat channel + */ void onChat(CNPlayer player, String message, String channel); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/ChatMessageProvider.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/ChatMessageProvider.java similarity index 50% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/ChatMessageProvider.java rename to api/src/main/java/net/momirealms/customnameplates/api/feature/chat/ChatMessageProvider.java index 06b3aca..95aabb7 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/ChatMessageProvider.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/ChatMessageProvider.java @@ -15,15 +15,39 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bubble.chat; +package net.momirealms.customnameplates.api.feature.chat; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Provides chat-related functionality, including channel membership and ignore status between players. + */ public interface ChatMessageProvider { + /** + * Checks if a player has joined a specific chat channel. + * + * @param player the player to check + * @param channelID the ID of the chat channel + * @return true if the player has joined the channel, false otherwise + */ boolean hasJoinedChannel(CNPlayer player, String channelID); + /** + * Checks if a player is allowed to join a specific chat channel. + * + * @param player the player to check + * @param channelID the ID of the chat channel + * @return true if the player can join the channel, false otherwise + */ boolean canJoinChannel(CNPlayer player, String channelID); + /** + * Checks if a player is ignoring another player. + * + * @param sender the player sending messages + * @param receiver the player who may be ignoring the sender + * @return true if the receiver is ignoring the sender, false otherwise + */ boolean isIgnoring(CNPlayer sender, CNPlayer receiver); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/emoji/EmojiProvider.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/emoji/EmojiProvider.java similarity index 60% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/emoji/EmojiProvider.java rename to api/src/main/java/net/momirealms/customnameplates/api/feature/chat/emoji/EmojiProvider.java index 657c9c3..cb2af6c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/emoji/EmojiProvider.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/chat/emoji/EmojiProvider.java @@ -15,11 +15,22 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bubble.emoji; +package net.momirealms.customnameplates.api.feature.chat.emoji; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Interface for providing emoji replacement functionality. + * Allows replacing certain text patterns with corresponding emojis for a given player. + */ public interface EmojiProvider { + /** + * Replaces specified text patterns in the given string with emojis, based on the player context. + * + * @param player the player for whom the emoji replacement is being processed + * @param text the original text to process + * @return the text with emojis replacing certain patterns + */ String replace(CNPlayer player, String text); -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/image/Image.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/image/Image.java index ba138c4..16c4751 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/image/Image.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/image/Image.java @@ -21,28 +21,86 @@ import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; public interface Image { + /** + * Returns the unique ID of the image configuration. + * + * @return the image ID + */ String id(); + /** + * Checks if the image has a shadow effect. + * + * @return true if the image has a shadow, false otherwise + */ boolean hasShadow(); + /** + * Returns the opacity level of the image. + * The value should typically range from 0 (fully transparent) to 255 (fully opaque). + * + * @return the opacity value of the image + */ int opacity(); + /** + * Returns the configured character associated with this image. + * + * @return the configured character + */ ConfiguredCharacter character(); + /** + * Creates a new builder for constructing an Image configuration. + * + * @return a new builder instance + */ static Builder builder() { return new ImageImpl.BuilderImpl(); } + /** + * Builder for constructing Image configurations. + */ interface Builder { + /** + * Sets the unique ID for the image configuration. + * + * @param id the image ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets whether the image has a shadow effect. + * + * @param has true if the image should have a shadow, false otherwise + * @return the builder instance + */ Builder hasShadow(boolean has); + /** + * Sets the opacity level of the image. + * + * @param opacity the opacity value, typically from 0 to 255 + * @return the builder instance + */ Builder opacity(int opacity); + /** + * Sets the configured character associated with this image. + * + * @param character the configured character + * @return the builder instance + */ Builder character(ConfiguredCharacter character); + /** + * Builds and returns the configured Image instance. + * + * @return the constructed Image + */ Image build(); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/image/ImageManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/image/ImageManager.java index 28db5d9..795a09c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/image/ImageManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/image/ImageManager.java @@ -24,8 +24,19 @@ import java.util.Collection; public interface ImageManager extends Reloadable { + /** + * Retrieves an Image configuration by its unique ID. + * + * @param id the unique ID of the image + * @return the Image instance, or null if not found + */ @Nullable - Image getImage(String id); + Image imageById(String id); - Collection getImages(); + /** + * Returns a collection of all available Image configurations. + * + * @return a collection of Image instances + */ + Collection images(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/Nameplate.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/Nameplate.java index 8e2affb..1aed722 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/Nameplate.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/Nameplate.java @@ -22,32 +22,100 @@ import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; public interface Nameplate extends AdaptiveImage { + /** + * Returns the unique ID of the nameplate configuration. + * + * @return the nameplate ID + */ String id(); + /** + * Returns the display name of the nameplate. + * + * @return the display name of the nameplate + */ String displayName(); + /** + * Returns the configured character for the left side of the nameplate. + * + * @return the left-side configured character + */ ConfiguredCharacter left(); + /** + * Returns the configured character for the middle section of the nameplate. + * + * @return the middle configured character + */ ConfiguredCharacter middle(); + /** + * Returns the configured character for the right side of the nameplate. + * + * @return the right-side configured character + */ ConfiguredCharacter right(); + /** + * Creates a new builder for constructing a Nameplate configuration. + * + * @return a new builder instance + */ static Builder builder() { return new NameplateImpl.BuilderImpl(); } + /** + * Builder for constructing Nameplate configurations. + */ interface Builder { + /** + * Sets the unique ID for the nameplate. + * + * @param id the nameplate ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets the display name for the nameplate. + * + * @param displayName the display name + * @return the builder instance + */ Builder displayName(String displayName); + /** + * Sets the configured character for the left side of the nameplate. + * + * @param left the left-side configured character + * @return the builder instance + */ Builder left(ConfiguredCharacter left); + /** + * Sets the configured character for the middle section of the nameplate. + * + * @param middle the middle configured character + * @return the builder instance + */ Builder middle(ConfiguredCharacter middle); + /** + * Sets the configured character for the right side of the nameplate. + * + * @param right the right-side configured character + * @return the builder instance + */ Builder right(ConfiguredCharacter right); + /** + * Builds and returns the configured Nameplate instance. + * + * @return the constructed Nameplate + */ Nameplate build(); } -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/NameplateManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/NameplateManager.java index 2a033ed..2b0e2e9 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/NameplateManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/NameplateManager.java @@ -25,16 +25,50 @@ import java.util.Collection; public interface NameplateManager extends Reloadable { + /** + * Retrieves a Nameplate by its unique ID. + * + * @param id the unique ID of the nameplate + * @return the Nameplate instance, or null if not found + */ @Nullable - Nameplate getNameplate(String id); + Nameplate nameplateById(String id); - Collection getNameplates(); + /** + * Returns a collection of all available nameplates. + * + * @return a collection of Nameplate instances + */ + Collection nameplates(); + /** + * Checks if a player has access to a specific nameplate by its ID. + * + * @param player the player to check + * @param id the ID of the nameplate + * @return true if the player has access, false otherwise + */ boolean hasNameplate(CNPlayer player, String id); + /** + * Returns a collection of nameplates available to the player. + * + * @param player the player to check + * @return a collection of available Nameplate instances + */ Collection availableNameplates(CNPlayer player); + /** + * Returns the ID of the default nameplate to be used when no specific nameplate is set. + * + * @return the default nameplate ID + */ String defaultNameplateId(); + /** + * Returns the player's name tag to be displayed on the nameplate. + * + * @return the player's name tag + */ String playerNameTag(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/ResourcePackManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/ResourcePackManager.java index 9767119..c250ddb 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/ResourcePackManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/ResourcePackManager.java @@ -21,5 +21,8 @@ import net.momirealms.customnameplates.common.plugin.feature.Reloadable; public interface ResourcePackManager extends Reloadable { + /** + * Generates the resource pack. + */ void generate(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/AbstractTag.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/AbstractTag.java index b294faa..7e03153 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/AbstractTag.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/AbstractTag.java @@ -118,28 +118,28 @@ public abstract class AbstractTag implements Tag { } @Override - public void updateOpacity(byte opacity) { + public void onPlayerCrouching(boolean isCrouching) { for (CNPlayer viewer : viewerArray) { - updateOpacity(viewer, opacity); + onPlayerCrouching(viewer, isCrouching); } } @Override - public void updateOpacity(CNPlayer viewer, byte opacity) { - Consumer> modifiers = CustomNameplates.getInstance().getPlatform().createOpacityModifier(opacity); + public void onPlayerCrouching(CNPlayer viewer, boolean isCrouching) { + Consumer> modifiers = CustomNameplates.getInstance().getPlatform().createOpacityModifier(isCrouching ? 64 : opacity()); Object packet = CustomNameplates.getInstance().getPlatform().updateTextDisplayPacket(entityID, List.of(modifiers)); CustomNameplates.getInstance().getPacketSender().sendPacket(viewer, packet); } @Override - public void updateScale(double scale) { + public void onPlayerScaleUpdate(double scale) { for (CNPlayer viewer : viewerArray) { - updateScale(viewer, scale); + onPlayerScaleUpdate(viewer, scale); } } @Override - public void updateScale(CNPlayer viewer, double scale) { + public void onPlayerScaleUpdate(CNPlayer viewer, double scale) { Consumer> modifier1 = CustomNameplates.getInstance().getPlatform().createScaleModifier(scale(viewer).multiply(scale)); Consumer> modifier2 = CustomNameplates.getInstance().getPlatform().createTranslationModifier(translation(viewer).multiply(scale)); Object packet = CustomNameplates.getInstance().getPlatform().updateTextDisplayPacket(entityID, List.of(modifier1, modifier2)); diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java index aa89983..1916ba9 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTagConfig.java @@ -24,84 +24,296 @@ import net.momirealms.customnameplates.api.util.Vector3; public interface NameTagConfig { + /** + * Returns the unique ID of the name tag configuration. + * + * @return the name tag configuration ID + */ String id(); + /** + * Returns the requirements for the name tag owner. + * + * @return an array of owner requirements + */ Requirement[] ownerRequirements(); + /** + * Returns the requirements for the name tag viewer. + * + * @return an array of viewer requirements + */ Requirement[] viewerRequirements(); + /** + * Returns the carousel texts displayed on the name tag. + * + * @return an array of carousel texts + */ CarouselText[] carouselTexts(); + /** + * Returns the opacity level of the name tag. + * + * @return the opacity value as a byte + */ byte opacity(); + /** + * Returns the background color of the name tag. + * + * @return the background color as an integer + */ int backgroundColor(); + /** + * Checks if the name tag has a shadow effect. + * + * @return true if the name tag has a shadow, false otherwise + */ boolean hasShadow(); + /** + * Checks if the name tag is see-through. + * + * @return true if the name tag is see-through, false otherwise + */ boolean isSeeThrough(); + /** + * Checks if the default background color is used. + * + * @return true if the default background color is used, false otherwise + */ boolean useDefaultBackgroundColor(); + /** + * Checks if the name tag is affected by the crouching state of the player. + * + * @return true if affected by crouching, false otherwise + */ boolean affectedByCrouching(); + /** + * Checks if the name tag is affected by scaling. + * + * @return true if affected by scaling, false otherwise + */ boolean affectedByScaling(); + /** + * Returns the alignment of the name tag. + * + * @return the alignment of the name tag + */ Alignment alignment(); + /** + * Returns the view range of the name tag. + * + * @return the view range as a float + */ float viewRange(); + /** + * Returns the shadow radius of the name tag. + * + * @return the shadow radius as a float + */ float shadowRadius(); + /** + * Returns the shadow strength of the name tag. + * + * @return the shadow strength as a float + */ float shadowStrength(); + /** + * Returns the scaling vector of the name tag. + * + * @return the scaling vector as a Vector3 + */ Vector3 scale(); + /** + * Returns the translation vector for the name tag. + * + * @return the translation vector as a Vector3 + */ Vector3 translation(); + /** + * Returns the maximum line width of the name tag. + * + * @return the line width as an integer + */ int lineWidth(); + /** + * Creates a new builder for constructing a NameTagConfig. + * + * @return a new builder instance + */ static Builder builder() { return new NameTagConfigImpl.BuilderImpl(); } + /** + * Builder for constructing NameTagConfig instances with customizable properties. + */ interface Builder { + /** + * Sets the unique ID for the NameTagConfig. + * + * @param id the name tag configuration ID + * @return the builder instance + */ Builder id(String id); + /** + * Sets the maximum line width for the name tag. + * + * @param lineWidth the maximum line width + * @return the builder instance + */ Builder lineWidth(int lineWidth); + /** + * Sets the requirements for the name tag owner. + * + * @param requirements an array of owner requirements + * @return the builder instance + */ Builder ownerRequirement(Requirement[] requirements); + /** + * Sets the requirements for the name tag viewer. + * + * @param requirements an array of viewer requirements + * @return the builder instance + */ Builder viewerRequirement(Requirement[] requirements); + /** + * Sets the carousel texts for the name tag. + * + * @param carouselTexts an array of carousel texts + * @return the builder instance + */ Builder carouselText(CarouselText[] carouselTexts); + /** + * Sets the opacity level for the name tag. + * + * @param opacity the opacity value as a byte + * @return the builder instance + */ Builder opacity(byte opacity); + /** + * Sets the background color for the name tag. + * + * @param backgroundColor the background color as an integer + * @return the builder instance + */ Builder backgroundColor(int backgroundColor); + /** + * Sets whether the name tag has a shadow effect. + * + * @param hasShadow true if the name tag should have a shadow, false otherwise + * @return the builder instance + */ Builder hasShadow(boolean hasShadow); + /** + * Sets whether the name tag is see-through. + * + * @param seeThrough true if the name tag is see-through, false otherwise + * @return the builder instance + */ Builder seeThrough(boolean seeThrough); + /** + * Sets whether the name tag uses the default background color. + * + * @param useDefaultBackgroundColor true to use the default background color, false otherwise + * @return the builder instance + */ Builder useDefaultBackgroundColor(boolean useDefaultBackgroundColor); + /** + * Sets the alignment of the name tag. + * + * @param alignment the alignment setting + * @return the builder instance + */ Builder alignment(Alignment alignment); + /** + * Sets the view range for the name tag. + * + * @param viewRange the view range as a float + * @return the builder instance + */ Builder viewRange(float viewRange); + /** + * Sets the shadow radius for the name tag. + * + * @param shadowRadius the shadow radius as a float + * @return the builder instance + */ Builder shadowRadius(float shadowRadius); + /** + * Sets the shadow strength for the name tag. + * + * @param shadowStrength the shadow strength as a float + * @return the builder instance + */ Builder shadowStrength(float shadowStrength); + /** + * Sets the scaling factor for the name tag. + * + * @param scale the scaling vector + * @return the builder instance + */ Builder scale(Vector3 scale); + /** + * Sets the translation vector for the name tag. + * + * @param translation the translation vector + * @return the builder instance + */ Builder translation(Vector3 translation); + /** + * Sets whether the name tag is affected by crouching. + * + * @param affectedByCrouching true if the name tag is affected by crouching, false otherwise + * @return the builder instance + */ Builder affectedByCrouching(boolean affectedByCrouching); + /** + * Sets whether the name tag is affected by scaling. + * + * @param affectedByScale true if the name tag is affected by scaling, false otherwise + * @return the builder instance + */ Builder affectedByScaling(boolean affectedByScale); + /** + * Builds and returns the configured NameTagConfig instance. + * + * @return the constructed NameTagConfig + */ NameTagConfig build(); } } + diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/Tag.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/Tag.java index b35ec4b..7d34a6b 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/Tag.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/Tag.java @@ -24,55 +24,180 @@ import java.util.UUID; public interface Tag { + /** + * Returns the ID of the tag. + * + * @return the tag ID + */ String id(); + /** + * Returns the entity ID associated with the tag. + * + * @return the entity ID + */ int entityID(); + /** + * Returns the UUID of the tag. + * + * @return the tag UUID + */ UUID uuid(); + /** + * Checks if the tag is affected by crouching. + * + * @return true if affected by crouching, false otherwise + */ boolean affectedByCrouching(); + /** + * Checks if the tag is affected by scaling. + * + * @return true if affected by scaling, false otherwise + */ boolean affectedByScaling(); + /** + * Hides the tag for all viewers. + */ void hide(); + /** + * Hides the tag for a specific viewer. + * + * @param viewer the player for whom the tag will be hidden + */ void hide(CNPlayer viewer); + /** + * Shows the tag to all viewers. + */ void show(); + /** + * Shows the tag to a specific viewer. + * + * @param viewer the player for whom the tag will be shown + */ void show(CNPlayer viewer); + /** + * Respawns the tag for all viewers. + */ void respawn(); + /** + * Respawns the tag for a specific viewer. + * + * @param viewer the player for whom the tag will be respawned + */ void respawn(CNPlayer viewer); + /** + * Returns the opacity of the tag. + * + * @return the opacity value as a byte + */ byte opacity(); - void updateOpacity(byte opacity); - - void updateOpacity(CNPlayer viewer, byte opacity); - + /** + * Checks if the tag can be shown to all viewers. + * + * @return true if the tag can be shown, false otherwise + */ boolean canShow(); - + + /** + * Checks if the tag can be shown to a specific viewer. + * + * @param viewer the player to check + * @return true if the tag can be shown, false otherwise + */ boolean canShow(CNPlayer viewer); + /** + * Checks if the tag is currently shown to all viewers. + * + * @return true if the tag is shown, false otherwise + */ boolean isShown(); + /** + * Checks if the tag is currently shown to a specific viewer. + * + * @param viewer the player to check + * @return true if the tag is shown, false otherwise + */ boolean isShown(CNPlayer viewer); + /** + * Called every tick to update the tag's state. + */ void tick(); + /** + * Initializes the tag. + */ void init(); + /** + * Returns the text height of the tag for a specific viewer. + * + * @param viewer the player to check + * @return the text height + */ double getTextHeight(CNPlayer viewer); - void updateScale(double scale); + /** + * Updates the tag state when the player crouches. + * + * @param isCrouching true if the player is crouching, false otherwise + */ + void onPlayerCrouching(boolean isCrouching); - void updateScale(CNPlayer viewer, double scale); + /** + * Updates the tag state when the player crouches for a specific viewer. + * + * @param viewer the player to update + * @param isCrouching true if the player is crouching, false otherwise + */ + void onPlayerCrouching(CNPlayer viewer, boolean isCrouching); + /** + * Updates the tag scale when the player's scale changes. + * + * @param scale the new scale value + */ + void onPlayerScaleUpdate(double scale); + + /** + * Updates the tag scale when the player's scale changes for a specific viewer. + * + * @param viewer the player to update + * @param scale the new scale value + */ + void onPlayerScaleUpdate(CNPlayer viewer, double scale); + + /** + * Updates the translation of the tag. + */ void updateTranslation(); + /** + * Returns the scaling vector of the tag for a specific viewer. + * + * @param viewer the player to check + * @return the scaling vector + */ Vector3 scale(CNPlayer viewer); + /** + * Returns the translation vector of the tag for a specific viewer. + * + * @param viewer the player to check + * @return the translation vector + */ Vector3 translation(CNPlayer viewer); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/TagRenderer.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/TagRenderer.java index f1d6ea0..bcd184d 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/TagRenderer.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/TagRenderer.java @@ -21,23 +21,72 @@ import java.util.function.Predicate; public interface TagRenderer { + /** + * Returns the offset applied to the tag for positioning a "hat" or similar element above the entity's head. + * + * @return the hat offset value + */ double hatOffset(); + /** + * Sets the offset applied to the tag for positioning a "hat" or similar element above the entity's head. + * + * @param hatOffset the new hat offset value + */ void hatOffset(double hatOffset); + /** + * Called every tick to update the state of the tags managed by this renderer. + */ void onTick(); + /** + * Destroys the renderer, cleaning up any resources or tags it manages. + */ void destroy(); + /** + * Adds a new tag to be rendered. + * + * @param tag the tag to add + */ void addTag(Tag tag); + /** + * Returns the array of tags currently managed by this renderer. + * + * @return an array of Tag instances + */ Tag[] tags(); + /** + * Removes tags that match the given predicate. + * + * @param predicate a predicate to test tags for removal + * @return the number of tags removed + */ int removeTagIf(Predicate predicate); + /** + * Returns the index of the specified tag in the renderer's tag list. + * + * @param tag the tag to check + * @return the index of the tag, or -1 if not found + */ int tagIndex(Tag tag); + /** + * Adds a tag at the specified index in the renderer's tag list. + * + * @param tag the tag to add + * @param index the index at which to insert the tag + */ void addTag(Tag tag, int index); + /** + * Removes the specified tag from the renderer's tag list. + * + * @param tag the tag to remove + */ void removeTag(Tag tag); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/UnlimitedTagManager.java b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/UnlimitedTagManager.java index 06ffa0f..dd342bf 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/UnlimitedTagManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/UnlimitedTagManager.java @@ -20,32 +20,96 @@ package net.momirealms.customnameplates.api.feature.tag; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.common.plugin.feature.Reloadable; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; public interface UnlimitedTagManager extends Reloadable { + /** + * Called every tick to update the state of tags. + */ void onTick(); + /** + * Checks if name tags should always be shown. + * + * @return true if name tags are always shown, false otherwise + */ boolean isAlwaysShow(); - NameTagConfig getConfig(String name); + /** + * Retrieves the name tag configuration by its id. + * + * @param id the id of the tag configuration + * @return the corresponding NameTagConfig + */ + NameTagConfig configById(String id); - NameTagConfig[] allConfigs(); + /** + * Returns all available name tag configurations. + * + * @return an array of all NameTagConfig instances + */ + NameTagConfig[] nameTagConfigs(); + /** + * Sets whether a player is in preview mode for tags. + * + * @param player the player to update + * @param preview true to enable preview mode, false to disable + */ void setPreviewing(CNPlayer player, boolean preview); + /** + * Returns the duration (in ticks) for which a tag preview is shown. + * + * @return the preview duration in ticks + */ int previewDuration(); + /** + * Returns the TagRenderer responsible for rendering tags for a specific owner. + * + * @param owner the owner of the tags + * @return the TagRenderer for the owner + */ + @Nullable TagRenderer getTagRender(CNPlayer owner); + /** + * Internal method for handling when a player is added to the owner's viewer list. + * + * @param owner the player who owns the tags + * @param added the player who is added to the viewer list + */ @ApiStatus.Internal void onAddPlayer(CNPlayer owner, CNPlayer added); + /** + * Internal method for handling when a player is removed from the owner's viewer list. + * + * @param owner the player who owns the tags + * @param removed the player who is removed from the viewer list + */ @ApiStatus.Internal void onRemovePlayer(CNPlayer owner, CNPlayer removed); + /** + * Internal method for updating a player's crouching state. + * + * @param owner the player who owns the tags + * @param viewer the player viewing the tags + * @param isCrouching true if the player is crouching, false otherwise + */ @ApiStatus.Internal void onPlayerDataSet(CNPlayer owner, CNPlayer viewer, boolean isCrouching); + /** + * Internal method for updating a player's scale attributes. + * + * @param owner the player who owns the tags + * @param viewer the player viewing the tags + * @param scale the new scale value + */ @ApiStatus.Internal void onPlayerAttributeSet(CNPlayer owner, CNPlayer viewer, double scale); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/helper/AdventureHelper.java b/api/src/main/java/net/momirealms/customnameplates/api/helper/AdventureHelper.java index 1d0f5db..c8ff0a3 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/helper/AdventureHelper.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/helper/AdventureHelper.java @@ -127,6 +127,12 @@ public class AdventureHelper { ); } + /** + * Converts a MiniMessage string to a Minecraft component object. + * + * @param miniMessage the MiniMessage string + * @return the Minecraft component object + */ public static Object miniMessageToMinecraftComponent(String miniMessage) { AdventureHelper instance = getInstance(); return instance.miniMessageToMinecraftComponentCache.get(miniMessage, (text) -> { @@ -135,6 +141,14 @@ public class AdventureHelper { }); } + /** + * Converts a MiniMessage string with a score component to a Minecraft component object. + * + * @param miniMessage the MiniMessage string + * @param name the name used in the score component + * @param objective the objective used in the score component + * @return the Minecraft component object + */ public static Object miniMessageToMinecraftComponent(String miniMessage, String name, String objective) { AdventureHelper instance = getInstance(); return instance.miniMessageToMinecraftComponentCache.get(miniMessage, (text) -> { @@ -143,6 +157,12 @@ public class AdventureHelper { }); } + /** + * Converts a Minecraft component object to a MiniMessage string. + * + * @param component the Minecraft component object + * @return the MiniMessage string representation + */ public static String minecraftComponentToMiniMessage(Object component) { AdventureHelper instance = getInstance(); return instance.minecraftComponentToMiniMessageCache.get(component, (object) -> { @@ -169,10 +189,22 @@ public class AdventureHelper { return getInstance().gsonComponentSerializer; } + /** + * Surrounds the provided text with the default nameplates font. + * + * @param text the text to surround + * @return the text surrounded by the default nameplates font tag + */ public static String surroundWithNameplatesFont(String text) { return surroundWithMiniMessageFont(text, ConfigManager.namespace() + ":" + ConfigManager.font()); } + /** + * Removes shadow from the provided text using a specific color code trick. + * + * @param text the text to modify + * @return the text wrapped in a color tag to remove shadows + */ public static String removeShadowTricky(String text) { return "<#FFFEFD>" + text + ""; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/network/PacketEvent.java b/api/src/main/java/net/momirealms/customnameplates/api/network/PacketEvent.java index 45963da..2fb9ccb 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/network/PacketEvent.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/network/PacketEvent.java @@ -24,20 +24,38 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +/** + * Represents a packet event, which can be cancelled and supports delayed tasks that are executed later. + */ public class PacketEvent implements Cancellable { private boolean cancelled; private List delayedTasks = null; private final Object packet; + /** + * Constructs a new PacketEvent with the specified packet. + * + * @param packet the packet associated with this event + */ public PacketEvent(Object packet) { this.packet = packet; } + /** + * Returns the packet associated with this event. + * + * @return the packet object + */ public Object getPacket() { return packet; } + /** + * Adds a task to be executed later, after the event has been processed. + * + * @param task the task to be added + */ public void addDelayedTask(Runnable task) { if (delayedTasks == null) { delayedTasks = new ArrayList<>(); @@ -45,17 +63,32 @@ public class PacketEvent implements Cancellable { delayedTasks.add(task); } + /** + * Returns the list of delayed tasks to be executed. + * + * @return a list of tasks, or an empty list if no tasks are added + */ public List getDelayedTasks() { return Optional.ofNullable(delayedTasks).orElse(Collections.emptyList()); } + /** + * Checks if the event has been cancelled. + * + * @return true if the event is cancelled, false otherwise + */ @Override public boolean cancelled() { return cancelled; } + /** + * Sets the cancelled state of the event. + * + * @param cancelled true to cancel the event, false to proceed + */ @Override public void cancelled(boolean cancelled) { this.cancelled = cancelled; } -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/network/PacketSender.java b/api/src/main/java/net/momirealms/customnameplates/api/network/PacketSender.java index 4b335ca..6c81528 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/network/PacketSender.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/network/PacketSender.java @@ -22,9 +22,24 @@ import org.jetbrains.annotations.NotNull; import java.util.List; +/** + * Interface for sending packets to players. + */ public interface PacketSender { + /** + * Sends a single packet to the specified player. + * + * @param player the player to send the packet to + * @param packet the packet to be sent + */ void sendPacket(@NotNull CNPlayer player, Object packet); + /** + * Sends a list of packets to the specified player. + * + * @param player the player to send the packets to + * @param packet the list of packets to be sent + */ void sendPacket(@NotNull CNPlayer player, List packet); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/network/PipelineInjector.java b/api/src/main/java/net/momirealms/customnameplates/api/network/PipelineInjector.java index d21cc59..4010ee8 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/network/PipelineInjector.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/network/PipelineInjector.java @@ -21,13 +21,38 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelDuplexHandler; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Interface for injecting and managing Netty pipeline handlers for players. + */ public interface PipelineInjector { + /** + * Retrieves the Netty channel associated with the specified player. + * + * @param player the player whose channel is being retrieved + * @return the Netty channel associated with the player + */ Channel getChannel(CNPlayer player); + /** + * Creates a custom ChannelDuplexHandler for the specified player, used to intercept and modify network traffic. + * + * @param player the player for whom the handler is being created + * @return a ChannelDuplexHandler for the player + */ ChannelDuplexHandler createHandler(CNPlayer player); + /** + * Injects a custom handler into the player's network channel, allowing interception and modification of packets. + * + * @param player the player whose channel will be injected + */ void inject(CNPlayer player); + /** + * Removes the custom handler from the player's network channel. + * + * @param player the player whose channel will have the handler removed + */ void uninject(CNPlayer player); -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/network/Tracker.java b/api/src/main/java/net/momirealms/customnameplates/api/network/Tracker.java index 9694619..9bcc288 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/network/Tracker.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/network/Tracker.java @@ -31,18 +31,17 @@ public class Tracker { private final Set passengerIDs = Collections.synchronizedSet(new HashSet<>()); + /** + * Constructs a new Tracker for the specified player. + * + * @param tracker the player being tracked + */ public Tracker(CNPlayer tracker) { this.isCrouching = false; this.scale = 1; this.tracker = tracker; } - public Tracker(CNPlayer tracker, boolean isCrouching, double scale) { - this.isCrouching = isCrouching; - this.scale = scale; - this.tracker = tracker; - } - public CNPlayer tracker() { return tracker; } @@ -78,4 +77,4 @@ public class Tracker { public boolean isEmpty() { return passengerIDs.isEmpty(); } -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/AbstractPlaceholder.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/AbstractPlaceholder.java index 48cb8ea..5849b66 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/AbstractPlaceholder.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/AbstractPlaceholder.java @@ -21,6 +21,9 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; +/** + * Abstract base class for placeholders, providing common functionality for managing children, ID, and refresh intervals. + */ public abstract class AbstractPlaceholder implements Placeholder { protected String id; @@ -29,48 +32,91 @@ public abstract class AbstractPlaceholder implements Placeholder { protected PlaceholderManager manager; protected Set children = new HashSet<>(); + /** + * Constructs an AbstractPlaceholder with the specified manager, ID, and refresh interval. + * + * @param manager the PlaceholderManager that manages this placeholder + * @param id the ID of the placeholder, must start and end with '%' + * @param refreshInterval the refresh interval for the placeholder, 0 will default to -1 (no refresh) + */ protected AbstractPlaceholder(PlaceholderManager manager, String id, int refreshInterval) { if (refreshInterval == 0) { refreshInterval = -1; } if (!(id.startsWith("%") && id.endsWith("%"))) { - throw new IllegalArgumentException("placeholder must start and end with '%'"); + throw new IllegalArgumentException("Placeholder ID must start and end with '%'"); } this.manager = manager; this.id = id; this.refreshInterval = refreshInterval; } + /** + * Returns the unique count ID of this placeholder. + * + * @return the count ID + */ @Override public int countId() { return countId; } + /** + * Returns the set of child placeholders associated with this placeholder. + * + * @return the set of child placeholders + */ @Override public Set children() { return children; } + /** + * Adds a child placeholder to this placeholder. + * + * @param placeholder the child placeholder to add + */ @Override public void addChild(Placeholder placeholder) { children.add(placeholder); } + /** + * Adds multiple child placeholders to this placeholder. + * + * @param placeholders the set of child placeholders to add + */ @Override - public void addChildren(Set placeholder) { - children.addAll(placeholder); + public void addChildren(Set placeholders) { + children.addAll(placeholders); } + /** + * Returns the refresh interval of this placeholder. + * + * @return the refresh interval + */ @Override public int refreshInterval() { return refreshInterval; } + /** + * Returns the ID of this placeholder. + * + * @return the placeholder ID + */ @Override public String id() { return id; } + /** + * Compares this placeholder with another object for equality based on the ID. + * + * @param o the object to compare + * @return true if the placeholders are equal, false otherwise + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -79,8 +125,13 @@ public abstract class AbstractPlaceholder implements Placeholder { return Objects.equals(id, that.id); } + /** + * Returns the hash code of this placeholder based on its ID. + * + * @return the hash code + */ @Override public int hashCode() { - return Objects.hashCode(id); + return Objects.hash(id); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/DummyPlaceholder.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/DummyPlaceholder.java index 7252c2b..a0912dd 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/DummyPlaceholder.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/DummyPlaceholder.java @@ -20,43 +20,87 @@ package net.momirealms.customnameplates.api.placeholder; import java.util.Objects; import java.util.Set; +/** + * A placeholder implementation used as a dummy or placeholder that does not have any child placeholders or refresh behavior. + */ public class DummyPlaceholder implements Placeholder { private final String id; private final int counterId = PlaceholderCounter.getAndIncrease(); + /** + * Constructs a DummyPlaceholder with the specified ID. + * + * @param id the ID of the placeholder + */ public DummyPlaceholder(String id) { this.id = id; } + /** + * Does nothing, as DummyPlaceholder does not support adding child placeholders. + * + * @param placeholder the child placeholder to add + */ @Override public void addChild(Placeholder placeholder) { } + /** + * Does nothing, as DummyPlaceholder does not support adding multiple child placeholders. + * + * @param placeholders the set of child placeholders to add + */ @Override - public void addChildren(Set placeholder) { + public void addChildren(Set placeholders) { } + /** + * Returns an empty set, as DummyPlaceholder does not have child placeholders. + * + * @return an empty set of child placeholders + */ @Override public Set children() { return Set.of(); } + /** + * Returns -1, indicating that this placeholder does not have a refresh interval. + * + * @return -1, meaning no refresh is needed + */ @Override public int refreshInterval() { return -1; } + /** + * Returns the ID of the DummyPlaceholder. + * + * @return the placeholder ID + */ @Override public String id() { return id; } + /** + * Returns the unique count ID of the DummyPlaceholder. + * + * @return the count ID + */ @Override public int countId() { return counterId; } + /** + * Checks if this DummyPlaceholder is equal to another object based on the ID. + * + * @param o the object to compare + * @return true if the placeholders are equal, false otherwise + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -65,8 +109,13 @@ public class DummyPlaceholder implements Placeholder { return Objects.equals(id, that.id); } + /** + * Returns the hash code of this DummyPlaceholder based on its ID. + * + * @return the hash code + */ @Override public int hashCode() { - return Objects.hashCode(id); + return Objects.hash(id); } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/Placeholder.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/Placeholder.java index e1b51e3..efb968e 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/Placeholder.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/Placeholder.java @@ -21,15 +21,45 @@ import java.util.Set; public interface Placeholder { + /** + * Adds a child placeholder to this placeholder. + * + * @param placeholder the child placeholder to add + */ void addChild(Placeholder placeholder); - void addChildren(Set placeholder); + /** + * Adds multiple child placeholders to this placeholder. + * + * @param placeholders the set of child placeholders to add + */ + void addChildren(Set placeholders); + /** + * Returns the set of child placeholders associated with this placeholder. + * + * @return the set of child placeholders + */ Set children(); + /** + * Returns the refresh interval of this placeholder. + * + * @return the refresh interval, or -1 if no refresh is required + */ int refreshInterval(); + /** + * Returns the unique ID of this placeholder. + * + * @return the placeholder ID + */ String id(); + /** + * Returns the unique count ID for this placeholder, used for identification purposes. + * + * @return the count ID + */ int countId(); -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderCounter.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderCounter.java index afdc80b..dde3b7d 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderCounter.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderCounter.java @@ -17,16 +17,27 @@ package net.momirealms.customnameplates.api.placeholder; +/** + * Utility class for managing a global counter for placeholder IDs. + */ public class PlaceholderCounter { private static int id = 1; + /** + * Returns the current ID and increments the counter by 1. + * + * @return the current ID + */ public static int getAndIncrease() { int i = id; id++; return i; } + /** + * Resets the ID counter back to 1. + */ public static void reset() { id = 1; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderManager.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderManager.java index 3a98398..746f5f8 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderManager.java @@ -25,62 +25,134 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; +/** + * Manages the registration, retrieval, and lifecycle of placeholders. Supports registering shared, player-specific, + * and relational placeholders with optional refresh intervals. + */ public interface PlaceholderManager extends Reloadable { + /** + * Refreshes all registered placeholders. + */ void refreshPlaceholders(); + /** + * Gets the refresh interval for a placeholder by its ID. + * + * @param id the ID of the placeholder + * @return the refresh interval in ticks + */ int getRefreshInterval(String id); + /** + * Registers a placeholder and returns the registered instance. + * + * @param placeholder the placeholder to register + * @param the type of the placeholder + * @return the registered placeholder instance + */ T registerPlaceholder(T placeholder); - SharedPlaceholder registerSharedPlaceholder( - String id, - int refreshInterval, - Supplier contextSupplier - ); + /** + * Registers a shared placeholder with a specific refresh interval and context supplier. + * + * @param id the placeholder ID + * @param refreshInterval the refresh interval in ticks + * @param contextSupplier the supplier providing the placeholder's content + * @return the registered shared placeholder + */ + SharedPlaceholder registerSharedPlaceholder(String id, int refreshInterval, Supplier contextSupplier); - default SharedPlaceholder registerSharedPlaceholder( - String id, - Supplier contextSupplier - ) { + /** + * Registers a shared placeholder using the default refresh interval. + * + * @param id the placeholder ID + * @param contextSupplier the supplier providing the placeholder's content + * @return the registered shared placeholder + */ + default SharedPlaceholder registerSharedPlaceholder(String id, Supplier contextSupplier) { return registerSharedPlaceholder(id, getRefreshInterval(id), contextSupplier); } - PlayerPlaceholder registerPlayerPlaceholder( - String id, - int refreshInterval, - Function function - ); + /** + * Registers a player-specific placeholder with a specific refresh interval and function. + * + * @param id the placeholder ID + * @param refreshInterval the refresh interval in ticks + * @param function the function providing the placeholder's content for a specific player + * @return the registered player placeholder + */ + PlayerPlaceholder registerPlayerPlaceholder(String id, int refreshInterval, Function function); - default PlayerPlaceholder registerPlayerPlaceholder( - String id, - Function function - ) { + /** + * Registers a player-specific placeholder using the default refresh interval. + * + * @param id the placeholder ID + * @param function the function providing the placeholder's content for a specific player + * @return the registered player placeholder + */ + default PlayerPlaceholder registerPlayerPlaceholder(String id, Function function) { return registerPlayerPlaceholder(id, getRefreshInterval(id), function); } - RelationalPlaceholder registerRelationalPlaceholder( - String id, - int refreshInterval, - BiFunction function - ); + /** + * Registers a relational placeholder with a specific refresh interval and function. + * + * @param id the placeholder ID + * @param refreshInterval the refresh interval in ticks + * @param function the function providing the placeholder's content based on two players + * @return the registered relational placeholder + */ + RelationalPlaceholder registerRelationalPlaceholder(String id, int refreshInterval, BiFunction function); - default RelationalPlaceholder registerRelationalPlaceholder( - String id, - BiFunction function - ) { + /** + * Registers a relational placeholder using the default refresh interval. + * + * @param id the placeholder ID + * @param function the function providing the placeholder's content based on two players + * @return the registered relational placeholder + */ + default RelationalPlaceholder registerRelationalPlaceholder(String id, BiFunction function) { return registerRelationalPlaceholder(id, getRefreshInterval(id), function); } + /** + * Retrieves a placeholder by its ID. + * + * @param id the ID of the placeholder + * @return the placeholder, or null if not found + */ Placeholder getPlaceholder(String id); + /** + * Retrieves a registered placeholder by its ID. + * + * @param id the ID of the placeholder + * @return the registered placeholder, or null if not found + */ Placeholder getRegisteredPlaceholder(String id); + /** + * Unregisters a placeholder by its ID. + * + * @param id the ID of the placeholder to unregister + */ void unregisterPlaceholder(String id); + /** + * Unregisters the specified placeholder. + * + * @param placeholder the placeholder to unregister + */ default void unregisterPlaceholder(Placeholder placeholder) { unregisterPlaceholder(placeholder.id()); } + /** + * Detects and returns a list of placeholder IDs present in the given raw string. + * + * @param raw the raw string containing potential placeholders + * @return a list of detected placeholder IDs + */ List detectPlaceholders(String raw); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlayerPlaceholder.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlayerPlaceholder.java index 24b4c64..c3e5c54 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlayerPlaceholder.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlayerPlaceholder.java @@ -19,7 +19,16 @@ package net.momirealms.customnameplates.api.placeholder; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Represents a player-specific placeholder, which provides dynamic content based on the player. + */ public interface PlayerPlaceholder extends Placeholder { + /** + * Requests the placeholder content for the specified player. + * + * @param player the player for whom the placeholder content is being requested + * @return the placeholder content as a string + */ String request(CNPlayer player); -} +} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/RelationalPlaceholder.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/RelationalPlaceholder.java index 83f47d9..3a1db32 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/RelationalPlaceholder.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/RelationalPlaceholder.java @@ -19,7 +19,17 @@ package net.momirealms.customnameplates.api.placeholder; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Represents a relational placeholder, which provides dynamic content based on the relationship between two players. + */ public interface RelationalPlaceholder extends Placeholder { + /** + * Requests the placeholder content based on the relationship between two players. + * + * @param p1 the first player + * @param p2 the second player + * @return the placeholder content as a string + */ String request(CNPlayer p1, CNPlayer p2); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/SharedPlaceholder.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/SharedPlaceholder.java index 99f6d84..b6df962 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/SharedPlaceholder.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/SharedPlaceholder.java @@ -17,11 +17,27 @@ package net.momirealms.customnameplates.api.placeholder; +/** + * Represents a shared placeholder, which provides content that is not specific to any individual player but can be updated globally. + */ public interface SharedPlaceholder extends Placeholder { + /** + * Requests the current placeholder content. + * + * @return the current placeholder content as a string + */ String request(); + /** + * Updates the placeholder content. This is typically called when the placeholder's value needs to be refreshed. + */ void update(); + /** + * Returns the latest value of the placeholder after the most recent update. + * + * @return the latest placeholder value as a string + */ String getLatestValue(); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/AdaptiveImageText.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/AdaptiveImageText.java index cb6d592..9631083 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/AdaptiveImageText.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/AdaptiveImageText.java @@ -22,8 +22,10 @@ import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.AdaptiveImage; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; import net.momirealms.customnameplates.api.helper.AdventureHelper; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +@ApiStatus.Internal public class AdaptiveImageText { private final String id; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/ShiftText.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/ShiftText.java index 856a7a7..bf45087 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/ShiftText.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/ShiftText.java @@ -18,7 +18,9 @@ package net.momirealms.customnameplates.api.placeholder.internal; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; +import org.jetbrains.annotations.ApiStatus; +@ApiStatus.Internal public class ShiftText { private final String font; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/StaticText.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/StaticText.java index 7cb9540..fc1f236 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/StaticText.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/StaticText.java @@ -22,7 +22,9 @@ import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.OffsetFont; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; import net.momirealms.customnameplates.api.helper.AdventureHelper; +import org.jetbrains.annotations.ApiStatus; +@ApiStatus.Internal public class StaticText { private final int width; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/VanillaHud.java b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/VanillaHud.java index 06749a6..0191c8b 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/VanillaHud.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/placeholder/internal/VanillaHud.java @@ -23,7 +23,9 @@ import net.momirealms.customnameplates.api.feature.OffsetFont; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; import net.momirealms.customnameplates.api.feature.image.Image; import net.momirealms.customnameplates.api.helper.AdventureHelper; +import org.jetbrains.annotations.ApiStatus; +@ApiStatus.Internal public class VanillaHud { private final String empty; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/EmptyRequirement.java b/api/src/main/java/net/momirealms/customnameplates/api/requirement/EmptyRequirement.java index fca8eb7..cf06b13 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/EmptyRequirement.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/requirement/EmptyRequirement.java @@ -19,29 +19,59 @@ package net.momirealms.customnameplates.api.requirement; import net.momirealms.customnameplates.api.CNPlayer; +/** + * A requirement that is always satisfied, representing an "empty" or default requirement. + */ public class EmptyRequirement implements Requirement { public static final EmptyRequirement INSTANCE = new EmptyRequirement(); + /** + * Returns the singleton instance of the EmptyRequirement. + * + * @return the singleton instance of EmptyRequirement + */ public static Requirement instance() { return INSTANCE; } + /** + * Always returns true, as this requirement is always satisfied. + * + * @param p1 the first player + * @param p2 the second player + * @return true (requirement is always satisfied) + */ @Override public boolean isSatisfied(CNPlayer p1, CNPlayer p2) { return true; } + /** + * Returns the type of this requirement. + * + * @return "empty" as the type + */ @Override public String type() { return "empty"; } + /** + * Returns -1, indicating that this requirement does not have a refresh interval. + * + * @return -1 (no refresh interval) + */ @Override public int refreshInterval() { return -1; } + /** + * Returns the hash code based on the requirement type. + * + * @return the hash code of the requirement type + */ @Override public int hashCode() { return type().hashCode(); diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/Requirement.java b/api/src/main/java/net/momirealms/customnameplates/api/requirement/Requirement.java index 5a10a06..bc9804d 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/Requirement.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/requirement/Requirement.java @@ -19,17 +19,48 @@ package net.momirealms.customnameplates.api.requirement; import net.momirealms.customnameplates.api.CNPlayer; +/** + * Represents a requirement that must be satisfied between two players. Requirements can have different types and refresh intervals. + */ public interface Requirement { + /** + * Checks if the requirement is satisfied between two players. + * + * @param p1 the first player + * @param p2 the second player + * @return true if the requirement is satisfied, false otherwise + */ boolean isSatisfied(CNPlayer p1, CNPlayer p2); + /** + * Returns the type of the requirement. + * + * @return the type as a string + */ String type(); + /** + * Returns the refresh interval of the requirement. + * + * @return the refresh interval in ticks + */ int refreshInterval(); + /** + * Returns the hash code for the requirement, ensuring uniqueness. + * + * @return the hash code + */ + @Override int hashCode(); + /** + * Returns an empty requirement that is always satisfied. + * + * @return an empty requirement + */ static Requirement empty() { return EmptyRequirement.instance(); } -} \ No newline at end of file +} diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementFactory.java b/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementFactory.java index 2066941..8e2507d 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementFactory.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementFactory.java @@ -18,9 +18,16 @@ package net.momirealms.customnameplates.api.requirement; /** - * Interface representing a factory for creating requirements. + * Interface representing a factory for creating {@link Requirement} instances. */ public interface RequirementFactory { + /** + * Processes the provided arguments and creates a new {@link Requirement} instance. + * + * @param args the arguments needed to create the requirement + * @param refreshInterval the refresh interval for the requirement + * @return a new {@link Requirement} instance + */ Requirement process(Object args, int refreshInterval); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementManager.java b/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementManager.java index 2dddc70..4dc1344 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/requirement/RequirementManager.java @@ -22,19 +22,69 @@ import net.momirealms.customnameplates.common.plugin.feature.Reloadable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * Manages the registration, parsing, and retrieval of requirements. Supports both rich and simple requirements. + */ public interface RequirementManager extends Reloadable { + /** + * Parses the requirements from the specified YAML section. + * + * @param section the YAML section to parse requirements from + * @return an array of parsed requirements + */ Requirement[] parseRequirements(Section section); + /** + * Registers a new requirement factory for one or more types. + * + * @param requirementFactory the factory responsible for creating requirements + * @param types the types of requirements that the factory can create + * @return true if the registration was successful, false otherwise + */ boolean registerRequirement(@NotNull RequirementFactory requirementFactory, @NotNull String... types); + /** + * Unregisters a requirement type. + * + * @param type the type of requirement to unregister + * @return true if the requirement was unregistered successfully, false otherwise + */ boolean unregisterRequirement(@NotNull String type); - @Nullable RequirementFactory getRequirementFactory(@NotNull String type); + /** + * Retrieves a requirement factory for a specific type. + * + * @param type the type of the requirement + * @return the corresponding requirement factory, or null if not found + */ + @Nullable + RequirementFactory getRequirementFactory(@NotNull String type); + /** + * Checks if a requirement type is registered. + * + * @param type the type of requirement to check + * @return true if the requirement type is registered, false otherwise + */ boolean hasRequirement(@NotNull String type); - @NotNull Requirement parseRichRequirement(@NotNull Section section); + /** + * Parses a rich requirement from the specified YAML section. Rich requirements can have complex structures. + * + * @param section the YAML section to parse + * @return the parsed rich requirement + */ + @NotNull + Requirement parseRichRequirement(@NotNull Section section); - @NotNull Requirement parseSimpleRequirement(@NotNull String type, @NotNull Object value); + /** + * Parses a simple requirement based on its type and value. + * + * @param type the type of the requirement + * @param value the value of the requirement + * @return the parsed simple requirement + */ + @NotNull + Requirement parseSimpleRequirement(@NotNull String type, @NotNull Object value); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/storage/DataStorageProvider.java b/api/src/main/java/net/momirealms/customnameplates/api/storage/DataStorageProvider.java index f63c274..f30bdd3 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/storage/DataStorageProvider.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/storage/DataStorageProvider.java @@ -27,7 +27,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; /** - * Interface representing a provider for data storage. + * Interface representing a provider for data storage. This provider handles the retrieval and updating of player data. */ public interface DataStorageProvider { @@ -43,11 +43,36 @@ public interface DataStorageProvider { */ void disable(); - StorageType getStorageType(); + /** + * Returns the type of storage used by this provider. + * + * @return the {@link StorageType} of the storage provider + */ + StorageType storageType(); + /** + * Retrieves the player data for a specific UUID. + * + * @param uuid the UUID of the player + * @param executor the executor to run the task asynchronously + * @return a {@link CompletableFuture} containing an {@link Optional} of {@link PlayerData} + */ CompletableFuture> getPlayerData(UUID uuid, Executor executor); + /** + * Updates the player data in the storage. + * + * @param playerData the player data to update + * @param executor the executor to run the task asynchronously + * @return a {@link CompletableFuture} indicating whether the update was successful + */ CompletableFuture updatePlayerData(PlayerData playerData, Executor executor); + /** + * Returns a set of all unique users (UUIDs) in the storage. + * + * @return a set of unique user UUIDs + */ Set getUniqueUsers(); } + diff --git a/api/src/main/java/net/momirealms/customnameplates/api/storage/StorageManager.java b/api/src/main/java/net/momirealms/customnameplates/api/storage/StorageManager.java index f86f0d2..a6ae20a 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/storage/StorageManager.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/storage/StorageManager.java @@ -25,22 +25,63 @@ import java.util.UUID; public interface StorageManager extends Reloadable { + /** + * Returns the server ID associated with this storage manager. + * + * @return the server ID as a string + */ @NotNull - String getServerID(); + String serverID(); + /** + * Returns the current data storage provider. + * + * @return the {@link DataStorageProvider} instance + */ @NotNull - DataStorageProvider getDataSource(); + DataStorageProvider dataSource(); + /** + * Checks if Redis is enabled for the storage manager. + * + * @return true if Redis is enabled, false otherwise + */ boolean isRedisEnabled(); + /** + * Converts player data into a byte array. + * + * @param data the {@link PlayerData} to convert + * @return the byte array representation of the player data + */ byte[] toBytes(@NotNull PlayerData data); + /** + * Converts player data into a JSON string. + * + * @param data the {@link PlayerData} to convert + * @return the JSON string representation of the player data + */ @NotNull String toJson(@NotNull PlayerData data); + /** + * Converts a JSON string into player data. + * + * @param uuid the UUID of the player + * @param json the JSON string containing the player data + * @return the {@link PlayerData} instance created from the JSON data + */ @NotNull PlayerData fromJson(UUID uuid, String json); + /** + * Converts a byte array into player data. + * + * @param uuid the UUID of the player + * @param data the byte array containing the player data + * @return the {@link PlayerData} instance created from the byte array + */ @NotNull PlayerData fromBytes(UUID uuid, byte[] data); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/storage/data/JsonData.java b/api/src/main/java/net/momirealms/customnameplates/api/storage/data/JsonData.java index 278bac3..12a06d3 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/storage/data/JsonData.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/storage/data/JsonData.java @@ -21,26 +21,52 @@ import com.google.gson.annotations.SerializedName; import java.util.UUID; +/** + * Represents the JSON data format for storing a player's nameplate and bubble information. + */ public class JsonData { @SerializedName("nameplate") private String nameplate; + @SerializedName("bubble") private String bubble; + /** + * Constructs a new {@link JsonData} instance. + * + * @param nameplate the nameplate value + * @param bubble the bubble value + */ public JsonData(String nameplate, String bubble) { this.nameplate = nameplate; this.bubble = bubble; } + /** + * Returns the nameplate stored in this JSON data. + * + * @return the nameplate + */ public String nameplate() { return nameplate; } + /** + * Returns the bubble stored in this JSON data. + * + * @return the bubble + */ public String bubble() { return bubble; } + /** + * Converts this JSON data back into a {@link PlayerData} instance. + * + * @param uuid the UUID of the player + * @return a {@link PlayerData} instance based on the JSON data + */ public PlayerData toPlayerData(UUID uuid) { return PlayerData.builder() .uuid(uuid) @@ -49,3 +75,4 @@ public class JsonData { .build(); } } + diff --git a/api/src/main/java/net/momirealms/customnameplates/api/storage/data/PlayerData.java b/api/src/main/java/net/momirealms/customnameplates/api/storage/data/PlayerData.java index 60592eb..889a5eb 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/storage/data/PlayerData.java +++ b/api/src/main/java/net/momirealms/customnameplates/api/storage/data/PlayerData.java @@ -19,40 +19,101 @@ package net.momirealms.customnameplates.api.storage.data; import java.util.UUID; +/** + * Represents player-specific data, including the player's nameplate, bubble, and UUID. + */ public interface PlayerData { String DEFAULT_NAMEPLATE = "none"; - String DEFAULT_BUBBLE = "none"; + String DEFAULT_BUBBLE = "none"; + /** + * Returns the nameplate associated with the player. + * + * @return the player's nameplate + */ String nameplate(); + /** + * Returns the bubble associated with the player. + * + * @return the player's bubble + */ String bubble(); + /** + * Returns the UUID of the player. + * + * @return the player's UUID + */ UUID uuid(); + /** + * Returns a builder for constructing {@link PlayerData} instances. + * + * @return a {@link PlayerData.Builder} instance + */ static Builder builder() { return new PlayerDataImpl.BuilderImpl(); } + /** + * Returns an empty {@link PlayerData} instance with default values for the given UUID. + * + * @param uuid the UUID of the player + * @return an empty {@link PlayerData} instance + */ static PlayerData empty(UUID uuid) { - return builder().uuid(uuid) + return builder() + .uuid(uuid) .nameplate(DEFAULT_NAMEPLATE) .bubble(DEFAULT_BUBBLE) .build(); } + /** + * Builder interface for constructing {@link PlayerData} instances. + */ interface Builder { + /** + * Sets the nameplate for the {@link PlayerData}. + * + * @param nameplate the nameplate value + * @return the builder instance + */ Builder nameplate(String nameplate); + /** + * Sets the bubble for the {@link PlayerData}. + * + * @param bubble the bubble value + * @return the builder instance + */ Builder bubble(String bubble); + /** + * Sets the UUID for the {@link PlayerData}. + * + * @param uuid the UUID value + * @return the builder instance + */ Builder uuid(UUID uuid); + /** + * Builds and returns the {@link PlayerData} instance. + * + * @return the constructed {@link PlayerData} instance + */ PlayerData build(); } - default JsonData toGsonData() { + /** + * Converts the player data into a {@link JsonData} object for serialization. + * + * @return a {@link JsonData} object containing the nameplate and bubble data + */ + default JsonData toJsonData() { return new JsonData(nameplate(), bubble()); } } diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 4e48cbe..5b98d93 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -22,6 +22,12 @@ dependencies { compileOnly("org.mongodb:mongodb-driver-sync:${rootProject.properties["mongodb_driver_version"]}") compileOnly("com.zaxxer:HikariCP:${rootProject.properties["hikari_version"]}") compileOnly("redis.clients:jedis:${rootProject.properties["jedis_version"]}") + // Cache + compileOnly("com.github.ben-manes.caffeine:caffeine:${rootProject.properties["caffeine_version"]}") + // COMMONS IO + compileOnly("commons-io:commons-io:${rootProject.properties["commons_io_version"]}") + // FOP + compileOnly("org.apache.pdfbox:fontbox:${rootProject.properties["fontbox_version"]}") } tasks { diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/actionbar/ActionBarManagerImpl.java similarity index 91% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/actionbar/ActionBarManagerImpl.java index 5a5a632..094f965 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/actionbar/ActionBarManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.actionbar; +package net.momirealms.customnameplates.backend.feature.actionbar; import dev.dejvokep.boostedyaml.YamlDocument; import dev.dejvokep.boostedyaml.block.implementation.Section; @@ -24,8 +24,11 @@ import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.feature.JoinQuitListener; +import net.momirealms.customnameplates.api.feature.actionbar.ActionBarConfig; +import net.momirealms.customnameplates.api.feature.actionbar.ActionBarManager; import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.util.ConfigUtils; +import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.LinkedHashMap; @@ -85,12 +88,12 @@ public class ActionBarManagerImpl implements ActionBarManager, JoinQuitListener } @Override - public ActionBarConfig getConfig(String name) { + public ActionBarConfig configById(String name) { return configs.get(name); } @Override - public ActionBarConfig[] allConfigs() { + public ActionBarConfig[] actionBarConfigs() { return configArray; } @@ -102,12 +105,12 @@ public class ActionBarManagerImpl implements ActionBarManager, JoinQuitListener } @Override - public String getExternalActionBar(CNPlayer player) { + public @Nullable String getExternalActionBar(CNPlayer player) { ActionBarSender sender = senders.get(player.uuid()); if (sender != null) { return sender.externalActionBar(); } - return ""; + return null; } @Override diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarSender.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/actionbar/ActionBarSender.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarSender.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/actionbar/ActionBarSender.java index d51b167..33a7a99 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/actionbar/ActionBarSender.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/actionbar/ActionBarSender.java @@ -15,13 +15,15 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.actionbar; +package net.momirealms.customnameplates.backend.feature.actionbar; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.feature.DynamicText; import net.momirealms.customnameplates.api.feature.Feature; +import net.momirealms.customnameplates.api.feature.actionbar.ActionBarConfig; +import net.momirealms.customnameplates.api.feature.actionbar.ActionBarManager; import net.momirealms.customnameplates.api.helper.AdventureHelper; import net.momirealms.customnameplates.api.placeholder.Placeholder; import org.jetbrains.annotations.NotNull; @@ -77,7 +79,7 @@ public class ActionBarSender implements Feature { } public void onConditionTimerCheck() { - ActionBarConfig[] configs = manager.allConfigs(); + ActionBarConfig[] configs = manager.actionBarConfigs(); outer: { for (ActionBarConfig config : configs) { if (owner.isMet(config.requirements())) { @@ -169,7 +171,7 @@ public class ActionBarSender implements Feature { @Override public Set allPlaceholders() { HashSet placeholders = new HashSet<>(); - for (ActionBarConfig config : manager.allConfigs()) { + for (ActionBarConfig config : manager.actionBarConfigs()) { for (CarouselText text : config.carouselTexts()) { placeholders.addAll(text.preParsedDynamicText().placeholders()); } @@ -194,7 +196,7 @@ public class ActionBarSender implements Feature { @Nullable public String externalActionBar() { if (System.currentTimeMillis() > externalExpireTime) { - externalActionBar = ""; + externalActionBar = null; } return externalActionBar; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/AdvanceManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/advance/AdvanceManagerImpl.java similarity index 98% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/advance/AdvanceManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/advance/AdvanceManagerImpl.java index f6fc2a7..835676d 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/AdvanceManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/advance/AdvanceManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.advance; +package net.momirealms.customnameplates.backend.feature.advance; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; @@ -37,6 +37,9 @@ import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; import net.momirealms.customnameplates.api.feature.OffsetFont; +import net.momirealms.customnameplates.api.feature.advance.AdvanceManager; +import net.momirealms.customnameplates.api.feature.advance.CharacterFontAdvanceData; +import net.momirealms.customnameplates.api.feature.advance.ConfigurableFontAdvanceData; import net.momirealms.customnameplates.api.feature.background.Background; import net.momirealms.customnameplates.api.feature.bubble.Bubble; import net.momirealms.customnameplates.api.feature.image.Image; @@ -895,18 +898,18 @@ public class AdvanceManagerImpl implements AdvanceManager { private void loadInternalFont() { ArrayList chars = new ArrayList<>(); - for (Nameplate nameplate : plugin.getNameplateManager().getNameplates()) { + for (Nameplate nameplate : plugin.getNameplateManager().nameplates()) { chars.add(nameplate.left()); chars.add(nameplate.middle()); chars.add(nameplate.right()); } - for (Bubble bubble : plugin.getBubbleManager().getBubbles()) { + for (Bubble bubble : plugin.getBubbleManager().bubbles()) { chars.add(bubble.left()); chars.add(bubble.middle()); chars.add(bubble.tail()); chars.add(bubble.right()); } - for (Image image : plugin.getImageManager().getImages()) { + for (Image image : plugin.getImageManager().images()) { chars.add(image.character()); } for (Background background : plugin.getBackgroundManager().getBackgrounds()) { @@ -943,14 +946,10 @@ public class AdvanceManagerImpl implements AdvanceManager { @Override public void disable() { this.unload(); - for (CharacterFontAdvanceData data : charFontWidthDataMap.values()) { - data.close(); - } this.charFontWidthDataMap.clear(); } - @Override - public void loadTemplates() { + private void loadTemplates() { YamlDocument mainConfig = ConfigManager.getMainConfig(); Section section = mainConfig.getSection("other-settings.font-templates"); if (section != null) { @@ -1029,12 +1028,12 @@ public class AdvanceManagerImpl implements AdvanceManager { @Override @Nullable - public ConfigurableFontAdvanceData getCustomFontData(String id) { + public ConfigurableFontAdvanceData customFontDataById(String id) { return configFontWidthDataMap.get(id); } @Override - public CharacterFontAdvanceData getCharacterFontData(String id) { + public CharacterFontAdvanceData templateFontDataById(String id) { return charFontWidthDataMap.get(id); } @@ -1047,7 +1046,7 @@ public class AdvanceManagerImpl implements AdvanceManager { @Override public float getCharAdvance(char[] chars, Key font, boolean bold) { int codePoint = chars.length == 2 ? Character.toCodePoint(chars[0], chars[1]) : chars[0]; - ConfigurableFontAdvanceData data = getCustomFontData(font.asString()); + ConfigurableFontAdvanceData data = customFontDataById(font.asString()); if (data == null) { plugin.getPluginLogger().warn("Detected unknown font: " + font + ". Please register it in advance-data.yml"); return 0f; @@ -1115,7 +1114,7 @@ public class AdvanceManagerImpl implements AdvanceManager { List> iterableTexts = miniMessageToIterable(text); float totalAdvance = 0; for (Tuple element : iterableTexts) { - ConfigurableFontAdvanceData data = getCustomFontData(element.mid().asString()); + ConfigurableFontAdvanceData data = customFontDataById(element.mid().asString()); if (data == null) { plugin.getPluginLogger().warn("Detected unknown font: " + element.mid() + ". Please register it in advance-data.yml"); continue; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/SizeOverrides.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/advance/SizeOverrides.java similarity index 92% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/advance/SizeOverrides.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/advance/SizeOverrides.java index 3eee277..7035538 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/advance/SizeOverrides.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/advance/SizeOverrides.java @@ -15,8 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.advance; +package net.momirealms.customnameplates.backend.feature.advance; public record SizeOverrides(int startCodePoint, int endCodePoint, int left, int right) { - } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/background/BackgroundManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/background/BackgroundManagerImpl.java similarity index 95% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/background/BackgroundManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/background/BackgroundManagerImpl.java index e9e8be2..620bba0 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/background/BackgroundManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/background/BackgroundManagerImpl.java @@ -15,11 +15,13 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.background; +package net.momirealms.customnameplates.backend.feature.background; import dev.dejvokep.boostedyaml.YamlDocument; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; +import net.momirealms.customnameplates.api.feature.background.Background; +import net.momirealms.customnameplates.api.feature.background.BackgroundManager; import net.momirealms.customnameplates.api.util.ConfigUtils; import org.jetbrains.annotations.Nullable; @@ -47,7 +49,7 @@ public class BackgroundManagerImpl implements BackgroundManager { @Nullable @Override - public Background getBackground(String id) { + public Background backgroundById(String id) { return this.backgrounds.get(id); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarDisplayController.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarDisplayController.java similarity index 90% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarDisplayController.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarDisplayController.java index 132c283..1a9a606 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarDisplayController.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarDisplayController.java @@ -15,9 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bossbar; +package net.momirealms.customnameplates.backend.feature.bossbar; import net.momirealms.customnameplates.api.CNPlayer; +import net.momirealms.customnameplates.api.feature.bossbar.BossBarConfig; +import net.momirealms.customnameplates.api.feature.bossbar.BossBarManager; import java.util.ArrayList; import java.util.List; @@ -32,7 +34,7 @@ public class BossBarDisplayController { this.owner = owner; this.manager = manager; List senderList = new ArrayList<>(); - for (BossBarConfig config : manager.allConfigs()) { + for (BossBarConfig config : manager.bossBarConfigs()) { BossBarSender sender = new BossBarSender(owner, config); senderList.add(sender); this.owner.addFeature(sender); diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarManagerImpl.java similarity index 93% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarManagerImpl.java index 538943c..e2afb7b 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bossbar; +package net.momirealms.customnameplates.backend.feature.bossbar; import dev.dejvokep.boostedyaml.YamlDocument; import dev.dejvokep.boostedyaml.block.implementation.Section; @@ -24,6 +24,9 @@ import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.feature.JoinQuitListener; +import net.momirealms.customnameplates.api.feature.bossbar.BossBar; +import net.momirealms.customnameplates.api.feature.bossbar.BossBarConfig; +import net.momirealms.customnameplates.api.feature.bossbar.BossBarManager; import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.util.ConfigUtils; @@ -100,12 +103,12 @@ public class BossBarManagerImpl implements BossBarManager, JoinQuitListener { } @Override - public BossBarConfig getConfig(String name) { + public BossBarConfig configById(String name) { return configs.get(name); } @Override - public BossBarConfig[] allConfigs() { + public BossBarConfig[] bossBarConfigs() { return configArray; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarSender.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarSender.java similarity index 96% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarSender.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarSender.java index 02cc98f..6c004c8 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bossbar/BossBarSender.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bossbar/BossBarSender.java @@ -15,13 +15,15 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bossbar; +package net.momirealms.customnameplates.backend.feature.bossbar; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.feature.DynamicText; import net.momirealms.customnameplates.api.feature.Feature; +import net.momirealms.customnameplates.api.feature.bossbar.BossBar; +import net.momirealms.customnameplates.api.feature.bossbar.BossBarConfig; import net.momirealms.customnameplates.api.helper.AdventureHelper; import net.momirealms.customnameplates.api.placeholder.Placeholder; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bubble/BubbleManagerImpl.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/bubble/BubbleManagerImpl.java index 7d84dec..e4c69d1 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bubble/BubbleManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bubble; +package net.momirealms.customnameplates.backend.feature.bubble; import dev.dejvokep.boostedyaml.YamlDocument; import dev.dejvokep.boostedyaml.block.implementation.Section; @@ -24,6 +24,10 @@ import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.ChatListener; import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; +import net.momirealms.customnameplates.api.feature.bubble.Bubble; +import net.momirealms.customnameplates.api.feature.bubble.BubbleConfig; +import net.momirealms.customnameplates.api.feature.bubble.BubbleManager; +import net.momirealms.customnameplates.api.feature.bubble.ChannelMode; import net.momirealms.customnameplates.api.feature.tag.TagRenderer; import net.momirealms.customnameplates.api.helper.AdventureHelper; import net.momirealms.customnameplates.api.requirement.Requirement; @@ -41,7 +45,6 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener { private Requirement[] sendBubbleRequirements; private Requirement[] viewBubbleRequirements; private String defaultBubbleId; - private String omittedText; private double yOffset; private int stayDuration; private int appearDuration; @@ -70,22 +73,22 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener { @Nullable @Override - public Bubble getBubble(String id) { + public Bubble bubbleById(String id) { return this.bubbles.get(id); } @Override - public @Nullable BubbleConfig getBubbleConfig(String id) { + public @Nullable BubbleConfig bubbleConfigById(String id) { return this.bubbleConfigs.get(id); } @Override - public Collection getBubbles() { + public Collection bubbles() { return new HashSet<>(bubbles.values()); } @Override - public Collection getBubbleConfigs() { + public Collection bubbleConfigs() { return new HashSet<>(bubbleConfigs.values()); } @@ -128,11 +131,6 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener { return viewBubbleRequirements; } - @Override - public String omittedText() { - return omittedText; - } - @Override public double verticalOffset() { return yOffset; @@ -169,7 +167,6 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener { sendBubbleRequirements = plugin.getRequirementManager().parseRequirements(document.getSection("sender-requirements")); viewBubbleRequirements = plugin.getRequirementManager().parseRequirements(document.getSection("viewer-requirements")); defaultBubbleId = document.getString("default-bubble", "chat"); - omittedText = document.getString("omitted-text", "..."); yOffset = document.getDouble("y-offset", 0.2); stayDuration = document.getInt("stay-duration", 160); appearDuration = document.getInt("appear-duration", 20); @@ -185,7 +182,7 @@ public class BubbleManagerImpl implements BubbleManager, ChatListener { int maxLines = inner.getInt("max-lines", 1); Bubble[] bubbleArray = new Bubble[maxLines]; for (int i = 0; i < maxLines; i++) { - bubbleArray[i] = getBubble(inner.getString("lines." + (i+1))); + bubbleArray[i] = bubbleById(inner.getString("lines." + (i+1))); } this.bubbleConfigs.put(key, BubbleConfig.builder() .id(key) diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleTag.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bubble/BubbleTag.java similarity index 97% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleTag.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/bubble/BubbleTag.java index 00083ca..c5a617c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/BubbleTag.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/bubble/BubbleTag.java @@ -15,10 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bubble; +package net.momirealms.customnameplates.backend.feature.bubble; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; +import net.momirealms.customnameplates.api.feature.bubble.BubbleConfig; +import net.momirealms.customnameplates.api.feature.bubble.BubbleManager; import net.momirealms.customnameplates.api.feature.tag.AbstractTag; import net.momirealms.customnameplates.api.feature.tag.Tag; import net.momirealms.customnameplates.api.feature.tag.TagRenderer; @@ -163,7 +165,7 @@ public class BubbleTag extends AbstractTag { } @Override - public void updateScale(CNPlayer viewer, double scale) { + public void onPlayerScaleUpdate(CNPlayer viewer, double scale) { Consumer> modifier1 = CustomNameplates.getInstance().getPlatform().createScaleModifier(scale(viewer).multiply(scale)); Vector3 translation = translation(viewer); Consumer> modifier2 = CustomNameplates.getInstance().getPlatform().createTranslationModifier(translation.multiply(scale).add(0.01,0,0.01)); diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/AbstractChatManager.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/chat/AbstractChatManager.java similarity index 90% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/AbstractChatManager.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/chat/AbstractChatManager.java index 1dde029..938cc92 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/bubble/chat/AbstractChatManager.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/chat/AbstractChatManager.java @@ -15,12 +15,15 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.bubble.chat; +package net.momirealms.customnameplates.backend.feature.chat; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.ChatListener; -import net.momirealms.customnameplates.api.feature.bubble.emoji.EmojiProvider; +import net.momirealms.customnameplates.api.feature.chat.AbstractChatMessageProvider; +import net.momirealms.customnameplates.api.feature.chat.ChatManager; +import net.momirealms.customnameplates.api.feature.chat.ChatMessageProvider; +import net.momirealms.customnameplates.api.feature.chat.emoji.EmojiProvider; import net.momirealms.customnameplates.api.helper.AdventureHelper; import java.util.ArrayList; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/image/ImageManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/image/ImageManagerImpl.java similarity index 91% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/image/ImageManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/image/ImageManagerImpl.java index 62904e8..9b4a033 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/image/ImageManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/image/ImageManagerImpl.java @@ -15,11 +15,13 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.image; +package net.momirealms.customnameplates.backend.feature.image; import dev.dejvokep.boostedyaml.YamlDocument; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; +import net.momirealms.customnameplates.api.feature.image.Image; +import net.momirealms.customnameplates.api.feature.image.ImageManager; import net.momirealms.customnameplates.api.util.ConfigUtils; import org.jetbrains.annotations.Nullable; @@ -49,12 +51,12 @@ public class ImageManagerImpl implements ImageManager { } @Override - public @Nullable Image getImage(String id) { + public @Nullable Image imageById(String id) { return images.get(id); } @Override - public Collection getImages() { + public Collection images() { return new HashSet<>(images.values()); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/NameplateManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/nameplate/NameplateManagerImpl.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/NameplateManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/nameplate/NameplateManagerImpl.java index ef7732c..47f81cc 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/nameplate/NameplateManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/nameplate/NameplateManagerImpl.java @@ -15,13 +15,14 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.nameplate; +package net.momirealms.customnameplates.backend.feature.nameplate; import dev.dejvokep.boostedyaml.YamlDocument; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.ConfiguredCharacter; -import net.momirealms.customnameplates.api.feature.DynamicText; +import net.momirealms.customnameplates.api.feature.nameplate.Nameplate; +import net.momirealms.customnameplates.api.feature.nameplate.NameplateManager; import net.momirealms.customnameplates.api.util.ConfigUtils; import org.jetbrains.annotations.Nullable; @@ -32,7 +33,6 @@ public class NameplateManagerImpl implements NameplateManager { private final CustomNameplates plugin; private final Map nameplates = new HashMap<>(); - private final Map tags = new HashMap<>(); private String defaultNameplateId; private String nameTag; @@ -53,12 +53,12 @@ public class NameplateManagerImpl implements NameplateManager { @Nullable @Override - public Nameplate getNameplate(String id) { + public Nameplate nameplateById(String id) { return this.nameplates.get(id); } @Override - public Collection getNameplates() { + public Collection nameplates() { return new HashSet<>(nameplates.values()); } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/ResourcePackManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/pack/ResourcePackManagerImpl.java similarity index 99% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/pack/ResourcePackManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/pack/ResourcePackManagerImpl.java index 562bdab..f428136 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/pack/ResourcePackManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/pack/ResourcePackManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.pack; +package net.momirealms.customnameplates.backend.feature.pack; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -31,6 +31,7 @@ import net.momirealms.customnameplates.api.feature.background.Background; import net.momirealms.customnameplates.api.feature.bubble.Bubble; import net.momirealms.customnameplates.api.feature.image.Image; import net.momirealms.customnameplates.api.feature.nameplate.Nameplate; +import net.momirealms.customnameplates.api.feature.pack.ResourcePackManager; import net.momirealms.customnameplates.api.helper.VersionHelper; import net.momirealms.customnameplates.api.util.CharacterUtils; import org.apache.commons.io.FileUtils; @@ -139,7 +140,7 @@ public class ResourcePackManagerImpl implements ResourcePackManager { if (split.length == 2) { properties.put("shift_y", Integer.parseInt(split[1])); } - CharacterFontAdvanceData data = plugin.getAdvanceManager().getCharacterFontData(split[0]); + CharacterFontAdvanceData data = plugin.getAdvanceManager().templateFontDataById(split[0]); if (data == null) { plugin.getPluginLogger().warn("Font template [" + split[0] + "] not found"); continue; @@ -220,7 +221,7 @@ public class ResourcePackManagerImpl implements ResourcePackManager { private List getBubbles(File texturesFolder) { ArrayList list = new ArrayList<>(); if (!ConfigManager.bubbleModule()) return list; - for (Bubble bubble : plugin.getBubbleManager().getBubbles()) { + for (Bubble bubble : plugin.getBubbleManager().bubbles()) { for (ConfiguredCharacter configuredChar : new ConfiguredCharacter[]{bubble.left(), bubble.middle(), bubble.right(), bubble.tail()}) { JsonObject jo = new JsonObject(); jo.add("type", new JsonPrimitive("bitmap")); @@ -282,7 +283,7 @@ public class ResourcePackManagerImpl implements ResourcePackManager { private List getImages(File texturesFolder) { ArrayList list = new ArrayList<>(); if (!ConfigManager.imageModule()) return list; - for (Image image : plugin.getImageManager().getImages()) { + for (Image image : plugin.getImageManager().images()) { ConfiguredCharacter character = image.character(); JsonObject jo = new JsonObject(); jo.add("type", new JsonPrimitive("bitmap")); @@ -309,7 +310,7 @@ public class ResourcePackManagerImpl implements ResourcePackManager { private List getNameplates(File texturesFolder) { ArrayList list = new ArrayList<>(); if (!ConfigManager.nameplateModule()) return list; - for (Nameplate nameplate : plugin.getNameplateManager().getNameplates()) { + for (Nameplate nameplate : plugin.getNameplateManager().nameplates()) { for (ConfiguredCharacter configuredChar : new ConfiguredCharacter[]{nameplate.left(), nameplate.middle(), nameplate.right()}) { JsonObject jo = new JsonObject(); jo.add("type", new JsonPrimitive("bitmap")); diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTag.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/NameTag.java similarity index 96% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTag.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/NameTag.java index 32688db..090ec6c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/NameTag.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/NameTag.java @@ -15,13 +15,16 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.tag; +package net.momirealms.customnameplates.backend.feature.tag; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.feature.DynamicText; import net.momirealms.customnameplates.api.feature.RelationalFeature; +import net.momirealms.customnameplates.api.feature.tag.AbstractTag; +import net.momirealms.customnameplates.api.feature.tag.NameTagConfig; +import net.momirealms.customnameplates.api.feature.tag.TagRenderer; import net.momirealms.customnameplates.api.helper.AdventureHelper; import net.momirealms.customnameplates.api.network.Tracker; import net.momirealms.customnameplates.api.placeholder.Placeholder; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/TagRendererImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/TagRendererImpl.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/tag/TagRendererImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/TagRendererImpl.java index d24c28a..bb905bd 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/TagRendererImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/TagRendererImpl.java @@ -15,11 +15,15 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.tag; +package net.momirealms.customnameplates.backend.feature.tag; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.Feature; +import net.momirealms.customnameplates.api.feature.tag.NameTagConfig; +import net.momirealms.customnameplates.api.feature.tag.Tag; +import net.momirealms.customnameplates.api.feature.tag.TagRenderer; +import net.momirealms.customnameplates.api.feature.tag.UnlimitedTagManager; import net.momirealms.customnameplates.api.network.Tracker; import java.util.ArrayList; @@ -39,7 +43,7 @@ public class TagRendererImpl implements TagRenderer { this.owner = owner; this.manager = manager; List senderList = new ArrayList<>(); - for (NameTagConfig config : manager.allConfigs()) { + for (NameTagConfig config : manager.nameTagConfigs()) { NameTag sender = new NameTag(owner, config, this); senderList.add(sender); this.owner.addFeature(sender); @@ -268,11 +272,7 @@ public class TagRendererImpl implements TagRenderer { if (display.affectedByCrouching()) { if (display.isShown()) { if (display.isShown(another)) { - if (isCrouching) { - display.updateOpacity(another, (byte) 64); - } else { - display.updateOpacity(another, display.opacity()); - } + display.onPlayerCrouching(another, isCrouching); } } } @@ -289,7 +289,7 @@ public class TagRendererImpl implements TagRenderer { if (display.affectedByScaling()) { if (display.isShown()) { if (display.isShown(another)) { - display.updateScale(another, scale); + display.onPlayerScaleUpdate(another, scale); } } } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/UnlimitedTagManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java similarity index 95% rename from api/src/main/java/net/momirealms/customnameplates/api/feature/tag/UnlimitedTagManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java index e88974a..b4a7e4a 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/feature/tag/UnlimitedTagManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/feature/tag/UnlimitedTagManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.feature.tag; +package net.momirealms.customnameplates.backend.feature.tag; import dev.dejvokep.boostedyaml.YamlDocument; import dev.dejvokep.boostedyaml.block.implementation.Section; @@ -25,6 +25,9 @@ import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.CarouselText; import net.momirealms.customnameplates.api.feature.JoinQuitListener; +import net.momirealms.customnameplates.api.feature.tag.NameTagConfig; +import net.momirealms.customnameplates.api.feature.tag.TagRenderer; +import net.momirealms.customnameplates.api.feature.tag.UnlimitedTagManager; import net.momirealms.customnameplates.api.helper.VersionHelper; import net.momirealms.customnameplates.api.network.Tracker; import net.momirealms.customnameplates.api.requirement.Requirement; @@ -130,12 +133,12 @@ public class UnlimitedTagManagerImpl implements UnlimitedTagManager, JoinQuitLis } @Override - public NameTagConfig getConfig(String name) { + public NameTagConfig configById(String name) { return configs.get(name); } @Override - public NameTagConfig[] allConfigs() { + public NameTagConfig[] nameTagConfigs() { return configArray; } diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/PlaceholderManagerImpl.java similarity index 95% rename from api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderManagerImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/PlaceholderManagerImpl.java index d1c0155..24a627b 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlaceholderManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/PlaceholderManagerImpl.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.placeholder; +package net.momirealms.customnameplates.backend.placeholder; import dev.dejvokep.boostedyaml.YamlDocument; import dev.dejvokep.boostedyaml.block.implementation.Section; @@ -30,6 +30,7 @@ import net.momirealms.customnameplates.api.feature.bubble.BubbleConfig; import net.momirealms.customnameplates.api.feature.image.Image; import net.momirealms.customnameplates.api.feature.nameplate.Nameplate; import net.momirealms.customnameplates.api.helper.AdventureHelper; +import net.momirealms.customnameplates.api.placeholder.*; import net.momirealms.customnameplates.api.placeholder.internal.*; import net.momirealms.customnameplates.api.requirement.Requirement; import net.momirealms.customnameplates.api.util.Vector3; @@ -110,7 +111,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { Placeholder placeholder1 = this.registerPlayerPlaceholder("%np_tag-image%", (player -> { String equippedNameplate = player.equippedNameplate(); if (equippedNameplate.equals("none")) equippedNameplate = plugin.getNameplateManager().defaultNameplateId(); - Nameplate nameplate = plugin.getNameplateManager().getNameplate(equippedNameplate); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(equippedNameplate); if (nameplate == null) return ""; String tag = nameTag.fastCreate(player).render(player); float advance = plugin.getAdvanceManager().getLineAdvance(tag); @@ -119,7 +120,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { Placeholder placeholder2 = this.registerRelationalPlaceholder("%rel_np_tag-image%", (p1, p2) -> { String equippedNameplate = p1.equippedNameplate(); if (equippedNameplate.equals("none")) equippedNameplate = plugin.getNameplateManager().defaultNameplateId(); - Nameplate nameplate = plugin.getNameplateManager().getNameplate(equippedNameplate); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(equippedNameplate); if (nameplate == null) return ""; String tag = nameTag.fastCreate(p1).render(p2); float advance = plugin.getAdvanceManager().getLineAdvance(tag); @@ -130,7 +131,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { Placeholder placeholder5 = this.registerPlayerPlaceholder("%np_tag%", (player -> { String equippedNameplate = player.equippedNameplate(); if (equippedNameplate.equals("none")) equippedNameplate = plugin.getNameplateManager().defaultNameplateId(); - Nameplate nameplate = plugin.getNameplateManager().getNameplate(equippedNameplate); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(equippedNameplate); String tag = nameTag.fastCreate(player).render(player); if (nameplate == null) return tag; float advance = plugin.getAdvanceManager().getLineAdvance(tag); @@ -139,7 +140,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { })); Placeholder placeholder6 = this.registerRelationalPlaceholder("%rel_np_tag%", (p1, p2) -> { String equippedNameplate = p1.equippedNameplate(); - Nameplate nameplate = plugin.getNameplateManager().getNameplate(equippedNameplate); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(equippedNameplate); if (nameplate == null) return p1.name(); String tag = nameTag.fastCreate(p1).render(p2); float advance = plugin.getAdvanceManager().getLineAdvance(tag); @@ -169,11 +170,11 @@ public class PlaceholderManagerImpl implements PlaceholderManager { this.registerPlayerPlaceholder("%np_equipped_nameplate%", CNPlayer::equippedNameplate); this.registerPlayerPlaceholder("%np_equipped_bubble%", CNPlayer::equippedBubble); this.registerPlayerPlaceholder("%np_equipped_nameplate-name%", (player) -> { - Nameplate nameplate = plugin.getNameplateManager().getNameplate(player.equippedNameplate()); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(player.equippedNameplate()); return Optional.ofNullable(nameplate).map(Nameplate::displayName).orElse(""); }); this.registerPlayerPlaceholder("%np_equipped_bubble-name%", (player) -> { - BubbleConfig bubble = plugin.getBubbleManager().getBubbleConfig(player.equippedBubble()); + BubbleConfig bubble = plugin.getBubbleManager().bubbleConfigById(player.equippedBubble()); return Optional.ofNullable(bubble).map(BubbleConfig::displayName).orElse(""); }); this.registerSharedPlaceholder("%shared_np_is-latest%", () -> String.valueOf(plugin.isUpToDate())); @@ -188,8 +189,8 @@ public class PlaceholderManagerImpl implements PlaceholderManager { if (minutes < 10) return hours + ":0" + minutes + ap; else return hours + ":" + minutes + ap; }); - this.registerPlayerPlaceholder("%np_actionbar%", (player) -> plugin.getActionBarManager().getExternalActionBar(player)); - for (Image image : plugin.getImageManager().getImages()) { + this.registerPlayerPlaceholder("%np_actionbar%", (player) -> Optional.ofNullable(plugin.getActionBarManager().getExternalActionBar(player)).orElse("")); + for (Image image : plugin.getImageManager().images()) { this.registerSharedPlaceholder("%shared_np_image_" + image.id() + "%", () -> AdventureHelper.surroundWithNameplatesFont(String.valueOf(image.character().character()))); this.registerPlayerPlaceholder("%np_image_" + image.id() + "%", @@ -278,9 +279,9 @@ public class PlaceholderManagerImpl implements PlaceholderManager { String id = entry.getKey(); if (entry.getValue() instanceof Section inner) { boolean reverse = inner.getBoolean("reverse", true); - Image empty = requireNonNull(plugin.getImageManager().getImage(inner.getString("images.empty")), "image.empty should not be null"); - Image half = requireNonNull(plugin.getImageManager().getImage(inner.getString("images.half")), "image.half should not be null"); - Image full = requireNonNull(plugin.getImageManager().getImage(inner.getString("images.full")), "image.full should not be null"); + Image empty = requireNonNull(plugin.getImageManager().imageById(inner.getString("images.empty")), "image.empty should not be null"); + Image half = requireNonNull(plugin.getImageManager().imageById(inner.getString("images.half")), "image.half should not be null"); + Image full = requireNonNull(plugin.getImageManager().imageById(inner.getString("images.full")), "image.full should not be null"); String currentValue = section.getString("placeholder.value", "1"); String maxValue = section.getString("placeholder.max-value", currentValue); boolean removeShadow = section.getBoolean("remove-shadow", false); @@ -345,7 +346,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { String id = entry.getKey(); if (entry.getValue() instanceof Section inner) { String bbID = inner.getString("bubble"); - Bubble bubble = plugin.getBubbleManager().getBubble(bbID); + Bubble bubble = plugin.getBubbleManager().bubbleById(bbID); if (bubble != null) { AdaptiveImageText adaptiveImageText = AdaptiveImageText.create( id, inner.getString("text"), bubble, inner.getBoolean("remove-shadow"), @@ -383,7 +384,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { String id = entry.getKey(); if (entry.getValue() instanceof Section inner) { String npID = inner.getString("nameplate"); - Nameplate nameplate = plugin.getNameplateManager().getNameplate(npID); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(npID); if (nameplate != null) { AdaptiveImageText adaptiveImageText = AdaptiveImageText.create( id, inner.getString("text"), nameplate, inner.getBoolean("remove-shadow"), @@ -421,7 +422,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { String id = entry.getKey(); if (entry.getValue() instanceof Section inner) { String bgID = inner.getString("background"); - Background background = plugin.getBackgroundManager().getBackground(bgID); + Background background = plugin.getBackgroundManager().backgroundById(bgID); if (background != null) { AdaptiveImageText adaptiveImageText = AdaptiveImageText.create( id, inner.getString("text"), background, inner.getBoolean("remove-shadow"), @@ -512,7 +513,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { if (!player.isOnline()) continue; Set featuresToNotifyUpdates = new HashSet<>(); Map> relationalFeaturesToNotifyUpdates = new HashMap<>(); - List placeholdersToUpdate = player.getRefreshValueTask(); + List placeholdersToUpdate = player.activePlaceholdersToRefresh(); List delayedPlaceholdersToUpdate = new ArrayList<>(); for (Placeholder placeholder : placeholdersToUpdate) { if (placeholder instanceof PlayerPlaceholder playerPlaceholder) { @@ -520,11 +521,11 @@ public class PlaceholderManagerImpl implements PlaceholderManager { if (previous == null) { String value = playerPlaceholder.request(player); player.setValue(placeholder, new TickStampData<>(value, MainTask.getTicks(), true)); - featuresToNotifyUpdates.addAll(player.getUsedFeatures(placeholder)); + featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder)); } else { if (previous.ticks() == MainTask.getTicks()) { if (previous.hasValueChanged()) { - featuresToNotifyUpdates.addAll(player.getUsedFeatures(placeholder)); + featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder)); } continue; } @@ -532,7 +533,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { if (!previous.data().equals(value)) { previous.data(value); previous.updateTicks(true); - featuresToNotifyUpdates.addAll(player.getUsedFeatures(placeholder)); + featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder)); } else { previous.updateTicks(false); } @@ -550,12 +551,12 @@ public class PlaceholderManagerImpl implements PlaceholderManager { value = sharedPlaceholder.request(); } player.setValue(placeholder, new TickStampData<>(value, MainTask.getTicks(), true)); - featuresToNotifyUpdates.addAll(player.getUsedFeatures(placeholder)); + featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder)); } else { // The placeholder has been refreshed by other codes if (previous.ticks() == MainTask.getTicks()) { if (previous.hasValueChanged()) { - featuresToNotifyUpdates.addAll(player.getUsedFeatures(placeholder)); + featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder)); } continue; } @@ -569,7 +570,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { if (!previous.data().equals(value)) { previous.data(value); previous.updateTicks(true); - featuresToNotifyUpdates.addAll(player.getUsedFeatures(placeholder)); + featuresToNotifyUpdates.addAll(player.activeFeatures(placeholder)); } else { previous.updateTicks(false); } @@ -583,7 +584,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { if (previous == null) { String value = placeholder.request(player, nearby); player.setRelationalValue(placeholder, nearby, new TickStampData<>(value, MainTask.getTicks(), true)); - for (Feature feature : player.getUsedFeatures(placeholder)) { + for (Feature feature : player.activeFeatures(placeholder)) { // Filter features that will not be updated for all players if (!featuresToNotifyUpdates.contains(feature)) { List players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ArrayList<>()); @@ -593,7 +594,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { } else { if (previous.ticks() == MainTask.getTicks()) { if (previous.hasValueChanged()) { - for (Feature feature : player.getUsedFeatures(placeholder)) { + for (Feature feature : player.activeFeatures(placeholder)) { // Filter features that will not be updated for all players if (!featuresToNotifyUpdates.contains(feature)) { List players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ArrayList<>()); @@ -607,7 +608,7 @@ public class PlaceholderManagerImpl implements PlaceholderManager { if (!previous.data().equals(value)) { previous.data(value); previous.updateTicks(true); - for (Feature feature : player.getUsedFeatures(placeholder)) { + for (Feature feature : player.activeFeatures(placeholder)) { // Filter features that will not be updated for all players if (!featuresToNotifyUpdates.contains(feature)) { List players = relationalFeaturesToNotifyUpdates.computeIfAbsent(feature, k -> new ArrayList<>()); diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlayerPlaceholderImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/PlayerPlaceholderImpl.java similarity index 81% rename from api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlayerPlaceholderImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/PlayerPlaceholderImpl.java index 908eb2d..aa20005 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/PlayerPlaceholderImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/PlayerPlaceholderImpl.java @@ -15,9 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.placeholder; +package net.momirealms.customnameplates.backend.placeholder; import net.momirealms.customnameplates.api.CNPlayer; +import net.momirealms.customnameplates.api.placeholder.AbstractPlaceholder; +import net.momirealms.customnameplates.api.placeholder.PlaceholderManager; +import net.momirealms.customnameplates.api.placeholder.PlayerPlaceholder; import java.util.function.Function; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/RelationalPlaceholderImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/RelationalPlaceholderImpl.java similarity index 81% rename from api/src/main/java/net/momirealms/customnameplates/api/placeholder/RelationalPlaceholderImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/RelationalPlaceholderImpl.java index faeba8f..ad67bea 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/RelationalPlaceholderImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/RelationalPlaceholderImpl.java @@ -15,9 +15,12 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.placeholder; +package net.momirealms.customnameplates.backend.placeholder; import net.momirealms.customnameplates.api.CNPlayer; +import net.momirealms.customnameplates.api.placeholder.AbstractPlaceholder; +import net.momirealms.customnameplates.api.placeholder.PlaceholderManager; +import net.momirealms.customnameplates.api.placeholder.RelationalPlaceholder; import java.util.function.BiFunction; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/SharedPlaceholderImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/SharedPlaceholderImpl.java similarity index 82% rename from api/src/main/java/net/momirealms/customnameplates/api/placeholder/SharedPlaceholderImpl.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/SharedPlaceholderImpl.java index 948a1ca..d528ebf 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/placeholder/SharedPlaceholderImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/placeholder/SharedPlaceholderImpl.java @@ -15,7 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.placeholder; +package net.momirealms.customnameplates.backend.placeholder; + +import net.momirealms.customnameplates.api.placeholder.AbstractPlaceholder; +import net.momirealms.customnameplates.api.placeholder.PlaceholderManager; +import net.momirealms.customnameplates.api.placeholder.SharedPlaceholder; import java.util.function.Supplier; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/AbstractRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/AbstractRequirement.java similarity index 88% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/AbstractRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/AbstractRequirement.java index 2a7b379..2966113 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/AbstractRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/AbstractRequirement.java @@ -15,7 +15,9 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement; +package net.momirealms.customnameplates.backend.requirement; + +import net.momirealms.customnameplates.api.requirement.Requirement; public abstract class AbstractRequirement implements Requirement { diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/AbstractRequirementManager.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/AbstractRequirementManager.java similarity index 97% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/AbstractRequirementManager.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/AbstractRequirementManager.java index 59d90be..b7a4cac 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/AbstractRequirementManager.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/AbstractRequirementManager.java @@ -15,13 +15,16 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement; +package net.momirealms.customnameplates.backend.requirement; import dev.dejvokep.boostedyaml.block.implementation.Section; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; -import net.momirealms.customnameplates.api.requirement.builtin.*; +import net.momirealms.customnameplates.api.requirement.Requirement; +import net.momirealms.customnameplates.api.requirement.RequirementFactory; +import net.momirealms.customnameplates.api.requirement.RequirementManager; import net.momirealms.customnameplates.api.util.ConfigUtils; +import net.momirealms.customnameplates.backend.requirement.builtin.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/AndRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/AndRequirement.java similarity index 93% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/AndRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/AndRequirement.java index 95ad58c..a260f0c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/AndRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/AndRequirement.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.CNPlayer; -import net.momirealms.customnameplates.api.requirement.AbstractRequirement; import net.momirealms.customnameplates.api.requirement.Requirement; +import net.momirealms.customnameplates.backend.requirement.AbstractRequirement; public class AndRequirement extends AbstractRequirement { diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/ContainsRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/ContainsRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/ContainsRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/ContainsRequirement.java index 9c8ac8a..3eb4583 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/ContainsRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/ContainsRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/EndWithRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/EndWithRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/EndWithRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/EndWithRequirement.java index a4404ee..15a2ff8 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/EndWithRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/EndWithRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/EqualsRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/EqualsRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/EqualsRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/EqualsRequirement.java index 8963cab..64a54fb 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/EqualsRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/EqualsRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/HasBubbleRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/HasBubbleRequirement.java similarity index 92% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/HasBubbleRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/HasBubbleRequirement.java index 7fdaad8..b5a569c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/HasBubbleRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/HasBubbleRequirement.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; -import net.momirealms.customnameplates.api.requirement.AbstractRequirement; +import net.momirealms.customnameplates.backend.requirement.AbstractRequirement; public class HasBubbleRequirement extends AbstractRequirement { diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/HasNameplateRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/HasNameplateRequirement.java similarity index 92% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/HasNameplateRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/HasNameplateRequirement.java index 127dd3c..0616a4a 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/HasNameplateRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/HasNameplateRequirement.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; -import net.momirealms.customnameplates.api.requirement.AbstractRequirement; +import net.momirealms.customnameplates.backend.requirement.AbstractRequirement; public class HasNameplateRequirement extends AbstractRequirement { diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/InListRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/InListRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/InListRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/InListRequirement.java index 44734cb..884adb9 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/InListRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/InListRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotContainsRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotContainsRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotContainsRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotContainsRequirement.java index 5ad6e9b..383aa57 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotContainsRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotContainsRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotEndWithRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotEndWithRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotEndWithRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotEndWithRequirement.java index aa59c6d..83289cc 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotEndWithRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotEndWithRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotEqualsRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotEqualsRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotEqualsRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotEqualsRequirement.java index c61a68b..f467942 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotEqualsRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotEqualsRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotInListRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotInListRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotInListRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotInListRequirement.java index 0427fa6..7db2e2c 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotInListRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotInListRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotStartWithRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotStartWithRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotStartWithRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotStartWithRequirement.java index 1991647..b0032ed 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NotStartWithRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NotStartWithRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberEqualsRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberEqualsRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberEqualsRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberEqualsRequirement.java index 0a652ae..f6a6167 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberEqualsRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberEqualsRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberGreaterRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberGreaterRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberGreaterRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberGreaterRequirement.java index 82f3365..d02a099 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberGreaterRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberGreaterRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberLessRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberLessRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberLessRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberLessRequirement.java index d16d1f5..d0e22b9 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberLessRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberLessRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNoGreaterRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNoGreaterRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNoGreaterRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNoGreaterRequirement.java index 26fd588..6372f3e 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNoGreaterRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNoGreaterRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNoLessRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNoLessRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNoLessRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNoLessRequirement.java index f173a04..87497da 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNoLessRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNoLessRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNotEqualsRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNotEqualsRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNotEqualsRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNotEqualsRequirement.java index 7d39d9a..5470d7d 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/NumberNotEqualsRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/NumberNotEqualsRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/OrRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/OrRequirement.java similarity index 93% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/OrRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/OrRequirement.java index 51eed47..18c43fa 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/OrRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/OrRequirement.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.CNPlayer; -import net.momirealms.customnameplates.api.requirement.AbstractRequirement; import net.momirealms.customnameplates.api.requirement.Requirement; +import net.momirealms.customnameplates.backend.requirement.AbstractRequirement; public class OrRequirement extends AbstractRequirement { diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/PlaceholderRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/PlaceholderRequirement.java similarity index 92% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/PlaceholderRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/PlaceholderRequirement.java index ed82e25..cfef868 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/PlaceholderRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/PlaceholderRequirement.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; -import net.momirealms.customnameplates.api.requirement.AbstractRequirement; +import net.momirealms.customnameplates.backend.requirement.AbstractRequirement; import java.util.Objects; import java.util.Set; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/PlaceholdersRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/PlaceholdersRequirement.java similarity index 93% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/PlaceholdersRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/PlaceholdersRequirement.java index b2fd1e6..c8392d4 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/PlaceholdersRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/PlaceholdersRequirement.java @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; -import net.momirealms.customnameplates.api.requirement.AbstractRequirement; +import net.momirealms.customnameplates.backend.requirement.AbstractRequirement; import java.util.Objects; import java.util.Set; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/RegexRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/RegexRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/RegexRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/RegexRequirement.java index c80ca46..31667cf 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/RegexRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/RegexRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/StartWithRequirement.java b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/StartWithRequirement.java similarity index 94% rename from api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/StartWithRequirement.java rename to backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/StartWithRequirement.java index 2c37d41..25f401e 100644 --- a/api/src/main/java/net/momirealms/customnameplates/api/requirement/builtin/StartWithRequirement.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/requirement/builtin/StartWithRequirement.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package net.momirealms.customnameplates.api.requirement.builtin; +package net.momirealms.customnameplates.backend.requirement.builtin; import net.momirealms.customnameplates.api.feature.PreParsedDynamicText; diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/StorageManagerImpl.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/StorageManagerImpl.java index 9b30c03..b6e3bae 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/StorageManagerImpl.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/StorageManagerImpl.java @@ -5,6 +5,7 @@ import dev.dejvokep.boostedyaml.YamlDocument; import net.momirealms.customnameplates.api.AbstractCNPlayer; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.CustomNameplates; +import net.momirealms.customnameplates.api.event.DataLoadEvent; import net.momirealms.customnameplates.api.feature.JoinQuitListener; import net.momirealms.customnameplates.api.helper.GsonHelper; import net.momirealms.customnameplates.api.storage.DataStorageProvider; @@ -53,17 +54,19 @@ public class StorageManagerImpl implements StorageManager, JoinQuitListener { PlayerData data = playerData1.get(); handleDataLoad(player, data); ((AbstractCNPlayer) player).setLoaded(true); + plugin.getEventManager().dispatch(DataLoadEvent.class, data); this.redisManager.updatePlayerData(data, async).thenAccept(result -> { if (!result) { plugin.getPluginLogger().warn("Failed to refresh redis player data for " + player.name()); } }); } else { - this.getDataSource().getPlayerData(uuid, async).thenAccept(playerData2 -> { + this.dataSource().getPlayerData(uuid, async).thenAccept(playerData2 -> { if (playerData2.isPresent()) { PlayerData data = playerData2.get(); handleDataLoad(player, data); ((AbstractCNPlayer) player).setLoaded(true); + plugin.getEventManager().dispatch(DataLoadEvent.class, data); this.redisManager.updatePlayerData(data, async).thenAccept(result -> { if (!result) { plugin.getPluginLogger().warn("Failed to refresh redis player data for " + player.name()); @@ -76,7 +79,7 @@ public class StorageManagerImpl implements StorageManager, JoinQuitListener { } }); } else { - this.getDataSource().getPlayerData(uuid, async).thenAccept(playerData -> { + this.dataSource().getPlayerData(uuid, async).thenAccept(playerData -> { if (playerData.isPresent()) { PlayerData data = playerData.get(); handleDataLoad(player, data); @@ -151,13 +154,13 @@ public class StorageManagerImpl implements StorageManager, JoinQuitListener { @NotNull @Override - public String getServerID() { + public String serverID() { return serverID; } @NotNull @Override - public DataStorageProvider getDataSource() { + public DataStorageProvider dataSource() { return dataSource; } @@ -174,7 +177,7 @@ public class StorageManagerImpl implements StorageManager, JoinQuitListener { @NotNull @Override public String toJson(@NotNull PlayerData data) { - return GsonHelper.get().toJson(data.toGsonData()); + return GsonHelper.get().toJson(data.toJsonData()); } @NotNull diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/DummyStorage.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/DummyStorage.java index 8a2bde1..8dbec9a 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/DummyStorage.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/DummyStorage.java @@ -17,7 +17,7 @@ public class DummyStorage extends AbstractStorage { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.NONE; } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/MongoDBProvider.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/MongoDBProvider.java index f432666..996a57c 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/MongoDBProvider.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/MongoDBProvider.java @@ -93,7 +93,7 @@ public class MongoDBProvider extends AbstractStorage { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.MongoDB; } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/RedisManager.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/RedisManager.java index 8b6e6d1..bd2674d 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/RedisManager.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/nosql/RedisManager.java @@ -103,7 +103,7 @@ public class RedisManager extends AbstractStorage { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.Redis; } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractHikariDatabase.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractHikariDatabase.java index 478c18c..9484ab9 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractHikariDatabase.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractHikariDatabase.java @@ -21,14 +21,14 @@ public abstract class AbstractHikariDatabase extends AbstractSQLDatabase { public AbstractHikariDatabase(CustomNameplates plugin) { super(plugin); - this.driverClass = getStorageType() == StorageType.MariaDB ? "org.mariadb.jdbc.Driver" : "com.mysql.cj.jdbc.Driver"; - this.sqlBrand = getStorageType() == StorageType.MariaDB ? "MariaDB" : "MySQL"; + this.driverClass = storageType() == StorageType.MariaDB ? "org.mariadb.jdbc.Driver" : "com.mysql.cj.jdbc.Driver"; + this.sqlBrand = storageType() == StorageType.MariaDB ? "MariaDB" : "MySQL"; try { Class.forName(this.driverClass); } catch (ClassNotFoundException e1) { - if (getStorageType() == StorageType.MariaDB) { + if (storageType() == StorageType.MariaDB) { plugin.getPluginLogger().warn("No MariaDB driver is found"); - } else if (getStorageType() == StorageType.MySQL) { + } else if (storageType() == StorageType.MySQL) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e2) { diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractSQLDatabase.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractSQLDatabase.java index e0b268f..5e67a87 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractSQLDatabase.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/AbstractSQLDatabase.java @@ -37,7 +37,7 @@ public abstract class AbstractSQLDatabase extends AbstractStorage { */ public void createTableIfNotExist() { try (Connection connection = getConnection()) { - final String[] databaseSchema = getSchema(getStorageType().name().toLowerCase(Locale.ENGLISH)); + final String[] databaseSchema = getSchema(storageType().name().toLowerCase(Locale.ENGLISH)); try (Statement statement = connection.createStatement()) { for (String tableCreationStatement : databaseSchema) { statement.execute(tableCreationStatement); diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/H2Provider.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/H2Provider.java index 8b6c7ec..fe49939 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/H2Provider.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/H2Provider.java @@ -58,7 +58,7 @@ public class H2Provider extends AbstractSQLDatabase { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.H2; } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MariaDBProvider.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MariaDBProvider.java index 1324c63..6df2013 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MariaDBProvider.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MariaDBProvider.java @@ -10,7 +10,7 @@ public class MariaDBProvider extends AbstractHikariDatabase { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.MariaDB; } } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MySQLProvider.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MySQLProvider.java index cd3d030..d408368 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MySQLProvider.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/MySQLProvider.java @@ -10,7 +10,7 @@ public class MySQLProvider extends AbstractHikariDatabase { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.MySQL; } } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/SQLiteProvider.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/SQLiteProvider.java index 1b8f320..a6f84e4 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/SQLiteProvider.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/database/sql/SQLiteProvider.java @@ -62,7 +62,7 @@ public class SQLiteProvider extends AbstractSQLDatabase { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.SQLite; } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/JsonProvider.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/JsonProvider.java index 7032137..293d0bd 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/JsonProvider.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/JsonProvider.java @@ -32,7 +32,7 @@ public class JsonProvider extends AbstractStorage { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.JSON; } @@ -61,7 +61,7 @@ public class JsonProvider extends AbstractStorage { if (executor == null) executor = plugin.getScheduler().async(); executor.execute(() -> { try { - this.saveToJsonFile(playerData.toGsonData(), getPlayerDataFile(playerData.uuid())); + this.saveToJsonFile(playerData.toJsonData(), getPlayerDataFile(playerData.uuid())); } catch (Exception e) { future.complete(false); } diff --git a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/YAMLProvider.java b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/YAMLProvider.java index 6aa83c3..93d1511 100644 --- a/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/YAMLProvider.java +++ b/backend/src/main/java/net/momirealms/customnameplates/backend/storage/method/file/YAMLProvider.java @@ -25,7 +25,7 @@ public class YAMLProvider extends AbstractStorage { } @Override - public StorageType getStorageType() { + public StorageType storageType() { return StorageType.YAML; } diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java index 5d7acff..8c3ed2c 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitChatManager.java @@ -19,7 +19,7 @@ package net.momirealms.customnameplates.bukkit; import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.CustomNameplates; -import net.momirealms.customnameplates.api.feature.bubble.chat.AbstractChatManager; +import net.momirealms.customnameplates.backend.feature.chat.AbstractChatManager; import net.momirealms.customnameplates.bukkit.compatibility.chat.*; import net.momirealms.customnameplates.bukkit.compatibility.emoji.ItemsAdderEmojiProvider; import net.momirealms.customnameplates.bukkit.compatibility.emoji.OraxenEmojiProvider; diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java index 08dcd56..c1579f7 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitCustomNameplates.java @@ -17,24 +17,21 @@ package net.momirealms.customnameplates.bukkit; -import net.momirealms.customnameplates.api.AbstractCNPlayer; -import net.momirealms.customnameplates.api.CNPlayer; -import net.momirealms.customnameplates.api.ConfigManager; -import net.momirealms.customnameplates.api.CustomNameplates; +import net.momirealms.customnameplates.api.*; import net.momirealms.customnameplates.api.event.NameplatesReloadEvent; import net.momirealms.customnameplates.api.feature.ChatListener; import net.momirealms.customnameplates.api.feature.JoinQuitListener; -import net.momirealms.customnameplates.api.feature.actionbar.ActionBarManagerImpl; -import net.momirealms.customnameplates.api.feature.advance.AdvanceManagerImpl; -import net.momirealms.customnameplates.api.feature.background.BackgroundManagerImpl; -import net.momirealms.customnameplates.api.feature.bossbar.BossBarManagerImpl; -import net.momirealms.customnameplates.api.feature.bubble.BubbleManagerImpl; -import net.momirealms.customnameplates.api.feature.image.ImageManagerImpl; -import net.momirealms.customnameplates.api.feature.nameplate.NameplateManagerImpl; -import net.momirealms.customnameplates.api.feature.pack.ResourcePackManagerImpl; -import net.momirealms.customnameplates.api.feature.tag.UnlimitedTagManagerImpl; import net.momirealms.customnameplates.api.helper.VersionHelper; -import net.momirealms.customnameplates.api.placeholder.PlaceholderManagerImpl; +import net.momirealms.customnameplates.backend.feature.actionbar.ActionBarManagerImpl; +import net.momirealms.customnameplates.backend.feature.advance.AdvanceManagerImpl; +import net.momirealms.customnameplates.backend.feature.background.BackgroundManagerImpl; +import net.momirealms.customnameplates.backend.feature.bossbar.BossBarManagerImpl; +import net.momirealms.customnameplates.backend.feature.bubble.BubbleManagerImpl; +import net.momirealms.customnameplates.backend.feature.image.ImageManagerImpl; +import net.momirealms.customnameplates.backend.feature.nameplate.NameplateManagerImpl; +import net.momirealms.customnameplates.backend.feature.pack.ResourcePackManagerImpl; +import net.momirealms.customnameplates.backend.feature.tag.UnlimitedTagManagerImpl; +import net.momirealms.customnameplates.backend.placeholder.PlaceholderManagerImpl; import net.momirealms.customnameplates.backend.storage.StorageManagerImpl; import net.momirealms.customnameplates.bukkit.command.BukkitCommandManager; import net.momirealms.customnameplates.bukkit.compatibility.NameplatesExpansion; @@ -64,6 +61,7 @@ import java.io.InputStream; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; public class BukkitCustomNameplates extends CustomNameplates implements Listener { @@ -204,7 +202,7 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener @Override public void disable() { if (!this.loaded) return; - super.disable(); + if (this.scheduledMainTask != null) this.scheduledMainTask.cancel(); this.configManager.disable(); this.actionBarManager.disable(); @@ -229,7 +227,12 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener @Override public void reload() { - super.reload(); + // cancel task + if (this.scheduledMainTask != null) + this.scheduledMainTask.cancel(); + // reset ticks + MainTask.reset(); + // reload players for (CNPlayer player : getOnlinePlayers()) { ((AbstractCNPlayer) player).reload(); } @@ -254,6 +257,8 @@ public class BukkitCustomNameplates extends CustomNameplates implements Listener this.chatManager.reload(); // dispatch the event this.eventManager.dispatch(NameplatesReloadEvent.class); + // run task + this.scheduledMainTask = getScheduler().asyncRepeating(mainTask, 50, 50, TimeUnit.MILLISECONDS); } @Override diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java index 9e19bd6..b73abdb 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitPlatform.java @@ -23,7 +23,6 @@ import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.CustomNameplates; import net.momirealms.customnameplates.api.Platform; -import net.momirealms.customnameplates.api.feature.actionbar.ActionBarManagerImpl; import net.momirealms.customnameplates.api.feature.bossbar.BossBar; import net.momirealms.customnameplates.api.helper.AdventureHelper; import net.momirealms.customnameplates.api.helper.VersionHelper; @@ -32,6 +31,7 @@ import net.momirealms.customnameplates.api.placeholder.DummyPlaceholder; import net.momirealms.customnameplates.api.placeholder.Placeholder; import net.momirealms.customnameplates.api.util.Alignment; import net.momirealms.customnameplates.api.util.Vector3; +import net.momirealms.customnameplates.backend.feature.actionbar.ActionBarManagerImpl; import net.momirealms.customnameplates.bukkit.util.EntityData; import net.momirealms.customnameplates.bukkit.util.Reflections; import net.momirealms.customnameplates.common.util.TriConsumer; diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesEquipCommand.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesEquipCommand.java index 11f8ccf..d9263fd 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesEquipCommand.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesEquipCommand.java @@ -22,7 +22,6 @@ import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.feature.bubble.BubbleConfig; import net.momirealms.customnameplates.api.helper.AdventureHelper; -import net.momirealms.customnameplates.api.storage.data.PlayerData; import net.momirealms.customnameplates.bukkit.BukkitCustomNameplates; import net.momirealms.customnameplates.bukkit.command.BukkitCommandFeature; import net.momirealms.customnameplates.common.command.CustomNameplatesCommandManager; @@ -65,7 +64,7 @@ public class BubblesEquipCommand extends BukkitCommandFeature { .handler(context -> { if (!ConfigManager.bubbleModule()) return; String bubbleId = context.get("bubble"); - BubbleConfig bubble = plugin.getBubbleManager().getBubbleConfig(bubbleId); + BubbleConfig bubble = plugin.getBubbleManager().bubbleConfigById(bubbleId); if (bubble == null) { handleFeedback(context, MessageConstants.COMMAND_BUBBLES_EQUIP_FAILURE_NOT_EXISTS, Component.text(bubbleId)); return; @@ -87,13 +86,8 @@ public class BubblesEquipCommand extends BukkitCommandFeature { return; } player.equippedBubble(bubbleId); + player.save(); handleFeedback(context, MessageConstants.COMMAND_BUBBLES_EQUIP_SUCCESS, Component.text(bubbleId), AdventureHelper.miniMessage(bubble.displayName())); - - plugin.getStorageManager().getDataSource().updatePlayerData(PlayerData.builder() - .uuid(player.uuid()) - .nameplate(player.equippedNameplate()) - .bubble(player.equippedBubble()) - .build(), plugin.getScheduler().async()); }); } diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesForceEquipCommand.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesForceEquipCommand.java index d7e1dad..ef4a502 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesForceEquipCommand.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/BubblesForceEquipCommand.java @@ -22,7 +22,6 @@ import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.feature.bubble.BubbleConfig; import net.momirealms.customnameplates.api.helper.AdventureHelper; -import net.momirealms.customnameplates.api.storage.data.PlayerData; import net.momirealms.customnameplates.bukkit.BukkitCustomNameplates; import net.momirealms.customnameplates.bukkit.command.BukkitCommandFeature; import net.momirealms.customnameplates.common.command.CustomNameplatesCommandManager; @@ -54,14 +53,14 @@ public class BubblesForceEquipCommand extends BukkitCommandFeature() { @Override public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { - return CompletableFuture.completedFuture(plugin.getBubbleManager().getBubbles().stream().map(it -> Suggestion.suggestion(it.id())).toList()); + return CompletableFuture.completedFuture(plugin.getBubbleManager().bubbles().stream().map(it -> Suggestion.suggestion(it.id())).toList()); } })) .handler(context -> { if (!ConfigManager.bubbleModule()) return; String bubbleId = context.get("bubble"); Player bukkitPlayer = context.get("player"); - BubbleConfig bubble = plugin.getBubbleManager().getBubbleConfig(bubbleId); + BubbleConfig bubble = plugin.getBubbleManager().bubbleConfigById(bubbleId); if (bubble == null) { handleFeedback(context, MessageConstants.COMMAND_BUBBLES_FORCE_EQUIP_FAILURE_NOT_EXISTS, Component.text(bukkitPlayer.getName()), Component.text(bubbleId)); return; @@ -75,13 +74,8 @@ public class BubblesForceEquipCommand extends BukkitCommandFeature { return; } player.equippedBubble("none"); + player.save(); handleFeedback(context, MessageConstants.COMMAND_BUBBLES_UNEQUIP_SUCCESS); - - plugin.getStorageManager().getDataSource().updatePlayerData(PlayerData.builder() - .uuid(player.uuid()) - .nameplate(player.equippedNameplate()) - .bubble(player.equippedBubble()) - .build(), plugin.getScheduler().async()); }); } diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesEquipCommand.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesEquipCommand.java index 0323642..428747f 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesEquipCommand.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesEquipCommand.java @@ -22,7 +22,6 @@ import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.feature.nameplate.Nameplate; import net.momirealms.customnameplates.api.helper.AdventureHelper; -import net.momirealms.customnameplates.api.storage.data.PlayerData; import net.momirealms.customnameplates.bukkit.BukkitCustomNameplates; import net.momirealms.customnameplates.bukkit.command.BukkitCommandFeature; import net.momirealms.customnameplates.common.command.CustomNameplatesCommandManager; @@ -65,7 +64,7 @@ public class NameplatesEquipCommand extends BukkitCommandFeature .handler(context -> { if (!ConfigManager.nameplateModule()) return; String nameplateId = context.get("nameplate"); - Nameplate nameplate = plugin.getNameplateManager().getNameplate(nameplateId); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(nameplateId); if (nameplate == null) { handleFeedback(context, MessageConstants.COMMAND_NAMEPLATES_EQUIP_FAILURE_NOT_EXISTS, Component.text(nameplateId)); return; @@ -87,13 +86,8 @@ public class NameplatesEquipCommand extends BukkitCommandFeature return; } player.equippedNameplate(nameplateId); + player.save(); handleFeedback(context, MessageConstants.COMMAND_NAMEPLATES_EQUIP_SUCCESS, Component.text(nameplateId), AdventureHelper.miniMessage(nameplate.displayName())); - - plugin.getStorageManager().getDataSource().updatePlayerData(PlayerData.builder() - .uuid(player.uuid()) - .nameplate(player.equippedNameplate()) - .bubble(player.equippedBubble()) - .build(), plugin.getScheduler().async()); }); } diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceEquipCommand.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceEquipCommand.java index e268766..3f5ce33 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceEquipCommand.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceEquipCommand.java @@ -22,7 +22,6 @@ import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.ConfigManager; import net.momirealms.customnameplates.api.feature.nameplate.Nameplate; import net.momirealms.customnameplates.api.helper.AdventureHelper; -import net.momirealms.customnameplates.api.storage.data.PlayerData; import net.momirealms.customnameplates.bukkit.BukkitCustomNameplates; import net.momirealms.customnameplates.bukkit.command.BukkitCommandFeature; import net.momirealms.customnameplates.common.command.CustomNameplatesCommandManager; @@ -54,14 +53,14 @@ public class NameplatesForceEquipCommand extends BukkitCommandFeature() { @Override public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { - return CompletableFuture.completedFuture(plugin.getNameplateManager().getNameplates().stream().map(it -> Suggestion.suggestion(it.id())).toList()); + return CompletableFuture.completedFuture(plugin.getNameplateManager().nameplates().stream().map(it -> Suggestion.suggestion(it.id())).toList()); } })) .handler(context -> { if (!ConfigManager.nameplateModule()) return; String nameplateId = context.get("nameplate"); Player bukkitPlayer = context.get("player"); - Nameplate nameplate = plugin.getNameplateManager().getNameplate(nameplateId); + Nameplate nameplate = plugin.getNameplateManager().nameplateById(nameplateId); if (nameplate == null) { handleFeedback(context, MessageConstants.COMMAND_NAMEPLATES_FORCE_EQUIP_FAILURE_NOT_EXISTS, Component.text(bukkitPlayer.getName()), Component.text(nameplateId)); return; @@ -75,13 +74,8 @@ public class NameplatesForceEquipCommand extends BukkitCommandFeature() { @Override public @NonNull CompletableFuture> suggestionsFuture(@NonNull CommandContext context, @NonNull CommandInput input) { - return CompletableFuture.completedFuture(plugin.getNameplateManager().getNameplates().stream().map(it -> Suggestion.suggestion(it.id())).toList()); + return CompletableFuture.completedFuture(plugin.getNameplateManager().nameplates().stream().map(it -> Suggestion.suggestion(it.id())).toList()); } })) .optional("time", IntegerParser.integerParser(0)) diff --git a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceUnEquipCommand.java b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceUnEquipCommand.java index fbaeaa0..0f17bf5 100644 --- a/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceUnEquipCommand.java +++ b/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/command/feature/NameplatesForceUnEquipCommand.java @@ -20,7 +20,6 @@ package net.momirealms.customnameplates.bukkit.command.feature; import net.kyori.adventure.text.Component; import net.momirealms.customnameplates.api.CNPlayer; import net.momirealms.customnameplates.api.ConfigManager; -import net.momirealms.customnameplates.api.storage.data.PlayerData; import net.momirealms.customnameplates.bukkit.BukkitCustomNameplates; import net.momirealms.customnameplates.bukkit.command.BukkitCommandFeature; import net.momirealms.customnameplates.common.command.CustomNameplatesCommandManager; @@ -53,13 +52,8 @@ public class NameplatesForceUnEquipCommand extends BukkitCommandFeature