Added WorldEdit logging

This commit is contained in:
Ammar Askar
2013-01-12 12:37:45 +05:00
parent 208dcc0160
commit e361c39937
6 changed files with 67 additions and 59 deletions

View File

@@ -57,7 +57,7 @@
<dependency> <dependency>
<groupId>com.sk89q</groupId> <groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId> <artifactId>worldedit</artifactId>
<version>5.4.4-SNAPSHOT</version> <version>5.4.6-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,18 +1,17 @@
package de.diddiz.LogBlock; package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.askRollbackAfterBan; import de.diddiz.LogBlock.config.Config;
import static de.diddiz.LogBlock.config.Config.autoClearLogDelay; import de.diddiz.LogBlock.listeners.*;
import static de.diddiz.LogBlock.config.Config.delayBetweenRuns; import de.diddiz.util.MySQLConnectionPool;
import static de.diddiz.LogBlock.config.Config.enableAutoClearLog; import de.diddiz.worldedit.LogBlockEditSessionFactory;
import static de.diddiz.LogBlock.config.Config.isLogging; import org.bukkit.ChatColor;
import static de.diddiz.LogBlock.config.Config.load; import org.bukkit.command.Command;
import static de.diddiz.LogBlock.config.Config.logPlayerInfo; import org.bukkit.command.CommandSender;
import static de.diddiz.LogBlock.config.Config.password; import org.bukkit.entity.Player;
import static de.diddiz.LogBlock.config.Config.toolsByType; import org.bukkit.permissions.Permission;
import static de.diddiz.LogBlock.config.Config.url; import org.bukkit.plugin.PluginManager;
import static de.diddiz.LogBlock.config.Config.useBukkitScheduler; import org.bukkit.plugin.java.JavaPlugin;
import static de.diddiz.LogBlock.config.Config.user;
import static org.bukkit.Bukkit.getPluginManager;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection; import java.sql.Connection;
@@ -23,34 +22,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import static de.diddiz.LogBlock.config.Config.*;
import org.bukkit.command.CommandSender; import static org.bukkit.Bukkit.getPluginManager;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.LogBlock.listeners.BanListener;
import de.diddiz.LogBlock.listeners.BlockBreakLogging;
import de.diddiz.LogBlock.listeners.BlockBurnLogging;
import de.diddiz.LogBlock.listeners.BlockPlaceLogging;
import de.diddiz.LogBlock.listeners.ChatLogging;
import de.diddiz.LogBlock.listeners.ChestAccessLogging;
import de.diddiz.LogBlock.listeners.EndermenLogging;
import de.diddiz.LogBlock.listeners.ExplosionLogging;
import de.diddiz.LogBlock.listeners.FluidFlowLogging;
import de.diddiz.LogBlock.listeners.InteractLogging;
import de.diddiz.LogBlock.listeners.KillLogging;
import de.diddiz.LogBlock.listeners.LeavesDecayLogging;
import de.diddiz.LogBlock.listeners.PlayerInfoLogging;
import de.diddiz.LogBlock.listeners.SignChangeLogging;
import de.diddiz.LogBlock.listeners.SnowFadeLogging;
import de.diddiz.LogBlock.listeners.SnowFormLogging;
import de.diddiz.LogBlock.listeners.StructureGrowLogging;
import de.diddiz.LogBlock.listeners.ToolListener;
import de.diddiz.LogBlock.listeners.WitherLogging;
import de.diddiz.util.MySQLConnectionPool;
public class LogBlock extends JavaPlugin public class LogBlock extends JavaPlugin
{ {
@@ -118,6 +92,8 @@ public class LogBlock extends JavaPlugin
new Exception("WorldEdit is not installed please download and install").printStackTrace(); new Exception("WorldEdit is not installed please download and install").printStackTrace();
pm.disablePlugin(this); pm.disablePlugin(this);
return; return;
} else {
LogBlockEditSessionFactory.initialize();
} }
commandsHandler = new CommandsHandler(this); commandsHandler = new CommandsHandler(this);
getCommand("lb").setExecutor(commandsHandler); getCommand("lb").setExecutor(commandsHandler);

View File

@@ -7,7 +7,7 @@ public enum Logging
LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT, LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT,
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, NATURALSTRUCTUREGROW, SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, NATURALSTRUCTUREGROW,
WITHER(true), WITHER_SKULL(true), WITHER(true), WITHER_SKULL(true),
BONEMEALSTRUCTUREGROW; BONEMEALSTRUCTUREGROW, WORLDEDIT;
public static final int length = Logging.values().length; public static final int length = Logging.values().length;
private final boolean defaultEnabled; private final boolean defaultEnabled;

View File

@@ -228,6 +228,11 @@ public class Config
return wcfg != null && wcfg.isLogging(l); return wcfg != null && wcfg.isLogging(l);
} }
public static boolean isLogging(String worldName, Logging l) {
final WorldConfig wcfg = worldConfigs.get(worldName);
return wcfg != null && wcfg.isLogging(l);
}
public static boolean isLogged(World world) { public static boolean isLogged(World world) {
return worldConfigs.containsKey(world.getName()); return worldConfigs.containsKey(world.getName());
} }

View File

@@ -1,31 +1,50 @@
package de.diddiz.worldedit; package de.diddiz.worldedit;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock; 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} * {@inheritDoc}
*/ */
public LogBlockEditSession(LocalWorld world, int maxBlocks) { public LogBlockEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
super(world, maxBlocks); super(world, maxBlocks);
this.player = player;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) { public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
super(world, maxBlocks, blockBag); super(world, maxBlocks, blockBag);
this.player = player;
} }
@Override @Override
public boolean rawSetBlock(Vector pt, BaseBlock block) { public boolean rawSetBlock(Vector pt, BaseBlock block) {
//TODO: perform logging actions here if (!(player.getWorld() instanceof BukkitWorld)) {
return super.rawSetBlock(pt, block); 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;
} }
} }

View File

@@ -1,20 +1,28 @@
package de.diddiz.worldedit; package de.diddiz.worldedit;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.EditSessionFactory;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.bags.BlockBag;
public class LogBlockEditSessionFactory extends EditSessionFactory { public class LogBlockEditSessionFactory extends EditSessionFactory {
@Override @Override
public EditSession getEditSession(LocalWorld world, int maxBlocks) { public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
return new LogBlockEditSession(world, maxBlocks); return new LogBlockEditSession(world, maxBlocks, player);
} }
@Override @Override
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) { public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
return new LogBlockEditSession(world, maxBlocks, blockBag); 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) {
}
} }
} }