remove debug msg

add reloadCommand
remove useless codes
This commit is contained in:
tony_all 2022-07-04 15:49:34 +08:00
parent 76f63fcd60
commit b3f020598f
6 changed files with 20 additions and 23 deletions

View File

@ -12,11 +12,6 @@ import work.microhand.sanseyooyea.sansefish.manager.BaitManager
import work.microhand.sanseyooyea.sansefish.manager.RodManager
object SanseFish : Plugin() {
@Config("settings.yml")
lateinit var conf: Configuration
private set
val baitKey by lazy { NamespacedKey(BukkitPlugin.getInstance(), "bait") }
val maxLuckKey by lazy { NamespacedKey(BukkitPlugin.getInstance(), "max_luck") }

View File

@ -30,4 +30,12 @@ fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
}
}
}
}
fun registerReload() = command("sanseReload", permission = "sansefish.reload") {
execute<CommandSender> { sender, _, _ ->
BaitManager.reload()
RodManager.reload()
sender.sendMessage("§a| §7插件已重载.")
}
}

View File

@ -35,7 +35,6 @@ object FishListener {
val rodItem = if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand
if (fishEvent.state == PlayerFishEvent.State.FISHING) {
player.sendMessage(rodItem.itemMeta!!.persistentDataContainer.keys.toString())
if (!rodItem.itemMeta!!.persistentDataContainer.has(
SanseFish.baitKey,
PersistentDataType.STRING
@ -59,7 +58,6 @@ object FishListener {
@SubscribeEvent
fun useBait(event: PlayerInteractEvent) {
println(event.action)
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

View File

@ -14,7 +14,11 @@ object RodManager {
val rods = HashMap<String, FishRod>()
init {
val folder = File(getDataFolder(),"rods").apply {
init()
}
private fun init() {
val folder = File(getDataFolder(), "rods").apply {
if (exists()) return@apply
mkdirs()
BukkitPlugin.getInstance().saveResource("rods/default.yml", false)
@ -43,8 +47,13 @@ object RodManager {
if (type == null) return null
val durability = builder.lore.findLast { it.startsWith("§e耐久: §7") }?.replace("§e耐久: §7", "")?.toInt()
?: SanseFish.conf.getInt("target-rod.max-durability")
?: type!!.maxDurability
val luck = builder.lore.findLast { it.startsWith("§d幸运值: §7") }?.replace("§d幸运值: §7", "")?.toInt() ?: 0
return FishingRodInstance(type!!, item, durability, luck)
}
fun reload() {
rods.clear()
init()
}
}

View File

@ -24,7 +24,7 @@ data class FishingRodInstance(
lore[0] = "§e耐久: §7$durability"
lore[1] = "§d幸运值: §7$luck"
}.let {
val durabilityPercentage = (durability.toDouble() / SanseFish.conf.getInt("target-rod.max-durability", 100))
val durabilityPercentage = (durability.toDouble() / type.maxDurability)
val meta = it.itemMeta
(meta as Damageable).damage = (64 * (1 - durabilityPercentage)).toInt()
it.itemMeta = meta
@ -51,7 +51,6 @@ data class FishingRodInstance(
}
val meta = item.itemMeta!!
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance()) { _ ->
println("remove bait")
meta.persistentDataContainer.remove(SanseFish.baitKey)
fishEvent.player.inventory.itemInMainHand.itemMeta = meta
}

View File

@ -1,12 +0,0 @@
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 # 霉运物品扣除幸运值