Skip to content

Commit 8cac6ad

Browse files
authored
Upload generated files for scripts (JaylyDev#245)
1 parent f770983 commit 8cac6ad

File tree

14 files changed

+98
-55
lines changed

14 files changed

+98
-55
lines changed

scripts/cps-counter/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Script example for ScriptAPI
2+
// Author: Jayly <https://github.com/JaylyDev>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
import { Player, world } from "@minecraft/server";
5+
;
6+
// Using map because typescript doesn't support prototype property declaration properly
7+
const clicks = new Map();
8+
world.afterEvents.entityHitBlock.subscribe(function ({ damagingEntity }) {
9+
if (!(damagingEntity instanceof Player))
10+
return;
11+
const clickInfo = { timestamp: Date.now() };
12+
const playerClicks = clicks.get(damagingEntity) || [];
13+
playerClicks.push(clickInfo);
14+
clicks.set(damagingEntity, playerClicks);
15+
});
16+
world.afterEvents.entityHitEntity.subscribe(function ({ damagingEntity }) {
17+
if (!(damagingEntity instanceof Player))
18+
return;
19+
const clickInfo = { timestamp: Date.now() };
20+
const playerClicks = clicks.get(damagingEntity) || [];
21+
playerClicks.push(clickInfo);
22+
clicks.set(damagingEntity, playerClicks);
23+
});
24+
/**
25+
* Get a player's clicks per second
26+
* @param player
27+
* @returns
28+
*/
29+
export function getPlayerCPS(player) {
30+
const currentTime = Date.now();
31+
const playerClicks = clicks.get(player) || [];
32+
const recentClicks = playerClicks.filter(({ timestamp }) => currentTime - 1000 < timestamp);
33+
clicks.set(player, recentClicks);
34+
return recentClicks.length;
35+
}
36+
;

scripts/dimension-entities/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# dimension-entities
2+
3+
## Description
4+
> This README is auto generated, Edit the README so that users know what this package does.
5+
6+
## Credits
7+
These scripts were written by Jayly#1397 on Jayly Discord

scripts/editor-fullbright/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Author: Jayly <https://github.com/JaylyDev>
33
// Project: https://github.com/JaylyDev/ScriptAPI
44
import { ActionTypes, EditorInputContext, InputModifier, KeyboardKey } from "@minecraft/server-editor";
5-
import { MinecraftEffectTypes } from "@minecraft/server";
5+
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
66
/**
77
* Class to enable toggles for full bright in menu in editor mode
88
*/
@@ -13,13 +13,13 @@ export class FullbrightToggle {
1313
const enableAction = uiSession.actionManager.createAction({
1414
actionType: ActionTypes.NoArgsAction,
1515
onExecute: () => {
16-
player.addEffect(MinecraftEffectTypes.nightVision, 20000000, { amplifier: 1, showParticles: false });
16+
player.addEffect(MinecraftEffectTypes.NightVision, 20000000, { amplifier: 1, showParticles: false });
1717
},
1818
});
1919
const disableAction = uiSession.actionManager.createAction({
2020
actionType: ActionTypes.NoArgsAction,
2121
onExecute: () => {
22-
player.runCommand("effect @s " + MinecraftEffectTypes.nightVision.getName() + " 0");
22+
player.removeEffect(MinecraftEffectTypes.NightVision);
2323
},
2424
});
2525
// Add actions to menu

scripts/minecraft-language/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Script example for ScriptAPI
2+
// Author: bot174 <https://github.com/bot174>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
14
export const languageKeys = [
25
"accessibility.disableTTS",
36
"accessibility.enableTTS",
@@ -9470,7 +9473,7 @@ export const languageKeys = [
94709473
"gathering.info.modal.body.connectFail",
94719474
"gathering.connect.title",
94729475
];
9473-
class MinecraftLanguageKeys {
9476+
export class MinecraftLanguageKeys {
94749477
}
94759478
MinecraftLanguageKeys["accessibility.disableTTS"] = { rawtext: [{ translate: "accessibility.disableTTS", },], };
94769479
MinecraftLanguageKeys["accessibility.enableTTS"] = { rawtext: [{ translate: "accessibility.enableTTS", },], };
@@ -18942,4 +18945,3 @@ MinecraftLanguageKeys["gathering.info.body.liveIsComing"] = { rawtext: [{ transl
1894218945
MinecraftLanguageKeys["gathering.info.modal.title.connectFail"] = { rawtext: [{ translate: "gathering.info.modal.title.connectFail", },], };
1894318946
MinecraftLanguageKeys["gathering.info.modal.body.connectFail"] = { rawtext: [{ translate: "gathering.info.modal.body.connectFail", },], };
1894418947
MinecraftLanguageKeys["gathering.connect.title"] = { rawtext: [{ translate: "gathering.connect.title", },], };
18945-
export { MinecraftLanguageKeys };

scripts/net-auth/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Script example for ScriptAPI
22
// Author: JaylyMC <https://github.com/JaylyDev>
33
// Project: https://github.com/JaylyDev/ScriptAPI
4-
import { http as Http, HttpHeader, HttpRequest, HttpRequestMethod, HttpClient as httpClient } from "@minecraft/server-net";
4+
import { http as __http, HttpHeader, HttpRequest, HttpRequestMethod } from "@minecraft/server-net";
55
class authoration {
66
}
77
authoration.authorized = false;
88
authoration.url = "http://localhost:14589";
99
authoration.PERMISSION_DENIED = "Permission Denied: This request is not authorized.";
1010
;
11-
export class HttpClient extends httpClient {
11+
export class HttpClient {
1212
/**
1313
* @remarks
1414
* Performs a simple HTTP get request.
@@ -20,7 +20,7 @@ export class HttpClient extends httpClient {
2020
async get(uri) {
2121
if (authoration.authorized !== true)
2222
throw Error(authoration.PERMISSION_DENIED);
23-
return await Http.get(uri);
23+
return await __http.get(uri);
2424
}
2525
;
2626
/**
@@ -35,20 +35,20 @@ export class HttpClient extends httpClient {
3535
async request(config) {
3636
if (authoration.authorized !== true)
3737
throw Error(authoration.PERMISSION_DENIED);
38-
return await Http.request(config);
38+
return await __http.request(config);
3939
}
4040
;
41-
constructor() {
42-
super();
41+
cancelAll(reason) {
42+
http.cancelAll(reason);
4343
}
4444
;
4545
}
4646
;
4747
export async function auth(token) {
4848
const localAuthRequest = new HttpRequest(authoration.url);
49-
localAuthRequest.setMethod(HttpRequestMethod.POST);
49+
localAuthRequest.setMethod(HttpRequestMethod.Post);
5050
localAuthRequest.setHeaders([new HttpHeader("token", token)]);
51-
const response = await Http.request(localAuthRequest);
51+
const response = await __http.request(localAuthRequest);
5252
if (response.status === 200) {
5353
authoration.authorized = true;
5454
return true;

scripts/player-velocity-fix/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* @author JaylyMC
77
* @project https://github.com/JaylyDev/GametestDB/
88
*/
9-
import { Player, MinecraftEntityTypes, MinecraftEffectTypes } from "@minecraft/server";
10-
import { Commands } from "../commands/index.js";
9+
import { Player, MinecraftEntityTypes } from "@minecraft/server";
10+
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
11+
import { Commands } from "commands/index.js";
1112
import { clearInterval, setInterval } from "../timers/index.js";
1213
function trunc(x, decimal) {
1314
let y = 10 ** decimal;
@@ -31,8 +32,8 @@ export function setVelocity(velocity, player) {
3132
let health = entity.getComponent('health');
3233
let movement = entity.getComponent('movement');
3334
let rideable = entity.getComponent('rideable');
34-
entity.addEffect(MinecraftEffectTypes.invisibility, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
35-
entity.addEffect(MinecraftEffectTypes.resistance, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
35+
entity.addEffect(MinecraftEffectTypes.Invisibility, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
36+
entity.addEffect(MinecraftEffectTypes.Resistance, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
3637
entity.applyImpulse(velocity);
3738
let onInterval = setInterval((isEntityMoving) => {
3839
try {

scripts/restful/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class REST {
101101
table.data.splice(memberIndex, 1);
102102
const encrypted = table.toRawtext();
103103
// version increment
104-
const version = participant.getScore(this.scoreboard);
104+
const version = this.scoreboard.getScore(participant);
105105
overworld.runCommand(`scoreboard players set ${JSON.stringify(encrypted)} ${JSON.stringify(this.scoreboard.id)} ${version + 1}`);
106106
}
107107
;
@@ -130,7 +130,7 @@ export class REST {
130130
member.value = parsedOption.value;
131131
const encrypted = table.toRawtext();
132132
// version increment
133-
const version = participant.getScore(this.scoreboard);
133+
const version = this.scoreboard.getScore(participant);
134134
overworld.runCommand(`scoreboard players set ${JSON.stringify(encrypted)} ${JSON.stringify(this.scoreboard.id)} ${version + 1}`);
135135
return version + 1;
136136
}

scripts/set-score/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ var ScoreboardAction;
2323
;
2424
/**
2525
* fetch scoreboard objective display
26-
* @internal
26+
* @deprecated Scoreboards Setter APIs Client Sync issue is fixed in 1.20.10
2727
*/
2828
const updateDisplay = (objective) => {
2929
/**
3030
* @type {(keyof typeof DisplaySlotId)[]}
3131
*/
32-
const displaySlots = [DisplaySlotId.belowname, DisplaySlotId.list, DisplaySlotId.sidebar];
32+
const displaySlots = [DisplaySlotId.BelowName, DisplaySlotId.List, DisplaySlotId.Sidebar];
3333
for (const displaySlotId of displaySlots) {
3434
const displaySlot = world.scoreboard.getObjectiveAtDisplaySlot(DisplaySlotId[displaySlotId]);
3535
if (displaySlot?.objective === objective) {
36-
world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.sidebar);
37-
world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.sidebar, displaySlot);
36+
world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar);
37+
world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, displaySlot);
3838
}
3939
}
4040
;
@@ -47,12 +47,12 @@ const updateDisplay = (objective) => {
4747
* @param {ScoreboardAction} action Decides whether to add, remove, or set score to entity (default = set)
4848
* @param {boolean} fetch Fetch scoreboard objective display (default = true)
4949
*/
50-
function setScore(entity, objectiveId, score, action, fetch = true) {
50+
function setScore(entity, objectiveId, score, action) {
5151
// Check if scoreboard object exist first
5252
const objective = world.scoreboard.getObjective(objectiveId);
5353
if (!objective)
5454
throw new ReferenceError('Scoreboard objective does not exist in world.');
55-
const previousScore = !!entity.scoreboardIdentity ? entity.scoreboardIdentity.getScore(objective) : 0;
55+
const previousScore = !!entity.scoreboardIdentity ? objective.getScore(entity.scoreboardIdentity) : 0;
5656
switch (action) {
5757
case ScoreboardAction.add:
5858
score += previousScore;
@@ -67,9 +67,7 @@ function setScore(entity, objectiveId, score, action, fetch = true) {
6767
if (!entity.scoreboardIdentity)
6868
entity.runCommand('scoreboard players set @s ' + objective + ' ' + score);
6969
else
70-
entity.scoreboardIdentity.setScore(objective, score);
71-
if (fetch)
72-
updateDisplay(objective);
70+
objective.setScore(entity.scoreboardIdentity, score);
7371
}
7472
;
7573
export { setScore };

scripts/spawn-simulated-player/tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { world, MinecraftEffectTypes, MinecraftItemTypes, ItemStack, } from "@minecraft/server";
1+
import { world, MinecraftItemTypes, ItemStack, } from "@minecraft/server";
2+
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
23
import { SpawnSimulatedPlayer } from "./index.js";
34
let host = [...world.getPlayers()][0];
45
SpawnSimulatedPlayer(host, function (simulatedPlayer) {
5-
simulatedPlayer.addEffect(MinecraftEffectTypes.absorption, 1);
6+
simulatedPlayer.addEffect(MinecraftEffectTypes.Absorption, 1);
67
simulatedPlayer.attack();
78
simulatedPlayer.dimension.createExplosion(simulatedPlayer.location, 5);
89
simulatedPlayer.giveItem(new ItemStack(MinecraftItemTypes.acaciaBoat));

scripts/ui-wrapper/ActionForm.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ export class ActionFormButton {
1111
* Builds a simple player form with buttons that let the player
1212
* take action.
1313
*/
14-
export class ActionFormBuilder extends ActionFormData {
14+
export class ActionFormBuilder {
1515
constructor() {
16-
super(...arguments);
1716
/**
1817
* Buttons of the the modal dialog.
1918
*/
@@ -28,12 +27,13 @@ export class ActionFormBuilder extends ActionFormData {
2827
return this;
2928
}
3029
show(player) {
30+
const form = new ActionFormData();
3131
if (!!this.titleText)
32-
super.title(this.titleText);
32+
form.title(this.titleText);
3333
if (!!this.bodyText)
34-
super.body(this.bodyText);
35-
this.buttons.forEach(item => super.button(item.text, item.iconPath));
36-
return super.show(player);
34+
form.body(this.bodyText);
35+
this.buttons.forEach(item => form.button(item.text, item.iconPath));
36+
return form.show(player);
3737
}
3838
title(titleText) {
3939
this.titleText = titleText;

scripts/ui-wrapper/MessageForm.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ export class MessageFormButton {
1010
* Builds a simple player form with buttons that let the player
1111
* take action.
1212
*/
13-
export class MessageFormBuilder extends MessageFormData {
13+
export class MessageFormBuilder {
1414
constructor() {
15-
super(...arguments);
1615
this.buttons = [];
1716
}
1817
body(bodyText) {
@@ -29,15 +28,16 @@ export class MessageFormBuilder extends MessageFormData {
2928
}
3029
show(player) {
3130
const [button1, button2] = this.buttons;
31+
const form = new MessageFormData();
3232
if (!!this.titleText)
33-
super.title(this.titleText);
33+
form.title(this.titleText);
3434
if (!!this.bodyText)
35-
super.body(this.bodyText);
35+
form.body(this.bodyText);
3636
if (!!button1)
37-
super.button1(button1.text);
37+
form.button1(button1.text);
3838
if (!!button2)
39-
super.button2(button2.text);
40-
return super.show(player);
39+
form.button2(button2.text);
40+
return form.show(player);
4141
}
4242
title(titleText) {
4343
this.titleText = titleText;

scripts/ui-wrapper/ModalForm.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ export class ModalFormToggle {
4040
* Used to create a fully customizable pop-up form for a
4141
* player.
4242
*/
43-
export class ModalFormBuilder extends ModalFormData {
43+
export class ModalFormBuilder {
4444
constructor() {
45-
super(...arguments);
4645
/**
4746
* Content of the pop-up form.
4847
*/
@@ -53,20 +52,21 @@ export class ModalFormBuilder extends ModalFormData {
5352
return this;
5453
}
5554
show(player) {
55+
const form = new ModalFormData();
5656
if (!!this.titleText)
57-
super.title(this.titleText);
57+
form.title(this.titleText);
5858
for (const item of this.content) {
5959
if (item instanceof ModalFormDropdown)
60-
super.dropdown(item.label, item.options, item.defaultValueIndex);
60+
form.dropdown(item.label, item.options, item.defaultValueIndex);
6161
else if (item instanceof ModalFormSlider)
62-
super.slider(item.label, item.minimumValue, item.maximumValue, item.valueStep, item.defaultValue);
62+
form.slider(item.label, item.minimumValue, item.maximumValue, item.valueStep, item.defaultValue);
6363
else if (item instanceof ModalFormTextField)
64-
super.textField(item.label, item.placeholderText, item.defaultValue);
64+
form.textField(item.label, item.placeholderText, item.defaultValue);
6565
else if (item instanceof ModalFormToggle)
66-
super.toggle(item.label, item.defaultValue);
66+
form.toggle(item.label, item.defaultValue);
6767
}
6868
;
69-
return super.show(player);
69+
return form.show(player);
7070
}
7171
slider(label, minimumValue, maximumValue, valueStep = 1, defaultValue) {
7272
this.content.push(new ModalFormSlider(label, minimumValue, maximumValue, valueStep, defaultValue));

scripts/vector3-polyfill/Vector.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var _a;
33
* Contains a description of a vector.
44
* @implements {Vector3}
55
*/
6-
class Vector {
6+
export class Vector {
77
/**
88
* @remarks
99
* Creates a new instance of an abstract vector.
@@ -268,4 +268,3 @@ Vector.up = new _a(0, 1, 0);
268268
* @readonly
269269
*/
270270
Vector.zero = new _a(0, 0, 0);
271-
export { Vector };

scripts/vector3-polyfill/Vector3.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var _a;
22
/**
33
* Wrapper class of Vector3
44
*/
5-
class Vector3 {
5+
export class Vector3 {
66
/**
77
* @remarks
88
* Creates a new instance of a vector.
@@ -345,4 +345,3 @@ Vector3.up = new _a(0, 1, 0);
345345
* @readonly
346346
*/
347347
Vector3.zero = new _a(0, 0, 0);
348-
export { Vector3 };

0 commit comments

Comments
 (0)