Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Ammar Askar edited this page · 6 revisions

How to log own block changes

Make sure you added a recent version of LogBlock (v0.14 +) as external library/jar or whatever this is called in your IDE. You don't have to add LogBlock.jar to the classpath.

You need the following imports:

import de.diddiz.LogBlock.Consumer;
import de.diddiz.LogBlock.LogBlock;

Then, you have to declare a local variable for the consumer:

public class MyPlugin extends JavaPlugin {
    private Consumer lbconsumer = null;

Next is to get an instance of the consumer:

public void onEnable() {
    final PluginManager pm = getServer().getPluginManager();
    final Plugin plugin = pm.getPlugin("LogBlock");
    if (plugin != null) lbconsumer = ((LogBlock) plugin).getConsumer();

Now you can queue blocks from everywhere in your code (for example):

lbconsumer.queueBlockBreak(event.getPlayer().getName(), event.getClickedBlock().getState());

To get a list of all queue methods have a look at the javadoc:

How to get block history from LogBlock

LogBlock logblock = (LogBlock)getServer().getPluginManager().getPlugin("LogBlock");
QueryParams params = new QueryParams(logblock);
params.bct = BlockChangeType.CREATED;
params.limit = -1;
params.minutes = 1440; = getServer().getWorlds().get(0);
params.needDate = true;
params.needType = true;
params.needData = true;
params.needPlayer = true;

try {
    for (BlockChange bc : logblock.getBlockChanges(params)) {
} catch (SQLException ex) {
    // Do nothing or throw an error if you want

Modify the params as you need. The variables expedient to manipulate are:


  • BlockChangeType
  • int limit - The maximum size of the result set, use -1 for a result set with no length restriction
  • int minutes
  • int radius
  • Location loc
  • Order order - The order in which you want the result set to be returned, default is Order.DESC
  • List players
  • boolean excludePlayersMode
  • boolean coords
  • Selection sel
  • List types
  • World world

You have to specify the columns you need (otherwise they'll get filled with 0 or null:

  • needId - The id column of the main table
  • needDate - The date
  • needType - type and replaced columns
  • needData - data column
  • needPlayer - joined playerName column from lb-players
  • needCoords - x,y and z columns
  • needSignText - All rows from -sign table
  • needChestAccess - All rows from -chest table

Most act like the in game parameters. For further understanding, have a look at the source:

Rollingback changes

LogBlock logblock = getServer().getPluginManager().getPlugin("LogBlock");
QueryParams params = new QueryParams(logblock);
params.setPlayer("DiddiZ"); = getServer().getWorlds().get(0);
params.silent = true;

try {
    logblock.getCommandsHandler().new CommandRollback(logblock, params, true);
} catch (Exception ex) {
    // Do nothing or throw an error if you want

The third parameter defines whether the rollback is performed async or snyc (true for async), so if you need to wait until the rollback has finished, use true and run the whole code in an own thread (or you'll freeze the server!).

Consumer filtering and manipulation

Some functions of the Consumer can now be modified before they are logged (currently only Block logging is implemented). This functionality will not work however unless the server operator enables the calling of PreLogEvents.


This event can be cancelled, thus, by using this you can filter out certain results with your plugin, for example you can cancel the logging of blocks in a spleef arena which gets reverted after every game.

Example King Midas Plugin

public class KingMidas extends JavaPlugin
    public void onEnable() {
        final PluginManager pm = getServer().getPluginManager();
        Plugin plugin = pm.getPlugin("LogBlock");
        if (plugin == null) {
        pm.registerEvents(new KMPlayerListener((LogBlock)plugin), this);

class KMPlayerListener implements Listener
    private final Consumer consumer;

    KMPlayerListener(LogBlock logblock) {
        consumer = logblock.getConsumer();

    public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
            consumer.queueBlockReplace(event.getPlayer().getName(), event.getClickedBlock().getState(), 41, (byte)0);
Something went wrong with that request. Please try again.