Added logging for dragon egg teleportation (#303)

This commit is contained in:
Intelli 2022-12-19 16:05:02 -07:00
parent 97eb0d777b
commit 5eabee6504
2 changed files with 61 additions and 6 deletions

View File

@ -87,6 +87,39 @@ public final class BlockFromToListener extends Queue implements Listener {
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { unixtimestamp, f, type });
Queue.queueBlockPlace(f, toBlock.getState(), block.getType(), toBlockState, type, -1, 0, blockData.getAsString());
}
else if (type.equals(Material.DRAGON_EGG)) {
Location location = block.getLocation();
int worldId = Util.getWorldId(location.getWorld().getName());
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
String coordinates = x + "." + y + "." + z + "." + worldId + "." + type.name();
String user = "#entity";
Object[] data = CacheHandler.interactCache.get(coordinates);
if (data != null && data[1] == Material.DRAGON_EGG) {
long newTime = System.currentTimeMillis();
long oldTime = (long) data[0];
if ((newTime - oldTime) < 20) { // 50ms = 1 tick
user = (String) data[2];
}
CacheHandler.interactCache.remove(coordinates);
}
if (Config.getConfig(block.getWorld()).BLOCK_BREAK) {
Queue.queueBlockBreak(user, block.getState(), block.getType(), block.getBlockData().getAsString(), 0);
}
if (Config.getConfig(block.getWorld()).BLOCK_PLACE) {
Block toBlock = event.getToBlock();
BlockState toBlockState = toBlock.getState();
if (Config.getConfig(world).BLOCK_MOVEMENT) {
toBlockState = BlockUtil.gravityScan(toBlock.getLocation(), type, user).getState();
}
Queue.queueBlockPlace(user, toBlockState, block.getType(), toBlockState, type, -1, 0, blockData.getAsString());
}
}
}
}

View File

@ -528,13 +528,20 @@ public final class PlayerInteractListener extends Queue implements Listener {
/* Logging for players punching out fire blocks. */
if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
World world = event.getClickedBlock().getWorld();
if (event.useInteractedBlock() != Event.Result.DENY && Config.getConfig(world).BLOCK_BREAK) {
Block relativeBlock = event.getClickedBlock().getRelative(event.getBlockFace());
if (event.useInteractedBlock() != Event.Result.DENY) {
Block block = event.getClickedBlock();
if (block.getType() == Material.DRAGON_EGG) {
clickedDragonEgg(event.getPlayer(), block);
}
if (BlockGroup.FIRE.contains(relativeBlock.getType())) {
Player player = event.getPlayer();
Material type = relativeBlock.getType();
Queue.queueBlockBreak(player.getName(), relativeBlock.getState(), type, relativeBlock.getBlockData().getAsString(), 0);
if (Config.getConfig(world).BLOCK_BREAK) {
Block relativeBlock = event.getClickedBlock().getRelative(event.getBlockFace());
if (BlockGroup.FIRE.contains(relativeBlock.getType())) {
Player player = event.getPlayer();
Material type = relativeBlock.getType();
Queue.queueBlockBreak(player.getName(), relativeBlock.getState(), type, relativeBlock.getBlockData().getAsString(), 0);
}
}
}
}
@ -663,6 +670,9 @@ public final class PlayerInteractListener extends Queue implements Listener {
}
}
}
else if (type == Material.DRAGON_EGG) {
clickedDragonEgg(player, block);
}
if (isCake || type == Material.CAKE) {
boolean placeCandle = false;
@ -802,4 +812,16 @@ public final class PlayerInteractListener extends Queue implements Listener {
}
}
}
private void clickedDragonEgg(Player player, Block block) {
Location location = block.getLocation();
long time = System.currentTimeMillis();
int wid = Util.getWorldId(location.getWorld().getName());
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
String coordinates = x + "." + y + "." + z + "." + wid + "." + Material.DRAGON_EGG.name();
CacheHandler.interactCache.put(coordinates, new Object[] { time, Material.DRAGON_EGG, player.getName() });
}
}