forked from LogBlock/LogBlock
This creates a new column in the lb-players table called UUID. If this is in the form of a UUID, it's assumed to be a player. If not, it's assumed to be a server entity (zombie, sheep, or WaterFlow, LavaFlow etc.). LogBlock will set the UUID of entities to "log_" plus their name (i.e. log_zombie or log_sheep) To assist this is a new class Actor, which wraps a name/UUID pair, with constructors that will generate one from server entities, or SQL results. Every listener and every class in Consumer needed to be updated to deal with this As of yet, only the playername is displayed in results (although the queries do return UUID data). Similarly, you can only query by name (the database stores the last name they have logged in as). In addition, the WorldEdit hook has been disabled (is not compiled) since LB needs to be updated to use their new API, and the LB code hook has to extract UUID information for insertion. The UUID importer assumes any player with an onlinetime of 0 is a server-generated source, and set the UUID as above (log_sheep etc.). For everything else, it sends 100 names at a time to Mojang's name->UUID service, and records them if available. If no result is found, it records their UUID as noimport_theirname. As this is more likely than other updates to be interrupted mid-way, the importer is tolerant of e.g. the column already being added, and will resume where it left off.
79 lines
3.0 KiB
Java
79 lines
3.0 KiB
Java
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;
|
|
}
|
|
|
|
}
|