diff --git a/.idea/codeStyles/Plexus_Code_Style.xml b/.idea/codeStyles/Plexus_Code_Style.xml
index a7db3e4..3dc4a27 100644
--- a/.idea/codeStyles/Plexus_Code_Style.xml
+++ b/.idea/codeStyles/Plexus_Code_Style.xml
@@ -1,33 +1,8 @@
-
-
-
-
-
-
-
-
-
+
+
+
@@ -36,14 +11,10 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index df773a2..a55e7a1 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index d8241ab..4d1a8ae 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -28,7 +28,7 @@ dependencies {
group = "dev.plex"
version = "1.0"
-description = "ExampleModule"
+description = "ShopModule"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
@@ -43,8 +43,12 @@ publishing {
}
tasks.getByName("jar") {
- archiveBaseName.set("Plex-ExampleModule")
+ archiveBaseName.set("Plex-Shop")
archiveVersion.set("")
+ duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.EXCLUDE
+ from({
+ configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
+ })
}
tasks {
diff --git a/src/main/java/dev/plex/ShopModule.kt b/src/main/java/dev/plex/ShopModule.kt
index 2956c06..1ea35a8 100644
--- a/src/main/java/dev/plex/ShopModule.kt
+++ b/src/main/java/dev/plex/ShopModule.kt
@@ -1,11 +1,48 @@
package dev.plex
+import dev.plex.commands.ShopCommand
+import dev.plex.config.ModuleConfig
+import dev.plex.listener.ShopListener
import dev.plex.module.PlexModule
+import dev.plex.shop.ShopMenu
+import dev.plex.shop.item.impl.FireballItem
+import dev.plex.util.PlexLog
+import dev.plex.util.item.ItemBuilder
+import dev.plex.util.minimessage.SafeMiniMessage
+import org.bukkit.Material
-public class ShopModule : PlexModule() {
+class ShopModule : PlexModule() {
+ companion object {
+ private var module: ShopModule? = null;
+ fun get(): ShopModule
+ {
+ return module!!
+ }
+ }
+
+ private var config: ModuleConfig? = null
+
+ override fun load()
+ {
+ module = this;
+ config = ModuleConfig(this, "data/config.yml", "config.yml")
+ getConfig().load()
+ }
override fun enable() {
+ ShopMenu.registerItem(18, FireballItem(
+ ItemBuilder(Material.FIRE_CHARGE).displayName(SafeMiniMessage.mmDeserialize("Fireball")).build(),
+ getConfig().getDouble("shop.prices.fireball", 0.0)
+ ))
+ registerListener(ShopListener())
+ registerCommand(ShopCommand())
+ PlexLog.debug("Shop loaded!")
+ }
+
+ fun getConfig(): ModuleConfig
+ {
+ return config!!
}
}
\ No newline at end of file
diff --git a/src/main/java/dev/plex/commands/ShopCommand.kt b/src/main/java/dev/plex/commands/ShopCommand.kt
new file mode 100644
index 0000000..fb2f255
--- /dev/null
+++ b/src/main/java/dev/plex/commands/ShopCommand.kt
@@ -0,0 +1,23 @@
+package dev.plex.commands
+
+import dev.plex.cache.DataUtils
+import dev.plex.command.PlexCommand
+import dev.plex.command.annotation.CommandParameters
+import dev.plex.command.annotation.CommandPermissions
+import dev.plex.command.source.RequiredCommandSource
+import dev.plex.rank.enums.Rank
+import dev.plex.shop.ShopMenu
+import net.kyori.adventure.text.Component
+import org.bukkit.command.CommandSender
+import org.bukkit.entity.Player
+
+@CommandParameters(name = "shop", description = "Opens the shop menu")
+@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.shop.open")
+class ShopCommand: PlexCommand()
+{
+ override fun execute(sender: CommandSender, player: Player?, args: Array?): Component?
+ {
+ ShopMenu.open(DataUtils.getPlayer(player!!.uniqueId))
+ return null
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/dev/plex/listener/ShopListener.kt b/src/main/java/dev/plex/listener/ShopListener.kt
new file mode 100644
index 0000000..21bcbc3
--- /dev/null
+++ b/src/main/java/dev/plex/listener/ShopListener.kt
@@ -0,0 +1,23 @@
+package dev.plex.listener
+
+import dev.plex.util.minimessage.SafeMiniMessage
+import net.kyori.adventure.text.Component
+import org.bukkit.event.EventHandler
+import org.bukkit.event.inventory.InventoryClickEvent
+
+class ShopListener : PlexListener()
+{
+ private val shopMenuTitle: Component = SafeMiniMessage.mmDeserialize("Shop")
+
+ @EventHandler
+ fun onClick(event: InventoryClickEvent)
+ {
+ if (!event.view.title().equals(shopMenuTitle))
+ {
+ return
+ }
+ event.isCancelled = true
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/dev/plex/shop/ShopMenu.kt b/src/main/java/dev/plex/shop/ShopMenu.kt
index 36703c3..c51bfca 100644
--- a/src/main/java/dev/plex/shop/ShopMenu.kt
+++ b/src/main/java/dev/plex/shop/ShopMenu.kt
@@ -1,9 +1,12 @@
package dev.plex.shop
+import com.google.common.collect.Maps
import dev.plex.player.PlexPlayer
import dev.plex.shop.item.AbstractItem
+import dev.plex.util.item.ItemBuilder
import dev.plex.util.minimessage.SafeMiniMessage
import org.bukkit.Bukkit
+import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.Inventory
@@ -13,22 +16,35 @@ import org.bukkit.inventory.Inventory
* @since 11:21 PM [10-06-2022]
*
*/
-class ShopMenu {
- companion object {
- val ITEMS = mapOf()
- }
-
- fun open(plexPlayer: PlexPlayer)
+class ShopMenu
+{
+ companion object
{
- val player: Player? = plexPlayer.player
- val inventory: Inventory = constructInventory()
- player?.openInventory(inventory)
- }
+ val ITEMS: HashMap = Maps.newHashMap()
+ fun registerItem(index: Int, item: AbstractItem)
+ {
+ ITEMS.put(index, item);
+ }
- 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
+ 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) }
+ for (i in 0 until inventory.size)
+ {
+ if (inventory.getItem(i) == null || inventory.getItem(i)?.type == Material.AIR)
+ {
+ inventory.setItem(i, ItemBuilder(Material.GRAY_STAINED_GLASS_PANE).displayName(SafeMiniMessage.mmDeserialize(" ")).build())
+ }
+ }
+ return inventory
+ }
}
}
\ No newline at end of file
diff --git a/src/main/java/dev/plex/shop/item/impl/FireballItem.kt b/src/main/java/dev/plex/shop/item/impl/FireballItem.kt
new file mode 100644
index 0000000..4015e4e
--- /dev/null
+++ b/src/main/java/dev/plex/shop/item/impl/FireballItem.kt
@@ -0,0 +1,8 @@
+package dev.plex.shop.item.impl
+
+import dev.plex.shop.item.AbstractItem
+import org.bukkit.inventory.ItemStack
+
+class FireballItem(item: ItemStack, cost: Double) : AbstractItem(item, cost)
+{
+}
\ No newline at end of file
diff --git a/src/main/resources/data/config.yml b/src/main/resources/data/config.yml
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/resources/module.yml b/src/main/resources/module.yml
index ced8897..9fa44f8 100644
--- a/src/main/resources/module.yml
+++ b/src/main/resources/module.yml
@@ -1,4 +1,4 @@
-name: Module-Example
+name: Plex-Shop
main: dev.plex.ShopModule
description: An example module for Plex
version: 1.0
\ No newline at end of file