2012-10-31 21:36:16 +05:00
|
|
|
package de.diddiz.worldedit;
|
|
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.EditSession;
|
2013-01-12 12:37:45 +05:00
|
|
|
import com.sk89q.worldedit.LocalPlayer;
|
2012-10-31 21:36:16 +05:00
|
|
|
import com.sk89q.worldedit.LocalWorld;
|
|
|
|
|
import com.sk89q.worldedit.Vector;
|
|
|
|
|
import com.sk89q.worldedit.bags.BlockBag;
|
|
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
2013-01-12 12:37:45 +05:00
|
|
|
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;
|
2013-01-20 12:34:13 +05:00
|
|
|
import org.bukkit.Material;
|
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
|
import org.bukkit.block.Sign;
|
2012-10-31 21:36:16 +05:00
|
|
|
|
2013-01-12 12:37:45 +05:00
|
|
|
public class LogBlockEditSession extends EditSession {
|
|
|
|
|
|
|
|
|
|
private LocalPlayer player;
|
2013-01-20 12:34:13 +05:00
|
|
|
private LogBlock plugin;
|
2012-10-31 21:36:16 +05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
2013-01-20 12:34:13 +05:00
|
|
|
public LogBlockEditSession(LocalWorld world, int maxBlocks, LocalPlayer player, LogBlock lb) {
|
2012-10-31 21:36:16 +05:00
|
|
|
super(world, maxBlocks);
|
2013-01-12 12:37:45 +05:00
|
|
|
this.player = player;
|
2013-01-20 12:34:13 +05:00
|
|
|
this.plugin = lb;
|
2012-10-31 21:36:16 +05:00
|
|
|
}
|
2013-01-12 12:37:45 +05:00
|
|
|
|
2012-10-31 21:36:16 +05:00
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
2013-01-20 12:34:13 +05:00
|
|
|
public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player, LogBlock lb) {
|
2012-10-31 21:36:16 +05:00
|
|
|
super(world, maxBlocks, blockBag);
|
2013-01-12 12:37:45 +05:00
|
|
|
this.player = player;
|
2013-01-20 12:34:13 +05:00
|
|
|
this.plugin = lb;
|
2012-10-31 21:36:16 +05:00
|
|
|
}
|
2013-01-12 12:37:45 +05:00
|
|
|
|
2012-10-31 21:36:16 +05:00
|
|
|
@Override
|
|
|
|
|
public boolean rawSetBlock(Vector pt, BaseBlock block) {
|
2013-01-20 12:34:13 +05:00
|
|
|
if (!(player.getWorld() instanceof BukkitWorld) || !(Config.isLogging(player.getWorld().getName(), Logging.WORLDEDIT))) {
|
2013-01-12 12:37:45 +05:00
|
|
|
return super.rawSetBlock(pt, block);
|
|
|
|
|
}
|
2013-01-20 12:34:13 +05:00
|
|
|
|
2013-01-12 12:37:45 +05:00
|
|
|
int typeBefore = ((BukkitWorld) player.getWorld()).getWorld().getBlockTypeIdAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
|
2013-01-20 12:34:13 +05:00
|
|
|
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();
|
|
|
|
|
}
|
2013-01-12 12:37:45 +05:00
|
|
|
boolean success = super.rawSetBlock(pt, block);
|
2013-01-20 12:34:13 +05:00
|
|
|
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())) {
|
2015-02-14 13:52:06 +00:00
|
|
|
plugin.getConsumer().queueSignBreak(player, (Sign) stateBefore);
|
2013-01-20 12:34:13 +05:00
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-12 12:37:45 +05:00
|
|
|
}
|
|
|
|
|
return success;
|
2012-10-31 21:36:16 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|