mbler 0.1.1 → 0.1.3-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/lib/build/base.js +297 -1
- package/lib/build/build-g-config.json +11 -11
- package/lib/build/getModule.js +182 -1
- package/lib/build/index.js +370 -1
- package/lib/build/manifest.build.js +103 -1
- package/lib/build/mcVersion.js +86 -1
- package/lib/build/utils.js +6 -1
- package/lib/code-processor/c-handler-export.js +12 -1
- package/lib/code-processor/index.js +141 -1
- package/lib/code-processor/mtreehandler.js +164 -1
- package/lib/commander/index.js +154 -1
- package/lib/data/includes.json +12 -12
- package/lib/git/clone.js +28 -1
- package/lib/git/index.js +12 -1
- package/lib/git/pull.js +100 -1
- package/lib/lang/__translate.js +93 -1
- package/lib/lang/en.js +128 -1
- package/lib/lang/index.js +78 -1
- package/lib/lang/zh.js +146 -1
- package/lib/loger/colors.js +13 -1
- package/lib/loger/index.js +136 -1
- package/lib/mcx/ast/index.js +11 -1
- package/lib/mcx/ast/prop.js +78 -1
- package/lib/mcx/ast/tag.js +246 -1
- package/lib/mcx/compile-component/lib.js +106 -1
- package/lib/mcx/compile-component/types.js +2 -1
- package/lib/mcx/compile-component/utils.js +26 -1
- package/lib/mcx/compile-mcx/_compile.js +1 -1
- package/lib/mcx/compile-mcx/compile.js +34 -1
- package/lib/mcx/compile-mcx/context.js +19 -1
- package/lib/mcx/compile-mcx/index.js +10 -1
- package/lib/mcx/compile-mcx/mcx/index.js +2 -1
- package/lib/mcx/compile-mcx/mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/template/module.js +42 -1
- package/lib/mcx/compile-mcx/types.js +2 -1
- package/lib/mcx/compile-mcx/utils.node.js +207 -1
- package/lib/mcx/index.js +13 -1
- package/lib/mcx/test/index.js +7 -1
- package/lib/mcx/test.js +21 -1
- package/lib/mcx/types.js +2 -1
- package/lib/mcx/utils.js +86 -1
- package/lib/module-handler/index.js +482 -1
- package/lib/modules/create-game/src/Runner/RunnerManager.js +113 -1
- package/lib/modules/create-game/src/Runner/scriptRunner.js +70 -1
- package/lib/modules/create-game/src/config.js +27 -1
- package/lib/modules/create-game/src/constants.js +19 -1
- package/lib/modules/create-game/src/createGameModule.js +24 -1
- package/lib/modules/create-game/src/gameComponent/common/autoStop.js +38 -1
- package/lib/modules/create-game/src/gameComponent/common/lazyLoader.js +76 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/stopWatch.js +90 -1
- package/lib/modules/create-game/src/gameComponent/common/stopWatch/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/onTimeEvent.js +36 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/tickEvent.js +29 -1
- package/lib/modules/create-game/src/gameComponent/common/timer/timer.js +87 -1
- package/lib/modules/create-game/src/gameComponent/gameComponent.js +53 -1
- package/lib/modules/create-game/src/gameComponent/index.js +31 -1
- package/lib/modules/create-game/src/gameComponent/player/blockInteractionBlocker.js +40 -1
- package/lib/modules/create-game/src/gameComponent/player/entityInteractionBlocker.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/healthIndicator.js +48 -1
- package/lib/modules/create-game/src/gameComponent/player/regionMonitor.js +22 -1
- package/lib/modules/create-game/src/gameComponent/player/respawn.js +59 -1
- package/lib/modules/create-game/src/gameComponent/player/spawnProtector.js +69 -1
- package/lib/modules/create-game/src/gameComponent/region/regionProtecter.js +53 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamChooser.js +71 -1
- package/lib/modules/create-game/src/gameComponent/region/regionTeamCleaner.js +20 -1
- package/lib/modules/create-game/src/gameComponent/view/infoScoreboard.js +77 -1
- package/lib/modules/create-game/src/gameComponent/view/teamScoreboard.js +83 -1
- package/lib/modules/create-game/src/gameContext.js +6 -1
- package/lib/modules/create-game/src/gameEngine.js +139 -1
- package/lib/modules/create-game/src/gameEvent/eventManager.js +108 -1
- package/lib/modules/create-game/src/gameEvent/eventSignal.js +28 -1
- package/lib/modules/create-game/src/gameEvent/events/buttonPush.js +41 -1
- package/lib/modules/create-game/src/gameEvent/events/inSlot.js +77 -1
- package/lib/modules/create-game/src/gameEvent/events/interval.js +51 -1
- package/lib/modules/create-game/src/gameEvent/events/itemUse.js +36 -1
- package/lib/modules/create-game/src/gameEvent/events/onBlock.js +106 -1
- package/lib/modules/create-game/src/gameEvent/events/regionEvents.js +105 -1
- package/lib/modules/create-game/src/gameEvent/events/signClick.js +45 -1
- package/lib/modules/create-game/src/gameEvent/gameEvent.js +54 -1
- package/lib/modules/create-game/src/gameEvent/index.js +20 -1
- package/lib/modules/create-game/src/gameEvent/mapEventSignal.js +101 -1
- package/lib/modules/create-game/src/gameEvent/subscription.js +17 -1
- package/lib/modules/create-game/src/gamePlayer/gamePlayer.js +102 -1
- package/lib/modules/create-game/src/gamePlayer/groupBuilder.js +38 -1
- package/lib/modules/create-game/src/gamePlayer/groupSet.js +96 -1
- package/lib/modules/create-game/src/gamePlayer/index.js +25 -1
- package/lib/modules/create-game/src/gamePlayer/playerGroup.js +145 -1
- package/lib/modules/create-game/src/gamePlayer/playerManager.js +57 -1
- package/lib/modules/create-game/src/gameRegion/gameRegion.js +229 -1
- package/lib/modules/create-game/src/gameRegion/index.js +43 -1
- package/lib/modules/create-game/src/gameRegion/regionHelper.js +79 -1
- package/lib/modules/create-game/src/gameState/common/autoStop.js +39 -1
- package/lib/modules/create-game/src/gameState/gameState.js +169 -1
- package/lib/modules/create-game/src/gameState/index.js +7 -1
- package/lib/modules/create-game/src/gameState/types.js +35 -1
- package/lib/modules/create-game/src/gameStructure/gameStructure.js +36 -1
- package/lib/modules/create-game/src/main.js +86 -1
- package/lib/modules/create-game/src/system/gameCommand.js +107 -1
- package/lib/modules/create-game/src/system/gameManager.js +124 -1
- package/lib/modules/create-game/src/system/globalPlayerManager.js +119 -1
- package/lib/modules/create-game/src/utils/GameError.js +31 -1
- package/lib/modules/create-game/src/utils/algorithm.js +95 -1
- package/lib/modules/create-game/src/utils/chunk.js +63 -1
- package/lib/modules/create-game/src/utils/deferredObject.js +27 -1
- package/lib/modules/create-game/src/utils/duration.js +25 -1
- package/lib/modules/create-game/src/utils/func.js +20 -1
- package/lib/modules/create-game/src/utils/index.js +52 -1
- package/lib/modules/create-game/src/utils/interfaces.js +2 -1
- package/lib/modules/create-game/src/utils/logger.js +47 -1
- package/lib/modules/create-game/src/utils/random.js +76 -1
- package/lib/modules/create-game/src/utils/vanila-data.js +123 -1
- package/lib/modules/create-game/src/utils/vector.js +96 -1
- package/lib/modules/gameLib/src/config.js +134 -1
- package/lib/modules/gameLib/src/data.js +77 -1
- package/lib/modules/gameLib/src/entity.js +256 -1
- package/lib/modules/gameLib/src/event.js +285 -1
- package/lib/modules/gameLib/src/index.js +20 -1
- package/lib/modules/gameLib/src/loger.js +21 -1
- package/lib/modules/gameLib/src/ui.js +209 -1
- package/lib/modules/gameLib/src/utils.js +122 -1
- package/lib/modules/gutils/src/index.js +22 -1
- package/lib/runTemp/File.js +54 -1
- package/lib/runTemp/index.js +137 -1
- package/lib/runTemp/securityFile.js +93 -1
- package/lib/start/addPack.js +3 -1
- package/lib/start/clean.js +84 -1
- package/lib/start/create.js +146 -1
- package/lib/start/dev.js +99 -1
- package/lib/start/getResConfig.js +3 -1
- package/lib/start/incg.js +3 -1
- package/lib/start/index.js +207 -1
- package/lib/start/init.js +125 -1
- package/lib/start/rechce.js +57 -1
- package/lib/start/unaddPack.js +3 -1
- package/lib/start/unincg.js +67 -1
- package/lib/start/version.js +73 -1
- package/lib/utils/index.js +298 -1
- package/lib/uuid/index.js +27 -1
- package/package.json +1 -1
- package/test/script-mbler/behavior/scripts/index.js +0 -5
|
@@ -1 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityInteractionBlocker = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const main_js_1 = require("../../main.js");
|
|
6
|
+
/**
|
|
7
|
+
* 通用实体交互阻止组件
|
|
8
|
+
*/
|
|
9
|
+
class EntityInteractionBlocker extends main_js_1.GameComponent {
|
|
10
|
+
onAttach() {
|
|
11
|
+
if (!this.options)
|
|
12
|
+
return;
|
|
13
|
+
const { groupSet, entityIds, entityComponentTypes, showMessage = true, message, } = this.options;
|
|
14
|
+
this.subscribe(server_1.world.beforeEvents.playerInteractWithEntity, (t) => {
|
|
15
|
+
const { player, target } = t;
|
|
16
|
+
console.log(target.typeId);
|
|
17
|
+
// 1️⃣ 不在限制组内 -> 放行
|
|
18
|
+
if (!groupSet.findById(player.id))
|
|
19
|
+
return;
|
|
20
|
+
// 2️⃣ 若有实体类型限制,且当前实体不在其中 -> 放行
|
|
21
|
+
if (entityIds &&
|
|
22
|
+
entityIds.length > 0 &&
|
|
23
|
+
!entityIds.includes(target.typeId)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// 3️⃣ 若指定组件类型数组,且实体不含任意一个组件 -> 放行
|
|
27
|
+
if (entityComponentTypes && entityComponentTypes.length > 0) {
|
|
28
|
+
const hasComponent = entityComponentTypes.some((type) => {
|
|
29
|
+
try {
|
|
30
|
+
return !!target.getComponent(type);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
if (!hasComponent)
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// 4️⃣ 阻止交互
|
|
40
|
+
t.cancel = true;
|
|
41
|
+
// 5️⃣ 提示
|
|
42
|
+
if (showMessage) {
|
|
43
|
+
server_1.system.run(() => player.onScreenDisplay.setActionBar(message ?? "§c你无法与该实体交互!"));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.EntityInteractionBlocker = EntityInteractionBlocker;
|
|
@@ -1 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayerHealthIndicator = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const main_js_1 = require("../../main.js");
|
|
6
|
+
const index_js_1 = require("../index.js");
|
|
7
|
+
class PlayerHealthIndicator extends index_js_1.GameComponent {
|
|
8
|
+
obj;
|
|
9
|
+
onAttach() {
|
|
10
|
+
if (!this.options)
|
|
11
|
+
return;
|
|
12
|
+
this.subscribe(main_js_1.Game.events.interval, () => this.refresh(), this.options.refreshInterval);
|
|
13
|
+
}
|
|
14
|
+
onDetach() {
|
|
15
|
+
if (this.obj?.isValid) {
|
|
16
|
+
server_1.world.scoreboard.removeObjective(this.obj);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
getObj() {
|
|
20
|
+
if (this.obj && this.obj.isValid)
|
|
21
|
+
return this.obj;
|
|
22
|
+
this.obj =
|
|
23
|
+
server_1.world.scoreboard.getObjective(this.options.scoreBoardName) ??
|
|
24
|
+
server_1.world.scoreboard.addObjective(this.options.scoreBoardName, this.options.displayName);
|
|
25
|
+
return this.obj;
|
|
26
|
+
}
|
|
27
|
+
/**展示 */
|
|
28
|
+
show() {
|
|
29
|
+
const obj = this.getObj();
|
|
30
|
+
server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.BelowName, {
|
|
31
|
+
objective: obj,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**刷新计分板 */
|
|
35
|
+
refresh() {
|
|
36
|
+
const obj = this.getObj();
|
|
37
|
+
server_1.world.getAllPlayers().forEach((p) => {
|
|
38
|
+
if (!p)
|
|
39
|
+
return;
|
|
40
|
+
const comp = p.getComponent(server_1.EntityComponentTypes.Health);
|
|
41
|
+
if (!comp)
|
|
42
|
+
return;
|
|
43
|
+
const cur = comp.currentValue;
|
|
44
|
+
obj.setScore(p, cur);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.PlayerHealthIndicator = PlayerHealthIndicator;
|
|
@@ -1 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlayerRegionMonitor = void 0;
|
|
4
|
+
const main_js_1 = require("../../main.js");
|
|
5
|
+
const gameComponent_js_1 = require("../gameComponent.js");
|
|
6
|
+
/**玩家区域监测 */
|
|
7
|
+
class PlayerRegionMonitor extends gameComponent_js_1.GameComponent {
|
|
8
|
+
onAttach() {
|
|
9
|
+
if (!this.options)
|
|
10
|
+
return;
|
|
11
|
+
this.subscribe(main_js_1.Game.events.interval, () => this.detectOutOfRegionPlayers(), this.options.interval);
|
|
12
|
+
}
|
|
13
|
+
detectOutOfRegionPlayers() {
|
|
14
|
+
const region = this.options.region;
|
|
15
|
+
this.options.groups.forEach((p) => {
|
|
16
|
+
if (!region.isInside(p.player.location)) {
|
|
17
|
+
this.options.onLeave(p);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.PlayerRegionMonitor = PlayerRegionMonitor;
|
|
@@ -1 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RespawnComponent = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const vanila_data_js_1 = require("../../utils/vanila-data.js");
|
|
6
|
+
const index_js_1 = require("../index.js");
|
|
7
|
+
class RespawnComponent extends index_js_1.GameComponent {
|
|
8
|
+
onAttach() {
|
|
9
|
+
if (!this.options)
|
|
10
|
+
return;
|
|
11
|
+
const { onDie, autoBroadcast, buildNameFunc, groupSet, onSpawn, buildMsg, } = this.options;
|
|
12
|
+
this.subscribe(server_1.world.afterEvents.entityDie, (event) => {
|
|
13
|
+
const deadEntity = event.deadEntity;
|
|
14
|
+
if (deadEntity.typeId !== vanila_data_js_1.EntityTypeIds.Player)
|
|
15
|
+
return;
|
|
16
|
+
const result = groupSet.findById(deadEntity.id);
|
|
17
|
+
if (!result)
|
|
18
|
+
return;
|
|
19
|
+
const { player, group } = result;
|
|
20
|
+
// 执行自定义逻辑
|
|
21
|
+
onDie?.(player, group, event.damageSource.damagingEntity);
|
|
22
|
+
// 自动广播消息
|
|
23
|
+
if (autoBroadcast && buildNameFunc) {
|
|
24
|
+
const playerName = buildNameFunc(player, group);
|
|
25
|
+
const killerName = this.getKillerName(event.damageSource.damagingEntity);
|
|
26
|
+
let message;
|
|
27
|
+
if (buildMsg) {
|
|
28
|
+
message = buildMsg(playerName, killerName, player);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
message = killerName
|
|
32
|
+
? `${playerName} §r 被 ${killerName} §r 杀死了`
|
|
33
|
+
: `${playerName} §r 死了`;
|
|
34
|
+
}
|
|
35
|
+
groupSet.sendMessage(message);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (onSpawn) {
|
|
39
|
+
this.subscribe(server_1.world.afterEvents.playerSpawn, (t) => {
|
|
40
|
+
const ans = groupSet.findById(t.player.id);
|
|
41
|
+
if (ans?.player) {
|
|
42
|
+
onSpawn(ans.player, ans.group);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
getKillerName(source) {
|
|
48
|
+
if (!source || source.typeId !== vanila_data_js_1.EntityTypeIds.Player)
|
|
49
|
+
return undefined;
|
|
50
|
+
const result = this.options.groupSet.findById(source.id);
|
|
51
|
+
if (!result)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (this.options.buildNameFunc) {
|
|
54
|
+
return this.options.buildNameFunc(result.player, result.group);
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.RespawnComponent = RespawnComponent;
|
|
@@ -1 +1,69 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpawnPointProtector = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const main_js_1 = require("../../main.js");
|
|
6
|
+
const index_js_1 = require("../../utils/index.js");
|
|
7
|
+
const gameComponent_js_1 = require("../gameComponent.js");
|
|
8
|
+
class SpawnPointProtector extends gameComponent_js_1.GameComponent {
|
|
9
|
+
onAttach() {
|
|
10
|
+
const options = this.options;
|
|
11
|
+
if (!options)
|
|
12
|
+
return;
|
|
13
|
+
// 初始设置玩家重生点
|
|
14
|
+
if (options.autoSetSpawnPoint ?? true) {
|
|
15
|
+
this.setPlayerSpawnPoints();
|
|
16
|
+
}
|
|
17
|
+
// 循环设置重生点 & 保护区域
|
|
18
|
+
const interval = options.protectInterval ?? new index_js_1.Duration(10);
|
|
19
|
+
this.subscribe(main_js_1.Game.events.interval, () => {
|
|
20
|
+
if (options.autoSetSpawnPoint) {
|
|
21
|
+
this.setPlayerSpawnPoints();
|
|
22
|
+
}
|
|
23
|
+
this.protectSpawnAreas();
|
|
24
|
+
}, interval);
|
|
25
|
+
// 出生点保护:拦截方块交互
|
|
26
|
+
const protectedBlock = index_js_1.Vector3Utils.below(options.spawnPoint);
|
|
27
|
+
this.subscribe(server_1.world.beforeEvents.playerInteractWithBlock, (t) => {
|
|
28
|
+
if (index_js_1.Vector3Utils.isEqual(t.block.location, protectedBlock)) {
|
|
29
|
+
t.cancel = true;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** 设置玩家重生点 */
|
|
34
|
+
setPlayerSpawnPoints() {
|
|
35
|
+
const { playerGroup, spawnPoint, dimension } = this.options;
|
|
36
|
+
playerGroup.forEach((p) => {
|
|
37
|
+
p.player.setSpawnPoint({
|
|
38
|
+
dimension,
|
|
39
|
+
...spawnPoint,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** 传送所有玩家到出生点 */
|
|
44
|
+
teleportAllToSpawn() {
|
|
45
|
+
const { playerGroup, spawnPoint, dimension } = this.options;
|
|
46
|
+
playerGroup.forEach((p) => {
|
|
47
|
+
p.player.teleport(spawnPoint, { dimension });
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** 循环保护出生点区域 */
|
|
51
|
+
protectSpawnAreas() {
|
|
52
|
+
const { spawnPoint, dimension, protectRadius } = this.options;
|
|
53
|
+
if (!spawnPoint || !dimension)
|
|
54
|
+
return;
|
|
55
|
+
try {
|
|
56
|
+
const radius = protectRadius ?? { x: 1, y: 1, z: 1 };
|
|
57
|
+
const max = index_js_1.Vector3Utils.add(spawnPoint, radius);
|
|
58
|
+
const min = index_js_1.Vector3Utils.subtract(spawnPoint, {
|
|
59
|
+
x: radius.x,
|
|
60
|
+
y: 0,
|
|
61
|
+
z: radius.z,
|
|
62
|
+
});
|
|
63
|
+
dimension.fillBlocks(new server_1.BlockVolume(max, min), "air");
|
|
64
|
+
dimension.setBlockType(index_js_1.Vector3Utils.below(spawnPoint), "bedrock");
|
|
65
|
+
}
|
|
66
|
+
catch (err) { }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.SpawnPointProtector = SpawnPointProtector;
|
|
@@ -1 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegionProtector = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const gameComponent_js_1 = require("../gameComponent.js");
|
|
6
|
+
class RegionProtector extends gameComponent_js_1.GameComponent {
|
|
7
|
+
onAttach() {
|
|
8
|
+
if (!this.options)
|
|
9
|
+
return;
|
|
10
|
+
// 处理破坏方块
|
|
11
|
+
if (this.options.blockBreakInside || this.options.blockBreakOutside) {
|
|
12
|
+
this.subscribe(server_1.world.beforeEvents.playerBreakBlock, (t) => {
|
|
13
|
+
if (this.options?.groupSet &&
|
|
14
|
+
!this.options.groupSet.has(t.player.id)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.handleBreak(t);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
// 处理方块交互
|
|
21
|
+
if (this.options.blockInteractOutside ||
|
|
22
|
+
this.options.blockInteractInside) {
|
|
23
|
+
this.subscribe(server_1.world.beforeEvents.playerInteractWithBlock, (t) => {
|
|
24
|
+
if (this.options?.groupSet &&
|
|
25
|
+
!this.options.groupSet.has(t.player.id)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.handleInteract(t);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
handleBreak(t) {
|
|
33
|
+
if (this.options.blockBreakInside &&
|
|
34
|
+
this.options.region.isBlockInside(t.block.location)) {
|
|
35
|
+
t.cancel = true;
|
|
36
|
+
}
|
|
37
|
+
else if (this.options.blockBreakOutside &&
|
|
38
|
+
!this.options.region.isBlockInside(t.block.location)) {
|
|
39
|
+
t.cancel = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
handleInteract(t) {
|
|
43
|
+
if (this.options.blockInteractInside &&
|
|
44
|
+
this.options.region.isBlockInside(t.block.location)) {
|
|
45
|
+
t.cancel = true;
|
|
46
|
+
}
|
|
47
|
+
else if (this.options.blockInteractOutside &&
|
|
48
|
+
!this.options.region.isBlockInside(t.block.location)) {
|
|
49
|
+
t.cancel = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.RegionProtector = RegionProtector;
|
|
@@ -1 +1,71 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegionTeamChooser = void 0;
|
|
4
|
+
const regionEvents_js_1 = require("../../gameEvent/events/regionEvents.js");
|
|
5
|
+
const main_js_1 = require("../../main.js");
|
|
6
|
+
const gameComponent_js_1 = require("../gameComponent.js");
|
|
7
|
+
const server_1 = require("@minecraft/server");
|
|
8
|
+
/**区域队伍选择器 */
|
|
9
|
+
class RegionTeamChooser extends gameComponent_js_1.GameComponent {
|
|
10
|
+
onAttach() {
|
|
11
|
+
if (!this.options)
|
|
12
|
+
return;
|
|
13
|
+
this.options.config.forEach((data) => {
|
|
14
|
+
this.subscribe(main_js_1.Game.events.region, (event) => this.handleRegionEvent(event, data), data.region);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
handleRegionEvent(event, data) {
|
|
18
|
+
const gamePlayer = this.state.playerManager.get(event.player);
|
|
19
|
+
if (!gamePlayer.isValid) {
|
|
20
|
+
if (event.player.isValid) {
|
|
21
|
+
event.player.sendMessage("暂时无法进入队伍");
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
switch (event.type) {
|
|
26
|
+
case regionEvents_js_1.RegionEventType.Enter:
|
|
27
|
+
this.handlePlayerEnter(gamePlayer, data);
|
|
28
|
+
break;
|
|
29
|
+
case regionEvents_js_1.RegionEventType.Leave:
|
|
30
|
+
this.handlePlayerLeave(gamePlayer, data);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
handlePlayerEnter(gamePlayer, configData) {
|
|
35
|
+
//不允许旁观者直接返回
|
|
36
|
+
if ((this.options.allowSpectator ?? true) &&
|
|
37
|
+
gamePlayer.player?.getGameMode() == server_1.GameMode.Spectator) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const newTeam = configData.team;
|
|
41
|
+
const alreadyInTeam = newTeam.has(gamePlayer);
|
|
42
|
+
if (configData.onEnter) {
|
|
43
|
+
configData.onEnter(gamePlayer);
|
|
44
|
+
}
|
|
45
|
+
//从所有队伍清除目标玩家
|
|
46
|
+
this.options?.config.forEach((d) => {
|
|
47
|
+
if (d.team !== newTeam) {
|
|
48
|
+
d.team.delete(gamePlayer);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
//添加到新队伍
|
|
52
|
+
newTeam.add(gamePlayer);
|
|
53
|
+
//执行回调
|
|
54
|
+
if (configData.onJoin && !alreadyInTeam) {
|
|
55
|
+
configData.onJoin(gamePlayer);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
handlePlayerLeave(gamePlayer, configData) {
|
|
59
|
+
const shouldRemoveOnLeave = this.options?.removeOnLeave ?? false;
|
|
60
|
+
if (shouldRemoveOnLeave) {
|
|
61
|
+
configData.team.delete(gamePlayer);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
onDetach() {
|
|
65
|
+
super.onDetach();
|
|
66
|
+
if (this.options) {
|
|
67
|
+
this.options.config.forEach((t) => t.team.clearInvalid());
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.RegionTeamChooser = RegionTeamChooser;
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegionTeamCleaner = void 0;
|
|
4
|
+
const regionEvents_js_1 = require("../../gameEvent/events/regionEvents.js");
|
|
5
|
+
const main_js_1 = require("../../main.js");
|
|
6
|
+
const gameComponent_js_1 = require("../gameComponent.js");
|
|
7
|
+
/**玩家离开指定区域时将他从team移除 */
|
|
8
|
+
class RegionTeamCleaner extends gameComponent_js_1.GameComponent {
|
|
9
|
+
onAttach() {
|
|
10
|
+
if (!this.options)
|
|
11
|
+
return;
|
|
12
|
+
this.subscribe(main_js_1.Game.events.region, (t) => {
|
|
13
|
+
if (t.type == regionEvents_js_1.RegionEventType.Leave) {
|
|
14
|
+
this.options?.teams.forEach((team) => team.delete(t.player));
|
|
15
|
+
this.options?.onClean?.(t.player);
|
|
16
|
+
}
|
|
17
|
+
}, this.options.region);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.RegionTeamCleaner = RegionTeamCleaner;
|
|
@@ -1 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InfoScoreboard = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const gameComponent_js_1 = require("../gameComponent.js");
|
|
6
|
+
/**信息侧边栏 */
|
|
7
|
+
class InfoScoreboard extends gameComponent_js_1.GameComponent {
|
|
8
|
+
objective;
|
|
9
|
+
initCode = 48;
|
|
10
|
+
getObj() {
|
|
11
|
+
if (this.objective && this.objective.isValid)
|
|
12
|
+
return this.objective;
|
|
13
|
+
const name = this.options.scoreBoardName;
|
|
14
|
+
this.objective =
|
|
15
|
+
server_1.world.scoreboard.getObjective(name) ??
|
|
16
|
+
server_1.world.scoreboard.addObjective(name, this.options.displayName);
|
|
17
|
+
return this.objective;
|
|
18
|
+
}
|
|
19
|
+
onAttach() {
|
|
20
|
+
if (!this.options) {
|
|
21
|
+
throw new Error("无options");
|
|
22
|
+
}
|
|
23
|
+
if (this.options.showOnAttach) {
|
|
24
|
+
this.show();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
onDetach() {
|
|
28
|
+
if (this.objective?.isValid) {
|
|
29
|
+
server_1.world.scoreboard.removeObjective(this.objective);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**手动显示计分板 */
|
|
33
|
+
show() {
|
|
34
|
+
if (!this.options)
|
|
35
|
+
return;
|
|
36
|
+
server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar, {
|
|
37
|
+
objective: this.getObj(),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**更新计分板内容 */
|
|
41
|
+
updateLines(lines) {
|
|
42
|
+
if (!this.options)
|
|
43
|
+
return;
|
|
44
|
+
const sb = this.getObj();
|
|
45
|
+
const isDisplay = server_1.world.scoreboard.getObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar)
|
|
46
|
+
?.objective.id == sb.id;
|
|
47
|
+
server_1.world.scoreboard.removeObjective(sb);
|
|
48
|
+
//如果不在显示则直接返回
|
|
49
|
+
if (!isDisplay) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.show();
|
|
53
|
+
//预处理
|
|
54
|
+
let blankCode = this.initCode;
|
|
55
|
+
for (let i = 0; i < lines.length; i++) {
|
|
56
|
+
if (lines[i] === "") {
|
|
57
|
+
lines[i] = "§" + String.fromCodePoint(blankCode++);
|
|
58
|
+
}
|
|
59
|
+
lines[i] = " ".repeat(this.options.paddingLeft ?? 0) + lines[i];
|
|
60
|
+
}
|
|
61
|
+
//加上header和footer
|
|
62
|
+
const header = this.options?.header;
|
|
63
|
+
const footer = this.options?.footer;
|
|
64
|
+
if (header) {
|
|
65
|
+
lines.unshift(...header());
|
|
66
|
+
}
|
|
67
|
+
if (footer) {
|
|
68
|
+
lines.push(...footer());
|
|
69
|
+
}
|
|
70
|
+
const sb1 = this.getObj();
|
|
71
|
+
//设置
|
|
72
|
+
for (let i = 0; i < lines.length; i++) {
|
|
73
|
+
sb1.setScore(lines[i], lines.length - i - 1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.InfoScoreboard = InfoScoreboard;
|
|
@@ -1 +1,83 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TeamScoreBoard = void 0;
|
|
4
|
+
const server_1 = require("@minecraft/server");
|
|
5
|
+
const gameComponent_js_1 = require("../gameComponent.js");
|
|
6
|
+
class TeamScoreBoard extends gameComponent_js_1.GameComponent {
|
|
7
|
+
obj;
|
|
8
|
+
lastRefresh = 0;
|
|
9
|
+
onAttach() {
|
|
10
|
+
if (!this.options)
|
|
11
|
+
return;
|
|
12
|
+
this.reset();
|
|
13
|
+
}
|
|
14
|
+
getObj() {
|
|
15
|
+
if (this.obj && this.obj.isValid)
|
|
16
|
+
return this.obj;
|
|
17
|
+
this.obj =
|
|
18
|
+
server_1.world.scoreboard.getObjective(this.options.scoreboardName) ??
|
|
19
|
+
server_1.world.scoreboard.addObjective(this.options.scoreboardName, this.options.displayName);
|
|
20
|
+
return this.obj;
|
|
21
|
+
}
|
|
22
|
+
reset() {
|
|
23
|
+
const obj = this.getObj();
|
|
24
|
+
const isDisplay = server_1.world.scoreboard.getObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar)
|
|
25
|
+
?.objective.id == obj.id;
|
|
26
|
+
server_1.world.scoreboard.removeObjective(obj);
|
|
27
|
+
if (isDisplay) {
|
|
28
|
+
this.show();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**显示 */
|
|
32
|
+
show() {
|
|
33
|
+
if (!this.options)
|
|
34
|
+
return;
|
|
35
|
+
server_1.world.scoreboard.setObjectiveAtDisplaySlot(server_1.DisplaySlotId.Sidebar, {
|
|
36
|
+
objective: this.getObj(),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**刷新选队计分板 */
|
|
40
|
+
refreshScoreBoard() {
|
|
41
|
+
if (!this.options)
|
|
42
|
+
return;
|
|
43
|
+
if (this.lastRefresh == server_1.system.currentTick)
|
|
44
|
+
return;
|
|
45
|
+
//清空计分板
|
|
46
|
+
this.reset();
|
|
47
|
+
//构建计分项
|
|
48
|
+
const scores = [];
|
|
49
|
+
const teams = this.options.teams;
|
|
50
|
+
for (const team of teams) {
|
|
51
|
+
let sortedTeam = team.team.getAll();
|
|
52
|
+
//过滤
|
|
53
|
+
if (team.teamFilter) {
|
|
54
|
+
sortedTeam = sortedTeam.filter(team.teamFilter);
|
|
55
|
+
}
|
|
56
|
+
//排序
|
|
57
|
+
if (team.teamSort) {
|
|
58
|
+
sortedTeam.sort(team.teamSort);
|
|
59
|
+
}
|
|
60
|
+
sortedTeam.forEach((p) => {
|
|
61
|
+
if (!(team.showInvalid ?? false) && !p.isValid) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const text = team.buildName
|
|
65
|
+
? team.buildName(p)
|
|
66
|
+
: (team.prefix ?? "") + p.name;
|
|
67
|
+
scores.push(text);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//设置积分项
|
|
71
|
+
const obj = this.getObj();
|
|
72
|
+
for (let i = 0; i < scores.length; i++) {
|
|
73
|
+
obj.setScore(scores[i], i);
|
|
74
|
+
}
|
|
75
|
+
this.lastRefresh = server_1.system.currentTick;
|
|
76
|
+
}
|
|
77
|
+
onDetach() {
|
|
78
|
+
if (this.obj?.isValid) {
|
|
79
|
+
server_1.world.scoreboard.removeObjective(this.obj);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.TeamScoreBoard = TeamScoreBoard;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GameContext = void 0;
|
|
4
|
+
class GameContext {
|
|
5
|
+
}
|
|
6
|
+
exports.GameContext = GameContext;
|