Added WorldEdit logging
This commit is contained in:
1 parent
208dcc0160
commit
e361c39937
6 files changed
+67
-59
No files matched your search
@@ -1,31 +1,50 @@
|
||||
package de.diddiz.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class LogBlockEditSession extends EditSession{
|
||||
public class LogBlockEditSession extends EditSession {
|
||||
|
||||
private LocalPlayer player;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public LogBlockEditSession(LocalWorld world, int maxBlocks) {
|
||||
public LogBlockEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
|
||||
super(world, maxBlocks);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) {
|
||||
public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
||||
super(world, maxBlocks, blockBag);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean rawSetBlock(Vector pt, BaseBlock block) {
|
||||
//TODO: perform logging actions here
|
||||
return super.rawSetBlock(pt, block);
|
||||
if (!(player.getWorld() instanceof BukkitWorld)) {
|
||||
return super.rawSetBlock(pt, block);
|
||||
}
|
||||
int typeBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockTypeIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
boolean success = super.rawSetBlock(pt, block);
|
||||
if (success && Config.isLogging(player.getWorld().getName(), Logging.WORLDEDIT)) {
|
||||
Location location = new Location(Bukkit.getWorld(player.getWorld().getName()), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||
LogBlock.getInstance().getConsumer().queueBlock(player.getName(), location, typeBefore, location.getBlock().getTypeId(), location.getBlock().getData());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,28 @@
|
||||
package de.diddiz.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.EditSessionFactory;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
|
||||
public class LogBlockEditSessionFactory extends EditSessionFactory {
|
||||
|
||||
|
||||
@Override
|
||||
public EditSession getEditSession(LocalWorld world, int maxBlocks) {
|
||||
return new LogBlockEditSession(world, maxBlocks);
|
||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
|
||||
return new LogBlockEditSession(world, maxBlocks, player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) {
|
||||
return new LogBlockEditSession(world, maxBlocks, blockBag);
|
||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
||||
return new LogBlockEditSession(world, maxBlocks, blockBag, player);
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
try {
|
||||
// Check to see if the world edit version is compatible
|
||||
Class.forName("com.sk89q.worldedit.EditSessionFactory").getDeclaredMethod("getEditSession", LocalWorld.class, int.class, BlockBag.class, LocalPlayer.class);
|
||||
WorldEdit.getInstance().setEditSessionFactory(new LogBlockEditSessionFactory());
|
||||
} catch (Throwable t) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user