mirror of
https://github.com/plexusorg/Module-Shop.git
synced 2024-12-22 09:57:38 +00:00
kotlin setup
This commit is contained in:
parent
6e6b8a4613
commit
babda6779e
@ -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"
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
rootProject.name = "plexmodule-template"
|
||||
rootProject.name = "plex-shop"
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
11
src/main/java/dev/plex/ShopModule.kt
Normal file
11
src/main/java/dev/plex/ShopModule.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package dev.plex
|
||||
|
||||
import dev.plex.module.PlexModule
|
||||
|
||||
public class ShopModule : PlexModule() {
|
||||
|
||||
override fun enable() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
34
src/main/java/dev/plex/shop/ShopMenu.kt
Normal file
34
src/main/java/dev/plex/shop/ShopMenu.kt
Normal 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
|
||||
}
|
||||
}
|
18
src/main/java/dev/plex/shop/item/AbstractItem.kt
Normal file
18
src/main/java/dev/plex/shop/item/AbstractItem.kt
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
name: Module-Example
|
||||
main: dev.plex.ExampleModule
|
||||
main: dev.plex.ShopModule
|
||||
description: An example module for Plex
|
||||
version: 1.0
|
Loading…
Reference in New Issue
Block a user