Files
LogBlock/src/main/java/de/diddiz/worldedit/LogBlockEditSession.java
T

51 lines
1.6 KiB
Java
Raw Normal View History

package de.diddiz.worldedit;
import com.sk89q.worldedit.EditSession;
2013-01-12 12:37:45 +05:00
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;
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.Bukkit;
import org.bukkit.Location;
2013-01-12 12:37:45 +05:00
public class LogBlockEditSession extends EditSession {
private LocalPlayer player;
/**
* {@inheritDoc}
*/
2013-01-12 12:37:45 +05:00
public LogBlockEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
super(world, maxBlocks);
2013-01-12 12:37:45 +05:00
this.player = player;
}
2013-01-12 12:37:45 +05:00
/**
* {@inheritDoc}
*/
2013-01-12 12:37:45 +05:00
public LogBlockEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
super(world, maxBlocks, blockBag);
2013-01-12 12:37:45 +05:00
this.player = player;
}
2013-01-12 12:37:45 +05:00
@Override
public boolean rawSetBlock(Vector pt, BaseBlock block) {
2013-01-12 12:37:45 +05:00
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;
}
}