Skip to content

Commit

Permalink
Bumps version.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed May 11, 2024
1 parent c288398 commit 38e7858
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import kr.toxicity.healthbar.api.nms.NMS;
import kr.toxicity.healthbar.api.plugin.ReloadResult;
import kr.toxicity.healthbar.api.scheduler.WrappedScheduler;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -38,6 +39,7 @@ public final void onLoad() {
public abstract @NotNull ModelEngineAdapter modelEngine();
public abstract @NotNull BedrockAdapter bedrock();
public abstract @NotNull MiniMessage miniMessage();
public abstract @NotNull BukkitAudiences audiences();
public abstract void loadAssets(@NotNull String prefix, @NotNull BiConsumer<String, InputStream> consumer);
public abstract void loadAssets(@NotNull String prefix, @NotNull File dir);

Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ allprojects {
apply(plugin = "kotlin")
apply(plugin = "org.jetbrains.dokka")
group = "kr.toxicity.healthbar"
version = "3.0-alpha-2"
version = "3.0-alpha-3"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
Expand Down Expand Up @@ -122,12 +122,12 @@ dependencies {
implementation(getProject("bedrock:floodgate").spigot().dependency("org.geysermc.floodgate:api:2.2.2-SNAPSHOT"))
implementation(getProject("modelengine:legacy").spigot().dependency("com.ticxo.modelengine:api:R3.2.0"))
implementation(getProject("modelengine:current").spigot().dependency("com.ticxo.modelengine:ModelEngine:R4.0.6"))
legacyNms.forEach {
ArrayList<NmsVersion>().apply {
addAll(legacyNms)
addAll(currentNms)
}.forEach {
implementation(project(":nms:${it.name}", configuration = "reobf"))
}
currentNms.forEach {
implementation(it.project)
}
}

val sourceJar by tasks.creating(Jar::class.java) {
Expand Down
41 changes: 41 additions & 0 deletions dist/src/main/kotlin/kr/toxicity/healthbar/BetterHealthBarImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ import kr.toxicity.healthbar.scheduler.StandardScheduler
import kr.toxicity.healthbar.util.*
import kr.toxicity.healthbar.version.MinecraftVersion
import kr.toxicity.healthbar.version.ModelEngineVersion
import net.kyori.adventure.platform.bukkit.BukkitAudiences
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.event.ClickEvent
import net.kyori.adventure.text.minimessage.MiniMessage
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import java.io.File
import java.io.InputStream
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.text.DecimalFormat
import java.util.concurrent.CompletableFuture
import java.util.function.BiConsumer
Expand All @@ -44,6 +54,7 @@ class BetterHealthBarImpl: BetterHealthBar() {
private var bedrock = BedrockAdapter.NONE
private var modelEngine = ModelEngineAdapter.NONE
private lateinit var nms: NMS
private lateinit var audiences: BukkitAudiences
private val scheduler = if (isFolia) FoliaScheduler() else StandardScheduler()

private val managers = listOf(
Expand Down Expand Up @@ -94,6 +105,7 @@ class BetterHealthBarImpl: BetterHealthBar() {
log.add("Floodgate support enabled.")
bedrock = FloodgateAdapter()
}
audiences = BukkitAudiences.create(this)
getCommand("healthbar")?.setExecutor { commandSender, _, _, _ ->
if (commandSender.hasPermission("betterhealthbar.reload")) {
commandSender.sendMessage("Starts reloading. please wait...")
Expand Down Expand Up @@ -124,6 +136,34 @@ class BetterHealthBarImpl: BetterHealthBar() {
}
}
}
runWithHandleException("Unable to get latest version.") {
HttpClient.newHttpClient().sendAsync(
HttpRequest.newBuilder()
.uri(URI.create("https://api.spigotmc.org/legacy/update.php?resource=116619/"))
.GET()
.build(), HttpResponse.BodyHandlers.ofString()
).thenAccept {
val body = it.body()
if (description.version != body) {
warn("New version found: $body")
warn("Download: https://www.spigotmc.org/resources/116619")
Bukkit.getPluginManager().registerEvents(object : Listener {
@EventHandler
fun join(e: PlayerJoinEvent) {
val player = e.player
if (player.isOp) {
player.info(Component.text("New BetterHealthBar version found: $body"))
player.info(Component.text("Download: https://www.spigotmc.org/resources/115559")
.clickEvent(ClickEvent.clickEvent(
ClickEvent.Action.OPEN_URL,
"https://www.spigotmc.org/resources/115559"
)))
}
}
}, this)
}
}
}
}

override fun reload(): ReloadResult {
Expand Down Expand Up @@ -193,6 +233,7 @@ class BetterHealthBarImpl: BetterHealthBar() {
override fun textManager(): TextManager = TextManagerImpl
override fun placeholderManager(): PlaceholderManager = PlaceholderManagerImpl
override fun mobManager(): MobManager = MobManagerImpl
override fun audiences(): BukkitAudiences = audiences

override fun onDisable() {
runWithHandleException("Error has occurred while disabling.") {
Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/kotlin/kr/toxicity/healthbar/util/Lists.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun <T> List<T>.forEachAsync(block: (T) -> Unit) {
val queue = LinkedList<() -> Unit>()
var i = 0
val add = (size.toDouble() / available).toInt()
while (i < size) {
while (i <= size) {
val get = subList(i, (i + add).coerceAtMost(size))
queue.add {
get.forEach { t ->
Expand Down
26 changes: 26 additions & 0 deletions dist/src/main/kotlin/kr/toxicity/healthbar/util/Senders.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package kr.toxicity.healthbar.util

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextDecoration
import org.bukkit.command.CommandSender

val PREFIX = Component.text()
.content("[$NAMESPACE]")
.color(NamedTextColor.AQUA)
.build()

private val EMPTY_DECORATION = TextDecoration.entries.associateWith {
TextDecoration.State.FALSE
}

val CommandSender.adventure
get() = PLUGIN.audiences().sender(this)

fun CommandSender.info(component: Component) = adventure.sendMessage(
Component.text()
.decorations(EMPTY_DECORATION)
.append(PREFIX)
.append(component)
.build()
)

0 comments on commit 38e7858

Please sign in to comment.