Skip to content

Commit 0d25845

Browse files
committed
Permissions improvements
Test build test permissions
1 parent 3f1b0a0 commit 0d25845

19 files changed

+271
-249
lines changed

Diff for: behavior_pack/functions/disable.mcfunction

-1
This file was deleted.

Diff for: behavior_pack/functions/enable.mcfunction

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_all_players_disable
2+
tell @s All players terminal mode is disabled.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_all_players_enable
2+
tell @s All players terminal mode is enabled.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_allow_blocks_enable
2+
tell @s Allow blocks disabled.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_allow_blocks_enable
2+
tell @s Allow blocks enabled.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_allow_entities_disable
2+
tell @s Entities are no longer able to run scripts.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_allow_entities_enable
2+
tell @s Entities are able to run scripts.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_player_enable
2+
tell @s You are able to use terminal, but OP level could be required.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_player_disable
2+
tell @s You are no longer able to use terminal, unless all_players mode is enabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_require_op_disable
2+
tell @s OP level is no longer required for using Terminal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_require_op_enable
2+
tell @s OP level is now required for using Terminal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_disable
2+
tell @s Terminal Disabled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scriptevent con:terminal_enable
2+
tell @s Terminal Enabled

Diff for: behavior_pack/scripts/con-terminal.d.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
export declare enum OutputType {
1+
declare enum OutputType {
22
SyntaxError = 0,
33
Error = 1,
44
Successfull = 2
55
}
6-
export declare enum LogTypes {
7-
log = 0,
8-
error = 1,
9-
warn = 2
10-
}
11-
export declare function TerminalInput<s>(source: s, message: string, scope?: never[], o?: (this: s, type: LogTypes, ...params: any[]) => void): Promise<{
6+
declare function formatView(object: any, viewStyle?: ViewStyle): string;
7+
declare function TerminalInput<s>(source: s, message: string, scope?: never[], console?: any): Promise<{
128
type: OutputType;
139
value: any;
1410
formatView: string;
1511
multicommand: boolean;
1612
startTime: number;
1713
}>;
14+
declare enum ViewStyle {
15+
Primitive = 0,
16+
Short = 1,
17+
Full = 2,
18+
Infinite = 3
19+
}
20+
declare function timeoutsSupported(): Promise<boolean>;
21+
export { OutputType, formatView as FormatView, TerminalInput, timeoutsSupported };

Diff for: behavior_pack/scripts/con-terminal.js

+71-109
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import { system } from "@minecraft/server";
21
const symbolError = Symbol("RunError");
32
const AsyncFunctionConstructor = (async function () { }).constructor;
43
const GeneratorFunctionConstructor = (function* () { }).constructor;
54
const AsyncGeneratorFunctionConstructor = (async function* () { }).constructor;
6-
const runInterval = system.runInterval.bind(system);
7-
const runTimeout = system.runTimeout.bind(system);
8-
const clearRun = system.clearRun.bind(system);
95
const nativeFunction = "{\n [native code]\n}";
106
const safePrototypes = [
117
Object.prototype,
@@ -26,35 +22,41 @@ const MinecraftModules = [
2622
{ module_name: "@minecraft/server-editor", tag: "editor" },
2723
{ module_name: "@minecraft/server-editor-bindings", tag: "bindings" }
2824
];
29-
export var OutputType;
25+
var OutputType;
3026
(function (OutputType) {
3127
OutputType[OutputType["SyntaxError"] = 0] = "SyntaxError";
3228
OutputType[OutputType["Error"] = 1] = "Error";
3329
OutputType[OutputType["Successfull"] = 2] = "Successfull";
3430
})(OutputType || (OutputType = {}));
35-
export var LogTypes;
31+
var LogTypes;
3632
(function (LogTypes) {
3733
LogTypes[LogTypes["log"] = 0] = "log";
3834
LogTypes[LogTypes["error"] = 1] = "error";
3935
LogTypes[LogTypes["warn"] = 2] = "warn";
36+
LogTypes[LogTypes["info"] = 3] = "info";
4037
})(LogTypes || (LogTypes = {}));
41-
const setInterval = (callBack, interval = 0, ...params) => runInterval(() => callBack(...params), interval);
42-
const setTimeout = (callBack, interval = 0, ...params) => runTimeout(() => callBack(...params), interval);
38+
const consoleTamplate = {
39+
log: consoleLike.bind(null, LogTypes.log),
40+
warn: consoleLike.bind(null, LogTypes.warn),
41+
error: consoleLike.bind(null, LogTypes.error),
42+
info: consoleLike.bind(null, LogTypes.info)
43+
};
44+
const runsTemplate = {};
4345
function consoleLike(type, ...texts) {
4446
console.warn(`[Terminal-${LogTypes[type]}]: `, ...texts.map(a => getView[typeof a](ViewStyle.Short, a)));
4547
}
46-
function formatView(type, object) {
47-
return getView[typeof object](ViewStyle.Full, object);
48+
function formatView(object, viewStyle = ViewStyle.Full) {
49+
return getView[typeof object](viewStyle, object);
4850
}
49-
export async function TerminalInput(source, message, scope = [], o = consoleLike) {
50-
const a = await RunCode(message, true, { console: { log: o.bind(source, LogTypes.log), Map, Set, warn: o.bind(source, LogTypes.warn), error: o.bind(source, LogTypes.error) }, print: o.bind(source, LogTypes.log), self: source, setTimeout, setInterval, clearInterval: clearRun, clearTimeout: clearRun }, ...scope);
51+
async function TerminalInput(source, message, scope = [], console = consoleTamplate) {
52+
const a = await RunCode(message, true, { console: { ...console }, print: consoleLike.bind(null, LogTypes.log), self: source }, runsTemplate, ...scope);
5153
const { multicommand, startTime } = a;
5254
if (a.syntaxError)
53-
return { type: OutputType.SyntaxError, value: a.syntaxError, formatView: formatView(OutputType.SyntaxError, a.syntaxError), multicommand, startTime };
55+
return { type: OutputType.SyntaxError, value: a.syntaxError, formatView: formatView(a.syntaxError), multicommand, startTime };
5456
const output = await a.promise;
5557
if (typeof output === "object" && output !== null && symbolError in output)
56-
return { type: OutputType.Error, value: output[symbolError], formatView: formatView(OutputType.Error, output[symbolError]), multicommand, startTime };
57-
return { type: OutputType.Successfull, value: output, formatView: formatView(OutputType.Successfull, output), multicommand, startTime };
58+
return { type: OutputType.Error, value: output[symbolError], formatView: formatView(output[symbolError]), multicommand, startTime };
59+
return { type: OutputType.Successfull, value: output, formatView: formatView(output), multicommand, startTime };
5860
}
5961
async function RunCode(code, useModules = true, ...scopes) {
6062
let func, output = { syntaxError: undefined, promise: undefined, multicommand: false };
@@ -101,6 +103,7 @@ var ViewStyle;
101103
ViewStyle[ViewStyle["Primitive"] = 0] = "Primitive";
102104
ViewStyle[ViewStyle["Short"] = 1] = "Short";
103105
ViewStyle[ViewStyle["Full"] = 2] = "Full";
106+
ViewStyle[ViewStyle["Infinite"] = 3] = "Infinite";
104107
})(ViewStyle || (ViewStyle = {}));
105108
const getView = {
106109
"object"(style, any) {
@@ -133,7 +136,7 @@ const getView = {
133136
return `§7${(typeOf == "Object" || typeOf == '') ? "" : typeOf + " "}{${realKeys.join("§7, ")}${keys.length > 5 ? "§r§7, ..." : "§r§7"}}`;
134137
}
135138
else {
136-
return getView["object"](ViewStyle.Short, any) + "\n" + buildCompoudView([], any, any).join('\n');
139+
return getView["object"](ViewStyle.Short, any) + "\n" + buildCompoudView(style, [], any, any).join('\n');
137140
}
138141
},
139142
"function"(n, any) {
@@ -149,15 +152,15 @@ const getView = {
149152
else if (n === ViewStyle.Primitive)
150153
return "§5§oƒ§r";
151154
else
152-
return getView["object"](ViewStyle.Short, any) + "\n" + buildCompoudView([], any, any, " ", true).join('\n');
155+
return getView["function"](ViewStyle.Short, any) + "\n" + buildCompoudView(n, [], any, any, " ", true).join('\n');
153156
},
154157
"number"(n, any) { return `§3${any.toString()}§r`; },
155158
"bigint"(n, any) { return `§3${any.toString()}§r`; },
156159
"boolean"(n, any) { return `§3${any.toString()}§r`; },
157160
"symbol"(n, any) { return `§7Symbol(${any.description})§r`; },
158161
"undefined"() { return "§7§oundefined§r"; },
159162
"string"(n, any) {
160-
if (n === ViewStyle.Full)
163+
if (n === ViewStyle.Full || n == ViewStyle.Infinite)
161164
return `§3"${any}"§r`;
162165
else if (n === ViewStyle.Short)
163166
return `§3"${any.split('\n')[0]}"§r`;
@@ -167,21 +170,37 @@ const getView = {
167170
}
168171
}
169172
};
170-
function buildCompoudView(array, base, object, offSet = " ", func = false, deepth = 1) {
173+
function buildCompoudView(viewStyle, array, base, object, offSet = " ", func = false, deepth = 1, knownSets = []) {
171174
const off = offSet.repeat(deepth);
172175
const prototype = Object.getPrototypeOf(object);
173176
const descriptors = Object.getOwnPropertyDescriptors(object);
177+
knownSets.push(object);
174178
for (const key of [...Object.getOwnPropertyNames(descriptors), ...Object.getOwnPropertySymbols(descriptors)]) {
175-
const { value, set, get } = descriptors[key];
176-
if (value) {
177-
array.push(`${off}§r${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §r${getView[typeof value](ViewStyle.Short, value)}§r`);
179+
const desc = descriptors[key], { value, set, get } = desc;
180+
if ("value" in desc) {
181+
//@ts-ignore
182+
if (viewStyle != ViewStyle.Infinite || typeof value !== "object")
183+
array.push(`${off}§r${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §r${getView[typeof value](ViewStyle.Short, value)}§r`);
184+
else if (knownSets.includes(value))
185+
array.push(`${off}§r${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §c::Recursive:: §r${getView[typeof value](ViewStyle.Short, value)}§r`);
186+
else {
187+
array.push(`${off}§r${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §r`);
188+
buildCompoudView(viewStyle, array, value, value, offSet, typeof value === "function", deepth + 1, [...knownSets]);
189+
}
178190
}
179191
else {
180192
if (get != undefined) {
181-
let v;
182193
try {
183-
v = get.call(base);
184-
array.push(`${off}§r§7get§r ${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §r${getView[typeof v](ViewStyle.Short, v)}§r`);
194+
const v = get.call(base);
195+
//@ts-ignore
196+
if (viewStyle != ViewStyle.Infinite || typeof v !== "object")
197+
array.push(`${off}§r§7get§r ${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §r${getView[typeof v](ViewStyle.Short, v)}§r`);
198+
else if (knownSets.includes(v))
199+
array.push(`${off}§r§7get§r ${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §c::Recursive:: §r${getView[typeof v](ViewStyle.Short, v)}§r`);
200+
else {
201+
array.push(`${off}§r§7get§r ${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7:§r`);
202+
buildCompoudView(viewStyle, array, v, v, offSet, typeof v === "function", deepth + 1, [...knownSets]);
203+
}
185204
}
186205
catch (error) {
187206
array.push(`${off}§r§7get§r ${typeof key == "string" ? key : getView["symbol"](ViewStyle.Primitive, key)}§7: §o(...)§r`);
@@ -196,94 +215,37 @@ function buildCompoudView(array, base, object, offSet = " ", func = false, deep
196215
if (prototype == null)
197216
return array;
198217
const typOf = getTypeOfObject(prototype);
199-
array.push(`${off}§7[[Prototype]]: ${(typOf == "" ? "Object" : typOf)}§r`);
200-
if (!safePrototypes.includes(prototype))
201-
buildCompoudView(array, base, prototype, offSet, typeof prototype === 'function', deepth + 1);
202-
return array;
203-
}
204-
/*
205-
export function toStringPrimitiveFull(any){
206-
switch (typeof any) {
207-
case 'object':
208-
if(any === null){
209-
return "§7§onull";
210-
}else if (any instanceof Error) {
211-
return `§6${any}\n${any.stack}`;
212-
}else{
213-
const base = any, names = Object.getOwnPropertyNames(base), symbols = Object.getOwnPropertySymbols(base);
214-
const keys = names.filter(a=>(base.__lookupGetter__?.(a) == undefined && base.__lookupSetter__?.(a) == undefined)).map(k=>`§7${k}§r§7: ${toStringPrimitiveShort(base[k])}§r`).concat(symbols.map(s=>`§r${toStringPrimitiveShort(s)}§r§7: ${toStringPrimitiveShort(base[s])}`));
215-
const realKeys = keys.slice(0,5), typeOf = getTypeOfObject(base);
216-
let output = `§7${(typeOf == "Object" || typeOf == '')?"":typeOf + " "}{${realKeys.join("§7, ")}${keys.length>5?"§r§7, ...":"§r§7"}}§r`;
217-
function buildLines(base, offSet = " "){
218-
const prototype = Object.getPrototypeOf(base);
219-
for (const keyName of Object.getOwnPropertyNames(base)) {
220-
let getter = base.__lookupGetter__?.(keyName);
221-
let setter = base.__lookupSetter__?.(keyName);
222-
if(getter == undefined&&setter == undefined){
223-
output += `\n${offSet}§r${keyName}§7: §r${toStringPrimitive(base[keyName])}`;
224-
} else {
225-
if(getter != undefined) output += `\n${offSet}§7get§r ${keyName}§7: (...)`;
226-
if(setter != undefined) output += `\n${offSet}§7set§r ${keyName}§7: (...)`;
227-
}
228-
}
229-
for (const keySymbol of Object.getOwnPropertySymbols(base)){
230-
let getter = base.__lookupGetter__?.(keySymbol);
231-
let setter = base.__lookupSetter__?.(keySymbol);
232-
if(getter == undefined&&setter == undefined){
233-
output += `\n${offSet}§r${toStringPrimitiveShort(keySymbol)}§7: §r${toStringPrimitive(base[keySymbol])}`;
234-
} else {
235-
if(getter != undefined) output += `\n${offSet}§7get§r ${toStringPrimitiveShort(keySymbol)}§7: (...)`;
236-
if(setter != undefined) output += `\n${offSet}§7set§r ${toStringPrimitiveShort(keySymbol)}§7: (...)`;
237-
}
238-
}
239-
if(prototype != null){
240-
const typOf = getTypeOfObject(prototype);
241-
output += `\n${offSet}§r[[Prototype]]§r§7: ` + (typOf==""?"Object":typOf)
242-
if(prototype != Object.prototype && prototype != Array.prototype && prototype != Map.prototype){
243-
buildLines(prototype, offSet + " ");
244-
}
245-
}
246-
}
247-
buildLines(base);
248-
return output;
249-
}
250-
case 'function': return any.toString();
251-
case 'symbol': return `§7Symbol(${any.description})`;
252-
case 'bigint':
253-
case 'number':
254-
case 'boolean': return `§3${any.toString()}§r`;
255-
case 'undefined': return "§7§oundefined";
256-
case 'string': return `§3"${any}"§r`;
257-
default:
258-
break;
218+
if (!safePrototypes.includes(prototype)) {
219+
array.push(`${off}§7[[Prototype]]: ${(typOf == "" ? "Object" : typOf)}§r`);
220+
buildCompoudView(viewStyle, array, base, prototype, offSet, typeof prototype === 'function', deepth + 1, [...knownSets]);
259221
}
222+
else
223+
array.push(`${off}§7[[Prototype]]: ${(typOf == "" ? "Object" : typOf)} §r${getView[typeof prototype](ViewStyle.Short, prototype)}§r`);
224+
return array;
260225
}
261-
export function toStringPrimitive(any: any){
262-
switch (typeof any) {
263-
case 'object':
264-
if(any === null){
265-
return "§7§onull§r";
266-
}else if (any instanceof Error) {
267-
return `§6${any}§r`;
268-
}else{
269-
const base = any, names = Object.getOwnPropertyNames(base), symbols = Object.getOwnPropertySymbols(base);
270-
const keys = names.map(k=>`§7${k}§r§7: ${toStringPrimitiveShort(base[k])}§r`).concat(symbols.map(s=>`§r${toStringPrimitiveShort(s)}§r§7: ${toStringPrimitiveShort(base[s])}`));
271-
const realKeys = keys.slice(0,5), typeOf = getTypeOfObject(base);
272-
return `§7${(typeOf == "Object" || typeOf == '')?"":typeOf + " "}{${realKeys.join("§7, ")}${keys.length>5?"§r§7, ...":"§r§7"}}`;
273-
}
274-
case 'function': return toFunctionString(any);
275-
case 'symbol': return `Symbol(${any.description})`;
276-
case 'bigint':
277-
case 'number':
278-
case 'boolean': return `§3${any.toString()}§r`;
279-
case 'undefined': return "§7§oundefined";
280-
case 'string': return `§6"${any}"§r`;
281-
default:
282-
break;
283-
}
284-
}*/
285226
function getTypeOfObject(obj) { return (obj[Symbol.toStringTag] ?? ((typeof obj === "function" ? obj.name : undefined) ?? ((obj.constructor?.prototype == obj ? obj.constructor?.name : obj.__proto__?.constructor?.name) ?? ""))); }
227+
async function timeoutsInit() {
228+
const a = await import("@minecraft/server").catch(e => null);
229+
if (a === null)
230+
return;
231+
if (a.system?.runTimeout == undefined)
232+
return;
233+
const system = a.system;
234+
const runInterval = system.runInterval.bind(system);
235+
const runTimeout = system.runTimeout.bind(system);
236+
const clearRun = system.clearRun.bind(system);
237+
runsTemplate.setInterval = (callBack, interval = 0, ...params) => runInterval(() => callBack(...params), interval);
238+
runsTemplate.setTimeout = (callBack, interval = 0, ...params) => runTimeout(() => callBack(...params), interval);
239+
runsTemplate.clearInterval = clearRun;
240+
runsTemplate.clearTimeout = clearRun;
241+
}
242+
async function timeoutsSupported() {
243+
const a = await import("@minecraft/server").catch(e => { });
244+
return a?.system?.runTimeout !== undefined;
245+
}
286246
//@ts-ignore
287247
globalThis[Symbol.toStringTag] = 'GlobalThis';
288248
//@ts-ignore
289249
globalThis.console[Symbol.toStringTag] = "Console";
250+
timeoutsInit();
251+
export { OutputType, formatView as FormatView, TerminalInput, timeoutsSupported };

0 commit comments

Comments
 (0)