File tree Expand file tree Collapse file tree 3 files changed +24
-10
lines changed
bukkit/src/main/kotlin/io/github/rothes/esu/bukkit Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package io.github.rothes.esu.bukkit.module.essentialcommands
33import io.github.rothes.esu.bukkit.user
44import io.github.rothes.esu.bukkit.user.PlayerUser
55import io.github.rothes.esu.bukkit.util.ComponentBukkitUtils.player
6+ import io.github.rothes.esu.bukkit.util.scheduler.Scheduler.syncTick
67import io.github.rothes.esu.core.command.annotation.ShortPerm
78import io.github.rothes.esu.core.configuration.data.MessageData
89import io.github.rothes.esu.core.configuration.data.MessageData.Companion.message
@@ -26,12 +27,14 @@ object Feed : BaseCommand<FeatureToggle.DefaultTrue, Feed.Lang>() {
2627 @Command(" feed <player>" )
2728 @ShortPerm(" others" )
2829 fun feed (sender : User , player : Player , @Flag(" silent" ) silent : Boolean = sender.uuid != player.uniqueId) {
29- player.foodLevel = 20
30- player.saturation = 20.0f // 5.0f on respawn
31- player.exhaustion = 0.0f
32- sender.message(lang, { fedPlayer }, player(player))
33- if (! silent) {
34- player.user.message(lang, { fed })
30+ player.syncTick {
31+ player.foodLevel = 20
32+ player.saturation = 20.0f // 5.0f on respawn
33+ player.exhaustion = 0.0f
34+ sender.message(lang, { fedPlayer }, player(player))
35+ if (! silent) {
36+ player.user.message(lang, { fed })
37+ }
3538 }
3639 }
3740 })
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package io.github.rothes.esu.bukkit.module.essentialcommands
33import io.github.rothes.esu.bukkit.user
44import io.github.rothes.esu.bukkit.user.PlayerUser
55import io.github.rothes.esu.bukkit.util.ComponentBukkitUtils.player
6+ import io.github.rothes.esu.bukkit.util.scheduler.Scheduler.syncTick
67import io.github.rothes.esu.bukkit.util.version.adapter.AttributeAdapter
78import io.github.rothes.esu.core.command.annotation.ShortPerm
89import io.github.rothes.esu.core.configuration.data.MessageData
@@ -27,10 +28,12 @@ object Heal : BaseCommand<FeatureToggle.DefaultTrue, Heal.Lang>() {
2728 @Command(" heal <player>" )
2829 @ShortPerm(" others" )
2930 fun heal (sender : User , player : Player , @Flag(" silent" ) silent : Boolean = sender.uuid != player.uniqueId) {
30- player.heal(player.getAttribute(AttributeAdapter .MAX_HEALTH )!! .value)
31- sender.message(lang, { healedPlayer }, player(player))
32- if (! silent) {
33- player.user.message(lang, { healed })
31+ player.syncTick {
32+ player.heal(player.getAttribute(AttributeAdapter .MAX_HEALTH )!! .value)
33+ sender.message(lang, { healedPlayer }, player(player))
34+ if (! silent) {
35+ player.user.message(lang, { healed })
36+ }
3437 }
3538 }
3639 })
Original file line number Diff line number Diff line change 11package io.github.rothes.esu.bukkit.util.scheduler
22
33import io.github.rothes.esu.bukkit.util.ServerCompatibility.isFolia
4+ import io.github.rothes.esu.bukkit.util.version.adapter.TickThreadAdapter.Companion.checkTickThread
45import kotlinx.coroutines.CompletableDeferred
56import org.bukkit.Bukkit
67import org.bukkit.Location
@@ -120,6 +121,13 @@ object Scheduler {
120121 return schedule(this , plugin, func)
121122 }
122123
124+ fun Entity.syncTick (plugin : Plugin = esuPlugin, func : () -> Unit ) {
125+ if (checkTickThread())
126+ func()
127+ else
128+ schedule(this , plugin, func)
129+ }
130+
123131 fun cancelTasks (plugin : Plugin = esuPlugin) {
124132 if (isFolia) {
125133 Bukkit .getGlobalRegionScheduler().cancelTasks(plugin)
You can’t perform that action at this time.
0 commit comments