Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 06f8735

Browse files
committed
change code style
1 parent 4673acf commit 06f8735

File tree

2 files changed

+71
-72
lines changed

2 files changed

+71
-72
lines changed

NavigationAPI.js

+62-63
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// LiteLoaderScript Dev Helper
33
/// <reference path="../HelperLib/src/index.d.ts"/>
44

5-
const pluginName = 'NavigationAPI';
6-
const exportNamespace = 'NavAPI';
7-
const tasks = new Map();
8-
const { Red, Green, Aqua, White, LightPurple, Clear, MinecoinGold } = Format;
5+
const pluginName = 'NavigationAPI'
6+
const exportNamespace = 'NavAPI'
7+
const tasks = new Map()
8+
const { Red, Green, Aqua, White, LightPurple, Clear, MinecoinGold } = Format
99

1010
/**
1111
* @typedef {Object} FloatPosObject
@@ -25,25 +25,25 @@ const { Red, Green, Aqua, White, LightPurple, Clear, MinecoinGold } = Format;
2525
* @returns {string}
2626
*/
2727
function formatPos(pos) {
28-
const { x, y, z, dimId } = pos;
28+
const { x, y, z, dimId } = pos
2929
const dim = (() => {
3030
switch (dimId) {
3131
case 0:
32-
return '主世界';
32+
return '主世界'
3333
case 1:
34-
return '地狱';
34+
return '地狱'
3535
case 2:
36-
return '末地';
36+
return '末地'
3737
default:
38-
return '未知';
38+
return '未知'
3939
}
40-
})();
40+
})()
4141
return (
4242
`${White}${x.toFixed(0)}, ` +
4343
`${y.toFixed(0)}, ` +
4444
`${z.toFixed(0)}, ` +
4545
`${LightPurple}${dim}`
46-
);
46+
)
4747
}
4848

4949
/**
@@ -53,18 +53,18 @@ function formatPos(pos) {
5353
* @returns {boolean} 是否成功
5454
*/
5555
function clearNavigationTask(xuid) {
56-
const pl = mc.getPlayer(xuid);
57-
const taskId = tasks.get(xuid);
56+
const pl = mc.getPlayer(xuid)
57+
const taskId = tasks.get(xuid)
5858

5959
if (!taskId) {
60-
pl.tell(`${Red}没有导航进行中`);
61-
return false;
60+
pl.tell(`${Red}没有导航进行中`)
61+
return false
6262
}
6363

64-
clearInterval(taskId);
65-
tasks.delete(xuid);
66-
pl.tell(`${Green}本次导航完成~欢迎下次使用~`, 5);
67-
return true;
64+
clearInterval(taskId)
65+
tasks.delete(xuid)
66+
pl.tell(`${Green}本次导航完成~欢迎下次使用~`, 5)
67+
return true
6868
}
6969

7070
/**
@@ -74,7 +74,7 @@ function clearNavigationTask(xuid) {
7474
* @returns {boolean} 玩家导航状态 true为正在导航
7575
*/
7676
function hasNavigationTask(xuid) {
77-
return !!tasks.get(xuid); // to boolean
77+
return !!tasks.get(xuid) // to boolean
7878
}
7979

8080
/**
@@ -85,91 +85,90 @@ function hasNavigationTask(xuid) {
8585
* @returns {boolean} 是否成功
8686
*/
8787
function newNavigationTask(xuid, warp) {
88-
const tmpPl = mc.getPlayer(xuid);
88+
const tmpPl = mc.getPlayer(xuid)
8989

9090
/**
9191
* @param {number} x
9292
* @param {number} z
9393
* @returns {string}
9494
*/
9595
function formatXZPos(x, z) {
96-
return `${Green}${x.toFixed()}, ~, ${z.toFixed()}`;
96+
return `${Green}${x.toFixed()}, ~, ${z.toFixed()}`
9797
}
9898

9999
if (hasNavigationTask(xuid)) {
100-
tmpPl.tell(`${Red}已有导航正在进行中,请先结束`);
101-
return false;
100+
tmpPl.tell(`${Red}已有导航正在进行中,请先结束`)
101+
return false
102102
}
103103

104104
function task() {
105-
const pl = mc.getPlayer(xuid);
105+
const pl = mc.getPlayer(xuid)
106106
const {
107107
pos: { x, y, z, dimid: dimId },
108-
} = pl;
109-
const { pos, name } = warp;
110-
const { x: dx, y: dy, z: dz, dimId: dDim } = pos;
108+
} = pl
109+
const { pos, name } = warp
110+
const { x: dx, y: dy, z: dz, dimId: dDim } = pos
111111
const distance = Math.sqrt(
112-
(x - dx) * (x - dx) + (y - dy) * (y - dy) + (z - dz) * (z - dz)
113-
);
112+
(x - dx) * (x - dx) + (y - dy) * (y - dy) + (z - dz) * (z - dz),
113+
)
114114

115115
let msg =
116116
`${Green}${name}${Clear} | ` +
117-
`${MinecoinGold}目标位置: ${formatPos(pos)}${Clear} | `;
117+
`${MinecoinGold}目标位置: ${formatPos(pos)}${Clear} | `
118118
if (dimId !== dDim) {
119119
msg += (() => {
120-
if (dimId === 2 || dDim === 2) return `${Red}维度不匹配`;
121-
if (dDim === 1)
120+
if (dimId === 2 || dDim === 2) return `${Red}维度不匹配`
121+
if (dDim === 1) {
122122
// warp点在地狱
123-
return `${MinecoinGold}主世界坐标: ${formatXZPos(dx * 8, dz * 8)}`;
124-
if (dDim === 0)
123+
return `${MinecoinGold}主世界坐标: ${formatXZPos(dx * 8, dz * 8)}`
124+
}
125+
if (dDim === 0) {
125126
// warp点在主世界
126-
return `${MinecoinGold}地狱坐标: ${formatXZPos(dx / 8, dz / 8)}`;
127-
return `${Red}非法导航`;
128-
})();
127+
return `${MinecoinGold}地狱坐标: ${formatXZPos(dx / 8, dz / 8)}`
128+
}
129+
return `${Red}非法导航`
130+
})()
129131
} else {
130132
if (distance <= 3) {
131-
clearNavigationTask(pl.xuid);
132-
return;
133+
clearNavigationTask(pl.xuid)
134+
return
133135
}
134136

135137
msg +=
136-
`${MinecoinGold}距离 ${Green}${distance.toFixed(2)} ` +
137-
`${MinecoinGold}方块`;
138+
`${MinecoinGold}距离 ${Green}${distance.toFixed(2)} ` + `${MinecoinGold}方块`
138139
}
139-
pl.tell(msg, 5);
140+
pl.tell(msg, 5)
140141
}
141142

142-
tmpPl.tell(`${Green}开始为您导航~`);
143-
tmpPl.tell(`${Green}开始为您导航~`, 5);
144-
const taskId = setInterval(task, 500);
145-
tasks.set(xuid, taskId);
146-
return true;
143+
tmpPl.tell(`${Green}开始为您导航~`)
144+
tmpPl.tell(`${Green}开始为您导航~`, 5)
145+
const taskId = setInterval(task, 500)
146+
tasks.set(xuid, taskId)
147+
return true
147148
}
148149

149-
mc.listen('onLeft', (pl) => clearNavigationTask(pl.xuid));
150+
mc.listen('onLeft', (pl) => clearNavigationTask(pl.xuid))
150151

151152
mc.listen('onServerStarted', () => {
152-
const cmd = mc.newCommand('stopnav', '停止导航', PermType.Any);
153+
const cmd = mc.newCommand('stopnav', '停止导航', PermType.Any)
153154

154155
cmd.setCallback((_, origin, out) => {
155156
if (!origin.player) {
156-
out.error(
157-
'该指令只能由玩家执行,请使用execute命令模拟目标玩家执行该指令'
158-
);
159-
return false;
157+
out.error('该指令只能由玩家执行,请使用execute命令模拟目标玩家执行该指令')
158+
return false
160159
}
161-
return clearNavigationTask(origin.player.xuid);
162-
});
160+
return clearNavigationTask(origin.player.xuid)
161+
})
163162

164-
cmd.overload();
165-
cmd.setup();
166-
});
163+
cmd.overload()
164+
cmd.setup()
165+
})
167166

168-
ll.exports(newNavigationTask, `${exportNamespace}_newTask`);
169-
ll.exports(clearNavigationTask, `${exportNamespace}_clearTask`);
170-
ll.exports(hasNavigationTask, `${exportNamespace}_hasTask`);
167+
ll.exports(newNavigationTask, `${exportNamespace}_newTask`)
168+
ll.exports(clearNavigationTask, `${exportNamespace}_clearTask`)
169+
ll.exports(hasNavigationTask, `${exportNamespace}_hasTask`)
171170

172171
ll.registerPlugin(pluginName, '导航API', [0, 1, 4], {
173172
Author: 'student_2333',
174173
License: 'Apache-2.0',
175-
});
174+
})

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
// ...
2828
"dependencies": [
2929
{
30-
"name": "NavigationAPI"
31-
}
32-
]
30+
"name": "NavigationAPI",
31+
},
32+
],
3333
}
3434
```
3535

3636
```js
37-
const newNavigationTask = ll.import('NavAPI_newTask');
38-
const clearNavigationTask = ll.import('NavAPI_clearTask');
39-
const hasNavigationTask = ll.import('NavAPI_hasTask');
37+
const newNavigationTask = ll.import('NavAPI_newTask')
38+
const clearNavigationTask = ll.import('NavAPI_clearTask')
39+
const hasNavigationTask = ll.import('NavAPI_hasTask')
4040
```
4141

4242
### 接口定义
@@ -127,16 +127,16 @@ QQ:3076823485
127127

128128
- <details>
129129
<summary>赞助二维码(点击展开)</summary>
130-
130+
131131
![讨饭](https://raw.githubusercontents.com/lgc2333/ShigureBotMenu/master/src/imgs/sponsor.png)
132-
132+
133133
</details>
134134

135135
## 更新日志
136136

137137
### 0.1.4
138138

139-
- 优化actionbar的显示风格,坐标保留整数,统一xyz颜色
139+
- 优化 actionbar 的显示风格,坐标保留整数,统一 xyz 颜色
140140

141141
### 0.1.2
142142

0 commit comments

Comments
 (0)