bug fix S2
This commit is contained in:
parent
678eb96762
commit
76f63fcd60
|
|
@ -8,6 +8,8 @@ import taboolib.module.configuration.Configuration
|
|||
import taboolib.platform.BukkitPlugin
|
||||
import work.microhand.sanseyooyea.sansefish.command.registerCommand
|
||||
import work.microhand.sanseyooyea.sansefish.command.StorageCommand
|
||||
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
||||
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
||||
|
||||
object SanseFish : Plugin() {
|
||||
|
||||
|
|
@ -23,7 +25,8 @@ object SanseFish : Plugin() {
|
|||
info("§a| §7作者QQ: 1187586838")
|
||||
registerCommand()
|
||||
StorageCommand.registerCommand()
|
||||
|
||||
BaitManager
|
||||
RodManager
|
||||
info("§a| §7插件加载完成.")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,19 @@ import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
|||
|
||||
fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
|
||||
dynamic {
|
||||
suggestion<Player> { _, _ ->
|
||||
Bukkit.getOnlinePlayers().map { it.name }
|
||||
}
|
||||
restrict<Player> { _, _, arg ->
|
||||
Bukkit.getPlayerExact(arg) != null
|
||||
}
|
||||
dynamic {
|
||||
suggestion<Player> { _, _ ->
|
||||
RodManager.rods.keys.toList()
|
||||
}
|
||||
execute<CommandSender> { sender, ctx, arg ->
|
||||
val target =
|
||||
Bukkit.getPlayerExact(ctx.argument(-1)) ?: return@execute sender.sendMessage("§c| §7该玩家不在线")
|
||||
Bukkit.getPlayerExact(ctx.argument(-1))!!
|
||||
val rod = RodManager.rods[arg]?: return@execute sender.sendMessage("§c| §7该鱼竿不存在")
|
||||
target.giveItem(rod.buildFishingRod())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ object StorageCommand {
|
|||
|
||||
private fun CommandBuilder.CommandBase.commandRemove() = literal("remove") {
|
||||
dynamic {
|
||||
suggestion<Player> { _, _ ->
|
||||
itemStorage.getKeys(false).toList()
|
||||
}
|
||||
execute<Player> { sender, _, arg ->
|
||||
itemStorage[arg] = null
|
||||
itemStorage.saveToFile()
|
||||
|
|
@ -56,12 +59,16 @@ object StorageCommand {
|
|||
//istorage give xxx Item
|
||||
private fun CommandBuilder.CommandBase.commandGive() = literal("give") {
|
||||
dynamic {
|
||||
suggestion<Player> { _, _ ->
|
||||
Bukkit.getOnlinePlayers().map { it.name }
|
||||
}
|
||||
restrict<Player> { _, _, arg -> Bukkit.getPlayerExact(arg) != null }
|
||||
dynamic {
|
||||
suggestion<Player> { _, _ -> itemStorage.getKeys(false).toList() }
|
||||
restrict<Player> { _, _, arg -> itemStorage.contains(arg) }
|
||||
execute<Player> { sender, ctx, arg ->
|
||||
val target = Bukkit.getPlayerExact(ctx.argument(-1))
|
||||
val item = itemStorage.getItemStack(arg)?: return@execute sender.sendMessage("§c| §7该物品不存在.")
|
||||
val item = itemStorage.getItemStack(arg) ?: return@execute sender.sendMessage("§c| §7该物品不存在.")
|
||||
target!!.giveItem(item)
|
||||
sender.sendMessage("§a| §7已将物品 §a${arg} §7给予 §a${target.name}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package work.microhand.sanseyooyea.sansefish.manager
|
|||
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import taboolib.common.platform.function.getDataFolder
|
||||
import taboolib.common.platform.function.warning
|
||||
import taboolib.library.xseries.getItemStack
|
||||
import taboolib.module.configuration.Configuration
|
||||
import taboolib.platform.BukkitPlugin
|
||||
import work.microhand.sanseyooyea.sansefish.command.StorageCommand
|
||||
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
||||
import work.microhand.sanseyooyea.sansefish.misc.BaitReward
|
||||
|
|
@ -26,10 +28,15 @@ object BaitManager {
|
|||
}
|
||||
|
||||
private fun init() {
|
||||
val folder = File(getDataFolder(),"baits").apply {
|
||||
if (exists()) return@apply
|
||||
mkdirs()
|
||||
BukkitPlugin.getInstance().saveResource("baits${File.separator}default.yml", false)
|
||||
}
|
||||
// load baits.
|
||||
File(getDataFolder(), "baits").listFiles()?.forEach { file ->
|
||||
folder.listFiles()?.forEach { file ->
|
||||
val config = Configuration.loadFromFile(file)
|
||||
val key = config.getString("item")?: throw IllegalArgumentException("鱼饵 ${file.nameWithoutExtension} 未配置物品.")
|
||||
val key = config.getString("item")?: return@forEach warning("鱼饵 ${file.nameWithoutExtension} 未配置物品.")
|
||||
val item = StorageCommand.itemStorage.getItemStack(key)?: throw IllegalArgumentException("物品 $key 不存在.")
|
||||
val rewards = BaitReward(config)
|
||||
baits[file.nameWithoutExtension] = Bait(file.nameWithoutExtension, item, rewards, config)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package work.microhand.sanseyooyea.sansefish.manager
|
|||
import org.bukkit.inventory.ItemStack
|
||||
import taboolib.common.platform.function.getDataFolder
|
||||
import taboolib.module.configuration.Configuration
|
||||
import taboolib.platform.BukkitPlugin
|
||||
import taboolib.platform.util.ItemBuilder
|
||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||
import work.microhand.sanseyooyea.sansefish.misc.FishingRodInstance
|
||||
|
|
@ -13,8 +14,14 @@ object RodManager {
|
|||
val rods = HashMap<String, FishRod>()
|
||||
|
||||
init {
|
||||
val folder = File(getDataFolder(),"rods").apply {
|
||||
if (exists()) return@apply
|
||||
mkdirs()
|
||||
BukkitPlugin.getInstance().saveResource("rods/default.yml", false)
|
||||
}
|
||||
|
||||
// load fish rods.
|
||||
File(getDataFolder(), "rods").listFiles()?.forEach { file ->
|
||||
folder.listFiles()?.forEach { file ->
|
||||
val config = Configuration.loadFromFile(file)
|
||||
val durability = config.getInt("max-durability")
|
||||
val luck = config.getInt("luck-def")
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit
|
|||
import org.bukkit.Material
|
||||
import org.bukkit.event.player.PlayerFishEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.Damageable
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
import taboolib.platform.BukkitPlugin
|
||||
import taboolib.platform.util.ItemBuilder
|
||||
|
|
@ -22,17 +23,26 @@ data class FishingRodInstance(
|
|||
lore.addAll(listOf("", "", type.lore))
|
||||
lore[0] = "§e耐久: §7$durability"
|
||||
lore[1] = "§d幸运值: §7$luck"
|
||||
}.let {
|
||||
val durabilityPercentage = (durability.toDouble() / SanseFish.conf.getInt("target-rod.max-durability", 100))
|
||||
damage = (64 * (1 - durabilityPercentage)).toInt()
|
||||
println("Damage Before: $damage")
|
||||
}.also { println("Damage After: ${ItemBuilder(it).damage}") }
|
||||
val meta = it.itemMeta
|
||||
(meta as Damageable).damage = (64 * (1 - durabilityPercentage)).toInt()
|
||||
it.itemMeta = meta
|
||||
it
|
||||
}
|
||||
|
||||
fun handleFished(fishEvent: PlayerFishEvent) {
|
||||
fishEvent.expToDrop = 0
|
||||
fishEvent.caught!!.remove()
|
||||
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++
|
||||
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) {
|
||||
val meta = item.itemMeta!!
|
||||
meta.persistentDataContainer[SanseFish.maxLuckKey, PersistentDataType.INTEGER] = luck
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class BaitUI(private val player: Player) {
|
|||
player.inventory.itemInMainHand.itemMeta = meta
|
||||
player.sendMessage(player.inventory.itemInMainHand.itemMeta!!.persistentDataContainer.keys.toString())
|
||||
player.sendMessage("§a| §7成功安装鱼饵")
|
||||
player.closeInventory()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
bait1:
|
||||
material: CLAY_BALL
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
item: null
|
||||
# 使用存放在ItemStorage 内的物品表示
|
||||
item: bait1
|
||||
|
||||
rewards:
|
||||
- items:
|
||||
Loading…
Reference in New Issue