Identify players by UUID and migrate existing databases to include this. Fixes #538, fixes #568

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.
This commit is contained in:
Philip Cass
2015-02-14 14:01:21 +00:00
parent d7f2ac5a65
commit e3dc430931
36 changed files with 596 additions and 277 deletions
+29 -28
View File
@@ -1,6 +1,10 @@
package de.diddiz.util;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.Consumer;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import de.diddiz.LogBlock.config.WorldConfig;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -17,13 +21,10 @@ import org.bukkit.material.RedstoneTorch;
import org.bukkit.material.Torch;
import org.bukkit.material.TrapDoor;
import org.bukkit.material.TripwireHook;
import de.diddiz.LogBlock.Consumer;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
public class LoggingUtil {
public static void smartLogFallables(Consumer consumer, String playerName, Block origin) {
public static void smartLogFallables(Consumer consumer, Actor actor, Block origin) {
WorldConfig wcfg = getWorldConfig(origin.getWorld());
if (wcfg == null) return;
@@ -35,7 +36,7 @@ public class LoggingUtil {
while (BukkitUtils.getRelativeTopFallables().contains(checkBlock.getType())) {
// Record this block as falling
consumer.queueBlockBreak(playerName, checkBlock.getState());
consumer.queueBlockBreak(actor, checkBlock.getState());
// Guess where the block is going (This could be thrown of by explosions, but it is better than nothing)
Location loc = origin.getLocation();
@@ -52,9 +53,9 @@ public class LoggingUtil {
if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
finalLoc.add(0, up, 0); // Add this here after checking for block breakers
if (finalLoc.getBlock().getType() == Material.AIR || BukkitUtils.getRelativeTopFallables().contains(finalLoc.getBlock().getType())) {
consumer.queueBlockPlace(playerName, finalLoc, checkBlock.getTypeId(), checkBlock.getData());
consumer.queueBlockPlace(actor, finalLoc, checkBlock.getTypeId(), checkBlock.getData());
} else {
consumer.queueBlockReplace(playerName, finalLoc, finalLoc.getBlock().getTypeId(), finalLoc.getBlock().getData(), checkBlock.getTypeId(), checkBlock.getData());
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getTypeId(), finalLoc.getBlock().getData(), checkBlock.getTypeId(), checkBlock.getData());
}
up++;
}
@@ -64,7 +65,7 @@ public class LoggingUtil {
}
}
public static void smartLogBlockBreak(Consumer consumer, String playerName, Block origin) {
public static void smartLogBlockBreak(Consumer consumer, Actor actor, Block origin) {
WorldConfig wcfg = getWorldConfig(origin.getWorld());
if (wcfg == null) return;
@@ -72,7 +73,7 @@ public class LoggingUtil {
Block checkBlock = origin.getRelative(BlockFace.UP);
if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getType())) {
if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
consumer.queueSignBreak(playerName, (Sign) checkBlock.getState());
consumer.queueSignBreak(actor, (Sign) checkBlock.getState());
} else if (checkBlock.getType() == Material.IRON_DOOR_BLOCK || checkBlock.getType() == Material.WOODEN_DOOR) {
Block doorBlock = checkBlock;
// If the doorBlock is the top half a door the player simply punched a door
@@ -81,9 +82,9 @@ public class LoggingUtil {
doorBlock = doorBlock.getRelative(BlockFace.UP);
// Fall back check just in case the top half wasn't a door
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
consumer.queueBlockBreak(playerName, doorBlock.getState());
consumer.queueBlockBreak(actor, doorBlock.getState());
}
consumer.queueBlockBreak(playerName, checkBlock.getState());
consumer.queueBlockBreak(actor, checkBlock.getState());
}
} else if (checkBlock.getType() == Material.DOUBLE_PLANT) {
Block plantBlock = checkBlock;
@@ -93,12 +94,12 @@ public class LoggingUtil {
plantBlock = plantBlock.getRelative(BlockFace.UP);
// Fall back check just in case the top half wasn't a plant
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
consumer.queueBlockBreak(playerName, plantBlock.getState());
consumer.queueBlockBreak(actor, plantBlock.getState());
}
consumer.queueBlockBreak(playerName, checkBlock.getState());
consumer.queueBlockBreak(actor, checkBlock.getState());
}
} else {
consumer.queueBlockBreak(playerName, checkBlock.getState());
consumer.queueBlockBreak(actor, checkBlock.getState());
}
}
@@ -112,56 +113,56 @@ public class LoggingUtil {
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
if (blockState.getBlock().getRelative(((RedstoneTorch) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
case TORCH:
if (blockState.getBlock().getRelative(((Torch) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
case COCOA:
if (blockState.getBlock().getRelative(((CocoaPlant) data).getAttachedFace().getOppositeFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
case LADDER:
if (blockState.getBlock().getRelative(((Ladder) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
case LEVER:
if (blockState.getBlock().getRelative(((Lever) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
case TRIPWIRE_HOOK:
if (blockState.getBlock().getRelative(((TripwireHook) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
case WOOD_BUTTON:
case STONE_BUTTON:
if (blockState.getBlock().getRelative(((Button) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
case WALL_SIGN:
if (blockState.getBlock().getRelative(((org.bukkit.material.Sign) data).getAttachedFace()).equals(origin)) {
if (wcfg.isLogging(Logging.SIGNTEXT)) {
consumer.queueSignBreak(playerName, (Sign) blockState);
consumer.queueSignBreak(actor, (Sign) blockState);
} else {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
}
break;
case TRAP_DOOR:
if (blockState.getBlock().getRelative(((TrapDoor) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
}
break;
default:
consumer.queueBlockBreak(playerName, blockState);
consumer.queueBlockBreak(actor, blockState);
break;
}
}
@@ -179,7 +180,7 @@ public class LoggingUtil {
}
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
consumer.queueBlockBreak(playerName, doorBlock.getState());
consumer.queueBlockBreak(actor, doorBlock.getState());
}
} else if (origin.getType() == Material.DOUBLE_PLANT) { // Special double plant check
Block plantBlock = origin;
@@ -192,11 +193,11 @@ public class LoggingUtil {
}
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
consumer.queueBlockBreak(playerName, plantBlock.getState());
consumer.queueBlockBreak(actor, plantBlock.getState());
}
}
// Do this down here so that the block is added after blocks sitting on it
consumer.queueBlockBreak(playerName, origin.getState());
consumer.queueBlockBreak(actor, origin.getState());
}
}