From babda6779e6a5619adcb72a04f5e5b0ba775149d Mon Sep 17 00:00:00 2001 From: Taah Date: Fri, 17 Jun 2022 22:23:22 -0700 Subject: [PATCH] kotlin setup --- build.gradle.kts | 13 ++++++- settings.gradle.kts | 2 +- src/main/java/dev/plex/ExampleModule.java | 21 ------------ src/main/java/dev/plex/ShopModule.kt | 11 ++++++ .../java/dev/plex/command/ExampleCommand.java | 21 ------------ .../dev/plex/listener/ExampleListener.java | 17 ---------- src/main/java/dev/plex/shop/ShopMenu.kt | 34 +++++++++++++++++++ .../java/dev/plex/shop/item/AbstractItem.kt | 18 ++++++++++ src/main/resources/module.yml | 2 +- 9 files changed, 77 insertions(+), 62 deletions(-) delete mode 100644 src/main/java/dev/plex/ExampleModule.java create mode 100644 src/main/java/dev/plex/ShopModule.kt delete mode 100644 src/main/java/dev/plex/command/ExampleCommand.java delete mode 100644 src/main/java/dev/plex/listener/ExampleListener.java create mode 100644 src/main/java/dev/plex/shop/ShopMenu.kt create mode 100644 src/main/java/dev/plex/shop/item/AbstractItem.kt diff --git a/build.gradle.kts b/build.gradle.kts index e5a4ff2..d8241ab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,9 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { java `maven-publish` + kotlin("jvm") version "1.7.0" } repositories { @@ -20,7 +23,7 @@ dependencies { annotationProcessor("org.projectlombok:lombok:1.18.24") compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT") compileOnly("dev.plex:server:1.2-SNAPSHOT") - compileOnly("dev.plex:api:1.2-SNAPSHOT") + implementation(kotlin("stdlib-jdk8")) } group = "dev.plex" @@ -54,4 +57,12 @@ tasks { processResources { filteringCharset = Charsets.UTF_8.name() } +} +val compileKotlin: KotlinCompile by tasks +compileKotlin.kotlinOptions { + jvmTarget = "17" +} +val compileTestKotlin: KotlinCompile by tasks +compileTestKotlin.kotlinOptions { + jvmTarget = "17" } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 6f497d0..4b44fc2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,2 @@ -rootProject.name = "plexmodule-template" +rootProject.name = "plex-shop" diff --git a/src/main/java/dev/plex/ExampleModule.java b/src/main/java/dev/plex/ExampleModule.java deleted file mode 100644 index 5de621d..0000000 --- a/src/main/java/dev/plex/ExampleModule.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.plex; - -import dev.plex.command.ExampleCommand; -import dev.plex.listener.ExampleListener; -import dev.plex.module.PlexModule; - -public class ExampleModule extends PlexModule -{ - @Override - public void enable() - { - registerCommand(new ExampleCommand()); - registerListener(new ExampleListener()); - } - - @Override - public void disable() - { - // Unregistering listeners / commands is handled by Plex - } -} diff --git a/src/main/java/dev/plex/ShopModule.kt b/src/main/java/dev/plex/ShopModule.kt new file mode 100644 index 0000000..2956c06 --- /dev/null +++ b/src/main/java/dev/plex/ShopModule.kt @@ -0,0 +1,11 @@ +package dev.plex + +import dev.plex.module.PlexModule + +public class ShopModule : PlexModule() { + + override fun enable() { + + } + +} \ No newline at end of file diff --git a/src/main/java/dev/plex/command/ExampleCommand.java b/src/main/java/dev/plex/command/ExampleCommand.java deleted file mode 100644 index e08610f..0000000 --- a/src/main/java/dev/plex/command/ExampleCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.plex.command; - -import dev.plex.command.annotation.CommandParameters; -import dev.plex.command.annotation.CommandPermissions; -import dev.plex.rank.enums.Rank; -import net.kyori.adventure.text.Component; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -@CommandParameters(name = "examplemodule", description = "An example command provided by Plex's example module") -@CommandPermissions(level = Rank.OP, permission = "plex.module.command") -public class ExampleCommand extends PlexCommand -{ - @Override - protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] strings) - { - return Component.text("Example module command"); - } -} diff --git a/src/main/java/dev/plex/listener/ExampleListener.java b/src/main/java/dev/plex/listener/ExampleListener.java deleted file mode 100644 index 8f2676f..0000000 --- a/src/main/java/dev/plex/listener/ExampleListener.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.plex.listener; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; - -public class ExampleListener extends PlexListener -{ - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - player.sendMessage(Component.text("This is a message from Plex's example module!").color(NamedTextColor.GOLD)); - } -} diff --git a/src/main/java/dev/plex/shop/ShopMenu.kt b/src/main/java/dev/plex/shop/ShopMenu.kt new file mode 100644 index 0000000..36703c3 --- /dev/null +++ b/src/main/java/dev/plex/shop/ShopMenu.kt @@ -0,0 +1,34 @@ +package dev.plex.shop + +import dev.plex.player.PlexPlayer +import dev.plex.shop.item.AbstractItem +import dev.plex.util.minimessage.SafeMiniMessage +import org.bukkit.Bukkit +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +/** + * @author Taah + * @project plex-shop + * @since 11:21 PM [10-06-2022] + * + */ +class ShopMenu { + companion object { + val ITEMS = mapOf() + } + + fun open(plexPlayer: PlexPlayer) + { + val player: Player? = plexPlayer.player + val inventory: Inventory = constructInventory() + player?.openInventory(inventory) + } + + private fun constructInventory(): Inventory + { + val inventory: Inventory = Bukkit.createInventory(null, 54, SafeMiniMessage.mmDeserialize("Shop")) + ITEMS.forEach { (t, u) -> inventory.setItem(t, u.item) } + return inventory + } +} \ No newline at end of file diff --git a/src/main/java/dev/plex/shop/item/AbstractItem.kt b/src/main/java/dev/plex/shop/item/AbstractItem.kt new file mode 100644 index 0000000..ec01386 --- /dev/null +++ b/src/main/java/dev/plex/shop/item/AbstractItem.kt @@ -0,0 +1,18 @@ +package dev.plex.shop.item + +import dev.plex.cache.DataUtils +import dev.plex.player.PlexPlayer +import org.bukkit.inventory.ItemStack +import java.util.concurrent.CompletableFuture + +abstract class AbstractItem(val item: ItemStack, private val cost: Double) +{ + fun purchase(player: PlexPlayer) + { + player.coins.minus(this.cost); + player.player?.inventory?.addItem(this.item); + CompletableFuture.runAsync { + DataUtils.update(player); + } + } +} diff --git a/src/main/resources/module.yml b/src/main/resources/module.yml index 171f2ac..ced8897 100644 --- a/src/main/resources/module.yml +++ b/src/main/resources/module.yml @@ -1,4 +1,4 @@ name: Module-Example -main: dev.plex.ExampleModule +main: dev.plex.ShopModule description: An example module for Plex version: 1.0 \ No newline at end of file