such a kotlin moment

setup shop command
setup shop listener
setup item registration
This commit is contained in:
taah 2022-06-18 00:35:27 -07:00
parent babda6779e
commit c4743c97cb
10 changed files with 134 additions and 52 deletions

View File

@ -1,33 +1,8 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Plexus Code Style" version="1">
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="20" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" />
<package name="" withSubpackages="true" static="true" />
</value>
</option>
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
</JetCodeStyleSettings>
<code_scheme name="Plexus Code Style" version="173">
<codeStyleSettings language="JAVA">
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
<option name="BRACE_STYLE" value="2" />
<option name="CLASS_BRACE_STYLE" value="2" />
<option name="METHOD_BRACE_STYLE" value="2" />
@ -36,14 +11,10 @@
<option name="WHILE_ON_NEW_LINE" value="true" />
<option name="CATCH_ON_NEW_LINE" value="true" />
<option name="FINALLY_ON_NEW_LINE" value="true" />
<option name="SPACE_AFTER_TYPE_CAST" value="true" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="0" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -1,5 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Plexus Code Style" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -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>("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 {

View File

@ -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("<!italic><red>Fireball")).build(),
getConfig().getDouble("shop.prices.fireball", 0.0)
))
registerListener(ShopListener())
registerCommand(ShopCommand())
PlexLog.debug("Shop loaded!")
}
fun getConfig(): ModuleConfig
{
return config!!
}
}

View File

@ -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<out String>?): Component?
{
ShopMenu.open(DataUtils.getPlayer(player!!.uniqueId))
return null
}
}

View File

@ -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("<gold>Shop")
@EventHandler
fun onClick(event: InventoryClickEvent)
{
if (!event.view.title().equals(shopMenuTitle))
{
return
}
event.isCancelled = true
}
}

View File

@ -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<Int, AbstractItem>()
}
fun open(plexPlayer: PlexPlayer)
class ShopMenu
{
companion object
{
val player: Player? = plexPlayer.player
val inventory: Inventory = constructInventory()
player?.openInventory(inventory)
}
val ITEMS: HashMap<Int, AbstractItem> = 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("<gold>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("<gold>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("<!italic> ")).build())
}
}
return inventory
}
}
}

View File

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

View File

View File

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