From af0028527973deb69a0f5f16fbff73fe24bbf9d2 Mon Sep 17 00:00:00 2001 From: PFiS1737 Date: Sun, 14 Jul 2024 16:21:33 +0800 Subject: [PATCH] feat(WrappedPlayer:gamemode): use native api --- src/lib/wrapper/entity/WrappedPlayer.class.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/lib/wrapper/entity/WrappedPlayer.class.ts b/src/lib/wrapper/entity/WrappedPlayer.class.ts index 0510745..0b87ec2 100644 --- a/src/lib/wrapper/entity/WrappedPlayer.class.ts +++ b/src/lib/wrapper/entity/WrappedPlayer.class.ts @@ -1,6 +1,5 @@ -import { GameMode, type ItemStack, type Player } from "@minecraft/server" +import type { GameMode, ItemStack, Player } from "@minecraft/server" -import { Commands } from "../../commands/index" import { EntityContainer } from "../container/index" import { WrappedEntity } from "./WrappedEntity.class" @@ -34,20 +33,13 @@ export class WrappedPlayer extends WrappedEntity { } getGameMode() { - const matches: GameMode[] = [] - each(GameMode, (mode) => { - if (this.testGameMode(mode)) matches.push(mode) - }) - return matches[0] + return this._player.getGameMode() } testGameMode(mode: GameMode) { - const playersUnderMode = this.dimension.getPlayers({ gameMode: mode }) - return playersUnderMode.some((player) => player.id === this.id) + return this.getGameMode() === mode } setGameMode(mode: GameMode) { - if (!Object.values(GameMode).includes(mode)) - throw new TypeError("Unknown gamemode.") - Commands.run(`gamemode ${mode}`, this._player) + this._player.setGameMode(mode) } getMainHandItem() {