a lot of bug fix
This commit is contained in:
parent
521e11197b
commit
678eb96762
|
|
@ -6,7 +6,6 @@ import taboolib.common.platform.function.info
|
||||||
import taboolib.module.configuration.Config
|
import taboolib.module.configuration.Config
|
||||||
import taboolib.module.configuration.Configuration
|
import taboolib.module.configuration.Configuration
|
||||||
import taboolib.platform.BukkitPlugin
|
import taboolib.platform.BukkitPlugin
|
||||||
import work.microhand.sanseyooyea.sansefish.command.setBaitCmd
|
|
||||||
import work.microhand.sanseyooyea.sansefish.command.registerCommand
|
import work.microhand.sanseyooyea.sansefish.command.registerCommand
|
||||||
import work.microhand.sanseyooyea.sansefish.command.StorageCommand
|
import work.microhand.sanseyooyea.sansefish.command.StorageCommand
|
||||||
|
|
||||||
|
|
@ -16,15 +15,14 @@ object SanseFish : Plugin() {
|
||||||
lateinit var conf: Configuration
|
lateinit var conf: Configuration
|
||||||
private set
|
private set
|
||||||
|
|
||||||
val baitKey = NamespacedKey(BukkitPlugin.getInstance(), "bait")
|
val baitKey by lazy { NamespacedKey(BukkitPlugin.getInstance(), "bait") }
|
||||||
val maxLuckKey = NamespacedKey(BukkitPlugin.getInstance(), "max_luck")
|
val maxLuckKey by lazy { NamespacedKey(BukkitPlugin.getInstance(), "max_luck") }
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
info("§a| §7正在加载钓鱼插件(SanseFish)..")
|
info("§a| §7正在加载钓鱼插件(SanseFish)..")
|
||||||
info("§a| §7作者QQ: 1187586838")
|
info("§a| §7作者QQ: 1187586838")
|
||||||
registerCommand()
|
registerCommand()
|
||||||
StorageCommand.registerCommand()
|
StorageCommand.registerCommand()
|
||||||
setBaitCmd()
|
|
||||||
|
|
||||||
info("§a| §7插件加载完成.")
|
info("§a| §7插件加载完成.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,4 @@ fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import org.bukkit.event.player.PlayerInteractEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
import taboolib.common.platform.event.SubscribeEvent
|
import taboolib.common.platform.event.SubscribeEvent
|
||||||
|
import taboolib.platform.util.ItemBuilder
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
||||||
import work.microhand.sanseyooyea.sansefish.ui.BaitUI
|
import work.microhand.sanseyooyea.sansefish.ui.BaitUI
|
||||||
|
|
@ -34,6 +35,7 @@ object FishListener {
|
||||||
val rodItem = if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand
|
val rodItem = if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand
|
||||||
|
|
||||||
if (fishEvent.state == PlayerFishEvent.State.FISHING) {
|
if (fishEvent.state == PlayerFishEvent.State.FISHING) {
|
||||||
|
player.sendMessage(rodItem.itemMeta!!.persistentDataContainer.keys.toString())
|
||||||
if (!rodItem.itemMeta!!.persistentDataContainer.has(
|
if (!rodItem.itemMeta!!.persistentDataContainer.has(
|
||||||
SanseFish.baitKey,
|
SanseFish.baitKey,
|
||||||
PersistentDataType.STRING
|
PersistentDataType.STRING
|
||||||
|
|
@ -57,9 +59,11 @@ object FishListener {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
fun useBait(event: PlayerInteractEvent) {
|
fun useBait(event: PlayerInteractEvent) {
|
||||||
|
println(event.action)
|
||||||
if (event.action != Action.LEFT_CLICK_AIR && event.action != Action.LEFT_CLICK_BLOCK) return
|
if (event.action != Action.LEFT_CLICK_AIR && event.action != Action.LEFT_CLICK_BLOCK) return
|
||||||
if (!event.hasItem()) return
|
if (!event.hasItem()) return
|
||||||
if (event.item!!.type != Material.FISHING_ROD) return
|
if (event.item!!.type != Material.FISHING_ROD) return
|
||||||
|
if (event.item!!.itemMeta!!.persistentDataContainer.has(SanseFish.baitKey, PersistentDataType.STRING)) return
|
||||||
RodManager.parseRod(event.item!!) ?: return
|
RodManager.parseRod(event.item!!) ?: return
|
||||||
BaitUI(event.player).open()
|
BaitUI(event.player).open()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import work.microhand.sanseyooyea.sansefish.command.StorageCommand
|
||||||
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
||||||
import work.microhand.sanseyooyea.sansefish.misc.BaitReward
|
import work.microhand.sanseyooyea.sansefish.misc.BaitReward
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.IllegalArgumentException
|
|
||||||
|
|
||||||
object BaitManager {
|
object BaitManager {
|
||||||
val baits = HashMap<String, Bait>()
|
val baits = HashMap<String, Bait>()
|
||||||
|
|
@ -30,7 +29,7 @@ object BaitManager {
|
||||||
// load baits.
|
// load baits.
|
||||||
File(getDataFolder(), "baits").listFiles()?.forEach { file ->
|
File(getDataFolder(), "baits").listFiles()?.forEach { file ->
|
||||||
val config = Configuration.loadFromFile(file)
|
val config = Configuration.loadFromFile(file)
|
||||||
val key = config.getString("item")!!
|
val key = config.getString("item")?: throw IllegalArgumentException("鱼饵 ${file.nameWithoutExtension} 未配置物品.")
|
||||||
val item = StorageCommand.itemStorage.getItemStack(key)?: throw IllegalArgumentException("物品 $key 不存在.")
|
val item = StorageCommand.itemStorage.getItemStack(key)?: throw IllegalArgumentException("物品 $key 不存在.")
|
||||||
val rewards = BaitReward(config)
|
val rewards = BaitReward(config)
|
||||||
baits[file.nameWithoutExtension] = Bait(file.nameWithoutExtension, item, rewards, config)
|
baits[file.nameWithoutExtension] = Bait(file.nameWithoutExtension, item, rewards, config)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
package work.microhand.sanseyooyea.sansefish.misc
|
package work.microhand.sanseyooyea.sansefish.misc
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.event.player.PlayerFishEvent
|
import org.bukkit.event.player.PlayerFishEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
|
import taboolib.platform.BukkitPlugin
|
||||||
|
import taboolib.platform.util.ItemBuilder
|
||||||
import taboolib.platform.util.buildItem
|
import taboolib.platform.util.buildItem
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
||||||
|
|
@ -16,23 +19,32 @@ data class FishingRodInstance(
|
||||||
) {
|
) {
|
||||||
fun updateFishingRod(): ItemStack = buildItem(item) {
|
fun updateFishingRod(): ItemStack = buildItem(item) {
|
||||||
lore.clear()
|
lore.clear()
|
||||||
lore.addAll(listOf("", "", "§8神奇的鱼竿"))
|
lore.addAll(listOf("", "", type.lore))
|
||||||
lore[0] = "§e耐久: §7$durability"
|
lore[0] = "§e耐久: §7$durability"
|
||||||
lore[1] = "§d幸运值: §7$luck"
|
lore[1] = "§d幸运值: §7$luck"
|
||||||
val durabilityPercentage = (durability.toDouble() / SanseFish.conf.getInt("target-rod.max-durability", 100))
|
val durabilityPercentage = (durability.toDouble() / SanseFish.conf.getInt("target-rod.max-durability", 100))
|
||||||
damage = (64 * (1 - durabilityPercentage)).toInt()
|
damage = (64 * (1 - durabilityPercentage)).toInt()
|
||||||
}
|
println("Damage Before: $damage")
|
||||||
|
}.also { println("Damage After: ${ItemBuilder(it).damage}") }
|
||||||
|
|
||||||
fun handleFished(fishEvent: PlayerFishEvent) {
|
fun handleFished(fishEvent: PlayerFishEvent) {
|
||||||
fishEvent.expToDrop = 0
|
fishEvent.expToDrop = 0
|
||||||
fishEvent.caught!!.remove()
|
fishEvent.caught!!.remove()
|
||||||
fishEvent.player.inventory.itemInMainHand
|
|
||||||
val bait = BaitManager.baits[item.itemMeta!!.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING]?: return]!!
|
val bait = BaitManager.baits[item.itemMeta!!.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING]?: return]!!
|
||||||
luck++
|
luck++
|
||||||
val maxLuck = item.itemMeta!!.persistentDataContainer.getOrDefault(SanseFish.maxLuckKey, PersistentDataType.INTEGER, type.defaultLuck)
|
val maxLuck = item.itemMeta!!.persistentDataContainer.getOrDefault(SanseFish.maxLuckKey, PersistentDataType.INTEGER, type.defaultLuck)
|
||||||
if (luck > maxLuck) {
|
if (luck > maxLuck) {
|
||||||
|
val meta = item.itemMeta!!
|
||||||
|
meta.persistentDataContainer[SanseFish.maxLuckKey, PersistentDataType.INTEGER] = luck
|
||||||
|
item.itemMeta = meta
|
||||||
bait.rewards.doGuarantee(fishEvent.player, luck, maxLuck)
|
bait.rewards.doGuarantee(fishEvent.player, luck, maxLuck)
|
||||||
}
|
}
|
||||||
|
val meta = item.itemMeta!!
|
||||||
|
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance()) { _ ->
|
||||||
|
println("remove bait")
|
||||||
|
meta.persistentDataContainer.remove(SanseFish.baitKey)
|
||||||
|
fishEvent.player.inventory.itemInMainHand.itemMeta = meta
|
||||||
|
}
|
||||||
bait.rewards.doReward(fishEvent.player, this)
|
bait.rewards.doReward(fishEvent.player, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class BaitUI(private val player: Player) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
player.inventory.forEach {
|
player.inventory.forEach {
|
||||||
|
if (it == null) return@forEach
|
||||||
val bait = BaitManager.parseBait(it) ?: return@forEach
|
val bait = BaitManager.parseBait(it) ?: return@forEach
|
||||||
baits[bait] = baits.getOrDefault(bait, 0) + it.amount
|
baits[bait] = baits.getOrDefault(bait, 0) + it.amount
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +31,10 @@ class BaitUI(private val player: Player) {
|
||||||
set(index, item) {
|
set(index, item) {
|
||||||
isCancelled = true
|
isCancelled = true
|
||||||
player.inventory.removeItem(bait.item)
|
player.inventory.removeItem(bait.item)
|
||||||
player.inventory.itemInMainHand.itemMeta!!.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING] = bait.type
|
val meta = player.inventory.itemInMainHand.itemMeta!!
|
||||||
|
meta.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING] = bait.type
|
||||||
|
player.inventory.itemInMainHand.itemMeta = meta
|
||||||
|
player.sendMessage(player.inventory.itemInMainHand.itemMeta!!.persistentDataContainer.keys.toString())
|
||||||
player.sendMessage("§a| §7成功安装鱼饵")
|
player.sendMessage("§a| §7成功安装鱼饵")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue