Ammar Askar edited this page Jun 23, 2015 · 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: https://logblock.github.io/LogBlock/de/diddiz/LogBlock/Consumer.html#method.summary

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;
params.world = 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: https://github.com/LogBlock/LogBlock/blob/master/src/main/java/de/diddiz/LogBlock/QueryParams.java

Rollingback changes

LogBlock logblock = getServer().getPluginManager().getPlugin("LogBlock");
QueryParams params = new QueryParams(logblock);
params.world = 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);