Skip to content

Commit

Permalink
simPlayers now log out when they die. removed respawn command
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestOfLight committed Dec 19, 2024
1 parent b98a124 commit 2a11a56
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
20 changes: 20 additions & 0 deletions scripts/classes/GameTestManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class GameTestManager {
throw new Error(`[Understudy] GameTestManager has already been started`);
gametest.register(extension.name, this.testName, (test) => {
this.test = test;
this.subscribeToEvents();
this.startPlayerLoop();
}).maxTicks(TEST_MAX_TICKS).structureName(`${extension.name}:${this.testName}`);
this.placeGametestStructure();
Expand Down Expand Up @@ -53,6 +54,25 @@ class GameTestManager {
}, 2);
}

static subscribeToEvents() {
world.afterEvents.entityDie.subscribe((event) => {
if (event.deadEntity.typeId === 'minecraft:player') {
const player = UnderstudyManager.getPlayer(event.deadEntity?.name);
if (player !== undefined) {
this.leaveAction(player);
UnderstudyManager.removePlayer(player);
}
}
});

world.afterEvents.playerGameModeChange.subscribe((event) => {
const player = UnderstudyManager.getPlayer(event.player?.name);
if (player !== undefined) {
player.savePlayerInfo();
}
});
}

static startPlayerLoop() {
system.runInterval(() => {
if (!this.#startupComplete) return;
Expand Down
2 changes: 1 addition & 1 deletion scripts/classes/Understudy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Understudy {
};
world.setDynamicProperty(`${this.name}:playerinfo`, JSON.stringify(dynamicInfo));
this.saveItems();
console.warn(`[Understudy] Player ${this.name} info saved`);
}

loadPlayerInfo() {
Expand Down Expand Up @@ -187,7 +188,6 @@ class Understudy {
gameMode: gameMode
};
this.nextActions.push(actionData);
this.savePlayerInfo(actionData);
}

leave() {
Expand Down
8 changes: 4 additions & 4 deletions scripts/commands/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const commandPlayerCommand = new Command({
{ usage: `player <name> join`, description: `Make a new player join at your location.` },
{ usage: `player <name> leave`, description: `Make a player leave the game.` },
{ usage: `player <name> rejoin`, description: `Make a player rejoin at its last location.` },
{ usage: `player <name> respawn`, description: `Make a player respawn after dying.` },
// { usage: `player <name> respawn`, description: `Make a player respawn after dying.` },
{ usage: `player <name> tp`, description: `Make a player teleport to you.` },
{ usage: `player <name> look [up/down/north/south/east/west/block/entity/me/x y z/pitch yaw]`, description: `Make a player look in specified directions.` },
{ usage: `player <name> move [forward/back/left/right/block/entity/me/x y z]`, description: `Make a player move in specified directions.` },
Expand Down Expand Up @@ -75,9 +75,9 @@ function playerCommand(sender, args) {
case 'rejoin':
rejoinAction(sender, name);
break;
case 'respawn':
respawnAction(sender, name);
break;
// case 'respawn':
// respawnAction(sender, name);
// break;
case 'tp':
tpAction(sender, name);
break;
Expand Down

0 comments on commit 2a11a56

Please sign in to comment.