Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from Lapis256/beta/1.18.20
Browse files Browse the repository at this point in the history
add gamemode.js
  • Loading branch information
Lapis256 authored Jan 29, 2022
2 parents 1675093 + 2b65de8 commit a4e73fe
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 98 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import "./src/commandInitializer.js";
export * from "./src/utils/index.js";
export * from "./src/debug/index.js";
export { Tick } from "./src/tick.js";
// export { Player } from "./src/player.js";
export { Command } from "./src/command.js";
export { Dimension } from "./src/dimension.js";
export { Gamemode } from "./src/gamemode.js";
export { RawTextBuilder } from "./src/rawTextBuilder/index.js";
43 changes: 43 additions & 0 deletions src/gamemode.js
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();
79 changes: 24 additions & 55 deletions src/player.js
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);
}
}
43 changes: 0 additions & 43 deletions src/tag.js

This file was deleted.

1 change: 1 addition & 0 deletions src/utils/index.js
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";
10 changes: 10 additions & 0 deletions src/utils/print.js
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);
}

0 comments on commit a4e73fe

Please sign in to comment.