支持自定义货币
This commit is contained in:
+4
-1
@@ -25,6 +25,8 @@ taboolib {
|
|||||||
install("expansion-command-helper")
|
install("expansion-command-helper")
|
||||||
classifier = null
|
classifier = null
|
||||||
version = "6.0.9-84"
|
version = "6.0.9-84"
|
||||||
|
options("skit-kotlin")
|
||||||
|
relocate("kotlin","libs.kotlin1510")
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -36,9 +38,10 @@ dependencies {
|
|||||||
compileOnly("ink.ptms:nms-all:1.0.0")
|
compileOnly("ink.ptms:nms-all:1.0.0")
|
||||||
compileOnly("public:papi:1.0.0")
|
compileOnly("public:papi:1.0.0")
|
||||||
compileOnly("public:vault:1.0.0")
|
compileOnly("public:vault:1.0.0")
|
||||||
|
compileOnly("public:points:1.0.0")
|
||||||
compileOnly("ink.ptms.core:v11902:11902-minimize:mapped")
|
compileOnly("ink.ptms.core:v11902:11902-minimize:mapped")
|
||||||
compileOnly("ink.ptms.core:v11902:11902-minimize:universal")
|
compileOnly("ink.ptms.core:v11902:11902-minimize:universal")
|
||||||
compileOnly(kotlin("stdlib"))
|
taboo(kotlin("stdlib"))
|
||||||
compileOnly(fileTree("libs"))
|
compileOnly(fileTree("libs"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
group=com.github.xbaimiao.shoppro
|
group=com.github.xbaimiao.shoppro
|
||||||
version=1.0.4
|
version=1.0.6-beta
|
||||||
|
|||||||
@@ -3,7 +3,13 @@ package com.github.xbaimiao.shoppro
|
|||||||
import com.github.xbaimiao.shoppro.core.database.Database
|
import com.github.xbaimiao.shoppro.core.database.Database
|
||||||
import com.github.xbaimiao.shoppro.core.database.MysqlDatabase
|
import com.github.xbaimiao.shoppro.core.database.MysqlDatabase
|
||||||
import com.github.xbaimiao.shoppro.core.database.SQLiteDatabase
|
import com.github.xbaimiao.shoppro.core.database.SQLiteDatabase
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.*
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.impl.HeadShopItem
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.impl.ItemImpl
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.impl.ItemsAdderShopItem
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.impl.VanillaShopItem
|
||||||
import com.github.xbaimiao.shoppro.core.shop.ShopManager
|
import com.github.xbaimiao.shoppro.core.shop.ShopManager
|
||||||
|
import com.github.xbaimiao.shoppro.core.vault.DiyCurrency
|
||||||
import taboolib.common.platform.Plugin
|
import taboolib.common.platform.Plugin
|
||||||
import taboolib.module.configuration.Config
|
import taboolib.module.configuration.Config
|
||||||
import taboolib.module.configuration.Configuration
|
import taboolib.module.configuration.Configuration
|
||||||
@@ -16,15 +22,23 @@ object ShopPro : Plugin() {
|
|||||||
|
|
||||||
lateinit var database: Database
|
lateinit var database: Database
|
||||||
|
|
||||||
|
val itemLoader = ArrayList<ItemLoader>()
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
ShopManager.load()
|
ShopManager.load()
|
||||||
|
DiyCurrency.load()
|
||||||
database = if (config.getBoolean("mysql.enable")) MysqlDatabase(config) else SQLiteDatabase()
|
database = if (config.getBoolean("mysql.enable")) MysqlDatabase(config) else SQLiteDatabase()
|
||||||
|
itemLoader.add(VanillaShopItem)
|
||||||
|
itemLoader.add(ItemImpl)
|
||||||
|
itemLoader.add(ItemsAdderShopItem)
|
||||||
|
itemLoader.add(HeadShopItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reload() {
|
fun reload() {
|
||||||
config.reload()
|
config.reload()
|
||||||
ShopManager.shops.clear()
|
ShopManager.shops.clear()
|
||||||
ShopManager.load()
|
ShopManager.load()
|
||||||
|
DiyCurrency.load()
|
||||||
database = if (config.getBoolean("mysql.enable")) MysqlDatabase(config) else SQLiteDatabase()
|
database = if (config.getBoolean("mysql.enable")) MysqlDatabase(config) else SQLiteDatabase()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.database
|
package com.github.xbaimiao.shoppro.core.database
|
||||||
|
|
||||||
import com.github.xbaimiao.shoppro.core.item.Item
|
import com.github.xbaimiao.shoppro.core.item.Item
|
||||||
import com.github.xbaimiao.shoppro.core.item.ItemsAdderShopItem
|
import com.github.xbaimiao.shoppro.core.item.impl.ItemsAdderShopItem
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import taboolib.module.database.Host
|
import taboolib.module.database.Host
|
||||||
import taboolib.module.database.Table
|
import taboolib.module.database.Table
|
||||||
@@ -27,10 +27,10 @@ abstract class SqlDatabase : Database {
|
|||||||
|
|
||||||
override fun reset() {
|
override fun reset() {
|
||||||
serverTable.workspace(dataSource) {
|
serverTable.workspace(dataSource) {
|
||||||
executeUpdate("DELETE FROM '$serverTableName';").run()
|
executeUpdate("DELETE FROM $serverTableName;").run()
|
||||||
}.run()
|
}.run()
|
||||||
playerTable.workspace(dataSource) {
|
playerTable.workspace(dataSource) {
|
||||||
executeUpdate("DELETE FROM '$playerTableName';").run()
|
executeUpdate("DELETE FROM $playerTableName;").run()
|
||||||
}.run()
|
}.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,20 @@ package com.github.xbaimiao.shoppro.core.item
|
|||||||
|
|
||||||
import com.github.xbaimiao.shoppro.core.shop.Shop
|
import com.github.xbaimiao.shoppro.core.shop.Shop
|
||||||
import com.github.xbaimiao.shoppro.core.shop.ShopManager
|
import com.github.xbaimiao.shoppro.core.shop.ShopManager
|
||||||
import com.github.xbaimiao.shoppro.core.vault.Vault
|
|
||||||
import com.github.xbaimiao.shoppro.core.vault.VaultImpl
|
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.permissions.Permission
|
import org.bukkit.permissions.Permission
|
||||||
import taboolib.module.chat.colored
|
import taboolib.module.chat.colored
|
||||||
|
|
||||||
|
interface ItemLoader {
|
||||||
|
val prefix: String?
|
||||||
|
fun formSection(char: Char, section: ConfigurationSection, shop: Shop): Item
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
interface Item {
|
interface Item {
|
||||||
|
|
||||||
val key: Char
|
val key: Char
|
||||||
@@ -21,9 +26,6 @@ interface Item {
|
|||||||
val commands: List<String>
|
val commands: List<String>
|
||||||
val shop: Shop
|
val shop: Shop
|
||||||
|
|
||||||
val vault: Vault
|
|
||||||
get() = VaultImpl
|
|
||||||
|
|
||||||
fun isCommodity(): Boolean
|
fun isCommodity(): Boolean
|
||||||
fun buildItem(): ItemStack
|
fun buildItem(): ItemStack
|
||||||
fun update(player: Player): ItemStack
|
fun update(player: Player): ItemStack
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.github.xbaimiao.shoppro.core.item
|
|||||||
|
|
||||||
import com.github.xbaimiao.shoppro.ShopPro
|
import com.github.xbaimiao.shoppro.ShopPro
|
||||||
import com.github.xbaimiao.shoppro.core.shop.Shop
|
import com.github.xbaimiao.shoppro.core.shop.Shop
|
||||||
|
import com.github.xbaimiao.shoppro.core.vault.Currency
|
||||||
|
import com.github.xbaimiao.shoppro.core.vault.VaultImpl
|
||||||
import com.github.xbaimiao.shoppro.util.Util.format
|
import com.github.xbaimiao.shoppro.util.Util.format
|
||||||
import com.github.xbaimiao.shoppro.util.Util.howManyItems
|
import com.github.xbaimiao.shoppro.util.Util.howManyItems
|
||||||
import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
||||||
@@ -19,6 +21,8 @@ abstract class ShopItem : Item {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currency: Currency = VaultImpl
|
||||||
|
|
||||||
abstract fun vanillaItem(): ItemStack
|
abstract fun vanillaItem(): ItemStack
|
||||||
|
|
||||||
abstract fun equal(itemStack: ItemStack): Boolean
|
abstract fun equal(itemStack: ItemStack): Boolean
|
||||||
@@ -43,7 +47,7 @@ abstract class ShopItem : Item {
|
|||||||
for (line in this) {
|
for (line in this) {
|
||||||
var newLine = line.replace("\${name}", name)
|
var newLine = line.replace("\${name}", name)
|
||||||
.replace("\${price}", price.toString())
|
.replace("\${price}", price.toString())
|
||||||
.replace("\${money}", vault.getMoney(player).toString())
|
.replace("\${money}", currency.getMoney(player).toString())
|
||||||
.replace("\${price64}", (price * 64).toString())
|
.replace("\${price64}", (price * 64).toString())
|
||||||
.replace("\${limit}", limitPlayer.toString())
|
.replace("\${limit}", limitPlayer.toString())
|
||||||
.replace("\${allLimit}", limitServer.toString())
|
.replace("\${allLimit}", limitServer.toString())
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.item
|
|
||||||
|
|
||||||
import com.github.xbaimiao.shoppro.core.shop.Shop
|
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.inventory.ItemStack
|
|
||||||
|
|
||||||
class VanillaShopItem(
|
|
||||||
override val key: Char,
|
|
||||||
override val material: Material,
|
|
||||||
override val price: Double,
|
|
||||||
override val limitServer: Long,
|
|
||||||
override val limitPlayer: Long,
|
|
||||||
override val name: String,
|
|
||||||
override val lore: List<String>,
|
|
||||||
override val vanilla: Boolean,
|
|
||||||
override val commands: List<String>,
|
|
||||||
override val shop: Shop
|
|
||||||
) : ShopItem() {
|
|
||||||
|
|
||||||
override fun vanillaItem(): ItemStack {
|
|
||||||
return taboolib.platform.util.buildItem(material)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equal(itemStack: ItemStack): Boolean {
|
|
||||||
return itemStack.itemMeta?.hasLore() == false && itemStack.type == material
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun buildItem(): ItemStack {
|
|
||||||
return taboolib.platform.util.buildItem(material) {
|
|
||||||
this.name = this@VanillaShopItem.name
|
|
||||||
this.lore.addAll(this@VanillaShopItem.lore)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+34
-1
@@ -1,9 +1,16 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.item
|
package com.github.xbaimiao.shoppro.core.item.impl
|
||||||
|
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.Item
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ItemLoader
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ShopItem
|
||||||
import com.github.xbaimiao.shoppro.core.shop.Shop
|
import com.github.xbaimiao.shoppro.core.shop.Shop
|
||||||
|
import com.github.xbaimiao.shoppro.core.vault.CurrencyType
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import taboolib.library.xseries.XMaterial
|
import taboolib.library.xseries.XMaterial
|
||||||
|
import taboolib.library.xseries.parseToMaterial
|
||||||
|
import taboolib.module.chat.colored
|
||||||
import taboolib.platform.util.ItemBuilder
|
import taboolib.platform.util.ItemBuilder
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -47,4 +54,30 @@ class HeadShopItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object : ItemLoader {
|
||||||
|
|
||||||
|
override var prefix: String? = "HEAD"
|
||||||
|
|
||||||
|
override fun formSection(char: Char, section: ConfigurationSection, shop: Shop): Item {
|
||||||
|
return HeadShopItem(
|
||||||
|
char,
|
||||||
|
section.getString("material")!!,
|
||||||
|
section.getDouble("price"),
|
||||||
|
section.getLong("limit"),
|
||||||
|
section.getLong("limit-player"),
|
||||||
|
section.getString("name")!!.colored(),
|
||||||
|
section.getStringList("lore").colored(),
|
||||||
|
section.getBoolean("vanilla", true),
|
||||||
|
section.getStringList("commands"),
|
||||||
|
shop,
|
||||||
|
section.getString("item")!!.parseToMaterial()
|
||||||
|
).also {
|
||||||
|
section.getString("currency")?.let { currency ->
|
||||||
|
it.currency = CurrencyType.formString(currency).func.invoke(currency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+22
-1
@@ -1,11 +1,15 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.item
|
package com.github.xbaimiao.shoppro.core.item.impl
|
||||||
|
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.Item
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ItemLoader
|
||||||
import com.github.xbaimiao.shoppro.core.shop.Shop
|
import com.github.xbaimiao.shoppro.core.shop.Shop
|
||||||
import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import taboolib.library.xseries.XMaterial
|
import taboolib.library.xseries.XMaterial
|
||||||
|
import taboolib.module.chat.colored
|
||||||
import taboolib.platform.util.ItemBuilder
|
import taboolib.platform.util.ItemBuilder
|
||||||
import taboolib.platform.util.modifyLore
|
import taboolib.platform.util.modifyLore
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -62,4 +66,21 @@ class ItemImpl(
|
|||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object : ItemLoader {
|
||||||
|
|
||||||
|
override var prefix: String? = null
|
||||||
|
|
||||||
|
override fun formSection(char: Char, section: ConfigurationSection, shop: Shop): Item {
|
||||||
|
return ItemImpl(
|
||||||
|
section.getString("material")!!,
|
||||||
|
section.getStringList("lore").colored(),
|
||||||
|
section.getString("name")!!.colored(),
|
||||||
|
char,
|
||||||
|
section.getBoolean("vanilla", true),
|
||||||
|
section.getStringList("commands"),
|
||||||
|
shop
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+32
-1
@@ -1,9 +1,15 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.item
|
package com.github.xbaimiao.shoppro.core.item.impl
|
||||||
|
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.Item
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ItemLoader
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ShopItem
|
||||||
import com.github.xbaimiao.shoppro.core.shop.Shop
|
import com.github.xbaimiao.shoppro.core.shop.Shop
|
||||||
|
import com.github.xbaimiao.shoppro.core.vault.CurrencyType
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import taboolib.library.xseries.XMaterial
|
import taboolib.library.xseries.XMaterial
|
||||||
|
import taboolib.module.chat.colored
|
||||||
|
|
||||||
class ItemsAdderShopItem(
|
class ItemsAdderShopItem(
|
||||||
override val key: Char,
|
override val key: Char,
|
||||||
@@ -47,4 +53,29 @@ class ItemsAdderShopItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object : ItemLoader {
|
||||||
|
|
||||||
|
override var prefix: String? = "IA"
|
||||||
|
|
||||||
|
override fun formSection(char: Char, section: ConfigurationSection, shop: Shop): Item {
|
||||||
|
return ItemsAdderShopItem(
|
||||||
|
char,
|
||||||
|
section.getDouble("price"),
|
||||||
|
section.getString("material")!!,
|
||||||
|
section.getLong("limit"),
|
||||||
|
section.getLong("limit-player"),
|
||||||
|
section.getString("name")!!.colored(),
|
||||||
|
section.getStringList("lore").colored(),
|
||||||
|
section.getBoolean("vanilla", true),
|
||||||
|
section.getStringList("commands"),
|
||||||
|
shop
|
||||||
|
).also {
|
||||||
|
section.getString("currency")?.let { currency ->
|
||||||
|
it.currency = CurrencyType.formString(currency).func.invoke(currency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.github.xbaimiao.shoppro.core.item.impl
|
||||||
|
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.Item
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ItemLoader
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ShopItem
|
||||||
|
import com.github.xbaimiao.shoppro.core.shop.Shop
|
||||||
|
import com.github.xbaimiao.shoppro.core.vault.CurrencyType
|
||||||
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import taboolib.library.xseries.parseToMaterial
|
||||||
|
import taboolib.module.chat.colored
|
||||||
|
|
||||||
|
class VanillaShopItem(
|
||||||
|
override val key: Char,
|
||||||
|
override val material: Material,
|
||||||
|
override val price: Double,
|
||||||
|
override val limitServer: Long,
|
||||||
|
override val limitPlayer: Long,
|
||||||
|
override val name: String,
|
||||||
|
override val lore: List<String>,
|
||||||
|
override val vanilla: Boolean,
|
||||||
|
override val commands: List<String>,
|
||||||
|
override val shop: Shop
|
||||||
|
) : ShopItem() {
|
||||||
|
|
||||||
|
override fun vanillaItem(): ItemStack {
|
||||||
|
return taboolib.platform.util.buildItem(material)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equal(itemStack: ItemStack): Boolean {
|
||||||
|
return itemStack.itemMeta?.hasLore() == false && itemStack.type == material
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun buildItem(): ItemStack {
|
||||||
|
return taboolib.platform.util.buildItem(material) {
|
||||||
|
this.name = this@VanillaShopItem.name
|
||||||
|
this.lore.addAll(this@VanillaShopItem.lore)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : ItemLoader {
|
||||||
|
|
||||||
|
override var prefix: String? = null
|
||||||
|
|
||||||
|
override fun formSection(char: Char, section: ConfigurationSection, shop: Shop): Item {
|
||||||
|
return VanillaShopItem(
|
||||||
|
char,
|
||||||
|
section.getString("material")!!.parseToMaterial(),
|
||||||
|
section.getDouble("price"),
|
||||||
|
section.getLong("limit"),
|
||||||
|
section.getLong("limit-player"),
|
||||||
|
section.getString("name")!!.colored(),
|
||||||
|
section.getStringList("lore").colored(),
|
||||||
|
section.getBoolean("vanilla", true),
|
||||||
|
section.getStringList("commands"),
|
||||||
|
shop
|
||||||
|
).also {
|
||||||
|
section.getString("currency")?.let { currency ->
|
||||||
|
it.currency = CurrencyType.formString(currency).func.invoke(currency)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,14 +4,16 @@ import com.github.xbaimiao.shoppro.ShopPro
|
|||||||
import com.github.xbaimiao.shoppro.api.ShopProBuyEvent
|
import com.github.xbaimiao.shoppro.api.ShopProBuyEvent
|
||||||
import com.github.xbaimiao.shoppro.api.ShopProSellEvent
|
import com.github.xbaimiao.shoppro.api.ShopProSellEvent
|
||||||
import com.github.xbaimiao.shoppro.core.database.LimitData
|
import com.github.xbaimiao.shoppro.core.database.LimitData
|
||||||
import com.github.xbaimiao.shoppro.core.item.*
|
import com.github.xbaimiao.shoppro.core.item.Item
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.impl.ItemImpl
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.ShopItem
|
||||||
|
import com.github.xbaimiao.shoppro.core.item.impl.VanillaShopItem
|
||||||
import com.github.xbaimiao.shoppro.util.Util.howManyItems
|
import com.github.xbaimiao.shoppro.util.Util.howManyItems
|
||||||
import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.configuration.Configuration
|
import org.bukkit.configuration.Configuration
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import taboolib.common.platform.function.info
|
import taboolib.common.platform.function.info
|
||||||
import taboolib.library.xseries.parseToMaterial
|
|
||||||
import taboolib.module.chat.colored
|
import taboolib.module.chat.colored
|
||||||
import taboolib.module.ui.ClickType
|
import taboolib.module.ui.ClickType
|
||||||
import taboolib.module.ui.openMenu
|
import taboolib.module.ui.openMenu
|
||||||
@@ -29,69 +31,22 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
val section = configuration.getConfigurationSection("items")!!
|
val section = configuration.getConfigurationSection("items")!!
|
||||||
for (key in section.getKeys(false)) {
|
a@ for (key in section.getKeys(false)) {
|
||||||
try {
|
try {
|
||||||
|
val subSection = section.getConfigurationSection(key)!!
|
||||||
if (section.getBoolean("$key.is-commodity", true)) {
|
if (section.getBoolean("$key.is-commodity", true)) {
|
||||||
val materialString = section.getString("$key.material")!!
|
val materialString = section.getString("$key.material")!!
|
||||||
if (materialString.startsWith("IA")) {
|
for (loader in ShopPro.itemLoader) {
|
||||||
items.add(
|
if (loader.prefix != null) {
|
||||||
ItemsAdderShopItem(
|
if (materialString.startsWith(loader.prefix!!)) {
|
||||||
key[0],
|
items.add(loader.formSection(key[0], subSection, this))
|
||||||
section.getDouble("$key.price"),
|
continue@a
|
||||||
materialString,
|
}
|
||||||
section.getLong("$key.limit"),
|
}
|
||||||
section.getLong("$key.limit-player"),
|
|
||||||
section.getString("$key.name")!!.colored(),
|
|
||||||
section.getStringList("$key.lore").colored(),
|
|
||||||
section.getBoolean("$key.vanilla", true),
|
|
||||||
section.getStringList("$key.commands"),
|
|
||||||
this
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else if (materialString.startsWith("HEAD:")) {
|
|
||||||
items.add(
|
|
||||||
HeadShopItem(
|
|
||||||
key[0],
|
|
||||||
section.getString("$key.material")!!,
|
|
||||||
section.getDouble("$key.price"),
|
|
||||||
section.getLong("$key.limit"),
|
|
||||||
section.getLong("$key.limit-player"),
|
|
||||||
section.getString("$key.name")!!.colored(),
|
|
||||||
section.getStringList("$key.lore").colored(),
|
|
||||||
section.getBoolean("$key.vanilla", true),
|
|
||||||
section.getStringList("$key.commands"),
|
|
||||||
this,
|
|
||||||
section.getString("$key.item")!!.parseToMaterial()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
items.add(
|
|
||||||
VanillaShopItem(
|
|
||||||
key[0],
|
|
||||||
section.getString("$key.material")!!.parseToMaterial(),
|
|
||||||
section.getDouble("$key.price"),
|
|
||||||
section.getLong("$key.limit"),
|
|
||||||
section.getLong("$key.limit-player"),
|
|
||||||
section.getString("$key.name")!!.colored(),
|
|
||||||
section.getStringList("$key.lore").colored(),
|
|
||||||
section.getBoolean("$key.vanilla", true),
|
|
||||||
section.getStringList("$key.commands"),
|
|
||||||
this
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
items.add(VanillaShopItem.formSection(key[0], subSection, this))
|
||||||
} else {
|
} else {
|
||||||
items.add(
|
items.add(ItemImpl.formSection(key[0], subSection, this))
|
||||||
ItemImpl(
|
|
||||||
section.getString("$key.material")!!,
|
|
||||||
section.getStringList("$key.lore").colored(),
|
|
||||||
section.getString("$key.name")!!.colored(),
|
|
||||||
key[0],
|
|
||||||
section.getBoolean("$key.vanilla", true),
|
|
||||||
section.getStringList("$key.commands"),
|
|
||||||
this
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
info("在加载Shop: ${getName()} 时,物品: $key 加载出现异常,跳过加载,错误信息如下")
|
info("在加载Shop: ${getName()} 时,物品: $key 加载出现异常,跳过加载,错误信息如下")
|
||||||
@@ -180,7 +135,7 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item.vault.takeMoney(player, item.price * amount)) {
|
if (item.currency.takeMoney(player, item.price * amount)) {
|
||||||
if (item.vanilla) {
|
if (item.vanilla) {
|
||||||
val vanilla = item.vanillaItem()
|
val vanilla = item.vanillaItem()
|
||||||
vanilla.amount = amount
|
vanilla.amount = amount
|
||||||
@@ -208,7 +163,7 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
|
|||||||
}
|
}
|
||||||
if (player.inventory.hasItem(amount) { item.equal(it) }) {
|
if (player.inventory.hasItem(amount) { item.equal(it) }) {
|
||||||
player.inventory.takeItem(amount) { item.equal(it) }
|
player.inventory.takeItem(amount) { item.equal(it) }
|
||||||
item.vault.giveMoney(player, item.price * amount)
|
item.currency.giveMoney(player, item.price * amount)
|
||||||
Bukkit.getPluginManager().callEvent(ShopProSellEvent(item, amount, player))
|
Bukkit.getPluginManager().callEvent(ShopProSellEvent(item, amount, player))
|
||||||
ShopPro.database.addAmount(item, player, LimitData(0L, amount.toLong()))
|
ShopPro.database.addAmount(item, player, LimitData(0L, amount.toLong()))
|
||||||
player.sendLang("sell-item", amount, item.name, item.price * amount)
|
player.sendLang("sell-item", amount, item.name, item.price * amount)
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.github.xbaimiao.shoppro.core.vault
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
|
interface Currency {
|
||||||
|
|
||||||
|
fun hasMoney(player: Player, double: Double): Boolean
|
||||||
|
|
||||||
|
fun giveMoney(player: Player, double: Double)
|
||||||
|
|
||||||
|
fun takeMoney(player: Player, double: Double): Boolean
|
||||||
|
|
||||||
|
fun getMoney(player: Player): Double
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class CurrencyType(val string: String, val func: (name: String) -> Currency) {
|
||||||
|
|
||||||
|
VAULT("vault", { VaultImpl }),
|
||||||
|
POINTS("points", {
|
||||||
|
PointsImpl()
|
||||||
|
}),
|
||||||
|
DIY("diy", {
|
||||||
|
DiyCurrency.formString(it)
|
||||||
|
});
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun formString(string: String): CurrencyType {
|
||||||
|
return CurrencyType.values().firstOrNull { it.string == string.lowercase() } ?: DIY
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.github.xbaimiao.shoppro.core.vault
|
||||||
|
|
||||||
|
import com.github.xbaimiao.shoppro.util.Util
|
||||||
|
import com.github.xbaimiao.shoppro.util.Util.format
|
||||||
|
import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.configuration.Configuration
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import taboolib.common.platform.function.info
|
||||||
|
import taboolib.platform.BukkitPlugin
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class DiyCurrency(configuration: Configuration) : Currency {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val cache = ArrayList<DiyCurrency>()
|
||||||
|
|
||||||
|
fun load() {
|
||||||
|
cache.clear()
|
||||||
|
val file = File(BukkitPlugin.getInstance().dataFolder, "currencys")
|
||||||
|
var listFile = file.listFiles()
|
||||||
|
if (listFile == null || listFile.isEmpty()) {
|
||||||
|
BukkitPlugin.getInstance().saveResource("currencys/Diy1.yml", false)
|
||||||
|
listFile = file.listFiles()!!
|
||||||
|
}
|
||||||
|
listFile.forEach {
|
||||||
|
cache.add(DiyCurrency(YamlConfiguration.loadConfiguration(it)))
|
||||||
|
}
|
||||||
|
info("加载了 ${cache.size} 个自定义货币")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun formString(name: String): DiyCurrency {
|
||||||
|
return cache.first { it.name == name }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
val name = configuration.getString("name")!!
|
||||||
|
private val takeCommand = configuration.getString("takeCommand")!!
|
||||||
|
private val giveCommand = configuration.getString("giveCommand")!!
|
||||||
|
private val amountPapi = configuration.getString("amountPapi")!!
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (!Util.hasPapi) {
|
||||||
|
error("自定义货币必须安装PlaceholderAPI插件")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hasMoney(player: Player, double: Double): Boolean {
|
||||||
|
return getMoney(player) >= double
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun giveMoney(player: Player, double: Double) {
|
||||||
|
val cmd = replace(giveCommand, player, double.format())
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun takeMoney(player: Player, double: Double): Boolean {
|
||||||
|
if (!hasMoney(player, double.format())) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
val cmd = replace(takeCommand, player, double.format())
|
||||||
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMoney(player: Player): Double {
|
||||||
|
return amountPapi.replacePapi(player).toDouble().format()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun replace(string: String, player: Player, num: Double): String {
|
||||||
|
return string.replace("%player%", player.name).replace("%num%", num.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.github.xbaimiao.shoppro.core.vault
|
||||||
|
|
||||||
|
import org.black_ixx.playerpoints.PlayerPoints
|
||||||
|
import org.black_ixx.playerpoints.PlayerPointsAPI
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
|
class PointsImpl : Currency {
|
||||||
|
|
||||||
|
private val pointsAPI: PlayerPointsAPI
|
||||||
|
|
||||||
|
init {
|
||||||
|
val plugin = Bukkit.getPluginManager().getPlugin("PlayerPoints")?.let {
|
||||||
|
it as PlayerPoints
|
||||||
|
} ?: error("未找到PlayerPoints")
|
||||||
|
pointsAPI = plugin.api
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hasMoney(player: Player, double: Double): Boolean {
|
||||||
|
return getMoney(player) >= double
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun giveMoney(player: Player, double: Double) {
|
||||||
|
pointsAPI.give(player.uniqueId, double.toInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun takeMoney(player: Player, double: Double): Boolean {
|
||||||
|
if (hasMoney(player, double)) {
|
||||||
|
pointsAPI.take(player.uniqueId, double.toInt())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMoney(player: Player): Double {
|
||||||
|
return pointsAPI.look(player.uniqueId).toDouble()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.vault
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player
|
|
||||||
|
|
||||||
interface Vault {
|
|
||||||
|
|
||||||
fun hasMoney(player: Player, double: Double): Boolean
|
|
||||||
|
|
||||||
fun giveMoney(player: Player, double: Double)
|
|
||||||
|
|
||||||
fun takeMoney(player: Player, double: Double): Boolean
|
|
||||||
|
|
||||||
fun getMoney(player: Player): Double
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ import com.github.xbaimiao.shoppro.util.Util.format
|
|||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import taboolib.platform.compat.VaultService
|
import taboolib.platform.compat.VaultService
|
||||||
|
|
||||||
object VaultImpl : Vault {
|
object VaultImpl : Currency {
|
||||||
|
|
||||||
override fun hasMoney(player: Player, double: Double): Boolean {
|
override fun hasMoney(player: Player, double: Double): Boolean {
|
||||||
return getMoney(player) >= double.format()
|
return getMoney(player) >= double.format()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.text.DecimalFormat
|
|||||||
|
|
||||||
object Util {
|
object Util {
|
||||||
|
|
||||||
private val hasPapi by lazy { Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null }.also {
|
val hasPapi by lazy { Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null }.also {
|
||||||
info("PlaceholderAPI Hook")
|
info("PlaceholderAPI Hook")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# 货币的识别名 可在物品哪里指定为你自定义的货币
|
||||||
|
# 例子
|
||||||
|
# A:
|
||||||
|
# material: STONE
|
||||||
|
# currency: DIY1
|
||||||
|
name: "DIY1"
|
||||||
|
takeCommand: "扣除货币的指令 %player% 为玩家变量 %num% 为数量"
|
||||||
|
giveCommand: "给货币的指令 %player% 为玩家变量 %num% 为数量"
|
||||||
|
amountPapi: "你自定义的这个货币的papi变量"
|
||||||
@@ -20,6 +20,10 @@ items:
|
|||||||
# 普通物品收购示例
|
# 普通物品收购示例
|
||||||
A:
|
A:
|
||||||
material: STONE
|
material: STONE
|
||||||
|
# 指定货币 如果不指定默认Vault
|
||||||
|
# 已预设点券支持 为: "points"
|
||||||
|
# 您可在 currencys 里自定义货币
|
||||||
|
currency: points
|
||||||
name: '石头'
|
name: '石头'
|
||||||
# 每日限购买
|
# 每日限购买
|
||||||
limit: 5000
|
limit: 5000
|
||||||
|
|||||||
Reference in New Issue
Block a user