support for legacy Minecraft
This commit is contained in:
parent
2fbb38e481
commit
f6a2b94943
|
|
@ -1,22 +1,21 @@
|
||||||
plugins {
|
plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("io.izzel.taboolib") version "1.40"
|
id("io.izzel.taboolib") version "1.42"
|
||||||
id("org.jetbrains.kotlin.jvm") version "1.6.0"
|
id("org.jetbrains.kotlin.jvm") version "1.7.10"
|
||||||
}
|
}
|
||||||
|
|
||||||
taboolib {
|
taboolib {
|
||||||
install("common")
|
install("common")
|
||||||
install("common-5")
|
install("common-5")
|
||||||
install("module-database")
|
|
||||||
install("module-chat")
|
install("module-chat")
|
||||||
install("module-ui")
|
install("module-ui")
|
||||||
install("module-ui-receptacle")
|
install("module-ui-receptacle")
|
||||||
install("module-configuration")
|
install("module-configuration")
|
||||||
install("expansion-player-database")
|
install("module-nms")
|
||||||
install("platform-bukkit")
|
install("platform-bukkit")
|
||||||
classifier = null
|
classifier = null
|
||||||
version = "6.0.9-5"
|
version = "6.0.9-111"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|
@ -25,8 +24,9 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("ink.ptms:nms-all:1.0.0")
|
compileOnly("ink.ptms:nms-all:1.0.0")
|
||||||
compileOnly("ink.ptms.core:v11802:11802-minimize:mapped")
|
implementation("ink.ptms.core:v11200:11200")
|
||||||
compileOnly("ink.ptms.core:v11802:11802-minimize:universal")
|
// compileOnly("ink.ptms.core:v11802:11802-minimize:mapped")
|
||||||
|
// compileOnly("ink.ptms.core:v11802:11802-minimize:universal")
|
||||||
compileOnly(kotlin("stdlib"))
|
compileOnly(kotlin("stdlib"))
|
||||||
compileOnly(fileTree("libs"))
|
compileOnly(fileTree("libs"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ import org.bukkit.event.block.Action
|
||||||
import org.bukkit.event.player.PlayerFishEvent
|
import org.bukkit.event.player.PlayerFishEvent
|
||||||
import org.bukkit.event.player.PlayerInteractEvent
|
import org.bukkit.event.player.PlayerInteractEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.persistence.PersistentDataType
|
|
||||||
import taboolib.common.platform.event.SubscribeEvent
|
import taboolib.common.platform.event.SubscribeEvent
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
import work.microhand.sanseyooyea.sansefish.manager.RodManager
|
||||||
|
import work.microhand.sanseyooyea.sansefish.nms.hasNBTTag
|
||||||
import work.microhand.sanseyooyea.sansefish.ui.BaitUI
|
import work.microhand.sanseyooyea.sansefish.ui.BaitUI
|
||||||
|
|
||||||
object FishListener {
|
object FishListener {
|
||||||
|
|
@ -34,11 +34,12 @@ object FishListener {
|
||||||
val rodItem = if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand
|
val rodItem = if (offHand) player.inventory.itemInOffHand else player.inventory.itemInMainHand
|
||||||
|
|
||||||
if (fishEvent.state == PlayerFishEvent.State.FISHING) {
|
if (fishEvent.state == PlayerFishEvent.State.FISHING) {
|
||||||
if (!rodItem.itemMeta!!.persistentDataContainer.has(
|
|
||||||
SanseFish.baitKey,
|
if (!rodItem.hasNBTTag(
|
||||||
PersistentDataType.STRING
|
SanseFish.baitKey.toString()
|
||||||
)
|
)
|
||||||
) return player.sendMessage("§e| §7该鱼竿未安装鱼饵. 请手持鱼竿左键安装.").also { fishEvent.isCancelled = true }
|
) return player.sendMessage("§e| §7该鱼竿未安装鱼饵. 请手持鱼竿左键安装.")
|
||||||
|
.also { fishEvent.isCancelled = true }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fishEvent.state == PlayerFishEvent.State.CAUGHT_FISH) {
|
if (fishEvent.state == PlayerFishEvent.State.CAUGHT_FISH) {
|
||||||
|
|
@ -51,7 +52,7 @@ object FishListener {
|
||||||
ItemStack(Material.AIR)
|
ItemStack(Material.AIR)
|
||||||
} else rod.updateFishingRod()
|
} else rod.updateFishingRod()
|
||||||
|
|
||||||
if (offHand) player.inventory.setItemInOffHand(resultItem) else player.inventory.setItemInMainHand(resultItem)
|
if (offHand) player.inventory.itemInOffHand = resultItem else player.inventory.itemInMainHand = resultItem
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|
@ -59,7 +60,7 @@ object FishListener {
|
||||||
if (event.action != Action.LEFT_CLICK_AIR && event.action != Action.LEFT_CLICK_BLOCK) return
|
if (event.action != Action.LEFT_CLICK_AIR && event.action != Action.LEFT_CLICK_BLOCK) return
|
||||||
if (!event.hasItem()) return
|
if (!event.hasItem()) return
|
||||||
if (event.item!!.type != Material.FISHING_ROD) return
|
if (event.item!!.type != Material.FISHING_ROD) return
|
||||||
if (event.item!!.itemMeta!!.persistentDataContainer.has(SanseFish.baitKey, PersistentDataType.STRING)) return
|
if (event.item!!.hasNBTTag(SanseFish.baitKey.toString())) return
|
||||||
RodManager.parseRod(event.item!!) ?: return
|
RodManager.parseRod(event.item!!) ?: return
|
||||||
BaitUI(event.player).open()
|
BaitUI(event.player).open()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
package work.microhand.sanseyooyea.sansefish.misc
|
package work.microhand.sanseyooyea.sansefish.misc
|
||||||
|
|
||||||
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 taboolib.platform.BukkitPlugin
|
|
||||||
import taboolib.platform.util.buildItem
|
import taboolib.platform.util.buildItem
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
||||||
|
import work.microhand.sanseyooyea.sansefish.nms.getNBTInt
|
||||||
|
import work.microhand.sanseyooyea.sansefish.nms.getNBTString
|
||||||
|
import work.microhand.sanseyooyea.sansefish.nms.removeNBTTag
|
||||||
|
import work.microhand.sanseyooyea.sansefish.nms.setNBTInt
|
||||||
|
|
||||||
data class FishingRodInstance(
|
data class FishingRodInstance(
|
||||||
val type: FishRod,
|
val type: FishRod,
|
||||||
|
|
@ -25,7 +25,7 @@ data class FishingRodInstance(
|
||||||
}.let {
|
}.let {
|
||||||
val durabilityPercentage = (durability.toDouble() / type.maxDurability)
|
val durabilityPercentage = (durability.toDouble() / type.maxDurability)
|
||||||
val meta = it.itemMeta
|
val meta = it.itemMeta
|
||||||
(meta as Damageable).damage = (64 * (1 - durabilityPercentage)).toInt()
|
it.durability = (64 * (1 - durabilityPercentage)).toInt().toShort()
|
||||||
it.itemMeta = meta
|
it.itemMeta = meta
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
|
|
@ -34,25 +34,15 @@ data class FishingRodInstance(
|
||||||
fishEvent.expToDrop = 0
|
fishEvent.expToDrop = 0
|
||||||
fishEvent.caught!!.remove()
|
fishEvent.caught!!.remove()
|
||||||
val bait =
|
val bait =
|
||||||
BaitManager.baits[item.itemMeta!!.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING]
|
BaitManager.baits[item.getNBTString(SanseFish.baitKey.toString()) ?: return]!!
|
||||||
?: return]!!
|
|
||||||
luck++
|
luck++
|
||||||
val maxLuck = item.itemMeta!!.persistentDataContainer.getOrDefault(
|
val maxLuck = item.getNBTInt(SanseFish.maxLuckKey.toString()) ?: type.defaultLuck
|
||||||
SanseFish.maxLuckKey,
|
|
||||||
PersistentDataType.INTEGER,
|
|
||||||
type.defaultLuck
|
|
||||||
)
|
|
||||||
if (luck > maxLuck) {
|
if (luck > maxLuck) {
|
||||||
val meta = item.itemMeta!!
|
item.setNBTInt(SanseFish.maxLuckKey.toString(), luck)
|
||||||
meta.persistentDataContainer[SanseFish.maxLuckKey, PersistentDataType.INTEGER] = luck
|
|
||||||
item.itemMeta = meta
|
|
||||||
bait.rewards.doGuarantee(fishEvent.player, luck, maxLuck)
|
bait.rewards.doGuarantee(fishEvent.player, luck, maxLuck)
|
||||||
}
|
}
|
||||||
val meta = item.itemMeta!!
|
item.removeNBTTag(SanseFish.baitKey.toString())
|
||||||
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance()) { _ ->
|
|
||||||
meta.persistentDataContainer.remove(SanseFish.baitKey)
|
|
||||||
fishEvent.player.inventory.itemInMainHand.itemMeta = meta
|
|
||||||
}
|
|
||||||
bait.rewards.doReward(fishEvent.player, this)
|
bait.rewards.doReward(fishEvent.player, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.nms
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
||||||
|
fun ItemStack.setNBTString(key: String, value: String) {
|
||||||
|
NMSBase.impl.setTagString(this, key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ItemStack.setNBTInt(key: String, value: Int) {
|
||||||
|
NMSBase.impl.setTagInt(this, key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ItemStack.getNBTString(key: String): String? = NMSBase.impl.getTagString(this, key)
|
||||||
|
|
||||||
|
fun ItemStack.getNBTInt(key: String): Int? = NMSBase.impl.getTagInt(this, key)
|
||||||
|
|
||||||
|
fun ItemStack.hasNBTTag(key: String): Boolean = NMSBase.impl.hasTag(this, key)
|
||||||
|
|
||||||
|
fun ItemStack.removeNBTTag(key: String) = NMSBase.impl.removeTag(this, key)
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.nms
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import taboolib.module.nms.nmsProxy
|
||||||
|
|
||||||
|
abstract class NMSBase {
|
||||||
|
abstract fun hasTag(item: ItemStack, key: String): Boolean
|
||||||
|
|
||||||
|
abstract fun removeTag(item: ItemStack, key: String)
|
||||||
|
|
||||||
|
abstract fun setTagString(item: ItemStack, key: String, value: String)
|
||||||
|
|
||||||
|
abstract fun getTagString(item: ItemStack, key: String): String?
|
||||||
|
|
||||||
|
abstract fun setTagInt(item: ItemStack, key: String, value: Int)
|
||||||
|
|
||||||
|
abstract fun getTagInt(item: ItemStack, key: String): Int?
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val impl = nmsProxy<NMSBase>()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
package work.microhand.sanseyooyea.sansefish.nms
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_12_R1.NBTTagCompound
|
||||||
|
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
import taboolib.library.reflex.Reflex.Companion.getProperty
|
||||||
|
|
||||||
|
class NMSBaseImpl : NMSBase() {
|
||||||
|
override fun setTagString(item: ItemStack, key: String, value: String) {
|
||||||
|
val tag = item.toNBT()
|
||||||
|
tag.setString(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hasTag(item: ItemStack, key: String): Boolean {
|
||||||
|
val tag = item.toNBT()
|
||||||
|
return tag.hasKey(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun removeTag(item: ItemStack, key: String) {
|
||||||
|
val tag = item.toNBT()
|
||||||
|
println("removing")
|
||||||
|
tag.remove(key)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getTagString(item: ItemStack, key: String): String? {
|
||||||
|
val tag = item.toNBT()
|
||||||
|
return tag.getString(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setTagInt(item: ItemStack, key: String, value: Int) {
|
||||||
|
val tag = item.toNBT()
|
||||||
|
tag.setInt(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getTagInt(item: ItemStack, key: String): Int? {
|
||||||
|
val tag = item.toNBT()
|
||||||
|
return if (hasTag(item, key)) {
|
||||||
|
tag.getInt(key)
|
||||||
|
} else null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ItemStack.toNBT(): NBTTagCompound {
|
||||||
|
val handle = (this as CraftItemStack).getProperty<net.minecraft.server.v1_12_R1.ItemStack>("handle")!!
|
||||||
|
return handle.c("sansefish")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
package work.microhand.sanseyooyea.sansefish.ui
|
package work.microhand.sanseyooyea.sansefish.ui
|
||||||
|
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.persistence.PersistentDataType
|
|
||||||
import taboolib.module.ui.buildMenu
|
import taboolib.module.ui.buildMenu
|
||||||
import taboolib.module.ui.type.Linked
|
import taboolib.module.ui.type.Linked
|
||||||
import work.microhand.sanseyooyea.sansefish.SanseFish
|
import work.microhand.sanseyooyea.sansefish.SanseFish
|
||||||
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
import work.microhand.sanseyooyea.sansefish.manager.BaitManager
|
||||||
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
import work.microhand.sanseyooyea.sansefish.misc.Bait
|
||||||
|
import work.microhand.sanseyooyea.sansefish.nms.setNBTString
|
||||||
|
|
||||||
class BaitUI(private val player: Player) {
|
class BaitUI(private val player: Player) {
|
||||||
private val baits = HashMap<Bait, Int>()
|
private val baits = HashMap<Bait, Int>()
|
||||||
|
|
@ -28,9 +28,8 @@ class BaitUI(private val player: Player) {
|
||||||
set(index, item) {
|
set(index, item) {
|
||||||
isCancelled = true
|
isCancelled = true
|
||||||
player.inventory.removeItem(bait.item)
|
player.inventory.removeItem(bait.item)
|
||||||
val meta = player.inventory.itemInMainHand.itemMeta!!
|
val item = player.inventory.itemInMainHand
|
||||||
meta.persistentDataContainer[SanseFish.baitKey, PersistentDataType.STRING] = bait.type
|
item.setNBTString(SanseFish.baitKey.toString(), bait.type)
|
||||||
player.inventory.itemInMainHand.itemMeta = meta
|
|
||||||
player.sendMessage("§a| §7成功安装鱼饵")
|
player.sendMessage("§a| §7成功安装鱼饵")
|
||||||
player.closeInventory()
|
player.closeInventory()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue