diff --git a/build.gradle.kts b/build.gradle.kts index 46d244d..f98649e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ group = "" version = execute("git", "describe", "--long", "--dirty") plugins { - val kotlinVersion = "1.4.10" + val kotlinVersion = "1.4.21" kotlin("jvm") version kotlinVersion kotlin("kapt") version kotlinVersion id("com.github.johnrengelman.shadow") version "2.0.4" @@ -14,29 +14,12 @@ plugins { repositories { mavenCentral() - maven { - name = "spigotmc-repo" - url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") - } - maven { - name = "sonatype-oss" - url = uri("https://oss.sonatype.org/content/groups/public/") - } - maven { - name = "enginehub-maven" - url = uri("https://maven.enginehub.org/repo/") - } - maven { - name = "aikar" - url = uri("https://repo.aikar.co/content/groups/aikar/") - } - maven { - name = "codemc-repo" - url = uri("https://repo.codemc.org/repository/maven-public/") - } - maven { - url = uri("https://repo.dmulloy2.net/nexus/repository/public/") - } + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + maven("https://oss.sonatype.org/content/groups/public/") + maven("https://maven.enginehub.org/repo/") + maven("https://repo.aikar.co/content/groups/aikar/") + maven("https://repo.codemc.org/repository/maven-public/") + maven("https://repo.dmulloy2.net/nexus/repository/public/") } dependencies { @@ -73,7 +56,10 @@ tasks.withType { kotlinOptions { jvmTarget = "1.8" javaParameters = true - freeCompilerArgs = listOf("-Xopt-in=kotlin.ExperimentalStdlibApi") + freeCompilerArgs = listOf( + "-Xopt-in=kotlin.ExperimentalStdlibApi", + "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi" + ) } } diff --git a/src/main/kotlin/Autowire.kt b/src/main/kotlin/Autowire.kt index c024a49..a1cb7a6 100644 --- a/src/main/kotlin/Autowire.kt +++ b/src/main/kotlin/Autowire.kt @@ -18,41 +18,37 @@ import org.bukkit.event.Listener import org.bukkit.event.block.BlockPlaceEvent import org.bukkit.event.player.PlayerQuitEvent import org.bukkit.inventory.ItemStack -import org.bukkit.plugin.java.JavaPlugin +import org.bukkit.plugin.PluginManager import java.util.* @CommandAlias("autowire|aw") @Description("Get that there redstone automagically!") @CommandPermission("redstonetools.autowire") class Autowire( - private val autos: MutableSet, - private val protocolManager: ProtocolManager -) : BaseCommand() { + private val protocolManager: ProtocolManager, + private val pluginManager: PluginManager, +) : BaseCommand(), Listener { + private val autos = mutableSetOf() + @Default - fun autowire(player: Player) { + fun toggleAutowire(player: Player) { if (player.uniqueId in autos) { autos.remove(player.uniqueId) - protocolManager.sendResponsePacket(player, "Auto Wire Disabled") + "Auto Wire Disabled" } else { autos.add(player.uniqueId) - protocolManager.sendResponsePacket(player, "Auto Wire Enabled") - } + "Auto Wire Enabled" + }.let { player.sendActionBarTitle(it) } } - private fun ProtocolManager.sendResponsePacket(player: Player, message: String) { - val titlePacket = this.createPacket(PacketType.Play.Server.TITLE) - titlePacket.titleActions - .write(0, EnumWrappers.TitleAction.ACTIONBAR) - titlePacket.chatComponents - .write(0, WrappedChatComponent.fromText(message)) - this.sendServerPacket(player, titlePacket) + private fun Player.sendActionBarTitle(message: String) { + val titlePacket = protocolManager.createPacket(PacketType.Play.Server.TITLE).apply { + titleActions.write(0, EnumWrappers.TitleAction.ACTIONBAR) + chatComponents.write(0, WrappedChatComponent.fromText(message)) + } + protocolManager.sendServerPacket(this, titlePacket) } -} -class AutoWireListener( - private val plugin: JavaPlugin, - private val autos: MutableSet -) : Listener { @EventHandler fun onLeaveEvent(event: PlayerQuitEvent) { autos.remove(event.player.uniqueId) @@ -75,7 +71,7 @@ class AutoWireListener( true, event.hand ) - plugin.server.pluginManager.callEvent(blockPlaceEvent) + pluginManager.callEvent(blockPlaceEvent) if (blockPlaceEvent.isCancelled) return wirePosition.block.type = Material.REDSTONE_WIRE val wireData: RedstoneWire = Material.REDSTONE_WIRE.createBlockData() as RedstoneWire @@ -84,4 +80,4 @@ class AutoWireListener( } wirePosition.block.blockData = wireData } -} \ No newline at end of file +} diff --git a/src/main/kotlin/RedstoneTools.kt b/src/main/kotlin/RedstoneTools.kt index 67d0a9e..4e3afda 100644 --- a/src/main/kotlin/RedstoneTools.kt +++ b/src/main/kotlin/RedstoneTools.kt @@ -49,11 +49,11 @@ class RedstoneTools : JavaPlugin() { return } val worldEdit = wePlugin.worldEdit - val autos: MutableSet = mutableSetOf() val protocolManager = ProtocolLibrary.getProtocolManager() + val autowire = Autowire(protocolManager, server.pluginManager) arrayOf( WorldEditHelper(this, worldEdit), - AutoWireListener(this, autos), + autowire, SlabListener(), ).forEach { server.pluginManager.registerEvents(it, this) } PaperCommandManager(this).apply { @@ -72,7 +72,7 @@ class RedstoneTools : JavaPlugin() { SignSearch(worldEdit), Container(), Slab(), - Autowire(autos, protocolManager) + autowire, ).forEach(::registerCommand) } }