Skip to content

Commit a331320

Browse files
committed
Bug fixes.
1 parent 621b5ec commit a331320

File tree

5 files changed

+18
-53
lines changed

5 files changed

+18
-53
lines changed

bootstrap/bukkit/src/main/resources/plugin.yml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ api-version: 1.17
55
author: toxicity
66
description: Make a hud in minecraft!
77
folia-supported: true
8-
load: STARTUP
98
website: "https://www.spigotmc.org/resources/115559"
109
softdepend:
1110
- MythicLib

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ val platform = "4.3.4"
3232
val targetJavaVersion = 21
3333
val velocity = "3.4.0"
3434
val bStats = "3.1.0"
35-
val betterCommand = "52e73bee1c"
35+
val betterCommand = "1.0"
3636

3737
val supportedMinecraftVersions = listOf(
3838
//1.17

dist/src/main/kotlin/kr/toxicity/hud/manager/CommandManager.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import net.kyori.adventure.text.Component
3030
import net.kyori.adventure.text.minimessage.MiniMessage
3131
import java.io.File
3232
import java.text.DecimalFormat
33-
import java.util.concurrent.CompletableFuture
3433

3534
object CommandManager : BetterHudManager {
3635

@@ -128,7 +127,7 @@ object CommandManager : BetterHudManager {
128127
@Permission("hud.reload")
129128
fun reload(@Source me: BetterCommandSource) {
130129
reload_tryReload.send(me)
131-
CompletableFuture.runAsync {
130+
asyncTask {
132131
when (val reload = PLUGIN.reload()) {
133132
is OnReload -> reload_onReload.send(me)
134133
is Success -> reload_success.send(me, mapOf("time" to reload.time.withDecimal()))
@@ -151,7 +150,7 @@ object CommandManager : BetterHudManager {
151150
@Permission("hud.generate")
152151
fun generate(@Source me: BetterCommandSource) {
153152
generate_tryGenerate.send(me)
154-
CompletableFuture.runAsync {
153+
asyncTask {
155154
val locale = me.locale()
156155
val localeString = mapOf("name" to Component.text(locale.toString()))
157156
if (library.generateDefaultLang(locale)) generate_success.send(me, localeString)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package kr.toxicity.hud.util
22

3-
import java.util.*
3+
import java.util.concurrent.CompletableFuture
4+
import java.util.concurrent.Executors
5+
import kotlin.collections.ArrayList
46

57
fun <T> List<T>.split(splitSize: Int): List<List<T>> {
68
val result = ArrayList<List<T>>()
@@ -25,16 +27,6 @@ fun <T> Collection<T>.forEachAsync(block: (T) -> Unit) {
2527
toList().forEachAsync(block)
2628
}
2729

28-
fun <T> List<T>.forEachSync(block: (T) -> Unit) {
29-
synchronized(this) {
30-
val iterator = iterator()
31-
synchronized(iterator) {
32-
while (iterator.hasNext()) {
33-
block(iterator.next())
34-
}
35-
}
36-
}
37-
}
3830
fun <T> MutableCollection<T>.removeIfSync(block: (T) -> Boolean) {
3931
synchronized(this) {
4032
val iterator = iterator()
@@ -50,14 +42,14 @@ fun <T> MutableCollection<T>.removeIfSync(block: (T) -> Boolean) {
5042
fun <T> List<T>.forEachAsync(block: (T) -> Unit) {
5143
if (isNotEmpty()) {
5244
val available = Runtime.getRuntime().availableProcessors()
53-
val queue = if (available >= size) {
54-
LinkedList(map {
45+
val tasks = if (available >= size) {
46+
map {
5547
{
5648
block(it)
5749
}
58-
})
50+
}
5951
} else {
60-
val queue = LinkedList<() -> Unit>()
52+
val queue = ArrayList<() -> Unit>()
6153
var i = 0
6254
val add = (size.toDouble() / available).toInt()
6355
while (i <= size) {
@@ -71,29 +63,13 @@ fun <T> List<T>.forEachAsync(block: (T) -> Unit) {
7163
}
7264
queue
7365
}
74-
var i = 0
75-
object : Thread() {
76-
private val index = TaskIndex(queue.size)
77-
override fun run() {
78-
while (!isInterrupted) {
79-
queue.poll()?.let {
80-
val task = i++
81-
Thread {
82-
runWithExceptionHandling(CONSOLE, "Fail to run thread $task.") {
83-
it()
84-
}
85-
synchronized(index) {
86-
if (++index.current == index.max) {
87-
interrupt()
88-
}
89-
}
90-
}.start()
91-
}
92-
}
93-
}
94-
}.run {
95-
start()
96-
join()
97-
}
66+
val pool = Executors.newFixedThreadPool(tasks.size)
67+
CompletableFuture.allOf(
68+
*tasks.map {
69+
CompletableFuture.runAsync({
70+
it()
71+
}, pool)
72+
}.toTypedArray()
73+
).join()
9874
}
9975
}

dist/src/main/kotlin/kr/toxicity/hud/util/TaskIndex.kt

-9
This file was deleted.

0 commit comments

Comments
 (0)