API

API

This page is related to the API for MaxBans.

I have intended for this plugin to be a very clean API (Much cleaner than my other project... QuickShop).

I recommend you get the java annotations from the source at github.com/netherfoam/MaxBans or something, as I've documented nearly every method already.

Ban Manager

The ban manager is the central hub for the plugin. This allows adjusting lockdowns, checking bans, fetching the DNSBL object, banning, unbanning, etc.

Most changes made to the ban manager will be reflected in the database.

The Ban class extends Object.
The IPBan class extends Ban.
The TempIPBan extends IPBan.
The TempBan extends Ban.

When you fetch a ban from the database, use code something like this:

Ban ban = MaxBans.instance.getBanManager().getBan("TestGuy");
if(ban == null){
    sender.sendMessage("No ban found for TestGuy");
}

if(ban instanceof TempBan){
    TempBan tBan = (TempBan) ban;
    sender.sendMessage("Tempbanned. Time: " + Util.getTimeUntil(tBan.getExpires());
}
else{
    sender.sendMessage("Permabanned");
}

String ip = MaxBans.instance.getBanManager().getIP("TestGuy");
if(ip == null){
    sender.sendMessage("No IP found for TestGuy");
}

IPBan ipban = MaxBans.instance.getBanManager().getIPBan(ip);
if(ipban == null){
    sender.sendMessage("No IP ban for " + ip);
}

if(ipban instanceof TempIPBan){
    TempIPBan tib = (TempIPBan) ipban;
    sender.sendMessage("TempIPBanned. Time: " + Util.getTimeUntil(tib.getExpires()
}
else{
    sender.sendMessage("Perma IP Banned");
}

The code is similar for mutes. Using banManager().getBan() and all variants will NEVER return an expired object.

DNSBL

If the DNSBL is enabled, BanManager().getDNSBL() will return it. Otherwise, it will return null.

Using DNSBL.getServers() returns an editable list of DNSBL servers. Using getRecord(ip) allows you to fetch the cache record for a given IP (is it a proxy? is it not?). This returns null if there is no record for it (or it has expired.) In which case, you'll want to use DNSBL.reload(ip), but this takes a few seconds to lookup (And automatically caches the result, so that getRecord(ip) will return not null next time).

Util

The static class, org.maxgamer.maxbans.util.Util is basically a misc class. it allows checking if a string is an IP, fetching invalid chars in a given string (think, username matching) and converting time to and from human-readable. Useful if you want to display things to a user, or make ambiguous commands.


Comments

Posts Quoted:
Reply
Clear All Quotes