diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index df99e6f..bf3c06f 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,9 +1,11 @@ +import net.minecrell.pluginyml.paper.PaperPluginDescription + plugins { kotlin("jvm") kotlin("plugin.serialization") id("com.gradleup.shadow") version "8.3.2" - id("net.minecrell.plugin-yml.bukkit") version "0.6.0" + id("net.minecrell.plugin-yml.paper") version "0.6.0" id("xyz.jpenilla.run-paper") version "2.3.0" id("io.github.seggan.uom") @@ -19,7 +21,7 @@ repositories { dependencies { fun DependencyHandlerScope.libraryAndTest(dependency: Any) { - library(dependency) + paperLibrary(dependency) testImplementation(dependency) } @@ -28,7 +30,7 @@ dependencies { testImplementation(dependency) } - library(kotlin("stdlib")) + paperLibrary(kotlin("stdlib")) libraryAndTest("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0-RC2") implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.5.0") // For some reason libraryloader doesn't like this libraryAndTest(kotlin("reflect")) @@ -74,8 +76,6 @@ tasks.test { } tasks.shadowJar { - dependsOn(tasks.test) - manifest { attributes["paperweight-mappings-namespace"] = "mojang" } @@ -107,15 +107,28 @@ tasks.shadowJar { archiveBaseName = "galactifun2" } -bukkit { +paper { name = rootProject.name main = "io.github.addoncommunity.galactifun.Galactifun2" + loader = "io.github.addoncommunity.galactifun.Galactifun2Loader" + bootstrapper = "io.github.addoncommunity.galactifun.Galactifun2Bootstrapper" version = project.version.toString() author = "Seggan" apiVersion = "1.20" - softDepend = listOf("ClayTech") - loadBefore = listOf("Multiverse-Core") - depend = listOf("Slimefun") + generateLibrariesJson = true + + serverDependencies { + register("Multiverse-Core") { + required = false + load = PaperPluginDescription.RelativeLoadOrder.AFTER + } + + register("Slimefun") { + required = true + load = PaperPluginDescription.RelativeLoadOrder.BEFORE + joinClasspath = true + } + } } tasks.runServer { diff --git a/plugin/src/main/java/io/github/addoncommunity/galactifun/Galactifun2Loader.java b/plugin/src/main/java/io/github/addoncommunity/galactifun/Galactifun2Loader.java new file mode 100644 index 0000000..74ebe1b --- /dev/null +++ b/plugin/src/main/java/io/github/addoncommunity/galactifun/Galactifun2Loader.java @@ -0,0 +1,51 @@ +package io.github.addoncommunity.galactifun; + +import com.google.gson.Gson; +import io.papermc.paper.plugin.loader.PluginClasspathBuilder; +import io.papermc.paper.plugin.loader.PluginLoader; +import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.repository.RemoteRepository; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +@SuppressWarnings("UnstableApiUsage") +public class Galactifun2Loader implements PluginLoader { + + @Override + public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) { + MavenLibraryResolver resolver = new MavenLibraryResolver(); + PluginLibraries pluginLibraries = load(); + pluginLibraries.asDependencies().forEach(resolver::addDependency); + pluginLibraries.asRepositories().forEach(resolver::addRepository); + classpathBuilder.addLibrary(resolver); + } + + private PluginLibraries load() { + try (var in = getClass().getResourceAsStream("/paper-libraries.json")) { + assert in != null; + return new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), PluginLibraries.class); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private record PluginLibraries(Map repositories, List dependencies) { + public Stream asDependencies() { + return dependencies.stream() + .map(d -> new Dependency(new DefaultArtifact(d), null)); + } + + public Stream asRepositories() { + return repositories.entrySet().stream() + .map(e -> new RemoteRepository.Builder(e.getKey(), "default", e.getValue()).build()); + } + } +} diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt index fcc848e..332d37f 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2.kt @@ -26,7 +26,6 @@ import io.github.seggan.sf4k.AbstractAddon import io.github.seggan.sf4k.serial.serializers.BukkitSerializerRegistry import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion import io.github.thebusybiscuit.slimefun4.implementation.Slimefun -import io.github.thebusybiscuit.slimefun4.libraries.paperlib.PaperLib import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.withContext @@ -48,38 +47,21 @@ import kotlin.script.experimental.host.toScriptSource import kotlin.time.Duration.Companion.days import kotlin.time.Duration.Companion.hours -open class Galactifun2 : AbstractAddon() { +object Galactifun2 : AbstractAddon() { private lateinit var manager: PaperCommandManager lateinit var launchMessages: List private set lateinit var structuresFolder: Path private set - var isTest = classLoader.javaClass.packageName.startsWith("be.seeseemelk.mockbukkit") - override suspend fun onLoadAsync() { - if (!isTest) { - Bukkit.spigot().config["world-settings.default.verbose"] = false - } BukkitSerializerRegistry.addSerializer(BlockVectorSerializer) } override suspend fun onEnableAsync() { - instance = this - var shouldDisable = false - if (!PaperLib.isPaper() && !isTest) { - logger.log(Level.SEVERE, "Galactifun2 only supports Paper and its forks (e.x. Airplane or Purpur)") - logger.log(Level.SEVERE, "Please use Paper or a fork of Paper") - shouldDisable = true - } - if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_19)) { - logger.log(Level.SEVERE, "Galactifun2 only supports Minecraft 1.19 and above") - logger.log(Level.SEVERE, "Please use Minecraft 1.19 or above") - shouldDisable = true - } - if (Bukkit.getPluginManager().isPluginEnabled("ClayTech")) { - logger.log(Level.SEVERE, "Galactifun2 will not work properly with ClayTech") - logger.log(Level.SEVERE, "Please disable ClayTech") + if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_20_5)) { + logger.log(Level.SEVERE, "Galactifun2 only supports Minecraft 1.20.5 and above") + logger.log(Level.SEVERE, "Please use Minecraft 1.20.5 or above") shouldDisable = true } if (Bukkit.getPluginManager().isPluginEnabled("Galactifun")) { @@ -93,9 +75,7 @@ open class Galactifun2 : AbstractAddon() { return } - if (!isTest) { - Metrics(this, 23447) - } + Metrics(this, 23447) manager = PaperCommandManager(this) manager.enableUnstableAPI("help") @@ -156,6 +136,8 @@ open class Galactifun2 : AbstractAddon() { GalactifunItems // Trigger static init + doTestingStuff() + launch { Bukkit.getConsoleSender().sendMessage( NamedTextColor.GREEN + """################# Galactifun2 $pluginVersion ################# @@ -166,8 +148,6 @@ open class Galactifun2 : AbstractAddon() { ###################################################""".trimIndent() ) } - - doTestingStuff() } override fun getJavaPlugin(): JavaPlugin = this @@ -237,14 +217,9 @@ open class Galactifun2 : AbstractAddon() { } } -private var instance: Galactifun2? = null - -val pluginInstance: Galactifun2 - get() = checkNotNull(instance) { "Plugin is not enabled" } - fun JavaPlugin.launchAsync( context: CoroutineContext = asyncDispatcher, block: suspend CoroutineScope.() -> Unit -): Job = pluginInstance.launch { +): Job = Galactifun2.launch { withContext(context, block) } \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2Bootstrapper.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2Bootstrapper.kt new file mode 100644 index 0000000..49beeb4 --- /dev/null +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2Bootstrapper.kt @@ -0,0 +1,18 @@ +package io.github.addoncommunity.galactifun + +import io.papermc.paper.plugin.bootstrap.BootstrapContext +import io.papermc.paper.plugin.bootstrap.PluginBootstrap +import io.papermc.paper.plugin.bootstrap.PluginProviderContext +import org.bukkit.plugin.java.JavaPlugin + +@Suppress("UnstableApiUsage") +class Galactifun2Bootstrapper : PluginBootstrap { + + override fun bootstrap(context: BootstrapContext) { + // Nothing to do here + } + + override fun createPlugin(context: PluginProviderContext): JavaPlugin { + return Galactifun2 + } +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/AlienWorld.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/AlienWorld.kt index de977e0..0a99fe7 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/AlienWorld.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/planet/AlienWorld.kt @@ -1,7 +1,7 @@ package io.github.addoncommunity.galactifun.api.objects.planet +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.api.objects.planet.gen.WorldGenerator -import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.util.general.log import org.bukkit.GameRule import org.bukkit.Material @@ -19,7 +19,7 @@ abstract class AlienWorld(name: String, baseItem: ItemStack) : PlanetaryWorld(na private val blockMappings = EnumMap(Material::class.java) override fun loadWorld(): World { - pluginInstance.logger.log("Loading world $name") + Galactifun2.logger.log("Loading world $name") val world = WorldCreator("world_galactifun_$id") .generator(generator) diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt index ae0e707..9068c4b 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/api/objects/properties/Orbit.kt @@ -1,8 +1,8 @@ package io.github.addoncommunity.galactifun.api.objects.properties import io.github.addoncommunity.galactifun.EARTH_GRAVITY +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.api.objects.CelestialObject -import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.units.* import io.github.addoncommunity.galactifun.units.Angle.Companion.radians import io.github.addoncommunity.galactifun.units.Distance.Companion.meters @@ -143,7 +143,7 @@ data class Orbit( } while (iterations++ != MAX_ITERATIONS && minDiff.radians > 1e-3) if (iterations == MAX_ITERATIONS + 1) { - pluginInstance.logger.warning("Failed to find a transfer orbit after $iterations iterations") + Galactifun2.logger.warning("Failed to find a transfer orbit after $iterations iterations") } return when (val transfer = transfers.minBy { it.key }.value) { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunItems.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunItems.kt index 95e500f..9151c0f 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunItems.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/GalactifunItems.kt @@ -1,8 +1,8 @@ package io.github.addoncommunity.galactifun.impl +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas import io.github.addoncommunity.galactifun.impl.items.* -import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.units.Force.Companion.kilonewtons import io.github.addoncommunity.galactifun.units.Volume.Companion.liters import io.github.addoncommunity.galactifun.util.items.MaterialType @@ -94,7 +94,7 @@ object GalactifunItems { init { for (gas in Gas.entries) { if (gas.item == null) continue - Gas.Item(GalactifunCategories.GASES, gas, RecipeType.NULL, emptyArray()).register(pluginInstance) + Gas.Item(GalactifunCategories.GASES, gas, RecipeType.NULL, emptyArray()).register(Galactifun2) } } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/CommandComputer.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/CommandComputer.kt index 35a94ec..614dece 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/CommandComputer.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/CommandComputer.kt @@ -2,6 +2,7 @@ package io.github.addoncommunity.galactifun.impl.items import com.destroystokyo.paper.ParticleBuilder import com.github.shynixn.mccoroutine.bukkit.launch +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.api.betteritem.BetterSlimefunItem import io.github.addoncommunity.galactifun.api.betteritem.ItemHandler import io.github.addoncommunity.galactifun.api.betteritem.Ticker @@ -9,7 +10,6 @@ import io.github.addoncommunity.galactifun.api.rockets.RocketInfo import io.github.addoncommunity.galactifun.impl.items.abstract.Seat import io.github.addoncommunity.galactifun.impl.managers.PlanetManager import io.github.addoncommunity.galactifun.impl.managers.RocketManager -import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.units.abs import io.github.addoncommunity.galactifun.util.* import io.github.addoncommunity.galactifun.util.bukkit.* @@ -66,7 +66,7 @@ class CommandComputer( private val frozenEntities = mutableSetOf() init { - Bukkit.getPluginManager().registerEvents(this, pluginInstance) + Bukkit.getPluginManager().registerEvents(this, Galactifun2) } @EventHandler @@ -136,7 +136,7 @@ class CommandComputer( && BlockStorage.check(seat) is CaptainsChair && seat.getBlockStorage("rocket") == pos ) { - RocketManager.launches += pluginInstance.launch { launchRocket(p, pos, info, seat) } + RocketManager.launches += Galactifun2.launch { launchRocket(p, pos, info, seat) } } else { e.player.sendMessage(NamedTextColor.GOLD + info.info) } @@ -207,7 +207,7 @@ class CommandComputer( var launched = false // Engine smoke - pluginInstance.launch { + Galactifun2.launch { while (!launched) { for ((_, engine) in firstStage.engines) { ParticleBuilder(Particle.CAMPFIRE_SIGNAL_SMOKE) @@ -221,7 +221,7 @@ class CommandComputer( } // Countdown - val launchMessages = ArrayDeque(pluginInstance.launchMessages) + val launchMessages = ArrayDeque(Galactifun2.launchMessages) launchMessages.shuffle() repeat(10) { val message = NamedTextColor.GOLD + "${launchMessages.removeFirst()}..." @@ -305,7 +305,7 @@ class CommandComputer( } for (entity in entities) { - pluginInstance.launch { + Galactifun2.launch { if (!entity.galactifunTeleport( dest + offsets[entity]!!.copy(world = PlanetManager.spaceWorld) ).await()) { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/SlimefunStructureBlock.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/SlimefunStructureBlock.kt index 869893c..a5c66e8 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/SlimefunStructureBlock.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/items/SlimefunStructureBlock.kt @@ -2,11 +2,11 @@ package io.github.addoncommunity.galactifun.impl.items import com.destroystokyo.paper.ParticleBuilder import com.github.shynixn.mccoroutine.bukkit.launch +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.api.betteritem.BetterSlimefunItem import io.github.addoncommunity.galactifun.api.betteritem.ItemHandler import io.github.addoncommunity.galactifun.api.betteritem.Ticker import io.github.addoncommunity.galactifun.impl.GalactifunHeads -import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.util.SlimefunStructure import io.github.addoncommunity.galactifun.util.bukkit.* import io.github.addoncommunity.galactifun.util.getValue @@ -89,7 +89,7 @@ class SlimefunStructureBlock( p.sendMessage(NamedTextColor.RED + "Please set a name first") return@onClick } - pluginInstance.structuresFolder.resolve("$name.nbt") + Galactifun2.structuresFolder.resolve("$name.nbt") .apply { deleteIfExists() } .createFile() .outputStream() @@ -117,7 +117,7 @@ class SlimefunStructureBlock( p.sendMessage(NamedTextColor.RED + "Please set a name first") return@onClick } - val structureFile = pluginInstance.structuresFolder.resolve("$name.nbt") + val structureFile = Galactifun2.structuresFolder.resolve("$name.nbt") if (!structureFile.exists()) { p.sendMessage(NamedTextColor.RED + "No structure found with name $name") return@onClick @@ -137,7 +137,7 @@ class SlimefunStructureBlock( +"Click to rename" onClick { p, _ -> - pluginInstance.launch { + Galactifun2.launch { p.closeInventory() p.sendMessage("Type the new name in chat") val name = p.awaitChatInput() @@ -318,7 +318,7 @@ class SlimefunStructureBlock( @ItemHandler(BlockUseHandler::class) private fun onClick(e: PlayerRightClickEvent) { e.cancel() - pluginInstance.launch { + Galactifun2.launch { delayTicks(1) BlockStorage.getInventory(e.clickedBlock.orElseThrow()).open(e.player) } diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/PlanetManager.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/PlanetManager.kt index 1d19004..b4dd8a8 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/PlanetManager.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/managers/PlanetManager.kt @@ -1,13 +1,13 @@ package io.github.addoncommunity.galactifun.impl.managers import com.github.shynixn.mccoroutine.bukkit.launch +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld import io.github.addoncommunity.galactifun.api.objects.properties.OrbitPosition import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere import io.github.addoncommunity.galactifun.impl.Permissions import io.github.addoncommunity.galactifun.impl.space.SpaceGenerator -import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.util.bukkit.getPdc import io.github.addoncommunity.galactifun.util.bukkit.key import io.github.addoncommunity.galactifun.util.bukkit.setPdc @@ -41,12 +41,12 @@ object PlanetManager : Listener { private val config = YamlConfiguration() init { - val configFile = pluginInstance.dataFolder.resolve("worlds.yml") + val configFile = Galactifun2.dataFolder.resolve("worlds.yml") if (configFile.exists()) { config.load(configFile) } - pluginInstance.launch { + Galactifun2.launch { config.options().copyDefaults(true) config.save(configFile) } @@ -61,7 +61,7 @@ object PlanetManager : Listener { orbits = spaceWorld.getPdc(orbitsKey) ?: mutableMapOf() - Bukkit.getPluginManager().registerEvents(this, pluginInstance) + Bukkit.getPluginManager().registerEvents(this, Galactifun2) } fun register(planet: PlanetaryObject) { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Earth.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Earth.kt index 0173a78..f84bac9 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Earth.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/impl/objects/earth/Earth.kt @@ -1,11 +1,11 @@ package io.github.addoncommunity.galactifun.impl.objects.earth +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.api.objects.planet.PlanetaryWorld import io.github.addoncommunity.galactifun.api.objects.properties.DayCycle import io.github.addoncommunity.galactifun.api.objects.properties.Orbit import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere import io.github.addoncommunity.galactifun.impl.BaseUniverse -import io.github.addoncommunity.galactifun.pluginInstance import io.github.addoncommunity.galactifun.units.Angle.Companion.degrees import io.github.addoncommunity.galactifun.units.Distance.Companion.au import io.github.addoncommunity.galactifun.units.Distance.Companion.kilometers @@ -31,7 +31,7 @@ class Earth : PlanetaryWorld("Earth", ItemStack(Material.GRASS_BLOCK)) { override val atmosphere = Atmosphere.EARTH_LIKE override fun loadWorld(): World { - val name = pluginInstance.config.getString("worlds.earth") ?: "world" + val name = Galactifun2.config.getString("worlds.earth") ?: "world" return WorldCreator(name).createWorld() // load the world ?: error("Failed to read earth world name from config; no default world found") } diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt index 44a1b51..3b5f067 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/scripting/ScriptDef.kt @@ -6,7 +6,6 @@ import io.github.addoncommunity.galactifun.api.objects.PlanetaryObject import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atmosphere import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Gas import io.github.addoncommunity.galactifun.impl.BaseUniverse -import io.github.addoncommunity.galactifun.pluginInstance import org.bukkit.Material import org.bukkit.World import org.bukkit.block.Biome @@ -71,7 +70,7 @@ object PlanetScriptHost : ScriptingHostConfiguration({ contextClassLoader: ClassLoader?, hostConfiguration: ScriptingHostConfiguration ): KClass<*> { - val cl = pluginInstance::class.java.classLoader + val cl = Galactifun2::class.java.classLoader val fromClass = classType.fromClass if (fromClass != null) { if (fromClass.java.classLoader == null) return fromClass // root classloader @@ -79,7 +78,7 @@ object PlanetScriptHost : ScriptingHostConfiguration({ if (actualClassLoadersChain.any { it == fromClass.java.classLoader }) return fromClass } return try { - pluginInstance::class.java.classLoader.loadClass(classType.typeName).kotlin + Galactifun2::class.java.classLoader.loadClass(classType.typeName).kotlin } catch (e: Throwable) { throw IllegalArgumentException("unable to load class ${classType.typeName}", e) } diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/DummyMetadataValue.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/DummyMetadataValue.kt index fd1c535..c7da532 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/DummyMetadataValue.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/bukkit/DummyMetadataValue.kt @@ -1,9 +1,9 @@ package io.github.addoncommunity.galactifun.util.bukkit -import io.github.addoncommunity.galactifun.pluginInstance +import io.github.addoncommunity.galactifun.Galactifun2 import org.bukkit.metadata.MetadataValueAdapter -object DummyMetadataValue : MetadataValueAdapter(pluginInstance) { +object DummyMetadataValue : MetadataValueAdapter(Galactifun2) { override fun value() = Unit override fun invalidate() {} } \ No newline at end of file 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 fcfdfb7..8dbac39 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 @@ -1,6 +1,6 @@ package io.github.addoncommunity.galactifun.util.bukkit -import io.github.addoncommunity.galactifun.pluginInstance +import io.github.addoncommunity.galactifun.Galactifun2 import net.kyori.adventure.text.Component import org.bukkit.* import org.bukkit.block.structure.Mirror @@ -13,7 +13,7 @@ import org.bukkit.util.Vector import java.util.* import java.util.concurrent.CompletableFuture -internal fun String.key(): NamespacedKey = NamespacedKey(pluginInstance, this) +internal fun String.key(): NamespacedKey = NamespacedKey(Galactifun2, this) fun Location.copy( world: World? = this.world, @@ -59,7 +59,7 @@ fun Entity.galactifunTeleport( dest, reason ).thenApply { - removeMetadata("galactifun.teleporting", pluginInstance) + removeMetadata("galactifun.teleporting", Galactifun2) it } } 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 4eac29a..b8e98dd 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 @@ -2,7 +2,7 @@ package io.github.addoncommunity.galactifun.util.bukkit import com.github.shynixn.mccoroutine.bukkit.launch import com.github.shynixn.mccoroutine.bukkit.ticks -import io.github.addoncommunity.galactifun.pluginInstance +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.thebusybiscuit.slimefun4.utils.ChatUtils import kotlinx.coroutines.delay import org.bukkit.entity.Player @@ -23,7 +23,7 @@ suspend fun delayTicks(ticks: Int) { inline fun Collection.consumeSpreadOut(ticks: Int, crossinline action: suspend (T) -> Unit) { val itemsPerTick = size / ticks + 1 - pluginInstance.launch { + Galactifun2.launch { for ((i, item) in this@consumeSpreadOut.withIndex()) { action(item) if (i % itemsPerTick == 0) { diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt index 89a47ee..6855085 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/items/ItemBuilder.kt @@ -1,6 +1,6 @@ package io.github.addoncommunity.galactifun.util.items -import io.github.addoncommunity.galactifun.pluginInstance +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.util.bukkit.miniMessageToLegacy import io.github.addoncommunity.galactifun.util.general.RequiredProperty import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup @@ -37,7 +37,7 @@ class ItemBuilder { *lore.toTypedArray() ) val constructor = clazz.primaryConstructor ?: error("Primary constructor not found for $clazz") - constructor.call(category, sfi, recipeType, recipe, *otherArgs).register(pluginInstance) + constructor.call(category, sfi, recipeType, recipe, *otherArgs).register(Galactifun2) return sfi } } diff --git a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/DoubleChunkGrid.kt b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/DoubleChunkGrid.kt index 9c9cc67..4d93b3e 100644 --- a/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/DoubleChunkGrid.kt +++ b/plugin/src/main/kotlin/io/github/addoncommunity/galactifun/util/worldgen/DoubleChunkGrid.kt @@ -1,8 +1,8 @@ package io.github.addoncommunity.galactifun.util.worldgen import com.google.common.util.concurrent.AtomicDoubleArray +import io.github.addoncommunity.galactifun.Galactifun2 import io.github.addoncommunity.galactifun.launchAsync -import io.github.addoncommunity.galactifun.pluginInstance import it.unimi.dsi.fastutil.longs.Long2LongOpenHashMap import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap import kotlinx.coroutines.Dispatchers @@ -24,7 +24,7 @@ class DoubleChunkGrid { init { val ref = WeakReference(this) - pluginInstance.launchAsync(Dispatchers.IO) { + Galactifun2.launchAsync(Dispatchers.IO) { while (true) { val time = System.currentTimeMillis() val grid = ref.get() ?: break @@ -38,7 +38,7 @@ class DoubleChunkGrid { } } grid.lock.writeLock().unlock() - if (!pluginInstance.isEnabled) return@launchAsync + if (!Galactifun2.isEnabled) return@launchAsync delay(2999) } }