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

Commit d740165

Browse files
committed
fix
1 parent ea49c83 commit d740165

File tree

1 file changed

+66
-62
lines changed

1 file changed

+66
-62
lines changed

EntityCounter.js

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -145,76 +145,80 @@ function objectToStr(obj) {
145145
return tmpLi.join('\n');
146146
}
147147

148-
const cmdEntC = mc.newCommand('entc', '查看服务器当前实体数量', PermType.Any);
148+
mc.listen('onServerStarted', () => {
149+
const cmdEntC = mc.newCommand('entc', '查看服务器当前实体数量', PermType.Any);
149150

150-
cmdEntC.optional('targets', ParamType.Actor);
151-
cmdEntC.optional('showAnalytics', ParamType.Bool);
152-
cmdEntC.overload(['showAnalytics', 'targets']);
153-
cmdEntC.setCallback(
154-
(
155-
_,
156-
origin,
157-
out,
158-
/** @type {{targets?:Entity[],showAnalytics?:boolean}} */ res
159-
) => {
160-
let { targets } = res;
161-
const { showAnalytics } = res;
162-
const { player } = origin;
163-
let isSelector = true;
151+
cmdEntC.optional('targets', ParamType.Actor);
152+
cmdEntC.optional('showAnalytics', ParamType.Bool);
153+
cmdEntC.overload(['showAnalytics', 'targets']);
154+
cmdEntC.setCallback(
155+
(
156+
_,
157+
origin,
158+
out,
159+
/** @type {{targets?:Entity[],showAnalytics?:boolean}} */ res
160+
) => {
161+
let { targets } = res;
162+
const { showAnalytics } = res;
163+
const { player } = origin;
164+
let isSelector = true;
164165

165-
if (!targets) {
166-
targets = mc.getAllEntities();
167-
isSelector = false;
168-
}
169-
// if (showAnalytics === undefined) showAnalytics = true;
166+
if (!targets) {
167+
targets = mc.getAllEntities();
168+
isSelector = false;
169+
}
170+
// if (showAnalytics === undefined) showAnalytics = true;
170171

171-
const count = targets.length;
172+
const count = targets.length;
172173

173-
/** @type { { [type: string]: number } } */
174-
const analytic = {};
175-
/** @type { { [type: string]: number } } */
176-
const itemAnalytic = {};
177-
targets.forEach((e) => {
178-
const { type, name } = e;
179-
// @ts-expect-error - type as keyof entityNames
180-
const disName = entityNames[type] || name;
181-
const num = analytic[disName] || 0;
182-
analytic[disName] = num + 1;
174+
/** @type { { [type: string]: number } } */
175+
const analytic = {};
176+
/** @type { { [type: string]: number } } */
177+
const itemAnalytic = {};
178+
targets.forEach((e) => {
179+
const { type, name } = e;
180+
// @ts-expect-error - type as keyof entityNames
181+
const disName = entityNames[type] || name;
182+
const num = analytic[disName] || 0;
183+
analytic[disName] = num + 1;
183184

184-
if (type === 'minecraft:item') {
185-
const itNum = itemAnalytic[name] || 0;
186-
itemAnalytic[name] = itNum + 1;
187-
}
188-
});
185+
if (type === 'minecraft:item') {
186+
const itNum = itemAnalytic[name] || 0;
187+
itemAnalytic[name] = itNum + 1;
188+
}
189+
});
189190

190-
const targetTip = isSelector
191-
? `§d目标选择器§r已选择`
192-
: '§d当前服务器§r已加载';
191+
const targetTip = isSelector
192+
? `§d目标选择器§r已选择`
193+
: '§d当前服务器§r已加载';
193194

194-
let analyticTip = '';
195-
if (count !== 0 && showAnalytics) {
196-
const tmpLi = [
197-
`\n==============\n以下是已统计实体及数量:\n${objectToStr(analytic)}`,
198-
];
199-
if (Object.keys(itemAnalytic).length > 0)
200-
tmpLi.push(
201-
`==============\n在这些实体中,§d掉落物§r的名称与数量:\n` +
202-
`${objectToStr(itemAnalytic)}`
203-
);
204-
analyticTip = tmpLi.join('\n');
205-
}
195+
let analyticTip = '';
196+
if (count !== 0 && showAnalytics) {
197+
const tmpLi = [
198+
`\n==============\n以下是已统计实体及数量:\n${objectToStr(
199+
analytic
200+
)}`,
201+
];
202+
if (Object.keys(itemAnalytic).length > 0)
203+
tmpLi.push(
204+
`==============\n在这些实体中,§d掉落物§r的名称与数量:\n` +
205+
`${objectToStr(itemAnalytic)}`
206+
);
207+
analyticTip = tmpLi.join('\n');
208+
}
206209

207-
const tip = `${targetTip} §l§6${count} §r个实体${analyticTip}`;
208-
if (player && showAnalytics) {
209-
player.sendForm(
210-
mc.newSimpleForm().setTitle('§b实体数量查看').setContent(tip),
211-
() => {}
212-
);
213-
} else {
214-
out.success(`§b[实体数量查看] ${tip}`);
210+
const tip = `${targetTip} §l§6${count} §r个实体${analyticTip}`;
211+
if (player && showAnalytics) {
212+
player.sendForm(
213+
mc.newSimpleForm().setTitle('§b实体数量查看').setContent(tip),
214+
() => {}
215+
);
216+
} else {
217+
out.success(`§b[实体数量查看] ${tip}`);
218+
}
215219
}
216-
}
217-
);
218-
cmdEntC.setup();
220+
);
221+
cmdEntC.setup();
222+
});
219223

220224
ll.registerPlugin('EntityCounter', '实体数量查看', [0, 0, 2], {});

0 commit comments

Comments
 (0)