update
This commit is contained in:
parent
9e15bdced5
commit
9891a7188d
|
|
@ -10,6 +10,8 @@ taboolib {
|
|||
install("common-5")
|
||||
install("module-database")
|
||||
install("module-chat")
|
||||
install("module-ui")
|
||||
install("module-ui-receptacle")
|
||||
install("module-configuration")
|
||||
install("expansion-player-database")
|
||||
install("platform-bukkit")
|
||||
|
|
@ -23,7 +25,8 @@ repositories {
|
|||
|
||||
dependencies {
|
||||
compileOnly("ink.ptms:nms-all:1.0.0")
|
||||
compileOnly("ink.ptms.core:v11200:11200-minimize")
|
||||
compileOnly("ink.ptms.core:v11802:11802-minimize:mapped")
|
||||
compileOnly("ink.ptms.core:v11802:11802-minimize:universal")
|
||||
compileOnly(kotlin("stdlib"))
|
||||
compileOnly(fileTree("libs"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
package work.microhand.sanseyooyea.sansefish
|
||||
|
||||
import org.bukkit.NamespacedKey
|
||||
import taboolib.common.platform.Plugin
|
||||
import taboolib.common.platform.function.info
|
||||
import taboolib.module.configuration.Config
|
||||
import taboolib.module.configuration.Configuration
|
||||
import work.microhand.sanseyooyea.sansefish.command.fishCmd
|
||||
import taboolib.platform.BukkitPlugin
|
||||
import work.microhand.sanseyooyea.sansefish.command.setBaitCmd
|
||||
import work.microhand.sanseyooyea.sansefish.command.registerCommand
|
||||
import work.microhand.sanseyooyea.sansefish.reward.RewardHandler
|
||||
import work.microhand.sanseyooyea.sansefish.storage.StorageCommand
|
||||
import work.microhand.sanseyooyea.sansefish.command.StorageCommand
|
||||
|
||||
object SanseFish : Plugin() {
|
||||
|
||||
|
|
@ -15,13 +16,16 @@ object SanseFish : Plugin() {
|
|||
lateinit var conf: Configuration
|
||||
private set
|
||||
|
||||
val baitKey = NamespacedKey(BukkitPlugin.getInstance(), "bait")
|
||||
val maxLuckKey = NamespacedKey(BukkitPlugin.getInstance(), "max_luck")
|
||||
|
||||
override fun onEnable() {
|
||||
info("§a| §7正在加载钓鱼插件(SanseFish)..")
|
||||
info("§a| §7作者QQ: 1187586838")
|
||||
registerCommand()
|
||||
StorageCommand.registerCommand()
|
||||
fishCmd()
|
||||
RewardHandler
|
||||
setBaitCmd()
|
||||
|
||||
info("§a| §7插件加载完成.")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import taboolib.common.platform.command.command
|
|||
import taboolib.library.xseries.setItemStack
|
||||
import taboolib.platform.util.giveItem
|
||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
||||
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
||||
|
||||
fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
|
||||
|
|
@ -22,10 +23,14 @@ fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
|
|||
}
|
||||
}
|
||||
|
||||
fun fishCmd() = command("setBait", permission = "sansefish.setbait") {
|
||||
execute<Player> { sender, _, _ ->
|
||||
fun setBaitCmd() = command("setBait", permission = "sansefish.setbait") {
|
||||
dynamic {
|
||||
execute<Player> { sender, _, arg ->
|
||||
val bait = BaitManager.baits[arg]?: return@execute sender.sendMessage("§a| §7未找到该鱼饵")
|
||||
sender.sendMessage("§a| §7您手中物品已设置为鱼饵.")
|
||||
|
||||
SanseFish.conf.setItemStack("target-rod.bait", sender.inventory.itemInMainHand.clone().apply { amount = 1 })
|
||||
SanseFish.conf.saveToFile()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package work.microhand.sanseyooyea.sansefish.storage
|
||||
package work.microhand.sanseyooyea.sansefish.command
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.entity.Player
|
||||
|
|
@ -62,7 +62,7 @@ object StorageCommand {
|
|||
execute<Player> { sender, ctx, arg ->
|
||||
val target = Bukkit.getPlayerExact(ctx.argument(-1))
|
||||
val item = itemStorage.getItemStack(arg)?: return@execute sender.sendMessage("§c| §7该物品不存在.")
|
||||
target.giveItem(item)
|
||||
target!!.giveItem(item)
|
||||
sender.sendMessage("§a| §7已将物品 §a${arg} §7给予 §a${target.name}")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
package work.microhand.sanseyooyea.sansefish.listener
|
||||
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.block.Action
|
||||
import org.bukkit.event.player.PlayerFishEvent
|
||||
import org.bukkit.event.player.PlayerInteractEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import taboolib.common.platform.event.SubscribeEvent
|
||||
import taboolib.library.xseries.getItemStack
|
||||
import taboolib.platform.util.hasItem
|
||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
||||
import work.microhand.sanseyooyea.sansefish.reward.RewardHandler
|
||||
import work.microhand.sanseyooyea.sansefish.ui.BaitUI
|
||||
|
||||
object FishListener {
|
||||
@SubscribeEvent
|
||||
|
|
@ -25,30 +26,36 @@ object FishListener {
|
|||
}
|
||||
|
||||
var offHand = false
|
||||
val rod = RodManager.parseRod(player.inventory.itemInMainHand) ?: RodManager.parseRod(player.inventory.itemInOffHand).also {
|
||||
val rod =
|
||||
RodManager.parseRod(player.inventory.itemInMainHand) ?: RodManager.parseRod(player.inventory.itemInOffHand)
|
||||
.also {
|
||||
offHand = true
|
||||
} ?: throw IllegalStateException("???你咋钓鱼的")
|
||||
val rodItem = if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand
|
||||
|
||||
if (fishEvent.state == PlayerFishEvent.State.FISHING) {
|
||||
if (!rodItem.itemMeta!!.persistentDataContainer.has(SanseFish.baitKey, PersistentDataType.STRING)) return
|
||||
}
|
||||
|
||||
if (fishEvent.state != PlayerFishEvent.State.BITE) rod.durability--
|
||||
|
||||
if (fishEvent.state == PlayerFishEvent.State.CAUGHT_FISH) {
|
||||
fishEvent.expToDrop = 0
|
||||
rod.luck++
|
||||
fishEvent.caught.remove()
|
||||
if (!player.inventory.hasItem(1) {
|
||||
it.clone().apply { amount = 1 } == SanseFish.conf.getItemStack("target-rod.bait")
|
||||
}) {
|
||||
player.sendMessage("§c| §7您没有足够的鱼饵.")
|
||||
return
|
||||
}
|
||||
player.inventory.removeItem(SanseFish.conf.getItemStack("target-rod.bait"))
|
||||
RewardHandler.doReward(player, rod)
|
||||
rod.handleFished(fishEvent)
|
||||
}
|
||||
val resultItem = if (rod.durability <= 0) {
|
||||
player.sendMessage("§c| §7您的鱼竿已损坏")
|
||||
ItemStack(Material.AIR)
|
||||
} else rod.updateFishingRod(if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand)
|
||||
} else rod.updateFishingRod()
|
||||
|
||||
if (offHand) player.inventory.itemInOffHand = resultItem else player.inventory.itemInMainHand = resultItem
|
||||
if (offHand) player.inventory.setItemInOffHand(resultItem) else player.inventory.setItemInMainHand(resultItem)
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
fun useBait(event: PlayerInteractEvent) {
|
||||
if (event.action != Action.LEFT_CLICK_AIR && event.action != Action.LEFT_CLICK_BLOCK) return
|
||||
if (!event.hasItem()) return
|
||||
if (event.item!!.type != Material.FISHING_ROD) return
|
||||
RodManager.parseRod(event.item!!) ?: return
|
||||
BaitUI(event.player).open()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,44 @@
|
|||
package work.microhand.sanseyooyea.sansefish.manager
|
||||
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import taboolib.common.platform.function.getDataFolder
|
||||
import taboolib.library.xseries.getItemStack
|
||||
import taboolib.module.configuration.Configuration
|
||||
import work.microhand.sanseyooyea.sansefish.command.StorageCommand
|
||||
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
||||
import work.microhand.sanseyooyea.sansefish.misc.BaitReward
|
||||
import java.io.File
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
object BaitManager {
|
||||
val baits = HashMap<String, Bait>()
|
||||
|
||||
init {
|
||||
init()
|
||||
}
|
||||
|
||||
fun parseBait(item: ItemStack): Bait? {
|
||||
baits.forEach { (_, bait) ->
|
||||
if (bait.item.isSimilar(item)) {
|
||||
return bait
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
// load baits.
|
||||
File(getDataFolder(), "baits").listFiles()?.forEach { file ->
|
||||
val config = Configuration.loadFromFile(file)
|
||||
val durability = config.getInt("max-durability")
|
||||
val luck = config.getInt("luck-def")
|
||||
val lore = config.getString("lore")!!
|
||||
baits[file.nameWithoutExtension] = Bait(file.nameWithoutExtension,)
|
||||
val key = config.getString("item")!!
|
||||
val item = StorageCommand.itemStorage.getItemStack(key)?: throw IllegalArgumentException("物品 $key 不存在.")
|
||||
val rewards = BaitReward(config)
|
||||
baits[file.nameWithoutExtension] = Bait(file.nameWithoutExtension, item, rewards, config)
|
||||
}
|
||||
}
|
||||
|
||||
fun reload() {
|
||||
baits.clear()
|
||||
init()
|
||||
}
|
||||
}
|
||||
|
|
@ -38,6 +38,6 @@ object RodManager {
|
|||
val durability = builder.lore.findLast { it.startsWith("§e耐久: §7") }?.replace("§e耐久: §7", "")?.toInt()
|
||||
?: SanseFish.conf.getInt("target-rod.max-durability")
|
||||
val luck = builder.lore.findLast { it.startsWith("§d幸运值: §7") }?.replace("§d幸运值: §7", "")?.toInt() ?: 0
|
||||
return FishingRodInstance(type!!, durability, luck)
|
||||
return FishingRodInstance(type!!, item, durability, luck)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
package work.microhand.sanseyooyea.sansefish.misc
|
||||
|
||||
data class Bait(val type: String, ) {
|
||||
}
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import taboolib.module.configuration.Configuration
|
||||
|
||||
data class Bait(val type: String, val item: ItemStack, val rewards: BaitReward, val config: Configuration)
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package work.microhand.sanseyooyea.sansefish.reward
|
||||
package work.microhand.sanseyooyea.sansefish.misc
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||
import work.microhand.sanseyooyea.sansefish.misc.FishingRodInstance
|
||||
import taboolib.library.configuration.ConfigurationSection
|
||||
|
||||
object RewardHandler {
|
||||
class BaitReward(config: ConfigurationSection) {
|
||||
private val rewardList = ArrayList<Reward>()
|
||||
|
||||
// load Rewards
|
||||
|
|
@ -20,7 +19,7 @@ object RewardHandler {
|
|||
config["de-luck"] as Int
|
||||
)
|
||||
|
||||
rewardList.addAll(SanseFish.conf.getList("rewards")!!.map { parseReward(it as Map<String, Any>) })
|
||||
rewardList.addAll(config.getList("rewards")!!.map { parseReward(it as Map<String, Any>) })
|
||||
}
|
||||
|
||||
fun doReward(player: Player, rod: FishingRodInstance) {
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
package work.microhand.sanseyooyea.sansefish.misc
|
||||
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import work.microhand.sanseyooyea.sansefish.misc.FishingRodInstance
|
||||
|
||||
data class FishRod(val type: String, val lore: String, val maxDurability: Int, val defaultLuck: Int) {
|
||||
fun buildFishingRod(): ItemStack = FishingRodInstance(this).updateFishingRod(ItemStack(Material.FISHING_ROD))
|
||||
fun buildFishingRod(): ItemStack = FishingRodInstance(this).updateFishingRod()
|
||||
}
|
||||
|
|
@ -1,15 +1,20 @@
|
|||
package work.microhand.sanseyooyea.sansefish.misc
|
||||
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.event.player.PlayerFishEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import taboolib.platform.util.buildItem
|
||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
||||
|
||||
data class FishingRodInstance(
|
||||
val type: FishRod,
|
||||
val item: ItemStack = ItemStack(Material.FISHING_ROD),
|
||||
var durability: Int = type.maxDurability,
|
||||
var luck: Int = type.defaultLuck,
|
||||
) {
|
||||
fun updateFishingRod(legacy: ItemStack): ItemStack = buildItem(legacy) {
|
||||
fun updateFishingRod(): ItemStack = buildItem(item) {
|
||||
lore.clear()
|
||||
lore.addAll(listOf("", "", "§8神奇的鱼竿"))
|
||||
lore[0] = "§e耐久: §7$durability"
|
||||
|
|
@ -17,4 +22,13 @@ data class FishingRodInstance(
|
|||
val durabilityPercentage = (durability.toDouble() / SanseFish.conf.getInt("target-rod.max-durability", 100))
|
||||
damage = (64 * (1 - durabilityPercentage)).toInt()
|
||||
}
|
||||
|
||||
fun handleFished(fishEvent: PlayerFishEvent) {
|
||||
fishEvent.expToDrop = 0
|
||||
luck++
|
||||
fishEvent.caught!!.remove()
|
||||
fishEvent.player.inventory.itemInMainHand
|
||||
val bait = BaitManager.baits[item.itemMeta!!.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING]?: return]!!
|
||||
bait.rewards.doReward(fishEvent.player, this)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package work.microhand.sanseyooyea.sansefish.reward
|
||||
package work.microhand.sanseyooyea.sansefish.misc
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
import taboolib.common.platform.function.console
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package work.microhand.sanseyooyea.sansefish.ui
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.PlayerInventory
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import taboolib.common.platform.function.console
|
||||
import taboolib.module.ui.buildMenu
|
||||
import taboolib.module.ui.type.Basic
|
||||
import taboolib.module.ui.type.Linked
|
||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
||||
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
||||
|
||||
class BaitUI(private val player: Player) {
|
||||
private val baits = HashMap<Bait, Int>()
|
||||
|
||||
init {
|
||||
player.inventory.forEach {
|
||||
val bait = BaitManager.parseBait(it) ?: return@forEach
|
||||
baits[bait] = baits.getOrDefault(bait, 0) + it.amount
|
||||
}
|
||||
}
|
||||
|
||||
fun open() {
|
||||
val menu = buildMenu<Linked<Bait>> {
|
||||
rows(6)
|
||||
baits.onEachIndexed { index, (bait, count) ->
|
||||
val item = bait.item.clone()
|
||||
item.amount = if (count >= 64) 64 else count
|
||||
set(index, item) {
|
||||
isCancelled = true
|
||||
player.inventory.removeItem(bait.item)
|
||||
player.inventory.itemInMainHand.itemMeta!!.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING] = bait.type
|
||||
player.sendMessage("§a| §7成功安装鱼饵")
|
||||
}
|
||||
}
|
||||
}
|
||||
player.openInventory(menu)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
item: null
|
||||
|
||||
rewards:
|
||||
- items:
|
||||
- "物品1"
|
||||
- "物品2"
|
||||
commands:
|
||||
- "mm i give xxx" #钓到鱼时执行命令, %player% 为玩家
|
||||
- "broadcast 玩家 %player% 钓到了好东西!"
|
||||
chance: 0.2 #以小数形式存储
|
||||
multiple: 0.01 # 重复出现概率
|
||||
isGuarantees: false # 是否为保底物品
|
||||
luck: 0 #不受幸运值限制
|
||||
de-luck: 0 # 霉运物品扣除幸运值
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
lore: "&7指定钓竿"
|
||||
max-durability: 100
|
||||
luck-def: 0
|
||||
compatible-bait:
|
||||
- ""
|
||||
Loading…
Reference in New Issue