-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,102 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = "ExamplePlugin" | ||
rootProject.name = "Jarnbjorn" |
11 changes: 0 additions & 11 deletions
11
src/main/kotlin/io/github/username/project/ExamplePlugin.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
src/main/kotlin/me/asgard/frontier/jarnbjorn/api/Permission.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
129
src/main/kotlin/me/asgard/frontier/jarnbjorn/api/blade/BladePainter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
101
src/main/kotlin/me/asgard/frontier/jarnbjorn/api/blade/Direction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.