This commit is contained in:
tonyall 2022-06-23 18:06:41 +08:00
parent 61912a7dd8
commit 1ba39b72de
3 changed files with 25 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package cc.maxmc.sansefish
import cc.maxmc.sansefish.command.fishCmd
import cc.maxmc.sansefish.command.registerCommand
import cc.maxmc.sansefish.reward.RewardHandler
import taboolib.common.platform.Plugin
@ -17,6 +18,7 @@ object SanseFish : Plugin() {
info("§a| §7正在加载钓鱼插件(SanseFish)..")
info("§a| §7作者QQ: 1187586838")
registerCommand()
fishCmd()
RewardHandler
info("§a| §7插件加载完成.")
}

View File

@ -1,19 +1,27 @@
package cc.maxmc.sansefish.command
import cc.maxmc.sansefish.FishingRod
import cc.maxmc.sansefish.SanseFish
import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import taboolib.common.platform.command.command
import taboolib.library.xseries.setItemStack
import taboolib.platform.util.giveItem
fun registerCommand() = command("giveRod") {
fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
dynamic {
restrict<CommandSender> { sender, _, _ ->
sender.hasPermission("sansefish.giverod")
}
execute<CommandSender> { sender, _, argument ->
val target = Bukkit.getPlayerExact(argument) ?: return@execute sender.sendMessage("§c| 该玩家不在线")
val target = Bukkit.getPlayerExact(argument) ?: return@execute sender.sendMessage("§c| §7该玩家不在线")
target.giveItem(FishingRod().buildFishingRod())
}
}
}
fun fishCmd() = command("setBait", permission = "sansefish.setbait") {
execute<Player> { sender, _, _ ->
sender.sendMessage("§a| §7您手中物品已设置为鱼饵.")
SanseFish.conf.setItemStack("target-rod.bait", sender.inventory.itemInMainHand.clone().apply { amount = 1 })
SanseFish.conf.saveToFile()
}
}

View File

@ -1,11 +1,14 @@
package cc.maxmc.sansefish.listener
import cc.maxmc.sansefish.SanseFish
import cc.maxmc.sansefish.parseRod
import cc.maxmc.sansefish.reward.RewardHandler
import org.bukkit.Material
import org.bukkit.event.player.PlayerFishEvent
import org.bukkit.inventory.ItemStack
import taboolib.common.platform.event.SubscribeEvent
import taboolib.library.xseries.getItemStack
import taboolib.platform.util.hasItem
object FishListener {
@SubscribeEvent
@ -31,6 +34,13 @@ object FishListener {
if (fishEvent.state == PlayerFishEvent.State.CAUGHT_FISH) {
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)
}
val resultItem = if (rod.durability <= 0) {