This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Lapis256/beta/1.18.20
add gamemode.js
- Loading branch information
Showing
6 changed files
with
80 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { GameMode } from "mojang-minecraft"; | ||
|
||
|
||
class _GameMode { | ||
#checkGameMode(player, mode) { | ||
try { | ||
player.runCommand(`testfor @s[m=${mode}]`); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
isCreative(player) { | ||
return this.#checkGameMode(player, "c"); | ||
} | ||
|
||
isSurvival(player) { | ||
return this.#checkGameMode(player, "s"); | ||
} | ||
|
||
isAdventure(player) { | ||
return this.#checkGameMode(player, "a"); | ||
} | ||
|
||
isDefault(player) { | ||
return this.#checkGameMode(player, "d"); | ||
} | ||
|
||
get(player) { | ||
if(this.isCreative(player)) { | ||
return GameMode.creative; | ||
} | ||
if(this.isSurvival(player)) { | ||
return GameMode.survival; | ||
} | ||
if(this.isAdventure(player)) { | ||
return GameMode.adventure; | ||
} | ||
} | ||
} | ||
|
||
export const Gamemode = new _GameMode(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,24 @@ | ||
import { World } from "mojang-minecraft"; | ||
import { Command } from "./command.js"; | ||
import { Tag } from "./tag.js"; | ||
import { mergeObject } from "./object.js"; | ||
import { range } from "./utils/index.js"; | ||
|
||
|
||
export class Player { | ||
#player; | ||
#tagSelector; | ||
#inventory; | ||
|
||
constructor(player) { | ||
mergeObject(this, player); | ||
|
||
this.#player = player; | ||
this.player = player; | ||
this.#tagSelector = Command.selectorBuilder(player.name); | ||
|
||
this.#inventory = player.getComponent("inventory").container; | ||
} | ||
|
||
static getAll() { | ||
return World.getPlayers().map(p => new Player(p)); | ||
} | ||
|
||
get items() { | ||
return range(this.#inventory.size) | ||
.map(i => this.#inventory.getItem(i)); | ||
} | ||
|
||
getAllTags() { | ||
return Tag.getAllTags(this.#tagSelector); | ||
} | ||
|
||
hasTag(tag) { | ||
return Tag.hasTag(this.#tagSelector, tag); | ||
} | ||
|
||
addTag(tag) { | ||
return Tag.addTag(this.#tagSelector, tag); | ||
} | ||
|
||
removeAllTags() { | ||
return Tag.removeAllTags(this.#tagSelector); | ||
} | ||
|
||
removeTag(tag) { | ||
return Tag.removeTag(this.#tagSelector, tag); | ||
} | ||
|
||
toString() { | ||
return this.name; | ||
} | ||
} | ||
import { RawTextBuilder } from "./rawTextBuilder/index.js"; | ||
|
||
|
||
export class Player { | ||
#player; | ||
|
||
constructor(player) { | ||
this.#player = player; | ||
} | ||
|
||
sendRawtext(text, ..._with) { | ||
const rawText = new RawTextBuilder() | ||
.addTranslate(text, ..._with.map(String)) | ||
.buildJson(); | ||
this.#player.runCommand("tellraw @s " + rawText); | ||
} | ||
|
||
showRawtext(text, ..._with) { | ||
const rawText = new RawTextBuilder() | ||
.addTranslate(text, ..._with.map(String)) | ||
.buildJson(); | ||
this.#player.runCommand("titleraw @s actionbar " + rawText); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// export * from "./object.js"; | ||
// export * from "./range.js"; | ||
export * from "./array.js"; | ||
// export * from "./print.js"; | ||
export * from "./options.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Player } from "../player.js"; | ||
|
||
|
||
export function showMessage(player, text, ..._with) { | ||
new Player(player).showMessage(text, ..._with); | ||
} | ||
|
||
export function showActionbar(player, text, ..._with) { | ||
new Player(player).showActionbar(text, ..._with); | ||
} |