Skip to content

Upload generated files for scripts #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions scripts/cps-counter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Script example for ScriptAPI
// Author: Jayly <https://github.com/JaylyDev>
// Project: https://github.com/JaylyDev/ScriptAPI
import { Player, world } from "@minecraft/server";
;
// Using map because typescript doesn't support prototype property declaration properly
const clicks = new Map();
world.afterEvents.entityHitBlock.subscribe(function ({ damagingEntity }) {
if (!(damagingEntity instanceof Player))
return;
const clickInfo = { timestamp: Date.now() };
const playerClicks = clicks.get(damagingEntity) || [];
playerClicks.push(clickInfo);
clicks.set(damagingEntity, playerClicks);
});
world.afterEvents.entityHitEntity.subscribe(function ({ damagingEntity }) {
if (!(damagingEntity instanceof Player))
return;
const clickInfo = { timestamp: Date.now() };
const playerClicks = clicks.get(damagingEntity) || [];
playerClicks.push(clickInfo);
clicks.set(damagingEntity, playerClicks);
});
/**
* Get a player's clicks per second
* @param player
* @returns
*/
export function getPlayerCPS(player) {
const currentTime = Date.now();
const playerClicks = clicks.get(player) || [];
const recentClicks = playerClicks.filter(({ timestamp }) => currentTime - 1000 < timestamp);
clicks.set(player, recentClicks);
return recentClicks.length;
}
;
7 changes: 7 additions & 0 deletions scripts/dimension-entities/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# dimension-entities

## Description
> This README is auto generated, Edit the README so that users know what this package does.

## Credits
These scripts were written by Jayly#1397 on Jayly Discord
6 changes: 3 additions & 3 deletions scripts/editor-fullbright/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Author: Jayly <https://github.com/JaylyDev>
// Project: https://github.com/JaylyDev/ScriptAPI
import { ActionTypes, EditorInputContext, InputModifier, KeyboardKey } from "@minecraft/server-editor";
import { MinecraftEffectTypes } from "@minecraft/server";
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
/**
* Class to enable toggles for full bright in menu in editor mode
*/
Expand All @@ -13,13 +13,13 @@ export class FullbrightToggle {
const enableAction = uiSession.actionManager.createAction({
actionType: ActionTypes.NoArgsAction,
onExecute: () => {
player.addEffect(MinecraftEffectTypes.nightVision, 20000000, { amplifier: 1, showParticles: false });
player.addEffect(MinecraftEffectTypes.NightVision, 20000000, { amplifier: 1, showParticles: false });
},
});
const disableAction = uiSession.actionManager.createAction({
actionType: ActionTypes.NoArgsAction,
onExecute: () => {
player.runCommand("effect @s " + MinecraftEffectTypes.nightVision.getName() + " 0");
player.removeEffect(MinecraftEffectTypes.NightVision);
},
});
// Add actions to menu
Expand Down
6 changes: 4 additions & 2 deletions scripts/minecraft-language/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Script example for ScriptAPI
// Author: bot174 <https://github.com/bot174>
// Project: https://github.com/JaylyDev/ScriptAPI
export const languageKeys = [
"accessibility.disableTTS",
"accessibility.enableTTS",
Expand Down Expand Up @@ -9470,7 +9473,7 @@ export const languageKeys = [
"gathering.info.modal.body.connectFail",
"gathering.connect.title",
];
class MinecraftLanguageKeys {
export class MinecraftLanguageKeys {
}
MinecraftLanguageKeys["accessibility.disableTTS"] = { rawtext: [{ translate: "accessibility.disableTTS", },], };
MinecraftLanguageKeys["accessibility.enableTTS"] = { rawtext: [{ translate: "accessibility.enableTTS", },], };
Expand Down Expand Up @@ -18942,4 +18945,3 @@ MinecraftLanguageKeys["gathering.info.body.liveIsComing"] = { rawtext: [{ transl
MinecraftLanguageKeys["gathering.info.modal.title.connectFail"] = { rawtext: [{ translate: "gathering.info.modal.title.connectFail", },], };
MinecraftLanguageKeys["gathering.info.modal.body.connectFail"] = { rawtext: [{ translate: "gathering.info.modal.body.connectFail", },], };
MinecraftLanguageKeys["gathering.connect.title"] = { rawtext: [{ translate: "gathering.connect.title", },], };
export { MinecraftLanguageKeys };
16 changes: 8 additions & 8 deletions scripts/net-auth/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Script example for ScriptAPI
// Author: JaylyMC <https://github.com/JaylyDev>
// Project: https://github.com/JaylyDev/ScriptAPI
import { http as Http, HttpHeader, HttpRequest, HttpRequestMethod, HttpClient as httpClient } from "@minecraft/server-net";
import { http as __http, HttpHeader, HttpRequest, HttpRequestMethod } from "@minecraft/server-net";
class authoration {
}
authoration.authorized = false;
authoration.url = "http://localhost:14589";
authoration.PERMISSION_DENIED = "Permission Denied: This request is not authorized.";
;
export class HttpClient extends httpClient {
export class HttpClient {
/**
* @remarks
* Performs a simple HTTP get request.
Expand All @@ -20,7 +20,7 @@ export class HttpClient extends httpClient {
async get(uri) {
if (authoration.authorized !== true)
throw Error(authoration.PERMISSION_DENIED);
return await Http.get(uri);
return await __http.get(uri);
}
;
/**
Expand All @@ -35,20 +35,20 @@ export class HttpClient extends httpClient {
async request(config) {
if (authoration.authorized !== true)
throw Error(authoration.PERMISSION_DENIED);
return await Http.request(config);
return await __http.request(config);
}
;
constructor() {
super();
cancelAll(reason) {
http.cancelAll(reason);
}
;
}
;
export async function auth(token) {
const localAuthRequest = new HttpRequest(authoration.url);
localAuthRequest.setMethod(HttpRequestMethod.POST);
localAuthRequest.setMethod(HttpRequestMethod.Post);
localAuthRequest.setHeaders([new HttpHeader("token", token)]);
const response = await Http.request(localAuthRequest);
const response = await __http.request(localAuthRequest);
if (response.status === 200) {
authoration.authorized = true;
return true;
Expand Down
9 changes: 5 additions & 4 deletions scripts/player-velocity-fix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* @author JaylyMC
* @project https://github.com/JaylyDev/GametestDB/
*/
import { Player, MinecraftEntityTypes, MinecraftEffectTypes } from "@minecraft/server";
import { Commands } from "../commands/index.js";
import { Player, MinecraftEntityTypes } from "@minecraft/server";
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
import { Commands } from "commands/index.js";
import { clearInterval, setInterval } from "../timers/index.js";
function trunc(x, decimal) {
let y = 10 ** decimal;
Expand All @@ -31,8 +32,8 @@ export function setVelocity(velocity, player) {
let health = entity.getComponent('health');
let movement = entity.getComponent('movement');
let rideable = entity.getComponent('rideable');
entity.addEffect(MinecraftEffectTypes.invisibility, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
entity.addEffect(MinecraftEffectTypes.resistance, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
entity.addEffect(MinecraftEffectTypes.Invisibility, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
entity.addEffect(MinecraftEffectTypes.Resistance, 0x7fff, { amplifier: 255, showParticles: false }); // makes the entity invisible
entity.applyImpulse(velocity);
let onInterval = setInterval((isEntityMoving) => {
try {
Expand Down
4 changes: 2 additions & 2 deletions scripts/restful/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class REST {
table.data.splice(memberIndex, 1);
const encrypted = table.toRawtext();
// version increment
const version = participant.getScore(this.scoreboard);
const version = this.scoreboard.getScore(participant);
overworld.runCommand(`scoreboard players set ${JSON.stringify(encrypted)} ${JSON.stringify(this.scoreboard.id)} ${version + 1}`);
}
;
Expand Down Expand Up @@ -130,7 +130,7 @@ export class REST {
member.value = parsedOption.value;
const encrypted = table.toRawtext();
// version increment
const version = participant.getScore(this.scoreboard);
const version = this.scoreboard.getScore(participant);
overworld.runCommand(`scoreboard players set ${JSON.stringify(encrypted)} ${JSON.stringify(this.scoreboard.id)} ${version + 1}`);
return version + 1;
}
Expand Down
16 changes: 7 additions & 9 deletions scripts/set-score/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ var ScoreboardAction;
;
/**
* fetch scoreboard objective display
* @internal
* @deprecated Scoreboards Setter APIs Client Sync issue is fixed in 1.20.10
*/
const updateDisplay = (objective) => {
/**
* @type {(keyof typeof DisplaySlotId)[]}
*/
const displaySlots = [DisplaySlotId.belowname, DisplaySlotId.list, DisplaySlotId.sidebar];
const displaySlots = [DisplaySlotId.BelowName, DisplaySlotId.List, DisplaySlotId.Sidebar];
for (const displaySlotId of displaySlots) {
const displaySlot = world.scoreboard.getObjectiveAtDisplaySlot(DisplaySlotId[displaySlotId]);
if (displaySlot?.objective === objective) {
world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.sidebar);
world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.sidebar, displaySlot);
world.scoreboard.clearObjectiveAtDisplaySlot(DisplaySlotId.Sidebar);
world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, displaySlot);
}
}
;
Expand All @@ -47,12 +47,12 @@ const updateDisplay = (objective) => {
* @param {ScoreboardAction} action Decides whether to add, remove, or set score to entity (default = set)
* @param {boolean} fetch Fetch scoreboard objective display (default = true)
*/
function setScore(entity, objectiveId, score, action, fetch = true) {
function setScore(entity, objectiveId, score, action) {
// Check if scoreboard object exist first
const objective = world.scoreboard.getObjective(objectiveId);
if (!objective)
throw new ReferenceError('Scoreboard objective does not exist in world.');
const previousScore = !!entity.scoreboardIdentity ? entity.scoreboardIdentity.getScore(objective) : 0;
const previousScore = !!entity.scoreboardIdentity ? objective.getScore(entity.scoreboardIdentity) : 0;
switch (action) {
case ScoreboardAction.add:
score += previousScore;
Expand All @@ -67,9 +67,7 @@ function setScore(entity, objectiveId, score, action, fetch = true) {
if (!entity.scoreboardIdentity)
entity.runCommand('scoreboard players set @s ' + objective + ' ' + score);
else
entity.scoreboardIdentity.setScore(objective, score);
if (fetch)
updateDisplay(objective);
objective.setScore(entity.scoreboardIdentity, score);
}
;
export { setScore };
5 changes: 3 additions & 2 deletions scripts/spawn-simulated-player/tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { world, MinecraftEffectTypes, MinecraftItemTypes, ItemStack, } from "@minecraft/server";
import { world, MinecraftItemTypes, ItemStack, } from "@minecraft/server";
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
import { SpawnSimulatedPlayer } from "./index.js";
let host = [...world.getPlayers()][0];
SpawnSimulatedPlayer(host, function (simulatedPlayer) {
simulatedPlayer.addEffect(MinecraftEffectTypes.absorption, 1);
simulatedPlayer.addEffect(MinecraftEffectTypes.Absorption, 1);
simulatedPlayer.attack();
simulatedPlayer.dimension.createExplosion(simulatedPlayer.location, 5);
simulatedPlayer.giveItem(new ItemStack(MinecraftItemTypes.acaciaBoat));
Expand Down
12 changes: 6 additions & 6 deletions scripts/ui-wrapper/ActionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export class ActionFormButton {
* Builds a simple player form with buttons that let the player
* take action.
*/
export class ActionFormBuilder extends ActionFormData {
export class ActionFormBuilder {
constructor() {
super(...arguments);
/**
* Buttons of the the modal dialog.
*/
Expand All @@ -28,12 +27,13 @@ export class ActionFormBuilder extends ActionFormData {
return this;
}
show(player) {
const form = new ActionFormData();
if (!!this.titleText)
super.title(this.titleText);
form.title(this.titleText);
if (!!this.bodyText)
super.body(this.bodyText);
this.buttons.forEach(item => super.button(item.text, item.iconPath));
return super.show(player);
form.body(this.bodyText);
this.buttons.forEach(item => form.button(item.text, item.iconPath));
return form.show(player);
}
title(titleText) {
this.titleText = titleText;
Expand Down
14 changes: 7 additions & 7 deletions scripts/ui-wrapper/MessageForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ export class MessageFormButton {
* Builds a simple player form with buttons that let the player
* take action.
*/
export class MessageFormBuilder extends MessageFormData {
export class MessageFormBuilder {
constructor() {
super(...arguments);
this.buttons = [];
}
body(bodyText) {
Expand All @@ -29,15 +28,16 @@ export class MessageFormBuilder extends MessageFormData {
}
show(player) {
const [button1, button2] = this.buttons;
const form = new MessageFormData();
if (!!this.titleText)
super.title(this.titleText);
form.title(this.titleText);
if (!!this.bodyText)
super.body(this.bodyText);
form.body(this.bodyText);
if (!!button1)
super.button1(button1.text);
form.button1(button1.text);
if (!!button2)
super.button2(button2.text);
return super.show(player);
form.button2(button2.text);
return form.show(player);
}
title(titleText) {
this.titleText = titleText;
Expand Down
16 changes: 8 additions & 8 deletions scripts/ui-wrapper/ModalForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ export class ModalFormToggle {
* Used to create a fully customizable pop-up form for a
* player.
*/
export class ModalFormBuilder extends ModalFormData {
export class ModalFormBuilder {
constructor() {
super(...arguments);
/**
* Content of the pop-up form.
*/
Expand All @@ -53,20 +52,21 @@ export class ModalFormBuilder extends ModalFormData {
return this;
}
show(player) {
const form = new ModalFormData();
if (!!this.titleText)
super.title(this.titleText);
form.title(this.titleText);
for (const item of this.content) {
if (item instanceof ModalFormDropdown)
super.dropdown(item.label, item.options, item.defaultValueIndex);
form.dropdown(item.label, item.options, item.defaultValueIndex);
else if (item instanceof ModalFormSlider)
super.slider(item.label, item.minimumValue, item.maximumValue, item.valueStep, item.defaultValue);
form.slider(item.label, item.minimumValue, item.maximumValue, item.valueStep, item.defaultValue);
else if (item instanceof ModalFormTextField)
super.textField(item.label, item.placeholderText, item.defaultValue);
form.textField(item.label, item.placeholderText, item.defaultValue);
else if (item instanceof ModalFormToggle)
super.toggle(item.label, item.defaultValue);
form.toggle(item.label, item.defaultValue);
}
;
return super.show(player);
return form.show(player);
}
slider(label, minimumValue, maximumValue, valueStep = 1, defaultValue) {
this.content.push(new ModalFormSlider(label, minimumValue, maximumValue, valueStep, defaultValue));
Expand Down
3 changes: 1 addition & 2 deletions scripts/vector3-polyfill/Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var _a;
* Contains a description of a vector.
* @implements {Vector3}
*/
class Vector {
export class Vector {
/**
* @remarks
* Creates a new instance of an abstract vector.
Expand Down Expand Up @@ -268,4 +268,3 @@ Vector.up = new _a(0, 1, 0);
* @readonly
*/
Vector.zero = new _a(0, 0, 0);
export { Vector };
3 changes: 1 addition & 2 deletions scripts/vector3-polyfill/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var _a;
/**
* Wrapper class of Vector3
*/
class Vector3 {
export class Vector3 {
/**
* @remarks
* Creates a new instance of a vector.
Expand Down Expand Up @@ -345,4 +345,3 @@ Vector3.up = new _a(0, 1, 0);
* @readonly
*/
Vector3.zero = new _a(0, 0, 0);
export { Vector3 };