Skip to content

Commit 3f1b0a0

Browse files
committed
Scope Improved
Add this object as global scoped - world: World - system: System - afterEvents: EfterEvents - beforeEvents: BeforeEvents - systemEvents: SystemEvents
1 parent eb9bfd9 commit 3f1b0a0

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

behavior_pack/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "Terminal with JS prompts by ConMaster2112",
66
"uuid": "4997eb94-8968-4158-864b-74f1999192f7",
77
"version": "1.0.0-beta",
8-
"min_engine_version": [1, 20, 0]
8+
"min_engine_version": [1, 20, 10]
99
},
1010
"modules": [
1111
{
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"dependencies": [
19-
{"module_name": "@minecraft/server","version": "1.3.0-beta"},
19+
{"module_name": "@minecraft/server","version": "1.4.0-beta"},
2020
{"module_name": "@minecraft/server-ui","version": "1.1.0-beta"},
2121
{"module_name": "@minecraft/server-gametest","version": "1.0.0-beta"}
2222
],

behavior_pack/scripts/con-terminal.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export declare enum LogTypes {
88
error = 1,
99
warn = 2
1010
}
11-
export declare function TerminalInput<s>(source: s, message: string, o?: (this: s, type: LogTypes, ...params: any[]) => void): Promise<{
11+
export declare function TerminalInput<s>(source: s, message: string, scope?: never[], o?: (this: s, type: LogTypes, ...params: any[]) => void): Promise<{
1212
type: OutputType;
1313
value: any;
1414
formatView: string;

behavior_pack/scripts/con-terminal.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function consoleLike(type, ...texts) {
4646
function formatView(type, object) {
4747
return getView[typeof object](ViewStyle.Full, object);
4848
}
49-
export async function TerminalInput(source, message, 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 });
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);
5151
const { multicommand, startTime } = a;
5252
if (a.syntaxError)
5353
return { type: OutputType.SyntaxError, value: a.syntaxError, formatView: formatView(OutputType.SyntaxError, a.syntaxError), multicommand, startTime };

behavior_pack/scripts/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ world.beforeEvents.chatSend.subscribe(async (ev) => {
88
if (reg !== null && sender.isOp() && sender.getDynamicProperty(propertyName)) {
99
ev.cancel = true;
1010
const code = message.substring(reg[0].length);
11-
const task = TerminalInput(sender, code).catch(er=>console.error(er,er.stack));
11+
const task = TerminalInput(sender, code,[{system,world,beforeEvents:world.beforeEvents,afterEvents:world.afterEvents,systemEvents:system.events}]).catch(er=>console.error(er,er.stack));
1212
sender.sendMessage(" §l§h> §r§7" + code);
1313
const out = await task;
1414
switch (out.type) {
@@ -20,7 +20,7 @@ world.beforeEvents.chatSend.subscribe(async (ev) => {
2020
return sender.sendMessage(" §l§4> §6" + out.value.message);
2121
case OutputType.Error:
2222
case 1:
23-
return sender.sendMessage(" §l§6< §7" + out.value);
23+
return sender.sendMessage(" §l§6< §7" + out.value);
2424
default:
2525
break;
2626
}

con-terminal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function consoleLike(this: any, type: LogTypes,...texts: any[]): void{
4545
function formatView(type: OutputType, object: any): string{
4646
return getView[typeof object](ViewStyle.Full, object);
4747
}
48-
export async function TerminalInput<s>(source: s, message: string, o:(this: s, type: LogTypes,...params: any[])=>void = consoleLike){
49-
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});
48+
export async function TerminalInput<s>(source: s, message: string, scope = [], o:(this: s, type: LogTypes,...params: any[])=>void = consoleLike){
49+
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);
5050
const {multicommand, startTime} = a;
5151
if(a.syntaxError) return {type: OutputType.SyntaxError, value: a.syntaxError, formatView: formatView(OutputType.SyntaxError, a.syntaxError),multicommand, startTime};
5252
const output = await a.promise;

0 commit comments

Comments
 (0)