From b3f020598f46d5fe8f32285801539273fbcc6ac7 Mon Sep 17 00:00:00 2001 From: tony_all Date: Mon, 4 Jul 2022 15:49:34 +0800 Subject: [PATCH] remove debug msg add reloadCommand remove useless codes --- .../microhand/sanseyooyea/sansefish/SanseFish.kt | 5 ----- .../sanseyooyea/sansefish/command/GetCommand.kt | 8 ++++++++ .../sanseyooyea/sansefish/listener/FishListener.kt | 2 -- .../sanseyooyea/sansefish/manager/RodManager.kt | 13 +++++++++++-- .../sansefish/misc/FishingRodInstance.kt | 3 +-- src/main/resources/settings.yml | 12 ------------ 6 files changed, 20 insertions(+), 23 deletions(-) delete mode 100644 src/main/resources/settings.yml diff --git a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/SanseFish.kt b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/SanseFish.kt index 2d89efb..6e9aa7b 100644 --- a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/SanseFish.kt +++ b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/SanseFish.kt @@ -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") } diff --git a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/command/GetCommand.kt b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/command/GetCommand.kt index 888f20e..19a1f65 100644 --- a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/command/GetCommand.kt +++ b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/command/GetCommand.kt @@ -30,4 +30,12 @@ fun registerCommand() = command("giveRod", permission = "sansefish.giverod") { } } } +} + +fun registerReload() = command("sanseReload", permission = "sansefish.reload") { + execute { sender, _, _ -> + BaitManager.reload() + RodManager.reload() + sender.sendMessage("§a| §7插件已重载.") + } } \ No newline at end of file diff --git a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/listener/FishListener.kt b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/listener/FishListener.kt index cce3781..9f2fe87 100644 --- a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/listener/FishListener.kt +++ b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/listener/FishListener.kt @@ -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 diff --git a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/manager/RodManager.kt b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/manager/RodManager.kt index fb76010..62161ae 100644 --- a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/manager/RodManager.kt +++ b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/manager/RodManager.kt @@ -14,7 +14,11 @@ object RodManager { val rods = HashMap() 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() + } } \ No newline at end of file diff --git a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/misc/FishingRodInstance.kt b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/misc/FishingRodInstance.kt index d38d05f..6c1cd56 100644 --- a/src/main/kotlin/work/microhand/sanseyooyea/sansefish/misc/FishingRodInstance.kt +++ b/src/main/kotlin/work/microhand/sanseyooyea/sansefish/misc/FishingRodInstance.kt @@ -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 } diff --git a/src/main/resources/settings.yml b/src/main/resources/settings.yml deleted file mode 100644 index 9c8b447..0000000 --- a/src/main/resources/settings.yml +++ /dev/null @@ -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 # 霉运物品扣除幸运值 \ No newline at end of file