rce.js-datastore
v1.1.2
Published
A SQLite database plugin for rce.js
Downloads
11
Readme
rce.js-datastore
A plugin for rce.js which allows database integration using an easy-to-use SQLite database
Installation
npm i rce.js-datastore
Example Usage - TypeScript
import { RCEManager } from "rce.js";
import RCEDatastore from "rce.js-datastore";
const rce = new RCEManager();
await rce.init({ username: "", password: "" }, { level: LogLevel.Info });
rce.registerPlugin("database", new RCEDatastore());
await rce.database.connect("myDatabase");
interface KillData {
kills: number;
deaths: number;
}
rce.on(RCEEvent.PlayerKill, async (data) => {
const killerKey = `kill:${data.server.identifier}:${data.killer.id}`;
const victimKey = `kill:${data.server.identifier}:${data.victim.id}`;
const killerData = rce.database.get<KillData>(killerKey, {
kills: 0,
deaths: 0,
});
const victimData = rce.database.get<KillData>(victimKey, {
kills: 0,
deaths: 0,
});
killerData.kills++;
victimData.deaths++;
await rce.database.set(killerKey, killerData);
await rce.database.set(victimKey, victimData);
await rce.servers.command(
data.server.identifier,
`say <color=red>${data.killer.name}</color> killed <color=red>${data.victim.name}</color>`
);
});
// Other Available Methods
rce.database.get("key", "defaultValue"); // Get Value from Key
rce.database.getAll(); // Get All Values
await rce.database.set("key", "value"); // Set Value to Key
await rce.database.delete("key"); // Delete Value from Key
await rce.database.drop(); // Drop Database
await rce.database.close(); // Disconnect
// Optional: For IntelliSense in TypeScript
declare module "rce.js" {
interface RCEManager {
database: DatabasePlugin;
}
}