index.ts
2.6 KB · sha256:1e1836ad597b235fcb0fedd812d35d1b195341e93d09543e50ad69b7b9b3ad0c
import { ensureDBConnection } from "./db/index";
import "./commands/ward";
import "./commands/ward-user";
import "./commands/ward-group";
import "./commands/ward-track";
import "./commands/ward-admin";
import "./commands/ward-web";
import "./commands/ward-rankup";
import { primeCaches } from "./lib/cache";
import { applyToPlayer, dropPlayer, refreshAll } from "./lib/attachments";
import { registerPapiExpansion } from "./placeholders/papi";
import {
listHandlers,
registerDefaultTransactions,
registerTransaction,
unregisterTransaction,
} from "./lib/transactions";
import {
clearAutoPromoteState,
startAutoPromoteTicker,
} from "./lib/track-engine";
import { registerWebApi } from "./lib/web-api";
const RUNE_PLUGIN_NAME = "Rune";
(globalThis as { ward?: WardApi }).ward = {
registerTransaction,
unregisterTransaction,
listTransactionHandlers: listHandlers,
};
const main = async () => {
await ensureDBConnection();
console.info("ward: mongo connected");
await primeCaches();
console.info("ward: caches primed");
// Run the transaction-handler probe on the next tick so every other
// plugin (especially Vault2 + whichever economy provider answers
// against Vault's ServicesManager) has finished onEnable before we
// look. Without this defer, plugin enable order alone determines
// whether vault:money shows up.
await rune.runOnMain(() => registerDefaultTransactions());
console.info(
`ward: transaction handlers ready (${listHandlers().join(", ") || "none"})`,
);
registerPapiExpansion();
await refreshAll();
const plugin = rune.bukkit.getPluginManager().getPlugin(RUNE_PLUGIN_NAME);
if (plugin) {
startAutoPromoteTicker(plugin);
console.info("ward: auto-promote ticker started");
} else {
console.warn(
`ward: cannot find host plugin '${RUNE_PLUGIN_NAME}' -- auto-promote disabled`,
);
}
rune.serve({ port: 3000 }, (app) => {
registerWebApi(app);
app.framework("./web", {
dev: false,
devPort: 3001,
});
});
console.info("ward: ready");
};
main().catch((err) =>
console.error("ward: bootstrap failed:", (err as Error)?.stack ?? err),
);
@Listener
export class WardLifecycle {
@EventHandler(Events.PlayerJoinEvent)
async onJoin(e: PlayerJoinEvent) {
try {
await applyToPlayer(e.getPlayer());
} catch (err) {
console.error(
`ward: onJoin failed for ${e.getPlayer().getName()}:`,
(err as Error)?.stack ?? err,
);
}
}
@EventHandler(Events.PlayerQuitEvent)
onQuit(e: PlayerQuitEvent) {
const uuid = String(e.getPlayer().getUniqueId());
dropPlayer(uuid);
clearAutoPromoteState(uuid);
}
}