diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/betteritem/BetterSlimefunItem.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/betteritem/BetterSlimefunItem.kt index 81b65d1..e2a63ad 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/betteritem/BetterSlimefunItem.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/betteritem/BetterSlimefunItem.kt @@ -107,14 +107,14 @@ open class BetterSlimefunItem : SlimefunItem { } else if (method.isAnnotationPresent(Ticker::class.java)) { method.isAccessible = true val handle = MethodHandles.lookup().unreflect(method).bindTo(this) - val ticker = method.getAnnotation(Ticker::class.java) + val isSync = !method.getAnnotation(Ticker::class.java).async addItemHandler(object : BlockTicker() { override fun tick(b: Block, item: SlimefunItem, data: Config) { handle.invoke(b) } override fun isSynchronized(): Boolean { - return !ticker.async + return isSync } }) } diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/Mass.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/blocks/ItemMass.kt similarity index 94% rename from plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/Mass.kt rename to plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/blocks/ItemMass.kt index 55572fd..be2ba9c 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/Mass.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/blocks/ItemMass.kt @@ -1,6 +1,5 @@ -package io.github.addoncommunity.galactifun.util.items +package io.github.addoncommunity.galactifun.api.blocks -import io.github.addoncommunity.galactifun.api.blocks.CustomMass import io.github.addoncommunity.galactifun.units.Mass import io.github.addoncommunity.galactifun.units.Mass.Companion.kilograms import io.github.addoncommunity.galactifun.units.Mass.Companion.tons diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt index e9aee35..51a191a 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/rockets/RocketInfo.kt @@ -1,13 +1,13 @@ package io.github.addoncommunity.galactifun.api.rockets import io.github.addoncommunity.galactifun.EARTH_GRAVITY +import io.github.addoncommunity.galactifun.api.blocks.wetMass import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas import io.github.addoncommunity.galactifun.impl.items.FuelTank import io.github.addoncommunity.galactifun.impl.items.RocketEngine import io.github.addoncommunity.galactifun.impl.managers.PlanetManager import io.github.addoncommunity.galactifun.units.* import io.github.addoncommunity.galactifun.util.general.mergeMaps -import io.github.addoncommunity.galactifun.util.items.wetMass import io.github.addoncommunity.galactifun.util.processSlimefunBlocks import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition import kotlin.math.ln diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/FuelTank.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/FuelTank.kt index 9ad2757..358c1cc 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/FuelTank.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/FuelTank.kt @@ -1,5 +1,7 @@ package io.github.addoncommunity.galactifun.impl.items +import io.github.addoncommunity.galactifun.api.betteritem.BetterSlimefunItem +import io.github.addoncommunity.galactifun.api.betteritem.Ticker import io.github.addoncommunity.galactifun.api.blocks.CustomMass import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas import io.github.addoncommunity.galactifun.units.* @@ -8,7 +10,6 @@ import io.github.addoncommunity.galactifun.util.bukkit.adjacentFaces import io.github.addoncommunity.galactifun.util.checkBlock import io.github.addoncommunity.galactifun.util.general.enumMapOf import io.github.addoncommunity.galactifun.util.general.mergeMaps -import io.github.addoncommunity.galactifun.util.items.TickingBlock import io.github.addoncommunity.galactifun.util.menu.buildMenu import io.github.seggan.sf4k.serial.blockstorage.getBlockStorage import io.github.seggan.sf4k.serial.blockstorage.setBlockStorage @@ -30,7 +31,7 @@ class FuelTank( recipeType: RecipeType, recipe: Array, private val capacity: Volume -) : TickingBlock(itemGroup, item, recipeType, recipe), CustomMass { +) : BetterSlimefunItem(itemGroup, item, recipeType, recipe), CustomMass { private companion object { private const val INPUT = 4 @@ -45,7 +46,8 @@ class FuelTank( } } - override fun tick(b: Block) { + @Ticker + private fun tick(b: Block) { val menu = BlockStorage.getInventory(b) val item = menu.getItemInSlot(INPUT) val gasItem = getByItem(item) diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/McUtils.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/McUtils.kt index 72d7600..99598ab 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/McUtils.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/McUtils.kt @@ -12,6 +12,7 @@ import org.bukkit.* import org.bukkit.entity.Entity import org.bukkit.event.player.PlayerTeleportEvent import org.bukkit.inventory.ItemStack +import org.bukkit.util.Vector import java.util.* import java.util.concurrent.CompletableFuture @@ -26,6 +27,8 @@ fun Location.copy( pitch: Float = this.pitch ): Location = Location(world, x, y, z, yaw, pitch) +fun Vector.copy(x: Double = this.x, y: Double = this.y, z: Double = this.z): Vector = Vector(x, y, z) + inline fun World.nearbyEntitiesByType( location: Location, radius: Double, diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/SusUtils.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/SusUtils.kt index 84caa5f..f646345 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/SusUtils.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/SusUtils.kt @@ -7,35 +7,10 @@ import io.github.addoncommunity.galactifun.pluginInstance import io.github.thebusybiscuit.slimefun4.utils.ChatUtils import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay -import kotlinx.coroutines.suspendCancellableCoroutine -import org.bukkit.Bukkit import org.bukkit.entity.Player -import org.bukkit.event.* import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine -suspend inline fun waitForEvent( - priority: EventPriority = EventPriority.NORMAL, - cancelIfEventCancelled: Boolean = false -): E { - return suspendCancellableCoroutine { cont -> - Bukkit.getPluginManager().registerEvent( - E::class.java, - object : Listener {}, - priority, - { listener, event -> - HandlerList.unregisterAll(listener) - if (cancelIfEventCancelled && event is Cancellable && event.isCancelled) { - cont.cancel() - } else { - cont.resume(event as E) - } - }, - pluginInstance - ) - } -} - suspend fun Player.awaitChatInput(): String { return suspendCoroutine { cont -> ChatUtils.awaitInput(this) { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/IntPair.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/IntPair.kt deleted file mode 100644 index 4ab366c..0000000 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/IntPair.kt +++ /dev/null @@ -1,5 +0,0 @@ -package io.github.addoncommunity.galactifun.util.general - -data class IntPair(val first: Int, val second: Int) - -infix fun Int.with(that: Int) = IntPair(this, that) diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/LazyDouble.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/LazyDouble.kt index 69cecaf..3273243 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/LazyDouble.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/general/LazyDouble.kt @@ -6,6 +6,7 @@ class LazyDouble(private val supplier: () -> Double) { private var value = Double.NaN private var initialized = false + operator fun getValue(thisRef: Any?, property: KProperty<*>): Double { if (!initialized) { value = supplier() diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/TickingBlock.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/TickingBlock.kt deleted file mode 100644 index 075132c..0000000 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/TickingBlock.kt +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.addoncommunity.galactifun.util.items - -import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack -import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType -import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config -import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker -import org.bukkit.block.Block -import org.bukkit.inventory.ItemStack - -abstract class TickingBlock( - itemGroup: ItemGroup, - item: SlimefunItemStack, - recipeType: RecipeType, - recipe: Array -) : SlimefunItem(itemGroup, item, recipeType, recipe) { - - protected open val tickSync = true - - init { - addItemHandler(object : BlockTicker() { - override fun isSynchronized() = tickSync - override fun tick(b: Block, item: SlimefunItem, data: Config) = tick(b) - }) - } - - protected abstract fun tick(b: Block) -} \ No newline at end of file