Skip to content

Commit 7400658

Browse files
jayly-botbot174
andauthored
SimpleDB (JaylyDev#159)
* Merge branch 'script-212cb' of https://github.com/joyloy-bot/ScriptAPI into joyloy-bot-script-212cb * Create database.js in script-212cb * Merge branch 'main' to pr/159 Squashed commit of the following: commit 3025751 Author: bot174 <[email protected]> Date: Sun Mar 19 07:38:00 2023 +0000 Update headerChecks.ts commit 7687744 Author: bot174 <[email protected]> Date: Sun Mar 19 07:35:45 2023 +0000 Fix error commit 8dec75f Author: bot174 <[email protected]> Date: Sun Mar 19 07:32:04 2023 +0000 Squashed commit of the following: commit 61e5a27 Author: bot174 <[email protected]> Date: Sun Mar 19 07:31:06 2023 +0000 Fix emitted files not have headers commit 58fb6d3 Merge: dd9c0b7 2e83b7d Author: bot174 <[email protected]> Date: Sun Mar 19 06:59:50 2023 +0000 Merge branch 'main' into patch-157 commit dd9c0b7 Author: bot174 <[email protected]> Date: Sat Mar 18 22:15:17 2023 +0000 Update tsconfig and workflow commit 2e83b7d Author: bot174 <[email protected]> Date: Sat Mar 18 22:30:31 2023 +0000 Update cl.yml commit efa3269 Author: bot174 <[email protected]> Date: Sat Mar 18 22:21:29 2023 +0000 Commit from GitHub Actions (CI) commit 4785b1a Author: bot174 <[email protected]> Date: Sat Mar 18 22:19:59 2023 +0000 Update tsconfig and workflow (JaylyDev#158) commit ff82e8f Author: bot174 <[email protected]> Date: Sat Mar 18 17:05:54 2023 +0000 Upload generated README files as artifacts (JaylyDev#156) * Register readme plugin * Update readme.ts * Update readme.ts * Update readme.ts * Update readme.ts * Update readme.ts * Update readme.ts * Update readme.ts * Add README to 59 packages Add README file to the following packages:\n- another-form\n- anti-32k\n- anti-32k-event\n- anti-nuker\n- beta-tick-event\n- bow-ding\n- calc-player-view-offset\n- calculate-distance\n- chat-command\n- chat-emoji-replacements\n- chat-ranks\n- color\n- command-handle\n- command-handler\n- compass-prompt\n- cps-counter\n- create-shockwave\n- custom-enchantments\n- database\n- delayed-function\n- delete-command-blocks\n- deprecate\n- editor-extensions\n- editor-utilities\n- entity-death-event\n- entity-hit\n- entity-spawner\n- event-listener\n- fill-blocks\n- force-show\n- full-moon\n- gamemode\n- get-gamemode\n- get-item-amount\n- get-level\n- get-score\n- has-lore\n- has-permission\n- intl\n- is-moving\n- is-not-op\n- jayly-task\n- json-stringify\n- kill-death-counter\n- knockback-from-point\n- player-spawn\n- random\n- scoreboard\n- scoreboard-levelup\n- sell-items\n- set-score\n- simulated-player\n- sleep\n- test-score\n- tick-event\n- to-roman-numeral\n- trace-line-evenly-spaced\n- vector3-polyfill\n- world-time * Revert "Add README to 59 packages" This reverts commit 6770322. * Add README to 59 packages Add README file to the following packages: - another-form - anti-32k - anti-32k-event - anti-nuker - beta-tick-event - bow-ding - calc-player-view-offset - calculate-distance - chat-command - chat-emoji-replacements - chat-ranks - color - command-handle - command-handler - compass-prompt - cps-counter - create-shockwave - custom-enchantments - database - delayed-function - delete-command-blocks - deprecate - editor-extensions - editor-utilities - entity-death-event - entity-hit - entity-spawner - event-listener - fill-blocks - force-show - full-moon - gamemode - get-gamemode - get-item-amount - get-level - get-score - has-lore - has-permission - intl - is-moving - is-not-op - jayly-task - json-stringify - kill-death-counter - knockback-from-point - player-spawn - random - scoreboard - scoreboard-levelup - sell-items - set-score - simulated-player - sleep - test-score - tick-event - to-roman-numeral - trace-line-evenly-spaced - vector3-polyfill - world-time * Revert "Add README to 59 packages" This reverts commit ade18a2. * Update readme.ts * Add README to 59 packages Add README file to the following packages: another-form, anti-32k, anti-32k-event, anti-nuker, beta-tick-event, bow-ding, calc-player-view-offset, calculate-distance, chat-command, chat-emoji-replacements, chat-ranks, color, command-handle, command-handler, compass-prompt, cps-counter, create-shockwave, custom-enchantments, database, delayed-function, delete-command-blocks, deprecate, editor-extensions, editor-utilities, entity-death-event, entity-hit, entity-spawner, event-listener, fill-blocks, force-show, full-moon, gamemode, get-gamemode, get-item-amount, get-level, get-score, has-lore, has-permission, intl, is-moving, is-not-op, jayly-task, json-stringify, kill-death-counter, knockback-from-point, player-spawn, random, scoreboard, scoreboard-levelup, sell-items, set-score, simulated-player, sleep, test-score, tick-event, to-roman-numeral, trace-line-evenly-spaced, vector3-polyfill, world-time * Revert "Add README to 59 packages" This reverts commit af185ab. * Add credits and subheadings * Update readme.ts * Add README to 59 packages Add README file to the following packages: another-form, anti-32k, anti-32k-event, anti-nuker, beta-tick-event, bow-ding, calc-player-view-offset, calculate-distance, chat-command, chat-emoji-replacements, chat-ranks, color, command-handle, command-handler, compass-prompt, cps-counter, create-shockwave, custom-enchantments, database, delayed-function, delete-command-blocks, deprecate, editor-extensions, editor-utilities, entity-death-event, entity-hit, entity-spawner, event-listener, fill-blocks, force-show, full-moon, gamemode, get-gamemode, get-item-amount, get-level, get-score, has-lore, has-permission, intl, is-moving, is-not-op, jayly-task, json-stringify, kill-death-counter, knockback-from-point, player-spawn, random, scoreboard, scoreboard-levelup, sell-items, set-score, simulated-player, sleep, test-score, tick-event, to-roman-numeral, trace-line-evenly-spaced, vector3-polyfill, world-time * Add desciptions * Using prettier * Update README.md * Revert changes in cl * a * Add force * add REF in env * Update packageReadme.ts * Update packageReadme.ts * Create index.js (JaylyDev#154) * Create index.js * typo * Update cl.yml * permission resolve * Update cl.yml * . * Prevent token leak * token * remove env.GITHUB_TOKEN * Update cl.yml * Update cl.yml * wefrgtjh * ewdfgh * Update cl.yml * wdergthjmhk,. * Update cl.yml * Update cl.yml * pull r * Update cl.yml * wqefrgtrh * sd * Update cl.yml * Update cl.yml * Update cl.yml * Update cl.yml * d e3rt * Update packageReadme.ts * Update packageReadme.ts * what --------- Co-authored-by: bot174 <[email protected]> * Delete readme.ts * Update and rename scripts/action-test/index.js to scripts/radius-check/index.js * add readme --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: bot174 <[email protected]> * Delete index.js * Delete database.js * rename --------- Co-authored-by: bot174 <[email protected]>
1 parent 5890656 commit 7400658

3 files changed

Lines changed: 88 additions & 18 deletions

File tree

scripts/get-gamemode/index.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/simple-db/index.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Script example for ScriptAPI
2+
// Author: GamerFile <Bedrock Add-ons>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
5+
// Import necessary Minecraft server modules
6+
import { world } from "@minecraft/server";
7+
8+
/**
9+
* This is a constructor function that creates a new Database object for managing Minecraft scoreboard objectives.
10+
* @param {string} name - The name of the database.
11+
*/
12+
export const Database = function(name) {
13+
14+
/**
15+
* This function sets the value of a Minecraft scoreboard objective.
16+
* If the objective already exists, its value is updated.
17+
* @param {string} objName - The name of the objective.
18+
* @param {string} objValue - The value to set for the objective.
19+
*/
20+
this.set = function(objName, objValue) {
21+
// Construct the scoreboard objective name using the database name and objective name
22+
let scoreboardObjName = `${name}:${objName}`;
23+
// If the objective already exists, delete it first and then create a new one
24+
if (this.get(objName)) {
25+
this.del(objName);
26+
this.set(objName, objValue);
27+
} else {
28+
world.scoreboard.addObjective(scoreboardObjName, objValue);
29+
}
30+
return this;
31+
};
32+
33+
/**
34+
* This function checks whether a Minecraft scoreboard objective exists.
35+
* @param {string} objName - The name of the objective.
36+
* @returns {boolean} - Whether the objective exists.
37+
*/
38+
this.has = function(objName) {
39+
return Boolean(this.get(objName));
40+
};
41+
42+
/**
43+
* This function gets the value of a Minecraft scoreboard objective.
44+
* @param {string} objName - The name of the objective.
45+
* @returns {string} - The value of the objective, or undefined if it doesn't exist.
46+
*/
47+
this.get = function(objName) {
48+
let scoreboardObjName = `${name}:${objName}`;
49+
let scoreboardObj = world.scoreboard.getObjective(scoreboardObjName);
50+
return scoreboardObj ? scoreboardObj.displayName : undefined;
51+
};
52+
53+
/**
54+
* This function creates a new Minecraft scoreboard objective with the given name and value.
55+
* If an objective with the same name already exists, an error is thrown.
56+
* @param {string} objName - The name of the objective.
57+
* @param {string} objValue - The value to set for the objective.
58+
*/
59+
this.new = function(objName, objValue) {
60+
let scoreboardObjName = `${name}:${objName}`;
61+
if (this.get(objName)) {
62+
throw new Error(`Objective Already Exist. Error At new()`);
63+
return;
64+
}
65+
return this.set(objName, objValue);
66+
};
67+
68+
/**
69+
* This function gets the names of all objectives in the database.
70+
* @returns {string[]} - An array of objective names.
71+
*/
72+
73+
this.getAll = function() {
74+
return world.scoreboard.getObjectives().filter(sb => {
75+
return sb.id.startsWith(`${name}:`);
76+
}).map(sb => sb.id.replace(`${name}:`, ""));
77+
};
78+
/**
79+
* This function deletes Minecraft scoreboard objective with the given name and value.
80+
* @param {string} objName - The value to delete the objective.
81+
*/
82+
this.del = (objName) => {
83+
if (this.has(objName)) {
84+
world.scoreboard.removeObjective(`${name}:${objName}`)
85+
}
86+
return this;
87+
}
88+
}

scripts/simulated-player/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Script example for ScriptAPI
2-
// Author: Jayly <https://github.com/JaylyDev>
3-
// Project: https://github.com/JaylyDev/ScriptAPI
41
import * as Minecraft from "@minecraft/server";
52
/**
63
* A simulated player can be used to represent

0 commit comments

Comments
 (0)