From 04b13b7fccc4c18e9f7b80ca58b41ee8e255068c Mon Sep 17 00:00:00 2001 From: Laotouy <18922569@qq.com> Date: Thu, 18 Sep 2025 01:08:25 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=20vv=20=EF=BC=8C=20vv?= =?UTF-8?q?=E5=80=92=E9=97=AD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bryanser/brapi/vview/VViewContext.kt | 17 - .../bryanser/brapi/vview/VViewHandler.kt | 57 -- .../bryanser/brapi/vview/dsl/Building.kt | 13 - .../bryanser/brapi/vview/dsl/ClickType.kt | 11 - .../bryanser/brapi/vview/dsl/Colorful.kt | 19 - .../vview/dsl/DynamicComponentBuilder.kt | 304 ------- .../bryanser/brapi/vview/dsl/HoverText.kt | 39 - .../bryanser/brapi/vview/dsl/VComponent.kt | 38 - .../brapi/vview/dsl/VComponentBuilder.kt | 750 ------------------ .../github/bryanser/brapi/vview/dsl/VView.kt | 89 --- .../bryanser/brapi/vview/dsl/VViewMaker.kt | 6 - 11 files changed, 1343 deletions(-) delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/VViewContext.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/VViewHandler.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/Building.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/ClickType.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/Colorful.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/DynamicComponentBuilder.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/HoverText.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/VComponent.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/VComponentBuilder.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/VView.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/vview/dsl/VViewMaker.kt diff --git a/src/main/java/com/github/bryanser/brapi/vview/VViewContext.kt b/src/main/java/com/github/bryanser/brapi/vview/VViewContext.kt deleted file mode 100644 index ada1af0..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/VViewContext.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.bryanser.brapi.vview - -import com.github.bryanser.brapi.vview.dsl.VView -import lk.vexview.api.VexViewAPI -import lk.vexview.gui.OpenedVexGui -import org.bukkit.entity.Player - -abstract class VViewContext( - val player: Player -) { - - lateinit var view: VView - - fun getOpenedVexGui(): OpenedVexGui { - return VexViewAPI.getPlayerCurrentGui(player) ?: throw IllegalStateException("玩家${player.name}未打开VexView") - } -} diff --git a/src/main/java/com/github/bryanser/brapi/vview/VViewHandler.kt b/src/main/java/com/github/bryanser/brapi/vview/VViewHandler.kt deleted file mode 100644 index 00c2fe9..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/VViewHandler.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.github.bryanser.brapi.vview - -import com.github.bryanser.brapi.ItemBuilder -import com.github.bryanser.brapi.Main -import com.github.bryanser.brapi.vview.dsl.VComponentBuilder -import com.github.bryanser.brapi.vview.dsl.VView -import lk.vexview.event.gui.VexGuiCloseEvent -import org.bukkit.Bukkit -import org.bukkit.Material -import org.bukkit.entity.Player -import org.bukkit.event.EventHandler -import org.bukkit.event.Listener -import org.bukkit.event.player.PlayerQuitEvent -import java.util.* - - -object VViewHandler : Listener { - var enable: Boolean = false - - val opening = hashMapOf() - - fun init() { - if (Bukkit.getPluginManager().getPlugin("VexView") == null) { - return - } - Bukkit.getPluginManager().registerEvents(this, Main.getPlugin()) - } - - fun getContext(p: Player): VViewContext? = opening[p.uniqueId] - - fun createView( - img: String, - x: Int, - y: Int, - w: Int, - h: Int, - contextFactory: (Player) -> VC, - init: VView.() -> Unit - ): VView { - val view = VView(img, x, y, w, h, contextFactory) - view.init() - return view - } - - - @EventHandler - fun onClose(evt: VexGuiCloseEvent) { - val vc = opening.remove(evt.player.uniqueId) ?: return - vc.view.onClose(vc) - } - - @EventHandler - fun onQuit(evt: PlayerQuitEvent) { - val vc = opening.remove(evt.player.uniqueId) ?: return - vc.view.onClose(vc) - } -} \ No newline at end of file diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/Building.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/Building.kt deleted file mode 100644 index 9a94a2a..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/Building.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -import com.github.bryanser.brapi.vview.VViewContext - -interface Building> { - var build: VCOM.(VC) -> Unit - - @JvmDefault - @VViewMaker - fun onBuild(func: VCOM.(VC) -> Unit) { - build = func - } -} \ No newline at end of file diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/ClickType.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/ClickType.kt deleted file mode 100644 index 7ab5d82..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/ClickType.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -import lk.vexview.event.VexSlotClickEvent - -enum class ClickType( - val type: VexSlotClickEvent.ClickType -){ - LEFT(VexSlotClickEvent.ClickType.values()[1]), - RIGHT(VexSlotClickEvent.ClickType.values()[0]), - MIDDLE(VexSlotClickEvent.ClickType.values()[2]) -} \ No newline at end of file diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/Colorful.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/Colorful.kt deleted file mode 100644 index ce52d32..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/Colorful.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -import java.awt.Color - -interface Colorful { - var mainColor: Int - var sideColor: Int - @VViewMaker - @JvmDefault - fun mainColor(color: Color) { - mainColor = color.rgb - } - - @VViewMaker - @JvmDefault - fun sideColor(color: Color) { - sideColor = color.rgb - } -} \ No newline at end of file diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/DynamicComponentBuilder.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/DynamicComponentBuilder.kt deleted file mode 100644 index 1c71cab..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/DynamicComponentBuilder.kt +++ /dev/null @@ -1,304 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -import com.github.bryanser.brapi.vview.VViewContext -import lk.vexview.gui.components.* -import lk.vexview.gui.components.expand.VexGifImage -import lk.vexview.gui.components.expand.VexMcImage -import lk.vexview.gui.components.expand.VexSplitImage -import java.util.* -import kotlin.collections.ArrayList - -open class DynamicComponentBuilder( - val father: VComponentBuilder? = null, - protected val components: MutableList> = mutableListOf() -) { - - - @VViewMaker - abstract inner class Button( - val id: UUID, - var x: Int = 0, - var y: Int = 0, - var w: Int = 0, - var h: Int = 0, - var name: String, - var img: String, - var clickImg: String = img, - protected var click: (VC.() -> Unit)? = null, - override var hover: MutableList = mutableListOf() - ) : VComponent(), HoverText { - - @VViewMaker - fun onClick(func: VC.() -> Unit) { - click = func - } - } - - inner class BuildingButton(id: UUID, x: Int, y: Int, w: Int, h: Int, name: String, img: String, clickImg: String) - : Button(id, x, y, w, h, name, img, clickImg), Building> { - override var build: Button.(VC) -> Unit = {} - - override fun createComponents(context: VC): VexButton { - return VexButton(id, name, img, clickImg, x, y, w, h, { - if (click != null && it.uniqueId == context.player.uniqueId) { - click!!(context) - } - }, if (hover.isEmpty()) { - null - } else { - VexHoverText(hover) - }) - } - - override fun copy(): BuildingButton { - return BuildingButton(id, x, y, w, h, name, img, clickImg).also { - it.click = click - it.hover = ArrayList(hover) - it.build = build - } - } - - } - - @VViewMaker - fun button( - name: String, - img: String, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - clickImg: String = img, - init: BuildingButton.() -> Unit - ): UUID { - val uid = UUID.randomUUID() - val btn = BuildingButton(uid, x, y, w, h, name, img, clickImg) - btn.init() - components += btn - return uid - } - - - abstract inner class Image( - var img: String, - var x: Int, - var y: Int, - var xs: Int, - var ys: Int, - override var hover: MutableList = mutableListOf() - ) : VComponent(), HoverText - - inner class BuildingImage(img: String, x: Int, y: Int, xs: Int, ys: Int) - : Image(img, x, y, xs, ys), Building> { - override var build: Image.(VC) -> Unit = {} - - override fun createComponents(context: VC): VexImage { - if (hover.isNotEmpty()) { - return VexImage(img, x, y, xs, ys, VexHoverText(hover)) - } else { - return VexImage(img, x, y, xs, ys) - } - } - - override fun copy(): BuildingImage { - return BuildingImage(img, x, y, xs, ys).also { - it.hover = ArrayList(hover) - it.build = build - } - } - } - - @VViewMaker - fun image( - img: String, - x: Int = 0, - y: Int = 0, - xs: Int = 0, - ys: Int = 0, - init: BuildingImage.() -> Unit - ) { - val img = BuildingImage(img, x, y, xs, ys) - img.init() - components += img - } - - inner class GifImage( - img: String, - x: Int, - y: Int, - xs: Int, - ys: Int, - var interval: Int = 1, - override var build: GifImage.(VC) -> Unit = {} - ) : Image(img, x, y, xs, ys), Building { - override fun createComponents(context: VC): VexGifImage { - return VexGifImage(img, x, y, xs, ys, interval).also { - if (hover.isNotEmpty()) { - it.setHover(VexHoverText(hover)) - } - } - } - - override fun copy(): GifImage { - return GifImage(img, x, y, xs, ys, interval, build).also { - it.hover = ArrayList(hover) - } - } - } - - @VViewMaker - fun gifImage( - img: String, - x: Int = 0, - y: Int = 0, - xs: Int = 0, - ys: Int = 0, - init: GifImage.() -> Unit - ) { - val img = GifImage(img, x, y, xs, ys) - img.init() - components += img - } - - abstract inner class SplitImage( - img: String, - x: Int, - y: Int, - xs: Int, - ys: Int, - var u: Int = 0, - var v: Int = 0, - var uWidth: Int = 100, - var vHeight: Int = 100, - var realWidth: Int = 100, - var realHeight: Int = 100 - ) : Image(img, x, y, xs, ys) - - - inner class BuildingSplitImage(img: String, x: Int, y: Int, xs: Int, ys: Int) - : SplitImage(img, x, y, xs, ys), Building> { - override var build: SplitImage.(VC) -> Unit = {} - override fun createComponents(context: VC): VexSplitImage { - return VexSplitImage(img, x, y, u, v, xs, ys, uWidth, vHeight, realWidth, realHeight).also { - if (hover.isNotEmpty()) { - it.setHover(VexHoverText(hover)) - } - } - } - - override fun copy(): BuildingSplitImage { - return BuildingSplitImage(img, x, y, xs, ys).also { - it.u = u - it.v = v - it.uWidth = uWidth - it.vHeight = vHeight - it.realHeight = realHeight - it.realWidth = realWidth - it.hover = ArrayList(hover) - it.build = build - } - } - } - - @VViewMaker - fun splitImage( - img: String, - x: Int = 0, - y: Int = 0, - xs: Int = 0, - ys: Int = 0, - init: BuildingSplitImage.() -> Unit - ) { - val si = BuildingSplitImage(img, x, y, xs, ys) - si.init() - components += si - } - - inner class BuildingMcImage(img: String, x: Int, y: Int, xs: Int, ys: Int) - : SplitImage(img, x, y, xs, ys), Building> { - override var build: SplitImage.(VC) -> Unit = {} - - override fun createComponents(context: VC): VexMcImage { - return VexMcImage(img, x, y, u, v, xs, ys, uWidth, vHeight, realWidth, realHeight).also { - if (hover.isNotEmpty()) { - it.setHover(VexHoverText(hover)) - } - } - } - - override fun copy(): BuildingMcImage { - return BuildingMcImage(img, x, y, xs, ys).also { - it.build = build - it.hover = ArrayList(hover) - } - } - } - - @VViewMaker - fun mcImage( - img: String, - x: Int = 0, - y: Int = 0, - xs: Int = 0, - ys: Int = 0, - init: BuildingMcImage.() -> Unit) { - val si = BuildingMcImage(img, x, y, xs, ys) - si.init() - components += si - } - - inner class Text( - var x: Int = 0, - var y: Int = 0, - var scale: Double = 1.0, - var textWidth: Int = 10, - var text: MutableList = mutableListOf(), - override var hover: MutableList = mutableListOf(), - override var build: Text.(VC) -> Unit = {} - ) : VComponent(), HoverText, Building { - - @VViewMaker - fun text(init: HoverText.Holder.() -> Unit) { - val hh = HoverText.Holder(text) - hh.init() - } - - override fun createComponents(context: VC): VexText { - if (hover.isEmpty()) { - return VexText(x, y, text, scale) - } - return VexText(x, y, text, scale, - VexHoverText(hover) - , textWidth) - } - - override fun copy(): Text { - return Text(x, y, scale, textWidth, ArrayList(text), ArrayList(hover), build) - } - } - - - @VViewMaker - fun text( - x: Int = 0, - y: Int = 0, - scale: Double = 1.0, - textWidth: Int = 10, - init: Text.() -> Unit - ) { - val text = Text(x, y, scale, textWidth) - text.init() - components += text - } - - - fun toComponentsList(context: VC): List { - return components.mapNotNull { - if (it.isVisible(context)) { - it.toVexComponents(context) - } else { - null - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/HoverText.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/HoverText.kt deleted file mode 100644 index 0618fbf..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/HoverText.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -@VViewMaker -interface HoverText { - val hover: MutableList - - class Holder( - val hover: MutableList - ) { - @VViewMaker - operator fun String.unaryPlus() { - hover += this - } - - @VViewMaker - operator fun String.unaryMinus() { - hover -= this - } - - @VViewMaker - operator fun set(index: Int, lore: String) { - while (this.hover.size <= index) { - +"" - } - this.hover[index] = lore - } - - - @VViewMaker - operator fun get(index: Int): String = hover[index] - } - - @JvmDefault - @VViewMaker - fun hover(init: Holder.() -> Unit) { - val ho = Holder(hover) - ho.init() - } -} \ No newline at end of file diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/VComponent.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/VComponent.kt deleted file mode 100644 index 5bdf036..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/VComponent.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -import com.github.bryanser.brapi.vview.VViewContext -import lk.vexview.gui.components.VexComponents - -abstract class VComponent( - protected var visible: VC.() -> Boolean = { true }, - protected var comInit: VC.(COM) -> Unit = {} -) { - // var build: VC.(VComponent) -> Unit = {} - fun isVisible(context: VC): Boolean = visible(context) - - @VViewMaker - fun visible(func: VC.() -> Boolean) { - visible = func - } - - @VViewMaker - fun init(func: VC.(COM) -> Unit) { - comInit = func - } - - protected abstract fun createComponents(context: VC): COM - - fun toVexComponents(context: VC): COM { - val copy = this.copy() - if (copy is Building<*, *>) { - val b = copy as Building> - b.build(copy, context) - } - val com = copy.createComponents(context) - copy.comInit(context, com) - return com - } - - abstract fun copy(): VComponent -} - diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/VComponentBuilder.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/VComponentBuilder.kt deleted file mode 100644 index bdbede1..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/VComponentBuilder.kt +++ /dev/null @@ -1,750 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -import com.github.bryanser.brapi.Main -import com.github.bryanser.brapi.vview.VViewContext -import lk.vexview.event.CheckBoxEvent -import lk.vexview.event.VexSlotClickEvent -import lk.vexview.gui.components.* -import lk.vexview.gui.components.expand.VexBase64Image -import lk.vexview.gui.components.expand.VexClickableButton -import lk.vexview.gui.components.expand.VexColorfulTextArea -import lk.vexview.gui.components.expand.VexColorfulTextField -import org.bukkit.Bukkit -import org.bukkit.entity.Entity -import org.bukkit.entity.EntityType -import org.bukkit.entity.Player -import org.bukkit.event.EventHandler -import org.bukkit.event.Listener -import org.bukkit.inventory.ItemStack -import java.io.ByteArrayInputStream -import java.io.File -import java.io.FileInputStream -import java.io.InputStream -import java.util.* -import kotlin.collections.ArrayList - - -open class VComponentBuilder( - father: VComponentBuilder? = null, - list: MutableList> = mutableListOf() -) : DynamicComponentBuilder(father, list), Listener { - - protected val bindCheckBox: MutableMap>> - protected val bindSlot: MutableMap>> - - init { - if (father == null) { - Bukkit.getPluginManager().registerEvents(this, Main.getPlugin()) - bindCheckBox = hashMapOf() - bindSlot = hashMapOf() - } else { - bindCheckBox = father.bindCheckBox - bindSlot = father.bindSlot - } - } - - fun copy(): VComponentBuilder { - return VComponentBuilder(this, ArrayList(components)) - } - - @EventHandler - open fun onClick(evt: VexSlotClickEvent) { - if (bindSlot.isEmpty()) { - return - } - for ((ctx, list) in bindSlot) { - if (ctx.player.uniqueId != evt.player.uniqueId) { - continue - } - for ((cb, vs) in list) { - if (evt.id == vs.id) { - val click = cb.click.getOrElse(evt.clickType) { - cb.click[cb.getSuperClick(evt.clickType) ?: return] - } ?: return - click(ctx) - return - } - } - } - } - - @EventHandler - open fun onChangeCheckBox(evt: CheckBoxEvent) { - if (bindCheckBox.isEmpty()) { - return - } - for ((ctx, list) in bindCheckBox) { - for ((cb, vcb) in list) { - if (evt.checkBox == vcb) { - cb.change(ctx, evt.checkBox.isChecked) - return - } - } - } - } - - - @VViewMaker - inner class CheckBox( - val id: Int, - var x: Int = 0, - var y: Int = 0, - var w: Int = 0, - var h: Int = 0, - var img: String, - var checkImg: String = img, - val default: Boolean = false, - override var hover: MutableList = mutableListOf(), - internal var change: VC.(check: Boolean) -> Unit = {}, - override var build: CheckBox.(VC) -> Unit = {} - ) : VComponent(), HoverText, Building { - - protected var proxy: VC.(CheckBoxProxy) -> Unit = {} - - - @VViewMaker - fun proxy(func: VC.(CheckBoxProxy) -> Unit) { - proxy = func - } - - @VViewMaker - fun onChange(func: VC.(check: Boolean) -> Unit) { - change = func - } - - inner class CheckBoxProxy( - val context: VC - ) : (Boolean) -> Unit { - fun setChecked(chk: Boolean) { - context.getOpenedVexGui().setCheckBox(id, chk) - } - - override fun invoke(p1: Boolean) { - setChecked(p1) - } - } - - override fun createComponents(context: VC): VexCheckBox { - val vcb = VexCheckBox(id, img, checkImg, x, y, w, h, default) - if (hover.isNotEmpty()) { - vcb.setHover(VexHoverText(hover)) - } - this@VComponentBuilder.bindCheckBox.getOrPut(context) { mutableListOf() }.add(this to vcb) - proxy(context, CheckBoxProxy(context)) - return vcb - } - - override fun copy(): CheckBox { - return CheckBox(id, x, y, w, h, img, checkImg, default, ArrayList(hover), change, build).also { - it.proxy = proxy - } - } - } - - @VViewMaker - fun checkBox( - id: Int, - img: String, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - clickImg: String = img, - default: Boolean = false, - init: CheckBox.() -> Unit - ) { - val cb = CheckBox(id, x, y, w, h, img, clickImg, default) - cb.init() - components += cb - } - - - @VViewMaker - inner class ScrollingList( - var x: Int, - var y: Int, - var w: Int, - var h: Int, - var fullHight: Int, - override var build: ScrollingList.(VC) -> Unit = {}, - protected val subCom: VComponentBuilder = VComponentBuilder(this@VComponentBuilder) - ) : VComponent(), Building { - - - @VViewMaker - fun component(init: VComponentBuilder.() -> Unit) { - subCom.init() - } - - inner class ScrollingProxy( - val context: VC - ) { - fun addListDynamicComponent(init: DynamicComponentBuilder.() -> Unit) { - val dcb = DynamicComponentBuilder() - dcb.init() - for (com in dcb.toComponentsList(context)) { - if (com is DynamicComponent) { - context.getOpenedVexGui().addListDynamicComponent(com) - } - } - } - - fun removeListDynamicComponent(com: VexComponents) { - if (com is DynamicComponent) { - context.getOpenedVexGui().removeListDynamicComponent(com) - } - } - } - - var proxy: VC.(ScrollingProxy) -> Unit = {} - - - @VViewMaker - fun dynamicProxy(func: VC.(ScrollingProxy) -> Unit) { - proxy = func - } - - override fun createComponents(context: VC): VexScrollingList { - val vsl = VexScrollingList(x, y, w, h, fullHight) - for (v in subCom.toComponentsList(context)) { - if (v is ScrollingListComponent) { - vsl.addComponent(v) - } - } - proxy(context, ScrollingProxy(context)) - return vsl - } - - override fun copy(): ScrollingList { - return ScrollingList(x, y, w, h, fullHight, build, subCom.copy()) - } - } - - - @VViewMaker - fun scrollingList( - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - fullHight: Int = 0, - init: ScrollingList.() -> Unit - ) { - val sl = ScrollingList(x, y, w, h, fullHight) - sl.init() - components += sl - } - - @VViewMaker - inner class Slot( - var id: Int = 0, - var x: Int = 0, - var y: Int = 0, - internal var provider: VC.() -> ItemStack? = { null }, - val click: EnumMap Unit> = EnumMap Unit>(VexSlotClickEvent.ClickType::class.java), - override var build: Slot.(VC) -> Unit = {} - ) : VComponent(), Building { - override fun copy(): Slot { - return Slot(id, x, y, provider, EnumMap(click), build) - } - - @VViewMaker - fun item(func: VC.() -> ItemStack?) { - provider = func - } - - @VViewMaker - fun item(item: ItemStack?) { - provider = { item } - } - - @VViewMaker - fun click(func: VC.() -> Unit) { - click[VexSlotClickEvent.ClickType.values()[1]] = func - } - - @VViewMaker - private fun click(type: VexSlotClickEvent.ClickType, func: VC.() -> Unit) { - click[type] = func - } - - @VViewMaker - fun click(type:ClickType,func:VC.()->Unit){ - click[type.type] = func - } - - override fun createComponents(context: VC): VexSlot { - return VexSlot(id, x, y, provider(context)).also { - bindSlot.getOrPut(context) { - mutableListOf() - }.add(this to it) - } - } - - fun getSuperClick(ct: VexSlotClickEvent.ClickType): VexSlotClickEvent.ClickType? { - return when (ct) { - VexSlotClickEvent.ClickType.values()[1] -> null - VexSlotClickEvent.ClickType.values()[0] -> VexSlotClickEvent.ClickType.values()[1] - VexSlotClickEvent.ClickType.values()[2] -> VexSlotClickEvent.ClickType.values()[1] - else -> null - } - } - } - - - @VViewMaker - fun slot( - id: Int = 0, - x: Int = 0, - y: Int = 0, - init: Slot.() -> Unit - ) { - val slot = Slot(id, x, y) - slot.init() - components += slot - } - - - abstract inner class TextField( - var id: Int, - var x: Int, - var y: Int, - var w: Int, - var h: Int, - var maxLength: Int, - var text: String, - override var hover: MutableList = mutableListOf() - ) : VComponent(), HoverText { - - internal var proxy: VC.(TextFieldProxy) -> Unit = {} - - fun proxy(func: VC.(TextFieldProxy) -> Unit) { - proxy = func - } - - inner class TextFieldProxy( - val context: VC - ) : (String) -> Unit { - - fun setTextFieldContent(text: String) { - context.getOpenedVexGui().setTextFieldContent(id, text) - } - - override fun invoke(p1: String) { - setTextFieldContent(p1) - } - - } - } - - inner class BuildingTextField(id: Int, x: Int, y: Int, w: Int, h: Int, maxLength: Int, text: String, override var build: TextField.(VC) -> Unit = {}) - : TextField(id, x, y, w, h, maxLength, text), Building> { - - override fun createComponents(context: VC): VexTextField { - proxy(context, TextFieldProxy(context)) - return VexTextField(x, y, w, h, maxLength, id, text).also { - if (hover.isNotEmpty()) { - it.setHover(VexHoverText(hover)) - } - } - } - - override fun copy(): BuildingTextField { - return BuildingTextField(id, x, y, w, h, maxLength, text, build).also { - it.hover = ArrayList(hover) - it.proxy = proxy - } - } - } - - @VViewMaker - fun textField( - id: Int, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - maxLength: Int = 100, - text: String = "", - init: TextField .() -> Unit - ) { - val ta = BuildingTextField(id, x, y, w, h, maxLength, text) - ta.init() - components += ta - } - - @VViewMaker - /** - * 注: vv2.6以上才推荐使用的类 - */ - inner class ExpandBuilder { - - abstract inner class TextArea( - var id: Int, - var x: Int, - var y: Int, - var w: Int, - var h: Int, - var maxLength: Int, - var text: MutableList = mutableListOf(), - override var hover: MutableList = mutableListOf() - ) : VComponent(), HoverText { - - @VViewMaker - fun text(init: HoverText.Holder.() -> Unit) { - val hh = HoverText.Holder(text) - hh.init() - } - } - - - inner class BuildingTextArea(id: Int, x: Int, y: Int, w: Int, h: Int, maxLength: Int, override var build: TextArea.(VC) -> Unit = {}) - : TextArea(id, x, y, w, h, maxLength), Building> { - - override fun createComponents(context: VC): VexTextArea { - return VexTextArea(x, y, w, h, maxLength, id, text).also { - if (hover.isNotEmpty()) { - it.setHover(VexHoverText(hover)) - } - } - } - - override fun copy(): BuildingTextArea { - return this@ExpandBuilder.BuildingTextArea(id, x, y, w, h, maxLength, build).also { - it.text = ArrayList(text) - it.hover = ArrayList(hover) - } - } - } - - @VViewMaker - fun textArea( - id: Int, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - maxLength: Int = 100, - init: BuildingTextArea.() -> Unit - ) { - val ta = BuildingTextArea(id, x, y, w, h, maxLength) - ta.init() - components += ta - } - - @VViewMaker - inner class Draw( - var x: Int = 0, - var y: Int = 0, - var scale: Int = 30, - var see: Boolean = true, - override var build: Draw.(VC) -> Unit = {}, - internal val create: Draw.(VC) -> VED - ) : VComponent(), Building> { - lateinit var provider: VC.() -> E - - @VViewMaker - fun data(func: VC.() -> E) { - provider = func - } - - fun getData(context: VC): E = provider(context) - override fun createComponents(context: VC): VED { - return create(this, context) - } - - override fun copy(): Draw { - return this@ExpandBuilder.Draw(x, y, scale, see, build, create).also { - it.provider = provider - } - } - } - - @VViewMaker - fun drawEntity( - x: Int = 0, - y: Int = 0, - scale: Int = 30, - see: Boolean = true, - init: Draw.() -> Unit - ) { - val draw = Draw(x, y, scale, see) { context -> - val ved = VexEntityDraw(x, y, scale, getData(context)) - ved.setSee(see) - ved - } - draw.init() - components += draw - } - - - @VViewMaker - fun drawPlayer( - x: Int = 0, - y: Int = 0, - scale: Int = 30, - see: Boolean = true, - init: Draw.() -> Unit - ) { - val draw = Draw(x, y, scale, see) { context -> - val ved = VexPlayerDraw(x, y, scale, getData(context)) - ved.setSee(see) - ved - } - draw.init() - components += draw - } - - @VViewMaker - fun drawEntityType( - x: Int = 0, - y: Int = 0, - scale: Int = 30, - see: Boolean = true, - init: Draw.() -> Unit - ) { - val draw = Draw(x, y, scale, see) { context -> - val ved = VexEntityDraw(x, y, scale, getData(context)) - ved.setSee(see) - ved - } - draw.init() - components += draw - } - - - @VViewMaker - fun drawPlayerGameProfile( - x: Int = 0, - y: Int = 0, - scale: Int = 30, - see: Boolean = true, - init: Draw.() -> Unit - ) { - val draw = Draw(x, y, scale, see) { context -> - val ved = VexPlayerDraw(x, y, scale, getData(context)) - ved.setSee(see) - ved - } - - draw.init() - components += draw - } - - - inner class Base64Image( - var id: String, - var x: Int, - var y: Int, - var w: Int, - var h: Int, - override var hover: MutableList = mutableListOf(), - override var build: Base64Image.(VC) -> Unit = {} - ) : VComponent(), HoverText, Building { - lateinit var imageField: () -> InputStream - - @VViewMaker - fun image(image: () -> InputStream) { - this.imageField = image - } - - @VViewMaker - fun image(image: File) { - image { - FileInputStream(image) - } - } - - @VViewMaker - fun image(base64: String) { - val code = Base64.getDecoder().decode(base64) - image { - ByteArrayInputStream(code) - } - } - - override fun createComponents(context: VC): VexBase64Image { - return VexBase64Image(imageField(), id, x, y, w, h, if (hover.isEmpty()) { - null - } else { - VexHoverText(hover) - }) - } - - override fun copy(): Base64Image { - return this@ExpandBuilder.Base64Image(id, x, y, w, h, ArrayList(hover), build).also { - if (this::imageField.isInitialized) { - it.imageField = imageField - } - } - } - } - - @VViewMaker - fun base64Image( - id: String, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - init: Base64Image.() -> Unit - ) { - val data = Base64Image(id, x, y, w, h) - data.init() - components += data - } - - inner class ClickableButton( - id: UUID, - x: Int, - y: Int, - w: Int, - h: Int, - name: String, - img: String, - var unclickableImg: String = img, - var clickable: Boolean = true, - override var build: ClickableButton.(VC) -> Unit = {} - ) : Button(id, x, y, w, h, name, img), Building { - internal var proxy: VC.(ButtonClickableProxy) -> Unit = {} - - override fun createComponents(context: VC): VexClickableButton { - return VexClickableButton(id, name, img, clickImg, unclickableImg, x, y, w, h, { - if (click != null && it.uniqueId == context.player.uniqueId) { - click!!(context) - } - }, clickable).also { - if (hover.isNotEmpty()) { - it.hover = VexHoverText(hover) - } - proxy(context, ButtonClickableProxy(context)) - } - } - - inner class ButtonClickableProxy(val context: VC) : (Boolean) -> Unit { - fun setButtonClickable(clickable: Boolean) { - context.getOpenedVexGui().setButtonClickable(id, clickable) - } - - override fun invoke(p1: Boolean) { - setButtonClickable(p1) - } - } - - fun proxy(func: VC.(ButtonClickableProxy) -> Unit) { - proxy = func - } - - override fun copy(): ClickableButton { - return this@ExpandBuilder.ClickableButton(id, x, y, w, h, name, img, unclickableImg, clickable, build).also { - it.proxy = proxy - } - } - } - - - @VViewMaker - fun clickableButton( - name: String, - img: String, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - init: ClickableButton.() -> Unit - ): UUID { - val uid = UUID.randomUUID() - val cb = ClickableButton(uid, x, y, w, h, name, img) - cb.init() - components += cb - return uid - } - - inner class ColorfulTextArea( - id: Int, - x: Int, - y: Int, - w: Int, - h: Int, - maxLength: Int, - override var mainColor: Int = 0, - override var sideColor: Int = 0, - override var build: ColorfulTextArea.(VC) -> Unit = {} - ) : TextArea(id, x, y, w, h, maxLength), Colorful, Building { - override fun createComponents(context: VC): VexColorfulTextArea { - return VexColorfulTextArea(x, y, w, h, maxLength, id, mainColor, sideColor, text).also { - if (hover.isNotEmpty()) { - it.setHover(VexHoverText(hover)) - } - } - } - - override fun copy(): ColorfulTextArea { - return this@ExpandBuilder.ColorfulTextArea(id, x, y, w, h, maxLength, mainColor, sideColor, build) - } - } - - @VViewMaker - fun colorfulTextArea( - id: Int, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - maxLength: Int = 30, - init: ColorfulTextArea.() -> Unit - ) { - val cta = ColorfulTextArea(id, x, y, w, h, maxLength) - cta.init() - components += cta - } - } - - - inner class ColorfulTextField( - id: Int, - x: Int, - y: Int, - w: Int, - h: Int, - maxLength: Int, - text: String, - override var mainColor: Int = 0, - override var sideColor: Int = 0, - override var build: ColorfulTextField.(VC) -> Unit = {} - ) : TextField(id, x, y, w, h, maxLength, text), Colorful, Building { - override fun createComponents(context: VC): VexColorfulTextField { - return VexColorfulTextField(x, y, w, h, maxLength, id, mainColor, sideColor, text).also { - if (hover.isNotEmpty()) { - it.setHover(VexHoverText(hover)) - } - } - } - - override fun copy(): ColorfulTextField { - return ColorfulTextField(id, x, y, w, h, maxLength, text, mainColor, sideColor, build) - } - } - - fun colorfulTextField( - id: Int, - x: Int = 0, - y: Int = 0, - w: Int = 0, - h: Int = 0, - maxLength: Int = 30, - text: String = "", - init: ColorfulTextField.() -> Unit - ) { - val ctf = ColorfulTextField(id, x, y, w, h, maxLength, text) - ctf.init() - components += ctf - } - - @VViewMaker - fun expand(init: ExpandBuilder.() -> Unit) { - ExpandBuilder().init() - } - -} - diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/VView.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/VView.kt deleted file mode 100644 index 9cbac1c..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/VView.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - -import com.github.bryanser.brapi.vview.VViewContext -import com.github.bryanser.brapi.vview.VViewHandler -import lk.vexview.api.VexViewAPI -import lk.vexview.gui.VexGui -import lk.vexview.gui.components.DynamicComponent -import lk.vexview.gui.components.VexComponents -import org.bukkit.entity.Player - -@VViewMaker -open class VView( - val img: String, - val x: Int, - val y: Int, - val w: Int, - val h: Int, - val contextFactory: (Player) -> VC -) : VComponentBuilder() { - - protected var close: VC.() -> Unit = {} - protected var open: VC.() -> Boolean = { true } - protected var proxy: VC.(ViewProxy) -> Unit = {} - - inner class ViewProxy( - val context: VC - ) { - fun addDynamicComponent(init: DynamicComponentBuilder.() -> Unit) { - val dcb = DynamicComponentBuilder() - dcb.init() - for (com in dcb.toComponentsList(context)) { - if (com is DynamicComponent) { - context.getOpenedVexGui().addDynamicComponent(com) - } - } - } - - fun removeDynamicComponent(com: VexComponents) { - if (com is DynamicComponent) { - context.getOpenedVexGui().removeDynamicComponent(com) - } - } - } - - @VViewMaker - fun dynamicProxy(func: VC.(ViewProxy) -> Unit) { - proxy = func - } - - @VViewMaker - fun onClose(func: VC.() -> Unit) { - close = func - } - - @VViewMaker - fun checkOpen(func: VC.() -> Boolean) { - open = func - } - - fun onClose(context: VC) { - close(context) - bindCheckBox.remove(context) - } - - open fun checkOpen(context: VC): Boolean = open(context) - - open fun build(context: VC): VexGui { - val gui = try { - VexGui(img, x, y, w, h) - } catch (e: Throwable) { - VexGui(img, x, y, w, h, w, h) - } - for (com in toComponentsList(context)) { - gui.addComponent(com) - } - return gui - } - - open fun open(player: Player) { - val context = contextFactory(player) - context.view = this as VView - VViewHandler.opening[player.uniqueId] = context - if (checkOpen(context)) { - bindCheckBox[context] = mutableListOf() - VexViewAPI.openGui(player, this.build(context)) - proxy(context, ViewProxy(context)) - } - } -} \ No newline at end of file diff --git a/src/main/java/com/github/bryanser/brapi/vview/dsl/VViewMaker.kt b/src/main/java/com/github/bryanser/brapi/vview/dsl/VViewMaker.kt deleted file mode 100644 index bf6bad2..0000000 --- a/src/main/java/com/github/bryanser/brapi/vview/dsl/VViewMaker.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.bryanser.brapi.vview.dsl - - -@DslMarker -@Retention(AnnotationRetention.BINARY) -annotation class VViewMaker \ No newline at end of file From fada48f4079f47421fa6a86807a0b16e1c217fde Mon Sep 17 00:00:00 2001 From: Laotouy <18922569@qq.com> Date: Thu, 18 Sep 2025 01:12:38 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20pom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index d89d92f..bd5d7e7 100644 --- a/pom.xml +++ b/pom.xml @@ -286,9 +286,9 @@ ${kotlin.version} - com.comphenix.protocol + net.dmulloy2 ProtocolLib - 4.4.0 + 5.4.0 provided @@ -297,16 +297,10 @@ 1.6 provided - - lk.vexview - VexView - 2.6 - provided - me.clip placeholderapi - 2.10.9 + 2.11.6 provided From 0a3b2ef925034c236a2e3c86051c3724243abfce Mon Sep 17 00:00:00 2001 From: Laotouy <18922569@qq.com> Date: Thu, 18 Sep 2025 01:12:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=8A=A0=E5=85=A5=20api=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/plugin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 15ed6d4..18c0d9a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,6 +3,7 @@ author: Bryan_lzh authors: ['Bryan_lzh','DarkBlade12'] main: com.github.bryanser.brapi.Main description: '开发者QQ:390807154' +api-version: 1.12 softdepend: [KotlinExt,Vault,VexView,PlaceholderAPI,TabooLib] loadbefore: [OpenInv] version: ${project.version} From 2f458baef3c33b663adb1fce06e8dc1e5dd8a158 Mon Sep 17 00:00:00 2001 From: Laotouy <18922569@qq.com> Date: Thu, 18 Sep 2025 01:40:21 +0800 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E5=BA=9F?= =?UTF-8?q?=E5=BC=83=E7=9A=84=E8=84=9A=E6=9C=AC=E7=B3=BB=E7=BB=9F=E5=92=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DJvmDefault=E5=BC=83=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除所有脚本相关类(ScriptListener, ScriptLoader, ScriptManager等) - 删除测试脚本相关类(Test, TestManager, RSACheck等) - 配置kotlin-maven-plugin使用-Xjvm-default=all替代废弃的@JvmDefault注解 - 移除代码中所有@JvmDefault注解 - 更新API版本到1.16 - 清理废弃的VexView相关代码 - 修复ProtocolLib相关的异常处理 Co-Authored-By: Claude --- pom.xml | 27 ++++ src/main/java/Br/API/ActionBar.java | 6 +- src/main/java/Br/API/Data/ProxyUtil.java | 90 ----------- .../java/Br/API/Scripts/ScriptListener.java | 46 ------ .../Br/API/Scripts/ScriptListenerManager.java | 34 ---- .../java/Br/API/Scripts/ScriptLoader.java | 100 ------------ src/main/java/Br/API/SignUtils.java | 6 +- .../java/com/github/bryanser/brapi/Main.kt | 26 ---- .../github/bryanser/brapi/ScriptManager.kt | 145 ------------------ .../com/github/bryanser/brapi/data/Value.kt | 1 - .../com/github/bryanser/brapi/kview/KIcon.kt | 2 - .../bryanser/brapi/particle/ParticleData.kt | 1 - .../github/bryanser/brapi/test/RSACheck.java | 99 ------------ .../com/github/bryanser/brapi/test/Script.kt | 143 ----------------- .../com/github/bryanser/brapi/test/Test.kt | 31 ---- .../github/bryanser/brapi/test/TestManager.kt | 41 ----- src/main/resources/plugin.yml | 2 +- 17 files changed, 30 insertions(+), 770 deletions(-) delete mode 100644 src/main/java/Br/API/Scripts/ScriptListener.java delete mode 100644 src/main/java/Br/API/Scripts/ScriptListenerManager.java delete mode 100644 src/main/java/Br/API/Scripts/ScriptLoader.java delete mode 100644 src/main/java/com/github/bryanser/brapi/ScriptManager.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/test/RSACheck.java delete mode 100644 src/main/java/com/github/bryanser/brapi/test/Script.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/test/Test.kt delete mode 100644 src/main/java/com/github/bryanser/brapi/test/TestManager.kt diff --git a/pom.xml b/pom.xml index bd5d7e7..87c5994 100644 --- a/pom.xml +++ b/pom.xml @@ -160,6 +160,33 @@ kotlin-maven-plugin org.jetbrains.kotlin 1.9.23 + + + compile + compile + + compile + + + + ${project.basedir}/src/main/java + + + + + test-compile + test-compile + + test-compile + + + + + + -Xjvm-default=all + + 1.8 + diff --git a/src/main/java/Br/API/ActionBar.java b/src/main/java/Br/API/ActionBar.java index ea04ff3..c69bcc8 100644 --- a/src/main/java/Br/API/ActionBar.java +++ b/src/main/java/Br/API/ActionBar.java @@ -25,11 +25,7 @@ public static void sendActionBar(Player p, String msg) { } catch (Throwable e) { pc.getBytes().write(0, (byte) 2); } - try { - pm.sendServerPacket(p, pc); - } catch (InvocationTargetException ex) { - Logger.getLogger(ActionBar.class.getName()).log(Level.SEVERE, null, ex); - } + pm.sendServerPacket(p, pc); } } diff --git a/src/main/java/Br/API/Data/ProxyUtil.java b/src/main/java/Br/API/Data/ProxyUtil.java index 17c98e7..d51a355 100644 --- a/src/main/java/Br/API/Data/ProxyUtil.java +++ b/src/main/java/Br/API/Data/ProxyUtil.java @@ -6,7 +6,6 @@ */ package Br.API.Data; -import Br.API.Scripts.ScriptLoader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -26,7 +25,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.script.ScriptException; -import jdk.nashorn.api.scripting.NashornScriptEngine; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; @@ -94,94 +92,6 @@ public static void addProxy(Plugin plugin, Class cls) { list.add(cls); } - public static void proxy(Plugin plugin) { - List> list = Proxied.get(plugin.getName()); - if (list == null) { - return; - } - File folder = new File(plugin.getDataFolder(), File.separator + "Proxy" + File.separator); - if (!folder.exists()) { - folder.mkdirs(); - } - for (Class cls : list) { - if (!cls.isAnnotationPresent(ProxyInfo.class)) { - continue; - } - ProxyInfo pi = cls.getAnnotation(ProxyInfo.class); - File file = Util.getFile(folder, pi.value()); - YamlConfiguration config; - if (!file.exists()) { - config = new YamlConfiguration(); - } else { - config = YamlConfiguration.loadConfiguration(file); - } - String[] patharr = pi.value().split("\\."); - String root = patharr[patharr.length - 1]; - boolean edit = false; - for (Field f : Util.getAllDeclaredFields(cls)) { - if (!Modifier.isStatic(f.getModifiers())) { - continue; - } - f.setAccessible(true); - if (f.isAnnotationPresent(ProxyScript.class)) { - if (!ProxiedScript.class.isAssignableFrom(f.getType())) { - continue; - } - ProxyScript ps = f.getAnnotation(ProxyScript.class); - File jsFile = Util.getJsFile(folder, ps.file()); - if (!jsFile.exists()) { - try { - Util.OutputFile(plugin, ps.fromJarFile(), jsFile); - } catch (IOException ex) { - Logger.getLogger(ProxyUtil.class.getName()).log(Level.SEVERE, null, ex); - } - } - ProxiedScript pds = new ProxiedScript() { - private String Function = ps.function(); - private NashornScriptEngine Engine = ScriptLoader.evalAsUTF8(plugin, jsFile); - - @Override - public Object proxy(Object... args) { - try { - return Engine.invokeFunction(Function, args); - } catch (ScriptException | NoSuchMethodException ex) { - Logger.getLogger(ProxyUtil.class.getName()).log(Level.SEVERE, null, ex); - } - return null; - } - }; - try { - f.set(pds, null); - } catch (IllegalArgumentException | IllegalAccessException ex) { - Logger.getLogger(ProxyUtil.class.getName()).log(Level.SEVERE, null, ex); - } - continue; - } - if (!f.isAnnotationPresent(Proxy.class)) { - continue; - } - Proxy p = f.getAnnotation(Proxy.class); - String path = root + '.' + (p.value().isEmpty() ? f.getName() : p.value()); - try { - if (config.contains(path)) { - f.set(config.get(path), null); - } else { - config.set(path, f.get(null)); - edit = true; - } - } catch (IllegalArgumentException | IllegalAccessException ex) { - Logger.getLogger(ProxyUtil.class.getName()).log(Level.SEVERE, null, ex); - } - } - if (edit) { - try { - config.save(file); - } catch (IOException ex) { - Logger.getLogger(ProxyUtil.class.getName()).log(Level.SEVERE, null, ex); - } - } - } - } static class Util { diff --git a/src/main/java/Br/API/Scripts/ScriptListener.java b/src/main/java/Br/API/Scripts/ScriptListener.java deleted file mode 100644 index 21ae6c0..0000000 --- a/src/main/java/Br/API/Scripts/ScriptListener.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 开发者:Bryan_lzh - * QQ:390807154 - * 保留一切所有权 - * 若为Bukkit插件 请前往plugin.yml查看剩余协议 - */ -package Br.API.Scripts; - -import org.bukkit.event.Event; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - -/** - * - * @author Bryan_lzh - * @version 1.0 - * @param - */ -public interface ScriptListener extends Listener { - - public void onEvent(E e); - - public String getEventName(); - - public default void castEvent(E evt){ - if(this.getEventClass().isInstance(evt)){ - this.onEvent(evt); - } - } - - public default Class getEventClass(){ - try { - return (Class) Class.forName(this.getEventName()); - } catch (ClassNotFoundException e) { - } - return null; - } - - public default EventPriority getPriority() { - return EventPriority.NORMAL; - } - - public default boolean ignoreCancelled(){ - return true; - } -} diff --git a/src/main/java/Br/API/Scripts/ScriptListenerManager.java b/src/main/java/Br/API/Scripts/ScriptListenerManager.java deleted file mode 100644 index 12c19c9..0000000 --- a/src/main/java/Br/API/Scripts/ScriptListenerManager.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 开发者:Bryan_lzh - * QQ:390807154 - * 保留一切所有权 - * 若为Bukkit插件 请前往plugin.yml查看剩余协议 - */ -package Br.API.Scripts; - -import java.nio.charset.Charset; -import org.bukkit.Bukkit; -import org.bukkit.event.HandlerList; -import org.bukkit.plugin.Plugin; - -/** - * - * @author Bryan_lzh - * @version 1.0 - */ -public class ScriptListenerManager { - - public static void RegisterListener(Plugin p, ScriptListener listener) { - Class cls = listener.getEventClass(); - if (cls != null) { - Bukkit.getPluginManager().registerEvent(cls, listener, listener.getPriority(), (l, e) -> listener.castEvent(e), p, listener.ignoreCancelled()); - } - } - - public static void UnregisterListener(ScriptListener l) { - HandlerList.unregisterAll(l); - } - - private ScriptListenerManager() { - } -} diff --git a/src/main/java/Br/API/Scripts/ScriptLoader.java b/src/main/java/Br/API/Scripts/ScriptLoader.java deleted file mode 100644 index ee0a7f6..0000000 --- a/src/main/java/Br/API/Scripts/ScriptLoader.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 开发者:Bryan_lzh - * QQ:390807154 - * 保留一切所有权 - * 若为Bukkit插件 请前往plugin.yml查看剩余协议 - */ -package Br.API.Scripts; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.util.function.Consumer; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; -import jdk.nashorn.api.scripting.NashornScriptEngine; -import jdk.nashorn.api.scripting.NashornScriptEngineFactory; -import org.bukkit.plugin.Plugin; - -/** - * nashorn脚本引擎存在一个明显的BUG
- * 位于
- * jdk.nashorn.api.scripting.NashornScriptEngineFactory:431的静态方法getAppClassLoader
- * 其中字节码描述如下: - *

- *
- * 0: invokestatic java/lang/Thread.currentThread:()Ljava/lang/Thread;
- * 3: invokevirtual - * java/lang/Thread.getContextClassLoader:()Ljava/lang/ClassLoader;
- * 6: astore_0
- * 7: aload_0
- * 8: ifnonnull 19
- * 11: ldc jdk/nashorn/api/scripting/NashornScriptEngineFactory
- * 13: invokevirtual - * java/lang/Class.getClassLoader:()Ljava/lang/ClassLoader;
- * 16: goto 20
- * 19: aload_0
- * 20: areturn

- * 显然
- * 代码返回的类加载器首先选取当前线程的类加载器(位于Thread.currentThread().getContextClassLoader())
- * 若返回null则返回NashornScriptEngineFactory的类加载器(NashornScriptEngineFactory.class.getClassLoader())
- * 这意味着 通过构造ScriptEngineManager所传入的类加载器没有任何用处 导致返回的ScriptEngine不使用所指定的类加载
- * - * @author Bryan_lzh - * @version 1.0 - */ -public class ScriptLoader { - - public static NashornScriptEngine eval(Plugin p, Reader fr) { - return eval(p, (t) -> { - try { - t.eval(fr); - } catch (ScriptException ex) { - Logger.getLogger(ScriptLoader.class.getName()).log(Level.SEVERE, null, ex); - } - }); - } - - public static NashornScriptEngine evalAsUTF8(Plugin p, File f) { - return eval(p, (t) -> { - try { - t.eval(new InputStreamReader(new FileInputStream(f), "UTF-8")); - } catch (ScriptException ex) { - Logger.getLogger(ScriptLoader.class.getName()).log(Level.SEVERE, null, ex); - } catch (FileNotFoundException ex) { - Logger.getLogger(ScriptLoader.class.getName()).log(Level.SEVERE, null, ex); - } catch (UnsupportedEncodingException ex) { - Logger.getLogger(ScriptLoader.class.getName()).log(Level.SEVERE, null, ex); - } - }); - } - - public static NashornScriptEngine eval(Plugin p, String fr) { - return eval(p, (t) -> { - try { - t.eval(fr); - } catch (ScriptException ex) { - Logger.getLogger(ScriptLoader.class.getName()).log(Level.SEVERE, null, ex); - } - }); - } - - public static NashornScriptEngine eval(Plugin p, Consumer c) { - ClassLoader backup = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(p.getClass().getClassLoader()); - ScriptEngineManager EngineManager = new ScriptEngineManager(p.getClass().getClassLoader()); - NashornScriptEngine ns = (NashornScriptEngine) EngineManager.getEngineByName("nashorn"); - if(ns == null){ - NashornScriptEngineFactory nsef = new NashornScriptEngineFactory(); - ns = (NashornScriptEngine) nsef.getScriptEngine(); - } - c.accept(ns); - Thread.currentThread().setContextClassLoader(backup); - return ns; - } -} diff --git a/src/main/java/Br/API/SignUtils.java b/src/main/java/Br/API/SignUtils.java index ec8e565..4336385 100644 --- a/src/main/java/Br/API/SignUtils.java +++ b/src/main/java/Br/API/SignUtils.java @@ -51,11 +51,7 @@ public void sendSignRequest(Player p, String id) { PacketContainer pc = new PacketContainer(PacketType.Play.Server.OPEN_SIGN_EDITOR); Location loc = p.getLocation(); pc.getBlockPositionModifier().write(0, new BlockPosition(loc.getBlockX(), loc.getBlockY() + 1, loc.getBlockZ())); - try { - pm.sendServerPacket(p, pc, false); - } catch (InvocationTargetException ex) { - Logger.getLogger(SignUtils.class.getName()).log(Level.SEVERE, null, ex); - } + pm.sendServerPacket(p, pc, false); } private static Map>> Callbacks = new HashMap<>(); diff --git a/src/main/java/com/github/bryanser/brapi/Main.kt b/src/main/java/com/github/bryanser/brapi/Main.kt index 718d10c..968f3a1 100644 --- a/src/main/java/com/github/bryanser/brapi/Main.kt +++ b/src/main/java/com/github/bryanser/brapi/Main.kt @@ -3,8 +3,6 @@ package com.github.bryanser.brapi import Br.API.EventListener import Br.API.Main.* import com.github.bryanser.brapi.kview.KViewHandler -import com.github.bryanser.brapi.test.TestManager -import com.github.bryanser.brapi.vview.VViewHandler import org.bukkit.Bukkit import org.bukkit.ChatColor import org.bukkit.command.Command @@ -47,11 +45,7 @@ class Main : JavaPlugin() { makeKotlinLoader() PLGUIN = this compOld() - ScriptManager.checkClass() - TestManager.init() KViewHandler.init() - ScriptManager.loadScript() - VViewHandler.init() } override fun onDisable() { @@ -91,32 +85,12 @@ class Main : JavaPlugin() { return true } if (args[1].equals("reload", true)) { - ScriptManager.loadScript() sender.sendMessage("§6重载成功") return true } sender.sendMessage("§6/$label script reload >> 重载所有脚本") return true } - if (args[0].equals("test", true) && args.size > 1 && sender.isOp) { - TestManager.init() - if (!TestManager.enable) { - return true - } - val test = TestManager.tests[args[1]] - if (test == null) { - sender.sendMessage("§c找不到名为${args[1]}的测试脚本") - return true - } - val sargs = if (args.size <= 2) arrayOf() else args.copyOfRange(2, args.size) - val r = test.test(sender, *sargs) - if (r.isEmpty()) { - sender.sendMessage("§6测试脚本执行成功") - } else { - sender.sendMessage("§c测试脚本执行失败: $r") - } - return true - } return true } diff --git a/src/main/java/com/github/bryanser/brapi/ScriptManager.kt b/src/main/java/com/github/bryanser/brapi/ScriptManager.kt deleted file mode 100644 index ea4e61c..0000000 --- a/src/main/java/com/github/bryanser/brapi/ScriptManager.kt +++ /dev/null @@ -1,145 +0,0 @@ -package com.github.bryanser.brapi - -import com.github.bryanser.brapi.test.Script -import jdk.nashorn.api.scripting.NashornScriptEngine -import jdk.nashorn.api.scripting.NashornScriptEngineFactory -import jdk.nashorn.api.scripting.ScriptObjectMirror -import org.bukkit.Bukkit -import org.bukkit.event.Event -import org.bukkit.event.EventPriority -import org.bukkit.event.Listener -import org.bukkit.plugin.Plugin -import java.io.File -import java.net.URL -import java.net.URLClassLoader -import java.util.logging.Level - -interface ScriptListenerRegister { - fun getPlugin(): Main - - fun registerListener(listener: ScriptObjectMirror, event: String): Listener? - fun registerListener(listener: ScriptObjectMirror, event: String, priority: EventPriority): Listener? - fun registerListener(listener: ScriptObjectMirror, event: String, ignoreCancel: Boolean): Listener? - fun registerListener(listener: ScriptObjectMirror, event: String, ignoreCancel: Boolean, priority: EventPriority): Listener? -} - -object ScriptManager : ScriptListenerRegister { - var hasNashorn: Boolean = false - - class ScriptListener( - val script: ScriptObjectMirror - ) : Listener { - fun call(evt: Event) { - script.call(script, evt) - } - } - - override fun getPlugin(): Main = Main.getPlugin() - - override fun registerListener(listener: ScriptObjectMirror, event: String): Listener? { - if (listener.isFunction) { - val evt = Class.forName(event) ?: return null - val targetevt = evt.asSubclass(Event::class.java) ?: return null - val ler = ScriptListener(listener) - Bukkit.getPluginManager().registerEvent(targetevt, ler, EventPriority.NORMAL, { listener, event -> - ler.call(event) - }, Main.getPlugin()) - return ler - } - return null - } - - override fun registerListener(listener: ScriptObjectMirror, event: String, priority: EventPriority): Listener? { - if (listener.isFunction) { - val evt = Class.forName(event) ?: return null - val targetevt = evt.asSubclass(Event::class.java) ?: return null - val ler = ScriptListener(listener) - Bukkit.getPluginManager().registerEvent(targetevt, ler, priority, { listener, event -> - ler.call(event) - }, Main.getPlugin()) - return ler - } - return null - } - - override fun registerListener(listener: ScriptObjectMirror, event: String, ignoreCancel: Boolean): Listener? { - if (listener.isFunction) { - val evt = Class.forName(event) ?: return null - val targetevt = evt.asSubclass(Event::class.java) ?: return null - val ler = ScriptListener(listener) - Bukkit.getPluginManager().registerEvent(targetevt, ler, EventPriority.NORMAL, { listener, event -> - ler.call(event) - }, Main.getPlugin(), ignoreCancel) - return ler - } - return null - } - - override fun registerListener(listener: ScriptObjectMirror, event: String, ignoreCancel: Boolean, priority: EventPriority): Listener? { - if (listener.isFunction) { - val evt = Class.forName(event) ?: return null - val targetevt = evt.asSubclass(Event::class.java) ?: return null - val ler = ScriptListener(listener) - Bukkit.getPluginManager().registerEvent(targetevt, ler, priority, { listener, event -> - ler.call(event) - }, Main.getPlugin(), ignoreCancel) - return ler - } - return null - } - - fun checkClass() { - try { - Class.forName("jdk.nashorn.api.scripting.NashornScriptEngine") - hasNashorn = true - return - } catch (e: ClassNotFoundException) { - val folder = Main.getPlugin().dataFolder - val f = File(folder, "nashorn.jar") - if (f.exists()) { - val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java) - method.isAccessible = true - val classLoader = this.javaClass.classLoader as URLClassLoader - val url = f.toURI().toURL() - method.invoke(classLoader, url); - hasNashorn = true - return - } - val log = Bukkit.getLogger() - log.log(Level.WARNING, "=================================================================") - log.log(Level.WARNING, " 未找到Nashorn脚本引擎 若无需求请忽略本提示 ") - log.log(Level.WARNING, " 若需要脚本引擎支持 请下载") - log.log(Level.WARNING, "https://github.com/BryanSer/BrAPI/raw/ver-kotlin/lib/nashorn.jar") - log.log(Level.WARNING, "并将jar放入 /plugins/BrAPI 目录下") - log.log(Level.WARNING, "=================================================================") - } - } - - fun createScriptEngine(plugin: Plugin): NashornScriptEngine { - val factory = NashornScriptEngineFactory() - val eng = factory.getScriptEngine(plugin.javaClass.classLoader) as NashornScriptEngine - return eng - } - - val scripts = mutableListOf