商店支持zap物品
This commit is contained in:
@@ -4,7 +4,6 @@ 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 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
|
||||||
@@ -22,7 +21,7 @@ interface Item {
|
|||||||
val shop: Shop
|
val shop: Shop
|
||||||
|
|
||||||
fun isCommodity(): Boolean
|
fun isCommodity(): Boolean
|
||||||
fun buildItem(): ItemStack
|
fun buildItem(player: Player): ItemStack
|
||||||
fun update(player: Player): ItemStack
|
fun update(player: Player): ItemStack
|
||||||
|
|
||||||
fun exeCommands(player: Player, amount: Int) {
|
fun exeCommands(player: Player, amount: Int) {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.item
|
package com.github.xbaimiao.shoppro.core.item
|
||||||
|
|
||||||
import com.github.xbaimiao.shoppro.core.item.impl.HeadShopItem
|
import com.github.xbaimiao.shoppro.core.item.impl.*
|
||||||
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
|
|
||||||
|
|
||||||
class ItemLoaderManager {
|
class ItemLoaderManager {
|
||||||
|
|
||||||
@@ -14,6 +11,7 @@ class ItemLoaderManager {
|
|||||||
itemLoaders.add(ItemImpl)
|
itemLoaders.add(ItemImpl)
|
||||||
itemLoaders.add(ItemsAdderShopItem)
|
itemLoaders.add(ItemsAdderShopItem)
|
||||||
itemLoaders.add(HeadShopItem)
|
itemLoaders.add(HeadShopItem)
|
||||||
|
itemLoaders.add(ZapItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVanillaShop(): ItemLoader = VanillaShopItem.Companion
|
fun getVanillaShop(): ItemLoader = VanillaShopItem.Companion
|
||||||
|
|||||||
@@ -69,7 +69,10 @@ abstract class ShopItem(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun vanillaItem(): ItemStack
|
/**
|
||||||
|
* 构建发送给玩家的物品
|
||||||
|
*/
|
||||||
|
abstract fun vanillaItem(player: Player): ItemStack
|
||||||
|
|
||||||
abstract fun equal(itemStack: ItemStack): Boolean
|
abstract fun equal(itemStack: ItemStack): Boolean
|
||||||
|
|
||||||
@@ -88,7 +91,7 @@ abstract class ShopItem(
|
|||||||
} else {
|
} else {
|
||||||
ShopPro.database.getServerAlreadyData(this).sell
|
ShopPro.database.getServerAlreadyData(this).sell
|
||||||
}
|
}
|
||||||
val item = buildItem().modifyLore {
|
val item = buildItem(player).modifyLore {
|
||||||
val newLore = ArrayList<String>()
|
val newLore = ArrayList<String>()
|
||||||
for (line in this) {
|
for (line in this) {
|
||||||
var newLine = line.replace("\${name}", name)
|
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 com.github.xbaimiao.shoppro.core.shop.Shop
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.configuration.ConfigurationSection
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
|
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.library.xseries.parseToMaterial
|
import taboolib.library.xseries.parseToMaterial
|
||||||
@@ -26,7 +27,7 @@ class HeadShopItem(
|
|||||||
head = headString.substring(5)
|
head = headString.substring(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun vanillaItem(): ItemStack {
|
override fun vanillaItem(player: Player): ItemStack {
|
||||||
return taboolib.platform.util.buildItem(material) {
|
return taboolib.platform.util.buildItem(material) {
|
||||||
skullTexture = ItemBuilder.SkullTexture(head, UUID.randomUUID())
|
skullTexture = ItemBuilder.SkullTexture(head, UUID.randomUUID())
|
||||||
}
|
}
|
||||||
@@ -36,7 +37,7 @@ class HeadShopItem(
|
|||||||
return itemStack.itemMeta?.hasLore() == false && itemStack.type == item
|
return itemStack.itemMeta?.hasLore() == false && itemStack.type == item
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun buildItem(): ItemStack {
|
override fun buildItem(player: Player): ItemStack {
|
||||||
return taboolib.platform.util.buildItem(material) {
|
return taboolib.platform.util.buildItem(material) {
|
||||||
this.name = this@HeadShopItem.name
|
this.name = this@HeadShopItem.name
|
||||||
this.lore.addAll(this@HeadShopItem.lore)
|
this.lore.addAll(this@HeadShopItem.lore)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class ItemImpl(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun buildItem(): ItemStack {
|
override fun buildItem(player: Player): ItemStack {
|
||||||
return taboolib.platform.util.buildItem(material) {
|
return taboolib.platform.util.buildItem(material) {
|
||||||
this.name = this@ItemImpl.name
|
this.name = this@ItemImpl.name
|
||||||
this.lore.addAll(this@ItemImpl.lore)
|
this.lore.addAll(this@ItemImpl.lore)
|
||||||
@@ -59,7 +59,7 @@ class ItemImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun update(player: Player): ItemStack {
|
override fun update(player: Player): ItemStack {
|
||||||
val item = buildItem().modifyLore {
|
val item = buildItem(player).modifyLore {
|
||||||
val newLore = ArrayList<String>()
|
val newLore = ArrayList<String>()
|
||||||
for (line in this) {
|
for (line in this) {
|
||||||
newLore.add(line.replacePapi(player))
|
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.ItemLoader
|
||||||
import com.github.xbaimiao.shoppro.core.item.ShopItem
|
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.configuration.ConfigurationSection
|
||||||
|
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
|
||||||
|
|
||||||
@@ -33,13 +33,13 @@ class ItemsAdderShopItem(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun vanillaItem(): ItemStack {
|
override fun vanillaItem(player: Player): ItemStack {
|
||||||
return taboolib.platform.util.buildItem(material) {
|
return taboolib.platform.util.buildItem(material) {
|
||||||
this.customModelData = custom
|
this.customModelData = custom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun buildItem(): ItemStack {
|
override fun buildItem(player: Player): ItemStack {
|
||||||
return taboolib.platform.util.buildItem(material) {
|
return taboolib.platform.util.buildItem(material) {
|
||||||
this.name = this@ItemsAdderShopItem.name
|
this.name = this@ItemsAdderShopItem.name
|
||||||
this.lore.addAll(this@ItemsAdderShopItem.lore)
|
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.ItemLoader
|
||||||
import com.github.xbaimiao.shoppro.core.item.ShopItem
|
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.configuration.ConfigurationSection
|
import org.bukkit.configuration.ConfigurationSection
|
||||||
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import taboolib.platform.util.hasLore
|
import taboolib.platform.util.hasLore
|
||||||
|
|
||||||
class VanillaShopItem(
|
open class VanillaShopItem(itemSetting: ItemSetting) : ShopItem(itemSetting) {
|
||||||
itemSetting: ItemSetting
|
|
||||||
) : ShopItem(itemSetting) {
|
|
||||||
|
|
||||||
override fun vanillaItem(): ItemStack {
|
override fun vanillaItem(player: Player): ItemStack {
|
||||||
return taboolib.platform.util.buildItem(material)
|
return taboolib.platform.util.buildItem(material)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +19,7 @@ class VanillaShopItem(
|
|||||||
return itemStack.type == material && !itemStack.hasLore()
|
return itemStack.type == material && !itemStack.hasLore()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun buildItem(): ItemStack {
|
override fun buildItem(player: Player): ItemStack {
|
||||||
return taboolib.platform.util.buildItem(material) {
|
return taboolib.platform.util.buildItem(material) {
|
||||||
this.name = this@VanillaShopItem.name
|
this.name = this@VanillaShopItem.name
|
||||||
this.lore.addAll(this@VanillaShopItem.lore)
|
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) {
|
private fun buy(amount: Int, item: ShopItem, player: Player) {
|
||||||
if (item.currency.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(player)
|
||||||
vanilla.amount = amount
|
vanilla.amount = amount
|
||||||
player.giveItem(vanilla)
|
player.giveItem(vanilla)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ title: "系统出售商店"
|
|||||||
# 物品摆放顺序
|
# 物品摆放顺序
|
||||||
slots:
|
slots:
|
||||||
- 'NNNNNNNNN'
|
- 'NNNNNNNNN'
|
||||||
- 'NAB N'
|
- 'NABC N'
|
||||||
- 'NNNNNNNNN'
|
- 'NNNNNNNNN'
|
||||||
items:
|
items:
|
||||||
N:
|
N:
|
||||||
@@ -71,4 +71,27 @@ items:
|
|||||||
# 关闭此选项 可只执行命令 不给原版物品
|
# 关闭此选项 可只执行命令 不给原版物品
|
||||||
vanilla: false
|
vanilla: false
|
||||||
commands:
|
commands:
|
||||||
- '[console] ia give %player% 物品 ${amount}'
|
- '[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}'
|
||||||
Reference in New Issue
Block a user