商店支持zap物品

This commit is contained in:
小白
2023-05-15 19:49:05 +08:00
parent f56bdade63
commit a37c867d0a
12 changed files with 98 additions and 24 deletions
@@ -4,7 +4,6 @@ import com.github.xbaimiao.shoppro.core.shop.Shop
import com.github.xbaimiao.shoppro.core.shop.ShopManager
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.permissions.Permission
@@ -22,7 +21,7 @@ interface Item {
val shop: Shop
fun isCommodity(): Boolean
fun buildItem(): ItemStack
fun buildItem(player: Player): ItemStack
fun update(player: Player): ItemStack
fun exeCommands(player: Player, amount: Int) {
@@ -1,9 +1,6 @@
package 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.item.impl.*
class ItemLoaderManager {
@@ -14,6 +11,7 @@ class ItemLoaderManager {
itemLoaders.add(ItemImpl)
itemLoaders.add(ItemsAdderShopItem)
itemLoaders.add(HeadShopItem)
itemLoaders.add(ZapItem)
}
fun getVanillaShop(): ItemLoader = VanillaShopItem.Companion
@@ -69,7 +69,10 @@ abstract class ShopItem(
return true
}
abstract fun vanillaItem(): ItemStack
/**
* 构建发送给玩家的物品
*/
abstract fun vanillaItem(player: Player): ItemStack
abstract fun equal(itemStack: ItemStack): Boolean
@@ -88,7 +91,7 @@ abstract class ShopItem(
} else {
ShopPro.database.getServerAlreadyData(this).sell
}
val item = buildItem().modifyLore {
val item = buildItem(player).modifyLore {
val newLore = ArrayList<String>()
for (line in this) {
var newLine = line.replace("\${name}", name)
@@ -6,6 +6,7 @@ import com.github.xbaimiao.shoppro.core.item.ShopItem
import com.github.xbaimiao.shoppro.core.shop.Shop
import org.bukkit.Material
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.library.xseries.XMaterial
import taboolib.library.xseries.parseToMaterial
@@ -26,7 +27,7 @@ class HeadShopItem(
head = headString.substring(5)
}
override fun vanillaItem(): ItemStack {
override fun vanillaItem(player: Player): ItemStack {
return taboolib.platform.util.buildItem(material) {
skullTexture = ItemBuilder.SkullTexture(head, UUID.randomUUID())
}
@@ -36,7 +37,7 @@ class HeadShopItem(
return itemStack.itemMeta?.hasLore() == false && itemStack.type == item
}
override fun buildItem(): ItemStack {
override fun buildItem(player: Player): ItemStack {
return taboolib.platform.util.buildItem(material) {
this.name = this@HeadShopItem.name
this.lore.addAll(this@HeadShopItem.lore)
@@ -47,7 +47,7 @@ class ItemImpl(
return false
}
override fun buildItem(): ItemStack {
override fun buildItem(player: Player): ItemStack {
return taboolib.platform.util.buildItem(material) {
this.name = this@ItemImpl.name
this.lore.addAll(this@ItemImpl.lore)
@@ -59,7 +59,7 @@ class ItemImpl(
}
override fun update(player: Player): ItemStack {
val item = buildItem().modifyLore {
val item = buildItem(player).modifyLore {
val newLore = ArrayList<String>()
for (line in this) {
newLore.add(line.replacePapi(player))
@@ -4,9 +4,9 @@ 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.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.library.xseries.XMaterial
@@ -33,13 +33,13 @@ class ItemsAdderShopItem(
return false
}
override fun vanillaItem(): ItemStack {
override fun vanillaItem(player: Player): ItemStack {
return taboolib.platform.util.buildItem(material) {
this.customModelData = custom
}
}
override fun buildItem(): ItemStack {
override fun buildItem(player: Player): ItemStack {
return taboolib.platform.util.buildItem(material) {
this.name = this@ItemsAdderShopItem.name
this.lore.addAll(this@ItemsAdderShopItem.lore)
@@ -4,16 +4,14 @@ 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.configuration.ConfigurationSection
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.platform.util.hasLore
class VanillaShopItem(
itemSetting: ItemSetting
) : ShopItem(itemSetting) {
open class VanillaShopItem(itemSetting: ItemSetting) : ShopItem(itemSetting) {
override fun vanillaItem(): ItemStack {
override fun vanillaItem(player: Player): ItemStack {
return taboolib.platform.util.buildItem(material)
}
@@ -21,7 +19,7 @@ class VanillaShopItem(
return itemStack.type == material && !itemStack.hasLore()
}
override fun buildItem(): ItemStack {
override fun buildItem(player: Player): ItemStack {
return taboolib.platform.util.buildItem(material) {
this.name = this@VanillaShopItem.name
this.lore.addAll(this@VanillaShopItem.lore)
@@ -0,0 +1,52 @@
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 ink.ptms.zaphkiel.Zaphkiel
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
/**
* @author 小白
* @date 2023/5/15 17:59
**/
class ZapItem(
private val zapItem: ink.ptms.zaphkiel.api.Item,
itemSetting: ItemSetting
) : VanillaShopItem(itemSetting) {
override val material: Material
get() = zapItem.buildItemStack(null).type
override fun vanillaItem(player: Player): ItemStack {
return zapItem.buildItemStack(player)
}
override fun equal(itemStack: ItemStack): Boolean {
val item = Zaphkiel.api().getItemHandler().getItem(itemStack) ?: return false
return item.id == zapItem.id
}
companion object : ItemLoader() {
override val prefix: String = "Zaphkiel"
override fun formSection(char: Char, section: ConfigurationSection, shop: Shop): Item {
if (Bukkit.getPluginManager().plugins.find { it.name.lowercase() == "Zaphkiel".lowercase() } == null) {
error("Zaphkiel Plugin not found")
}
val zapId = section.getString("material")!!.substring(prefix.length + 1)
val item = Zaphkiel.api().getItemManager().getItem(zapId) ?: error("ZapItem $zapId not found")
return ZapItem(item, section.toItemSetting(char, shop))
}
override fun parseToMaterial(section: ConfigurationSection): Material {
return Material.AIR
}
}
}
@@ -172,7 +172,7 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
private fun buy(amount: Int, item: ShopItem, player: Player) {
if (item.currency.takeMoney(player, item.price * amount)) {
if (item.vanilla) {
val vanilla = item.vanillaItem()
val vanilla = item.vanillaItem(player)
vanilla.amount = amount
player.giveItem(vanilla)
}
+24 -1
View File
@@ -7,7 +7,7 @@ title: "系统出售商店"
# 物品摆放顺序
slots:
- 'NNNNNNNNN'
- 'NAB N'
- 'NABC N'
- 'NNNNNNNNN'
items:
N:
@@ -72,3 +72,26 @@ items:
vanilla: false
commands:
- '[console] ia give %player% 物品 ${amount}'
# Zaphkiel物品示范
C:
material: 'Zaphkiel:example_sword'
name: 'Zaphkiel物品'
# 每日限购买
limit: 5000
# 每个玩家限购买
limit-player: 500
# 物品金额
price: 2
lore:
- '&e| &7这里可以购买&6 ${name}'
- '&e| &7购买单价 &6${price}'
- '&e| &7你的余额 &6${money}'
- ''
- '&e|&6 左击 &7购买 &6单个'
- '&e|&6 右击 &7购买 &6一组 &7需要 &6${price64}'
- ''
- '&e| &7限买公示:'
- '&e| &7每人限制购买: ${limit}'
- '&e| &7全服限制购买: ${allLimit}'
- '&e| &7您已购买: ${limit-player}'
- '&e| &7全服剩余: ${limit-server}'