From a22fc36e67e53b14133bd972723e69313a6183fe Mon Sep 17 00:00:00 2001 From: toxicity Date: Mon, 21 Oct 2024 22:14:42 +0900 Subject: [PATCH] Adds Skript supports. --- README.md | 6 ++- .../healthbar/api/bedrock/BedrockAdapter.java | 1 + .../api/condition/HealthBarCondition.java | 4 +- .../configuration/HealthBarConfiguration.java | 1 + .../api/event/HealthBarCreateEvent.java | 43 +++++++++++++++++++ .../healthbar/api/healthbar/HealthBar.java | 3 +- .../api/healthbar/HealthBarData.java | 14 ------ .../api/healthbar/HealthBarUpdaterGroup.java | 3 +- .../healthbar/api/layout/ImageLayout.java | 4 +- .../healthbar/api/layout/TextLayout.java | 6 +-- .../api/listener/HealthBarListener.java | 4 +- .../api/modelengine/ModelEngineAdapter.java | 1 + .../api/placeholder/HealthBarPlaceholder.java | 4 +- .../api/placeholder/PlaceholderBuilder.java | 12 +++--- .../api/placeholder/PlaceholderContainer.java | 18 ++++---- .../api/scheduler/WrappedScheduler.java | 1 + .../healthbar/api/scheduler/WrappedTask.java | 1 + .../api/trigger/HealthBarTrigger.java | 1 + .../healthbar/bedrock/FloodgateAdapter.kt | 2 +- .../healthbar/bedrock/GeyserAdapter.kt | 2 +- build.gradle.kts | 19 +++++--- .../toxicity/healthbar/BetterHealthBarImpl.kt | 16 +++---- .../compatibility/CitizensCompatibility.kt | 2 +- .../compatibility/MythicMobsCompatibility.kt | 2 +- .../PlaceholderAPICompatibility.kt | 2 +- .../compatibility/SkriptCompatibility.kt | 27 ++++++++++++ .../mob/MythicMobsMobProvider.kt | 2 +- .../skript/ExprHealthBarEntity.kt | 19 ++++++++ .../skript/ExprHealthBarPlayer.kt | 19 ++++++++ .../healthbar/healthbar/HealthBarImpl.kt | 10 ++--- .../healthbar/HealthBarUpdaterGroupImpl.kt | 4 +- .../healthbar/healthbar/RenderedLayout.kt | 8 ++-- .../healthbar/layout/ImageLayoutImpl.kt | 6 +-- .../healthbar/layout/TextLayoutImpl.kt | 8 ++-- .../healthbar/manager/CompatibilityManager.kt | 6 ++- .../healthbar/manager/ConfigManagerImpl.kt | 2 +- .../healthbar/manager/HealthBarManagerImpl.kt | 2 +- .../healthbar/manager/ImageManagerImpl.kt | 2 +- .../healthbar/manager/LayoutManagerImpl.kt | 2 +- .../healthbar/manager/ListenerManagerImpl.kt | 2 +- .../healthbar/manager/MobManagerImpl.kt | 2 +- .../manager/PlaceholderManagerImpl.kt | 24 +++++------ .../healthbar/manager/PlayerManagerImpl.kt | 2 +- .../healthbar/manager/TextManagerImpl.kt | 2 +- .../toxicity/healthbar/pack/PackGenerator.kt | 4 +- .../healthbar/player/HealthBarPlayerImpl.kt | 6 ++- .../kr/toxicity/healthbar/util/Entities.kt | 6 +-- .../kr/toxicity/healthbar/util/Events.kt | 10 +++++ .../kr/toxicity/healthbar/util/Functions.kt | 4 +- dist/src/main/resources/plugin.yml | 5 +++ dist/src/main/resources/rendertype_text.vsh | 4 -- .../modelengine/CurrentModelEngineAdapter.kt | 32 +++++++++----- .../modelengine/LegacyModelEngineAdapter.kt | 32 +++++++++----- .../healthbar/nms/v1_19_R3/NMSImpl.kt | 30 +++++++------ .../healthbar/nms/v1_20_R1/NMSImpl.kt | 30 +++++++------ .../healthbar/nms/v1_20_R2/NMSImpl.kt | 30 +++++++------ .../healthbar/nms/v1_20_R3/NMSImpl.kt | 30 +++++++------ .../healthbar/nms/v1_20_R4/NMSImpl.kt | 30 +++++++------ .../healthbar/nms/v1_21_R1/NMSImpl.kt | 30 +++++++------ .../healthbar/scheduler/FoliaScheduler.kt | 8 +++- .../healthbar/scheduler/StandardScheduler.kt | 5 ++- 61 files changed, 400 insertions(+), 217 deletions(-) create mode 100644 api/src/main/java/kr/toxicity/healthbar/api/event/HealthBarCreateEvent.java delete mode 100644 api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarData.java create mode 100644 dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/SkriptCompatibility.kt create mode 100644 dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarEntity.kt create mode 100644 dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarPlayer.kt create mode 100644 dist/src/main/kotlin/kr/toxicity/healthbar/util/Events.kt diff --git a/README.md b/README.md index cc58888..38a96fa 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ ![healthbar](https://github.com/toxicity188/BetterHealthBar3/assets/114675706/8af7d97c-3277-42f7-bccd-d5e124dfa5df) +**NOTICE: If you want to use BetterHealthBar with shaderspack, set use-core-shaders to false in config.yml** + Welcome to BetterHealthBar! [![GitHub Release](https://img.shields.io/github/v/release/toxicity188/BetterHealthBar3?display_name=release&style=for-the-badge&logo=kotlin)](https://github.com/toxicity188/BetterHealthBar3/releases/latest) @@ -22,9 +24,9 @@ This plugin implements beautiful health bar! ![ezgif-4-6688863fff](https://github.com/toxicity188/BetterHealthBar3/assets/114675706/8484a92e-d0c2-4fd5-a766-5c5cb9fe697c) This plugin supports sight-trace system. -### Custom core shader +### Custom core shaders ![2024_05_03_10_05_19_637-min](https://github.com/toxicity188/BetterHealthBar3/assets/114675706/7a0efa03-a6e7-42fd-b38e-a92d69503ad3) -This plugin has it's own core shader, fixes z-fighting issue! +This plugin has it's own core shaders, fixes z-fighting issue! ### Stack system ![녹화_2024_05_05_10_11_17_395-min](https://github.com/toxicity188/BetterHealthBar3/assets/114675706/d0903a79-e55d-4634-babb-063af2ef0c7c) diff --git a/api/src/main/java/kr/toxicity/healthbar/api/bedrock/BedrockAdapter.java b/api/src/main/java/kr/toxicity/healthbar/api/bedrock/BedrockAdapter.java index 29b3576..0a4e41d 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/bedrock/BedrockAdapter.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/bedrock/BedrockAdapter.java @@ -4,6 +4,7 @@ import java.util.UUID; +@FunctionalInterface public interface BedrockAdapter { BedrockAdapter NONE = u -> false; boolean isBedrockPlayer(@NotNull UUID uuid); diff --git a/api/src/main/java/kr/toxicity/healthbar/api/condition/HealthBarCondition.java b/api/src/main/java/kr/toxicity/healthbar/api/condition/HealthBarCondition.java index 2413da1..04f14f4 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/condition/HealthBarCondition.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/condition/HealthBarCondition.java @@ -1,11 +1,11 @@ package kr.toxicity.healthbar.api.condition; -import kr.toxicity.healthbar.api.healthbar.HealthBarData; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import org.jetbrains.annotations.NotNull; import java.util.function.Function; -public interface HealthBarCondition extends Function { +public interface HealthBarCondition extends Function { HealthBarCondition TRUE = p -> true; default @NotNull HealthBarCondition not() { diff --git a/api/src/main/java/kr/toxicity/healthbar/api/configuration/HealthBarConfiguration.java b/api/src/main/java/kr/toxicity/healthbar/api/configuration/HealthBarConfiguration.java index 1cae213..99fcb1d 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/configuration/HealthBarConfiguration.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/configuration/HealthBarConfiguration.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; +@FunctionalInterface public interface HealthBarConfiguration { @NotNull String path(); diff --git a/api/src/main/java/kr/toxicity/healthbar/api/event/HealthBarCreateEvent.java b/api/src/main/java/kr/toxicity/healthbar/api/event/HealthBarCreateEvent.java new file mode 100644 index 0000000..209e9e5 --- /dev/null +++ b/api/src/main/java/kr/toxicity/healthbar/api/event/HealthBarCreateEvent.java @@ -0,0 +1,43 @@ +package kr.toxicity.healthbar.api.event; + +import kr.toxicity.healthbar.api.entity.HealthBarEntity; +import kr.toxicity.healthbar.api.healthbar.HealthBar; +import kr.toxicity.healthbar.api.player.HealthBarPlayer; +import kr.toxicity.healthbar.api.trigger.HealthBarTrigger; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +@Getter +@Setter +public class HealthBarCreateEvent extends Event implements Cancellable { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final @NotNull HealthBar healthBar; + private final @NotNull HealthBarTrigger trigger; + private final @NotNull HealthBarPlayer player; + private final @NotNull HealthBarEntity entity; + + private boolean cancelled; + + public HealthBarCreateEvent(@NotNull HealthBar healthBar, @NotNull HealthBarTrigger trigger, @NotNull HealthBarPlayer player, @NotNull HealthBarEntity entity) { + super(true); + this.healthBar = healthBar; + this.trigger = trigger; + this.player = player; + this.entity = entity; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBar.java b/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBar.java index 459e5d2..64cdf5e 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBar.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBar.java @@ -2,6 +2,7 @@ import kr.toxicity.healthbar.api.condition.HealthBarCondition; import kr.toxicity.healthbar.api.configuration.HealthBarConfiguration; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import kr.toxicity.healthbar.api.layout.LayoutGroup; import kr.toxicity.healthbar.api.renderer.HealthBarRenderer; import kr.toxicity.healthbar.api.trigger.HealthBarTriggerType; @@ -35,7 +36,7 @@ public interface HealthBar extends HealthBarConfiguration { boolean isDefault(); @NotNull - HealthBarRenderer createRenderer(@NotNull HealthBarData pair); + HealthBarRenderer createRenderer(@NotNull HealthBarCreateEvent pair); @NotNull HealthBarCondition condition(); } diff --git a/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarData.java b/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarData.java deleted file mode 100644 index 97160cf..0000000 --- a/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarData.java +++ /dev/null @@ -1,14 +0,0 @@ -package kr.toxicity.healthbar.api.healthbar; - -import kr.toxicity.healthbar.api.entity.HealthBarEntity; -import kr.toxicity.healthbar.api.player.HealthBarPlayer; -import kr.toxicity.healthbar.api.trigger.HealthBarTrigger; -import org.jetbrains.annotations.NotNull; - -public record HealthBarData( - @NotNull HealthBar healthBar, - @NotNull HealthBarTrigger trigger, - @NotNull HealthBarPlayer player, - @NotNull HealthBarEntity entity -) { -} diff --git a/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarUpdaterGroup.java b/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarUpdaterGroup.java index c68376d..01742e2 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarUpdaterGroup.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/healthbar/HealthBarUpdaterGroup.java @@ -1,6 +1,7 @@ package kr.toxicity.healthbar.api.healthbar; import kr.toxicity.healthbar.api.entity.HealthBarEntity; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import kr.toxicity.healthbar.api.player.HealthBarPlayer; import org.jetbrains.annotations.NotNull; @@ -25,5 +26,5 @@ default void remove() { updaters.clear(); } - void addHealthBar(@NotNull HealthBarData data); + void addHealthBar(@NotNull HealthBarCreateEvent data); } diff --git a/api/src/main/java/kr/toxicity/healthbar/api/layout/ImageLayout.java b/api/src/main/java/kr/toxicity/healthbar/api/layout/ImageLayout.java index d6c8651..b900a86 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/layout/ImageLayout.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/layout/ImageLayout.java @@ -1,6 +1,6 @@ package kr.toxicity.healthbar.api.layout; -import kr.toxicity.healthbar.api.healthbar.HealthBarData; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import kr.toxicity.healthbar.api.image.HealthBarImage; import kr.toxicity.healthbar.api.listener.HealthBarListener; import kr.toxicity.healthbar.api.renderer.ImageRenderer; @@ -14,5 +14,5 @@ public interface ImageLayout extends Layout { int duration(); @NotNull - ImageRenderer createImageRenderer(@NotNull HealthBarData entity); + ImageRenderer createImageRenderer(@NotNull HealthBarCreateEvent entity); } diff --git a/api/src/main/java/kr/toxicity/healthbar/api/layout/TextLayout.java b/api/src/main/java/kr/toxicity/healthbar/api/layout/TextLayout.java index 425667f..f574362 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/layout/TextLayout.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/layout/TextLayout.java @@ -1,6 +1,6 @@ package kr.toxicity.healthbar.api.layout; -import kr.toxicity.healthbar.api.healthbar.HealthBarData; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import kr.toxicity.healthbar.api.renderer.TextRenderer; import kr.toxicity.healthbar.api.text.TextAlign; import net.kyori.adventure.text.Component; @@ -19,8 +19,8 @@ public interface TextLayout extends Layout { TextAlign align(); @NotNull - Function pattern(); + Function pattern(); @NotNull - TextRenderer createRenderer(@NotNull HealthBarData pair); + TextRenderer createRenderer(@NotNull HealthBarCreateEvent pair); } diff --git a/api/src/main/java/kr/toxicity/healthbar/api/listener/HealthBarListener.java b/api/src/main/java/kr/toxicity/healthbar/api/listener/HealthBarListener.java index 1c11367..630fe16 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/listener/HealthBarListener.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/listener/HealthBarListener.java @@ -1,11 +1,11 @@ package kr.toxicity.healthbar.api.listener; -import kr.toxicity.healthbar.api.healthbar.HealthBarData; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import org.jetbrains.annotations.NotNull; public interface HealthBarListener { HealthBarListener ZERO = e -> 0; HealthBarListener INVALID = e -> -1; - double value(@NotNull HealthBarData entity); + double value(@NotNull HealthBarCreateEvent entity); } diff --git a/api/src/main/java/kr/toxicity/healthbar/api/modelengine/ModelEngineAdapter.java b/api/src/main/java/kr/toxicity/healthbar/api/modelengine/ModelEngineAdapter.java index 6e0e11b..d6bbc6b 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/modelengine/ModelEngineAdapter.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/modelengine/ModelEngineAdapter.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +@FunctionalInterface public interface ModelEngineAdapter { ModelEngineAdapter NONE = e -> null; @Nullable diff --git a/api/src/main/java/kr/toxicity/healthbar/api/placeholder/HealthBarPlaceholder.java b/api/src/main/java/kr/toxicity/healthbar/api/placeholder/HealthBarPlaceholder.java index ca6e8fc..52e4cea 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/placeholder/HealthBarPlaceholder.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/placeholder/HealthBarPlaceholder.java @@ -1,6 +1,6 @@ package kr.toxicity.healthbar.api.placeholder; -import kr.toxicity.healthbar.api.healthbar.HealthBarData; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -8,7 +8,7 @@ public interface HealthBarPlaceholder { @NotNull Class type(); @NotNull - T value(@NotNull HealthBarData player); + T value(@NotNull HealthBarCreateEvent player); default @Nullable T cast(@NotNull Object object) { return type().isAssignableFrom(object.getClass()) ? type().cast(object) : null; diff --git a/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderBuilder.java b/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderBuilder.java index 0ae0263..560185a 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderBuilder.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderBuilder.java @@ -1,21 +1,21 @@ package kr.toxicity.healthbar.api.placeholder; -import kr.toxicity.healthbar.api.healthbar.HealthBarData; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.function.Function; public interface PlaceholderBuilder { - HealthBarPlaceholder build(@NotNull List strings); + @NotNull HealthBarPlaceholder build(@NotNull List strings); int requiredArgsCount(); - static PlaceholderBuilder of(int length, @NotNull Class clazz, @NotNull Function, Function> tFunction) { + static PlaceholderBuilder of(int length, @NotNull Class clazz, @NotNull Function, Function> tFunction) { return new PlaceholderBuilder<>() { @Override - public HealthBarPlaceholder build(@NotNull List strings) { + public @NotNull HealthBarPlaceholder build(@NotNull List strings) { var get = tFunction.apply(strings); - return new HealthBarPlaceholder() { + return new HealthBarPlaceholder<>() { @NotNull @Override public Class type() { @@ -24,7 +24,7 @@ public Class type() { @NotNull @Override - public T value(@NotNull HealthBarData player) { + public T value(@NotNull HealthBarCreateEvent player) { return get.apply(player); } }; diff --git a/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderContainer.java b/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderContainer.java index f8dcbe5..132f017 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderContainer.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/placeholder/PlaceholderContainer.java @@ -1,6 +1,6 @@ package kr.toxicity.healthbar.api.placeholder; -import kr.toxicity.healthbar.api.healthbar.HealthBarData; +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -68,7 +68,7 @@ public PlaceholderContainer(@NotNull Class clazz, String name, @NotNull Funct private final Map> map = new HashMap<>(); - public void addPlaceholder(@NotNull String name, @NotNull Function function) { + public void addPlaceholder(@NotNull String name, @NotNull Function function) { map.put(name, new PlaceholderBuilder<>() { @Override public int requiredArgsCount() { @@ -76,11 +76,11 @@ public int requiredArgsCount() { } @Override - public HealthBarPlaceholder build(@NotNull List strings) { + public @NotNull HealthBarPlaceholder build(@NotNull List strings) { return new HealthBarPlaceholder<>() { @NotNull @Override - public T value(@NotNull HealthBarData player) { + public T value(@NotNull HealthBarCreateEvent player) { return function.apply(player); } @@ -129,7 +129,7 @@ public Class type() { @NotNull @Override - public String value(@NotNull HealthBarData player) { + public String value(@NotNull HealthBarCreateEvent player) { return stringMapper.apply(apply.value(player)); } }; @@ -147,7 +147,7 @@ public Class type() { @NotNull @Override - public Object value(@NotNull HealthBarData player) { + public Object value(@NotNull HealthBarCreateEvent player) { return v; } }; @@ -179,15 +179,15 @@ public Class type() { @NotNull @Override - public Object value(@NotNull HealthBarData player) { + public Object value(@NotNull HealthBarCreateEvent player) { return cast.parser.apply(string.value(player)); } }; } else return get.value(list); } - public static @NotNull Function toString(@NotNull String pattern) { - var array = new ArrayList>(); + public static @NotNull Function toString(@NotNull String pattern) { + var array = new ArrayList>(); var sb = new StringBuilder(); var skip = false; for (char c : pattern.toCharArray()) { diff --git a/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedScheduler.java b/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedScheduler.java index 995df1b..b468a52 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedScheduler.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedScheduler.java @@ -5,6 +5,7 @@ public interface WrappedScheduler { @NotNull WrappedTask task(@NotNull Runnable runnable); + @NotNull WrappedTask asyncTask(@NotNull Runnable runnable); @NotNull WrappedTask taskLater(long delay, @NotNull Runnable runnable); @NotNull WrappedTask task(@NotNull World world, int x, int z, @NotNull Runnable runnable); @NotNull WrappedTask asyncTaskTimer(long delay, long period, @NotNull Runnable runnable); diff --git a/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedTask.java b/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedTask.java index 4583c2e..6586498 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedTask.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/scheduler/WrappedTask.java @@ -1,5 +1,6 @@ package kr.toxicity.healthbar.api.scheduler; +@FunctionalInterface public interface WrappedTask { void cancel(); } diff --git a/api/src/main/java/kr/toxicity/healthbar/api/trigger/HealthBarTrigger.java b/api/src/main/java/kr/toxicity/healthbar/api/trigger/HealthBarTrigger.java index 93dd620..5d705db 100644 --- a/api/src/main/java/kr/toxicity/healthbar/api/trigger/HealthBarTrigger.java +++ b/api/src/main/java/kr/toxicity/healthbar/api/trigger/HealthBarTrigger.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; +@FunctionalInterface public interface HealthBarTrigger { @NotNull HealthBarTriggerType type(); } diff --git a/bedrock/floodgate/src/main/kotlin/kr/toxicity/healthbar/bedrock/FloodgateAdapter.kt b/bedrock/floodgate/src/main/kotlin/kr/toxicity/healthbar/bedrock/FloodgateAdapter.kt index 2ef665e..1cb34c0 100644 --- a/bedrock/floodgate/src/main/kotlin/kr/toxicity/healthbar/bedrock/FloodgateAdapter.kt +++ b/bedrock/floodgate/src/main/kotlin/kr/toxicity/healthbar/bedrock/FloodgateAdapter.kt @@ -4,7 +4,7 @@ import kr.toxicity.healthbar.api.bedrock.BedrockAdapter import org.geysermc.floodgate.api.FloodgateApi import java.util.* -class FloodgateAdapter: BedrockAdapter { +class FloodgateAdapter : BedrockAdapter { override fun isBedrockPlayer(uuid: UUID): Boolean { return FloodgateApi.getInstance().isFloodgatePlayer(uuid) } diff --git a/bedrock/geyser/src/main/kotlin/kr/toxicity/healthbar/bedrock/GeyserAdapter.kt b/bedrock/geyser/src/main/kotlin/kr/toxicity/healthbar/bedrock/GeyserAdapter.kt index 5add4d9..84f0f39 100644 --- a/bedrock/geyser/src/main/kotlin/kr/toxicity/healthbar/bedrock/GeyserAdapter.kt +++ b/bedrock/geyser/src/main/kotlin/kr/toxicity/healthbar/bedrock/GeyserAdapter.kt @@ -4,7 +4,7 @@ import kr.toxicity.healthbar.api.bedrock.BedrockAdapter import org.geysermc.api.Geyser import java.util.* -class GeyserAdapter: BedrockAdapter { +class GeyserAdapter : BedrockAdapter { override fun isBedrockPlayer(uuid: UUID): Boolean { return Geyser.api().isBedrockPlayer(uuid) } diff --git a/build.gradle.kts b/build.gradle.kts index 33a8772..001cfb6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,10 @@ plugins { `java-library` - kotlin("jvm") version("2.0.21") - id("io.github.goooler.shadow") version("8.1.8") - id("io.papermc.paperweight.userdev") version("1.7.3") apply(false) - id("xyz.jpenilla.run-paper") version("2.3.1") - id("org.jetbrains.dokka") version("1.9.20") + kotlin("jvm") version "2.0.21" + id("io.github.goooler.shadow") version "8.1.8" + id("io.papermc.paperweight.userdev") version "1.7.3" apply false + id("xyz.jpenilla.run-paper") version "2.3.1" + id("org.jetbrains.dokka") version "1.9.20" } @@ -27,6 +27,7 @@ allprojects { maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") maven("https://mvn.lumine.io/repository/maven-public/") maven("https://jitpack.io/") + maven("https://repo.skriptlang.org/releases") maven("https://repo.alessiodp.com/releases/") maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") maven("https://maven.citizensnpcs.co/repo/") @@ -34,6 +35,7 @@ allprojects { } dependencies { implementation("org.bstats:bstats-bukkit:3.1.0") + implementation("net.jodah:expiringmap:0.5.11") testImplementation(kotlin("test")) } tasks { @@ -87,6 +89,7 @@ val dist = getApiDependencyProject("dist").spigot() .dependency("com.github.toxicity188:BetterHud:c3e147bbd3") .dependency("net.citizensnpcs:citizens-main:2.0.33-SNAPSHOT") .dependency("net.byteflux:libby-bukkit:1.3.0") + .dependency("com.github.SkriptLang:Skript:2.9.3") .also { it.tasks.processResources { filteringCharset = Charsets.UTF_8.name() @@ -171,8 +174,9 @@ tasks { version(minecraft) pluginJars(fileTree("plugins")) downloadPlugins { - url("https://github.com/toxicity188/BetterHud/releases/download/1.5/BetterHud-1.5.jar") - url("https://ci.extendedclip.com/job/PlaceholderAPI/lastSuccessfulBuild/artifact/build/libs/PlaceholderAPI-2.11.7-DEV-200.jar") + modrinth("betterhud2", "1.6.253") + hangar("PlaceholderAPI", "2.11.6") + hangar("Skript", "2.9.3") } } shadowJar { @@ -188,6 +192,7 @@ tasks { } prefix("kotlin") prefix("org.bstats") + prefix("net.jodah.expiringmap") dependencies { exclude(dependency("org.jetbrains:annotations:13.0")) } diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/BetterHealthBarImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/BetterHealthBarImpl.kt index 5351890..5b55b49 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/BetterHealthBarImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/BetterHealthBarImpl.kt @@ -41,7 +41,7 @@ import java.util.function.BiConsumer import java.util.jar.JarFile @Suppress("UNUSED") -class BetterHealthBarImpl: BetterHealthBar() { +class BetterHealthBarImpl : BetterHealthBar() { private val isFolia = runCatching { Class.forName("io.papermc.paper.threadedregions.scheduler.FoliaAsyncScheduler") @@ -76,13 +76,6 @@ class BetterHealthBarImpl: BetterHealthBar() { override fun onEnable() { val log = ArrayList() val manager = Bukkit.getPluginManager() - manager.getPlugin("ModelEngine")?.let { - runWithHandleException("Failed to load ModelEngine support.") { - val version = ModelEngineVersion(it.description.version) - modelEngine = if (version >= ModelEngineVersion.version_4_0_0) CurrentModelEngineAdapter() else LegacyModelEngineAdapter() - log.add("ModelEngine support enabled. $version") - } - } nms = when (MinecraftVersion.current) { MinecraftVersion.version1_21, MinecraftVersion.version1_21_1 -> kr.toxicity.healthbar.nms.v1_21_R1.NMSImpl() MinecraftVersion.version1_20_5, MinecraftVersion.version1_20_6 -> kr.toxicity.healthbar.nms.v1_20_R4.NMSImpl() @@ -99,6 +92,13 @@ class BetterHealthBarImpl: BetterHealthBar() { return } } + manager.getPlugin("ModelEngine")?.let { + runWithHandleException("Failed to load ModelEngine support.") { + val version = ModelEngineVersion(it.description.version) + modelEngine = if (version >= ModelEngineVersion.version_4_0_0) CurrentModelEngineAdapter() else LegacyModelEngineAdapter() + log.add("ModelEngine support enabled: $version") + } + } if (manager.isPluginEnabled("Geyser-Spigot")) { log.add("Geyser support enabled.") bedrock = GeyserAdapter() diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/CitizensCompatibility.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/CitizensCompatibility.kt index 7e58477..f3dfb07 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/CitizensCompatibility.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/CitizensCompatibility.kt @@ -5,7 +5,7 @@ import kr.toxicity.healthbar.util.placeholder import net.citizensnpcs.api.CitizensAPI import java.util.function.Function -class CitizensCompatibility: Compatibility { +class CitizensCompatibility : Compatibility { override fun accept() { PlaceholderContainer.BOOL.addPlaceholder("citizens_npc", placeholder(0) { Function { diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/MythicMobsCompatibility.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/MythicMobsCompatibility.kt index 0df9142..adac4ca 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/MythicMobsCompatibility.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/MythicMobsCompatibility.kt @@ -8,7 +8,7 @@ import kr.toxicity.healthbar.manager.MobManagerImpl import kr.toxicity.healthbar.util.placeholder import java.util.function.Function -class MythicMobsCompatibility: Compatibility { +class MythicMobsCompatibility : Compatibility { override fun accept() { MobManagerImpl.addProvider(MythicMobsMobProvider()) diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/PlaceholderAPICompatibility.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/PlaceholderAPICompatibility.kt index 2086844..1b3c958 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/PlaceholderAPICompatibility.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/PlaceholderAPICompatibility.kt @@ -5,7 +5,7 @@ import kr.toxicity.healthbar.util.placeholder import me.clip.placeholderapi.PlaceholderAPI import java.util.function.Function -class PlaceholderAPICompatibility: Compatibility { +class PlaceholderAPICompatibility : Compatibility { override fun accept() { PlaceholderContainer.STRING.addPlaceholder("papi", placeholder(1) { val papi = if (it[0].startsWith('%')) it[0] else "%${it[0]}%" diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/SkriptCompatibility.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/SkriptCompatibility.kt new file mode 100644 index 0000000..572ce03 --- /dev/null +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/SkriptCompatibility.kt @@ -0,0 +1,27 @@ +package kr.toxicity.healthbar.compatibility + +import ch.njol.skript.Skript +import ch.njol.skript.lang.ExpressionType +import ch.njol.skript.lang.VariableString +import kr.toxicity.healthbar.api.placeholder.PlaceholderContainer +import kr.toxicity.healthbar.compatibility.skript.ExprHealthBarEntity +import kr.toxicity.healthbar.compatibility.skript.ExprHealthBarPlayer +import kr.toxicity.healthbar.util.ifNull +import kr.toxicity.healthbar.util.placeholder +import org.bukkit.entity.Entity +import org.bukkit.entity.Player +import java.util.function.Function + +class SkriptCompatibility : Compatibility { + override fun accept() { + Skript.registerExpression(ExprHealthBarPlayer::class.java, Player::class.java, ExpressionType.SIMPLE, "healthbar player") + Skript.registerExpression(ExprHealthBarEntity::class.java, Entity::class.java, ExpressionType.SIMPLE, "healthbar entity") + + PlaceholderContainer.STRING.addPlaceholder("skript_variable", placeholder(1) { args -> + val value = VariableString.newInstance(args.joinToString(",")).ifNull("Invalid variable.") + Function { + value.getSingle(it) ?: "" + } + }) + } +} \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/mob/MythicMobsMobProvider.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/mob/MythicMobsMobProvider.kt index 2dddbf6..87f52cd 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/mob/MythicMobsMobProvider.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/mob/MythicMobsMobProvider.kt @@ -6,7 +6,7 @@ import kr.toxicity.healthbar.api.mob.MobProvider import kr.toxicity.healthbar.manager.MobManagerImpl import org.bukkit.entity.LivingEntity -class MythicMobsMobProvider: MobProvider { +class MythicMobsMobProvider : MobProvider { override fun provide(entity: LivingEntity): HealthBarMob? { return MythicBukkit.inst().mobManager.getMythicMobInstance(entity)?.let { MythicActiveMobImpl(it, MobManagerImpl.configuration(it.mobType) ?: return null) diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarEntity.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarEntity.kt new file mode 100644 index 0000000..51b5f6d --- /dev/null +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarEntity.kt @@ -0,0 +1,19 @@ +package kr.toxicity.healthbar.compatibility.skript + +import ch.njol.skript.lang.Expression +import ch.njol.skript.lang.SkriptParser +import ch.njol.skript.lang.util.SimpleExpression +import ch.njol.util.Kleenean +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent +import org.bukkit.entity.Entity +import org.bukkit.event.Event + +class ExprHealthBarEntity : SimpleExpression() { + override fun toString(p0: Event?, p1: Boolean): String = "healthbar entity" + override fun init(p0: Array>, p1: Int, p2: Kleenean, p3: SkriptParser.ParseResult): Boolean { + return true + } + override fun isSingle(): Boolean = true + override fun getReturnType(): Class = Entity::class.java + override fun get(p0: Event): Array = if (p0 is HealthBarCreateEvent) arrayOf(p0.entity.entity()) else emptyArray() +} \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarPlayer.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarPlayer.kt new file mode 100644 index 0000000..ea0b0b7 --- /dev/null +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/compatibility/skript/ExprHealthBarPlayer.kt @@ -0,0 +1,19 @@ +package kr.toxicity.healthbar.compatibility.skript + +import ch.njol.skript.lang.Expression +import ch.njol.skript.lang.SkriptParser +import ch.njol.skript.lang.util.SimpleExpression +import ch.njol.util.Kleenean +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent +import org.bukkit.entity.Player +import org.bukkit.event.Event + +class ExprHealthBarPlayer : SimpleExpression() { + override fun toString(p0: Event?, p1: Boolean): String = "healthbar player" + override fun init(p0: Array>, p1: Int, p2: Kleenean, p3: SkriptParser.ParseResult): Boolean { + return true + } + override fun isSingle(): Boolean = true + override fun getReturnType(): Class = Player::class.java + override fun get(p0: Event): Array = if (p0 is HealthBarCreateEvent) arrayOf(p0.player.player()) else emptyArray() +} \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarImpl.kt index cb636ee..f46bc3e 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarImpl.kt @@ -4,7 +4,7 @@ import kr.toxicity.healthbar.api.component.WidthComponent import kr.toxicity.healthbar.api.condition.HealthBarCondition import kr.toxicity.healthbar.api.healthbar.GroupIndex import kr.toxicity.healthbar.api.healthbar.HealthBar -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.trigger.HealthBarTriggerType import kr.toxicity.healthbar.api.layout.LayoutGroup import kr.toxicity.healthbar.api.nms.VirtualTextDisplay @@ -58,7 +58,7 @@ class HealthBarImpl( override fun duration(): Int = duration - override fun createRenderer(pair: HealthBarData): HealthBarRenderer { + override fun createRenderer(pair: HealthBarCreateEvent): HealthBarRenderer { return if (ConfigManagerImpl.useCoreShaders()) SingleRenderer(pair) else MultiRenderer(pair) } @@ -75,7 +75,7 @@ class HealthBarImpl( return s.hashCode() } - private abstract inner class AbstractRenderer(protected val pair: HealthBarData): HealthBarRenderer { + private abstract inner class AbstractRenderer(protected val pair: HealthBarCreateEvent): HealthBarRenderer { protected val indexes = groups.mapNotNull { it.group() }.associateWith { @@ -101,7 +101,7 @@ class HealthBarImpl( } } private inner class MultiRenderer( - pair: HealthBarData + pair: HealthBarCreateEvent ): AbstractRenderer(pair) { private val displays = render.map { @@ -146,7 +146,7 @@ class HealthBarImpl( } } private inner class SingleRenderer( - pair: HealthBarData + pair: HealthBarCreateEvent ): AbstractRenderer(pair) { private val display = pair.createEntity(render()) diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarUpdaterGroupImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarUpdaterGroupImpl.kt index 2916519..ca3a99d 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarUpdaterGroupImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/HealthBarUpdaterGroupImpl.kt @@ -1,7 +1,7 @@ package kr.toxicity.healthbar.healthbar import kr.toxicity.healthbar.api.entity.HealthBarEntity -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.healthbar.HealthBarUpdater import kr.toxicity.healthbar.api.healthbar.HealthBarUpdaterGroup import kr.toxicity.healthbar.api.player.HealthBarPlayer @@ -18,7 +18,7 @@ class HealthBarUpdaterGroupImpl( override fun updaters(): Collection = updaters.values - override fun addHealthBar(data: HealthBarData) { + override fun addHealthBar(data: HealthBarCreateEvent) { updaters.computeIfAbsent(data.healthBar.uuid()) { HealthBarUpdaterImpl(this, data.healthBar.createRenderer(data)) }.updateTick() diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/RenderedLayout.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/RenderedLayout.kt index cf134a9..819c8d1 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/RenderedLayout.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/healthbar/RenderedLayout.kt @@ -1,7 +1,7 @@ package kr.toxicity.healthbar.healthbar import kr.toxicity.healthbar.api.healthbar.GroupIndex -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.layout.LayoutGroup import kr.toxicity.healthbar.api.nms.VirtualTextDisplay import kr.toxicity.healthbar.api.renderer.ImageRenderer @@ -9,7 +9,7 @@ import kr.toxicity.healthbar.api.renderer.PixelRenderer import kr.toxicity.healthbar.util.* import org.bukkit.Location -class RenderedLayout(group: LayoutGroup, pair: HealthBarData) { +class RenderedLayout(group: LayoutGroup, pair: HealthBarCreateEvent) { val group = group.group() val images = group.images().map { it.createImageRenderer(pair) @@ -18,10 +18,10 @@ class RenderedLayout(group: LayoutGroup, pair: HealthBarData) { it.createRenderer(pair) }.toMutableList() - fun createPool(data: HealthBarData, indexes: Map) = RenderedEntityPool(data, indexes) + fun createPool(data: HealthBarCreateEvent, indexes: Map) = RenderedEntityPool(data, indexes) inner class RenderedEntityPool( - private val data: HealthBarData, + private val data: HealthBarCreateEvent, private val indexes: Map ) { private val imagesEntity = images.map { diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/layout/ImageLayoutImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/layout/ImageLayoutImpl.kt index 33b1c48..f2957e6 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/layout/ImageLayoutImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/layout/ImageLayoutImpl.kt @@ -4,7 +4,7 @@ import com.google.gson.JsonArray import com.google.gson.JsonObject import kr.toxicity.healthbar.api.component.PixelComponent import kr.toxicity.healthbar.api.component.WidthComponent -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.image.HealthBarImage import kr.toxicity.healthbar.api.layout.ImageLayout import kr.toxicity.healthbar.api.listener.HealthBarListener @@ -71,12 +71,12 @@ class ImageLayoutImpl( } } - override fun createImageRenderer(pair: HealthBarData): ImageRenderer { + override fun createImageRenderer(pair: HealthBarCreateEvent): ImageRenderer { return Renderer(pair) } private inner class Renderer( - private val pair: HealthBarData + private val pair: HealthBarCreateEvent ): ImageRenderer { private var next = 0 private var d = 0 diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/layout/TextLayoutImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/layout/TextLayoutImpl.kt index 59ee9f3..3c69b28 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/layout/TextLayoutImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/layout/TextLayoutImpl.kt @@ -4,7 +4,7 @@ import com.google.gson.JsonArray import com.google.gson.JsonObject import kr.toxicity.healthbar.api.component.PixelComponent import kr.toxicity.healthbar.api.component.WidthComponent -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.layout.TextLayout import kr.toxicity.healthbar.api.placeholder.PlaceholderContainer import kr.toxicity.healthbar.api.renderer.TextRenderer @@ -52,7 +52,7 @@ class TextLayoutImpl( override fun charWidth(): Map = textWidth override fun align(): TextAlign = align - override fun pattern(): Function = pattern + override fun pattern(): Function = pattern private class WidthKey( val key: Key, @@ -104,12 +104,12 @@ class TextLayoutImpl( } } - override fun createRenderer(pair: HealthBarData): TextRenderer { + override fun createRenderer(pair: HealthBarCreateEvent): TextRenderer { return Renderer(pair) } private inner class Renderer( - private val pair: HealthBarData + private val pair: HealthBarCreateEvent ): TextRenderer { private var d = 0 override fun hasNext(): Boolean { diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/CompatibilityManager.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/CompatibilityManager.kt index f81e7ee..cd65571 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/CompatibilityManager.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/CompatibilityManager.kt @@ -3,6 +3,7 @@ package kr.toxicity.healthbar.manager import kr.toxicity.healthbar.compatibility.MythicMobsCompatibility import kr.toxicity.healthbar.compatibility.PlaceholderAPICompatibility import kr.toxicity.healthbar.compatibility.CitizensCompatibility +import kr.toxicity.healthbar.compatibility.SkriptCompatibility import kr.toxicity.healthbar.pack.PackResource import kr.toxicity.healthbar.util.PLUGIN import kr.toxicity.hud.api.BetterHudAPI @@ -13,7 +14,7 @@ import org.bukkit.event.Listener import java.io.InputStreamReader import java.nio.charset.StandardCharsets -object CompatibilityManager: BetterHealthBerManager { +object CompatibilityManager : BetterHealthBerManager { private val compMap = mapOf( "MythicMobs" to { @@ -24,6 +25,9 @@ object CompatibilityManager: BetterHealthBerManager { }, "Citizens" to { CitizensCompatibility() + }, + "Skript" to { + SkriptCompatibility() } ) diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ConfigManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ConfigManagerImpl.kt index 8dd2d18..1de992a 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ConfigManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ConfigManagerImpl.kt @@ -13,7 +13,7 @@ import java.io.File import java.util.Collections import java.util.EnumSet -object ConfigManagerImpl: ConfigManager, BetterHealthBerManager { +object ConfigManagerImpl : ConfigManager, BetterHealthBerManager { private var debug = true private var metrics = true diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/HealthBarManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/HealthBarManagerImpl.kt index 6e21412..366578c 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/HealthBarManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/HealthBarManagerImpl.kt @@ -12,7 +12,7 @@ import java.util.Collections import java.util.UUID import java.util.concurrent.ConcurrentHashMap -object HealthBarManagerImpl: HealthBarManager, BetterHealthBerManager { +object HealthBarManagerImpl : HealthBarManager, BetterHealthBerManager { private val healthBarMap = ConcurrentHashMap() private val uuidSet = Collections.synchronizedSet(HashSet()) diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ImageManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ImageManagerImpl.kt index b6d2bff..8f3f554 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ImageManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ImageManagerImpl.kt @@ -11,7 +11,7 @@ import java.io.File import java.util.concurrent.ConcurrentHashMap import java.util.regex.Pattern -object ImageManagerImpl: ImageManager, BetterHealthBerManager { +object ImageManagerImpl : ImageManager, BetterHealthBerManager { private val imageMap = ConcurrentHashMap() private val framePattern = Pattern.compile("(?(([a-zA-Z]|_|[0-9])+)):(?([0-9]+))") diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/LayoutManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/LayoutManagerImpl.kt index 4c7be84..c81e53b 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/LayoutManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/LayoutManagerImpl.kt @@ -12,7 +12,7 @@ import java.util.Collections import java.util.HashSet import java.util.concurrent.ConcurrentHashMap -object LayoutManagerImpl: LayoutManager, BetterHealthBerManager { +object LayoutManagerImpl : LayoutManager, BetterHealthBerManager { private val layoutMap = ConcurrentHashMap() private val groupData = ConcurrentHashMap>() diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ListenerManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ListenerManagerImpl.kt index 57b76af..4d00087 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ListenerManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/ListenerManagerImpl.kt @@ -9,7 +9,7 @@ import org.bukkit.configuration.ConfigurationSection import java.util.concurrent.ConcurrentHashMap import java.util.function.Function -object ListenerManagerImpl: ListenerManager, BetterHealthBerManager { +object ListenerManagerImpl : ListenerManager, BetterHealthBerManager { private val listenerMap = ConcurrentHashMap HealthBarListener>().apply { put("health") { diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/MobManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/MobManagerImpl.kt index 07f1c00..2cc22c0 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/MobManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/MobManagerImpl.kt @@ -15,7 +15,7 @@ import kr.toxicity.healthbar.util.subFolder import org.bukkit.entity.LivingEntity import java.util.concurrent.ConcurrentHashMap -object MobManagerImpl: BetterHealthBerManager, MobManager { +object MobManagerImpl : BetterHealthBerManager, MobManager { private val mobProviders = ArrayList() private val mobConfigurationMap = ConcurrentHashMap() diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlaceholderManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlaceholderManagerImpl.kt index 8f777be..29eaa1d 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlaceholderManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlaceholderManagerImpl.kt @@ -1,7 +1,7 @@ package kr.toxicity.healthbar.manager import kr.toxicity.healthbar.api.compatibility.MythicActiveMob -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.manager.PlaceholderManager import kr.toxicity.healthbar.api.placeholder.PlaceholderContainer import kr.toxicity.healthbar.pack.PackResource @@ -15,28 +15,28 @@ import org.bukkit.entity.Player import org.bukkit.potion.PotionEffectType import java.util.function.Function -object PlaceholderManagerImpl: PlaceholderManager, BetterHealthBerManager { +object PlaceholderManagerImpl : PlaceholderManager, BetterHealthBerManager { override fun start() { PlaceholderContainer.NUMBER.run { - addPlaceholder("health") { e: HealthBarData -> + addPlaceholder("health") { e: HealthBarCreateEvent -> e.entity.entity().health } - addPlaceholder("max_health") { e: HealthBarData -> + addPlaceholder("max_health") { e: HealthBarCreateEvent -> e.entity.entity().getAttribute(Attribute.GENERIC_MAX_HEALTH)!!.value } - addPlaceholder("health_percentage") { e: HealthBarData -> + addPlaceholder("health_percentage") { e: HealthBarCreateEvent -> e.entity.entity().health / e.entity.entity().getAttribute(Attribute.GENERIC_MAX_HEALTH)!!.value } - addPlaceholder("absorption") { e: HealthBarData -> + addPlaceholder("absorption") { e: HealthBarCreateEvent -> e.entity.entity().absorptionAmount } } PlaceholderContainer.STRING.run { - addPlaceholder("entity_type") { e: HealthBarData -> + addPlaceholder("entity_type") { e: HealthBarCreateEvent -> e.entity.entity().type.toString().lowercase() } - addPlaceholder("entity_name") { e: HealthBarData -> + addPlaceholder("entity_name") { e: HealthBarCreateEvent -> e.entity.entity().name } } @@ -48,20 +48,20 @@ object PlaceholderManagerImpl: PlaceholderManager, BetterHealthBerManager { @Suppress("DEPRECATION") PotionEffectType.getByName(it[0]) }?.let { type -> - Function { pair: HealthBarData -> + Function { pair: HealthBarCreateEvent -> pair.entity.entity().hasPotionEffect(type) } } ?: run { warn("Unable to find this potion effect: ${it[0]}") - Function { _: HealthBarData -> + Function { _: HealthBarCreateEvent -> false } } }) - addPlaceholder("is_player") { e: HealthBarData -> + addPlaceholder("is_player") { e: HealthBarCreateEvent -> e.entity.entity() is Player } - addPlaceholder("is_mythic_mob") { e: HealthBarData -> + addPlaceholder("is_mythic_mob") { e: HealthBarCreateEvent -> e.entity.mob() is MythicActiveMob } } diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlayerManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlayerManagerImpl.kt index 258b881..fd741a4 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlayerManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/PlayerManagerImpl.kt @@ -17,7 +17,7 @@ import org.bukkit.event.player.PlayerQuitEvent import java.util.* import java.util.concurrent.ConcurrentHashMap -object PlayerManagerImpl: PlayerManager, BetterHealthBerManager { +object PlayerManagerImpl : PlayerManager, BetterHealthBerManager { private val playerMap = ConcurrentHashMap() override fun preReload() { diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/TextManagerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/TextManagerImpl.kt index 7e2d076..4660b29 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/manager/TextManagerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/manager/TextManagerImpl.kt @@ -20,7 +20,7 @@ import java.util.TreeSet import java.util.concurrent.ConcurrentHashMap import kotlin.math.roundToInt -object TextManagerImpl: TextManager, BetterHealthBerManager { +object TextManagerImpl : TextManager, BetterHealthBerManager { private val frc = FontRenderContext(null, true, true) private const val SPLIT_SIZE = 16 diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/pack/PackGenerator.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/pack/PackGenerator.kt index bb243ed..f1eeb83 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/pack/PackGenerator.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/pack/PackGenerator.kt @@ -20,7 +20,7 @@ object PackGenerator { fun zip(resource: PackResource) } - private class FolderPack: Pack { + private class FolderPack : Pack { private val parent: File = ConfigManagerImpl.buildFolder() private val buildFolder = File(parent, "assets").apply { mkdirs() @@ -88,7 +88,7 @@ object PackGenerator { } } - private class ZipPack: Pack { + private class ZipPack : Pack { private val file = ConfigManagerImpl.buildFolder().run { File(parentFile.also { diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt index c296e9e..92aa408 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/player/HealthBarPlayerImpl.kt @@ -2,7 +2,7 @@ package kr.toxicity.healthbar.player import kr.toxicity.healthbar.api.entity.HealthBarEntity import kr.toxicity.healthbar.api.healthbar.HealthBar -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.healthbar.HealthBarUpdaterGroup import kr.toxicity.healthbar.api.player.HealthBarPlayer import kr.toxicity.healthbar.api.trigger.HealthBarTrigger @@ -10,6 +10,7 @@ import kr.toxicity.healthbar.healthbar.HealthBarUpdaterGroupImpl import kr.toxicity.healthbar.manager.ConfigManagerImpl import kr.toxicity.healthbar.util.PLUGIN import kr.toxicity.healthbar.util.asyncTaskTimer +import kr.toxicity.healthbar.util.call import org.bukkit.entity.Player import java.util.* @@ -57,12 +58,13 @@ class HealthBarPlayerImpl( entity.mob()?.let { if (it.configuration().blacklist()) return } - val data = HealthBarData( + val data = HealthBarCreateEvent( healthBar, trigger, this, entity ) + if (!data.call()) return if (!healthBar.condition().apply(data)) return synchronized(updaterMap) { updaterMap.computeIfAbsent(entity.entity().uniqueId) { diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/util/Entities.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/util/Entities.kt index 33867fe..1699b4b 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/util/Entities.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/util/Entities.kt @@ -1,13 +1,13 @@ package kr.toxicity.healthbar.util import kr.toxicity.healthbar.api.component.WidthComponent -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.nms.VirtualTextDisplay import kr.toxicity.healthbar.manager.ConfigManagerImpl import org.bukkit.Location import org.bukkit.util.Vector -fun HealthBarData.toEntityLocation(): Location { +fun HealthBarCreateEvent.toEntityLocation(): Location { return entity.entity().location.apply { y += (PLUGIN.modelEngine().height(entity.entity()) ?: entity.entity().eyeHeight) + ConfigManagerImpl.defaultHeight() entity.mob()?.let { @@ -15,7 +15,7 @@ fun HealthBarData.toEntityLocation(): Location { } } } -fun HealthBarData.createEntity(component: WidthComponent, layer: Int = 0): VirtualTextDisplay { +fun HealthBarCreateEvent.createEntity(component: WidthComponent, layer: Int = 0): VirtualTextDisplay { return PLUGIN.nms().createTextDisplay(player.player(), toEntityLocation(), component.component.build()).apply { val scale = healthBar.scale() transformation( diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/util/Events.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/util/Events.kt new file mode 100644 index 0000000..1b9c340 --- /dev/null +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/util/Events.kt @@ -0,0 +1,10 @@ +package kr.toxicity.healthbar.util + +import org.bukkit.Bukkit +import org.bukkit.event.Cancellable +import org.bukkit.event.Event + +fun Event.call(): Boolean { + Bukkit.getPluginManager().callEvent(this) + return if (this is Cancellable) !isCancelled else true +} \ No newline at end of file diff --git a/dist/src/main/kotlin/kr/toxicity/healthbar/util/Functions.kt b/dist/src/main/kotlin/kr/toxicity/healthbar/util/Functions.kt index d6c47a9..7777fdc 100644 --- a/dist/src/main/kotlin/kr/toxicity/healthbar/util/Functions.kt +++ b/dist/src/main/kotlin/kr/toxicity/healthbar/util/Functions.kt @@ -1,6 +1,6 @@ package kr.toxicity.healthbar.util -import kr.toxicity.healthbar.api.healthbar.HealthBarData +import kr.toxicity.healthbar.api.event.HealthBarCreateEvent import kr.toxicity.healthbar.api.placeholder.PlaceholderBuilder import kr.toxicity.healthbar.manager.ConfigManagerImpl import java.util.function.Function @@ -19,6 +19,6 @@ fun Throwable.handleException(log: String): Array { ) } -inline fun placeholder(length: Int, function: Function, Function>): PlaceholderBuilder { +inline fun placeholder(length: Int, function: Function, Function>): PlaceholderBuilder { return PlaceholderBuilder.of(length, T::class.java, function) } \ No newline at end of file diff --git a/dist/src/main/resources/plugin.yml b/dist/src/main/resources/plugin.yml index eaa3f0e..09f71a4 100644 --- a/dist/src/main/resources/plugin.yml +++ b/dist/src/main/resources/plugin.yml @@ -6,6 +6,7 @@ author: toxicity description: Make mob has greater health bar! load: POSTWORLD folia-supported: true +website: "https://www.spigotmc.org/resources/116619/" libraries: - "net.kyori:adventure-api:${adventure}" - "net.kyori:adventure-text-minimessage:${adventure}" @@ -16,6 +17,10 @@ softdepend: - MythicMobs - PlaceholderAPI - Citizens + - Skript + - SkBee + - skript-placeholders + - skript-reflect commands: healthbar: aliases: hb diff --git a/dist/src/main/resources/rendertype_text.vsh b/dist/src/main/resources/rendertype_text.vsh index 83be628..c1b22a9 100644 --- a/dist/src/main/resources/rendertype_text.vsh +++ b/dist/src/main/resources/rendertype_text.vsh @@ -51,7 +51,6 @@ void main() { float x = abs(pos.x) + abs(ModelViewMat[3].x); float y = abs(pos.y) + abs(ModelViewMat[3].y); float z = abs(pos.z) + abs(ModelViewMat[3].z); - float length1 = -cos(pitch) * y; float length2 = sin(pitch) * sqrt(pow(x, 2.0) + pow(z, 2.0)); if (abs(length1 - length2) >= DISPLAY_HEIGHT / 2 || abs(length1 + length2) >= DISPLAY_HEIGHT / 2) { @@ -59,14 +58,11 @@ void main() { if (alpha < 1) { applyColor = 1; float pitchAdd = cos(pitch - 3.1415 / 2) * DISPLAY_HEIGHT; - float xAlpha = cos(pitch) * alpha; vec3 alphaVector = vec3(xAlpha * sin(yaw), -sin(pitch) * alpha, -xAlpha * cos(yaw)); - pos.y += cos(pitch) * DISPLAY_HEIGHT; pos.x += sin(yaw) * pitchAdd; pos.z -= cos(yaw) * pitchAdd; - pos += alphaVector / 100; } } diff --git a/modelengine/current/src/main/kotlin/kr/toxicity/healthbar/modelengine/CurrentModelEngineAdapter.kt b/modelengine/current/src/main/kotlin/kr/toxicity/healthbar/modelengine/CurrentModelEngineAdapter.kt index fd45315..cd73077 100644 --- a/modelengine/current/src/main/kotlin/kr/toxicity/healthbar/modelengine/CurrentModelEngineAdapter.kt +++ b/modelengine/current/src/main/kotlin/kr/toxicity/healthbar/modelengine/CurrentModelEngineAdapter.kt @@ -3,21 +3,33 @@ package kr.toxicity.healthbar.modelengine import com.ticxo.modelengine.api.ModelEngineAPI import com.ticxo.modelengine.api.generator.blueprint.BlueprintBone import kr.toxicity.healthbar.api.modelengine.ModelEngineAdapter +import net.jodah.expiringmap.ExpirationPolicy +import net.jodah.expiringmap.ExpiringMap import org.bukkit.entity.Entity +import java.util.concurrent.TimeUnit + +class CurrentModelEngineAdapter : ModelEngineAdapter { + + private val blueprintCache = ExpiringMap.builder() + .maxSize(256) + .expirationPolicy(ExpirationPolicy.CREATED) + .expiration(1, TimeUnit.MINUTES) + .build() -class CurrentModelEngineAdapter: ModelEngineAdapter { override fun height(entity: Entity): Double? { return ModelEngineAPI.getModeledEntity(entity.uniqueId)?.run { - models.values.maxOf { - fun getChildren(blueprint: BlueprintBone): Double { - val children: Collection = blueprint.children.values - return if (children.isEmpty()) blueprint.globalPosition.y.toDouble() - else children.maxOf { bb -> - getChildren(bb) + models.values.maxOfOrNull { + blueprintCache.computeIfAbsent(it.blueprint.name) { _ -> + fun getChildren(blueprint: BlueprintBone): Double { + val children: Collection = blueprint.children.values + return if (children.isEmpty()) blueprint.globalPosition.y.toDouble() + else children.maxOf { bb -> + getChildren(bb) + } } - } - it.blueprint.bones.values.maxOf { bb -> - getChildren(bb) + it.blueprint.bones.values.maxOfOrNull { bb -> + getChildren(bb) + } ?: 0.0 } } } diff --git a/modelengine/legacy/src/main/kotlin/kr/toxicity/healthbar/modelengine/LegacyModelEngineAdapter.kt b/modelengine/legacy/src/main/kotlin/kr/toxicity/healthbar/modelengine/LegacyModelEngineAdapter.kt index 0e94556..53a1c0e 100644 --- a/modelengine/legacy/src/main/kotlin/kr/toxicity/healthbar/modelengine/LegacyModelEngineAdapter.kt +++ b/modelengine/legacy/src/main/kotlin/kr/toxicity/healthbar/modelengine/LegacyModelEngineAdapter.kt @@ -3,21 +3,33 @@ package kr.toxicity.healthbar.modelengine import com.ticxo.modelengine.api.ModelEngineAPI import com.ticxo.modelengine.api.generator.model.BlueprintBone import kr.toxicity.healthbar.api.modelengine.ModelEngineAdapter +import net.jodah.expiringmap.ExpirationPolicy +import net.jodah.expiringmap.ExpiringMap import org.bukkit.entity.Entity +import java.util.concurrent.TimeUnit + +class LegacyModelEngineAdapter : ModelEngineAdapter { + + private val blueprintCache = ExpiringMap.builder() + .maxSize(256) + .expirationPolicy(ExpirationPolicy.CREATED) + .expiration(1, TimeUnit.MINUTES) + .build() -class LegacyModelEngineAdapter: ModelEngineAdapter { override fun height(entity: Entity): Double? { return ModelEngineAPI.getModeledEntity(entity.uniqueId)?.run { - models.values.maxOf { - fun getChildren(blueprint: BlueprintBone): Double { - val children: Set? = blueprint.children - return if (children.isNullOrEmpty()) blueprint.globalOrigin.y - else children.maxOf { bb -> - getChildren(bb) + models.values.maxOfOrNull { + blueprintCache.computeIfAbsent(it.blueprint.modelId) { _ -> + fun getChildren(blueprint: BlueprintBone): Double { + val children: Set? = blueprint.children + return if (children.isNullOrEmpty()) blueprint.globalOrigin.y + else children.maxOf { bb -> + getChildren(bb) + } } - } - it.blueprint.bones.values.maxOf { bb -> - getChildren(bb) + it.blueprint.bones.values.maxOfOrNull { bb -> + getChildren(bb) + } ?: 0.0 } } } diff --git a/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt b/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt index 2c0bec8..feb643b 100644 --- a/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt +++ b/nms/v1_19_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_19_R3/NMSImpl.kt @@ -56,7 +56,7 @@ import kotlin.math.atan2 import kotlin.math.sqrt @Suppress("UNUSED") -class NMSImpl: NMS { +class NMSImpl : NMS { private val plugin get() = BetterHealthBar.inst() @@ -292,7 +292,7 @@ class NMSImpl: NMS { injectionMap.remove(player.player().uniqueId)?.uninject() } - private inner class PlayerInjection(val player: HealthBarPlayer): ChannelDuplexHandler() { + private inner class PlayerInjection(val player: HealthBarPlayer) : ChannelDuplexHandler() { private val serverPlayer = (player.player() as CraftPlayer).handle private val connection = serverPlayer.connection private val world = player.player().world @@ -321,26 +321,30 @@ class NMSImpl: NMS { val set = HashSet(plugin.healthBarManager().allHealthBars().filter { it.isDefault && it.triggers().contains(trigger) }) - fun add() { + fun add(sync: Boolean = false) { val bukkit = e.bukkitEntity if (bukkit is CraftLivingEntity && bukkit.isValid) { val adapt = plugin.mobManager().entity(if (bukkit is Player) foliaAdapt(bukkit) else foliaAdapt(bukkit)) val types = adapt.mob()?.configuration()?.types() val packet = PacketTrigger(trigger, handle) - set.filter { - (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> - types.contains(t) - }) - }.forEach { - player.showHealthBar(it, packet, adapt) - } - adapt.mob()?.configuration()?.healthBars()?.forEach { - player.showHealthBar(it, packet, adapt) + val run = Runnable { + set.filter { + (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> + types.contains(t) + }) + }.forEach { + player.showHealthBar(it, packet, adapt) + } + adapt.mob()?.configuration()?.healthBars()?.forEach { + player.showHealthBar(it, packet, adapt) + } } + if (sync) plugin.scheduler().asyncTask(run) + else run.run() } } if (plugin.isFolia) plugin.scheduler().task(world, e.x.toInt() shr 4, e.z.toInt() shr 4) { - add() + add(true) } else add() } } diff --git a/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt b/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt index e9668f5..f8e52a5 100644 --- a/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt +++ b/nms/v1_20_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R1/NMSImpl.kt @@ -56,7 +56,7 @@ import kotlin.math.atan2 import kotlin.math.sqrt @Suppress("UNUSED") -class NMSImpl: NMS { +class NMSImpl : NMS { private val plugin get() = BetterHealthBar.inst() @@ -298,7 +298,7 @@ class NMSImpl: NMS { injectionMap.remove(player.player().uniqueId)?.uninject() } - private inner class PlayerInjection(val player: HealthBarPlayer): ChannelDuplexHandler() { + private inner class PlayerInjection(val player: HealthBarPlayer) : ChannelDuplexHandler() { private val serverPlayer = (player.player() as CraftPlayer).handle private val connection = serverPlayer.connection private val world = player.player().world @@ -327,26 +327,30 @@ class NMSImpl: NMS { val set = HashSet(plugin.healthBarManager().allHealthBars().filter { it.isDefault && it.triggers().contains(trigger) }) - fun add() { + fun add(sync: Boolean = false) { val bukkit = e.bukkitEntity if (bukkit is CraftLivingEntity && bukkit.isValid) { val adapt = plugin.mobManager().entity(if (bukkit is Player) foliaAdapt(bukkit) else foliaAdapt(bukkit)) val types = adapt.mob()?.configuration()?.types() val packet = PacketTrigger(trigger, handle) - set.filter { - (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> - types.contains(t) - }) - }.forEach { - player.showHealthBar(it, packet, adapt) - } - adapt.mob()?.configuration()?.healthBars()?.forEach { - player.showHealthBar(it, packet, adapt) + val run = Runnable { + set.filter { + (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> + types.contains(t) + }) + }.forEach { + player.showHealthBar(it, packet, adapt) + } + adapt.mob()?.configuration()?.healthBars()?.forEach { + player.showHealthBar(it, packet, adapt) + } } + if (sync) plugin.scheduler().asyncTask(run) + else run.run() } } if (plugin.isFolia) plugin.scheduler().task(world, e.x.toInt() shr 4, e.z.toInt() shr 4) { - add() + add(true) } else add() } } diff --git a/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt b/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt index 6af91ce..34648f7 100644 --- a/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt +++ b/nms/v1_20_R2/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R2/NMSImpl.kt @@ -56,7 +56,7 @@ import kotlin.math.atan2 import kotlin.math.sqrt @Suppress("UNUSED") -class NMSImpl: NMS { +class NMSImpl : NMS { private val plugin get() = BetterHealthBar.inst() @@ -294,7 +294,7 @@ class NMSImpl: NMS { injectionMap.remove(player.player().uniqueId)?.uninject() } - private inner class PlayerInjection(val player: HealthBarPlayer): ChannelDuplexHandler() { + private inner class PlayerInjection(val player: HealthBarPlayer) : ChannelDuplexHandler() { private val serverPlayer = (player.player() as CraftPlayer).handle private val connection = serverPlayer.connection private val world = player.player().world @@ -323,26 +323,30 @@ class NMSImpl: NMS { val set = HashSet(plugin.healthBarManager().allHealthBars().filter { it.isDefault && it.triggers().contains(trigger) }) - fun add() { + fun add(sync: Boolean = false) { val bukkit = e.bukkitEntity if (bukkit is CraftLivingEntity && bukkit.isValid) { val adapt = plugin.mobManager().entity(if (bukkit is Player) foliaAdapt(bukkit) else foliaAdapt(bukkit)) val types = adapt.mob()?.configuration()?.types() val packet = PacketTrigger(trigger, handle) - set.filter { - (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> - types.contains(t) - }) - }.forEach { - player.showHealthBar(it, packet, adapt) - } - adapt.mob()?.configuration()?.healthBars()?.forEach { - player.showHealthBar(it, packet, adapt) + val run = Runnable { + set.filter { + (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> + types.contains(t) + }) + }.forEach { + player.showHealthBar(it, packet, adapt) + } + adapt.mob()?.configuration()?.healthBars()?.forEach { + player.showHealthBar(it, packet, adapt) + } } + if (sync) plugin.scheduler().asyncTask(run) + else run.run() } } if (plugin.isFolia) plugin.scheduler().task(world, e.x.toInt() shr 4, e.z.toInt() shr 4) { - add() + add(true) } else add() } } diff --git a/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt b/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt index d6a7e16..c1c00aa 100644 --- a/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt +++ b/nms/v1_20_R3/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R3/NMSImpl.kt @@ -56,7 +56,7 @@ import kotlin.math.atan2 import kotlin.math.sqrt @Suppress("UNUSED") -class NMSImpl: NMS { +class NMSImpl : NMS { private val plugin get() = BetterHealthBar.inst() @@ -294,7 +294,7 @@ class NMSImpl: NMS { injectionMap.remove(player.player().uniqueId)?.uninject() } - private inner class PlayerInjection(val player: HealthBarPlayer): ChannelDuplexHandler() { + private inner class PlayerInjection(val player: HealthBarPlayer) : ChannelDuplexHandler() { private val serverPlayer = (player.player() as CraftPlayer).handle private val connection = serverPlayer.connection private val world = player.player().world @@ -323,26 +323,30 @@ class NMSImpl: NMS { val set = HashSet(plugin.healthBarManager().allHealthBars().filter { it.isDefault && it.triggers().contains(trigger) }) - fun add() { + fun add(sync: Boolean = false) { val bukkit = e.bukkitEntity if (bukkit is CraftLivingEntity && bukkit.isValid) { val adapt = plugin.mobManager().entity(if (bukkit is Player) foliaAdapt(bukkit) else foliaAdapt(bukkit)) val types = adapt.mob()?.configuration()?.types() val packet = PacketTrigger(trigger, handle) - set.filter { - (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> - types.contains(t) - }) - }.forEach { - player.showHealthBar(it, packet, adapt) - } - adapt.mob()?.configuration()?.healthBars()?.forEach { - player.showHealthBar(it, packet, adapt) + val run = Runnable { + set.filter { + (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> + types.contains(t) + }) + }.forEach { + player.showHealthBar(it, packet, adapt) + } + adapt.mob()?.configuration()?.healthBars()?.forEach { + player.showHealthBar(it, packet, adapt) + } } + if (sync) plugin.scheduler().asyncTask(run) + else run.run() } } if (plugin.isFolia) plugin.scheduler().task(world, e.x.toInt() shr 4, e.z.toInt() shr 4) { - add() + add(true) } else add() } } diff --git a/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt b/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt index 7edb98f..cc77639 100644 --- a/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt +++ b/nms/v1_20_R4/src/main/kotlin/kr/toxicity/healthbar/nms/v1_20_R4/NMSImpl.kt @@ -56,7 +56,7 @@ import kotlin.math.atan2 import kotlin.math.sqrt @Suppress("UNUSED") -class NMSImpl: NMS { +class NMSImpl : NMS { private val plugin get() = BetterHealthBar.inst() @@ -294,7 +294,7 @@ class NMSImpl: NMS { injectionMap.remove(player.player().uniqueId)?.uninject() } - private inner class PlayerInjection(val player: HealthBarPlayer): ChannelDuplexHandler() { + private inner class PlayerInjection(val player: HealthBarPlayer) : ChannelDuplexHandler() { private val serverPlayer = (player.player() as CraftPlayer).handle private val world = player.player().world private val connection = serverPlayer.connection @@ -323,26 +323,30 @@ class NMSImpl: NMS { val set = HashSet(plugin.healthBarManager().allHealthBars().filter { it.triggers().contains(trigger) }) - fun add() { + fun add(sync: Boolean = false) { val bukkit = e.bukkitEntity if (bukkit is CraftLivingEntity && bukkit.isValid) { val adapt = plugin.mobManager().entity(if (bukkit is Player) foliaAdapt(bukkit) else foliaAdapt(bukkit)) val types = adapt.mob()?.configuration()?.types() val packet = PacketTrigger(trigger, handle) - set.filter { - (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> - types.contains(t) - }) - }.forEach { - player.showHealthBar(it, packet, adapt) - } - adapt.mob()?.configuration()?.healthBars()?.forEach { - player.showHealthBar(it, packet, adapt) + val run = Runnable { + set.filter { + (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> + types.contains(t) + }) + }.forEach { + player.showHealthBar(it, packet, adapt) + } + adapt.mob()?.configuration()?.healthBars()?.forEach { + player.showHealthBar(it, packet, adapt) + } } + if (sync) plugin.scheduler().asyncTask(run) + else run.run() } } if (plugin.isFolia) plugin.scheduler().task(world, e.x.toInt() shr 4, e.z.toInt() shr 4) { - add() + add(true) } else add() } } diff --git a/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt b/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt index 03f7a56..edad1ee 100644 --- a/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt +++ b/nms/v1_21_R1/src/main/kotlin/kr/toxicity/healthbar/nms/v1_21_R1/NMSImpl.kt @@ -56,7 +56,7 @@ import kotlin.math.atan2 import kotlin.math.sqrt @Suppress("UNUSED") -class NMSImpl: NMS { +class NMSImpl : NMS { private val plugin get() = BetterHealthBar.inst() @@ -306,7 +306,7 @@ class NMSImpl: NMS { injectionMap.remove(player.player().uniqueId)?.uninject() } - private inner class PlayerInjection(val player: HealthBarPlayer): ChannelDuplexHandler() { + private inner class PlayerInjection(val player: HealthBarPlayer) : ChannelDuplexHandler() { private val serverPlayer = (player.player() as CraftPlayer).handle private val world = player.player().world private val connection = serverPlayer.connection @@ -335,26 +335,30 @@ class NMSImpl: NMS { val set = HashSet(plugin.healthBarManager().allHealthBars().filter { it.triggers().contains(trigger) }) - fun add() { + fun add(sync: Boolean = false) { val bukkit = e.bukkitEntity if (bukkit is CraftLivingEntity && bukkit.isValid) { val adapt = plugin.mobManager().entity(if (bukkit is Player) foliaAdapt(bukkit) else foliaAdapt(bukkit)) val types = adapt.mob()?.configuration()?.types() val packet = PacketTrigger(trigger, handle) - set.filter { - (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> - types.contains(t) - }) - }.forEach { - player.showHealthBar(it, packet, adapt) - } - adapt.mob()?.configuration()?.healthBars()?.forEach { - player.showHealthBar(it, packet, adapt) + val run = Runnable { + set.filter { + (adapt.mob()?.configuration()?.ignoreDefault() != true && it.isDefault) || (types != null && it.applicableTypes().any { t -> + types.contains(t) + }) + }.forEach { + player.showHealthBar(it, packet, adapt) + } + adapt.mob()?.configuration()?.healthBars()?.forEach { + player.showHealthBar(it, packet, adapt) + } } + if (sync) plugin.scheduler().asyncTask(run) + else run.run() } } if (plugin.isFolia) plugin.scheduler().task(world, e.x.toInt() shr 4, e.z.toInt() shr 4) { - add() + add(true) } else add() } } diff --git a/scheduler/folia/src/main/kotlin/kr/toxicity/healthbar/scheduler/FoliaScheduler.kt b/scheduler/folia/src/main/kotlin/kr/toxicity/healthbar/scheduler/FoliaScheduler.kt index e5b2f09..4e482bf 100644 --- a/scheduler/folia/src/main/kotlin/kr/toxicity/healthbar/scheduler/FoliaScheduler.kt +++ b/scheduler/folia/src/main/kotlin/kr/toxicity/healthbar/scheduler/FoliaScheduler.kt @@ -8,7 +8,7 @@ import org.bukkit.Bukkit import org.bukkit.World import java.util.concurrent.TimeUnit -class FoliaScheduler: WrappedScheduler { +class FoliaScheduler : WrappedScheduler { private val plugin get() = BetterHealthBar.inst() @@ -19,6 +19,12 @@ class FoliaScheduler: WrappedScheduler { }.wrap() } + override fun asyncTask(runnable: Runnable): WrappedTask { + return Bukkit.getAsyncScheduler().runNow(plugin) { + runnable.run() + }.wrap() + } + override fun taskLater(delay: Long, runnable: Runnable): WrappedTask { return Bukkit.getGlobalRegionScheduler().runDelayed(plugin, { runnable.run() diff --git a/scheduler/standard/src/main/kotlin/kr/toxicity/healthbar/scheduler/StandardScheduler.kt b/scheduler/standard/src/main/kotlin/kr/toxicity/healthbar/scheduler/StandardScheduler.kt index 27dc842..f1f07da 100644 --- a/scheduler/standard/src/main/kotlin/kr/toxicity/healthbar/scheduler/StandardScheduler.kt +++ b/scheduler/standard/src/main/kotlin/kr/toxicity/healthbar/scheduler/StandardScheduler.kt @@ -7,7 +7,7 @@ import org.bukkit.Bukkit import org.bukkit.World import org.bukkit.scheduler.BukkitTask -class StandardScheduler: WrappedScheduler { +class StandardScheduler : WrappedScheduler { private val plugin get() = BetterHealthBar.inst() @@ -15,6 +15,9 @@ class StandardScheduler: WrappedScheduler { override fun task(runnable: Runnable): WrappedTask { return Bukkit.getScheduler().runTask(plugin, runnable).wrap() } + override fun asyncTask(runnable: Runnable): WrappedTask { + return Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable).wrap() + } override fun taskLater(delay: Long, runnable: Runnable): WrappedTask { return Bukkit.getScheduler().runTaskLater(plugin, runnable, delay).wrap() }