Skip to content
rmsy edited this page Feb 22, 2012 · 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. Javadocs are currently not available for the LogBlock API.

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:

@Override
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: + http://diddiz.insane-architects.net/LogBlock/doc/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.setPlayer("DiddiZ");
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))
		System.out.println(bc.toString());
}

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

  • BlockChangeType
  • int limit
  • int minutes
  • int radius
  • Location loc
  • Order order
  • 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 imgame parameters. For further understanding, have a look at the source: https://github.com/DiddiZ/LogBlock/blob/master/src/de/diddiz/LogBlock/QueryParams.java

== How to do rollbacks:

LogBlock logblock = getServer().getPluginManager().getPlugin("LogBlock");
QueryParams params = new QueryParams(logblock);
params.setPlayer("DiddiZ");
params.world = getServer().getWorlds().get(0);
params.silent = true;
try {
	logblock.getCommandsHandler().new CommandRollback(logblock, params, true);
}

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!).

== How write own listeners

Not implemented yet, but a later implementation will work with queuing blocks

== Example King Midas Plugin

public class KingMidas extends JavaPlugin
{
	@Override
	public void onEnable() {
		final PluginManager pm = getServer().getPluginManager();
		Plugin plugin = pm.getPlugin("LogBlock");
		if (plugin == null) {
			pm.disablePlugin(this);
			return;
		}
		pm.registerEvent(Type.PLAYER_INTERACT, new KMPlayerListener((LogBlock)plugin, Priority.Normal, this);
	}
}

class KMPlayerListener extends PlayerListener
{
	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)
			event.getClickedBlock().setTypeId(41)
		}
	}
}

Clone this wiki locally