Skip to content

Commit

Permalink
feat(WrappedPlayer:gamemode): use native api
Browse files Browse the repository at this point in the history
  • Loading branch information
PFiS1737 committed Jul 14, 2024
1 parent 8c1a6ea commit af00285
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/lib/wrapper/entity/WrappedPlayer.class.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit af00285

Please sign in to comment.