Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Commit 447a0c3

Browse files
committed
Update nms-util
1 parent 191d776 commit 447a0c3

File tree

10 files changed

+324
-9
lines changed

10 files changed

+324
-9
lines changed

source/plugin/module/expansion/command-helper.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
==========
44

55
快速生成你的插件指令帮助。
6+
67
**该模块依赖于:**
78

89
* common

source/plugin/module/expansion/javascript.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ JavaScript
33
============
44

55
将字符串编译为 JavaScript 脚本(基于 Nashorn 引擎)。
6+
67
**该模块依赖于:**
78

89
* common
Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
11
===========
22
译名
3-
===========
3+
===========
4+
5+
关于物品本地化名称的部分工具,具体表现为以下扩展函数:
6+
7+
.. code-block:: kotlin
8+
9+
/**
10+
* 获得物品的名称,如果没有则返回译名
11+
*/
12+
fun ItemStack.getName(player: Player? = null): String {
13+
return if (itemMeta?.hasDisplayName() == true) itemMeta!!.displayName else getI18nName(player)
14+
}
15+
16+
/**
17+
* 获取物品内部名称
18+
*/
19+
fun ItemStack.getInternalKey(): String {
20+
return nmsGeneric.getKey(this)
21+
}
22+
23+
/**
24+
* 获取物品内部名称
25+
*/
26+
fun ItemStack.getInternalName(): String {
27+
return nmsGeneric.getName(this)
28+
}
29+
30+
/**
31+
* 获取物品的本地化名称
32+
*/
33+
fun ItemStack.getI18nName(player: Player? = null): String {
34+
return I18n.instance.getName(player, this)
35+
}
36+
37+
/**
38+
* 获取实体内部名称
39+
*/
40+
fun Entity.getInternalName(): String {
41+
return nmsGeneric.getName(this)
42+
}
43+
44+
/**
45+
* 获取实体本地化名称
46+
*/
47+
fun Entity.getI18nName(player: Player? = null): String {
48+
return I18n.instance.getName(player, this)
49+
}
50+
51+
/**
52+
* 获取附魔内部名称
53+
*/
54+
fun Enchantment.getInternalName(): String {
55+
return nmsGeneric.getEnchantmentKey(this)
56+
}
57+
58+
/**
59+
* 获取附魔本地化名称
60+
*/
61+
fun Enchantment.getI18nName(player: Player? = null): String {
62+
return I18n.instance.getName(player, this)
63+
}
64+
65+
/**
66+
* 获取药水效果内部名称
67+
*/
68+
fun PotionEffectType.getInternalName(): String {
69+
return nmsGeneric.getPotionEffectTypeKey(this)
70+
}
71+
72+
/**
73+
* 获取药水效果本地化名称
74+
*/
75+
fun PotionEffectType.getI18nName(player: Player? = null): String {
76+
return I18n.instance.getName(player, this)
77+
}
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
11
===========
22
光照
3-
===========
3+
===========
4+
5+
关于方块光照的工具,该工具只适用于1.12及以上游戏版本
6+
7+
**具体表现为以下扩展函数:**
8+
9+
.. code-block:: kotlin
10+
11+
/**
12+
* 创建光源
13+
*
14+
* @param lightLevel 光照等级
15+
* @param lightType 光源类型
16+
* @param update 是否更新区块光照
17+
* @param viewers 可见玩家
18+
*/
19+
fun Block.createLight(
20+
lightLevel: Int,
21+
lightType: LightType = LightType.ALL,
22+
update: Boolean = true,
23+
viewers: Collection<Player> = Bukkit.getOnlinePlayers()
24+
): Boolean
25+
26+
/**
27+
* 删除光源
28+
*
29+
* @param lightType 光源类型
30+
* @param update 是否更新区块光照
31+
* @param viewers 可见玩家
32+
*/
33+
fun Block.deleteLight(
34+
lightType: LightType = LightType.ALL,
35+
update: Boolean = true,
36+
viewers: Collection<Player> = Bukkit.getOnlinePlayers(),
37+
): Boolean
Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,127 @@
11
==========
22
地图
3-
==========
3+
==========
4+
5+
关于地图的工具,具体表现为以下扩展函数:
6+
7+
.. code-block:: kotlin
8+
9+
/**
10+
* MAIN 主手
11+
* OFF 副手
12+
*/
13+
enum class Hand {
14+
MAIN, OFF
15+
}
16+
17+
/**
18+
* 将NMSMap发送给玩家
19+
*
20+
* @param player 玩家
21+
*/
22+
fun NMSMap.sendTo(player: Player)
23+
24+
/**
25+
* 构建一个地图
26+
*
27+
* @param url 图片地址
28+
* @param hand 手
29+
* @param width 宽度
30+
* @param height 高度
31+
* @param builder 物品构建器
32+
* @return NMSMap
33+
*/
34+
fun buildMap(
35+
url: String,
36+
hand: NMSMap.Hand = NMSMap.Hand.MAIN,
37+
width: Int = 128,
38+
height: Int = 128,
39+
builder: ItemBuilder.() -> Unit = {}
40+
): NMSMap
41+
42+
/**
43+
* 构建一个地图
44+
*
45+
* @param file 图片文件
46+
* @param hand 手
47+
* @param width 宽度
48+
* @param height 高度
49+
* @param builder 物品构建器
50+
* @return NMSMap
51+
*/
52+
fun buildMap(
53+
file: File,
54+
hand: NMSMap.Hand = NMSMap.Hand.MAIN,
55+
width: Int = 128,
56+
height: Int = 128,
57+
builder: ItemBuilder.() -> Unit = {}
58+
): NMSMap
59+
60+
/**
61+
* 构建一个地图
62+
*
63+
* @param image 缓冲区图像
64+
* @param hand 手
65+
* @param width 宽度
66+
* @param height 高度
67+
* @param builder 物品构建器
68+
* @return NMSMap
69+
*/
70+
fun buildMap(
71+
image: BufferedImage,
72+
hand: NMSMap.Hand = NMSMap.Hand.MAIN,
73+
width: Int = 128,
74+
height: Int = 128,
75+
builder: ItemBuilder.() -> Unit = {}
76+
): NMSMap
77+
78+
/**
79+
* 给玩家构建并发送地图
80+
*
81+
* @param url 图片地址
82+
* @param hand 手
83+
* @param width 宽度
84+
* @param height 高度
85+
* @param builder 物品构建器
86+
*/
87+
fun Player.sendMap(
88+
url: String,
89+
hand: NMSMap.Hand = NMSMap.Hand.MAIN,
90+
width: Int = 128,
91+
height: Int = 128,
92+
builder: ItemBuilder.() -> Unit = {}
93+
)
94+
95+
/**
96+
* 给玩家构建并发送地图
97+
*
98+
* @param file 图片文件
99+
* @param hand 手
100+
* @param width 宽度
101+
* @param height 高度
102+
* @param builder 物品构建器
103+
*/
104+
fun Player.sendMap(
105+
file: File,
106+
hand: NMSMap.Hand = NMSMap.Hand.MAIN,
107+
width: Int = 128,
108+
height: Int = 128,
109+
builder: ItemBuilder.() -> Unit = {}
110+
)
111+
112+
/**
113+
* 给玩家构建并发送地图
114+
*
115+
* @param image 缓冲区图像
116+
* @param hand 手
117+
* @param width 宽度
118+
* @param height 高度
119+
* @param builder 物品构建器
120+
*/
121+
fun Player.sendMap(
122+
image: BufferedImage,
123+
hand: NMSMap.Hand = NMSMap.Hand.MAIN,
124+
width: Int = 128,
125+
height: Int = 128,
126+
builder: ItemBuilder.() -> Unit = {}
127+
)

source/plugin/module/nms-util/nbt.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
.. code-block:: kotlin
1111
1212
/**
13-
* 获取物品的NBT
13+
* 获取物品的NBT数据
1414
*/
1515
fun ItemStack.getItemTag()
1616
1717
/**
18-
* 保存物品的NBT
18+
* 写入物品的NBT数据
1919
*
2020
* @param itemTag NBT
2121
* @return 物品堆
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
==========
22
记分板
3-
==========
3+
==========
4+
5+
关于计分板的部分工具,具体表现为以下扩展函数:
6+
7+
.. code-block:: kotlin
8+
9+
/**
10+
* 发送记分板数据包
11+
*
12+
* @param content 记分板内容(设置为空时注销记分板)
13+
*/
14+
fun Player.sendScoreboard(vararg content: String)
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
==========
22
告示牌捕获
3-
==========
3+
==========
4+
5+
关于告示牌捕获的工具,具体表现为以下扩展函数:
6+
7+
.. code-block:: kotlin
8+
9+
/**
10+
* 捕获玩家在告示牌中输入的内容
11+
*
12+
* @param lines 告示牌内容
13+
* @param function 方法
14+
*/
15+
fun Player.inputSign(lines: Array<String> = arrayOf(), function: (lines: Array<String>) -> Unit)
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
11
==========
22
进度
3-
==========
3+
==========
4+
5+
关于进度的工具,该工具只适用于1.13及以上游戏版本
6+
7+
**具体表现为以下扩展函数:**
8+
9+
.. code-block:: kotlin
10+
11+
/**
12+
* 发送虚拟 Toast 成就信息
13+
*
14+
* @param icon 图标
15+
* @param message 信息
16+
* @param frame 成就框架
17+
* @param background 成就背景图片
18+
*/
19+
fun Player.sendToast(icon: Material, message: String, frame: ToastFrame = ToastFrame.TASK, background: ToastBackground = ToastBackground.ADVENTURE)
20+
21+
/**
22+
* 成就框架枚举
23+
*
24+
* TASK 条目
25+
* GOAL 目标
26+
* CHALLENGE 挑战
27+
*/
28+
enum class ToastFrame {
29+
TASK,GOAL,CHALLENGE
30+
}
31+
32+
/**
33+
* 成就背景图片枚举
34+
*
35+
* @param url 地址
36+
* ADVENTURE 冒险
37+
* END 末地之路
38+
*/
39+
enum class ToastBackground(val url: String) {
40+
ADVENTURE("minecraft:textures/gui/advancements/backgrounds/adventure.png"),
41+
END("minecraft:textures/gui/advancements/backgrounds/end.png")
42+
}
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
==========
22
扩展方法
3-
==========
3+
==========
4+
5+
有关NMS的其它拓展工具,具体表现为以下顶级或扩展函数:**
6+
7+
.. code-block:: kotlin
8+
9+
/**
10+
* 生成实体并在生成之前执行特定行为
11+
*/
12+
fun <T : Entity> Location.spawnEntity(entity: Class<T>, func: Consumer<T>)
13+
14+
/**
15+
* 调整图片分辨率
16+
* 地图最佳显示分辨率为128*128
17+
*
18+
* @parma width 宽度
19+
* @parma height 高度
20+
* @return 缓冲区图像
21+
*/
22+
fun BufferedImage.zoomed(width: Int = 128, height: Int = 128): BufferedImage

0 commit comments

Comments
 (0)