Skip to content

Commit

Permalink
Various doodads
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed May 22, 2024
1 parent 1d1f713 commit 8c1d347
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.settings
/target
/.idea
/.kotlin
*.iml
.project
.classpath
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm") version "1.9.23" apply false
kotlin("jvm") version "2.0.0" apply false
}

allprojects {
Expand Down
4 changes: 2 additions & 2 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
kotlin("jvm")
kotlin("plugin.serialization") version "1.9.23"
id("com.google.devtools.ksp") version "1.9.23-1.0.20"
id("com.google.devtools.ksp") version "2.0.0-1.0.21"

id("com.github.johnrengelman.shadow") version "8.1.1"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
Expand Down Expand Up @@ -62,7 +62,7 @@ kotlin {
}

tasks.compileKotlin {
kotlinOptions.javaParameters = true
compilerOptions.javaParameters = true
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType
import org.bukkit.Material
import kotlin.time.Duration.Companion.seconds

@Suppress("unused")
object GalactifunItems {

val COMMAND_COMPUTER = buildSlimefunItem<CommandComputer> {
Expand Down Expand Up @@ -40,7 +41,7 @@ object GalactifunItems {
+"<yellow>Capacity: 1000 L"
}

val ROCKET_ENGINE_I = buildSlimefunItem<RocketEngine>(300.seconds, 100.kilonewtons, Gas.HYDROGEN) {
val ROCKET_ENGINE_I = buildSlimefunItem<RocketEngine>(3000.seconds, 100.kilonewtons, Gas.HYDROGEN) {
category = GalactifunCategories.ROCKET_COMPONENTS
id = "ROCKET_ENGINE_I"
name = "<white>BMR-50 \"Lil' Boomer\""
Expand All @@ -52,7 +53,7 @@ object GalactifunItems {
+""
+"<gray>Manufacturer: Boomer & Bros. Explosives, Inc."
+"<yellow>Thrust: 100 kN"
+"<yellow>Specific impulse: 300 s"
+"<yellow>Specific impulse: 3000 s"
+"<yellow>Fuel: Hydrogen"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.addoncommunity.galactifun.util

import io.github.addoncommunity.galactifun.pluginInstance
import kotlinx.coroutines.suspendCancellableCoroutine
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.TextComponent
import net.kyori.adventure.text.format.TextColor
Expand All @@ -9,9 +10,11 @@ import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import org.bukkit.*
import org.bukkit.entity.Entity
import org.bukkit.event.*
import org.bukkit.event.player.PlayerTeleportEvent
import org.bukkit.metadata.FixedMetadataValue
import java.util.concurrent.CompletableFuture
import kotlin.coroutines.resume

fun String.key(): NamespacedKey = NamespacedKey(pluginInstance, this)

Expand Down Expand Up @@ -65,3 +68,25 @@ fun String.miniMessageToLegacy(): String =
fun locationZero(world: World?): Location {
return Location(world, 0.0, 0.0, 0.0)
}

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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.github.addoncommunity.galactifun.api.objects.MilkyWay
import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject
import io.github.addoncommunity.galactifun.api.objects.Star
import io.github.addoncommunity.galactifun.impl.managers.PlanetManager
import io.github.addoncommunity.galactifun.util.PlanetMenu.PlanetClickHandler
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils
import kotlinx.datetime.Clock
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu
Expand All @@ -20,14 +19,15 @@ import org.bukkit.inventory.ItemStack
import java.util.*
import kotlin.collections.ArrayDeque

class PlanetMenu(
private val exitHandler: MenuClickHandler = MenuClickHandler { p, _, _, _ -> p.closeInventory(); false },
private val clickHandler: PlanetClickHandler = PlanetClickHandler { _, _, _ -> true },
private val modifier: (Player, CelestialObject, ItemStack) -> ItemStack = { _, _, item -> item }
) {
open class PlanetMenu {

private val history = mutableMapOf<UUID, ArrayDeque<CelestialObject>>()

private val exitHandler = MenuClickHandler { player, _, _, _ ->
onExit(player)
false
}

fun open(p: Player) {
openGalaxy(p)
}
Expand Down Expand Up @@ -100,23 +100,45 @@ class PlanetMenu(
}
val item = to.item.clone()
item.lore(info)
menu[i] = modifier(p, to, item)
menu[i] = modifyItem(p, to, item)
menu[i] = MenuClickHandler { _, _, _, action ->
if (clickHandler.onClick(p, to, action) && to.orbiters.isNotEmpty()) {
if (onClick(p, to, action) && to.orbiters.isNotEmpty()) {
history.getOrPut(p.uniqueId, ::ArrayDeque).addLast(from)
open(p, to)
}
false
}
}

fun interface PlanetClickHandler {
/**
* @param p The player who clicked
* @param obj The celestial object that was clicked
* @param action The action that was performed
* @return True if the menu should open the planet's children
*/
fun onClick(p: Player, obj: CelestialObject, action: ClickAction): Boolean
/**
* Called when the menu is closed
*
* @param p The player who closed the menu
*/
open fun onExit(p: Player) {
p.closeInventory()
}

/**
* Called when a player clicks on a celestial object
*
* @param p The player who clicked
* @param obj The celestial object that was clicked
* @param action The action that was performed
* @return `true` if the menu should open the planet's children
*/
open fun onClick(p: Player, obj: CelestialObject, action: ClickAction): Boolean {
return true
}

/**
* Modifies the item that represents a celestial object
*
* @param p The player who is viewing the menu
* @param obj The celestial object that is being displayed
* @param item The item that represents the celestial object
*/
open fun modifyItem(p: Player, obj: CelestialObject, item: ItemStack): ItemStack {
return item
}
}
2 changes: 1 addition & 1 deletion uom-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = "0.1-SNAPSHOT"
dependencies {
implementation(kotlin("stdlib"))
implementation(project(":uom"))
implementation("com.google.devtools.ksp:symbol-processing-api:1.9.22-1.0.17")
implementation("com.google.devtools.ksp:symbol-processing-api:2.0.0-1.0.21")
implementation("com.squareup:kotlinpoet-ksp:1.16.0")
}

Expand Down
2 changes: 1 addition & 1 deletion uom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "io.github.seggan"
version = "unspecified"
version = "0.1.0"

kotlin {
jvmToolchain(17)
Expand Down

0 comments on commit 8c1d347

Please sign in to comment.