Skip to content

Commit

Permalink
2.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
smell-of-curry committed Dec 16, 2022
1 parent cceb3d9 commit 9921f17
Show file tree
Hide file tree
Showing 84 changed files with 4,712 additions and 449 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rubedo Version 2.6.3-beta
# Rubedo Version 2.6.4-beta

Welcome to Rubedo, an anti-cheat designed to protect your world from cheaters. Rubedo is designed to be smarter than cheaters by giving users access to advanced tools to protect
their world from hacked items, nuker, crashes, griefing, and so much more. Rubedo makes it possible to protect permissions and manage performance with the click of a button!
Expand Down
28 changes: 26 additions & 2 deletions entities/player.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
}
},
"component_groups": {
"has_container_open": {
"minecraft:mark_variant": {
"value": 1
}
},
"dosent_have_container_open": {
"minecraft:mark_variant": {
"value": 2
}
},
"kick": {
"minecraft:explode": {
"breaks_blocks": false,
Expand Down Expand Up @@ -247,8 +257,22 @@
},
"events": {
"rubedo:becomeAdmin": {},
"rubedo:has_container_open": {},
"rubedo:dosent_have_container_open": {},
"rubedo:has_container_open": {
"add": {
"component_groups": ["has_container_open"]
},
"remove": {
"component_groups": ["dosent_have_container_open"]
}
},
"rubedo:dosent_have_container_open": {
"add": {
"component_groups": ["dosent_have_container_open"]
},
"remove": {
"component_groups": ["has_container_open"]
}
},
"on_death": {},
"kick": {
"add": {
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
"description": "pack.description",
"min_engine_version": [1, 19, 50],
"uuid": "d98b03cc-38f8-4a82-81c6-5fb7ede55cb8",
"version": [2, 6, 3]
"version": [2, 6, 4]
},
"modules": [
{
"description": "Data Module",
"type": "data",
"uuid": "1e866a8b-1807-4689-8329-192a43404d5b",
"version": [2, 6, 3]
"version": [2, 6, 4]
},
{
"description": "Gametest Module",
"language": "javascript",
"type": "script",
"uuid": "9d7fbe86-68ed-4aac-8fe8-dfe980e671fc",
"version": [2, 6, 3],
"version": [2, 6, 4],
"entry": "scripts/index.js"
}
],
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"name": "rubedo",
"description": "Welcome to Rubedo, Rubedo is a brand new Anti-cheat designed for Realms, Servers, Worlds and anyone who wants to protect there worlds from Hackers! Rubedo Uses Minecraft's Most advanced functionality so that includes Gametest.",
"version": "2.6.3-beta",
"version": "2.6.4-beta",
"main": "index.js",
"repository": {
"type": "git",
Expand Down
4,236 changes: 4,233 additions & 3 deletions scripts/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions scripts/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| This is the version of rubedo recommended to NOT CHANGE could cause bugs.
|
*/
export const VERSION = "2.6.3-beta";
export const VERSION = "2.6.4-beta";

/*
|--------------------------------------------------------------------------
Expand Down
104 changes: 49 additions & 55 deletions src/lib/Database/Database.ts → src/database/Database.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {
Entity,
ItemStack,
MinecraftItemTypes,
system,
} from "@minecraft/server";
import { AIR } from "../../index.js";
import { Entity, ItemStack, MinecraftItemTypes } from "@minecraft/server";
import {
ENTITY_IDENTIFIER,
ENTITY_LOCATION,
INVENTORY_SIZE,
MAX_DATABASE_STRING_SIZE,
} from "../../config/database";
import { awaitWorldLoad, DIMENSIONS, onWorldLoad } from "../../utils";
import { chunkString } from "./utils";
} from "../config/database";
import { EntitiesLoad } from "../lib/Events/EntitiesLoad";
import { DIMENSIONS } from "../utils";
import { chunkString } from "../utils";

export class Database<Key extends string = string, Value = {}> {
/**
Expand Down Expand Up @@ -61,12 +56,9 @@ export class Database<Key extends string = string, Value = {}> {
this.tableName = tableName;
this.MEMORY = null;
this.QUEUE = [];
system.runSchedule(() => {
if (this.QUEUE.length == 0) return;
this.QUEUE.shift()(); // removes queue item and runs it
}, 1);
onWorldLoad(async () => {
this.MEMORY = await this.getData();
EntitiesLoad.subscribe(async () => {
await this.initData();
this.QUEUE.forEach((v) => v());
});
}

Expand All @@ -76,9 +68,7 @@ export class Database<Key extends string = string, Value = {}> {
*/
private async addQueueTask(): Promise<void> {
return new Promise((resolve) => {
this.QUEUE.push(() => {
resolve();
});
this.QUEUE.push(resolve);
});
}

Expand All @@ -87,16 +77,18 @@ export class Database<Key extends string = string, Value = {}> {
* @param data
* @returns once data is saved
*/
private async saveData(data: { [key in Key]: Value }): Promise<void> {
await this.addQueueTask();
await awaitWorldLoad(); // Await till world is loaded
this.MEMORY = data; // set memory
private async saveData(): Promise<void> {
if (!this.MEMORY) await this.addQueueTask();

let entities = Database.getTableEntities(this.tableName);
/**
* The split chunks of the stringified data, This is done because we can
* only store {@link MAX_DATABASE_STRING_SIZE} chars in a single nameTag
*/
let chunks = chunkString(JSON.stringify(data), MAX_DATABASE_STRING_SIZE);
let chunks = chunkString(
JSON.stringify(this.MEMORY),
MAX_DATABASE_STRING_SIZE
);
/**
* The amount of entities that is needed to store {@link chunks} data
*/
Expand All @@ -119,7 +111,7 @@ export class Database<Key extends string = string, Value = {}> {
}
// Set all unUsed slots to air
for (let i = chunks.length + 1; i < inventory.size; i++) {
inventory.setItem(i, AIR);
inventory.setItem(i, new ItemStack(MinecraftItemTypes.stick, 0));
}
entity.setDynamicProperty("index", i);
entities[i] = null; // Set this entity to null because its maxed out!
Expand All @@ -132,12 +124,10 @@ export class Database<Key extends string = string, Value = {}> {
}

/**
* Grabs all data from this table
* Grabs Data and should only be used on worldLoad
* @returns
*/
private async getData(): Promise<{ [key in Key]: Value }> {
await awaitWorldLoad(); // Await till world is loaded
if (this.MEMORY) return this.MEMORY;
private async initData(): Promise<{ [key in Key]: Value }> {
let entities = Database.getTableEntities(this.tableName).sort(
(a, b) =>
(a.getDynamicProperty("index") as number) -
Expand All @@ -152,7 +142,9 @@ export class Database<Key extends string = string, Value = {}> {
stringifiedData = stringifiedData + item.nameTag;
}
}
return stringifiedData == "" ? {} : JSON.parse(stringifiedData);
const data = stringifiedData == "" ? {} : JSON.parse(stringifiedData);
this.MEMORY = data;
return data;
}

/**
Expand All @@ -161,10 +153,8 @@ export class Database<Key extends string = string, Value = {}> {
* @param value
*/
async set(key: Key, value: Value): Promise<void> {
const data = await this.getData();
data[key] = value;
await this.saveData(data);
return;
this.MEMORY[key] = value;
return await this.saveData();
}

/**
Expand All @@ -175,7 +165,7 @@ export class Database<Key extends string = string, Value = {}> {
get(key: Key): Value {
if (!this.MEMORY)
throw new Error(
"World is not loaded! Consider using `getAsync` instead!"
"Entities not loaded! Consider using `getAsync` instead!"
);
return this.MEMORY[key];
}
Expand All @@ -187,8 +177,9 @@ export class Database<Key extends string = string, Value = {}> {
* @returns
*/
async getSync(key: Key): Promise<Value> {
const data = await this.getData();
return data[key];
if (this.MEMORY) return this.get(key);
await this.addQueueTask();
return this.MEMORY[key];
}

/**
Expand All @@ -198,7 +189,7 @@ export class Database<Key extends string = string, Value = {}> {
keys(): Key[] {
if (!this.MEMORY)
throw new Error(
"World is not loaded! Consider using `keysSync` instead!"
"Entities not loaded! Consider using `keysSync` instead!"
);
return Object.keys(this.MEMORY) as Key[];
}
Expand All @@ -208,8 +199,9 @@ export class Database<Key extends string = string, Value = {}> {
* @returns
*/
async keysSync(): Promise<Key[]> {
const data = await this.getData();
return Object.keys(data) as Key[];
if (this.MEMORY) return this.keys();
await this.addQueueTask();
return Object.keys(this.MEMORY) as Key[];
}

/**
Expand All @@ -219,7 +211,7 @@ export class Database<Key extends string = string, Value = {}> {
values(): Value[] {
if (!this.MEMORY)
throw new Error(
"World is not loaded! Consider using `valuesSync` instead!"
"Entities not loaded! Consider using `valuesSync` instead!"
);
return Object.values(this.MEMORY) as Value[];
}
Expand All @@ -229,8 +221,9 @@ export class Database<Key extends string = string, Value = {}> {
* @returns
*/
async valuesSync(): Promise<Value[]> {
const data = await this.getData();
return Object.values(data) as Value[];
if (this.MEMORY) return this.values();
await this.addQueueTask();
return Object.values(this.MEMORY) as Value[];
}

/**
Expand All @@ -240,9 +233,8 @@ export class Database<Key extends string = string, Value = {}> {
*/
has(key: Key): boolean {
if (!this.MEMORY)
throw new Error("World is not loaded! Consider using `hasSync` instead!");
const keys = this.keys();
return keys.includes(key);
throw new Error("Entities not loaded! Consider using `hasSync` instead!");
return (Object.keys(this.MEMORY) as Key[]).includes(key);
}

/**
Expand All @@ -251,8 +243,9 @@ export class Database<Key extends string = string, Value = {}> {
* @returns
*/
async hasSync(key: Key): Promise<boolean> {
const keys = await this.keysSync();
return keys.includes(key);
if (this.MEMORY) return this.has(key);
await this.addQueueTask();
return (Object.keys(this.MEMORY) as Key[]).includes(key);
}

/**
Expand All @@ -262,7 +255,7 @@ export class Database<Key extends string = string, Value = {}> {
collection(): { [key in Key]: Value } {
if (!this.MEMORY)
throw new Error(
"World is not loaded! Consider using `collectionSync` instead!"
"Entities not loaded! Consider using `collectionSync` instead!"
);
return this.MEMORY;
}
Expand All @@ -272,7 +265,9 @@ export class Database<Key extends string = string, Value = {}> {
* @returns
*/
async collectionSync(): Promise<{ [key in Key]: Value }> {
return await this.getData();
if (this.MEMORY) return this.collection();
await this.addQueueTask();
return this.MEMORY;
}

/**
Expand All @@ -281,17 +276,16 @@ export class Database<Key extends string = string, Value = {}> {
* @returns
*/
async delete(key: Key): Promise<boolean> {
const data = await this.getData();
const status = delete data[key];
await this.saveData(data);
const status = delete this.MEMORY[key];
await this.saveData();
return status;
}

/**
* Clear everything in the table
*/
async clear(): Promise<void> {
await this.saveData({} as { [key in Key]: Value });
return;
this.MEMORY = {} as { [key in Key]: Value };
return await this.saveData();
}
}
Loading

0 comments on commit 9921f17

Please sign in to comment.