2014-04-03 23:22:26 -04:00
|
|
|
package de.diddiz.worldedit;
|
|
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
|
import com.sk89q.worldedit.Vector;
|
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2015-02-21 18:20:47 +00:00
|
|
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
2014-04-03 23:22:26 -04:00
|
|
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
|
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
|
|
|
|
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
|
|
|
|
|
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
|
|
|
|
import de.diddiz.LogBlock.LogBlock;
|
|
|
|
|
import de.diddiz.LogBlock.Logging;
|
|
|
|
|
import de.diddiz.LogBlock.config.Config;
|
|
|
|
|
import org.bukkit.Bukkit;
|
2015-02-21 18:20:47 +00:00
|
|
|
import org.bukkit.World;
|
2014-04-03 23:22:26 -04:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
import java.util.logging.Level;
|
|
|
|
|
|
|
|
|
|
//...so they ALSO have a class called Actor... need to fully-qualify when we use ours
|
|
|
|
|
|
2014-04-03 23:22:26 -04:00
|
|
|
public class WorldEditLoggingHook {
|
|
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
private LogBlock plugin;
|
2014-04-03 23:22:26 -04:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
public WorldEditLoggingHook(LogBlock plugin) {
|
|
|
|
|
this.plugin = plugin;
|
|
|
|
|
}
|
2014-04-03 23:22:26 -04:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
// Convert WE Actor to LB Actor
|
|
|
|
|
private de.diddiz.LogBlock.Actor AtoA(Actor weActor) {
|
|
|
|
|
if (weActor.isPlayer()) {
|
|
|
|
|
return new de.diddiz.LogBlock.Actor(weActor.getName(), weActor.getUniqueId());
|
|
|
|
|
}
|
|
|
|
|
return new de.diddiz.LogBlock.Actor(weActor.getName());
|
|
|
|
|
}
|
2015-02-17 12:54:38 +00:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
private World adapt(com.sk89q.worldedit.world.World weWorld) {
|
|
|
|
|
if (weWorld == null) {
|
|
|
|
|
throw new NullPointerException("[Logblock-Worldedit] The provided world was null.");
|
|
|
|
|
}
|
|
|
|
|
if (weWorld instanceof BukkitWorld) {
|
|
|
|
|
return ((BukkitWorld) weWorld).getWorld();
|
|
|
|
|
}
|
|
|
|
|
World world = Bukkit.getServer().getWorld(weWorld.getName());
|
|
|
|
|
if (world == null) {
|
|
|
|
|
throw new IllegalArgumentException("Can't find a Bukkit world for " + weWorld);
|
|
|
|
|
}
|
|
|
|
|
return world;
|
|
|
|
|
}
|
2015-02-21 18:20:47 +00:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
public void hook() {
|
|
|
|
|
WorldEdit.getInstance().getEventBus().register(new Object() {
|
|
|
|
|
@Subscribe
|
|
|
|
|
public void wrapForLogging(final EditSessionEvent event) {
|
|
|
|
|
final Actor actor = event.getActor();
|
|
|
|
|
if (actor == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final de.diddiz.LogBlock.Actor lbActor = AtoA(actor);
|
2014-04-03 23:22:26 -04:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
// Check to ensure the world should be logged
|
|
|
|
|
final World world;
|
|
|
|
|
final com.sk89q.worldedit.world.World k = event.getWorld();
|
|
|
|
|
try {
|
|
|
|
|
world = adapt(k);
|
|
|
|
|
} catch (RuntimeException ex) {
|
|
|
|
|
plugin.getLogger().warning("Failed to register logging for WorldEdit!");
|
|
|
|
|
plugin.getLogger().log(Level.WARNING, ex.getMessage(), ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-21 18:20:47 +00:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
// If config becomes reloadable, this check should be moved
|
|
|
|
|
if (!(Config.isLogging(world, Logging.WORLDEDIT))) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-04-03 23:22:26 -04:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
event.setExtent(new AbstractLoggingExtent(event.getExtent()) {
|
|
|
|
|
@Override
|
|
|
|
|
protected void onBlockChange(Vector pt, BaseBlock block) {
|
2014-04-03 23:22:26 -04:00
|
|
|
|
2015-03-22 20:15:04 +05:00
|
|
|
if (event.getStage() != EditSession.Stage.BEFORE_CHANGE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-04-03 23:22:26 -04:00
|
|
|
|
2018-07-21 02:41:52 +02:00
|
|
|
// FIXME wait for updated worldedit
|
|
|
|
|
// Location location = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
|
|
|
// Block origin = location.getBlock();
|
|
|
|
|
// Material typeBefore = origin.getType();
|
|
|
|
|
// byte dataBefore = origin.getData();
|
|
|
|
|
// // If we're dealing with a sign, store the block state to read the text off
|
|
|
|
|
// BlockState stateBefore = null;
|
|
|
|
|
// if (typeBefore == Material.SIGN || typeBefore == Material.WALL_SIGN) {
|
|
|
|
|
// stateBefore = origin.getState();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // Check to see if we've broken a sign
|
|
|
|
|
// if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN || typeBefore == Material.WALL_SIGN)) {
|
|
|
|
|
// plugin.getConsumer().queueSignBreak(lbActor, (Sign) stateBefore);
|
|
|
|
|
// if (block.getType() != Material.AIR.getId()) {
|
|
|
|
|
// plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// if (dataBefore != 0) {
|
|
|
|
|
// plugin.getConsumer().queueBlockBreak(lbActor, location, typeBefore, dataBefore);
|
|
|
|
|
// if (block.getType() != Material.AIR.getId()) {
|
|
|
|
|
// plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// plugin.getConsumer().queueBlock(lbActor, location, typeBefore, block.getType(), (byte) block.getData());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2015-03-22 20:15:04 +05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-04-03 23:22:26 -04:00
|
|
|
}
|