kotlin setup

This commit is contained in:
Taah 2022-06-17 22:23:22 -07:00
parent 6e6b8a4613
commit babda6779e
9 changed files with 77 additions and 62 deletions

View File

@ -1,6 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
java java
`maven-publish` `maven-publish`
kotlin("jvm") version "1.7.0"
} }
repositories { repositories {
@ -20,7 +23,7 @@ dependencies {
annotationProcessor("org.projectlombok:lombok:1.18.24") annotationProcessor("org.projectlombok:lombok:1.18.24")
compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("dev.plex:server:1.2-SNAPSHOT") compileOnly("dev.plex:server:1.2-SNAPSHOT")
compileOnly("dev.plex:api:1.2-SNAPSHOT") implementation(kotlin("stdlib-jdk8"))
} }
group = "dev.plex" group = "dev.plex"
@ -54,4 +57,12 @@ tasks {
processResources { processResources {
filteringCharset = Charsets.UTF_8.name() filteringCharset = Charsets.UTF_8.name()
} }
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "17"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "17"
} }

View File

@ -1,2 +1,2 @@
rootProject.name = "plexmodule-template" rootProject.name = "plex-shop"

View File

@ -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
}
}

View File

@ -0,0 +1,11 @@
package dev.plex
import dev.plex.module.PlexModule
public class ShopModule : PlexModule() {
override fun enable() {
}
}

View File

@ -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");
}
}

View File

@ -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));
}
}

View File

@ -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<Int, AbstractItem>()
}
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("<gold>Shop"))
ITEMS.forEach { (t, u) -> inventory.setItem(t, u.item) }
return inventory
}
}

View File

@ -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);
}
}
}

View File

@ -1,4 +1,4 @@
name: Module-Example name: Module-Example
main: dev.plex.ExampleModule main: dev.plex.ShopModule
description: An example module for Plex description: An example module for Plex
version: 1.0 version: 1.0