From 98d9ea1090576a1aa56656ff837c7b5dc6e0dbf4 Mon Sep 17 00:00:00 2001 From: Lonewoss Date: Sat, 20 Sep 2025 12:52:21 +0500 Subject: [PATCH] 1.0.0 GOLDEN CARROTS MUST DIE --- build.gradle.kts | 7 ++-- settings.gradle.kts | 2 +- .../dev/marrow/plugin/commands/Example.kt | 36 ------------------- .../dev/marrow/{plugin => zcarrots}/Core.kt | 15 +++----- .../{plugin => zcarrots}/config/ConfigIO.kt | 8 ++--- .../zcarrots/listeners/CarrotListener.kt | 25 +++++++++++++ .../{plugin => zcarrots}/utils/CommonUtils.kt | 2 +- .../utils/ComponentExtension.kt | 2 +- 8 files changed, 41 insertions(+), 56 deletions(-) delete mode 100755 src/main/kotlin/dev/marrow/plugin/commands/Example.kt rename src/main/kotlin/dev/marrow/{plugin => zcarrots}/Core.kt (56%) mode change 100755 => 100644 rename src/main/kotlin/dev/marrow/{plugin => zcarrots}/config/ConfigIO.kt (83%) create mode 100644 src/main/kotlin/dev/marrow/zcarrots/listeners/CarrotListener.kt rename src/main/kotlin/dev/marrow/{plugin => zcarrots}/utils/CommonUtils.kt (88%) rename src/main/kotlin/dev/marrow/{plugin => zcarrots}/utils/ComponentExtension.kt (97%) mode change 100755 => 100644 diff --git a/build.gradle.kts b/build.gradle.kts index 5e96da4..54b6416 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ val javaVersion = 24 group = "dev.marrow" version = "1.0" -description = "paper plugin template" +description = "Golden carrots must die" // paper-plugin.yml paper { @@ -25,7 +25,7 @@ paper { // version is version value foliaSupported = true - author = "You" + author = "Lonewoss" main = "$group.${project.name.lowercase()}.Core" apiVersion = "1.21" prefix = project.name.lowercase() @@ -70,7 +70,8 @@ publishing { tasks { runServer { - version("1.21.8") + serverJar(file("run/prismatic-bundler-1.21.8-R0.1-SNAPSHOT-mojmap.jar")) + version("1.21.7") } build { diff --git a/settings.gradle.kts b/settings.gradle.kts index d7fafab..4842d63 100755 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1 @@ -rootProject.name = "plugin" \ No newline at end of file +rootProject.name = "zcarrots" \ No newline at end of file diff --git a/src/main/kotlin/dev/marrow/plugin/commands/Example.kt b/src/main/kotlin/dev/marrow/plugin/commands/Example.kt deleted file mode 100755 index fb72c66..0000000 --- a/src/main/kotlin/dev/marrow/plugin/commands/Example.kt +++ /dev/null @@ -1,36 +0,0 @@ -package dev.marrow.plugin.commands - -import com.mojang.brigadier.arguments.StringArgumentType -import com.mojang.brigadier.tree.LiteralCommandNode -import net.kyori.adventure.text.Component -import com.mojang.brigadier.Command -import dev.marrow.plugin.Core -import io.papermc.paper.command.brigadier.CommandSourceStack -import io.papermc.paper.command.brigadier.Commands.literal -import io.papermc.paper.command.brigadier.Commands.argument -import io.papermc.paper.command.brigadier.argument.ArgumentTypes -import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver - -class Example private constructor() { - companion object { - operator fun invoke(command: String): LiteralCommandNode { - return literal(command).apply { - then(argument("player", ArgumentTypes.player()).apply { - then(argument("message", StringArgumentType.greedyString()).apply { - executes { - val sender = it.source.sender - val targetResolver = it.getArgument("player", PlayerSelectorArgumentResolver::class.java) - val target = targetResolver.resolve(it.source).first() - val message = it.getArgument("message", String::class.java) - sender.sendMessage("${target.name} will receive your message in 1 second") - target.scheduler.runDelayed(Core.instance, { - target.sendMessage(Component.text("${sender.name}: $message")) - }, null, 20) - Command.SINGLE_SUCCESS - } - }) - }) - }.build() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/dev/marrow/plugin/Core.kt b/src/main/kotlin/dev/marrow/zcarrots/Core.kt old mode 100755 new mode 100644 similarity index 56% rename from src/main/kotlin/dev/marrow/plugin/Core.kt rename to src/main/kotlin/dev/marrow/zcarrots/Core.kt index 2c8048e..7849fb4 --- a/src/main/kotlin/dev/marrow/plugin/Core.kt +++ b/src/main/kotlin/dev/marrow/zcarrots/Core.kt @@ -1,9 +1,8 @@ -package dev.marrow.plugin +package dev.marrow.zcarrots -import dev.marrow.plugin.commands.Example -import dev.marrow.plugin.config.ConfigIO -import dev.marrow.plugin.utils.ComponentExtension.deserializeMiniMessage -import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents +import dev.marrow.zcarrots.config.ConfigIO +import dev.marrow.zcarrots.listeners.CarrotListener +import dev.marrow.zcarrots.utils.ComponentExtension.deserializeMiniMessage import org.bukkit.plugin.java.JavaPlugin import java.io.File import java.util.logging.Logger @@ -20,14 +19,10 @@ class Core : JavaPlugin() { console = logger ConfigIO.readConfig() - this.lifecycleManager.registerEventHandler(LifecycleEvents.COMMANDS) { - it.registrar().register(Example("example"), listOf("example_alias")) - } - + server.pluginManager.registerEvents(CarrotListener(this), this) server.consoleSender.sendMessage(ConfigIO.instance.enabledMessage.deserializeMiniMessage()) } - override fun onLoad() { File("${System.getProperty("user.dir")}/plugins/${this.name}").mkdir() } diff --git a/src/main/kotlin/dev/marrow/plugin/config/ConfigIO.kt b/src/main/kotlin/dev/marrow/zcarrots/config/ConfigIO.kt similarity index 83% rename from src/main/kotlin/dev/marrow/plugin/config/ConfigIO.kt rename to src/main/kotlin/dev/marrow/zcarrots/config/ConfigIO.kt index b1abce1..7f2dd3f 100644 --- a/src/main/kotlin/dev/marrow/plugin/config/ConfigIO.kt +++ b/src/main/kotlin/dev/marrow/zcarrots/config/ConfigIO.kt @@ -1,7 +1,7 @@ -package dev.marrow.plugin.config +package dev.marrow.zcarrots.config -import dev.marrow.plugin.Core -import dev.marrow.plugin.utils.CommonUtils.gson +import dev.marrow.zcarrots.Core +import dev.marrow.zcarrots.utils.CommonUtils.gson import java.io.BufferedReader import java.io.File import java.io.FileReader @@ -13,7 +13,7 @@ object ConfigIO { lateinit var instance: ConfigurationModel data class ConfigurationModel( - val enabledMessage: String = "example plugin enabled" + val enabledMessage: String = "ZCarrots enabled" ) private val file = File("${System.getProperty("user.dir")}/plugins/${Core.instance.name}/config.json") diff --git a/src/main/kotlin/dev/marrow/zcarrots/listeners/CarrotListener.kt b/src/main/kotlin/dev/marrow/zcarrots/listeners/CarrotListener.kt new file mode 100644 index 0000000..6a98512 --- /dev/null +++ b/src/main/kotlin/dev/marrow/zcarrots/listeners/CarrotListener.kt @@ -0,0 +1,25 @@ +package dev.marrow.zcarrots.listeners + +import dev.marrow.zcarrots.Core +import org.bukkit.Material +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.event.player.PlayerItemConsumeEvent +import org.bukkit.inventory.EquipmentSlot +import org.bukkit.inventory.PlayerInventory + +class CarrotListener(private val plugin: Core) : Listener { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + fun onTakeGoldenCarrot(e: InventoryClickEvent) { + val item = e.cursor.takeIf { it.type == Material.GOLDEN_CARROT } ?: e.currentItem.takeIf { it?.type == Material.GOLDEN_CARROT } ?: return + val itemMeta = item.itemMeta ?: return + if (!itemMeta.hasEquippable()) return + + val inventory = e.whoClicked.inventory + val sourceSlot = inventory.first(item) + if (sourceSlot == -1) return + inventory.setItem(sourceSlot, null) + } +} \ No newline at end of file diff --git a/src/main/kotlin/dev/marrow/plugin/utils/CommonUtils.kt b/src/main/kotlin/dev/marrow/zcarrots/utils/CommonUtils.kt similarity index 88% rename from src/main/kotlin/dev/marrow/plugin/utils/CommonUtils.kt rename to src/main/kotlin/dev/marrow/zcarrots/utils/CommonUtils.kt index 92e49ba..1ac13f0 100644 --- a/src/main/kotlin/dev/marrow/plugin/utils/CommonUtils.kt +++ b/src/main/kotlin/dev/marrow/zcarrots/utils/CommonUtils.kt @@ -1,4 +1,4 @@ -package dev.marrow.plugin.utils +package dev.marrow.zcarrots.utils import com.google.gson.Gson import com.google.gson.GsonBuilder diff --git a/src/main/kotlin/dev/marrow/plugin/utils/ComponentExtension.kt b/src/main/kotlin/dev/marrow/zcarrots/utils/ComponentExtension.kt old mode 100755 new mode 100644 similarity index 97% rename from src/main/kotlin/dev/marrow/plugin/utils/ComponentExtension.kt rename to src/main/kotlin/dev/marrow/zcarrots/utils/ComponentExtension.kt index 948f2ea..e8a0a4f --- a/src/main/kotlin/dev/marrow/plugin/utils/ComponentExtension.kt +++ b/src/main/kotlin/dev/marrow/zcarrots/utils/ComponentExtension.kt @@ -1,6 +1,6 @@ @file:Suppress("unused") -package dev.marrow.plugin.utils +package dev.marrow.zcarrots.utils import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.TextDecoration