update
This commit is contained in:
parent
c453c22579
commit
9e15bdced5
|
|
@ -1,38 +0,0 @@
|
||||||
package work.microhand.sanseyooyea.sansefish
|
|
||||||
|
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.inventory.ItemStack
|
|
||||||
import taboolib.platform.util.ItemBuilder
|
|
||||||
import taboolib.platform.util.buildItem
|
|
||||||
|
|
||||||
data class FishingRod(
|
|
||||||
var durability: Int = SanseFish.conf.getInt("target-rod.max-durability", 100),
|
|
||||||
var luck: Int = 0,
|
|
||||||
) {
|
|
||||||
fun buildFishingRod(): ItemStack = buildItem(Material.FISHING_ROD) {
|
|
||||||
lore.clear()
|
|
||||||
lore.addAll(listOf("", "", "§8神奇的鱼竿"))
|
|
||||||
lore[0] = "§e耐久: §7$durability"
|
|
||||||
lore[1] = "§d幸运值: §7$luck"
|
|
||||||
val durabilityPercentage = (durability.toDouble() / SanseFish.conf.getInt("target-rod.max-durability", 100))
|
|
||||||
damage = (64 * (1 - durabilityPercentage)).toInt()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* FishingRod
|
|
||||||
*
|
|
||||||
* §e耐久: §7<Int>
|
|
||||||
* §d幸运值: §7<Int>
|
|
||||||
* §8神奇的鱼竿
|
|
||||||
*/
|
|
||||||
fun parseRod(item: ItemStack): FishingRod? {
|
|
||||||
val builder = ItemBuilder(item)
|
|
||||||
if (!builder.lore.contains("§8神奇的鱼竿")) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
val durability = builder.lore.findLast { it.startsWith("§e耐久: §7") }?.replace("§e耐久: §7", "")?.toInt()
|
|
||||||
?: SanseFish.conf.getInt("target-rod.max-durability")
|
|
||||||
val luck = builder.lore.findLast { it.startsWith("§d幸运值: §7") }?.replace("§d幸运值: §7", "")?.toInt() ?: 0
|
|
||||||
return FishingRod(durability, luck)
|
|
||||||
}
|
|
||||||
|
|
@ -7,6 +7,7 @@ import taboolib.module.configuration.Configuration
|
||||||
import work.microhand.sanseyooyea.sansefish.command.fishCmd
|
import work.microhand.sanseyooyea.sansefish.command.fishCmd
|
||||||
import work.microhand.sanseyooyea.sansefish.command.registerCommand
|
import work.microhand.sanseyooyea.sansefish.command.registerCommand
|
||||||
import work.microhand.sanseyooyea.sansefish.reward.RewardHandler
|
import work.microhand.sanseyooyea.sansefish.reward.RewardHandler
|
||||||
|
import work.microhand.sanseyooyea.sansefish.storage.StorageCommand
|
||||||
|
|
||||||
object SanseFish : Plugin() {
|
object SanseFish : Plugin() {
|
||||||
|
|
||||||
|
|
@ -18,6 +19,7 @@ object SanseFish : Plugin() {
|
||||||
info("§a| §7正在加载钓鱼插件(SanseFish)..")
|
info("§a| §7正在加载钓鱼插件(SanseFish)..")
|
||||||
info("§a| §7作者QQ: 1187586838")
|
info("§a| §7作者QQ: 1187586838")
|
||||||
registerCommand()
|
registerCommand()
|
||||||
|
StorageCommand.registerCommand()
|
||||||
fishCmd()
|
fishCmd()
|
||||||
RewardHandler
|
RewardHandler
|
||||||
info("§a| §7插件加载完成.")
|
info("§a| §7插件加载完成.")
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,18 @@ import org.bukkit.entity.Player
|
||||||
import taboolib.common.platform.command.command
|
import taboolib.common.platform.command.command
|
||||||
import taboolib.library.xseries.setItemStack
|
import taboolib.library.xseries.setItemStack
|
||||||
import taboolib.platform.util.giveItem
|
import taboolib.platform.util.giveItem
|
||||||
import work.microhand.sanseyooyea.sansefish.FishingRod
|
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
|
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
||||||
|
|
||||||
fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
|
fun registerCommand() = command("giveRod", permission = "sansefish.giverod") {
|
||||||
dynamic {
|
dynamic {
|
||||||
execute<CommandSender> { sender, _, argument ->
|
dynamic {
|
||||||
val target = Bukkit.getPlayerExact(argument) ?: return@execute sender.sendMessage("§c| §7该玩家不在线")
|
execute<CommandSender> { sender, ctx, arg ->
|
||||||
target.giveItem(FishingRod().buildFishingRod())
|
val target =
|
||||||
|
Bukkit.getPlayerExact(ctx.argument(-1)) ?: return@execute sender.sendMessage("§c| §7该玩家不在线")
|
||||||
|
val rod = RodManager.rods[arg]?: return@execute sender.sendMessage("§c| §7该鱼竿不存在")
|
||||||
|
target.giveItem(rod.buildFishingRod())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import taboolib.common.platform.event.SubscribeEvent
|
||||||
import taboolib.library.xseries.getItemStack
|
import taboolib.library.xseries.getItemStack
|
||||||
import taboolib.platform.util.hasItem
|
import taboolib.platform.util.hasItem
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
import work.microhand.sanseyooyea.sansefish.parseRod
|
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
||||||
import work.microhand.sanseyooyea.sansefish.reward.RewardHandler
|
import work.microhand.sanseyooyea.sansefish.reward.RewardHandler
|
||||||
|
|
||||||
object FishListener {
|
object FishListener {
|
||||||
|
|
@ -15,7 +15,7 @@ object FishListener {
|
||||||
fun onFish(fishEvent: PlayerFishEvent) {
|
fun onFish(fishEvent: PlayerFishEvent) {
|
||||||
val player = fishEvent.player
|
val player = fishEvent.player
|
||||||
// Disable Vanilla Fishing Rod
|
// Disable Vanilla Fishing Rod
|
||||||
if (fishEvent.state == PlayerFishEvent.State.FISHING && parseRod(player.inventory.itemInMainHand) == null && parseRod(
|
if (fishEvent.state == PlayerFishEvent.State.FISHING && RodManager.parseRod(player.inventory.itemInMainHand) == null && RodManager.parseRod(
|
||||||
player.inventory.itemInOffHand
|
player.inventory.itemInOffHand
|
||||||
) == null
|
) == null
|
||||||
) {
|
) {
|
||||||
|
|
@ -25,13 +25,14 @@ object FishListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
var offHand = false
|
var offHand = false
|
||||||
val rod = parseRod(player.inventory.itemInMainHand) ?: parseRod(player.inventory.itemInOffHand).also {
|
val rod = RodManager.parseRod(player.inventory.itemInMainHand) ?: RodManager.parseRod(player.inventory.itemInOffHand).also {
|
||||||
offHand = true
|
offHand = true
|
||||||
} ?: throw IllegalStateException("???你咋钓鱼的")
|
} ?: throw IllegalStateException("???你咋钓鱼的")
|
||||||
|
|
||||||
if (fishEvent.state != PlayerFishEvent.State.BITE) rod.durability--
|
if (fishEvent.state != PlayerFishEvent.State.BITE) rod.durability--
|
||||||
|
|
||||||
if (fishEvent.state == PlayerFishEvent.State.CAUGHT_FISH) {
|
if (fishEvent.state == PlayerFishEvent.State.CAUGHT_FISH) {
|
||||||
|
fishEvent.expToDrop = 0
|
||||||
rod.luck++
|
rod.luck++
|
||||||
fishEvent.caught.remove()
|
fishEvent.caught.remove()
|
||||||
if (!player.inventory.hasItem(1) {
|
if (!player.inventory.hasItem(1) {
|
||||||
|
|
@ -46,8 +47,8 @@ object FishListener {
|
||||||
val resultItem = if (rod.durability <= 0) {
|
val resultItem = if (rod.durability <= 0) {
|
||||||
player.sendMessage("§c| §7您的鱼竿已损坏")
|
player.sendMessage("§c| §7您的鱼竿已损坏")
|
||||||
ItemStack(Material.AIR)
|
ItemStack(Material.AIR)
|
||||||
} else rod.buildFishingRod()
|
} else rod.updateFishingRod(if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand)
|
||||||
|
|
||||||
if (offHand) player.inventory.itemInOffHand = resultItem else player.inventory.itemInMainHand = resultItem
|
if (offHand) player.inventory.itemInOffHand = resultItem else player.inventory.itemInMainHand = resultItem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.manager
|
||||||
|
|
||||||
|
import taboolib.common.platform.function.getDataFolder
|
||||||
|
import taboolib.module.configuration.Configuration
|
||||||
|
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
object BaitManager {
|
||||||
|
val baits = HashMap<String, Bait>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
// load baits.
|
||||||
|
File(getDataFolder(), "baits").listFiles()?.forEach { file ->
|
||||||
|
val config = Configuration.loadFromFile(file)
|
||||||
|
val durability = config.getInt("max-durability")
|
||||||
|
val luck = config.getInt("luck-def")
|
||||||
|
val lore = config.getString("lore")!!
|
||||||
|
baits[file.nameWithoutExtension] = Bait(file.nameWithoutExtension,)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
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.util.ItemBuilder
|
||||||
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
|
import work.microhand.sanseyooyea.sansefish.misc.FishingRodInstance
|
||||||
|
import work.microhand.sanseyooyea.sansefish.misc.FishRod
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
object RodManager {
|
||||||
|
val rods = HashMap<String, FishRod>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
// load fish rods.
|
||||||
|
File(getDataFolder(), "rods").listFiles()?.forEach { file ->
|
||||||
|
val config = Configuration.loadFromFile(file)
|
||||||
|
val durability = config.getInt("max-durability")
|
||||||
|
val luck = config.getInt("luck-def")
|
||||||
|
val lore = config.getString("lore")!!
|
||||||
|
rods[file.nameWithoutExtension] = FishRod(file.nameWithoutExtension, lore, durability, luck)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseRod(item: ItemStack): FishingRodInstance? {
|
||||||
|
val builder = ItemBuilder(item)
|
||||||
|
var type: FishRod? = null
|
||||||
|
rods.forEach { (_, rod) ->
|
||||||
|
if (builder.lore.contains(rod.lore)) {
|
||||||
|
type = rod
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// null if not target fishing rod.
|
||||||
|
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")
|
||||||
|
val luck = builder.lore.findLast { it.startsWith("§d幸运值: §7") }?.replace("§d幸运值: §7", "")?.toInt() ?: 0
|
||||||
|
return FishingRodInstance(type!!, durability, luck)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.misc
|
||||||
|
|
||||||
|
data class Bait(val type: String, ) {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.misc
|
||||||
|
|
||||||
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import work.microhand.sanseyooyea.sansefish.misc.FishingRodInstance
|
||||||
|
|
||||||
|
data class FishRod(val type: String, val lore: String, val maxDurability: Int, val defaultLuck: Int) {
|
||||||
|
fun buildFishingRod(): ItemStack = FishingRodInstance(this).updateFishingRod(ItemStack(Material.FISHING_ROD))
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.misc
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import taboolib.platform.util.buildItem
|
||||||
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
|
|
||||||
|
data class FishingRodInstance(
|
||||||
|
val type: FishRod,
|
||||||
|
var durability: Int = type.maxDurability,
|
||||||
|
var luck: Int = type.defaultLuck,
|
||||||
|
) {
|
||||||
|
fun updateFishingRod(legacy: ItemStack): ItemStack = buildItem(legacy) {
|
||||||
|
lore.clear()
|
||||||
|
lore.addAll(listOf("", "", "§8神奇的鱼竿"))
|
||||||
|
lore[0] = "§e耐久: §7$durability"
|
||||||
|
lore[1] = "§d幸运值: §7$luck"
|
||||||
|
val durabilityPercentage = (durability.toDouble() / SanseFish.conf.getInt("target-rod.max-durability", 100))
|
||||||
|
damage = (64 * (1 - durabilityPercentage)).toInt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
package work.microhand.sanseyooyea.sansefish.reward
|
package work.microhand.sanseyooyea.sansefish.reward
|
||||||
|
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import work.microhand.sanseyooyea.sansefish.FishingRod
|
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
|
import work.microhand.sanseyooyea.sansefish.misc.FishingRodInstance
|
||||||
|
|
||||||
object RewardHandler {
|
object RewardHandler {
|
||||||
private val rewardList = ArrayList<Reward>()
|
private val rewardList = ArrayList<Reward>()
|
||||||
|
|
||||||
// load Rewards
|
// load Rewards
|
||||||
init {
|
init {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun parseReward(config: Map<String, Any>) =
|
fun parseReward(config: Map<String, Any>) =
|
||||||
Reward(
|
Reward(
|
||||||
config["commands"] as List<String>,
|
config["commands"] as List<String>,
|
||||||
|
|
@ -22,7 +23,7 @@ object RewardHandler {
|
||||||
rewardList.addAll(SanseFish.conf.getList("rewards")!!.map { parseReward(it as Map<String, Any>) })
|
rewardList.addAll(SanseFish.conf.getList("rewards")!!.map { parseReward(it as Map<String, Any>) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doReward(player: Player, rod: FishingRod) {
|
fun doReward(player: Player, rod: FishingRodInstance) {
|
||||||
rewardList.forEach {
|
rewardList.forEach {
|
||||||
// handle deLuck
|
// handle deLuck
|
||||||
if (it.deLuck >= 0) {
|
if (it.deLuck >= 0) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.storage
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import taboolib.common.platform.command.CommandBuilder
|
||||||
|
import taboolib.common.platform.command.command
|
||||||
|
import taboolib.library.xseries.getItemStack
|
||||||
|
import taboolib.library.xseries.setItemStack
|
||||||
|
import taboolib.module.configuration.Config
|
||||||
|
import taboolib.module.configuration.Configuration
|
||||||
|
import taboolib.platform.util.giveItem
|
||||||
|
|
||||||
|
object StorageCommand {
|
||||||
|
@Config("ItemStorage.yaml")
|
||||||
|
lateinit var itemStorage: Configuration
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun registerCommand() {
|
||||||
|
command("istorage", permission = "sansefish.istorage") {
|
||||||
|
commandSet()
|
||||||
|
commandRemove()
|
||||||
|
commandList()
|
||||||
|
commandGive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.CommandBase.commandSet() = literal("set") {
|
||||||
|
dynamic {
|
||||||
|
execute<Player> { sender, _, arg ->
|
||||||
|
val item = sender.inventory.itemInMainHand
|
||||||
|
itemStorage.setItemStack(arg, item)
|
||||||
|
itemStorage.saveToFile()
|
||||||
|
sender.sendMessage("§a| §7已将该物品设置为 §a${arg}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.CommandBase.commandRemove() = literal("remove") {
|
||||||
|
dynamic {
|
||||||
|
execute<Player> { sender, _, arg ->
|
||||||
|
itemStorage[arg] = null
|
||||||
|
itemStorage.saveToFile()
|
||||||
|
sender.sendMessage("§a| §7已移除物品 §a${arg}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.CommandBase.commandList() = literal("list") {
|
||||||
|
execute<Player> { sender, _, _ ->
|
||||||
|
val items = itemStorage.getKeys(false).joinToString(", ")
|
||||||
|
sender.sendMessage("§e| §7目前存储的物品有: §e${items}")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//istorage give xxx Item
|
||||||
|
private fun CommandBuilder.CommandBase.commandGive() = literal("give") {
|
||||||
|
dynamic {
|
||||||
|
restrict<Player> { _, _, arg -> Bukkit.getPlayerExact(arg) != null }
|
||||||
|
dynamic {
|
||||||
|
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该物品不存在.")
|
||||||
|
target.giveItem(item)
|
||||||
|
sender.sendMessage("§a| §7已将物品 §a${arg} §7给予 §a${target.name}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
lore: "&7指定钓竿"
|
||||||
|
max-durability: 100
|
||||||
|
luck-def: 0
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
target-rod:
|
|
||||||
lore: "&7指定钓竿"
|
|
||||||
max-durability: 100
|
|
||||||
|
|
||||||
rewards:
|
rewards:
|
||||||
- commands:
|
- items:
|
||||||
|
- "物品1"
|
||||||
|
- "物品2"
|
||||||
|
commands:
|
||||||
- "mm i give xxx" #钓到鱼时执行命令, %player% 为玩家
|
- "mm i give xxx" #钓到鱼时执行命令, %player% 为玩家
|
||||||
- "broadcast 玩家 %player% 钓到了好东西!"
|
- "broadcast 玩家 %player% 钓到了好东西!"
|
||||||
chance: 0.2 #以小数形式存储
|
chance: 0.2 #以小数形式存储
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue