mirror of
https://github.com/plexusorg/Module-Shop.git
synced 2024-12-22 18:07:39 +00:00
such a kotlin moment
setup shop command setup shop listener setup item registration
This commit is contained in:
parent
babda6779e
commit
c4743c97cb
35
.idea/codeStyles/Plexus_Code_Style.xml
generated
35
.idea/codeStyles/Plexus_Code_Style.xml
generated
@ -1,33 +1,8 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Plexus Code Style" version="1">
|
<code_scheme name="Plexus Code Style" version="173">
|
||||||
<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>
|
|
||||||
<codeStyleSettings language="JAVA">
|
<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="BRACE_STYLE" value="2" />
|
||||||
<option name="CLASS_BRACE_STYLE" value="2" />
|
<option name="CLASS_BRACE_STYLE" value="2" />
|
||||||
<option name="METHOD_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="WHILE_ON_NEW_LINE" value="true" />
|
||||||
<option name="CATCH_ON_NEW_LINE" value="true" />
|
<option name="CATCH_ON_NEW_LINE" value="true" />
|
||||||
<option name="FINALLY_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="IF_BRACE_FORCE" value="3" />
|
||||||
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
||||||
<option name="WHILE_BRACE_FORCE" value="3" />
|
<option name="WHILE_BRACE_FORCE" value="3" />
|
||||||
<option name="FOR_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>
|
</codeStyleSettings>
|
||||||
</code_scheme>
|
</code_scheme>
|
||||||
</component>
|
</component>
|
2
.idea/codeStyles/codeStyleConfig.xml
generated
2
.idea/codeStyles/codeStyleConfig.xml
generated
@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<state>
|
<state>
|
||||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Plexus Code Style" />
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
</state>
|
</state>
|
||||||
</component>
|
</component>
|
@ -28,7 +28,7 @@ dependencies {
|
|||||||
|
|
||||||
group = "dev.plex"
|
group = "dev.plex"
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
description = "ExampleModule"
|
description = "ShopModule"
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
@ -43,8 +43,12 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tasks.getByName<Jar>("jar") {
|
tasks.getByName<Jar>("jar") {
|
||||||
archiveBaseName.set("Plex-ExampleModule")
|
archiveBaseName.set("Plex-Shop")
|
||||||
archiveVersion.set("")
|
archiveVersion.set("")
|
||||||
|
duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.EXCLUDE
|
||||||
|
from({
|
||||||
|
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
@ -1,11 +1,48 @@
|
|||||||
package dev.plex
|
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.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() {
|
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!!
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
23
src/main/java/dev/plex/commands/ShopCommand.kt
Normal file
23
src/main/java/dev/plex/commands/ShopCommand.kt
Normal 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
|
||||||
|
}
|
||||||
|
}
|
23
src/main/java/dev/plex/listener/ShopListener.kt
Normal file
23
src/main/java/dev/plex/listener/ShopListener.kt
Normal 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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,12 @@
|
|||||||
package dev.plex.shop
|
package dev.plex.shop
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps
|
||||||
import dev.plex.player.PlexPlayer
|
import dev.plex.player.PlexPlayer
|
||||||
import dev.plex.shop.item.AbstractItem
|
import dev.plex.shop.item.AbstractItem
|
||||||
|
import dev.plex.util.item.ItemBuilder
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage
|
import dev.plex.util.minimessage.SafeMiniMessage
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.Inventory
|
import org.bukkit.inventory.Inventory
|
||||||
|
|
||||||
@ -13,9 +16,14 @@ import org.bukkit.inventory.Inventory
|
|||||||
* @since 11:21 PM [10-06-2022]
|
* @since 11:21 PM [10-06-2022]
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class ShopMenu {
|
class ShopMenu
|
||||||
companion object {
|
{
|
||||||
val ITEMS = mapOf<Int, AbstractItem>()
|
companion object
|
||||||
|
{
|
||||||
|
val ITEMS: HashMap<Int, AbstractItem> = Maps.newHashMap()
|
||||||
|
fun registerItem(index: Int, item: AbstractItem)
|
||||||
|
{
|
||||||
|
ITEMS.put(index, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
fun open(plexPlayer: PlexPlayer)
|
fun open(plexPlayer: PlexPlayer)
|
||||||
@ -29,6 +37,14 @@ class ShopMenu {
|
|||||||
{
|
{
|
||||||
val inventory: Inventory = Bukkit.createInventory(null, 54, SafeMiniMessage.mmDeserialize("<gold>Shop"))
|
val inventory: Inventory = Bukkit.createInventory(null, 54, SafeMiniMessage.mmDeserialize("<gold>Shop"))
|
||||||
ITEMS.forEach { (t, u) -> inventory.setItem(t, u.item) }
|
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
|
return inventory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
8
src/main/java/dev/plex/shop/item/impl/FireballItem.kt
Normal file
8
src/main/java/dev/plex/shop/item/impl/FireballItem.kt
Normal 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)
|
||||||
|
{
|
||||||
|
}
|
0
src/main/resources/data/config.yml
Normal file
0
src/main/resources/data/config.yml
Normal file
@ -1,4 +1,4 @@
|
|||||||
name: Module-Example
|
name: Plex-Shop
|
||||||
main: dev.plex.ShopModule
|
main: dev.plex.ShopModule
|
||||||
description: An example module for Plex
|
description: An example module for Plex
|
||||||
version: 1.0
|
version: 1.0
|
Loading…
Reference in New Issue
Block a user