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