Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Mar 3, 2024
1 parent 0a8a115 commit 72156f0
Show file tree
Hide file tree
Showing 22 changed files with 1,102 additions and 35 deletions.
22 changes: 4 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
# TabooLib SDK
# Jarnbjorn

## 构建发行版本

发行版本用于正常使用, 不含 TabooLib 本体。

```
./gradlew clean build
```

## 构建开发版本

开发版本包含 TabooLib 本体, 用于开发者使用, 但不可运行。

```
./gradlew clean taboolibBuildApi -PDeleteCode
```

> 参数 -PDeleteCode 表示移除所有逻辑代码以减少体积。
> Jarnbjorn was the Dwarven-forged battle axe composed of Asgardian Steel and created for Rūna, one of the original members of the Valkyrior. After she mysteriously disappeared, having been assimilated by the Headless Celestial, it was stored in Asgard's armory and eventually taken up by Thor long before he obtained Mjolnir.
你可以简称它为 —— JB。
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io.izzel.taboolib.gradle.BUKKIT
import io.izzel.taboolib.gradle.UNIVERSAL
import io.izzel.taboolib.gradle.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -11,16 +10,17 @@ plugins {
taboolib {
env {
// 安装模块
install(UNIVERSAL, BUKKIT)
install(UNIVERSAL, BUKKIT_ALL, EXPANSION_JEXL, EFFECT, NMS_UTIL)
}
version { taboolib = "6.1.0" }
version { taboolib = "6.1.1-beta3" }
}

repositories {
mavenCentral()
}

dependencies {
taboo("com.flowpowered:flow-math:1.0.3")
compileOnly("ink.ptms.core:v12004:12004:mapped")
compileOnly("ink.ptms.core:v12004:12004:universal")
compileOnly(kotlin("stdlib"))
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
group=io.github.username.project
group=me.asgard.frontier.jarnbjorn
version=1.0.0
kotlin.incremental=true
kotlin.incremental.java=true
Expand Down
Binary file added libs/Adyeshach-2.0.4-api.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "ExamplePlugin"
rootProject.name = "Jarnbjorn"
11 changes: 0 additions & 11 deletions src/main/kotlin/io/github/username/project/ExamplePlugin.kt

This file was deleted.

38 changes: 38 additions & 0 deletions src/main/kotlin/me/asgard/frontier/jarnbjorn/Jarnbjorn.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package me.asgard.frontier.jarnbjorn

import me.asgard.frontier.jarnbjorn.api.event.PluginReloadEvent
import me.asgard.frontier.jarnbjorn.api.template.BladeTemplateManager
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.platform.Plugin
import taboolib.module.configuration.Config
import taboolib.module.configuration.Configuration

object Jarnbjorn : Plugin() {

@Config
lateinit var conf: Configuration
private set

/** 模板管理器 */
lateinit var bladeTemplateManager: BladeTemplateManager

/**
* 重载插件
*/
@Awake(LifeCycle.ACTIVE)
fun reload() {
// 重载前事件
PluginReloadEvent.Pre().call()
conf.reload()
bladeTemplateManager.reload()
// 重载后事件
PluginReloadEvent.Post().call()
}

fun isBladeTemplateManagerInitialized(): Boolean {
return this::bladeTemplateManager.isInitialized
}
}

typealias FrontierCombat = Jarnbjorn
45 changes: 45 additions & 0 deletions src/main/kotlin/me/asgard/frontier/jarnbjorn/api/Permission.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package me.asgard.frontier.jarnbjorn.api

import me.asgard.frontier.jarnbjorn.Jarnbjorn
import org.bukkit.entity.Player
import org.bukkit.permissions.PermissionAttachment
import taboolib.platform.util.bukkitPlugin

fun isPreventAntiCheat(): Boolean {
return Jarnbjorn.conf.getBoolean("prevent-anti-cheat.enable")
}

fun getPreventAntiCheatPermissions(): List<String> {
return Jarnbjorn.conf.getStringList("prevent-anti-cheat.permission")
}

/**
* 临时赋予玩家绕过反作弊的权限
* 防止在一些特殊的伤害动作下被反作弊系统拦截
*/
fun <T> preventAntiCheat(player: Player, runnable: () -> T?): T? {
var r: T? = null
grantPermission(player).run {
try {
r = runnable()
} catch (t: Throwable) {
t.printStackTrace()
}
revokePermission(player, this)
}
return r
}

fun grantPermission(player: Player): PermissionAttachment {
val attachment = player.addAttachment(bukkitPlugin)
if (isPreventAntiCheat()) {
getPreventAntiCheatPermissions().forEach {
attachment.setPermission(it, true)
}
}
return attachment
}

fun revokePermission(player: Player, attachment: PermissionAttachment) {
player.removeAttachment(attachment)
}
129 changes: 129 additions & 0 deletions src/main/kotlin/me/asgard/frontier/jarnbjorn/api/blade/BladePainter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package me.asgard.frontier.jarnbjorn.api.blade

import ink.ptms.adyeshach.core.util.modify
import ink.ptms.adyeshach.core.util.plus
import me.asgard.frontier.jarnbjorn.api.template.BladeTemplate
import org.bukkit.Location
import org.bukkit.Particle
import org.bukkit.entity.Player
import taboolib.common.platform.function.info
import taboolib.common.platform.function.submitAsync
import taboolib.module.effect.createLine
import taboolib.module.effect.createNRankBezierCurve
import taboolib.module.nms.createPacket
import taboolib.module.nms.sendBundlePacket
import taboolib.module.nms.sendBundlePacketBlocking
import taboolib.module.nms.sendPacket
import taboolib.platform.util.onlinePlayers
import taboolib.platform.util.toBukkitLocation
import taboolib.platform.util.toProxyLocation

/**
* Jarnbjorn
* me.asgard.frontier.jarnbjorn.api.blade.BladePainter
*
* @author 坏黑
* @since 2024/3/3 17:50
*/
class BladePainter(val template: BladeTemplate) {

/** 基础位置 */
private val base = template.location.add(0.5, 2.0, 0.5).modify(0f, 0f)

/** 中心点 */
private val mid = template.startPoint.toVector().getMidpoint(template.endPoint.toVector())

/** 路径 */
private val path = Path(template.startPoint.toVector(), template.endPoint.toVector(), mid)

/** 旋转器 */
private val rotator = Rotator(base.toVector(), base.yaw, base.pitch, path)

/** 当前视角 */
private var eyeLocation = base
get() = field.clone()

private var distance = 1.5
private var step = 0.05
private var points = arrayListOf<Location>()
private var packets = arrayListOf<Any>()
private var groupSize = -1

/** 设置坐标 */
fun use(eyeLocation: Location): BladePainter {
this.eyeLocation = eyeLocation
return this
}

/** 设置距离 */
fun distance(distance: Double): BladePainter {
this.distance = distance
return this
}

/** 设置步长 */
fun step(step: Double): BladePainter {
this.step += step
return this
}

/** 绘制曲线 */
fun draw(): BladePainter {
val rotated = rotator.rotate(eyeLocation)
val start = rotated.getStartLocation(base.world!!)
val end = rotated.getEndLocation(base.world!!)
val mid = start.toVector().getMidpoint(end.toVector())
val midLoc = mid.clone().add(mid.clone().subtract(eyeLocation.toVector()).normalize().multiply(distance)).toLocation(base.world!!)
points.clear()
createNRankBezierCurve(listOf(start.toProxyLocation(), midLoc.toProxyLocation(), end.toProxyLocation()), step) { points += it.toBukkitLocation() }.show()
info("draw ${points.size} points")
return this
}

/** 生成粒子包 */
fun build(func: (index: Int, loc: Location) -> Any): BladePainter {
packets.clear()
points.forEachIndexed { index, loc -> packets += func(index, loc) }
return this
}

/** 每组大小 */
fun groupSize(groupSize: Int): BladePainter {
this.groupSize = groupSize
return this
}

/** 发送粒子 */
fun sendTo(player: Player, stayTicks: Int, internal: Long): BladePainter {
submitAsync {
packets.split(groupSize) { _, p ->
player.sendBundlePacketBlocking(p)
Thread.sleep(internal)
}
repeat(stayTicks) {
player.sendBundlePacketBlocking(packets)
Thread.sleep(50)
}
}
return this
}

/**
* 将列表分割为多个列表
*/
internal fun <E> List<E>.split(groupSize: Int, func: (i: Int, el: List<E>) -> Unit) {
if (groupSize == -1) {
func(0, this)
return
}
val size = size
val group = size / groupSize
val remainder = size % groupSize
for (i in 0 until group) {
func(i, subList(i * groupSize, (i + 1) * groupSize))
}
if (remainder != 0) {
func(group, subList(group * groupSize, size))
}
}
}
101 changes: 101 additions & 0 deletions src/main/kotlin/me/asgard/frontier/jarnbjorn/api/blade/Direction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package me.asgard.frontier.jarnbjorn.api.blade

import org.bukkit.util.Vector
import kotlin.math.absoluteValue

/**
* FrontierCombat
* me.asgard.frontier.combat.util.Direction
*
* @author 坏黑
* @since 2023/5/28 21:30
*/
enum class Direction {

/** 自上而下 **/
UP,

/** 自下而上 **/
DOWN,

/** 自左而右 **/
LEFT,

/** 自右而左 **/
RIGHT,

/** 左上到右下 **/
LEFT_UP,

/** 右上到左下 **/
RIGHT_UP,

/** 左下到右上 **/
LEFT_DOWN,

/** 右下到左上 **/
RIGHT_DOWN;

/** 获取反向 **/
fun opposite(): Direction {
return when (this) {
UP -> DOWN
DOWN -> UP
LEFT -> RIGHT
RIGHT -> LEFT
LEFT_UP -> RIGHT_DOWN
RIGHT_UP -> LEFT_DOWN
LEFT_DOWN -> RIGHT_UP
RIGHT_DOWN -> LEFT_UP
}
}

companion object {

/**
* 从字符串获取方向
*/
fun fromString(str: String): Direction? {
return when (str) {
"UP" -> UP
"DOWN" -> DOWN
"LEFT" -> LEFT
"RIGHT" -> RIGHT
"LEFT_UP" -> LEFT_UP
"RIGHT_UP" -> RIGHT_UP
"LEFT_DOWN" -> LEFT_DOWN
"RIGHT_DOWN" -> RIGHT_DOWN
else -> null
}
}

/**
* 获取方向
*/
fun get(start: Vector, end: Vector, center: Vector): Direction {
// 计算差值
val diff = end.clone().subtract(start).normalize()
// 是否自上而下
val isUp = diff.y < 0
// 是否自左到右
val isLeft = (end.x - start.x) * (center.z - start.z) - (center.x - start.x) * (end.z - start.z) > 0

// 是否垂直(差值 0.45)
val isVertical = diff.x.absoluteValue < 0.45 && diff.z.absoluteValue < 0.45
// 是否水平
val isHorizontal = diff.y.absoluteValue < 0.45

// 计算方向
return when {
isVertical && isUp -> UP
isVertical && !isUp -> DOWN
isHorizontal && isLeft -> LEFT
isHorizontal && !isLeft -> RIGHT
isUp && isLeft -> LEFT_UP
isUp && !isLeft -> RIGHT_UP
!isUp && isLeft -> LEFT_DOWN
else -> RIGHT_DOWN
}
}
}
}
Loading

0 comments on commit 72156f0

Please sign in to comment.