Repository navigation
Developer API
XWardenAPI lets your plugin report into the same pipeline and read back what X-Warden knows.
The contract lives in its own artifact, X-WardenAPI, so you never compile against the plugin itself:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.github.drawethree</groupId>
<artifactId>X-WardenAPI</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>Always provided. X-Warden supplies these classes at runtime; shading them into your own jar puts a
second copy on the server and the two will not be the same class.
Guard for its absence — most servers will not have it installed:
XWardenAPI.find().ifPresent(warden -> {
warden.registerCheck("economy", "mygame-impossible-win"); // once, on enable
warden.report(player.getUniqueId(), "economy", "mygame-impossible-win", 80,
Map.of("Wagered", "1000", "Returned", "9999999"));
});find() returns empty when X-Warden is missing, disabled or still starting. getInstance() throws
instead, if you would rather fail loudly.
Guard the class, not just the call. A field or parameter typed as an X-Warden class is resolved when your own class links, which is before any
find()runs. Keep everything that names an X-Warden type in one package and enter it only after checking the plugin is installed. X-Prison Player Vaults is the worked example.
| Method | For |
|---|---|
registerCheck(moduleId, checkId) |
telling Warden a check id of yours exists |
report(player, moduleId, checkId, confidence, evidence) |
something you detected about a player |
reportBug(source, detail) |
a defect — reaches staff as a bug notice, never touches a violation level |
Register your check ids first. Warden resolves a check id against a fixed list, so anything it
does not recognise is treated as switched off and the report is discarded. Call registerCheck once
on enable, before your first report. It returns false if the module id is not one of Warden's own
— economy, integrity, automation or network.
A registered check picks up whatever the owner has written under
modules.<module>.checks.<check> in warden.yml, and Warden's ordinary defaults where they have
written nothing: enabled, on ALERT. An addon therefore cannot ship a check that punishes on its
own — only the server owner can raise it. Registrations survive /xwarden reload.
Keep your ids lowercase and hyphenated, and distinctive enough not to collide with another addon's.
A report is also discarded when the player holds a bypass permission, or when another plugin cancels
WardenViolationEvent.
confidence is 0–100 and means how sure you are, not how bad it is.
Warden fires three Bukkit events, so you do not have to poll.
| Event | When | Cancellable |
|---|---|---|
WardenViolationEvent |
a check has decided to report somebody, before anything is stored or acted on | yes |
WardenViolationRecordedEvent |
the same finding, once it has been stored and acted on | no |
WardenFlagResolvedEvent |
a staff member marked one finding as handled | no |
Use WardenViolationRecordedEvent if you are showing findings to a person. The first event fires
before anything is written, precisely so it can be vetoed — which means it carries no id, no
violation level, and no record of what Warden decided to do, because none of them exist yet. The
second carries the finished Violation with all three.
Cancelling WardenViolationEvent discards the finding entirely — no row in the flag list, no
violation level, no action. It is the same outcome as a bypass permission, and it is what to use when
your plugin knows something Warden cannot: an event world, a staff build session, a player your own
systems have already cleared.
@EventHandler
public void onWardenFlag(WardenViolationEvent event) {
if (myEventWorld.contains(event.getPlayer())) {
event.setCancelled(true);
}
}
⚠️ Both are often fired off the main thread. Analysis runs asynchronously and resolving writes to the database, so a handler must not touch the Bukkit API without hopping back to the server thread.isAsynchronous()tells you which you are on.
The shortcuts on XWardenAPI itself cover the common cases:
int score = warden.getAutomationScore(uuid);
Optional<AutomationBreakdown> breakdown = warden.getAutomationBreakdown(uuid);
int level = warden.getViolationLevel(uuid, "automation");
List<Violation> recent = warden.getRecentViolations(uuid, 10);
boolean trusted = warden.isTrusted(uuid, "integrity");Everything else is behind nine area APIs:
| For | |
|---|---|
getFlagsApi() |
findings — paged, filtered, grouped, resolved |
getLedgerApi() |
transactions, mining income, lifetime totals |
getEconomyApi() |
currencies, balances, multiplier audits, rollback |
getIntegrityApi() |
fingerprints, sightings, circulation, sweeps |
getNetworkApi() |
linked accounts and sessions |
getAutomationApi() |
scores, signals, calibration, verification challenges |
getModulesApi() |
modules, per-check settings, and whether a check can actually fire |
getStaffApi() |
server status, freeze, watch, player snapshots |
getConfigApi() |
reading and changing the configuration |
FlagPage page = warden.getFlagsApi().page(
ViolationQuery.all(20).inModule("automation").openOnly(true).page(0, 20));
System.out.println("showing " + page.rows().size() + " of " + page.total());Two things are true at once: reads hit a database and block, and calls into the server are only legal on the thread that ticks it. Both ways of getting it wrong work nine times out of ten in testing, so X-Warden refuses the call outright rather than letting you find out on a live server.
Every method says which it needs with @ThreadSafety:
| Means | |
|---|---|
OFF_PRIMARY |
reads the database. Never call it from the server thread |
PRIMARY |
touches the server. Only call it from the server thread |
ANY |
reads memory. Safe from anywhere |
Inside an addon, XWardenAddonContext gives you async(...) to get off the server thread and
call(...) / sync(...) to get back onto it. See Addons.
for (CheckReachability answer : warden.getModulesApi().reachability()) {
if (!answer.reachable()) {
getLogger().warning(answer.explanation());
}
}A finding adds confidence / 100 to a violation level and vl-decay is charged per minute, so a
check that cannot report again before decay takes back more than a finding is worth has a ceiling —
and if that ceiling sits under vl-threshold, the check detects exactly what it was built for and
tells nobody, silently, for ever. This answers that question about the settings actually in force.
WriteResult written = warden.getConfigApi()
.set(Target.WARDEN, "modules.economy.checks.balance-velocity.vl-threshold", "2.0");
if (!written.ok()) {
getLogger().warning(written.reason() + ": " + written.detail());
}A write edits the one line the setting lives on and leaves every other byte of the file alone —
warden.yml is mostly comments explaining what each default is for, and they are worth keeping.
Anything it cannot place beyond doubt it refuses, and says which kind of doubt it was.
Check effective() rather than assuming a successful write took effect. A value can be correctly
written and still be overridden by the preset: an owner value identical to the bundled default defers
to the preset, so writing the default back is not the same as resetting it.
If your plugin stores items on a player's behalf, register a ContainerSource. Without one, an
item hidden in your storage can never be reported as a duplicate — which makes it the best hiding
place on the server.
warden.registerContainerSource(new ContainerSource() {
public String id() { return "MyVaults"; }
public List<HeldItem> snapshot() { return List.copyOf(alreadyPrepared); }
});snapshot() is called asynchronously, so it must return an already-materialised list and must
not touch Bukkit state. Build that list beforehand, on the server thread, with describeStored:
warden.describeStored(item, ownerId, ownerName, "vault " + number, slot)
.ifPresent(alreadyPrepared::add);Work the identity out yourself and you will get it wrong: a prison pickaxe carries an identity of its own, everything else carries X-Warden's, and which is which depends on what is installed.
X-Warden is usually enabled after other plugins and addons, so registering during your own
onEnable will find nothing. Wait for PluginEnableEvent for X-Warden instead — that also covers
somebody installing it later without a restart.
XWardenAPI only ever grows, so a method you compiled against does not disappear. What can happen is
the reverse: you build against a newer X-Warden than the server is running, and the call site throws
NoSuchMethodError — a stack trace nobody can act on.
apiVersion() counts the additions since the contract was first published. Check it before calling
anything added after the version you built against, and refuse politely instead:
if (warden.apiVersion() >= 2) {
warden.unloadAddon("MyAddon");
}| Version | Added |
|---|---|
| 1 | the nine area APIs, apiVersion(), the addon contract, the addon registry methods |
| 2 | unloadAddon(String) |
List<XWardenAddonInfo> loaded = warden.getLoadedAddons();
warden.disableAddon("Dashboard"); // stops it; the jar stays open
warden.unloadAddon("Dashboard"); // stops it and lets go of the jar
warden.loadAddonFromFile("MyAddon-2.0.jar"); // reads a jar from plugins/X-Warden/addons/disableAddon is not unloadAddon. Disabling calls onDisable and leaves the addon loaded
against the same classloader, which still holds its jar open — so replacing the file and enabling it
again runs the version it started with. Unloading closes the classloader, which is what makes a new
jar readable. See Addons.
unloadAddon refuses while another loaded addon declares X-Warden-Depends on this one, and names
the dependent in the console.
warden.recordTransaction(uuid, "tokens", amount, "MyCasino", correlationId);
Optional<MultiplierBreakdown> chain = warden.auditMultipliers(player, "tokens");Use recordTransaction for money your own plugin moves outside the core currency API, so it appears
in reports and can be rolled back. Pass the same correlationId for both halves of a transfer.