Skip to content

Commit

Permalink
Clean up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Sep 18, 2024
1 parent 01cdc39 commit dd550c2
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*
Expand All @@ -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
Expand All @@ -30,7 +31,7 @@ class FuelTank(
recipeType: RecipeType,
recipe: Array<out ItemStack?>,
private val capacity: Volume
) : TickingBlock(itemGroup, item, recipeType, recipe), CustomMass {
) : BetterSlimefunItem(itemGroup, item, recipeType, recipe), CustomMass {

private companion object {
private const val INPUT = 4
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <reified T : Entity> World.nearbyEntitiesByType(
location: Location,
radius: Double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <reified E : Event> 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) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

This file was deleted.

0 comments on commit dd550c2

Please sign in to comment.