forked from LogBlock/LogBlock
Merge branch 'worldedit-6.0.0' of https://github.com/DarkArc/LogBlock into DarkArc-worldedit-6.0.0
Conflicts: src/main/java/de/diddiz/LogBlock/LogBlock.java src/main/java/de/diddiz/LogBlock/listeners/ExplosionLogging.java src/main/java/de/diddiz/worldedit/LogBlockEditSession.java Update Worldedit 6.0 hook to support UUIDs
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -54,7 +54,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sk89q</groupId>
|
<groupId>com.sk89q</groupId>
|
||||||
<artifactId>worldedit</artifactId>
|
<artifactId>worldedit</artifactId>
|
||||||
<version>5.5</version>
|
<version>6.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@@ -89,9 +89,6 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<source>1.6</source>
|
<source>1.6</source>
|
||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
<excludes>
|
|
||||||
<exclude>**/de/diddiz/worldedit/*.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@@ -24,7 +24,7 @@ import de.diddiz.LogBlock.listeners.StructureGrowLogging;
|
|||||||
import de.diddiz.LogBlock.listeners.ToolListener;
|
import de.diddiz.LogBlock.listeners.ToolListener;
|
||||||
import de.diddiz.LogBlock.listeners.WitherLogging;
|
import de.diddiz.LogBlock.listeners.WitherLogging;
|
||||||
import de.diddiz.util.MySQLConnectionPool;
|
import de.diddiz.util.MySQLConnectionPool;
|
||||||
//import de.diddiz.worldedit.LogBlockEditSessionFactory;
|
import de.diddiz.worldedit.WorldEditLoggingHook;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -109,9 +109,9 @@ public class LogBlock extends JavaPlugin
|
|||||||
}
|
}
|
||||||
if (noDb)
|
if (noDb)
|
||||||
return;
|
return;
|
||||||
// if (pm.getPlugin("WorldEdit") != null) {
|
if (pm.getPlugin("WorldEdit") != null) {
|
||||||
// LogBlockEditSessionFactory.initialize(this);
|
new WorldEditLoggingHook(this).hook();
|
||||||
// }
|
}
|
||||||
commandsHandler = new CommandsHandler(this);
|
commandsHandler = new CommandsHandler(this);
|
||||||
getCommand("lb").setExecutor(commandsHandler);
|
getCommand("lb").setExecutor(commandsHandler);
|
||||||
if (enableAutoClearLog && autoClearLogDelay > 0)
|
if (enableAutoClearLog && autoClearLogDelay > 0)
|
||||||
|
@@ -1,78 +0,0 @@
|
|||||||
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.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
|
|
||||||
public class LogBlockEditSession extends EditSession {
|
|
||||||
|
|
||||||
private LocalPlayer player;
|
|
||||||
private LogBlock plugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public LogBlockEditSession(LocalWorld world, int maxBlocks, LocalPlayer player, LogBlock lb) {
|
|
||||||
super(world, maxBlocks);
|
|
||||||
this.player = player;
|
|
||||||
this.plugin = lb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player, LogBlock lb) {
|
|
||||||
super(world, maxBlocks, blockBag);
|
|
||||||
this.player = player;
|
|
||||||
this.plugin = lb;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean rawSetBlock(Vector pt, BaseBlock block) {
|
|
||||||
if (!(player.getWorld() instanceof BukkitWorld) || !(Config.isLogging(player.getWorld().getName(), Logging.WORLDEDIT))) {
|
|
||||||
return super.rawSetBlock(pt, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
int typeBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockTypeIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
||||||
byte dataBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData();
|
|
||||||
// If we're dealing with a sign, store the block state to read the text off
|
|
||||||
BlockState stateBefore = null;
|
|
||||||
if (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId()) {
|
|
||||||
stateBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getState();
|
|
||||||
}
|
|
||||||
boolean success = super.rawSetBlock(pt, block);
|
|
||||||
if (success) {
|
|
||||||
Location location = new Location(((BukkitWorld) player.getWorld()).getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
|
||||||
|
|
||||||
// Check to see if we've broken a sign
|
|
||||||
if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId())) {
|
|
||||||
plugin.getConsumer().queueSignBreak(player, (Sign) stateBefore);
|
|
||||||
if (block.getType() != Material.AIR.getId()) {
|
|
||||||
plugin.getConsumer().queueBlockPlace(player.getName(), location, block.getType(), (byte) block.getData());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (dataBefore != 0) {
|
|
||||||
plugin.getConsumer().queueBlockBreak(player.getName(), location, typeBefore, dataBefore);
|
|
||||||
if (block.getType() != Material.AIR.getId()) {
|
|
||||||
plugin.getConsumer().queueBlockPlace(player.getName(), location, block.getType(), (byte) block.getData());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plugin.getConsumer().queueBlock(player.getName(), location, typeBefore, block.getType(), (byte) block.getData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,39 +0,0 @@
|
|||||||
package de.diddiz.worldedit;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
|
||||||
import com.sk89q.worldedit.EditSessionFactory;
|
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
|
||||||
import de.diddiz.LogBlock.LogBlock;
|
|
||||||
|
|
||||||
public class LogBlockEditSessionFactory extends EditSessionFactory {
|
|
||||||
|
|
||||||
private LogBlock plugin;
|
|
||||||
|
|
||||||
public LogBlockEditSessionFactory(LogBlock lb) {
|
|
||||||
this.plugin = lb;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
|
|
||||||
return new LogBlockEditSession(world, maxBlocks, player, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
|
|
||||||
return new LogBlockEditSession(world, maxBlocks, blockBag, player, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initialize(LogBlock logBlock) {
|
|
||||||
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(logBlock));
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
99
src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java
Normal file
99
src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.java
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
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;
|
||||||
|
import com.sk89q.worldedit.entity.Player;
|
||||||
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||||
|
//...so they ALSO have a class called Actor... need to fully-qualify when we use ours
|
||||||
|
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;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
|
||||||
|
public class WorldEditLoggingHook {
|
||||||
|
|
||||||
|
private LogBlock plugin;
|
||||||
|
|
||||||
|
public WorldEditLoggingHook(LogBlock plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert WE Actor to LB Actor
|
||||||
|
private de.diddiz.LogBlock.Actor AtoA(Actor weActor) {
|
||||||
|
if (weActor.isPlayer()) {
|
||||||
|
return de.diddiz.LogBlock.Actor.actorFromEntity(plugin.getServer().getPlayer(weActor.getName()));
|
||||||
|
}
|
||||||
|
return new de.diddiz.LogBlock.Actor(weActor.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Check to ensure the world should be logged
|
||||||
|
String worldName = event.getWorld().getName();
|
||||||
|
// If config becomes reloadable, this check should be moved
|
||||||
|
if (!(Config.isLogging(worldName, Logging.WORLDEDIT))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName);
|
||||||
|
if (bukkitWorld == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setExtent(new AbstractLoggingExtent(event.getExtent()) {
|
||||||
|
@Override
|
||||||
|
protected void onBlockChange(Vector pt, BaseBlock block) {
|
||||||
|
|
||||||
|
if (event.getStage() != EditSession.Stage.BEFORE_CHANGE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location location = new Location(bukkitWorld, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
||||||
|
|
||||||
|
Block origin = location.getBlock();
|
||||||
|
int typeBefore = origin.getTypeId();
|
||||||
|
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_POST.getId() || typeBefore == Material.SIGN.getId()) {
|
||||||
|
stateBefore = origin.getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to see if we've broken a sign
|
||||||
|
if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId())) {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user