Skip to content

Commit dbf75d8

Browse files
committed
Content Update
1 parent ed65acd commit dbf75d8

File tree

12 files changed

+151
-2
lines changed

12 files changed

+151
-2
lines changed
File renamed without changes.

scripts/commands-run/index.ts renamed to scripts/commands/index.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dimension, Entity } from "mojang-minecraft";
1+
import { CommandResult, Dimension, Entity } from "mojang-minecraft";
22

33
/**
44
* Contains a method that lets you run console commands within
@@ -8,7 +8,7 @@ import { Dimension, Entity } from "mojang-minecraft";
88
export class Commands {
99
/**
1010
* @remarks
11-
* Runs a particular command from the context of the server.
11+
* Runs a particular command from the context.
1212
* @param commandString
1313
* Command to run. Note that command strings should not start
1414
* with slash.
@@ -27,4 +27,26 @@ export class Commands {
2727
if (target instanceof Dimension || Entity) return target.runCommand(commandString);
2828
else throw TypeError("Native type conversion failed");
2929
};
30+
31+
/**
32+
* @remarks
33+
* Runs a particular command asynchronously from the context.
34+
* Where possible - and especially for
35+
* long-running operations - you should use runCommandAsync
36+
* over runCommand.
37+
* @param commandString
38+
* Command to run. Note that command strings should not start
39+
* with slash.
40+
* @param target
41+
* Target to be used as context for the command to run
42+
* within.
43+
* @returns
44+
* For commands that return data, returns a CommandResult with
45+
* an indicator of command results.
46+
* @throws This function can throw errors.
47+
*/
48+
static async runAsync(commandString: string, target: Dimension | Entity): Promise<CommandResult> {
49+
if (target instanceof Dimension || Entity) return target.runCommandAsync(commandString);
50+
else throw TypeError("Native type conversion failed");
51+
};
3052
};
File renamed without changes.
File renamed without changes.
File renamed without changes.

scripts/run-command-async/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 JaylyDev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

scripts/run-command-async/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Dimension, Player, Entity } from "mojang-minecraft";
2+
3+
Dimension.prototype.runCommandAsync = async (commandString) => this.runCommand(await commandString);
4+
5+
Player.prototype.runCommandAsync = async (commandString) => this.runCommand(await commandString);
6+
7+
Entity.prototype.runCommandAsync = async (commandString) => this.runCommand(await commandString);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { world } from "mojang-minecraft";
2+
3+
let commands = [
4+
() => world.getDimension("overworld").runCommandAsync("say Dimension native runCommandAsync"),
5+
() => [...world.getPlayers()][0].runCommandAsync("say Player native runCommandAsync"),
6+
() => [...world.getDimension("overworld").getEntities()][0].runCommandAsync("say Entity native runCommandAsync")
7+
];
8+
9+
// native runCommandAsync
10+
for (let command of commands) {
11+
let time = new Date().getTime();
12+
command();
13+
world.getDimension("overworld").runCommand(`say ${new Date().getTime() - time}`);
14+
};
15+
16+
//custom runCommandAsync
17+
import "./index.js";
18+
for (let command of commands) {
19+
let time = new Date().getTime();
20+
command();
21+
world.getDimension("overworld").runCommand(`say ${new Date().getTime() - time}`);
22+
};

utilities/gpm/index.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const https = require("https");
2+
const path = require("path");
3+
const { exit } = require("process");
4+
5+
const API_HOST = "https://api.github.com/repos/";
6+
const REPO_FULL_NAME = "JaylyDev/GametestDB";
7+
const REPO_BRANCH = "main";
8+
const REPO_URL = new URL(`${REPO_FULL_NAME}/git/trees/${REPO_BRANCH}`, API_HOST);
9+
10+
https.get(getRequestOptions(REPO_URL), function (res) {
11+
var body = "";
12+
res.on("data", (chunk) => body += chunk);
13+
res.on("end", function () {
14+
/**
15+
* @type {{path: string, mode: string, type: 'blob' | 'tree', sha: string, size: number, url: string}[]}
16+
*/
17+
const tree = JSON.parse(body).tree;
18+
19+
const SCRIPTS_URL = new URL(tree.find(obj => obj.path === "scripts" && obj.type === "tree").url);
20+
21+
https.get(getRequestOptions(SCRIPTS_URL), function (res) {
22+
var body = "";
23+
res.on("data", (chunk) => body += chunk);
24+
res.on("end", function () {
25+
/**
26+
* @type {{path: string, mode: string, type: 'blob' | 'tree', sha: string, size: number, url: string}[]}
27+
*/
28+
const tree = JSON.parse(body).tree;
29+
const objects = tree.map(obj => obj.path);
30+
const packages = process.argv.slice(3);
31+
32+
if (process.argv[2] == "save" && packages.length > 0) {
33+
for (let package of packages) {
34+
let PackageIndex = objects.findIndex(obj => obj === package);
35+
if (PackageIndex < 0) { console.error(`Package not found: ${package}`); }
36+
else {
37+
console.log(tree[PackageIndex].url);
38+
const packageTreeURL = new URL(tree[PackageIndex].url);
39+
console.warn(`Downloading ${package}...`);
40+
41+
https.get(getRequestOptions(packageTreeURL), function (res) {});
42+
};
43+
}
44+
} else {
45+
console.log("GametestDB Package Manager.\ngpm save <package>");
46+
exit(1);
47+
};
48+
});
49+
});
50+
});
51+
});
52+
53+
/**
54+
*
55+
* @param {URL} url
56+
* @returns {{ host: string, path: string, method: string, headers: object }}
57+
*/
58+
function getRequestOptions (url) {
59+
return {
60+
host: url.host,
61+
path: url.pathname,
62+
method: "GET",
63+
headers: { accept: "*/*", "User-Agent": null }
64+
}
65+
}

utilities/gpm/package.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "package-manager",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}

0 commit comments

Comments
 (0)