forked from LogBlock/LogBlock
Fix line endings
This commit is contained in:
@ -1,182 +1,182 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import static de.diddiz.LogBlock.util.BukkitUtils.entityName;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class Actor {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.UUID != null ? this.UUID.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Actor other = (Actor) obj;
|
||||
return (this.UUID == null) ? (other.UUID == null) : this.UUID.equals(other.UUID);
|
||||
}
|
||||
|
||||
final String name;
|
||||
final String UUID;
|
||||
final Location blockLocation;
|
||||
final Entity entity;
|
||||
|
||||
public Actor(String name, String UUID) {
|
||||
this.name = name;
|
||||
this.UUID = UUID == null ? "unknown" : (UUID.length() > 36 ? UUID.substring(0, 36) : UUID);
|
||||
this.blockLocation = null;
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, String UUID, Block block) {
|
||||
this.name = name;
|
||||
this.UUID = UUID == null ? "unknown" : (UUID.length() > 36 ? UUID.substring(0, 36) : UUID);
|
||||
this.blockLocation = block == null ? null : block.getLocation();
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, java.util.UUID UUID) {
|
||||
this.name = name;
|
||||
this.UUID = UUID.toString();
|
||||
this.blockLocation = null;
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, java.util.UUID UUID, Block block) {
|
||||
this.name = name;
|
||||
this.UUID = UUID.toString();
|
||||
this.blockLocation = block == null ? null : block.getLocation();
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, java.util.UUID UUID, Entity entity) {
|
||||
this.name = name;
|
||||
this.UUID = UUID.toString();
|
||||
this.blockLocation = null;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Actor(String name) {
|
||||
this(name, generateUUID(name));
|
||||
}
|
||||
|
||||
public Actor(String name, Block block) {
|
||||
this(name, generateUUID(name), block);
|
||||
}
|
||||
|
||||
public Actor(String name, Entity entity) {
|
||||
this.name = name;
|
||||
this.UUID = generateUUID(name);
|
||||
this.blockLocation = null;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Actor(ResultSet rs) throws SQLException {
|
||||
this(rs.getString("playername"), rs.getString("UUID"));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getUUID() {
|
||||
return UUID;
|
||||
}
|
||||
|
||||
public Location getBlockLocation() {
|
||||
return blockLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* The acting entity object (if known)
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static Actor actorFromEntity(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
return new Actor(entityName(entity), entity.getUniqueId(), entity);
|
||||
}
|
||||
if (entity instanceof Projectile) {
|
||||
ProjectileSource shooter = ((Projectile) entity).getShooter();
|
||||
if (shooter != null) {
|
||||
return actorFromProjectileSource(shooter);
|
||||
}
|
||||
}
|
||||
return new Actor(entityName(entity), entity);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Actor actorFromEntity(EntityType entity) {
|
||||
return new Actor(entity.name());
|
||||
}
|
||||
|
||||
public static Actor actorFromProjectileSource(ProjectileSource psource) {
|
||||
if (psource instanceof Entity) {
|
||||
return actorFromEntity((Entity) psource);
|
||||
}
|
||||
if (psource instanceof BlockProjectileSource) {
|
||||
return new Actor(((BlockProjectileSource) psource).getBlock().getType().toString());
|
||||
} else {
|
||||
return new Actor(psource.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an Actor object from a String name, trying to guess if it's an online player
|
||||
* and if so, setting the UUID accordingly. This only checks against currently online
|
||||
* players and is a "best effort" attempt for use with the pre-UUID API
|
||||
* <p>
|
||||
* If you know something is an entity (player or otherwise) use the {@link #actorFromEntity(org.bukkit.entity.Entity) }
|
||||
* or {@link #actorFromEntity(org.bukkit.entity.EntityType) } methods
|
||||
* <p>
|
||||
* If you know something is a server effect (like gravity) use {@link #Actor(java.lang.String)}
|
||||
*
|
||||
* @deprecated Only use this if you have a String of unknown origin
|
||||
*
|
||||
* @param actorName
|
||||
* String of unknown origin
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static Actor actorFromString(String actorName) {
|
||||
Player p = Bukkit.getServer().getPlayerExact(actorName);
|
||||
if (p != null) {
|
||||
return actorFromEntity(p);
|
||||
}
|
||||
// No player found online with that name, assuming non-player entity/effect
|
||||
return new Actor(actorName);
|
||||
}
|
||||
|
||||
public static boolean isValidUUID(String uuid) {
|
||||
try {
|
||||
java.util.UUID.fromString(uuid);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateUUID(String name) {
|
||||
return "log_" + name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.projectiles.BlockProjectileSource;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
import static de.diddiz.LogBlock.util.BukkitUtils.entityName;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class Actor {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.UUID != null ? this.UUID.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Actor other = (Actor) obj;
|
||||
return (this.UUID == null) ? (other.UUID == null) : this.UUID.equals(other.UUID);
|
||||
}
|
||||
|
||||
final String name;
|
||||
final String UUID;
|
||||
final Location blockLocation;
|
||||
final Entity entity;
|
||||
|
||||
public Actor(String name, String UUID) {
|
||||
this.name = name;
|
||||
this.UUID = UUID == null ? "unknown" : (UUID.length() > 36 ? UUID.substring(0, 36) : UUID);
|
||||
this.blockLocation = null;
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, String UUID, Block block) {
|
||||
this.name = name;
|
||||
this.UUID = UUID == null ? "unknown" : (UUID.length() > 36 ? UUID.substring(0, 36) : UUID);
|
||||
this.blockLocation = block == null ? null : block.getLocation();
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, java.util.UUID UUID) {
|
||||
this.name = name;
|
||||
this.UUID = UUID.toString();
|
||||
this.blockLocation = null;
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, java.util.UUID UUID, Block block) {
|
||||
this.name = name;
|
||||
this.UUID = UUID.toString();
|
||||
this.blockLocation = block == null ? null : block.getLocation();
|
||||
this.entity = null;
|
||||
}
|
||||
|
||||
public Actor(String name, java.util.UUID UUID, Entity entity) {
|
||||
this.name = name;
|
||||
this.UUID = UUID.toString();
|
||||
this.blockLocation = null;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Actor(String name) {
|
||||
this(name, generateUUID(name));
|
||||
}
|
||||
|
||||
public Actor(String name, Block block) {
|
||||
this(name, generateUUID(name), block);
|
||||
}
|
||||
|
||||
public Actor(String name, Entity entity) {
|
||||
this.name = name;
|
||||
this.UUID = generateUUID(name);
|
||||
this.blockLocation = null;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Actor(ResultSet rs) throws SQLException {
|
||||
this(rs.getString("playername"), rs.getString("UUID"));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getUUID() {
|
||||
return UUID;
|
||||
}
|
||||
|
||||
public Location getBlockLocation() {
|
||||
return blockLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* The acting entity object (if known)
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static Actor actorFromEntity(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
return new Actor(entityName(entity), entity.getUniqueId(), entity);
|
||||
}
|
||||
if (entity instanceof Projectile) {
|
||||
ProjectileSource shooter = ((Projectile) entity).getShooter();
|
||||
if (shooter != null) {
|
||||
return actorFromProjectileSource(shooter);
|
||||
}
|
||||
}
|
||||
return new Actor(entityName(entity), entity);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Actor actorFromEntity(EntityType entity) {
|
||||
return new Actor(entity.name());
|
||||
}
|
||||
|
||||
public static Actor actorFromProjectileSource(ProjectileSource psource) {
|
||||
if (psource instanceof Entity) {
|
||||
return actorFromEntity((Entity) psource);
|
||||
}
|
||||
if (psource instanceof BlockProjectileSource) {
|
||||
return new Actor(((BlockProjectileSource) psource).getBlock().getType().toString());
|
||||
} else {
|
||||
return new Actor(psource.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an Actor object from a String name, trying to guess if it's an online player
|
||||
* and if so, setting the UUID accordingly. This only checks against currently online
|
||||
* players and is a "best effort" attempt for use with the pre-UUID API
|
||||
* <p>
|
||||
* If you know something is an entity (player or otherwise) use the {@link #actorFromEntity(org.bukkit.entity.Entity) }
|
||||
* or {@link #actorFromEntity(org.bukkit.entity.EntityType) } methods
|
||||
* <p>
|
||||
* If you know something is a server effect (like gravity) use {@link #Actor(java.lang.String)}
|
||||
*
|
||||
* @deprecated Only use this if you have a String of unknown origin
|
||||
*
|
||||
* @param actorName
|
||||
* String of unknown origin
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static Actor actorFromString(String actorName) {
|
||||
Player p = Bukkit.getServer().getPlayerExact(actorName);
|
||||
if (p != null) {
|
||||
return actorFromEntity(p);
|
||||
}
|
||||
// No player found online with that name, assuming non-player entity/effect
|
||||
return new Actor(actorName);
|
||||
}
|
||||
|
||||
public static boolean isValidUUID(String uuid) {
|
||||
try {
|
||||
java.util.UUID.fromString(uuid);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateUUID(String name) {
|
||||
return "log_" + name;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.autoClearLog;
|
||||
import static org.bukkit.Bukkit.*;
|
||||
|
||||
public class AutoClearLog implements Runnable {
|
||||
private final LogBlock logblock;
|
||||
|
||||
AutoClearLog(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final CommandsHandler handler = logblock.getCommandsHandler();
|
||||
for (final String paramStr : autoClearLog) {
|
||||
if (!logblock.isCompletelyEnabled()) {
|
||||
return; // do not try when plugin is disabled
|
||||
}
|
||||
try {
|
||||
final QueryParams params = new QueryParams(logblock, getConsoleSender(), Arrays.asList(paramStr.split(" ")));
|
||||
params.noForcedLimit = true;
|
||||
handler.new CommandClearLog(getServer().getConsoleSender(), params, false);
|
||||
} catch (final Exception ex) {
|
||||
getLogger().log(Level.SEVERE, "Failed to schedule auto ClearLog: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.autoClearLog;
|
||||
import static org.bukkit.Bukkit.*;
|
||||
|
||||
public class AutoClearLog implements Runnable {
|
||||
private final LogBlock logblock;
|
||||
|
||||
AutoClearLog(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final CommandsHandler handler = logblock.getCommandsHandler();
|
||||
for (final String paramStr : autoClearLog) {
|
||||
if (!logblock.isCompletelyEnabled()) {
|
||||
return; // do not try when plugin is disabled
|
||||
}
|
||||
try {
|
||||
final QueryParams params = new QueryParams(logblock, getConsoleSender(), Arrays.asList(paramStr.split(" ")));
|
||||
params.noForcedLimit = true;
|
||||
handler.new CommandClearLog(getServer().getConsoleSender(), params, false);
|
||||
} catch (final Exception ex) {
|
||||
getLogger().log(Level.SEVERE, "Failed to schedule auto ClearLog: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,272 +1,272 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.ActionColor.CREATE;
|
||||
import static de.diddiz.LogBlock.util.ActionColor.DESTROY;
|
||||
import static de.diddiz.LogBlock.util.ActionColor.INTERACT;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.createTextComponentWithColor;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyDate;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyLocation;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyMaterial;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyState;
|
||||
import static de.diddiz.LogBlock.util.TypeColor.DEFAULT;
|
||||
|
||||
import de.diddiz.LogBlock.blockstate.BlockStateCodecs;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.Utils;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Candle;
|
||||
import org.bukkit.block.data.type.Comparator;
|
||||
import org.bukkit.block.data.type.DaylightDetector;
|
||||
import org.bukkit.block.data.type.Lectern;
|
||||
import org.bukkit.block.data.type.NoteBlock;
|
||||
import org.bukkit.block.data.type.Repeater;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BlockChange implements LookupCacheElement {
|
||||
public final long id, date;
|
||||
public final Location loc;
|
||||
public final Actor actor;
|
||||
public final String playerName;
|
||||
public final int replacedMaterial, replacedData, typeMaterial, typeData;
|
||||
public final byte[] replacedState, typeState;
|
||||
public final ChestAccess ca;
|
||||
|
||||
public BlockChange(long date, Location loc, Actor actor, int replaced, int replacedData, byte[] replacedState, int type, int typeData, byte[] typeState, ChestAccess ca) {
|
||||
id = 0;
|
||||
this.date = date;
|
||||
this.loc = loc;
|
||||
this.actor = actor;
|
||||
this.replacedMaterial = replaced;
|
||||
this.replacedData = replacedData;
|
||||
this.replacedState = replacedState;
|
||||
this.typeMaterial = type;
|
||||
this.typeData = typeData;
|
||||
this.typeState = typeState;
|
||||
this.ca = ca;
|
||||
this.playerName = actor == null ? null : actor.getName();
|
||||
}
|
||||
|
||||
public BlockChange(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
loc = p.needCoords ? new Location(p.world, rs.getInt("x"), rs.getInt("y"), rs.getInt("z")) : null;
|
||||
actor = p.needPlayer ? new Actor(rs) : null;
|
||||
playerName = p.needPlayer ? rs.getString("playername") : null;
|
||||
replacedMaterial = p.needType ? rs.getInt("replaced") : 0;
|
||||
replacedData = p.needType ? rs.getInt("replacedData") : -1;
|
||||
typeMaterial = p.needType ? rs.getInt("type") : 0;
|
||||
typeData = p.needType ? rs.getInt("typeData") : -1;
|
||||
replacedState = p.needType ? rs.getBytes("replacedState") : null;
|
||||
typeState = p.needType ? rs.getBytes("typeState") : null;
|
||||
ChestAccess catemp = null;
|
||||
if (p.needChestAccess) {
|
||||
ItemStack stack = Utils.loadItemStack(rs.getBytes("item"));
|
||||
if (stack != null) {
|
||||
catemp = new ChestAccess(stack, rs.getBoolean("itemremove"), rs.getInt("itemtype"));
|
||||
}
|
||||
}
|
||||
ca = catemp;
|
||||
}
|
||||
|
||||
private BaseComponent getTypeDetails(BlockData type, byte[] typeState) {
|
||||
return getTypeDetails(type, typeState, null, null);
|
||||
}
|
||||
|
||||
private BaseComponent getTypeDetails(BlockData type, byte[] typeState, BlockData oldType, byte[] oldTypeState) {
|
||||
BaseComponent typeDetails = null;
|
||||
|
||||
if (BlockStateCodecs.hasCodec(type.getMaterial())) {
|
||||
try {
|
||||
typeDetails = BlockStateCodecs.getChangesAsComponent(type.getMaterial(), Utils.deserializeYamlConfiguration(typeState), type.equals(oldType) ? Utils.deserializeYamlConfiguration(oldTypeState) : null);
|
||||
} catch (Exception e) {
|
||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not parse BlockState for " + type.getMaterial(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeDetails == null) {
|
||||
return new TextComponent("");
|
||||
} else {
|
||||
TextComponent component = new TextComponent(" ");
|
||||
component.addExtra(typeDetails);
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return BaseComponent.toPlainText(getLogMessage(-1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
if (actor != null) {
|
||||
msg.addExtra(actor.getName());
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
BlockData type = getBlockSet();
|
||||
BlockData replaced = getBlockReplaced();
|
||||
if (type == null || replaced == null) {
|
||||
msg.addExtra("did an unknown block modification");
|
||||
return new BaseComponent[] { msg };
|
||||
}
|
||||
|
||||
// Process type details once for later use.
|
||||
BaseComponent typeDetails = getTypeDetails(type, typeState, replaced, replacedState);
|
||||
BaseComponent replacedDetails = getTypeDetails(replaced, replacedState);
|
||||
|
||||
if (type.getMaterial().equals(replaced.getMaterial()) || (type.getMaterial() == Material.CAKE && BukkitUtils.isCandleCake(replaced.getMaterial()))) {
|
||||
if (BukkitUtils.isEmpty(type.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("did an unspecified action", INTERACT.getColor()));
|
||||
} else if (ca != null) {
|
||||
if (ca.itemStack == null) {
|
||||
msg.addExtra(createTextComponentWithColor("looked inside ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (ca.remove) {
|
||||
msg.addExtra(createTextComponentWithColor("took ", DESTROY.getColor()));
|
||||
msg.addExtra(BukkitUtils.toString(ca.itemStack));
|
||||
msg.addExtra(createTextComponentWithColor(" from ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("put ", CREATE.getColor()));
|
||||
msg.addExtra(BukkitUtils.toString(ca.itemStack));
|
||||
msg.addExtra(createTextComponentWithColor(" into ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
}
|
||||
} else if (type instanceof Waterlogged && ((Waterlogged) type).isWaterlogged() != ((Waterlogged) replaced).isWaterlogged()) {
|
||||
if (((Waterlogged) type).isWaterlogged()) {
|
||||
msg.addExtra(createTextComponentWithColor("waterlogged ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("dried ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
}
|
||||
} else if (BukkitUtils.getContainerBlocks().contains(type.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("opened ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type instanceof Openable && ((Openable) type).isOpen() != ((Openable) replaced).isOpen()) {
|
||||
// Door, Trapdoor, Fence gate
|
||||
msg.addExtra(createTextComponentWithColor(((Openable) type).isOpen() ? "opened " : "closed ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.LEVER && ((Switch) type).isPowered() != ((Switch) replaced).isPowered()) {
|
||||
msg.addExtra(createTextComponentWithColor("switched ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(((Switch) type).isPowered() ? " on" : " off"));
|
||||
} else if (type instanceof Switch && ((Switch) type).isPowered() != ((Switch) replaced).isPowered()) {
|
||||
msg.addExtra(createTextComponentWithColor("pressed ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.CAKE) {
|
||||
msg.addExtra(createTextComponentWithColor("ate a piece of ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.NOTE_BLOCK) {
|
||||
Note note = ((NoteBlock) type).getNote();
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(note.getTone().name() + (note.isSharped() ? "#" : "")));
|
||||
} else if (type.getMaterial() == Material.REPEATER) {
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(((Repeater) type).getDelay()));
|
||||
msg.addExtra(createTextComponentWithColor(" ticks delay", DEFAULT.getColor()));
|
||||
} else if (type.getMaterial() == Material.COMPARATOR) {
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(((Comparator) type).getMode()));
|
||||
} else if (type.getMaterial() == Material.DAYLIGHT_DETECTOR) {
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(((DaylightDetector) type).isInverted() ? "inverted" : "normal"));
|
||||
} else if (type instanceof Lectern) {
|
||||
msg.addExtra(createTextComponentWithColor("changed the book on a ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to");
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else if (type instanceof Powerable) {
|
||||
msg.addExtra(createTextComponentWithColor("stepped on ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.TRIPWIRE) {
|
||||
msg.addExtra(createTextComponentWithColor("ran into ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type instanceof Sign || type instanceof WallSign) {
|
||||
msg.addExtra(createTextComponentWithColor("edited a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(createTextComponentWithColor(" to", CREATE.getColor()));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else if (type instanceof Candle && ((Candle) type).getCandles() != ((Candle) replaced).getCandles()) {
|
||||
msg.addExtra(createTextComponentWithColor("added a candle to ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if ((type instanceof Candle || BukkitUtils.isCandleCake(type.getMaterial())) && ((Lightable) type).isLit() != ((Lightable) replaced).isLit()) {
|
||||
if (((Lightable) type).isLit()) {
|
||||
msg.addExtra(createTextComponentWithColor("lit a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("extinguished a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
}
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(replaced));
|
||||
msg.addExtra(prettyState(replacedDetails));
|
||||
msg.addExtra(createTextComponentWithColor(" with ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
}
|
||||
} else if (BukkitUtils.isEmpty(type.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("destroyed ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(replaced));
|
||||
msg.addExtra(prettyState(replacedDetails));
|
||||
} else if (BukkitUtils.isEmpty(replaced.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("created ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(replaced));
|
||||
msg.addExtra(prettyState(replacedDetails));
|
||||
msg.addExtra(createTextComponentWithColor(" with ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
}
|
||||
if (loc != null) {
|
||||
msg.addExtra(" at ");
|
||||
msg.addExtra(prettyLocation(loc, entry));
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
}
|
||||
|
||||
public BlockData getBlockReplaced() {
|
||||
return MaterialConverter.getBlockData(replacedMaterial, replacedData);
|
||||
}
|
||||
|
||||
public BlockData getBlockSet() {
|
||||
return MaterialConverter.getBlockData(typeMaterial, typeData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.ActionColor.CREATE;
|
||||
import static de.diddiz.LogBlock.util.ActionColor.DESTROY;
|
||||
import static de.diddiz.LogBlock.util.ActionColor.INTERACT;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.createTextComponentWithColor;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyDate;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyLocation;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyMaterial;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyState;
|
||||
import static de.diddiz.LogBlock.util.TypeColor.DEFAULT;
|
||||
|
||||
import de.diddiz.LogBlock.blockstate.BlockStateCodecs;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.Utils;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.Powerable;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.block.data.type.Candle;
|
||||
import org.bukkit.block.data.type.Comparator;
|
||||
import org.bukkit.block.data.type.DaylightDetector;
|
||||
import org.bukkit.block.data.type.Lectern;
|
||||
import org.bukkit.block.data.type.NoteBlock;
|
||||
import org.bukkit.block.data.type.Repeater;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BlockChange implements LookupCacheElement {
|
||||
public final long id, date;
|
||||
public final Location loc;
|
||||
public final Actor actor;
|
||||
public final String playerName;
|
||||
public final int replacedMaterial, replacedData, typeMaterial, typeData;
|
||||
public final byte[] replacedState, typeState;
|
||||
public final ChestAccess ca;
|
||||
|
||||
public BlockChange(long date, Location loc, Actor actor, int replaced, int replacedData, byte[] replacedState, int type, int typeData, byte[] typeState, ChestAccess ca) {
|
||||
id = 0;
|
||||
this.date = date;
|
||||
this.loc = loc;
|
||||
this.actor = actor;
|
||||
this.replacedMaterial = replaced;
|
||||
this.replacedData = replacedData;
|
||||
this.replacedState = replacedState;
|
||||
this.typeMaterial = type;
|
||||
this.typeData = typeData;
|
||||
this.typeState = typeState;
|
||||
this.ca = ca;
|
||||
this.playerName = actor == null ? null : actor.getName();
|
||||
}
|
||||
|
||||
public BlockChange(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
loc = p.needCoords ? new Location(p.world, rs.getInt("x"), rs.getInt("y"), rs.getInt("z")) : null;
|
||||
actor = p.needPlayer ? new Actor(rs) : null;
|
||||
playerName = p.needPlayer ? rs.getString("playername") : null;
|
||||
replacedMaterial = p.needType ? rs.getInt("replaced") : 0;
|
||||
replacedData = p.needType ? rs.getInt("replacedData") : -1;
|
||||
typeMaterial = p.needType ? rs.getInt("type") : 0;
|
||||
typeData = p.needType ? rs.getInt("typeData") : -1;
|
||||
replacedState = p.needType ? rs.getBytes("replacedState") : null;
|
||||
typeState = p.needType ? rs.getBytes("typeState") : null;
|
||||
ChestAccess catemp = null;
|
||||
if (p.needChestAccess) {
|
||||
ItemStack stack = Utils.loadItemStack(rs.getBytes("item"));
|
||||
if (stack != null) {
|
||||
catemp = new ChestAccess(stack, rs.getBoolean("itemremove"), rs.getInt("itemtype"));
|
||||
}
|
||||
}
|
||||
ca = catemp;
|
||||
}
|
||||
|
||||
private BaseComponent getTypeDetails(BlockData type, byte[] typeState) {
|
||||
return getTypeDetails(type, typeState, null, null);
|
||||
}
|
||||
|
||||
private BaseComponent getTypeDetails(BlockData type, byte[] typeState, BlockData oldType, byte[] oldTypeState) {
|
||||
BaseComponent typeDetails = null;
|
||||
|
||||
if (BlockStateCodecs.hasCodec(type.getMaterial())) {
|
||||
try {
|
||||
typeDetails = BlockStateCodecs.getChangesAsComponent(type.getMaterial(), Utils.deserializeYamlConfiguration(typeState), type.equals(oldType) ? Utils.deserializeYamlConfiguration(oldTypeState) : null);
|
||||
} catch (Exception e) {
|
||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not parse BlockState for " + type.getMaterial(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeDetails == null) {
|
||||
return new TextComponent("");
|
||||
} else {
|
||||
TextComponent component = new TextComponent(" ");
|
||||
component.addExtra(typeDetails);
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return BaseComponent.toPlainText(getLogMessage(-1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
if (actor != null) {
|
||||
msg.addExtra(actor.getName());
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
BlockData type = getBlockSet();
|
||||
BlockData replaced = getBlockReplaced();
|
||||
if (type == null || replaced == null) {
|
||||
msg.addExtra("did an unknown block modification");
|
||||
return new BaseComponent[] { msg };
|
||||
}
|
||||
|
||||
// Process type details once for later use.
|
||||
BaseComponent typeDetails = getTypeDetails(type, typeState, replaced, replacedState);
|
||||
BaseComponent replacedDetails = getTypeDetails(replaced, replacedState);
|
||||
|
||||
if (type.getMaterial().equals(replaced.getMaterial()) || (type.getMaterial() == Material.CAKE && BukkitUtils.isCandleCake(replaced.getMaterial()))) {
|
||||
if (BukkitUtils.isEmpty(type.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("did an unspecified action", INTERACT.getColor()));
|
||||
} else if (ca != null) {
|
||||
if (ca.itemStack == null) {
|
||||
msg.addExtra(createTextComponentWithColor("looked inside ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (ca.remove) {
|
||||
msg.addExtra(createTextComponentWithColor("took ", DESTROY.getColor()));
|
||||
msg.addExtra(BukkitUtils.toString(ca.itemStack));
|
||||
msg.addExtra(createTextComponentWithColor(" from ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("put ", CREATE.getColor()));
|
||||
msg.addExtra(BukkitUtils.toString(ca.itemStack));
|
||||
msg.addExtra(createTextComponentWithColor(" into ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
}
|
||||
} else if (type instanceof Waterlogged && ((Waterlogged) type).isWaterlogged() != ((Waterlogged) replaced).isWaterlogged()) {
|
||||
if (((Waterlogged) type).isWaterlogged()) {
|
||||
msg.addExtra(createTextComponentWithColor("waterlogged ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("dried ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
}
|
||||
} else if (BukkitUtils.getContainerBlocks().contains(type.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("opened ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type instanceof Openable && ((Openable) type).isOpen() != ((Openable) replaced).isOpen()) {
|
||||
// Door, Trapdoor, Fence gate
|
||||
msg.addExtra(createTextComponentWithColor(((Openable) type).isOpen() ? "opened " : "closed ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.LEVER && ((Switch) type).isPowered() != ((Switch) replaced).isPowered()) {
|
||||
msg.addExtra(createTextComponentWithColor("switched ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(((Switch) type).isPowered() ? " on" : " off"));
|
||||
} else if (type instanceof Switch && ((Switch) type).isPowered() != ((Switch) replaced).isPowered()) {
|
||||
msg.addExtra(createTextComponentWithColor("pressed ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.CAKE) {
|
||||
msg.addExtra(createTextComponentWithColor("ate a piece of ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.NOTE_BLOCK) {
|
||||
Note note = ((NoteBlock) type).getNote();
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(note.getTone().name() + (note.isSharped() ? "#" : "")));
|
||||
} else if (type.getMaterial() == Material.REPEATER) {
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(((Repeater) type).getDelay()));
|
||||
msg.addExtra(createTextComponentWithColor(" ticks delay", DEFAULT.getColor()));
|
||||
} else if (type.getMaterial() == Material.COMPARATOR) {
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(((Comparator) type).getMode()));
|
||||
} else if (type.getMaterial() == Material.DAYLIGHT_DETECTOR) {
|
||||
msg.addExtra(createTextComponentWithColor("set ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to ");
|
||||
msg.addExtra(prettyState(((DaylightDetector) type).isInverted() ? "inverted" : "normal"));
|
||||
} else if (type instanceof Lectern) {
|
||||
msg.addExtra(createTextComponentWithColor("changed the book on a ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(" to");
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else if (type instanceof Powerable) {
|
||||
msg.addExtra(createTextComponentWithColor("stepped on ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type.getMaterial() == Material.TRIPWIRE) {
|
||||
msg.addExtra(createTextComponentWithColor("ran into ", INTERACT.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if (type instanceof Sign || type instanceof WallSign) {
|
||||
msg.addExtra(createTextComponentWithColor("edited a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(createTextComponentWithColor(" to", CREATE.getColor()));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else if (type instanceof Candle && ((Candle) type).getCandles() != ((Candle) replaced).getCandles()) {
|
||||
msg.addExtra(createTextComponentWithColor("added a candle to ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else if ((type instanceof Candle || BukkitUtils.isCandleCake(type.getMaterial())) && ((Lightable) type).isLit() != ((Lightable) replaced).isLit()) {
|
||||
if (((Lightable) type).isLit()) {
|
||||
msg.addExtra(createTextComponentWithColor("lit a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("extinguished a ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
}
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(replaced));
|
||||
msg.addExtra(prettyState(replacedDetails));
|
||||
msg.addExtra(createTextComponentWithColor(" with ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
}
|
||||
} else if (BukkitUtils.isEmpty(type.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("destroyed ", DESTROY.getColor()));
|
||||
msg.addExtra(prettyMaterial(replaced));
|
||||
msg.addExtra(prettyState(replacedDetails));
|
||||
} else if (BukkitUtils.isEmpty(replaced.getMaterial())) {
|
||||
msg.addExtra(createTextComponentWithColor("created ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
} else {
|
||||
msg.addExtra(createTextComponentWithColor("replaced ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(replaced));
|
||||
msg.addExtra(prettyState(replacedDetails));
|
||||
msg.addExtra(createTextComponentWithColor(" with ", CREATE.getColor()));
|
||||
msg.addExtra(prettyMaterial(type));
|
||||
msg.addExtra(prettyState(typeDetails));
|
||||
}
|
||||
if (loc != null) {
|
||||
msg.addExtra(" at ");
|
||||
msg.addExtra(prettyLocation(loc, entry));
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
}
|
||||
|
||||
public BlockData getBlockReplaced() {
|
||||
return MaterialConverter.getBlockData(replacedMaterial, replacedData);
|
||||
}
|
||||
|
||||
public BlockData getBlockSet() {
|
||||
return MaterialConverter.getBlockData(typeMaterial, typeData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +1,59 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.checkText;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.brackets;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyDate;
|
||||
|
||||
import de.diddiz.LogBlock.util.MessagingUtil;
|
||||
import de.diddiz.LogBlock.util.MessagingUtil.BracketType;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class ChatMessage implements LookupCacheElement {
|
||||
final long id, date;
|
||||
final String playerName, message;
|
||||
final Actor player;
|
||||
|
||||
public ChatMessage(Actor player, String message) {
|
||||
id = 0;
|
||||
date = System.currentTimeMillis() / 1000;
|
||||
this.player = player;
|
||||
this.message = checkText(message);
|
||||
this.playerName = player == null ? null : player.getName();
|
||||
}
|
||||
|
||||
public ChatMessage(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
player = p.needPlayer ? new Actor(rs) : null;
|
||||
playerName = p.needPlayer ? rs.getString("playername") : null;
|
||||
message = p.needMessage ? rs.getString("message") : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
if (playerName != null) {
|
||||
msg.addExtra(brackets(BracketType.ANGLE, MessagingUtil.createTextComponentWithColor(playerName, net.md_5.bungee.api.ChatColor.WHITE)));
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
if (message != null) {
|
||||
for (BaseComponent messageComponent : TextComponent.fromLegacyText(message)) {
|
||||
msg.addExtra(messageComponent);
|
||||
}
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.checkText;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.brackets;
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyDate;
|
||||
|
||||
import de.diddiz.LogBlock.util.MessagingUtil;
|
||||
import de.diddiz.LogBlock.util.MessagingUtil.BracketType;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class ChatMessage implements LookupCacheElement {
|
||||
final long id, date;
|
||||
final String playerName, message;
|
||||
final Actor player;
|
||||
|
||||
public ChatMessage(Actor player, String message) {
|
||||
id = 0;
|
||||
date = System.currentTimeMillis() / 1000;
|
||||
this.player = player;
|
||||
this.message = checkText(message);
|
||||
this.playerName = player == null ? null : player.getName();
|
||||
}
|
||||
|
||||
public ChatMessage(ResultSet rs, QueryParams p) throws SQLException {
|
||||
id = p.needId ? rs.getLong("id") : 0;
|
||||
date = p.needDate ? rs.getTimestamp("date").getTime() : 0;
|
||||
player = p.needPlayer ? new Actor(rs) : null;
|
||||
playerName = p.needPlayer ? rs.getString("playername") : null;
|
||||
message = p.needMessage ? rs.getString("message") : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
TextComponent msg = new TextComponent();
|
||||
if (date > 0) {
|
||||
msg.addExtra(prettyDate(date));
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
if (playerName != null) {
|
||||
msg.addExtra(brackets(BracketType.ANGLE, MessagingUtil.createTextComponentWithColor(playerName, net.md_5.bungee.api.ChatColor.WHITE)));
|
||||
msg.addExtra(" ");
|
||||
}
|
||||
if (message != null) {
|
||||
for (BaseComponent messageComponent : TextComponent.fromLegacyText(message)) {
|
||||
msg.addExtra(messageComponent);
|
||||
}
|
||||
}
|
||||
return new BaseComponent[] { msg };
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ChestAccess {
|
||||
public final ItemStack itemStack;
|
||||
public final boolean remove;
|
||||
public final int itemType;
|
||||
|
||||
public ChestAccess(ItemStack itemStack, boolean remove, int itemType) {
|
||||
this.itemStack = itemStack;
|
||||
this.remove = remove;
|
||||
this.itemType = itemType;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ChestAccess {
|
||||
public final ItemStack itemStack;
|
||||
public final boolean remove;
|
||||
public final int itemType;
|
||||
|
||||
public ChestAccess(ItemStack itemStack, boolean remove, int itemType) {
|
||||
this.itemStack = itemStack;
|
||||
this.remove = remove;
|
||||
this.itemType = itemType;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,147 +1,147 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.Utils.newline;
|
||||
|
||||
import de.diddiz.LogBlock.util.Utils.ExtensionFilenameFilter;
|
||||
import java.io.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DumpedLogImporter implements Runnable {
|
||||
private final LogBlock logblock;
|
||||
|
||||
DumpedLogImporter(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final File[] imports = new File(logblock.getDataFolder(), "import").listFiles(new ExtensionFilenameFilter("sql"));
|
||||
if (imports != null && imports.length > 0) {
|
||||
logblock.getLogger().info("Found " + imports.length + " imports.");
|
||||
Arrays.sort(imports, new ImportsComparator());
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = logblock.getConnection();
|
||||
if (conn == null) {
|
||||
return;
|
||||
}
|
||||
conn.setAutoCommit(false);
|
||||
final Statement st = conn.createStatement();
|
||||
final BufferedWriter writer = new BufferedWriter(new FileWriter(new File(logblock.getDataFolder(), "import/failed.txt")));
|
||||
int successes = 0, errors = 0;
|
||||
try {
|
||||
for (final File sqlFile : imports) {
|
||||
String line = null;
|
||||
try {
|
||||
logblock.getLogger().info("Trying to import " + sqlFile.getName() + " ...");
|
||||
// first try batch import the whole file
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(sqlFile));
|
||||
int statements = 0;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.endsWith(";")) {
|
||||
line = line.substring(0, line.length() - 1);
|
||||
}
|
||||
if (!line.isEmpty()) {
|
||||
statements++;
|
||||
st.addBatch(line);
|
||||
}
|
||||
}
|
||||
st.executeBatch();
|
||||
conn.commit();
|
||||
reader.close();
|
||||
sqlFile.delete();
|
||||
successes += statements;
|
||||
logblock.getLogger().info("Successfully imported " + sqlFile.getName() + ".");
|
||||
} catch (final Exception ignored) {
|
||||
// if the batch import did not work, retry line by line
|
||||
try {
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(sqlFile));
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.endsWith(";")) {
|
||||
line = line.substring(0, line.length() - 1);
|
||||
}
|
||||
if (!line.isEmpty()) {
|
||||
try {
|
||||
st.execute(line);
|
||||
successes++;
|
||||
} catch (final SQLException ex) {
|
||||
logblock.getLogger().severe("Error while importing: '" + line + "': " + ex.getMessage());
|
||||
writer.write(line + newline);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.commit();
|
||||
reader.close();
|
||||
sqlFile.delete();
|
||||
logblock.getLogger().info("Successfully imported " + sqlFile.getName() + ".");
|
||||
} catch (final Exception ex) {
|
||||
logblock.getLogger().severe("Error while importing " + sqlFile.getName() + ": " + ex.getMessage());
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
st.close();
|
||||
logblock.getLogger().info("Successfully imported stored queue. (" + successes + " rows imported, " + errors + " errors)");
|
||||
} catch (final Exception ex) {
|
||||
logblock.getLogger().log(Level.WARNING, "Error while importing: ", ex);
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (final SQLException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImportsComparator implements Comparator<File> {
|
||||
private final Pattern splitPattern = Pattern.compile("[\\-\\.]");
|
||||
|
||||
@Override
|
||||
public int compare(File o1, File o2) {
|
||||
String[] name1 = splitPattern.split(o1.getName());
|
||||
String[] name2 = splitPattern.split(o2.getName());
|
||||
if (name1.length > name2.length) {
|
||||
return 1;
|
||||
} else if (name1.length < name2.length) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < name1.length; i++) {
|
||||
String part1 = name1[i];
|
||||
String part2 = name2[i];
|
||||
if (part1.length() > 0 && part2.length() > 0) {
|
||||
char first1 = part1.charAt(0);
|
||||
char first2 = part2.charAt(0);
|
||||
if (first1 >= '0' && first1 <= '9' && first2 >= '0' && first2 <= '9') {
|
||||
try {
|
||||
long long1 = Long.parseLong(part1);
|
||||
long long2 = Long.parseLong(part2);
|
||||
if (long1 == long2) {
|
||||
continue;
|
||||
}
|
||||
return long1 > long2 ? 1 : -1;
|
||||
} catch (NumberFormatException e) {
|
||||
// fallthrough to string compare
|
||||
}
|
||||
}
|
||||
}
|
||||
int compareString = part1.compareTo(part2);
|
||||
if (compareString != 0) {
|
||||
return compareString;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.Utils.newline;
|
||||
|
||||
import de.diddiz.LogBlock.util.Utils.ExtensionFilenameFilter;
|
||||
import java.io.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DumpedLogImporter implements Runnable {
|
||||
private final LogBlock logblock;
|
||||
|
||||
DumpedLogImporter(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final File[] imports = new File(logblock.getDataFolder(), "import").listFiles(new ExtensionFilenameFilter("sql"));
|
||||
if (imports != null && imports.length > 0) {
|
||||
logblock.getLogger().info("Found " + imports.length + " imports.");
|
||||
Arrays.sort(imports, new ImportsComparator());
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = logblock.getConnection();
|
||||
if (conn == null) {
|
||||
return;
|
||||
}
|
||||
conn.setAutoCommit(false);
|
||||
final Statement st = conn.createStatement();
|
||||
final BufferedWriter writer = new BufferedWriter(new FileWriter(new File(logblock.getDataFolder(), "import/failed.txt")));
|
||||
int successes = 0, errors = 0;
|
||||
try {
|
||||
for (final File sqlFile : imports) {
|
||||
String line = null;
|
||||
try {
|
||||
logblock.getLogger().info("Trying to import " + sqlFile.getName() + " ...");
|
||||
// first try batch import the whole file
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(sqlFile));
|
||||
int statements = 0;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.endsWith(";")) {
|
||||
line = line.substring(0, line.length() - 1);
|
||||
}
|
||||
if (!line.isEmpty()) {
|
||||
statements++;
|
||||
st.addBatch(line);
|
||||
}
|
||||
}
|
||||
st.executeBatch();
|
||||
conn.commit();
|
||||
reader.close();
|
||||
sqlFile.delete();
|
||||
successes += statements;
|
||||
logblock.getLogger().info("Successfully imported " + sqlFile.getName() + ".");
|
||||
} catch (final Exception ignored) {
|
||||
// if the batch import did not work, retry line by line
|
||||
try {
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(sqlFile));
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.endsWith(";")) {
|
||||
line = line.substring(0, line.length() - 1);
|
||||
}
|
||||
if (!line.isEmpty()) {
|
||||
try {
|
||||
st.execute(line);
|
||||
successes++;
|
||||
} catch (final SQLException ex) {
|
||||
logblock.getLogger().severe("Error while importing: '" + line + "': " + ex.getMessage());
|
||||
writer.write(line + newline);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.commit();
|
||||
reader.close();
|
||||
sqlFile.delete();
|
||||
logblock.getLogger().info("Successfully imported " + sqlFile.getName() + ".");
|
||||
} catch (final Exception ex) {
|
||||
logblock.getLogger().severe("Error while importing " + sqlFile.getName() + ": " + ex.getMessage());
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
st.close();
|
||||
logblock.getLogger().info("Successfully imported stored queue. (" + successes + " rows imported, " + errors + " errors)");
|
||||
} catch (final Exception ex) {
|
||||
logblock.getLogger().log(Level.WARNING, "Error while importing: ", ex);
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (final SQLException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImportsComparator implements Comparator<File> {
|
||||
private final Pattern splitPattern = Pattern.compile("[\\-\\.]");
|
||||
|
||||
@Override
|
||||
public int compare(File o1, File o2) {
|
||||
String[] name1 = splitPattern.split(o1.getName());
|
||||
String[] name2 = splitPattern.split(o2.getName());
|
||||
if (name1.length > name2.length) {
|
||||
return 1;
|
||||
} else if (name1.length < name2.length) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < name1.length; i++) {
|
||||
String part1 = name1[i];
|
||||
String part2 = name2[i];
|
||||
if (part1.length() > 0 && part2.length() > 0) {
|
||||
char first1 = part1.charAt(0);
|
||||
char first2 = part2.charAt(0);
|
||||
if (first1 >= '0' && first1 <= '9' && first2 >= '0' && first2 <= '9') {
|
||||
try {
|
||||
long long1 = Long.parseLong(part1);
|
||||
long long2 = Long.parseLong(part2);
|
||||
if (long1 == long2) {
|
||||
continue;
|
||||
}
|
||||
return long1 > long2 ? 1 : -1;
|
||||
} catch (NumberFormatException e) {
|
||||
// fallthrough to string compare
|
||||
}
|
||||
}
|
||||
}
|
||||
int compareString = part1.compareTo(part2);
|
||||
if (compareString != 0) {
|
||||
return compareString;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,378 +1,378 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import de.diddiz.LogBlock.addons.worldguard.WorldGuardLoggingFlagsAddon;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.listeners.*;
|
||||
import de.diddiz.LogBlock.questioner.Questioner;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.MySQLConnectionPool;
|
||||
import de.diddiz.LogBlock.worldedit.WorldEditHelper;
|
||||
import de.diddiz.LogBlock.worldedit.WorldEditLoggingHook;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.*;
|
||||
import static org.bukkit.Bukkit.getPluginManager;
|
||||
|
||||
public class LogBlock extends JavaPlugin {
|
||||
private static LogBlock logblock = null;
|
||||
private MySQLConnectionPool pool;
|
||||
private Consumer consumer = null;
|
||||
private CommandsHandler commandsHandler;
|
||||
private boolean noDb = false, connected = true;
|
||||
private PlayerInfoLogging playerInfoLogging;
|
||||
private ScaffoldingLogging scaffoldingLogging;
|
||||
private Questioner questioner;
|
||||
private WorldGuardLoggingFlagsAddon worldGuardLoggingFlagsAddon;
|
||||
private boolean isConfigLoaded;
|
||||
private volatile boolean isCompletelyEnabled;
|
||||
|
||||
public static LogBlock getInstance() {
|
||||
return logblock;
|
||||
}
|
||||
|
||||
public boolean isCompletelyEnabled() {
|
||||
return isCompletelyEnabled;
|
||||
}
|
||||
|
||||
public Consumer getConsumer() {
|
||||
return consumer;
|
||||
}
|
||||
|
||||
public CommandsHandler getCommandsHandler() {
|
||||
return commandsHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
logblock = this;
|
||||
BukkitUtils.isDoublePlant(Material.AIR); // Force static code to run
|
||||
try {
|
||||
Config.load(this);
|
||||
isConfigLoaded = true;
|
||||
} catch (final Exception ex) {
|
||||
getLogger().log(Level.SEVERE, "Could not load LogBlock config! " + ex.getMessage(), ex);
|
||||
}
|
||||
if (Config.worldGuardLoggingFlags) {
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") == null) {
|
||||
getLogger().log(Level.SEVERE, "Invalid config! addons.worldguardLoggingFlags is set to true, but WorldGuard is not loaded.");
|
||||
} else {
|
||||
worldGuardLoggingFlagsAddon = new WorldGuardLoggingFlagsAddon(this);
|
||||
worldGuardLoggingFlagsAddon.onPluginLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
if (!isConfigLoaded) {
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
consumer = new Consumer(this);
|
||||
try {
|
||||
getLogger().info("Connecting to " + user + "@" + url + "...");
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
pool = new MySQLConnectionPool(url, user, password, mysqlUseSSL, mysqlRequireSSL);
|
||||
final Connection conn = getConnection(true);
|
||||
if (conn == null) {
|
||||
noDb = true;
|
||||
return;
|
||||
}
|
||||
final Statement st = conn.createStatement();
|
||||
final ResultSet rs = st.executeQuery("SHOW CHARACTER SET where charset='utf8mb4';");
|
||||
if (rs.next()) {
|
||||
Config.mb4 = true;
|
||||
// Allegedly JDBC driver since 2010 hasn't needed this. I did.
|
||||
st.executeUpdate("SET NAMES utf8mb4;");
|
||||
}
|
||||
conn.close();
|
||||
Updater updater = new Updater(this);
|
||||
updater.checkTables();
|
||||
MaterialConverter.initializeMaterials(getConnection());
|
||||
MaterialConverter.getOrAddMaterialId(Material.AIR); // AIR must be the first entry
|
||||
EntityTypeConverter.initializeEntityTypes(getConnection());
|
||||
if (updater.update()) {
|
||||
load(this);
|
||||
}
|
||||
} catch (final NullPointerException ex) {
|
||||
getLogger().log(Level.SEVERE, "Error while loading: ", ex);
|
||||
} catch (final Exception ex) {
|
||||
getLogger().log(Level.SEVERE, "Error while loading: " + ex.getMessage(), ex);
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (WorldEditHelper.hasWorldEdit()) {
|
||||
new WorldEditLoggingHook(this).hook();
|
||||
}
|
||||
commandsHandler = new CommandsHandler(this);
|
||||
getCommand("lb").setExecutor(commandsHandler);
|
||||
if (enableAutoClearLog && autoClearLogDelay > 0) {
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
|
||||
}
|
||||
new DumpedLogImporter(this).run();
|
||||
registerEvents();
|
||||
consumer.start();
|
||||
for (final Tool tool : toolsByType.values()) {
|
||||
if (pm.getPermission("logblock.tools." + tool.name) == null) {
|
||||
final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault);
|
||||
pm.addPermission(perm);
|
||||
}
|
||||
}
|
||||
questioner = new Questioner(this);
|
||||
if (worldGuardLoggingFlagsAddon != null) {
|
||||
worldGuardLoggingFlagsAddon.onPluginEnable();
|
||||
}
|
||||
isCompletelyEnabled = true;
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new Updater.PlayerCountChecker(this));
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
pm.registerEvents(new ToolListener(this), this);
|
||||
pm.registerEvents(playerInfoLogging = new PlayerInfoLogging(this), this);
|
||||
if (askRollbackAfterBan) {
|
||||
pm.registerEvents(new BanListener(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BLOCKPLACE)) {
|
||||
pm.registerEvents(new BlockPlaceLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.LAVAFLOW) || isLogging(Logging.WATERFLOW)) {
|
||||
pm.registerEvents(new FluidFlowLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BLOCKBREAK)) {
|
||||
pm.registerEvents(new BlockBreakLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SIGNTEXT)) {
|
||||
pm.registerEvents(new SignChangeLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.FIRE)) {
|
||||
pm.registerEvents(new BlockBurnLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SNOWFORM)) {
|
||||
pm.registerEvents(new SnowFormLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SNOWFADE)) {
|
||||
pm.registerEvents(new SnowFadeLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SCAFFOLDING)) {
|
||||
pm.registerEvents(scaffoldingLogging = new ScaffoldingLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CAULDRONINTERACT)) {
|
||||
pm.registerEvents(new CauldronLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CREEPEREXPLOSION) || isLogging(Logging.TNTEXPLOSION) || isLogging(Logging.GHASTFIREBALLEXPLOSION) || isLogging(Logging.ENDERDRAGON) || isLogging(Logging.MISCEXPLOSION)) {
|
||||
pm.registerEvents(new ExplosionLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.LEAVESDECAY)) {
|
||||
pm.registerEvents(new LeavesDecayLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CHESTACCESS)) {
|
||||
pm.registerEvents(new ChestAccessLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BLOCKBREAK) || isLogging(Logging.BLOCKPLACE) || isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.COMPARATORINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT)
|
||||
|| isLogging(Logging.PRESUREPLATEINTERACT) || isLogging(Logging.TRIPWIREINTERACT) || isLogging(Logging.CROPTRAMPLE)) {
|
||||
pm.registerEvents(new InteractLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CREATURECROPTRAMPLE)) {
|
||||
pm.registerEvents(new CreatureInteractLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.KILL)) {
|
||||
pm.registerEvents(new KillLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CHAT) || isLogging(Logging.PLAYER_COMMANDS) || isLogging(Logging.CONSOLE_COMMANDS) || isLogging(Logging.COMMANDBLOCK_COMMANDS)) {
|
||||
pm.registerEvents(new ChatLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.ENDERMEN)) {
|
||||
pm.registerEvents(new EndermenLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.WITHER)) {
|
||||
pm.registerEvents(new WitherLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.NATURALSTRUCTUREGROW)) {
|
||||
pm.registerEvents(new StructureGrowLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BONEMEALSTRUCTUREGROW)) {
|
||||
pm.registerEvents(new BlockFertilizeLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.GRASSGROWTH) || isLogging(Logging.MYCELIUMSPREAD) || isLogging(Logging.VINEGROWTH) || isLogging(Logging.MUSHROOMSPREAD) || isLogging(Logging.BAMBOOGROWTH) || isLogging(Logging.DRIPSTONEGROWTH) || isLogging(Logging.SCULKSPREAD)) {
|
||||
pm.registerEvents(new BlockSpreadLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
|
||||
pm.registerEvents(new DragonEggLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.LECTERNBOOKCHANGE)) {
|
||||
pm.registerEvents(new LecternLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.OXIDIZATION)) {
|
||||
pm.registerEvents(new OxidizationLogging(this), this);
|
||||
}
|
||||
if (Config.isLoggingAnyEntities()) {
|
||||
if (!WorldEditHelper.hasFullWorldEdit()) {
|
||||
getLogger().severe("No compatible WorldEdit found, entity logging will not work!");
|
||||
} else {
|
||||
pm.registerEvents(new AdvancedEntityLogging(this), this);
|
||||
getLogger().info("Entity logging enabled!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
isCompletelyEnabled = false;
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
if (consumer != null) {
|
||||
if (logPlayerInfo && playerInfoLogging != null) {
|
||||
for (final Player player : getServer().getOnlinePlayers()) {
|
||||
playerInfoLogging.onPlayerQuit(player);
|
||||
}
|
||||
}
|
||||
getLogger().info("Waiting for consumer ...");
|
||||
consumer.shutdown();
|
||||
if (consumer.getQueueSize() > 0) {
|
||||
getLogger().info("Remaining queue size: " + consumer.getQueueSize() + ". Trying to write to a local file.");
|
||||
try {
|
||||
consumer.writeToFile();
|
||||
getLogger().info("Successfully dumped queue.");
|
||||
} catch (final FileNotFoundException ex) {
|
||||
getLogger().info("Failed to write. Given up.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pool != null) {
|
||||
pool.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (noDb) {
|
||||
sender.sendMessage(ChatColor.RED + "No database connected. Check your MySQL user/pw and database for typos. Start/restart your MySQL server.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender, String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return getConnection(false);
|
||||
}
|
||||
|
||||
public Connection getConnection(boolean testConnection) {
|
||||
try {
|
||||
final Connection conn = pool.getConnection();
|
||||
if (!connected) {
|
||||
getLogger().info("MySQL connection rebuild");
|
||||
connected = true;
|
||||
}
|
||||
return conn;
|
||||
} catch (final Exception ex) {
|
||||
if (testConnection) {
|
||||
getLogger().log(Level.SEVERE, "Could not connect to the Database! Please check your config! " + ex.getMessage());
|
||||
} else if (connected) {
|
||||
getLogger().log(Level.SEVERE, "Error while fetching connection: ", ex);
|
||||
connected = false;
|
||||
} else {
|
||||
getLogger().log(Level.SEVERE, "MySQL connection lost", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of block changes based on the given query parameters, the query parameters
|
||||
* are essentially programmatic versions of the parameters a player would pass
|
||||
* to the logblock lookup command i.e /lb lookup <i>query-parameters</i>
|
||||
*
|
||||
* Note: this method directly calls a SQL query and is hence a slow blocking function, avoid running
|
||||
* it on the main game thread
|
||||
*
|
||||
* @param params QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
|
||||
* @return Returns a list of block changes based on the given query parameters
|
||||
* @throws SQLException if a sql exception occurs while looking up the block changes
|
||||
*/
|
||||
public List<BlockChange> getBlockChanges(QueryParams params) throws SQLException {
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null) {
|
||||
throw new SQLException("No connection");
|
||||
}
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final ResultSet rs = state.executeQuery(params.getQuery());
|
||||
final List<BlockChange> blockchanges = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
blockchanges.add(new BlockChange(rs, params));
|
||||
}
|
||||
return blockchanges;
|
||||
} finally {
|
||||
if (state != null) {
|
||||
state.close();
|
||||
}
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount(QueryParams params) throws SQLException {
|
||||
if (params == null || params.world == null || !Config.isLogged(params.world)) {
|
||||
throw new IllegalArgumentException("World is not logged: " + ((params == null || params.world == null) ? "null" : params.world.getName()));
|
||||
}
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null) {
|
||||
throw new SQLException("No connection");
|
||||
}
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final QueryParams p = params.clone();
|
||||
p.needCount = true;
|
||||
final ResultSet rs = state.executeQuery(p.getQuery());
|
||||
if (!rs.next()) {
|
||||
return 0;
|
||||
}
|
||||
return rs.getInt(1);
|
||||
} finally {
|
||||
if (state != null) {
|
||||
state.close();
|
||||
}
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return super.getFile();
|
||||
}
|
||||
|
||||
public Questioner getQuestioner() {
|
||||
return questioner;
|
||||
}
|
||||
|
||||
public ScaffoldingLogging getScaffoldingLogging() {
|
||||
return scaffoldingLogging;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import de.diddiz.LogBlock.addons.worldguard.WorldGuardLoggingFlagsAddon;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.listeners.*;
|
||||
import de.diddiz.LogBlock.questioner.Questioner;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.MySQLConnectionPool;
|
||||
import de.diddiz.LogBlock.worldedit.WorldEditHelper;
|
||||
import de.diddiz.LogBlock.worldedit.WorldEditLoggingHook;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.*;
|
||||
import static org.bukkit.Bukkit.getPluginManager;
|
||||
|
||||
public class LogBlock extends JavaPlugin {
|
||||
private static LogBlock logblock = null;
|
||||
private MySQLConnectionPool pool;
|
||||
private Consumer consumer = null;
|
||||
private CommandsHandler commandsHandler;
|
||||
private boolean noDb = false, connected = true;
|
||||
private PlayerInfoLogging playerInfoLogging;
|
||||
private ScaffoldingLogging scaffoldingLogging;
|
||||
private Questioner questioner;
|
||||
private WorldGuardLoggingFlagsAddon worldGuardLoggingFlagsAddon;
|
||||
private boolean isConfigLoaded;
|
||||
private volatile boolean isCompletelyEnabled;
|
||||
|
||||
public static LogBlock getInstance() {
|
||||
return logblock;
|
||||
}
|
||||
|
||||
public boolean isCompletelyEnabled() {
|
||||
return isCompletelyEnabled;
|
||||
}
|
||||
|
||||
public Consumer getConsumer() {
|
||||
return consumer;
|
||||
}
|
||||
|
||||
public CommandsHandler getCommandsHandler() {
|
||||
return commandsHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
logblock = this;
|
||||
BukkitUtils.isDoublePlant(Material.AIR); // Force static code to run
|
||||
try {
|
||||
Config.load(this);
|
||||
isConfigLoaded = true;
|
||||
} catch (final Exception ex) {
|
||||
getLogger().log(Level.SEVERE, "Could not load LogBlock config! " + ex.getMessage(), ex);
|
||||
}
|
||||
if (Config.worldGuardLoggingFlags) {
|
||||
if (getServer().getPluginManager().getPlugin("WorldGuard") == null) {
|
||||
getLogger().log(Level.SEVERE, "Invalid config! addons.worldguardLoggingFlags is set to true, but WorldGuard is not loaded.");
|
||||
} else {
|
||||
worldGuardLoggingFlagsAddon = new WorldGuardLoggingFlagsAddon(this);
|
||||
worldGuardLoggingFlagsAddon.onPluginLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
if (!isConfigLoaded) {
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
consumer = new Consumer(this);
|
||||
try {
|
||||
getLogger().info("Connecting to " + user + "@" + url + "...");
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
pool = new MySQLConnectionPool(url, user, password, mysqlUseSSL, mysqlRequireSSL);
|
||||
final Connection conn = getConnection(true);
|
||||
if (conn == null) {
|
||||
noDb = true;
|
||||
return;
|
||||
}
|
||||
final Statement st = conn.createStatement();
|
||||
final ResultSet rs = st.executeQuery("SHOW CHARACTER SET where charset='utf8mb4';");
|
||||
if (rs.next()) {
|
||||
Config.mb4 = true;
|
||||
// Allegedly JDBC driver since 2010 hasn't needed this. I did.
|
||||
st.executeUpdate("SET NAMES utf8mb4;");
|
||||
}
|
||||
conn.close();
|
||||
Updater updater = new Updater(this);
|
||||
updater.checkTables();
|
||||
MaterialConverter.initializeMaterials(getConnection());
|
||||
MaterialConverter.getOrAddMaterialId(Material.AIR); // AIR must be the first entry
|
||||
EntityTypeConverter.initializeEntityTypes(getConnection());
|
||||
if (updater.update()) {
|
||||
load(this);
|
||||
}
|
||||
} catch (final NullPointerException ex) {
|
||||
getLogger().log(Level.SEVERE, "Error while loading: ", ex);
|
||||
} catch (final Exception ex) {
|
||||
getLogger().log(Level.SEVERE, "Error while loading: " + ex.getMessage(), ex);
|
||||
pm.disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (WorldEditHelper.hasWorldEdit()) {
|
||||
new WorldEditLoggingHook(this).hook();
|
||||
}
|
||||
commandsHandler = new CommandsHandler(this);
|
||||
getCommand("lb").setExecutor(commandsHandler);
|
||||
if (enableAutoClearLog && autoClearLogDelay > 0) {
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
|
||||
}
|
||||
new DumpedLogImporter(this).run();
|
||||
registerEvents();
|
||||
consumer.start();
|
||||
for (final Tool tool : toolsByType.values()) {
|
||||
if (pm.getPermission("logblock.tools." + tool.name) == null) {
|
||||
final Permission perm = new Permission("logblock.tools." + tool.name, tool.permissionDefault);
|
||||
pm.addPermission(perm);
|
||||
}
|
||||
}
|
||||
questioner = new Questioner(this);
|
||||
if (worldGuardLoggingFlagsAddon != null) {
|
||||
worldGuardLoggingFlagsAddon.onPluginEnable();
|
||||
}
|
||||
isCompletelyEnabled = true;
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new Updater.PlayerCountChecker(this));
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
final PluginManager pm = getPluginManager();
|
||||
pm.registerEvents(new ToolListener(this), this);
|
||||
pm.registerEvents(playerInfoLogging = new PlayerInfoLogging(this), this);
|
||||
if (askRollbackAfterBan) {
|
||||
pm.registerEvents(new BanListener(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BLOCKPLACE)) {
|
||||
pm.registerEvents(new BlockPlaceLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.LAVAFLOW) || isLogging(Logging.WATERFLOW)) {
|
||||
pm.registerEvents(new FluidFlowLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BLOCKBREAK)) {
|
||||
pm.registerEvents(new BlockBreakLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SIGNTEXT)) {
|
||||
pm.registerEvents(new SignChangeLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.FIRE)) {
|
||||
pm.registerEvents(new BlockBurnLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SNOWFORM)) {
|
||||
pm.registerEvents(new SnowFormLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SNOWFADE)) {
|
||||
pm.registerEvents(new SnowFadeLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.SCAFFOLDING)) {
|
||||
pm.registerEvents(scaffoldingLogging = new ScaffoldingLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CAULDRONINTERACT)) {
|
||||
pm.registerEvents(new CauldronLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CREEPEREXPLOSION) || isLogging(Logging.TNTEXPLOSION) || isLogging(Logging.GHASTFIREBALLEXPLOSION) || isLogging(Logging.ENDERDRAGON) || isLogging(Logging.MISCEXPLOSION)) {
|
||||
pm.registerEvents(new ExplosionLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.LEAVESDECAY)) {
|
||||
pm.registerEvents(new LeavesDecayLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CHESTACCESS)) {
|
||||
pm.registerEvents(new ChestAccessLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BLOCKBREAK) || isLogging(Logging.BLOCKPLACE) || isLogging(Logging.SWITCHINTERACT) || isLogging(Logging.DOORINTERACT) || isLogging(Logging.CAKEEAT) || isLogging(Logging.DIODEINTERACT) || isLogging(Logging.COMPARATORINTERACT) || isLogging(Logging.NOTEBLOCKINTERACT)
|
||||
|| isLogging(Logging.PRESUREPLATEINTERACT) || isLogging(Logging.TRIPWIREINTERACT) || isLogging(Logging.CROPTRAMPLE)) {
|
||||
pm.registerEvents(new InteractLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CREATURECROPTRAMPLE)) {
|
||||
pm.registerEvents(new CreatureInteractLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.KILL)) {
|
||||
pm.registerEvents(new KillLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.CHAT) || isLogging(Logging.PLAYER_COMMANDS) || isLogging(Logging.CONSOLE_COMMANDS) || isLogging(Logging.COMMANDBLOCK_COMMANDS)) {
|
||||
pm.registerEvents(new ChatLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.ENDERMEN)) {
|
||||
pm.registerEvents(new EndermenLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.WITHER)) {
|
||||
pm.registerEvents(new WitherLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.NATURALSTRUCTUREGROW)) {
|
||||
pm.registerEvents(new StructureGrowLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.BONEMEALSTRUCTUREGROW)) {
|
||||
pm.registerEvents(new BlockFertilizeLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.GRASSGROWTH) || isLogging(Logging.MYCELIUMSPREAD) || isLogging(Logging.VINEGROWTH) || isLogging(Logging.MUSHROOMSPREAD) || isLogging(Logging.BAMBOOGROWTH) || isLogging(Logging.DRIPSTONEGROWTH) || isLogging(Logging.SCULKSPREAD)) {
|
||||
pm.registerEvents(new BlockSpreadLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.DRAGONEGGTELEPORT)) {
|
||||
pm.registerEvents(new DragonEggLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.LECTERNBOOKCHANGE)) {
|
||||
pm.registerEvents(new LecternLogging(this), this);
|
||||
}
|
||||
if (isLogging(Logging.OXIDIZATION)) {
|
||||
pm.registerEvents(new OxidizationLogging(this), this);
|
||||
}
|
||||
if (Config.isLoggingAnyEntities()) {
|
||||
if (!WorldEditHelper.hasFullWorldEdit()) {
|
||||
getLogger().severe("No compatible WorldEdit found, entity logging will not work!");
|
||||
} else {
|
||||
pm.registerEvents(new AdvancedEntityLogging(this), this);
|
||||
getLogger().info("Entity logging enabled!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
isCompletelyEnabled = false;
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
if (consumer != null) {
|
||||
if (logPlayerInfo && playerInfoLogging != null) {
|
||||
for (final Player player : getServer().getOnlinePlayers()) {
|
||||
playerInfoLogging.onPlayerQuit(player);
|
||||
}
|
||||
}
|
||||
getLogger().info("Waiting for consumer ...");
|
||||
consumer.shutdown();
|
||||
if (consumer.getQueueSize() > 0) {
|
||||
getLogger().info("Remaining queue size: " + consumer.getQueueSize() + ". Trying to write to a local file.");
|
||||
try {
|
||||
consumer.writeToFile();
|
||||
getLogger().info("Successfully dumped queue.");
|
||||
} catch (final FileNotFoundException ex) {
|
||||
getLogger().info("Failed to write. Given up.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pool != null) {
|
||||
pool.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
if (noDb) {
|
||||
sender.sendMessage(ChatColor.RED + "No database connected. Check your MySQL user/pw and database for typos. Start/restart your MySQL server.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPermission(CommandSender sender, String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return getConnection(false);
|
||||
}
|
||||
|
||||
public Connection getConnection(boolean testConnection) {
|
||||
try {
|
||||
final Connection conn = pool.getConnection();
|
||||
if (!connected) {
|
||||
getLogger().info("MySQL connection rebuild");
|
||||
connected = true;
|
||||
}
|
||||
return conn;
|
||||
} catch (final Exception ex) {
|
||||
if (testConnection) {
|
||||
getLogger().log(Level.SEVERE, "Could not connect to the Database! Please check your config! " + ex.getMessage());
|
||||
} else if (connected) {
|
||||
getLogger().log(Level.SEVERE, "Error while fetching connection: ", ex);
|
||||
connected = false;
|
||||
} else {
|
||||
getLogger().log(Level.SEVERE, "MySQL connection lost", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of block changes based on the given query parameters, the query parameters
|
||||
* are essentially programmatic versions of the parameters a player would pass
|
||||
* to the logblock lookup command i.e /lb lookup <i>query-parameters</i>
|
||||
*
|
||||
* Note: this method directly calls a SQL query and is hence a slow blocking function, avoid running
|
||||
* it on the main game thread
|
||||
*
|
||||
* @param params QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
|
||||
* @return Returns a list of block changes based on the given query parameters
|
||||
* @throws SQLException if a sql exception occurs while looking up the block changes
|
||||
*/
|
||||
public List<BlockChange> getBlockChanges(QueryParams params) throws SQLException {
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null) {
|
||||
throw new SQLException("No connection");
|
||||
}
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final ResultSet rs = state.executeQuery(params.getQuery());
|
||||
final List<BlockChange> blockchanges = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
blockchanges.add(new BlockChange(rs, params));
|
||||
}
|
||||
return blockchanges;
|
||||
} finally {
|
||||
if (state != null) {
|
||||
state.close();
|
||||
}
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount(QueryParams params) throws SQLException {
|
||||
if (params == null || params.world == null || !Config.isLogged(params.world)) {
|
||||
throw new IllegalArgumentException("World is not logged: " + ((params == null || params.world == null) ? "null" : params.world.getName()));
|
||||
}
|
||||
final Connection conn = getConnection();
|
||||
Statement state = null;
|
||||
if (conn == null) {
|
||||
throw new SQLException("No connection");
|
||||
}
|
||||
try {
|
||||
state = conn.createStatement();
|
||||
final QueryParams p = params.clone();
|
||||
p.needCount = true;
|
||||
final ResultSet rs = state.executeQuery(p.getQuery());
|
||||
if (!rs.next()) {
|
||||
return 0;
|
||||
}
|
||||
return rs.getInt(1);
|
||||
} finally {
|
||||
if (state != null) {
|
||||
state.close();
|
||||
}
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return super.getFile();
|
||||
}
|
||||
|
||||
public Questioner getQuestioner() {
|
||||
return questioner;
|
||||
}
|
||||
|
||||
public ScaffoldingLogging getScaffoldingLogging() {
|
||||
return scaffoldingLogging;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface LookupCacheElement {
|
||||
public Location getLocation();
|
||||
|
||||
public default BaseComponent[] getLogMessage() {
|
||||
return getLogMessage(-1);
|
||||
}
|
||||
|
||||
public BaseComponent[] getLogMessage(int entry);
|
||||
|
||||
public default int getNumChanges() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface LookupCacheElement {
|
||||
public Location getLocation();
|
||||
|
||||
public default BaseComponent[] getLogMessage() {
|
||||
return getLogMessage(-1);
|
||||
}
|
||||
|
||||
public BaseComponent[] getLogMessage(int entry);
|
||||
|
||||
public default int getNumChanges() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,40 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import de.diddiz.LogBlock.QueryParams.BlockChangeType;
|
||||
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class LookupCacheElementFactory {
|
||||
private final QueryParams params;
|
||||
private final float spaceFactor;
|
||||
|
||||
public LookupCacheElementFactory(QueryParams params, float spaceFactor) {
|
||||
this.params = params;
|
||||
this.spaceFactor = spaceFactor;
|
||||
}
|
||||
|
||||
public LookupCacheElement getLookupCacheElement(ResultSet rs) throws SQLException {
|
||||
if (params.bct == BlockChangeType.CHAT) {
|
||||
return new ChatMessage(rs, params);
|
||||
}
|
||||
if (params.bct == BlockChangeType.KILLS) {
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new Kill(rs, params);
|
||||
} else if (params.sum == SummarizationMode.PLAYERS) {
|
||||
return new SummedKills(rs, params, spaceFactor);
|
||||
}
|
||||
}
|
||||
if (params.bct == BlockChangeType.ENTITIES || params.bct == BlockChangeType.ENTITIES_CREATED || params.bct == BlockChangeType.ENTITIES_KILLED) {
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new EntityChange(rs, params);
|
||||
}
|
||||
return new SummedEntityChanges(rs, params, spaceFactor);
|
||||
}
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new BlockChange(rs, params);
|
||||
}
|
||||
return new SummedBlockChanges(rs, params, spaceFactor);
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import de.diddiz.LogBlock.QueryParams.BlockChangeType;
|
||||
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class LookupCacheElementFactory {
|
||||
private final QueryParams params;
|
||||
private final float spaceFactor;
|
||||
|
||||
public LookupCacheElementFactory(QueryParams params, float spaceFactor) {
|
||||
this.params = params;
|
||||
this.spaceFactor = spaceFactor;
|
||||
}
|
||||
|
||||
public LookupCacheElement getLookupCacheElement(ResultSet rs) throws SQLException {
|
||||
if (params.bct == BlockChangeType.CHAT) {
|
||||
return new ChatMessage(rs, params);
|
||||
}
|
||||
if (params.bct == BlockChangeType.KILLS) {
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new Kill(rs, params);
|
||||
} else if (params.sum == SummarizationMode.PLAYERS) {
|
||||
return new SummedKills(rs, params, spaceFactor);
|
||||
}
|
||||
}
|
||||
if (params.bct == BlockChangeType.ENTITIES || params.bct == BlockChangeType.ENTITIES_CREATED || params.bct == BlockChangeType.ENTITIES_KILLED) {
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new EntityChange(rs, params);
|
||||
}
|
||||
return new SummedEntityChanges(rs, params, spaceFactor);
|
||||
}
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
return new BlockChange(rs, params);
|
||||
}
|
||||
return new SummedBlockChanges(rs, params, spaceFactor);
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.toolsByType;
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
public class Session {
|
||||
private static final Map<String, Session> sessions = new HashMap<>();
|
||||
public QueryParams lastQuery = null;
|
||||
public LookupCacheElement[] lookupCache = null;
|
||||
public int page = 1;
|
||||
public Map<Tool, ToolData> toolData;
|
||||
|
||||
private Session(Player player) {
|
||||
toolData = new HashMap<>();
|
||||
final LogBlock logblock = LogBlock.getInstance();
|
||||
if (player != null) {
|
||||
for (final Tool tool : toolsByType.values()) {
|
||||
toolData.put(tool, new ToolData(tool, logblock, player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasSession(CommandSender sender) {
|
||||
return sessions.containsKey(sender.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static boolean hasSession(String playerName) {
|
||||
return sessions.containsKey(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
public static Session getSession(CommandSender sender) {
|
||||
return getSession(sender.getName());
|
||||
}
|
||||
|
||||
public static Session getSession(String playerName) {
|
||||
Session session = sessions.get(playerName.toLowerCase());
|
||||
if (session == null) {
|
||||
session = new Session(getServer().getPlayer(playerName));
|
||||
sessions.put(playerName.toLowerCase(), session);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.toolsByType;
|
||||
import static org.bukkit.Bukkit.getServer;
|
||||
|
||||
public class Session {
|
||||
private static final Map<String, Session> sessions = new HashMap<>();
|
||||
public QueryParams lastQuery = null;
|
||||
public LookupCacheElement[] lookupCache = null;
|
||||
public int page = 1;
|
||||
public Map<Tool, ToolData> toolData;
|
||||
|
||||
private Session(Player player) {
|
||||
toolData = new HashMap<>();
|
||||
final LogBlock logblock = LogBlock.getInstance();
|
||||
if (player != null) {
|
||||
for (final Tool tool : toolsByType.values()) {
|
||||
toolData.put(tool, new ToolData(tool, logblock, player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasSession(CommandSender sender) {
|
||||
return sessions.containsKey(sender.getName().toLowerCase());
|
||||
}
|
||||
|
||||
public static boolean hasSession(String playerName) {
|
||||
return sessions.containsKey(playerName.toLowerCase());
|
||||
}
|
||||
|
||||
public static Session getSession(CommandSender sender) {
|
||||
return getSession(sender.getName());
|
||||
}
|
||||
|
||||
public static Session getSession(String playerName) {
|
||||
Session session = sessions.get(playerName.toLowerCase());
|
||||
if (session == null) {
|
||||
session = new Session(getServer().getPlayer(playerName));
|
||||
sessions.put(playerName.toLowerCase(), session);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyMaterial;
|
||||
|
||||
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
|
||||
import de.diddiz.LogBlock.util.MessagingUtil;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class SummedBlockChanges implements LookupCacheElement {
|
||||
private final int type;
|
||||
private final int created, destroyed;
|
||||
private final float spaceFactor;
|
||||
private final Actor actor;
|
||||
|
||||
public SummedBlockChanges(ResultSet rs, QueryParams p, float spaceFactor) throws SQLException {
|
||||
// Actor currently useless here as we don't yet output UUID in results anywhere
|
||||
actor = p.sum == SummarizationMode.PLAYERS ? new Actor(rs) : null;
|
||||
type = p.sum == SummarizationMode.TYPES ? rs.getInt("type") : 0;
|
||||
created = rs.getInt("created");
|
||||
destroyed = rs.getInt("destroyed");
|
||||
this.spaceFactor = spaceFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
return MessagingUtil.formatSummarizedChanges(created, destroyed, actor != null ? new TextComponent(actor.getName()) : prettyMaterial(Objects.toString(MaterialConverter.getMaterial(type))), 10, 10, spaceFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumChanges() {
|
||||
return created + destroyed;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.LogBlock.util.MessagingUtil.prettyMaterial;
|
||||
|
||||
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
|
||||
import de.diddiz.LogBlock.util.MessagingUtil;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Objects;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class SummedBlockChanges implements LookupCacheElement {
|
||||
private final int type;
|
||||
private final int created, destroyed;
|
||||
private final float spaceFactor;
|
||||
private final Actor actor;
|
||||
|
||||
public SummedBlockChanges(ResultSet rs, QueryParams p, float spaceFactor) throws SQLException {
|
||||
// Actor currently useless here as we don't yet output UUID in results anywhere
|
||||
actor = p.sum == SummarizationMode.PLAYERS ? new Actor(rs) : null;
|
||||
type = p.sum == SummarizationMode.TYPES ? rs.getInt("type") : 0;
|
||||
created = rs.getInt("created");
|
||||
destroyed = rs.getInt("destroyed");
|
||||
this.spaceFactor = spaceFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent[] getLogMessage(int entry) {
|
||||
return MessagingUtil.formatSummarizedChanges(created, destroyed, actor != null ? new TextComponent(actor.getName()) : prettyMaterial(Objects.toString(MaterialConverter.getMaterial(type))), 10, 10, spaceFactor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumChanges() {
|
||||
return created + destroyed;
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Tool {
|
||||
public final String name;
|
||||
public final List<String> aliases;
|
||||
public final ToolBehavior leftClickBehavior, rightClickBehavior;
|
||||
public final boolean defaultEnabled;
|
||||
public final Material item;
|
||||
public final boolean canDrop;
|
||||
public final QueryParams params;
|
||||
public final ToolMode mode;
|
||||
public final PermissionDefault permissionDefault;
|
||||
public final boolean removeOnDisable;
|
||||
public final boolean dropToDisable;
|
||||
|
||||
public Tool(String name, List<String> aliases, ToolBehavior leftClickBehavior, ToolBehavior rightClickBehavior, boolean defaultEnabled, Material item, boolean canDrop, QueryParams params, ToolMode mode, PermissionDefault permissionDefault, boolean removeOnDisable, boolean dropToDisable) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
this.leftClickBehavior = leftClickBehavior;
|
||||
this.rightClickBehavior = rightClickBehavior;
|
||||
this.defaultEnabled = defaultEnabled;
|
||||
this.item = item;
|
||||
this.canDrop = canDrop;
|
||||
this.params = params;
|
||||
this.mode = mode;
|
||||
this.permissionDefault = permissionDefault;
|
||||
this.removeOnDisable = removeOnDisable;
|
||||
this.dropToDisable = dropToDisable;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Tool {
|
||||
public final String name;
|
||||
public final List<String> aliases;
|
||||
public final ToolBehavior leftClickBehavior, rightClickBehavior;
|
||||
public final boolean defaultEnabled;
|
||||
public final Material item;
|
||||
public final boolean canDrop;
|
||||
public final QueryParams params;
|
||||
public final ToolMode mode;
|
||||
public final PermissionDefault permissionDefault;
|
||||
public final boolean removeOnDisable;
|
||||
public final boolean dropToDisable;
|
||||
|
||||
public Tool(String name, List<String> aliases, ToolBehavior leftClickBehavior, ToolBehavior rightClickBehavior, boolean defaultEnabled, Material item, boolean canDrop, QueryParams params, ToolMode mode, PermissionDefault permissionDefault, boolean removeOnDisable, boolean dropToDisable) {
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
this.leftClickBehavior = leftClickBehavior;
|
||||
this.rightClickBehavior = rightClickBehavior;
|
||||
this.defaultEnabled = defaultEnabled;
|
||||
this.item = item;
|
||||
this.canDrop = canDrop;
|
||||
this.params = params;
|
||||
this.mode = mode;
|
||||
this.permissionDefault = permissionDefault;
|
||||
this.removeOnDisable = removeOnDisable;
|
||||
this.dropToDisable = dropToDisable;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum ToolBehavior {
|
||||
TOOL,
|
||||
BLOCK,
|
||||
NONE
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum ToolBehavior {
|
||||
TOOL,
|
||||
BLOCK,
|
||||
NONE
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ToolData {
|
||||
public boolean enabled;
|
||||
public QueryParams params;
|
||||
public ToolMode mode;
|
||||
|
||||
public ToolData(Tool tool, LogBlock logblock, Player player) {
|
||||
enabled = tool.defaultEnabled && logblock.hasPermission(player, "logblock.tools." + tool.name);
|
||||
params = tool.params.clone();
|
||||
mode = tool.mode;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ToolData {
|
||||
public boolean enabled;
|
||||
public QueryParams params;
|
||||
public ToolMode mode;
|
||||
|
||||
public ToolData(Tool tool, LogBlock logblock, Player player) {
|
||||
enabled = tool.defaultEnabled && logblock.hasPermission(player, "logblock.tools." + tool.name);
|
||||
params = tool.params.clone();
|
||||
mode = tool.mode;
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum ToolMode {
|
||||
CLEARLOG("logblock.clearlog"),
|
||||
LOOKUP("logblock.lookup"),
|
||||
REDO("logblock.rollback"),
|
||||
ROLLBACK("logblock.rollback"),
|
||||
WRITELOGFILE("logblock.rollback");
|
||||
private final String permission;
|
||||
|
||||
private ToolMode(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
public enum ToolMode {
|
||||
CLEARLOG("logblock.clearlog"),
|
||||
LOOKUP("logblock.lookup"),
|
||||
REDO("logblock.rollback"),
|
||||
ROLLBACK("logblock.rollback"),
|
||||
WRITELOGFILE("logblock.rollback");
|
||||
private final String permission;
|
||||
|
||||
private ToolMode(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,171 +1,171 @@
|
||||
package de.diddiz.LogBlock.config;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.WaterMob;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WorldConfig extends LoggingEnabledMapping {
|
||||
public final String world;
|
||||
public final String table;
|
||||
public final String insertBlockStatementString;
|
||||
public final String selectBlockActorIdStatementString;
|
||||
public final String insertBlockStateStatementString;
|
||||
public final String insertBlockChestDataStatementString;
|
||||
public final String insertEntityStatementString;
|
||||
public final String updateEntityUUIDString;
|
||||
|
||||
private final EnumMap<EntityLogging, EntityLoggingList> entityLogging = new EnumMap<>(EntityLogging.class);
|
||||
public final boolean logNaturalEntitySpawns;
|
||||
public final boolean logAllNamedEntityKills;
|
||||
|
||||
public WorldConfig(String world, File file) throws IOException {
|
||||
this.world = world;
|
||||
final Map<String, Object> def = new HashMap<>();
|
||||
// "Before MySQL 5.1.6, database and table names cannot contain "/", "\", ".", or characters that are not permitted in file names" - MySQL manual
|
||||
// They _can_ contain spaces, but replace them as well
|
||||
def.put("table", "lb-" + file.getName().substring(0, file.getName().length() - 4).replaceAll("[ ./\\\\]", "_"));
|
||||
for (final Logging l : Logging.values()) {
|
||||
def.put("logging." + l.toString(), l.isDefaultEnabled());
|
||||
}
|
||||
final YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
for (final Entry<String, Object> e : def.entrySet()) {
|
||||
if (config.get(e.getKey()) == null) {
|
||||
config.set(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
for (EntityLogging el : EntityLogging.values()) {
|
||||
if (!(config.get("entity." + el.name().toLowerCase()) instanceof List)) {
|
||||
config.set("entity." + el.name().toLowerCase(), el.getDefaultEnabled());
|
||||
}
|
||||
entityLogging.put(el, new EntityLoggingList(el, config.getStringList("entity." + el.name().toLowerCase())));
|
||||
}
|
||||
if (!config.isBoolean("entity.logNaturalSpawns")) {
|
||||
config.set("entity.logNaturalSpawns", false);
|
||||
}
|
||||
logNaturalEntitySpawns = config.getBoolean("entity.logNaturalSpawns");
|
||||
|
||||
if (!config.isBoolean("entity.logAllNamedEntityKills")) {
|
||||
config.set("entity.logAllNamedEntityKills", true);
|
||||
}
|
||||
logAllNamedEntityKills = config.getBoolean("entity.logAllNamedEntityKills");
|
||||
|
||||
config.save(file);
|
||||
table = config.getString("table");
|
||||
for (final Logging l : Logging.values()) {
|
||||
setLogging(l, config.getBoolean("logging." + l.toString()));
|
||||
}
|
||||
|
||||
insertBlockStatementString = "INSERT INTO `" + table + "-blocks` (date, playerid, replaced, replaceddata, type, typedata, x, y, z) VALUES (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
selectBlockActorIdStatementString = "SELECT playerid FROM `" + table + "-blocks` WHERE x = ? AND y = ? AND z = ? ORDER BY date DESC LIMIT 1";
|
||||
insertBlockStateStatementString = "INSERT INTO `" + table + "-state` (replacedState, typeState, id) VALUES(?, ?, ?)";
|
||||
insertBlockChestDataStatementString = "INSERT INTO `" + table + "-chestdata` (item, itemremove, id, itemtype) values (?, ?, ?, ?)";
|
||||
insertEntityStatementString = "INSERT INTO `" + table + "-entities` (date, playerid, entityid, entitytypeid, x, y, z, action, data) VALUES (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
updateEntityUUIDString = "UPDATE `" + table + "-entityids` SET entityuuid = ? WHERE entityid = ?";
|
||||
}
|
||||
|
||||
public boolean isLogging(EntityLogging logging, Entity entity) {
|
||||
return entityLogging.get(logging).isLogging(entity);
|
||||
}
|
||||
|
||||
public boolean isLoggingAnyEntities() {
|
||||
for (EntityLoggingList list : entityLogging.values()) {
|
||||
if (list.isLoggingAnyEntities()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class EntityLoggingList {
|
||||
private final EntityLogging entityAction;
|
||||
private final HashSet<EntityType> logged = new HashSet<>();
|
||||
private final boolean logAll;
|
||||
private final boolean logAnimals;
|
||||
private final boolean logWateranimals;
|
||||
private final boolean logMonsters;
|
||||
private final boolean logLiving;
|
||||
|
||||
public EntityLoggingList(EntityLogging entityAction, List<String> types) {
|
||||
this.entityAction = entityAction;
|
||||
boolean all = false;
|
||||
boolean animals = false;
|
||||
boolean wateranimals = false;
|
||||
boolean monsters = false;
|
||||
boolean living = false;
|
||||
for (String type : types) {
|
||||
EntityType et = BukkitUtils.matchEntityType(type);
|
||||
if (et != null) {
|
||||
logged.add(et);
|
||||
} else {
|
||||
if (type.equalsIgnoreCase("all")) {
|
||||
all = true;
|
||||
} else if (type.equalsIgnoreCase("animal") || type.equalsIgnoreCase("animals")) {
|
||||
animals = true;
|
||||
} else if (type.equalsIgnoreCase("wateranimal") || type.equalsIgnoreCase("wateranimals")) {
|
||||
wateranimals = true;
|
||||
} else if (type.equalsIgnoreCase("monster") || type.equalsIgnoreCase("monsters")) {
|
||||
monsters = true;
|
||||
} else if (type.equalsIgnoreCase("living")) {
|
||||
living = true;
|
||||
} else {
|
||||
LogBlock.getInstance().getLogger().log(Level.WARNING, "Unkown entity type in config for " + world + ": " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
logAll = all;
|
||||
logAnimals = animals;
|
||||
logWateranimals = wateranimals;
|
||||
logMonsters = monsters;
|
||||
logLiving = living;
|
||||
}
|
||||
|
||||
public boolean isLogging(Entity entity) {
|
||||
if (entity == null || (entity instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
EntityType type = entity.getType();
|
||||
if (logAll || logged.contains(type)) {
|
||||
return true;
|
||||
}
|
||||
if (logLiving && LivingEntity.class.isAssignableFrom(entity.getClass()) && !(entity instanceof ArmorStand)) {
|
||||
return true;
|
||||
}
|
||||
if (logAnimals && Animals.class.isAssignableFrom(entity.getClass())) {
|
||||
return true;
|
||||
}
|
||||
if (logWateranimals && WaterMob.class.isAssignableFrom(entity.getClass())) {
|
||||
return true;
|
||||
}
|
||||
if (logMonsters && (Monster.class.isAssignableFrom(entity.getClass()) || entity.getType() == EntityType.SLIME || entity.getType() == EntityType.WITHER || entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.SHULKER || entity.getType() == EntityType.GHAST)) {
|
||||
return true;
|
||||
}
|
||||
if (entityAction == EntityLogging.DESTROY && logAllNamedEntityKills && entity.getCustomName() != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLoggingAnyEntities() {
|
||||
return logAll || logAnimals || logLiving || logMonsters || !logged.isEmpty() || (entityAction == EntityLogging.DESTROY && logAllNamedEntityKills);
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.config;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.WaterMob;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WorldConfig extends LoggingEnabledMapping {
|
||||
public final String world;
|
||||
public final String table;
|
||||
public final String insertBlockStatementString;
|
||||
public final String selectBlockActorIdStatementString;
|
||||
public final String insertBlockStateStatementString;
|
||||
public final String insertBlockChestDataStatementString;
|
||||
public final String insertEntityStatementString;
|
||||
public final String updateEntityUUIDString;
|
||||
|
||||
private final EnumMap<EntityLogging, EntityLoggingList> entityLogging = new EnumMap<>(EntityLogging.class);
|
||||
public final boolean logNaturalEntitySpawns;
|
||||
public final boolean logAllNamedEntityKills;
|
||||
|
||||
public WorldConfig(String world, File file) throws IOException {
|
||||
this.world = world;
|
||||
final Map<String, Object> def = new HashMap<>();
|
||||
// "Before MySQL 5.1.6, database and table names cannot contain "/", "\", ".", or characters that are not permitted in file names" - MySQL manual
|
||||
// They _can_ contain spaces, but replace them as well
|
||||
def.put("table", "lb-" + file.getName().substring(0, file.getName().length() - 4).replaceAll("[ ./\\\\]", "_"));
|
||||
for (final Logging l : Logging.values()) {
|
||||
def.put("logging." + l.toString(), l.isDefaultEnabled());
|
||||
}
|
||||
final YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
for (final Entry<String, Object> e : def.entrySet()) {
|
||||
if (config.get(e.getKey()) == null) {
|
||||
config.set(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
for (EntityLogging el : EntityLogging.values()) {
|
||||
if (!(config.get("entity." + el.name().toLowerCase()) instanceof List)) {
|
||||
config.set("entity." + el.name().toLowerCase(), el.getDefaultEnabled());
|
||||
}
|
||||
entityLogging.put(el, new EntityLoggingList(el, config.getStringList("entity." + el.name().toLowerCase())));
|
||||
}
|
||||
if (!config.isBoolean("entity.logNaturalSpawns")) {
|
||||
config.set("entity.logNaturalSpawns", false);
|
||||
}
|
||||
logNaturalEntitySpawns = config.getBoolean("entity.logNaturalSpawns");
|
||||
|
||||
if (!config.isBoolean("entity.logAllNamedEntityKills")) {
|
||||
config.set("entity.logAllNamedEntityKills", true);
|
||||
}
|
||||
logAllNamedEntityKills = config.getBoolean("entity.logAllNamedEntityKills");
|
||||
|
||||
config.save(file);
|
||||
table = config.getString("table");
|
||||
for (final Logging l : Logging.values()) {
|
||||
setLogging(l, config.getBoolean("logging." + l.toString()));
|
||||
}
|
||||
|
||||
insertBlockStatementString = "INSERT INTO `" + table + "-blocks` (date, playerid, replaced, replaceddata, type, typedata, x, y, z) VALUES (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
selectBlockActorIdStatementString = "SELECT playerid FROM `" + table + "-blocks` WHERE x = ? AND y = ? AND z = ? ORDER BY date DESC LIMIT 1";
|
||||
insertBlockStateStatementString = "INSERT INTO `" + table + "-state` (replacedState, typeState, id) VALUES(?, ?, ?)";
|
||||
insertBlockChestDataStatementString = "INSERT INTO `" + table + "-chestdata` (item, itemremove, id, itemtype) values (?, ?, ?, ?)";
|
||||
insertEntityStatementString = "INSERT INTO `" + table + "-entities` (date, playerid, entityid, entitytypeid, x, y, z, action, data) VALUES (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
updateEntityUUIDString = "UPDATE `" + table + "-entityids` SET entityuuid = ? WHERE entityid = ?";
|
||||
}
|
||||
|
||||
public boolean isLogging(EntityLogging logging, Entity entity) {
|
||||
return entityLogging.get(logging).isLogging(entity);
|
||||
}
|
||||
|
||||
public boolean isLoggingAnyEntities() {
|
||||
for (EntityLoggingList list : entityLogging.values()) {
|
||||
if (list.isLoggingAnyEntities()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class EntityLoggingList {
|
||||
private final EntityLogging entityAction;
|
||||
private final HashSet<EntityType> logged = new HashSet<>();
|
||||
private final boolean logAll;
|
||||
private final boolean logAnimals;
|
||||
private final boolean logWateranimals;
|
||||
private final boolean logMonsters;
|
||||
private final boolean logLiving;
|
||||
|
||||
public EntityLoggingList(EntityLogging entityAction, List<String> types) {
|
||||
this.entityAction = entityAction;
|
||||
boolean all = false;
|
||||
boolean animals = false;
|
||||
boolean wateranimals = false;
|
||||
boolean monsters = false;
|
||||
boolean living = false;
|
||||
for (String type : types) {
|
||||
EntityType et = BukkitUtils.matchEntityType(type);
|
||||
if (et != null) {
|
||||
logged.add(et);
|
||||
} else {
|
||||
if (type.equalsIgnoreCase("all")) {
|
||||
all = true;
|
||||
} else if (type.equalsIgnoreCase("animal") || type.equalsIgnoreCase("animals")) {
|
||||
animals = true;
|
||||
} else if (type.equalsIgnoreCase("wateranimal") || type.equalsIgnoreCase("wateranimals")) {
|
||||
wateranimals = true;
|
||||
} else if (type.equalsIgnoreCase("monster") || type.equalsIgnoreCase("monsters")) {
|
||||
monsters = true;
|
||||
} else if (type.equalsIgnoreCase("living")) {
|
||||
living = true;
|
||||
} else {
|
||||
LogBlock.getInstance().getLogger().log(Level.WARNING, "Unkown entity type in config for " + world + ": " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
logAll = all;
|
||||
logAnimals = animals;
|
||||
logWateranimals = wateranimals;
|
||||
logMonsters = monsters;
|
||||
logLiving = living;
|
||||
}
|
||||
|
||||
public boolean isLogging(Entity entity) {
|
||||
if (entity == null || (entity instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
EntityType type = entity.getType();
|
||||
if (logAll || logged.contains(type)) {
|
||||
return true;
|
||||
}
|
||||
if (logLiving && LivingEntity.class.isAssignableFrom(entity.getClass()) && !(entity instanceof ArmorStand)) {
|
||||
return true;
|
||||
}
|
||||
if (logAnimals && Animals.class.isAssignableFrom(entity.getClass())) {
|
||||
return true;
|
||||
}
|
||||
if (logWateranimals && WaterMob.class.isAssignableFrom(entity.getClass())) {
|
||||
return true;
|
||||
}
|
||||
if (logMonsters && (Monster.class.isAssignableFrom(entity.getClass()) || entity.getType() == EntityType.SLIME || entity.getType() == EntityType.WITHER || entity.getType() == EntityType.ENDER_DRAGON || entity.getType() == EntityType.SHULKER || entity.getType() == EntityType.GHAST)) {
|
||||
return true;
|
||||
}
|
||||
if (entityAction == EntityLogging.DESTROY && logAllNamedEntityKills && entity.getCustomName() != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLoggingAnyEntities() {
|
||||
return logAll || logAnimals || logLiving || logMonsters || !logged.isEmpty() || (entityAction == EntityLogging.DESTROY && logAllNamedEntityKills);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +1,48 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.CommandsHandler;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.QueryParams;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.banPermission;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogged;
|
||||
import static org.bukkit.Bukkit.getScheduler;
|
||||
|
||||
public class BanListener implements Listener {
|
||||
private final CommandsHandler handler;
|
||||
private final LogBlock logblock;
|
||||
|
||||
public BanListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
handler = logblock.getCommandsHandler();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
final String[] split = event.getMessage().split(" ");
|
||||
if (split.length > 1 && split[0].equalsIgnoreCase("/ban") && logblock.hasPermission(event.getPlayer(), banPermission)) {
|
||||
final QueryParams p = new QueryParams(logblock);
|
||||
p.setPlayer(split[1].equalsIgnoreCase("g") ? split[2] : split[1]);
|
||||
p.since = 0;
|
||||
p.silent = false;
|
||||
getScheduler().runTaskAsynchronously(logblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (final World world : logblock.getServer().getWorlds()) {
|
||||
if (isLogged(world)) {
|
||||
p.world = world;
|
||||
try {
|
||||
handler.new CommandRollback(event.getPlayer(), p, false);
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.CommandsHandler;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.QueryParams;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.banPermission;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogged;
|
||||
import static org.bukkit.Bukkit.getScheduler;
|
||||
|
||||
public class BanListener implements Listener {
|
||||
private final CommandsHandler handler;
|
||||
private final LogBlock logblock;
|
||||
|
||||
public BanListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
handler = logblock.getCommandsHandler();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
final String[] split = event.getMessage().split(" ");
|
||||
if (split.length > 1 && split[0].equalsIgnoreCase("/ban") && logblock.hasPermission(event.getPlayer(), banPermission)) {
|
||||
final QueryParams p = new QueryParams(logblock);
|
||||
p.setPlayer(split[1].equalsIgnoreCase("g") ? split[2] : split[1]);
|
||||
p.since = 0;
|
||||
p.silent = false;
|
||||
getScheduler().runTaskAsynchronously(logblock, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (final World world : logblock.getServer().getWorlds()) {
|
||||
if (isLogged(world)) {
|
||||
p.world = world;
|
||||
try {
|
||||
handler.new CommandRollback(event.getPlayer(), p, false);
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,74 +1,74 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockBreak;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockReplace;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogFallables;
|
||||
|
||||
public class BlockBreakLogging extends LoggingListener {
|
||||
public BlockBreakLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.BLOCKBREAK)) {
|
||||
WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
if (wcfg == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
final Block origin = event.getBlock();
|
||||
final Material type = origin.getType();
|
||||
|
||||
if (wcfg.isLogging(Logging.CHESTACCESS) && BukkitUtils.getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||
consumer.queueContainerBreak(actor, origin.getState());
|
||||
} else if (type == Material.ICE) {
|
||||
// When in creative mode ice doesn't form water
|
||||
if (event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
|
||||
smartLogBlockBreak(consumer, actor, origin);
|
||||
} else {
|
||||
smartLogBlockReplace(consumer, actor, origin, Bukkit.createBlockData(Material.WATER));
|
||||
}
|
||||
} else {
|
||||
smartLogBlockBreak(consumer, actor, origin);
|
||||
}
|
||||
smartLogFallables(consumer, actor, origin);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
if (isLogging(event.getBlockClicked().getWorld(), Logging.BLOCKBREAK)) {
|
||||
BlockData clickedBlockData = event.getBlockClicked().getBlockData();
|
||||
if (clickedBlockData instanceof Waterlogged) {
|
||||
Waterlogged clickedWaterlogged = (Waterlogged) clickedBlockData;
|
||||
if (clickedWaterlogged.isWaterlogged()) {
|
||||
Waterlogged clickedWaterloggedWithoutWater = (Waterlogged) clickedWaterlogged.clone();
|
||||
clickedWaterloggedWithoutWater.setWaterlogged(false);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getLocation(), clickedWaterlogged, clickedWaterloggedWithoutWater);
|
||||
}
|
||||
} else {
|
||||
consumer.queueBlockBreak(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockBreak;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockReplace;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogFallables;
|
||||
|
||||
public class BlockBreakLogging extends LoggingListener {
|
||||
public BlockBreakLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.BLOCKBREAK)) {
|
||||
WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
if (wcfg == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
final Block origin = event.getBlock();
|
||||
final Material type = origin.getType();
|
||||
|
||||
if (wcfg.isLogging(Logging.CHESTACCESS) && BukkitUtils.getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||
consumer.queueContainerBreak(actor, origin.getState());
|
||||
} else if (type == Material.ICE) {
|
||||
// When in creative mode ice doesn't form water
|
||||
if (event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
|
||||
smartLogBlockBreak(consumer, actor, origin);
|
||||
} else {
|
||||
smartLogBlockReplace(consumer, actor, origin, Bukkit.createBlockData(Material.WATER));
|
||||
}
|
||||
} else {
|
||||
smartLogBlockBreak(consumer, actor, origin);
|
||||
}
|
||||
smartLogFallables(consumer, actor, origin);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
if (isLogging(event.getBlockClicked().getWorld(), Logging.BLOCKBREAK)) {
|
||||
BlockData clickedBlockData = event.getBlockClicked().getBlockData();
|
||||
if (clickedBlockData instanceof Waterlogged) {
|
||||
Waterlogged clickedWaterlogged = (Waterlogged) clickedBlockData;
|
||||
if (clickedWaterlogged.isWaterlogged()) {
|
||||
Waterlogged clickedWaterloggedWithoutWater = (Waterlogged) clickedWaterlogged.clone();
|
||||
clickedWaterloggedWithoutWater.setWaterlogged(false);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getLocation(), clickedWaterlogged, clickedWaterloggedWithoutWater);
|
||||
}
|
||||
} else {
|
||||
consumer.queueBlockBreak(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,72 +1,72 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockBreak;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockReplace;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogFallables;
|
||||
|
||||
public class BlockBurnLogging extends LoggingListener {
|
||||
public BlockBurnLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.FIRE)) {
|
||||
smartLogBlockReplace(consumer, new Actor("Fire", Config.logFireSpreadAsPlayerWhoCreatedIt ? event.getIgnitingBlock() : null), event.getBlock(), Material.FIRE.createBlockData());
|
||||
smartLogFallables(consumer, new Actor("Fire", Config.logFireSpreadAsPlayerWhoCreatedIt ? event.getIgnitingBlock() : null), event.getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
Actor actor = new Actor("Fire", Config.logFireSpreadAsPlayerWhoCreatedIt ? event.getIgnitingBlock() : null);
|
||||
if (event.getCause() == IgniteCause.FLINT_AND_STEEL) {
|
||||
if (event.getIgnitingEntity() != null) {
|
||||
return; // handled in block place
|
||||
} else {
|
||||
actor = new Actor("Dispenser");
|
||||
}
|
||||
} else if (event.getCause() == IgniteCause.LIGHTNING) {
|
||||
actor = new Actor("Lightning");
|
||||
} else if (event.getCause() == IgniteCause.EXPLOSION) {
|
||||
actor = new Actor("Explosion");
|
||||
} else if (event.getCause() == IgniteCause.LAVA) {
|
||||
actor = new Actor("Lava");
|
||||
} else if (event.getCause() == IgniteCause.ENDER_CRYSTAL) {
|
||||
actor = new Actor("EnderCrystal");
|
||||
}
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.FIRE)) {
|
||||
consumer.queueBlockPlace(actor, event.getBlock().getLocation(), Material.FIRE.createBlockData());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onExtinguish(PlayerInteractEvent event) {
|
||||
if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
if (block.getType().equals(Material.FIRE) && isLogging(player.getWorld(), Logging.FIRE)) {
|
||||
Actor actor = Actor.actorFromEntity(player);
|
||||
smartLogBlockBreak(consumer, actor, block);
|
||||
smartLogFallables(consumer, actor, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockBreak;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockReplace;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogFallables;
|
||||
|
||||
public class BlockBurnLogging extends LoggingListener {
|
||||
public BlockBurnLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.FIRE)) {
|
||||
smartLogBlockReplace(consumer, new Actor("Fire", Config.logFireSpreadAsPlayerWhoCreatedIt ? event.getIgnitingBlock() : null), event.getBlock(), Material.FIRE.createBlockData());
|
||||
smartLogFallables(consumer, new Actor("Fire", Config.logFireSpreadAsPlayerWhoCreatedIt ? event.getIgnitingBlock() : null), event.getBlock());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
Actor actor = new Actor("Fire", Config.logFireSpreadAsPlayerWhoCreatedIt ? event.getIgnitingBlock() : null);
|
||||
if (event.getCause() == IgniteCause.FLINT_AND_STEEL) {
|
||||
if (event.getIgnitingEntity() != null) {
|
||||
return; // handled in block place
|
||||
} else {
|
||||
actor = new Actor("Dispenser");
|
||||
}
|
||||
} else if (event.getCause() == IgniteCause.LIGHTNING) {
|
||||
actor = new Actor("Lightning");
|
||||
} else if (event.getCause() == IgniteCause.EXPLOSION) {
|
||||
actor = new Actor("Explosion");
|
||||
} else if (event.getCause() == IgniteCause.LAVA) {
|
||||
actor = new Actor("Lava");
|
||||
} else if (event.getCause() == IgniteCause.ENDER_CRYSTAL) {
|
||||
actor = new Actor("EnderCrystal");
|
||||
}
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.FIRE)) {
|
||||
consumer.queueBlockPlace(actor, event.getBlock().getLocation(), Material.FIRE.createBlockData());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onExtinguish(PlayerInteractEvent event) {
|
||||
if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getClickedBlock().getRelative(event.getBlockFace());
|
||||
if (block.getType().equals(Material.FIRE) && isLogging(player.getWorld(), Logging.FIRE)) {
|
||||
Actor actor = Actor.actorFromEntity(player);
|
||||
smartLogBlockBreak(consumer, actor, block);
|
||||
smartLogFallables(consumer, actor, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,67 +1,67 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.util.LoggingUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class BlockPlaceLogging extends LoggingListener {
|
||||
public BlockPlaceLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (Config.isLogging(event.getBlock().getWorld(), Logging.BLOCKPLACE)) {
|
||||
final BlockState before = event.getBlockReplacedState();
|
||||
final BlockState after = event.getBlockPlaced().getState();
|
||||
final Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
if (before.getType() == Material.LECTERN && after.getType() == Material.LECTERN) {
|
||||
return;
|
||||
}
|
||||
LoggingUtil.smartLogBlockPlace(consumer, actor, before, after);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
if (isLogging(event.getPlayer().getWorld(), Logging.BLOCKPLACE)) {
|
||||
Material placedMaterial = event.getBucket() == Material.LAVA_BUCKET ? Material.LAVA : Material.WATER;
|
||||
BlockData clickedBlockData = event.getBlockClicked().getBlockData();
|
||||
if (placedMaterial == Material.WATER && clickedBlockData instanceof Waterlogged) {
|
||||
Waterlogged clickedWaterlogged = (Waterlogged) clickedBlockData;
|
||||
if (!clickedWaterlogged.isWaterlogged()) {
|
||||
Waterlogged clickedWaterloggedWithWater = (Waterlogged) clickedWaterlogged.clone();
|
||||
clickedWaterloggedWithWater.setWaterlogged(true);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getLocation(), clickedWaterlogged, clickedWaterloggedWithWater);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Block placedAt = event.getBlockClicked().getRelative(event.getBlockFace());
|
||||
if (placedAt.isEmpty()) {
|
||||
consumer.queueBlockPlace(Actor.actorFromEntity(event.getPlayer()), placedAt.getLocation(), placedMaterial.createBlockData());
|
||||
} else {
|
||||
BlockData placedAtBlock = placedAt.getBlockData();
|
||||
if (placedAtBlock instanceof Waterlogged && !(((Waterlogged) placedAtBlock).isWaterlogged())) {
|
||||
Waterlogged clickedWaterloggedWithWater = (Waterlogged) placedAtBlock.clone();
|
||||
clickedWaterloggedWithWater.setWaterlogged(true);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), placedAt.getLocation(), placedAtBlock, clickedWaterloggedWithWater);
|
||||
} else {
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), placedAt.getLocation(), placedAtBlock, placedMaterial.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.util.LoggingUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class BlockPlaceLogging extends LoggingListener {
|
||||
public BlockPlaceLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (Config.isLogging(event.getBlock().getWorld(), Logging.BLOCKPLACE)) {
|
||||
final BlockState before = event.getBlockReplacedState();
|
||||
final BlockState after = event.getBlockPlaced().getState();
|
||||
final Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
if (before.getType() == Material.LECTERN && after.getType() == Material.LECTERN) {
|
||||
return;
|
||||
}
|
||||
LoggingUtil.smartLogBlockPlace(consumer, actor, before, after);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
if (isLogging(event.getPlayer().getWorld(), Logging.BLOCKPLACE)) {
|
||||
Material placedMaterial = event.getBucket() == Material.LAVA_BUCKET ? Material.LAVA : Material.WATER;
|
||||
BlockData clickedBlockData = event.getBlockClicked().getBlockData();
|
||||
if (placedMaterial == Material.WATER && clickedBlockData instanceof Waterlogged) {
|
||||
Waterlogged clickedWaterlogged = (Waterlogged) clickedBlockData;
|
||||
if (!clickedWaterlogged.isWaterlogged()) {
|
||||
Waterlogged clickedWaterloggedWithWater = (Waterlogged) clickedWaterlogged.clone();
|
||||
clickedWaterloggedWithWater.setWaterlogged(true);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getLocation(), clickedWaterlogged, clickedWaterloggedWithWater);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Block placedAt = event.getBlockClicked().getRelative(event.getBlockFace());
|
||||
if (placedAt.isEmpty()) {
|
||||
consumer.queueBlockPlace(Actor.actorFromEntity(event.getPlayer()), placedAt.getLocation(), placedMaterial.createBlockData());
|
||||
} else {
|
||||
BlockData placedAtBlock = placedAt.getBlockData();
|
||||
if (placedAtBlock instanceof Waterlogged && !(((Waterlogged) placedAtBlock).isWaterlogged())) {
|
||||
Waterlogged clickedWaterloggedWithWater = (Waterlogged) placedAtBlock.clone();
|
||||
clickedWaterloggedWithWater.setWaterlogged(true);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), placedAt.getLocation(), placedAtBlock, clickedWaterloggedWithWater);
|
||||
} else {
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), placedAt.getLocation(), placedAtBlock, placedMaterial.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +1,58 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.minecart.CommandMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class ChatLogging extends LoggingListener {
|
||||
public ChatLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (isLogging(event.getPlayer().getWorld(), Logging.PLAYER_COMMANDS)) {
|
||||
consumer.queueChat(Actor.actorFromEntity(event.getPlayer()), event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (isLogging(event.getPlayer().getWorld(), Logging.CHAT)) {
|
||||
consumer.queueChat(Actor.actorFromEntity(event.getPlayer()), event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onServerCommand(ServerCommandEvent event) {
|
||||
CommandSender sender = event.getSender();
|
||||
Actor actor;
|
||||
if (sender instanceof BlockCommandSender) {
|
||||
if (!isLogging(((BlockCommandSender) sender).getBlock().getWorld(), Logging.COMMANDBLOCK_COMMANDS)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("CommandBlock");
|
||||
} else if (sender instanceof CommandMinecart) {
|
||||
if (!isLogging(((CommandMinecart) sender).getWorld(), Logging.COMMANDBLOCK_COMMANDS)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("CommandMinecart");
|
||||
} else {
|
||||
if (!isLogging(Logging.CONSOLE_COMMANDS)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("Console");
|
||||
}
|
||||
consumer.queueChat(actor, "/" + event.getCommand());
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.minecart.CommandMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class ChatLogging extends LoggingListener {
|
||||
public ChatLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (isLogging(event.getPlayer().getWorld(), Logging.PLAYER_COMMANDS)) {
|
||||
consumer.queueChat(Actor.actorFromEntity(event.getPlayer()), event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (isLogging(event.getPlayer().getWorld(), Logging.CHAT)) {
|
||||
consumer.queueChat(Actor.actorFromEntity(event.getPlayer()), event.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onServerCommand(ServerCommandEvent event) {
|
||||
CommandSender sender = event.getSender();
|
||||
Actor actor;
|
||||
if (sender instanceof BlockCommandSender) {
|
||||
if (!isLogging(((BlockCommandSender) sender).getBlock().getWorld(), Logging.COMMANDBLOCK_COMMANDS)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("CommandBlock");
|
||||
} else if (sender instanceof CommandMinecart) {
|
||||
if (!isLogging(((CommandMinecart) sender).getWorld(), Logging.COMMANDBLOCK_COMMANDS)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("CommandMinecart");
|
||||
} else {
|
||||
if (!isLogging(Logging.CONSOLE_COMMANDS)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("Console");
|
||||
}
|
||||
consumer.queueChat(actor, "/" + event.getCommand());
|
||||
}
|
||||
}
|
||||
|
@ -1,303 +1,303 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.BukkitUtils.*;
|
||||
|
||||
public class ChestAccessLogging extends LoggingListener {
|
||||
private class PlayerActiveInventoryModifications {
|
||||
private final HumanEntity actor;
|
||||
private final Location location;
|
||||
private final HashMap<ItemStack, Integer> modifications;
|
||||
|
||||
public PlayerActiveInventoryModifications(HumanEntity actor, Location location) {
|
||||
this.actor = actor;
|
||||
this.location = location;
|
||||
this.modifications = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addModification(ItemStack stack, int amount) {
|
||||
if (amount == 0) {
|
||||
return;
|
||||
}
|
||||
// if we have other viewers, we have to flush their changes
|
||||
ArrayList<PlayerActiveInventoryModifications> allViewers = containersByLocation.get(location);
|
||||
if (allViewers.size() > 1) {
|
||||
for (PlayerActiveInventoryModifications other : allViewers) {
|
||||
if (other != this) {
|
||||
other.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// consumer.getLogblock().getLogger().info("Modify container: " + stack + " change: " + amount);
|
||||
stack = new ItemStack(stack);
|
||||
stack.setAmount(1);
|
||||
Integer existing = modifications.get(stack);
|
||||
int newTotal = amount + (existing == null ? 0 : existing);
|
||||
if (newTotal == 0) {
|
||||
modifications.remove(stack);
|
||||
} else {
|
||||
modifications.put(stack, newTotal);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
if (!modifications.isEmpty()) {
|
||||
for (Entry<ItemStack, Integer> e : modifications.entrySet()) {
|
||||
ItemStack stack = e.getKey();
|
||||
int amount = e.getValue();
|
||||
stack.setAmount(Math.abs(amount));
|
||||
// consumer.getLogblock().getLogger().info("Store container: " + stack + " take: " + (amount < 0));
|
||||
consumer.queueChestAccess(Actor.actorFromEntity(actor), location, location.getWorld().getBlockAt(location).getBlockData(), stack, amount < 0);
|
||||
}
|
||||
modifications.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public HumanEntity getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<HumanEntity, PlayerActiveInventoryModifications> containersByOwner = new HashMap<>();
|
||||
private final Map<Location, ArrayList<PlayerActiveInventoryModifications>> containersByLocation = new HashMap<>();
|
||||
|
||||
public ChestAccessLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
final HumanEntity player = event.getPlayer();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
final PlayerActiveInventoryModifications modifications = containersByOwner.remove(player);
|
||||
if (modifications != null) {
|
||||
final Location loc = modifications.getLocation();
|
||||
ArrayList<PlayerActiveInventoryModifications> atLocation = containersByLocation.get(loc);
|
||||
atLocation.remove(modifications);
|
||||
if (atLocation.isEmpty()) {
|
||||
containersByLocation.remove(loc);
|
||||
}
|
||||
modifications.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
final HumanEntity player = event.getPlayer();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
if (event.getInventory() != null) {
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
if (getInventoryHolderType(holder) != Material.CRAFTING_TABLE) {
|
||||
PlayerActiveInventoryModifications modifications = new PlayerActiveInventoryModifications(event.getPlayer(), getInventoryHolderLocation(holder));
|
||||
containersByOwner.put(modifications.getActor(), modifications);
|
||||
containersByLocation.compute(modifications.getLocation(), (k, v) -> {
|
||||
if (v == null) {
|
||||
v = new ArrayList<>();
|
||||
}
|
||||
v.add(modifications);
|
||||
return v;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
final HumanEntity player = event.getWhoClicked();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
final PlayerActiveInventoryModifications modifications = containersByOwner.get(player);
|
||||
if (modifications != null) {
|
||||
switch (event.getAction()) {
|
||||
case PICKUP_ONE:
|
||||
case DROP_ONE_SLOT:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCurrentItem(), -1);
|
||||
}
|
||||
break;
|
||||
case PICKUP_HALF:
|
||||
// server behaviour: round up
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCurrentItem(), -(event.getCurrentItem().getAmount() + 1) / 2);
|
||||
}
|
||||
break;
|
||||
case PICKUP_SOME: // oversized stack - can not take all when clicking
|
||||
// server behaviour: leave a full stack in the slot, take everything else
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
int taken = event.getCurrentItem().getAmount() - event.getCurrentItem().getMaxStackSize();
|
||||
modifications.addModification(event.getCursor(), -taken);
|
||||
}
|
||||
break;
|
||||
case PICKUP_ALL:
|
||||
case DROP_ALL_SLOT:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCurrentItem(), -event.getCurrentItem().getAmount());
|
||||
}
|
||||
break;
|
||||
case PLACE_ONE:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCursor(), 1);
|
||||
}
|
||||
break;
|
||||
case PLACE_SOME: // not enough free place in target slot
|
||||
// server behaviour: place as much as possible
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
int placeable = event.getCurrentItem().getMaxStackSize() - event.getCurrentItem().getAmount();
|
||||
modifications.addModification(event.getCursor(), placeable);
|
||||
}
|
||||
break;
|
||||
case PLACE_ALL:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCursor(), event.getCursor().getAmount());
|
||||
}
|
||||
break;
|
||||
case SWAP_WITH_CURSOR:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCursor(), event.getCursor().getAmount());
|
||||
modifications.addModification(event.getCurrentItem(), -event.getCurrentItem().getAmount());
|
||||
}
|
||||
break;
|
||||
case MOVE_TO_OTHER_INVENTORY: // shift + click
|
||||
boolean removed = event.getRawSlot() < event.getView().getTopInventory().getSize();
|
||||
modifications.addModification(event.getCurrentItem(), event.getCurrentItem().getAmount() * (removed ? -1 : 1));
|
||||
break;
|
||||
case COLLECT_TO_CURSOR: // double click
|
||||
// server behaviour: first collect all with an amount != maxstacksize, then others, starting from slot 0 (container)
|
||||
ItemStack cursor = event.getCursor();
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
int toPickUp = cursor.getMaxStackSize() - cursor.getAmount();
|
||||
int takenFromContainer = 0;
|
||||
boolean takeFromFullStacks = false;
|
||||
Inventory top = event.getView().getTopInventory();
|
||||
Inventory bottom = event.getView().getBottomInventory();
|
||||
while (toPickUp > 0) {
|
||||
for (ItemStack stack : top.getStorageContents()) {
|
||||
if (cursor.isSimilar(stack)) {
|
||||
if (takeFromFullStacks == (stack.getAmount() == stack.getMaxStackSize())) {
|
||||
int take = Math.min(toPickUp, stack.getAmount());
|
||||
toPickUp -= take;
|
||||
takenFromContainer += take;
|
||||
if (toPickUp <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toPickUp <= 0) {
|
||||
break;
|
||||
}
|
||||
for (ItemStack stack : bottom.getStorageContents()) {
|
||||
if (cursor.isSimilar(stack)) {
|
||||
if (takeFromFullStacks == (stack.getAmount() == stack.getMaxStackSize())) {
|
||||
int take = Math.min(toPickUp, stack.getAmount());
|
||||
toPickUp -= take;
|
||||
if (toPickUp <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (takeFromFullStacks) {
|
||||
break;
|
||||
} else {
|
||||
takeFromFullStacks = true;
|
||||
}
|
||||
}
|
||||
if (takenFromContainer > 0) {
|
||||
modifications.addModification(event.getCursor(), -takenFromContainer);
|
||||
}
|
||||
break;
|
||||
case HOTBAR_SWAP: // number key or offhand key
|
||||
case HOTBAR_MOVE_AND_READD: // something was in the other slot
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
ItemStack otherSlot = (event.getClick() == ClickType.SWAP_OFFHAND) ? event.getWhoClicked().getInventory().getItemInOffHand() : event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) {
|
||||
modifications.addModification(event.getCurrentItem(), -event.getCurrentItem().getAmount());
|
||||
}
|
||||
if (otherSlot != null && otherSlot.getType() != Material.AIR) {
|
||||
modifications.addModification(otherSlot, otherSlot.getAmount());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DROP_ALL_CURSOR:
|
||||
case DROP_ONE_CURSOR:
|
||||
case CLONE_STACK:
|
||||
case NOTHING:
|
||||
// only the cursor or nothing (but not the inventory) was modified
|
||||
break;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
// unable to log something we don't know
|
||||
consumer.getLogblock().getLogger().warning("Unknown inventory action by " + event.getWhoClicked().getName() + ": " + event.getAction() + " Slot: " + event.getSlot() + " Slot type: " + event.getSlotType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryDrag(InventoryDragEvent event) {
|
||||
final HumanEntity player = event.getWhoClicked();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
final PlayerActiveInventoryModifications modifications = containersByOwner.get(player);
|
||||
if (modifications != null) {
|
||||
Inventory container = event.getView().getTopInventory();
|
||||
int containerSize = container.getSize();
|
||||
for (Entry<Integer, ItemStack> e : event.getNewItems().entrySet()) {
|
||||
int slot = e.getKey();
|
||||
if (slot < containerSize) {
|
||||
ItemStack old = container.getItem(slot);
|
||||
int oldAmount = (old == null || old.getType() == Material.AIR) ? 0 : old.getAmount();
|
||||
modifications.addModification(e.getValue(), e.getValue().getAmount() - oldAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.BukkitUtils.*;
|
||||
|
||||
public class ChestAccessLogging extends LoggingListener {
|
||||
private class PlayerActiveInventoryModifications {
|
||||
private final HumanEntity actor;
|
||||
private final Location location;
|
||||
private final HashMap<ItemStack, Integer> modifications;
|
||||
|
||||
public PlayerActiveInventoryModifications(HumanEntity actor, Location location) {
|
||||
this.actor = actor;
|
||||
this.location = location;
|
||||
this.modifications = new HashMap<>();
|
||||
}
|
||||
|
||||
public void addModification(ItemStack stack, int amount) {
|
||||
if (amount == 0) {
|
||||
return;
|
||||
}
|
||||
// if we have other viewers, we have to flush their changes
|
||||
ArrayList<PlayerActiveInventoryModifications> allViewers = containersByLocation.get(location);
|
||||
if (allViewers.size() > 1) {
|
||||
for (PlayerActiveInventoryModifications other : allViewers) {
|
||||
if (other != this) {
|
||||
other.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// consumer.getLogblock().getLogger().info("Modify container: " + stack + " change: " + amount);
|
||||
stack = new ItemStack(stack);
|
||||
stack.setAmount(1);
|
||||
Integer existing = modifications.get(stack);
|
||||
int newTotal = amount + (existing == null ? 0 : existing);
|
||||
if (newTotal == 0) {
|
||||
modifications.remove(stack);
|
||||
} else {
|
||||
modifications.put(stack, newTotal);
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
if (!modifications.isEmpty()) {
|
||||
for (Entry<ItemStack, Integer> e : modifications.entrySet()) {
|
||||
ItemStack stack = e.getKey();
|
||||
int amount = e.getValue();
|
||||
stack.setAmount(Math.abs(amount));
|
||||
// consumer.getLogblock().getLogger().info("Store container: " + stack + " take: " + (amount < 0));
|
||||
consumer.queueChestAccess(Actor.actorFromEntity(actor), location, location.getWorld().getBlockAt(location).getBlockData(), stack, amount < 0);
|
||||
}
|
||||
modifications.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public HumanEntity getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<HumanEntity, PlayerActiveInventoryModifications> containersByOwner = new HashMap<>();
|
||||
private final Map<Location, ArrayList<PlayerActiveInventoryModifications>> containersByLocation = new HashMap<>();
|
||||
|
||||
public ChestAccessLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
final HumanEntity player = event.getPlayer();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
final PlayerActiveInventoryModifications modifications = containersByOwner.remove(player);
|
||||
if (modifications != null) {
|
||||
final Location loc = modifications.getLocation();
|
||||
ArrayList<PlayerActiveInventoryModifications> atLocation = containersByLocation.get(loc);
|
||||
atLocation.remove(modifications);
|
||||
if (atLocation.isEmpty()) {
|
||||
containersByLocation.remove(loc);
|
||||
}
|
||||
modifications.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
final HumanEntity player = event.getPlayer();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
if (event.getInventory() != null) {
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
if (getInventoryHolderType(holder) != Material.CRAFTING_TABLE) {
|
||||
PlayerActiveInventoryModifications modifications = new PlayerActiveInventoryModifications(event.getPlayer(), getInventoryHolderLocation(holder));
|
||||
containersByOwner.put(modifications.getActor(), modifications);
|
||||
containersByLocation.compute(modifications.getLocation(), (k, v) -> {
|
||||
if (v == null) {
|
||||
v = new ArrayList<>();
|
||||
}
|
||||
v.add(modifications);
|
||||
return v;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
final HumanEntity player = event.getWhoClicked();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
final PlayerActiveInventoryModifications modifications = containersByOwner.get(player);
|
||||
if (modifications != null) {
|
||||
switch (event.getAction()) {
|
||||
case PICKUP_ONE:
|
||||
case DROP_ONE_SLOT:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCurrentItem(), -1);
|
||||
}
|
||||
break;
|
||||
case PICKUP_HALF:
|
||||
// server behaviour: round up
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCurrentItem(), -(event.getCurrentItem().getAmount() + 1) / 2);
|
||||
}
|
||||
break;
|
||||
case PICKUP_SOME: // oversized stack - can not take all when clicking
|
||||
// server behaviour: leave a full stack in the slot, take everything else
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
int taken = event.getCurrentItem().getAmount() - event.getCurrentItem().getMaxStackSize();
|
||||
modifications.addModification(event.getCursor(), -taken);
|
||||
}
|
||||
break;
|
||||
case PICKUP_ALL:
|
||||
case DROP_ALL_SLOT:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCurrentItem(), -event.getCurrentItem().getAmount());
|
||||
}
|
||||
break;
|
||||
case PLACE_ONE:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCursor(), 1);
|
||||
}
|
||||
break;
|
||||
case PLACE_SOME: // not enough free place in target slot
|
||||
// server behaviour: place as much as possible
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
int placeable = event.getCurrentItem().getMaxStackSize() - event.getCurrentItem().getAmount();
|
||||
modifications.addModification(event.getCursor(), placeable);
|
||||
}
|
||||
break;
|
||||
case PLACE_ALL:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCursor(), event.getCursor().getAmount());
|
||||
}
|
||||
break;
|
||||
case SWAP_WITH_CURSOR:
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
modifications.addModification(event.getCursor(), event.getCursor().getAmount());
|
||||
modifications.addModification(event.getCurrentItem(), -event.getCurrentItem().getAmount());
|
||||
}
|
||||
break;
|
||||
case MOVE_TO_OTHER_INVENTORY: // shift + click
|
||||
boolean removed = event.getRawSlot() < event.getView().getTopInventory().getSize();
|
||||
modifications.addModification(event.getCurrentItem(), event.getCurrentItem().getAmount() * (removed ? -1 : 1));
|
||||
break;
|
||||
case COLLECT_TO_CURSOR: // double click
|
||||
// server behaviour: first collect all with an amount != maxstacksize, then others, starting from slot 0 (container)
|
||||
ItemStack cursor = event.getCursor();
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
int toPickUp = cursor.getMaxStackSize() - cursor.getAmount();
|
||||
int takenFromContainer = 0;
|
||||
boolean takeFromFullStacks = false;
|
||||
Inventory top = event.getView().getTopInventory();
|
||||
Inventory bottom = event.getView().getBottomInventory();
|
||||
while (toPickUp > 0) {
|
||||
for (ItemStack stack : top.getStorageContents()) {
|
||||
if (cursor.isSimilar(stack)) {
|
||||
if (takeFromFullStacks == (stack.getAmount() == stack.getMaxStackSize())) {
|
||||
int take = Math.min(toPickUp, stack.getAmount());
|
||||
toPickUp -= take;
|
||||
takenFromContainer += take;
|
||||
if (toPickUp <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toPickUp <= 0) {
|
||||
break;
|
||||
}
|
||||
for (ItemStack stack : bottom.getStorageContents()) {
|
||||
if (cursor.isSimilar(stack)) {
|
||||
if (takeFromFullStacks == (stack.getAmount() == stack.getMaxStackSize())) {
|
||||
int take = Math.min(toPickUp, stack.getAmount());
|
||||
toPickUp -= take;
|
||||
if (toPickUp <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (takeFromFullStacks) {
|
||||
break;
|
||||
} else {
|
||||
takeFromFullStacks = true;
|
||||
}
|
||||
}
|
||||
if (takenFromContainer > 0) {
|
||||
modifications.addModification(event.getCursor(), -takenFromContainer);
|
||||
}
|
||||
break;
|
||||
case HOTBAR_SWAP: // number key or offhand key
|
||||
case HOTBAR_MOVE_AND_READD: // something was in the other slot
|
||||
if (event.getRawSlot() < event.getView().getTopInventory().getSize()) {
|
||||
ItemStack otherSlot = (event.getClick() == ClickType.SWAP_OFFHAND) ? event.getWhoClicked().getInventory().getItemInOffHand() : event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) {
|
||||
modifications.addModification(event.getCurrentItem(), -event.getCurrentItem().getAmount());
|
||||
}
|
||||
if (otherSlot != null && otherSlot.getType() != Material.AIR) {
|
||||
modifications.addModification(otherSlot, otherSlot.getAmount());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DROP_ALL_CURSOR:
|
||||
case DROP_ONE_CURSOR:
|
||||
case CLONE_STACK:
|
||||
case NOTHING:
|
||||
// only the cursor or nothing (but not the inventory) was modified
|
||||
break;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
// unable to log something we don't know
|
||||
consumer.getLogblock().getLogger().warning("Unknown inventory action by " + event.getWhoClicked().getName() + ": " + event.getAction() + " Slot: " + event.getSlot() + " Slot type: " + event.getSlotType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryDrag(InventoryDragEvent event) {
|
||||
final HumanEntity player = event.getWhoClicked();
|
||||
if (!isLogging(player.getWorld(), Logging.CHESTACCESS)) {
|
||||
return;
|
||||
}
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if (holder instanceof BlockState || holder instanceof DoubleChest) {
|
||||
final PlayerActiveInventoryModifications modifications = containersByOwner.get(player);
|
||||
if (modifications != null) {
|
||||
Inventory container = event.getView().getTopInventory();
|
||||
int containerSize = container.getSize();
|
||||
for (Entry<Integer, ItemStack> e : event.getNewItems().entrySet()) {
|
||||
int slot = e.getKey();
|
||||
if (slot < containerSize) {
|
||||
ItemStack old = container.getItem(slot);
|
||||
int oldAmount = (old == null || old.getType() == Material.AIR) ? 0 : old.getAmount();
|
||||
modifications.addModification(e.getValue(), e.getValue().getAmount() - oldAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class EndermenLogging extends LoggingListener {
|
||||
public EndermenLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
if (event.getEntity() instanceof Enderman && isLogging(event.getBlock().getWorld(), Logging.ENDERMEN)) {
|
||||
consumer.queueBlockReplace(new Actor("Enderman"), event.getBlock().getState(), event.getBlockData()); // Figure out how to get the data of the placed block;
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class EndermenLogging extends LoggingListener {
|
||||
public EndermenLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
if (event.getEntity() instanceof Enderman && isLogging(event.getBlock().getWorld(), Logging.ENDERMEN)) {
|
||||
consumer.queueBlockReplace(new Actor("Enderman"), event.getBlock().getState(), event.getBlockData()); // Figure out how to get the data of the placed block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,229 +1,229 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.RespawnAnchor;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
import static de.diddiz.LogBlock.config.Config.logCreeperExplosionsAsPlayerWhoTriggeredThese;
|
||||
import static de.diddiz.LogBlock.util.BukkitUtils.getContainerBlocks;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExplosionLogging extends LoggingListener {
|
||||
|
||||
private UUID lastBedInteractionPlayer;
|
||||
private Location lastBedInteractionLocation;
|
||||
private UUID lastRespawnAnchorInteractionPlayer;
|
||||
private Location lastRespawnAnchorInteractionLocation;
|
||||
|
||||
public ExplosionLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getLocation().getWorld());
|
||||
if (wcfg != null) {
|
||||
Actor actor = new Actor("Explosion");
|
||||
Entity source = event.getEntity();
|
||||
if (source == null) {
|
||||
if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
} else if (source instanceof TNTPrimed) {
|
||||
if (!wcfg.isLogging(Logging.TNTEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("TNT");
|
||||
} else if (source instanceof ExplosiveMinecart) {
|
||||
if (!wcfg.isLogging(Logging.TNTMINECARTEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("TNTMinecart");
|
||||
} else if (source instanceof Creeper) {
|
||||
if (!wcfg.isLogging(Logging.CREEPEREXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
if (logCreeperExplosionsAsPlayerWhoTriggeredThese) {
|
||||
final Entity target = ((Creeper) source).getTarget();
|
||||
actor = target instanceof Player ? Actor.actorFromEntity(target) : new Actor("Creeper");
|
||||
} else {
|
||||
actor = new Actor("Creeper");
|
||||
}
|
||||
} else if (source instanceof Wither) {
|
||||
if (!wcfg.isLogging(Logging.WITHER)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (source instanceof WitherSkull) {
|
||||
if (!wcfg.isLogging(Logging.WITHER_SKULL)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (source instanceof Fireball) {
|
||||
Fireball fireball = (Fireball) source;
|
||||
ProjectileSource shooter = fireball.getShooter();
|
||||
if (shooter == null) {
|
||||
if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (shooter instanceof Ghast) {
|
||||
if (!wcfg.isLogging(Logging.GHASTFIREBALLEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromProjectileSource(shooter);
|
||||
} else if (shooter instanceof Wither) {
|
||||
if (!wcfg.isLogging(Logging.WITHER)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromProjectileSource(shooter);
|
||||
}
|
||||
} else if (source instanceof EnderDragon) {
|
||||
if (!wcfg.isLogging(Logging.ENDERDRAGON)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (source instanceof EnderCrystal) {
|
||||
if (!wcfg.isLogging(Logging.ENDERCRYSTALEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
|
||||
} else {
|
||||
if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (final Block block : event.blockList()) {
|
||||
final Material type = block.getType();
|
||||
if (wcfg.isLogging(Logging.CHESTACCESS) && getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||
consumer.queueContainerBreak(actor, block.getState());
|
||||
} else {
|
||||
consumer.queueBlockBreak(actor, block.getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock()) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (BukkitUtils.isBed(block.getType()) && !block.getWorld().isBedWorks()) {
|
||||
if (!Config.isLogging(block.getWorld(), Logging.BEDEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
lastBedInteractionPlayer = event.getPlayer().getUniqueId();
|
||||
lastBedInteractionLocation = block.getLocation();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lastBedInteractionPlayer = null;
|
||||
lastBedInteractionLocation = null;
|
||||
}
|
||||
}.runTask(LogBlock.getInstance());
|
||||
} else if (block.getType() == Material.RESPAWN_ANCHOR && block.getBlockData() instanceof RespawnAnchor data) {
|
||||
if (!Config.isLogging(block.getWorld(), Logging.RESPAWNANCHOREXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
ItemStack inHand = event.getItem();
|
||||
int charges = data.getCharges();
|
||||
if (charges < data.getMaximumCharges() && inHand != null && inHand.getType() == Material.GLOWSTONE) {
|
||||
// charge
|
||||
Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
RespawnAnchor blockNew = (RespawnAnchor) data.clone();
|
||||
blockNew.setCharges(charges + 1);
|
||||
consumer.queueBlockReplace(actor, block.getState(), blockNew);
|
||||
} else if (charges > 0 && !block.getWorld().isRespawnAnchorWorks()) {
|
||||
// explode
|
||||
Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
consumer.queueBlockBreak(actor, block.getState());
|
||||
lastRespawnAnchorInteractionPlayer = event.getPlayer().getUniqueId();
|
||||
lastRespawnAnchorInteractionLocation = block.getLocation();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lastRespawnAnchorInteractionPlayer = null;
|
||||
lastRespawnAnchorInteractionLocation = null;
|
||||
}
|
||||
}.runTask(LogBlock.getInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockExplode(BlockExplodeEvent event) {
|
||||
Player bedCause = null;
|
||||
if (lastBedInteractionPlayer != null && lastBedInteractionLocation != null) {
|
||||
Location block = event.getBlock().getLocation();
|
||||
if (lastBedInteractionLocation.getWorld() == block.getWorld() && block.distanceSquared(lastBedInteractionLocation) <= 1) {
|
||||
bedCause = Bukkit.getPlayer(lastBedInteractionPlayer);
|
||||
}
|
||||
}
|
||||
Player respawnAnchorCause = null;
|
||||
if (lastRespawnAnchorInteractionPlayer != null && lastRespawnAnchorInteractionLocation != null) {
|
||||
Location block = event.getBlock().getLocation();
|
||||
if (lastRespawnAnchorInteractionLocation.equals(block)) {
|
||||
respawnAnchorCause = Bukkit.getPlayer(lastRespawnAnchorInteractionPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
for (final Block block : event.blockList()) {
|
||||
final WorldConfig wcfg = getWorldConfig(block.getLocation().getWorld());
|
||||
|
||||
if (wcfg != null) {
|
||||
Actor actor = new Actor("Explosion");
|
||||
if (bedCause != null) {
|
||||
if (!wcfg.isLogging(Logging.BEDEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
if (Config.logBedExplosionsAsPlayerWhoTriggeredThese) {
|
||||
actor = Actor.actorFromEntity(bedCause);
|
||||
} else {
|
||||
actor = new Actor("BedExplosion");
|
||||
}
|
||||
} else if (respawnAnchorCause != null) {
|
||||
if (!wcfg.isLogging(Logging.RESPAWNANCHOREXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
if (Config.logBedExplosionsAsPlayerWhoTriggeredThese) {
|
||||
actor = Actor.actorFromEntity(respawnAnchorCause);
|
||||
} else {
|
||||
actor = new Actor("RespawnAnchorExplosion");
|
||||
}
|
||||
} else if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Material type = block.getType();
|
||||
if (wcfg.isLogging(Logging.CHESTACCESS) && getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||
consumer.queueContainerBreak(actor, block.getState());
|
||||
} else {
|
||||
consumer.queueBlockBreak(actor, block.getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.RespawnAnchor;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
import static de.diddiz.LogBlock.config.Config.logCreeperExplosionsAsPlayerWhoTriggeredThese;
|
||||
import static de.diddiz.LogBlock.util.BukkitUtils.getContainerBlocks;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExplosionLogging extends LoggingListener {
|
||||
|
||||
private UUID lastBedInteractionPlayer;
|
||||
private Location lastBedInteractionLocation;
|
||||
private UUID lastRespawnAnchorInteractionPlayer;
|
||||
private Location lastRespawnAnchorInteractionLocation;
|
||||
|
||||
public ExplosionLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getLocation().getWorld());
|
||||
if (wcfg != null) {
|
||||
Actor actor = new Actor("Explosion");
|
||||
Entity source = event.getEntity();
|
||||
if (source == null) {
|
||||
if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
} else if (source instanceof TNTPrimed) {
|
||||
if (!wcfg.isLogging(Logging.TNTEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("TNT");
|
||||
} else if (source instanceof ExplosiveMinecart) {
|
||||
if (!wcfg.isLogging(Logging.TNTMINECARTEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = new Actor("TNTMinecart");
|
||||
} else if (source instanceof Creeper) {
|
||||
if (!wcfg.isLogging(Logging.CREEPEREXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
if (logCreeperExplosionsAsPlayerWhoTriggeredThese) {
|
||||
final Entity target = ((Creeper) source).getTarget();
|
||||
actor = target instanceof Player ? Actor.actorFromEntity(target) : new Actor("Creeper");
|
||||
} else {
|
||||
actor = new Actor("Creeper");
|
||||
}
|
||||
} else if (source instanceof Wither) {
|
||||
if (!wcfg.isLogging(Logging.WITHER)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (source instanceof WitherSkull) {
|
||||
if (!wcfg.isLogging(Logging.WITHER_SKULL)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (source instanceof Fireball) {
|
||||
Fireball fireball = (Fireball) source;
|
||||
ProjectileSource shooter = fireball.getShooter();
|
||||
if (shooter == null) {
|
||||
if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (shooter instanceof Ghast) {
|
||||
if (!wcfg.isLogging(Logging.GHASTFIREBALLEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromProjectileSource(shooter);
|
||||
} else if (shooter instanceof Wither) {
|
||||
if (!wcfg.isLogging(Logging.WITHER)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromProjectileSource(shooter);
|
||||
}
|
||||
} else if (source instanceof EnderDragon) {
|
||||
if (!wcfg.isLogging(Logging.ENDERDRAGON)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
} else if (source instanceof EnderCrystal) {
|
||||
if (!wcfg.isLogging(Logging.ENDERCRYSTALEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
actor = Actor.actorFromEntity(source);
|
||||
|
||||
} else {
|
||||
if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (final Block block : event.blockList()) {
|
||||
final Material type = block.getType();
|
||||
if (wcfg.isLogging(Logging.CHESTACCESS) && getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||
consumer.queueContainerBreak(actor, block.getState());
|
||||
} else {
|
||||
consumer.queueBlockBreak(actor, block.getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock()) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (BukkitUtils.isBed(block.getType()) && !block.getWorld().isBedWorks()) {
|
||||
if (!Config.isLogging(block.getWorld(), Logging.BEDEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
lastBedInteractionPlayer = event.getPlayer().getUniqueId();
|
||||
lastBedInteractionLocation = block.getLocation();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lastBedInteractionPlayer = null;
|
||||
lastBedInteractionLocation = null;
|
||||
}
|
||||
}.runTask(LogBlock.getInstance());
|
||||
} else if (block.getType() == Material.RESPAWN_ANCHOR && block.getBlockData() instanceof RespawnAnchor data) {
|
||||
if (!Config.isLogging(block.getWorld(), Logging.RESPAWNANCHOREXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
ItemStack inHand = event.getItem();
|
||||
int charges = data.getCharges();
|
||||
if (charges < data.getMaximumCharges() && inHand != null && inHand.getType() == Material.GLOWSTONE) {
|
||||
// charge
|
||||
Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
RespawnAnchor blockNew = (RespawnAnchor) data.clone();
|
||||
blockNew.setCharges(charges + 1);
|
||||
consumer.queueBlockReplace(actor, block.getState(), blockNew);
|
||||
} else if (charges > 0 && !block.getWorld().isRespawnAnchorWorks()) {
|
||||
// explode
|
||||
Actor actor = Actor.actorFromEntity(event.getPlayer());
|
||||
consumer.queueBlockBreak(actor, block.getState());
|
||||
lastRespawnAnchorInteractionPlayer = event.getPlayer().getUniqueId();
|
||||
lastRespawnAnchorInteractionLocation = block.getLocation();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lastRespawnAnchorInteractionPlayer = null;
|
||||
lastRespawnAnchorInteractionLocation = null;
|
||||
}
|
||||
}.runTask(LogBlock.getInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockExplode(BlockExplodeEvent event) {
|
||||
Player bedCause = null;
|
||||
if (lastBedInteractionPlayer != null && lastBedInteractionLocation != null) {
|
||||
Location block = event.getBlock().getLocation();
|
||||
if (lastBedInteractionLocation.getWorld() == block.getWorld() && block.distanceSquared(lastBedInteractionLocation) <= 1) {
|
||||
bedCause = Bukkit.getPlayer(lastBedInteractionPlayer);
|
||||
}
|
||||
}
|
||||
Player respawnAnchorCause = null;
|
||||
if (lastRespawnAnchorInteractionPlayer != null && lastRespawnAnchorInteractionLocation != null) {
|
||||
Location block = event.getBlock().getLocation();
|
||||
if (lastRespawnAnchorInteractionLocation.equals(block)) {
|
||||
respawnAnchorCause = Bukkit.getPlayer(lastRespawnAnchorInteractionPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
for (final Block block : event.blockList()) {
|
||||
final WorldConfig wcfg = getWorldConfig(block.getLocation().getWorld());
|
||||
|
||||
if (wcfg != null) {
|
||||
Actor actor = new Actor("Explosion");
|
||||
if (bedCause != null) {
|
||||
if (!wcfg.isLogging(Logging.BEDEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
if (Config.logBedExplosionsAsPlayerWhoTriggeredThese) {
|
||||
actor = Actor.actorFromEntity(bedCause);
|
||||
} else {
|
||||
actor = new Actor("BedExplosion");
|
||||
}
|
||||
} else if (respawnAnchorCause != null) {
|
||||
if (!wcfg.isLogging(Logging.RESPAWNANCHOREXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
if (Config.logBedExplosionsAsPlayerWhoTriggeredThese) {
|
||||
actor = Actor.actorFromEntity(respawnAnchorCause);
|
||||
} else {
|
||||
actor = new Actor("RespawnAnchorExplosion");
|
||||
}
|
||||
} else if (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Material type = block.getType();
|
||||
if (wcfg.isLogging(Logging.CHESTACCESS) && getContainerBlocks().contains(type) && !BukkitUtils.getShulkerBoxBlocks().contains(type)) {
|
||||
consumer.queueContainerBreak(actor, block.getState());
|
||||
} else {
|
||||
consumer.queueBlockBreak(actor, block.getState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,127 +1,127 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
|
||||
public class FluidFlowLogging extends LoggingListener {
|
||||
|
||||
public FluidFlowLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
if (wcfg != null && (wcfg.isLogging(Logging.WATERFLOW) || wcfg.isLogging(Logging.LAVAFLOW))) {
|
||||
final BlockData blockDataFrom = event.getBlock().getBlockData();
|
||||
Material typeFrom = blockDataFrom.getMaterial();
|
||||
boolean fromWaterlogged = false;
|
||||
if (blockDataFrom instanceof Waterlogged) {
|
||||
typeFrom = Material.WATER;
|
||||
fromWaterlogged = true;
|
||||
}
|
||||
if (typeFrom == Material.SEAGRASS || typeFrom == Material.KELP_PLANT || typeFrom == Material.KELP) {
|
||||
typeFrom = Material.WATER;
|
||||
fromWaterlogged = true;
|
||||
}
|
||||
|
||||
Block source = Config.logFluidFlowAsPlayerWhoTriggeredIt ? event.getBlock() : null;
|
||||
final Block to = event.getToBlock();
|
||||
final Material typeTo = to.getType();
|
||||
boolean down = event.getFace() == BlockFace.DOWN;
|
||||
final boolean canFlow = BukkitUtils.isEmpty(typeTo) || BukkitUtils.getNonFluidProofBlocks().contains(typeTo);
|
||||
if (typeFrom == Material.LAVA && wcfg.isLogging(Logging.LAVAFLOW)) {
|
||||
Levelled levelledFrom = (Levelled) blockDataFrom;
|
||||
if (canFlow) {
|
||||
if (isSurroundedByWater(to) && levelledFrom.getLevel() <= 2) {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), Material.COBBLESTONE.createBlockData());
|
||||
} else {
|
||||
Levelled newBlock = (Levelled) blockDataFrom.clone();
|
||||
newBlock.setLevel(down ? 1 : Math.min(levelledFrom.getLevel() + 1, levelledFrom.getMaximumLevel()));
|
||||
if (BukkitUtils.isEmpty(typeTo)) {
|
||||
consumer.queueBlockPlace(new Actor("LavaFlow", source), to.getLocation(), newBlock);
|
||||
} else {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), newBlock);
|
||||
}
|
||||
}
|
||||
} else if (typeTo == Material.WATER) {
|
||||
if (down) {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), Material.STONE.createBlockData());
|
||||
} else {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), Material.COBBLESTONE.createBlockData());
|
||||
}
|
||||
}
|
||||
} else if ((typeFrom == Material.WATER) && wcfg.isLogging(Logging.WATERFLOW)) {
|
||||
Levelled levelledFrom = fromWaterlogged ? null : (Levelled) blockDataFrom;
|
||||
Levelled newBlock = (Levelled) Material.WATER.createBlockData();
|
||||
newBlock.setLevel(fromWaterlogged || down ? 1 : Math.min(levelledFrom.getLevel() + 1, levelledFrom.getMaximumLevel()));
|
||||
if (BukkitUtils.isEmpty(typeTo)) {
|
||||
consumer.queueBlockPlace(new Actor("WaterFlow", source), to.getLocation(), newBlock);
|
||||
} else if (BukkitUtils.getNonFluidProofBlocks().contains(typeTo)) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), to.getState(), newBlock);
|
||||
} else if (typeTo == Material.LAVA) {
|
||||
int toLevel = ((Levelled) to.getBlockData()).getLevel();
|
||||
if (toLevel == 0) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), to.getState(), Material.OBSIDIAN.createBlockData());
|
||||
} else if (event.getFace() == BlockFace.DOWN) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), to.getState(), Material.STONE.createBlockData());
|
||||
}
|
||||
}
|
||||
if (BukkitUtils.isEmpty(typeTo) || BukkitUtils.getNonFluidProofBlocks().contains(typeTo)) {
|
||||
for (final BlockFace face : new BlockFace[] { BlockFace.DOWN, BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH }) {
|
||||
final Block lower = to.getRelative(face);
|
||||
if (lower.getType() == Material.LAVA) {
|
||||
int toLevel = ((Levelled) lower.getBlockData()).getLevel();
|
||||
if (toLevel == 0) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), lower.getState(), Material.OBSIDIAN.createBlockData());
|
||||
} else if (event.getFace() == BlockFace.DOWN) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), lower.getState(), Material.STONE.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
if (wcfg != null && (wcfg.isLogging(Logging.WATERFLOW) || wcfg.isLogging(Logging.LAVAFLOW))) {
|
||||
if (wcfg.isLogging(Logging.LAVAFLOW) && event.getBlock().getType() == Material.WATER && event.getNewState().getType() == Material.COBBLESTONE) {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow"), event.getBlock().getBlockData(), event.getNewState());
|
||||
}
|
||||
if (wcfg.isLogging(Logging.WATERFLOW) && event.getBlock().getType() == Material.LAVA) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow"), event.getBlock().getBlockData(), event.getNewState());
|
||||
}
|
||||
if (wcfg.isLogging(Logging.WATERFLOW) && BukkitUtils.isConcreteBlock(event.getNewState().getType())) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow"), event.getBlock().getBlockData(), event.getNewState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSurroundedByWater(Block block) {
|
||||
for (final BlockFace face : new BlockFace[] { BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH }) {
|
||||
if (block.getRelative(face).getType() == Material.WATER) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockFromToEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
|
||||
public class FluidFlowLogging extends LoggingListener {
|
||||
|
||||
public FluidFlowLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockFromTo(BlockFromToEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
if (wcfg != null && (wcfg.isLogging(Logging.WATERFLOW) || wcfg.isLogging(Logging.LAVAFLOW))) {
|
||||
final BlockData blockDataFrom = event.getBlock().getBlockData();
|
||||
Material typeFrom = blockDataFrom.getMaterial();
|
||||
boolean fromWaterlogged = false;
|
||||
if (blockDataFrom instanceof Waterlogged) {
|
||||
typeFrom = Material.WATER;
|
||||
fromWaterlogged = true;
|
||||
}
|
||||
if (typeFrom == Material.SEAGRASS || typeFrom == Material.KELP_PLANT || typeFrom == Material.KELP) {
|
||||
typeFrom = Material.WATER;
|
||||
fromWaterlogged = true;
|
||||
}
|
||||
|
||||
Block source = Config.logFluidFlowAsPlayerWhoTriggeredIt ? event.getBlock() : null;
|
||||
final Block to = event.getToBlock();
|
||||
final Material typeTo = to.getType();
|
||||
boolean down = event.getFace() == BlockFace.DOWN;
|
||||
final boolean canFlow = BukkitUtils.isEmpty(typeTo) || BukkitUtils.getNonFluidProofBlocks().contains(typeTo);
|
||||
if (typeFrom == Material.LAVA && wcfg.isLogging(Logging.LAVAFLOW)) {
|
||||
Levelled levelledFrom = (Levelled) blockDataFrom;
|
||||
if (canFlow) {
|
||||
if (isSurroundedByWater(to) && levelledFrom.getLevel() <= 2) {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), Material.COBBLESTONE.createBlockData());
|
||||
} else {
|
||||
Levelled newBlock = (Levelled) blockDataFrom.clone();
|
||||
newBlock.setLevel(down ? 1 : Math.min(levelledFrom.getLevel() + 1, levelledFrom.getMaximumLevel()));
|
||||
if (BukkitUtils.isEmpty(typeTo)) {
|
||||
consumer.queueBlockPlace(new Actor("LavaFlow", source), to.getLocation(), newBlock);
|
||||
} else {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), newBlock);
|
||||
}
|
||||
}
|
||||
} else if (typeTo == Material.WATER) {
|
||||
if (down) {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), Material.STONE.createBlockData());
|
||||
} else {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow", source), to.getState(), Material.COBBLESTONE.createBlockData());
|
||||
}
|
||||
}
|
||||
} else if ((typeFrom == Material.WATER) && wcfg.isLogging(Logging.WATERFLOW)) {
|
||||
Levelled levelledFrom = fromWaterlogged ? null : (Levelled) blockDataFrom;
|
||||
Levelled newBlock = (Levelled) Material.WATER.createBlockData();
|
||||
newBlock.setLevel(fromWaterlogged || down ? 1 : Math.min(levelledFrom.getLevel() + 1, levelledFrom.getMaximumLevel()));
|
||||
if (BukkitUtils.isEmpty(typeTo)) {
|
||||
consumer.queueBlockPlace(new Actor("WaterFlow", source), to.getLocation(), newBlock);
|
||||
} else if (BukkitUtils.getNonFluidProofBlocks().contains(typeTo)) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), to.getState(), newBlock);
|
||||
} else if (typeTo == Material.LAVA) {
|
||||
int toLevel = ((Levelled) to.getBlockData()).getLevel();
|
||||
if (toLevel == 0) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), to.getState(), Material.OBSIDIAN.createBlockData());
|
||||
} else if (event.getFace() == BlockFace.DOWN) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), to.getState(), Material.STONE.createBlockData());
|
||||
}
|
||||
}
|
||||
if (BukkitUtils.isEmpty(typeTo) || BukkitUtils.getNonFluidProofBlocks().contains(typeTo)) {
|
||||
for (final BlockFace face : new BlockFace[] { BlockFace.DOWN, BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH }) {
|
||||
final Block lower = to.getRelative(face);
|
||||
if (lower.getType() == Material.LAVA) {
|
||||
int toLevel = ((Levelled) lower.getBlockData()).getLevel();
|
||||
if (toLevel == 0) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), lower.getState(), Material.OBSIDIAN.createBlockData());
|
||||
} else if (event.getFace() == BlockFace.DOWN) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow", source), lower.getState(), Material.STONE.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
|
||||
if (wcfg != null && (wcfg.isLogging(Logging.WATERFLOW) || wcfg.isLogging(Logging.LAVAFLOW))) {
|
||||
if (wcfg.isLogging(Logging.LAVAFLOW) && event.getBlock().getType() == Material.WATER && event.getNewState().getType() == Material.COBBLESTONE) {
|
||||
consumer.queueBlockReplace(new Actor("LavaFlow"), event.getBlock().getBlockData(), event.getNewState());
|
||||
}
|
||||
if (wcfg.isLogging(Logging.WATERFLOW) && event.getBlock().getType() == Material.LAVA) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow"), event.getBlock().getBlockData(), event.getNewState());
|
||||
}
|
||||
if (wcfg.isLogging(Logging.WATERFLOW) && BukkitUtils.isConcreteBlock(event.getNewState().getType())) {
|
||||
consumer.queueBlockReplace(new Actor("WaterFlow"), event.getBlock().getBlockData(), event.getNewState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSurroundedByWater(Block block) {
|
||||
for (final BlockFace face : new BlockFace[] { BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH }) {
|
||||
if (block.getRelative(face).getType() == Material.WATER) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,276 +1,276 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.Reflections;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.Note.Tone;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.type.Cake;
|
||||
import org.bukkit.block.data.type.Candle;
|
||||
import org.bukkit.block.data.type.Comparator;
|
||||
import org.bukkit.block.data.type.Comparator.Mode;
|
||||
import org.bukkit.block.data.type.DaylightDetector;
|
||||
import org.bukkit.block.data.type.Door;
|
||||
import org.bukkit.block.data.type.NoteBlock;
|
||||
import org.bukkit.block.data.type.Repeater;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.block.data.type.TurtleEgg;
|
||||
import org.bukkit.block.sign.Side;
|
||||
import org.bukkit.block.sign.SignSide;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.world.GenericGameEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
|
||||
public class InteractLogging extends LoggingListener {
|
||||
public InteractLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
private UUID lastInteractionPlayer;
|
||||
private BlockData lastInteractionBlockData;
|
||||
private Location lastInteractionLocation;
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getPlayer().getWorld());
|
||||
if (wcfg != null) {
|
||||
final Block clicked = event.getClickedBlock();
|
||||
if (clicked == null) {
|
||||
return;
|
||||
}
|
||||
final BlockData blockData = clicked.getBlockData();
|
||||
final Material type = blockData.getMaterial();
|
||||
final Player player = event.getPlayer();
|
||||
final Location loc = clicked.getLocation();
|
||||
lastInteractionPlayer = player.getUniqueId();
|
||||
lastInteractionBlockData = blockData;
|
||||
lastInteractionLocation = loc;
|
||||
|
||||
if (BukkitUtils.isFenceGate(type) || BukkitUtils.isWoodenTrapdoor(type)) {
|
||||
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Openable newBlockData = (Openable) blockData.clone();
|
||||
newBlockData.setOpen(!newBlockData.isOpen());
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (BukkitUtils.isPressurePlate(type)) {
|
||||
if (wcfg.isLogging(Logging.PRESUREPLATEINTERACT) && event.getAction() == Action.PHYSICAL) {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, blockData);
|
||||
}
|
||||
} else if (BukkitUtils.isWoodenDoor(type)) {
|
||||
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Door newBlockData = (Door) blockData.clone();
|
||||
newBlockData.setOpen(!newBlockData.isOpen());
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (BukkitUtils.isButton(type) || type == Material.LEVER) {
|
||||
if (wcfg.isLogging(Logging.SWITCHINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Switch newBlockData = (Switch) blockData.clone();
|
||||
if (!newBlockData.isPowered() || type == Material.LEVER) {
|
||||
newBlockData.setPowered(!newBlockData.isPowered());
|
||||
}
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (BukkitUtils.isSign(type)) {
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getItem() != null) {
|
||||
Material itemType = event.getItem().getType();
|
||||
if (BukkitUtils.isDye(itemType) || itemType == Material.GLOW_INK_SAC || itemType == Material.INK_SAC || itemType == Material.HONEYCOMB) {
|
||||
final BlockState before = event.getClickedBlock().getState();
|
||||
if (before instanceof Sign signBefore) {
|
||||
boolean waxed = Reflections.isSignWaxed(signBefore);
|
||||
if (!waxed) {
|
||||
final Sign signAfter = (Sign) event.getClickedBlock().getState();
|
||||
Side side = BukkitUtils.getFacingSignSide(player, clicked);
|
||||
SignSide signSideBefore = signBefore.getSide(side);
|
||||
SignSide signSideAfter = signAfter.getSide(side);
|
||||
if (itemType == Material.GLOW_INK_SAC) {
|
||||
if (!signSideBefore.isGlowingText() && hasText(signSideBefore)) {
|
||||
signSideAfter.setGlowingText(true);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
}
|
||||
} else if (itemType == Material.INK_SAC) {
|
||||
if (signSideBefore.isGlowingText() && hasText(signSideBefore)) {
|
||||
signSideAfter.setGlowingText(false);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
}
|
||||
} else if (itemType == Material.HONEYCOMB) {
|
||||
signAfter.setEditable(false);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
} else if (BukkitUtils.isDye(itemType) && hasText(signSideBefore)) {
|
||||
DyeColor newColor = BukkitUtils.dyeToDyeColor(itemType);
|
||||
if (newColor != null && signSideBefore.getColor() != newColor) {
|
||||
signSideAfter.setColor(newColor);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (type == Material.CAKE) {
|
||||
if (event.hasItem() && BukkitUtils.isCandle(event.getItem().getType()) && event.useItemInHand() != Result.DENY) {
|
||||
BlockData newBlockData = Material.valueOf(event.getItem().getType().name() + "_CAKE").createBlockData();
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
} else if (wcfg.isLogging(Logging.CAKEEAT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getFoodLevel() < 20) {
|
||||
Cake newBlockData = (Cake) blockData.clone();
|
||||
if (newBlockData.getBites() < 6) {
|
||||
newBlockData.setBites(newBlockData.getBites() + 1);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
} else {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, Material.AIR.createBlockData());
|
||||
}
|
||||
}
|
||||
} else if (type == Material.NOTE_BLOCK) {
|
||||
if (wcfg.isLogging(Logging.NOTEBLOCKINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
NoteBlock newBlockData = (NoteBlock) blockData.clone();
|
||||
if (newBlockData.getNote().getOctave() == 2) {
|
||||
newBlockData.setNote(new Note(0, Tone.F, true));
|
||||
} else {
|
||||
newBlockData.setNote(newBlockData.getNote().sharped());
|
||||
}
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.REPEATER) {
|
||||
if (wcfg.isLogging(Logging.DIODEINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Repeater newBlockData = (Repeater) blockData.clone();
|
||||
newBlockData.setDelay((newBlockData.getDelay() % 4) + 1);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.COMPARATOR) {
|
||||
if (wcfg.isLogging(Logging.COMPARATORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Comparator newBlockData = (Comparator) blockData.clone();
|
||||
newBlockData.setMode(newBlockData.getMode() == Mode.COMPARE ? Mode.SUBTRACT : Mode.COMPARE);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.DAYLIGHT_DETECTOR) {
|
||||
if (wcfg.isLogging(Logging.DAYLIGHTDETECTORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
DaylightDetector newBlockData = (DaylightDetector) blockData.clone();
|
||||
newBlockData.setInverted(!newBlockData.isInverted());
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.TRIPWIRE) {
|
||||
if (wcfg.isLogging(Logging.TRIPWIREINTERACT) && event.getAction() == Action.PHYSICAL) {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, blockData);
|
||||
}
|
||||
} else if (type == Material.FARMLAND) {
|
||||
if (wcfg.isLogging(Logging.CROPTRAMPLE) && event.getAction() == Action.PHYSICAL) {
|
||||
// 3 = Dirt ID
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, Material.DIRT.createBlockData());
|
||||
// Log the crop on top as being broken
|
||||
Block trampledCrop = clicked.getRelative(BlockFace.UP);
|
||||
if (BukkitUtils.getCropBlocks().contains(trampledCrop.getType())) {
|
||||
consumer.queueBlockBreak(Actor.actorFromEntity(player), trampledCrop.getState());
|
||||
}
|
||||
}
|
||||
} else if (type == Material.TURTLE_EGG) {
|
||||
if (wcfg.isLogging(Logging.BLOCKBREAK) && event.getAction() == Action.PHYSICAL) {
|
||||
TurtleEgg turtleEggData = (TurtleEgg) blockData;
|
||||
int eggs = turtleEggData.getEggs();
|
||||
if (eggs > 1) {
|
||||
TurtleEgg turtleEggData2 = (TurtleEgg) turtleEggData.clone();
|
||||
turtleEggData2.setEggs(eggs - 1);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, turtleEggData, turtleEggData2);
|
||||
} else {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, turtleEggData, Material.AIR.createBlockData());
|
||||
}
|
||||
}
|
||||
} else if (type == Material.PUMPKIN) {
|
||||
if ((wcfg.isLogging(Logging.BLOCKBREAK) || wcfg.isLogging(Logging.BLOCKPLACE)) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
ItemStack inHand = event.getItem();
|
||||
if (inHand != null && inHand.getType() == Material.SHEARS) {
|
||||
BlockFace clickedFace = event.getBlockFace();
|
||||
Directional newBlockData = (Directional) Material.CARVED_PUMPKIN.createBlockData();
|
||||
if (clickedFace == BlockFace.NORTH || clickedFace == BlockFace.SOUTH || clickedFace == BlockFace.EAST || clickedFace == BlockFace.WEST) {
|
||||
newBlockData.setFacing(clickedFace);
|
||||
} else {
|
||||
// use player distance to calculate the facing
|
||||
Location playerLoc = player.getLocation();
|
||||
playerLoc.subtract(0.5, 0, 0.5);
|
||||
double dx = playerLoc.getX() - loc.getX();
|
||||
double dz = playerLoc.getZ() - loc.getZ();
|
||||
if (Math.abs(dx) > Math.abs(dz)) {
|
||||
newBlockData.setFacing(dx > 0 ? BlockFace.EAST : BlockFace.WEST);
|
||||
} else {
|
||||
newBlockData.setFacing(dz > 0 ? BlockFace.SOUTH : BlockFace.NORTH);
|
||||
}
|
||||
}
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasText(SignSide signSide) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!signSide.getLine(i).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onGenericGameEvent(GenericGameEvent event) {
|
||||
if (lastInteractionPlayer != null && event.getEntity() != null && event.getEntity().getUniqueId().equals(lastInteractionPlayer) && lastInteractionLocation != null && event.getLocation().equals(lastInteractionLocation)) {
|
||||
if (lastInteractionBlockData instanceof Candle) {
|
||||
Candle previousCandle = (Candle) lastInteractionBlockData;
|
||||
if (previousCandle.isLit()) {
|
||||
BlockData newData = lastInteractionLocation.getBlock().getBlockData();
|
||||
if (newData instanceof Candle) {
|
||||
Candle newCandle = (Candle) newData;
|
||||
if (!newCandle.isLit() && !newCandle.isWaterlogged()) {
|
||||
// log candle extinguish
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (lastInteractionBlockData instanceof Lightable && BukkitUtils.isCandleCake(lastInteractionBlockData.getMaterial())) {
|
||||
Lightable previousLightable = (Lightable) lastInteractionBlockData;
|
||||
BlockData newData = lastInteractionLocation.getBlock().getBlockData();
|
||||
if (event.getEvent().equals(GameEvent.EAT)) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getLocation().getWorld());
|
||||
if (wcfg.isLogging(Logging.CAKEEAT)) {
|
||||
// nom nom (don't know why newData is incorrect here)
|
||||
newData = Material.CAKE.createBlockData();
|
||||
((Cake) newData).setBites(1);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
} else if (previousLightable.isLit()) {
|
||||
if (newData instanceof Lightable) {
|
||||
Lightable newLightable = (Lightable) newData;
|
||||
if (!newLightable.isLit()) {
|
||||
// log cake extinguish
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastInteractionPlayer = null;
|
||||
lastInteractionBlockData = null;
|
||||
lastInteractionLocation = null;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.Reflections;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Note;
|
||||
import org.bukkit.Note.Tone;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.block.data.Openable;
|
||||
import org.bukkit.block.data.type.Cake;
|
||||
import org.bukkit.block.data.type.Candle;
|
||||
import org.bukkit.block.data.type.Comparator;
|
||||
import org.bukkit.block.data.type.Comparator.Mode;
|
||||
import org.bukkit.block.data.type.DaylightDetector;
|
||||
import org.bukkit.block.data.type.Door;
|
||||
import org.bukkit.block.data.type.NoteBlock;
|
||||
import org.bukkit.block.data.type.Repeater;
|
||||
import org.bukkit.block.data.type.Switch;
|
||||
import org.bukkit.block.data.type.TurtleEgg;
|
||||
import org.bukkit.block.sign.Side;
|
||||
import org.bukkit.block.sign.SignSide;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.world.GenericGameEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
|
||||
public class InteractLogging extends LoggingListener {
|
||||
public InteractLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
private UUID lastInteractionPlayer;
|
||||
private BlockData lastInteractionBlockData;
|
||||
private Location lastInteractionLocation;
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getPlayer().getWorld());
|
||||
if (wcfg != null) {
|
||||
final Block clicked = event.getClickedBlock();
|
||||
if (clicked == null) {
|
||||
return;
|
||||
}
|
||||
final BlockData blockData = clicked.getBlockData();
|
||||
final Material type = blockData.getMaterial();
|
||||
final Player player = event.getPlayer();
|
||||
final Location loc = clicked.getLocation();
|
||||
lastInteractionPlayer = player.getUniqueId();
|
||||
lastInteractionBlockData = blockData;
|
||||
lastInteractionLocation = loc;
|
||||
|
||||
if (BukkitUtils.isFenceGate(type) || BukkitUtils.isWoodenTrapdoor(type)) {
|
||||
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Openable newBlockData = (Openable) blockData.clone();
|
||||
newBlockData.setOpen(!newBlockData.isOpen());
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (BukkitUtils.isPressurePlate(type)) {
|
||||
if (wcfg.isLogging(Logging.PRESUREPLATEINTERACT) && event.getAction() == Action.PHYSICAL) {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, blockData);
|
||||
}
|
||||
} else if (BukkitUtils.isWoodenDoor(type)) {
|
||||
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Door newBlockData = (Door) blockData.clone();
|
||||
newBlockData.setOpen(!newBlockData.isOpen());
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (BukkitUtils.isButton(type) || type == Material.LEVER) {
|
||||
if (wcfg.isLogging(Logging.SWITCHINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Switch newBlockData = (Switch) blockData.clone();
|
||||
if (!newBlockData.isPowered() || type == Material.LEVER) {
|
||||
newBlockData.setPowered(!newBlockData.isPowered());
|
||||
}
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (BukkitUtils.isSign(type)) {
|
||||
if (wcfg.isLogging(Logging.SIGNTEXT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getItem() != null) {
|
||||
Material itemType = event.getItem().getType();
|
||||
if (BukkitUtils.isDye(itemType) || itemType == Material.GLOW_INK_SAC || itemType == Material.INK_SAC || itemType == Material.HONEYCOMB) {
|
||||
final BlockState before = event.getClickedBlock().getState();
|
||||
if (before instanceof Sign signBefore) {
|
||||
boolean waxed = Reflections.isSignWaxed(signBefore);
|
||||
if (!waxed) {
|
||||
final Sign signAfter = (Sign) event.getClickedBlock().getState();
|
||||
Side side = BukkitUtils.getFacingSignSide(player, clicked);
|
||||
SignSide signSideBefore = signBefore.getSide(side);
|
||||
SignSide signSideAfter = signAfter.getSide(side);
|
||||
if (itemType == Material.GLOW_INK_SAC) {
|
||||
if (!signSideBefore.isGlowingText() && hasText(signSideBefore)) {
|
||||
signSideAfter.setGlowingText(true);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
}
|
||||
} else if (itemType == Material.INK_SAC) {
|
||||
if (signSideBefore.isGlowingText() && hasText(signSideBefore)) {
|
||||
signSideAfter.setGlowingText(false);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
}
|
||||
} else if (itemType == Material.HONEYCOMB) {
|
||||
signAfter.setEditable(false);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
} else if (BukkitUtils.isDye(itemType) && hasText(signSideBefore)) {
|
||||
DyeColor newColor = BukkitUtils.dyeToDyeColor(itemType);
|
||||
if (newColor != null && signSideBefore.getColor() != newColor) {
|
||||
signSideAfter.setColor(newColor);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(player), signBefore, signAfter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (type == Material.CAKE) {
|
||||
if (event.hasItem() && BukkitUtils.isCandle(event.getItem().getType()) && event.useItemInHand() != Result.DENY) {
|
||||
BlockData newBlockData = Material.valueOf(event.getItem().getType().name() + "_CAKE").createBlockData();
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
} else if (wcfg.isLogging(Logging.CAKEEAT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getFoodLevel() < 20) {
|
||||
Cake newBlockData = (Cake) blockData.clone();
|
||||
if (newBlockData.getBites() < 6) {
|
||||
newBlockData.setBites(newBlockData.getBites() + 1);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
} else {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, Material.AIR.createBlockData());
|
||||
}
|
||||
}
|
||||
} else if (type == Material.NOTE_BLOCK) {
|
||||
if (wcfg.isLogging(Logging.NOTEBLOCKINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
NoteBlock newBlockData = (NoteBlock) blockData.clone();
|
||||
if (newBlockData.getNote().getOctave() == 2) {
|
||||
newBlockData.setNote(new Note(0, Tone.F, true));
|
||||
} else {
|
||||
newBlockData.setNote(newBlockData.getNote().sharped());
|
||||
}
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.REPEATER) {
|
||||
if (wcfg.isLogging(Logging.DIODEINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Repeater newBlockData = (Repeater) blockData.clone();
|
||||
newBlockData.setDelay((newBlockData.getDelay() % 4) + 1);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.COMPARATOR) {
|
||||
if (wcfg.isLogging(Logging.COMPARATORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Comparator newBlockData = (Comparator) blockData.clone();
|
||||
newBlockData.setMode(newBlockData.getMode() == Mode.COMPARE ? Mode.SUBTRACT : Mode.COMPARE);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.DAYLIGHT_DETECTOR) {
|
||||
if (wcfg.isLogging(Logging.DAYLIGHTDETECTORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
DaylightDetector newBlockData = (DaylightDetector) blockData.clone();
|
||||
newBlockData.setInverted(!newBlockData.isInverted());
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
} else if (type == Material.TRIPWIRE) {
|
||||
if (wcfg.isLogging(Logging.TRIPWIREINTERACT) && event.getAction() == Action.PHYSICAL) {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, blockData);
|
||||
}
|
||||
} else if (type == Material.FARMLAND) {
|
||||
if (wcfg.isLogging(Logging.CROPTRAMPLE) && event.getAction() == Action.PHYSICAL) {
|
||||
// 3 = Dirt ID
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, Material.DIRT.createBlockData());
|
||||
// Log the crop on top as being broken
|
||||
Block trampledCrop = clicked.getRelative(BlockFace.UP);
|
||||
if (BukkitUtils.getCropBlocks().contains(trampledCrop.getType())) {
|
||||
consumer.queueBlockBreak(Actor.actorFromEntity(player), trampledCrop.getState());
|
||||
}
|
||||
}
|
||||
} else if (type == Material.TURTLE_EGG) {
|
||||
if (wcfg.isLogging(Logging.BLOCKBREAK) && event.getAction() == Action.PHYSICAL) {
|
||||
TurtleEgg turtleEggData = (TurtleEgg) blockData;
|
||||
int eggs = turtleEggData.getEggs();
|
||||
if (eggs > 1) {
|
||||
TurtleEgg turtleEggData2 = (TurtleEgg) turtleEggData.clone();
|
||||
turtleEggData2.setEggs(eggs - 1);
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, turtleEggData, turtleEggData2);
|
||||
} else {
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, turtleEggData, Material.AIR.createBlockData());
|
||||
}
|
||||
}
|
||||
} else if (type == Material.PUMPKIN) {
|
||||
if ((wcfg.isLogging(Logging.BLOCKBREAK) || wcfg.isLogging(Logging.BLOCKPLACE)) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
ItemStack inHand = event.getItem();
|
||||
if (inHand != null && inHand.getType() == Material.SHEARS) {
|
||||
BlockFace clickedFace = event.getBlockFace();
|
||||
Directional newBlockData = (Directional) Material.CARVED_PUMPKIN.createBlockData();
|
||||
if (clickedFace == BlockFace.NORTH || clickedFace == BlockFace.SOUTH || clickedFace == BlockFace.EAST || clickedFace == BlockFace.WEST) {
|
||||
newBlockData.setFacing(clickedFace);
|
||||
} else {
|
||||
// use player distance to calculate the facing
|
||||
Location playerLoc = player.getLocation();
|
||||
playerLoc.subtract(0.5, 0, 0.5);
|
||||
double dx = playerLoc.getX() - loc.getX();
|
||||
double dz = playerLoc.getZ() - loc.getZ();
|
||||
if (Math.abs(dx) > Math.abs(dz)) {
|
||||
newBlockData.setFacing(dx > 0 ? BlockFace.EAST : BlockFace.WEST);
|
||||
} else {
|
||||
newBlockData.setFacing(dz > 0 ? BlockFace.SOUTH : BlockFace.NORTH);
|
||||
}
|
||||
}
|
||||
consumer.queueBlock(Actor.actorFromEntity(player), loc, blockData, newBlockData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasText(SignSide signSide) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!signSide.getLine(i).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onGenericGameEvent(GenericGameEvent event) {
|
||||
if (lastInteractionPlayer != null && event.getEntity() != null && event.getEntity().getUniqueId().equals(lastInteractionPlayer) && lastInteractionLocation != null && event.getLocation().equals(lastInteractionLocation)) {
|
||||
if (lastInteractionBlockData instanceof Candle) {
|
||||
Candle previousCandle = (Candle) lastInteractionBlockData;
|
||||
if (previousCandle.isLit()) {
|
||||
BlockData newData = lastInteractionLocation.getBlock().getBlockData();
|
||||
if (newData instanceof Candle) {
|
||||
Candle newCandle = (Candle) newData;
|
||||
if (!newCandle.isLit() && !newCandle.isWaterlogged()) {
|
||||
// log candle extinguish
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (lastInteractionBlockData instanceof Lightable && BukkitUtils.isCandleCake(lastInteractionBlockData.getMaterial())) {
|
||||
Lightable previousLightable = (Lightable) lastInteractionBlockData;
|
||||
BlockData newData = lastInteractionLocation.getBlock().getBlockData();
|
||||
if (event.getEvent().equals(GameEvent.EAT)) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getLocation().getWorld());
|
||||
if (wcfg.isLogging(Logging.CAKEEAT)) {
|
||||
// nom nom (don't know why newData is incorrect here)
|
||||
newData = Material.CAKE.createBlockData();
|
||||
((Cake) newData).setBites(1);
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
} else if (previousLightable.isLit()) {
|
||||
if (newData instanceof Lightable) {
|
||||
Lightable newLightable = (Lightable) newData;
|
||||
if (!newLightable.isLit()) {
|
||||
// log cake extinguish
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), lastInteractionLocation, lastInteractionBlockData, newData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastInteractionPlayer = null;
|
||||
lastInteractionBlockData = null;
|
||||
lastInteractionLocation = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +1,51 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.*;
|
||||
|
||||
public class KillLogging extends LoggingListener {
|
||||
|
||||
public KillLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityDeath(EntityDeathEvent deathEvent) {
|
||||
EntityDamageEvent event = deathEvent.getEntity().getLastDamageCause();
|
||||
// For a death event, there should always be a damage event and it should not be cancelled. Check anyway.
|
||||
if (event != null && event.isCancelled() == false && isLogging(event.getEntity().getWorld(), Logging.KILL) && event.getEntity() instanceof LivingEntity) {
|
||||
final LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
final Entity killer = ((EntityDamageByEntityEvent) event).getDamager();
|
||||
if (logKillsLevel == LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player)) {
|
||||
return;
|
||||
} else if (logKillsLevel == LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster)) {
|
||||
return;
|
||||
}
|
||||
consumer.queueKill(killer, victim);
|
||||
} else if (deathEvent.getEntity().getKiller() != null) {
|
||||
consumer.queueKill(deathEvent.getEntity().getKiller(), victim);
|
||||
} else if (logEnvironmentalKills) {
|
||||
if (logKillsLevel == LogKillsLevel.PLAYERS && !(victim instanceof Player)) {
|
||||
return;
|
||||
} else if (logKillsLevel == LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster))) {
|
||||
return;
|
||||
}
|
||||
consumer.queueKill(new Actor(event.getCause().toString()), victim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.Config.*;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.*;
|
||||
|
||||
public class KillLogging extends LoggingListener {
|
||||
|
||||
public KillLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityDeath(EntityDeathEvent deathEvent) {
|
||||
EntityDamageEvent event = deathEvent.getEntity().getLastDamageCause();
|
||||
// For a death event, there should always be a damage event and it should not be cancelled. Check anyway.
|
||||
if (event != null && event.isCancelled() == false && isLogging(event.getEntity().getWorld(), Logging.KILL) && event.getEntity() instanceof LivingEntity) {
|
||||
final LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
final Entity killer = ((EntityDamageByEntityEvent) event).getDamager();
|
||||
if (logKillsLevel == LogKillsLevel.PLAYERS && !(victim instanceof Player && killer instanceof Player)) {
|
||||
return;
|
||||
} else if (logKillsLevel == LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster) && killer instanceof Player || killer instanceof Monster)) {
|
||||
return;
|
||||
}
|
||||
consumer.queueKill(killer, victim);
|
||||
} else if (deathEvent.getEntity().getKiller() != null) {
|
||||
consumer.queueKill(deathEvent.getEntity().getKiller(), victim);
|
||||
} else if (logEnvironmentalKills) {
|
||||
if (logKillsLevel == LogKillsLevel.PLAYERS && !(victim instanceof Player)) {
|
||||
return;
|
||||
} else if (logKillsLevel == LogKillsLevel.MONSTERS && !((victim instanceof Player || victim instanceof Monster))) {
|
||||
return;
|
||||
}
|
||||
consumer.queueKill(new Actor(event.getCause().toString()), victim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,26 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockBreak;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogFallables;
|
||||
|
||||
public class LeavesDecayLogging extends LoggingListener {
|
||||
public LeavesDecayLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.LEAVESDECAY)) {
|
||||
smartLogBlockBreak(consumer, new Actor("LeavesDecay"), event.getBlock());
|
||||
smartLogFallables(consumer, new Actor("LeavesDecay"), event.getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogBlockBreak;
|
||||
import static de.diddiz.LogBlock.util.LoggingUtil.smartLogFallables;
|
||||
|
||||
public class LeavesDecayLogging extends LoggingListener {
|
||||
public LeavesDecayLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.LEAVESDECAY)) {
|
||||
smartLogBlockBreak(consumer, new Actor("LeavesDecay"), event.getBlock());
|
||||
smartLogFallables(consumer, new Actor("LeavesDecay"), event.getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Consumer;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class LoggingListener implements Listener {
|
||||
protected final Consumer consumer;
|
||||
|
||||
public LoggingListener(LogBlock lb) {
|
||||
consumer = lb.getConsumer();
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Consumer;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class LoggingListener implements Listener {
|
||||
protected final Consumer consumer;
|
||||
|
||||
public LoggingListener(LogBlock lb) {
|
||||
consumer = lb.getConsumer();
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,43 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerInfoLogging extends LoggingListener {
|
||||
|
||||
private final HashMap<UUID, Long> playerLogins = new HashMap<>();
|
||||
|
||||
public PlayerInfoLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
playerLogins.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
||||
consumer.queueJoin(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
onPlayerQuit(event.getPlayer());
|
||||
}
|
||||
|
||||
public void onPlayerQuit(Player player) {
|
||||
Long joinTime = playerLogins.remove(player.getUniqueId());
|
||||
if (Config.logPlayerInfo && joinTime != null) {
|
||||
long onlineTime = (System.currentTimeMillis() - joinTime) / 1000;
|
||||
if (onlineTime > 0) {
|
||||
consumer.queueLeave(player, onlineTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerInfoLogging extends LoggingListener {
|
||||
|
||||
private final HashMap<UUID, Long> playerLogins = new HashMap<>();
|
||||
|
||||
public PlayerInfoLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
playerLogins.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
||||
consumer.queueJoin(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
onPlayerQuit(event.getPlayer());
|
||||
}
|
||||
|
||||
public void onPlayerQuit(Player player) {
|
||||
Long joinTime = playerLogins.remove(player.getUniqueId());
|
||||
if (Config.logPlayerInfo && joinTime != null) {
|
||||
long onlineTime = (System.currentTimeMillis() - joinTime) / 1000;
|
||||
if (onlineTime > 0) {
|
||||
consumer.queueLeave(player, onlineTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,33 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.sign.SignSide;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class SignChangeLogging extends LoggingListener {
|
||||
public SignChangeLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.SIGNTEXT)) {
|
||||
BlockState newState = event.getBlock().getState();
|
||||
if (newState instanceof Sign sign) {
|
||||
SignSide signSide = sign.getSide(event.getSide());
|
||||
for (int i = 0; i < 4; i++) {
|
||||
signSide.setLine(i, event.getLine(i));
|
||||
}
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), event.getBlock().getState(), newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.sign.SignSide;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class SignChangeLogging extends LoggingListener {
|
||||
public SignChangeLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.SIGNTEXT)) {
|
||||
BlockState newState = event.getBlock().getState();
|
||||
if (newState instanceof Sign sign) {
|
||||
SignSide signSide = sign.getSide(event.getSide());
|
||||
for (int i = 0; i < 4; i++) {
|
||||
signSide.setLine(i, event.getLine(i));
|
||||
}
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getPlayer()), event.getBlock().getState(), newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class SnowFadeLogging extends LoggingListener {
|
||||
public SnowFadeLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockFade(BlockFadeEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFADE)) {
|
||||
final Material type = event.getBlock().getType();
|
||||
if (type == Material.SNOW || type == Material.ICE) {
|
||||
consumer.queueBlockReplace(new Actor("SnowFade"), event.getBlock().getState(), event.getNewState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class SnowFadeLogging extends LoggingListener {
|
||||
public SnowFadeLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockFade(BlockFadeEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFADE)) {
|
||||
final Material type = event.getBlock().getType();
|
||||
if (type == Material.SNOW || type == Material.ICE) {
|
||||
consumer.queueBlockReplace(new Actor("SnowFade"), event.getBlock().getState(), event.getNewState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class SnowFormLogging extends LoggingListener {
|
||||
public SnowFormLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFORM)) {
|
||||
final Material type = event.getNewState().getType();
|
||||
if (type == Material.SNOW || type == Material.ICE) {
|
||||
consumer.queueBlockReplace(new Actor("SnowForm"), event.getBlock().getState(), event.getNewState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockFormEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class SnowFormLogging extends LoggingListener {
|
||||
public SnowFormLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFORM)) {
|
||||
final Material type = event.getNewState().getType();
|
||||
if (type == Material.SNOW || type == Material.ICE) {
|
||||
consumer.queueBlockReplace(new Actor("SnowForm"), event.getBlock().getState(), event.getNewState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,34 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
|
||||
public class StructureGrowLogging extends LoggingListener {
|
||||
public StructureGrowLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onStructureGrow(StructureGrowEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getWorld());
|
||||
if (wcfg != null) {
|
||||
if (!wcfg.isLogging(Logging.NATURALSTRUCTUREGROW)) {
|
||||
return;
|
||||
}
|
||||
if (!event.isFromBonemeal()) {
|
||||
final Actor actor = new Actor("NaturalGrow");
|
||||
for (final BlockState state : event.getBlocks()) {
|
||||
consumer.queueBlockReplace(actor, state.getBlock().getState(), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import de.diddiz.LogBlock.config.WorldConfig;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
|
||||
|
||||
public class StructureGrowLogging extends LoggingListener {
|
||||
public StructureGrowLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onStructureGrow(StructureGrowEvent event) {
|
||||
final WorldConfig wcfg = getWorldConfig(event.getWorld());
|
||||
if (wcfg != null) {
|
||||
if (!wcfg.isLogging(Logging.NATURALSTRUCTUREGROW)) {
|
||||
return;
|
||||
}
|
||||
if (!event.isFromBonemeal()) {
|
||||
final Actor actor = new Actor("NaturalGrow");
|
||||
for (final BlockState state : event.getBlocks()) {
|
||||
consumer.queueBlockReplace(actor, state.getBlock().getState(), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,151 +1,151 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.*;
|
||||
import de.diddiz.LogBlock.events.ToolUseEvent;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.CuboidRegion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static de.diddiz.LogBlock.Session.getSession;
|
||||
import static de.diddiz.LogBlock.Session.hasSession;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogged;
|
||||
import static de.diddiz.LogBlock.config.Config.toolsByType;
|
||||
|
||||
public class ToolListener implements Listener {
|
||||
private final CommandsHandler handler;
|
||||
private final LogBlock logblock;
|
||||
|
||||
public ToolListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
handler = logblock.getCommandsHandler();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getMaterial() != null) {
|
||||
final Action action = event.getAction();
|
||||
final Material type = event.getMaterial();
|
||||
final Tool tool = toolsByType.get(type);
|
||||
final Player player = event.getPlayer();
|
||||
if (tool != null && (action == Action.RIGHT_CLICK_BLOCK || action == Action.LEFT_CLICK_BLOCK) && logblock.hasPermission(player, "logblock.tools." + tool.name)) {
|
||||
final ToolBehavior behavior = action == Action.RIGHT_CLICK_BLOCK ? tool.rightClickBehavior : tool.leftClickBehavior;
|
||||
final ToolData toolData = getSession(player).toolData.get(tool);
|
||||
if (behavior != ToolBehavior.NONE && toolData.enabled) {
|
||||
if (!isLogged(player.getWorld())) {
|
||||
player.sendMessage(ChatColor.RED + "This world is not currently logged.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getClickedBlock();
|
||||
final QueryParams params = toolData.params.clone();
|
||||
params.loc = null;
|
||||
params.sel = null;
|
||||
if (behavior == ToolBehavior.BLOCK) {
|
||||
params.setLocation(block.getRelative(event.getBlockFace()).getLocation());
|
||||
} else if (tool.params.radius != 0) {
|
||||
params.setLocation(block.getLocation());
|
||||
} else {
|
||||
Block otherHalfChest = BukkitUtils.getConnectedChest(block);
|
||||
if (otherHalfChest == null) {
|
||||
params.setLocation(block.getLocation());
|
||||
} else {
|
||||
params.setSelection(CuboidRegion.fromCorners(block.getLocation().getWorld(), block.getLocation(), otherHalfChest.getLocation()));
|
||||
}
|
||||
}
|
||||
try {
|
||||
params.validate();
|
||||
if (this.callToolUseEvent(new ToolUseEvent(player, tool, behavior, params))) {
|
||||
return;
|
||||
}
|
||||
if (toolData.mode == ToolMode.ROLLBACK) {
|
||||
handler.new CommandRollback(player, params, true);
|
||||
} else if (toolData.mode == ToolMode.REDO) {
|
||||
handler.new CommandRedo(player, params, true);
|
||||
} else if (toolData.mode == ToolMode.CLEARLOG) {
|
||||
handler.new CommandClearLog(player, params, true);
|
||||
} else if (toolData.mode == ToolMode.WRITELOGFILE) {
|
||||
handler.new CommandWriteLogFile(player, params, true);
|
||||
} else {
|
||||
handler.new CommandLookup(player, params, true);
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
player.sendMessage(ChatColor.RED + ex.getMessage());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean callToolUseEvent(ToolUseEvent event) {
|
||||
this.logblock.getServer().getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (hasSession(player)) {
|
||||
final Session session = getSession(player);
|
||||
for (final Entry<Tool, ToolData> entry : session.toolData.entrySet()) {
|
||||
final Tool tool = entry.getKey();
|
||||
final ToolData toolData = entry.getValue();
|
||||
if (toolData.enabled && !logblock.hasPermission(player, "logblock.tools." + tool.name)) {
|
||||
toolData.enabled = false;
|
||||
if (tool.removeOnDisable && logblock.hasPermission(player, "logblock.spawnTools")) {
|
||||
player.getInventory().removeItem(new ItemStack(tool.item, 1));
|
||||
}
|
||||
player.sendMessage(ChatColor.GREEN + "Tool disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (hasSession(player)) {
|
||||
final Session session = getSession(player);
|
||||
for (final Entry<Tool, ToolData> entry : session.toolData.entrySet()) {
|
||||
final Tool tool = entry.getKey();
|
||||
final ToolData toolData = entry.getValue();
|
||||
final Material item = event.getItemDrop().getItemStack().getType();
|
||||
if (item == tool.item && toolData.enabled) {
|
||||
if (tool.dropToDisable) {
|
||||
toolData.enabled = false;
|
||||
ItemStack stack = event.getItemDrop().getItemStack();
|
||||
if (tool.removeOnDisable && logblock.hasPermission(player, "logblock.spawnTools")) {
|
||||
if (stack.isSimilar(new ItemStack(item))) {
|
||||
if (stack.getAmount() > 1) {
|
||||
stack.setAmount(stack.getAmount() - 1);
|
||||
event.getItemDrop().setItemStack(stack);
|
||||
} else {
|
||||
event.getItemDrop().remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (BukkitUtils.hasInventoryStorageSpaceFor(player.getInventory(), stack)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
player.sendMessage(ChatColor.GREEN + "Tool disabled.");
|
||||
} else if (!tool.canDrop) {
|
||||
player.sendMessage(ChatColor.RED + "You cannot drop this tool.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.*;
|
||||
import de.diddiz.LogBlock.events.ToolUseEvent;
|
||||
import de.diddiz.LogBlock.util.BukkitUtils;
|
||||
import de.diddiz.LogBlock.util.CuboidRegion;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static de.diddiz.LogBlock.Session.getSession;
|
||||
import static de.diddiz.LogBlock.Session.hasSession;
|
||||
import static de.diddiz.LogBlock.config.Config.isLogged;
|
||||
import static de.diddiz.LogBlock.config.Config.toolsByType;
|
||||
|
||||
public class ToolListener implements Listener {
|
||||
private final CommandsHandler handler;
|
||||
private final LogBlock logblock;
|
||||
|
||||
public ToolListener(LogBlock logblock) {
|
||||
this.logblock = logblock;
|
||||
handler = logblock.getCommandsHandler();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getMaterial() != null) {
|
||||
final Action action = event.getAction();
|
||||
final Material type = event.getMaterial();
|
||||
final Tool tool = toolsByType.get(type);
|
||||
final Player player = event.getPlayer();
|
||||
if (tool != null && (action == Action.RIGHT_CLICK_BLOCK || action == Action.LEFT_CLICK_BLOCK) && logblock.hasPermission(player, "logblock.tools." + tool.name)) {
|
||||
final ToolBehavior behavior = action == Action.RIGHT_CLICK_BLOCK ? tool.rightClickBehavior : tool.leftClickBehavior;
|
||||
final ToolData toolData = getSession(player).toolData.get(tool);
|
||||
if (behavior != ToolBehavior.NONE && toolData.enabled) {
|
||||
if (!isLogged(player.getWorld())) {
|
||||
player.sendMessage(ChatColor.RED + "This world is not currently logged.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
final Block block = event.getClickedBlock();
|
||||
final QueryParams params = toolData.params.clone();
|
||||
params.loc = null;
|
||||
params.sel = null;
|
||||
if (behavior == ToolBehavior.BLOCK) {
|
||||
params.setLocation(block.getRelative(event.getBlockFace()).getLocation());
|
||||
} else if (tool.params.radius != 0) {
|
||||
params.setLocation(block.getLocation());
|
||||
} else {
|
||||
Block otherHalfChest = BukkitUtils.getConnectedChest(block);
|
||||
if (otherHalfChest == null) {
|
||||
params.setLocation(block.getLocation());
|
||||
} else {
|
||||
params.setSelection(CuboidRegion.fromCorners(block.getLocation().getWorld(), block.getLocation(), otherHalfChest.getLocation()));
|
||||
}
|
||||
}
|
||||
try {
|
||||
params.validate();
|
||||
if (this.callToolUseEvent(new ToolUseEvent(player, tool, behavior, params))) {
|
||||
return;
|
||||
}
|
||||
if (toolData.mode == ToolMode.ROLLBACK) {
|
||||
handler.new CommandRollback(player, params, true);
|
||||
} else if (toolData.mode == ToolMode.REDO) {
|
||||
handler.new CommandRedo(player, params, true);
|
||||
} else if (toolData.mode == ToolMode.CLEARLOG) {
|
||||
handler.new CommandClearLog(player, params, true);
|
||||
} else if (toolData.mode == ToolMode.WRITELOGFILE) {
|
||||
handler.new CommandWriteLogFile(player, params, true);
|
||||
} else {
|
||||
handler.new CommandLookup(player, params, true);
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
player.sendMessage(ChatColor.RED + ex.getMessage());
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean callToolUseEvent(ToolUseEvent event) {
|
||||
this.logblock.getServer().getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (hasSession(player)) {
|
||||
final Session session = getSession(player);
|
||||
for (final Entry<Tool, ToolData> entry : session.toolData.entrySet()) {
|
||||
final Tool tool = entry.getKey();
|
||||
final ToolData toolData = entry.getValue();
|
||||
if (toolData.enabled && !logblock.hasPermission(player, "logblock.tools." + tool.name)) {
|
||||
toolData.enabled = false;
|
||||
if (tool.removeOnDisable && logblock.hasPermission(player, "logblock.spawnTools")) {
|
||||
player.getInventory().removeItem(new ItemStack(tool.item, 1));
|
||||
}
|
||||
player.sendMessage(ChatColor.GREEN + "Tool disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (hasSession(player)) {
|
||||
final Session session = getSession(player);
|
||||
for (final Entry<Tool, ToolData> entry : session.toolData.entrySet()) {
|
||||
final Tool tool = entry.getKey();
|
||||
final ToolData toolData = entry.getValue();
|
||||
final Material item = event.getItemDrop().getItemStack().getType();
|
||||
if (item == tool.item && toolData.enabled) {
|
||||
if (tool.dropToDisable) {
|
||||
toolData.enabled = false;
|
||||
ItemStack stack = event.getItemDrop().getItemStack();
|
||||
if (tool.removeOnDisable && logblock.hasPermission(player, "logblock.spawnTools")) {
|
||||
if (stack.isSimilar(new ItemStack(item))) {
|
||||
if (stack.getAmount() > 1) {
|
||||
stack.setAmount(stack.getAmount() - 1);
|
||||
event.getItemDrop().setItemStack(stack);
|
||||
} else {
|
||||
event.getItemDrop().remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (BukkitUtils.hasInventoryStorageSpaceFor(player.getInventory(), stack)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
player.sendMessage(ChatColor.GREEN + "Tool disabled.");
|
||||
} else if (!tool.canDrop) {
|
||||
player.sendMessage(ChatColor.RED + "You cannot drop this tool.");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.entity.Wither;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class WitherLogging extends LoggingListener {
|
||||
public WitherLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
if (event.getEntity() instanceof Wither && isLogging(event.getBlock().getWorld(), Logging.WITHER)) {
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), event.getBlock().getState(), event.getBlockData()); // Wither walked through a block.
|
||||
}
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.listeners;
|
||||
|
||||
import de.diddiz.LogBlock.Actor;
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
import de.diddiz.LogBlock.Logging;
|
||||
import org.bukkit.entity.Wither;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
||||
import static de.diddiz.LogBlock.config.Config.isLogging;
|
||||
|
||||
public class WitherLogging extends LoggingListener {
|
||||
public WitherLogging(LogBlock lb) {
|
||||
super(lb);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||
if (event.getEntity() instanceof Wither && isLogging(event.getBlock().getWorld(), Logging.WITHER)) {
|
||||
consumer.queueBlockReplace(Actor.actorFromEntity(event.getEntity()), event.getBlock().getState(), event.getBlockData()); // Wither walked through a block.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,424 +1,424 @@
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
// Taken from maven-artifact at
|
||||
// http://grepcode.com/file_/repo1.maven.org/maven2/org.apache.maven/maven-artifact/3.2.3/org/apache/maven/artifact/versioning/ComparableVersion.java/?v=source
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Generic implementation of version comparison.
|
||||
*
|
||||
* <p>Features:
|
||||
* <ul>
|
||||
* <li>mixing of '<code>-</code>' (dash) and '<code>.</code>' (dot) separators,</li>
|
||||
* <li>transition between characters and digits also constitutes a separator:
|
||||
* <code>1.0alpha1 => [1, 0, alpha, 1]</code></li>
|
||||
* <li>unlimited number of version components,</li>
|
||||
* <li>version components in the text can be digits or strings,</li>
|
||||
* <li>strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering.
|
||||
* Well-known qualifiers (case insensitive) are:<ul>
|
||||
* <li><code>alpha</code> or <code>a</code></li>
|
||||
* <li><code>beta</code> or <code>b</code></li>
|
||||
* <li><code>milestone</code> or <code>m</code></li>
|
||||
* <li><code>rc</code> or <code>cr</code></li>
|
||||
* <li><code>snapshot</code></li>
|
||||
* <li><code>(the empty string)</code> or <code>ga</code> or <code>final</code></li>
|
||||
* <li><code>sp</code></li>
|
||||
* </ul>
|
||||
* Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive),
|
||||
* </li>
|
||||
* <li>a dash usually precedes a qualifier, and is always less important than something preceded with a dot.</li>
|
||||
* </ul></p>
|
||||
*
|
||||
* @see <a href="https://cwiki.apache.org/confluence/display/MAVENOLD/Versioning">"Versioning" on Maven Wiki</a>
|
||||
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
|
||||
* @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
|
||||
*/
|
||||
public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
private String value;
|
||||
|
||||
private String canonical;
|
||||
|
||||
private ListItem items;
|
||||
|
||||
private interface Item {
|
||||
int INTEGER_ITEM = 0;
|
||||
int STRING_ITEM = 1;
|
||||
int LIST_ITEM = 2;
|
||||
|
||||
int compareTo(Item item);
|
||||
|
||||
int getType();
|
||||
|
||||
boolean isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a numeric item in the version item list.
|
||||
*/
|
||||
private static class IntegerItem implements Item {
|
||||
private static final BigInteger BIG_INTEGER_ZERO = new BigInteger("0");
|
||||
|
||||
private final BigInteger value;
|
||||
|
||||
public static final IntegerItem ZERO = new IntegerItem();
|
||||
|
||||
private IntegerItem() {
|
||||
this.value = BIG_INTEGER_ZERO;
|
||||
}
|
||||
|
||||
public IntegerItem(String str) {
|
||||
this.value = new BigInteger(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return INTEGER_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return BIG_INTEGER_ZERO.equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Item item) {
|
||||
if (item == null) {
|
||||
return BIG_INTEGER_ZERO.equals(value) ? 0 : 1; // 1.0 == 1, 1.1 > 1
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case INTEGER_ITEM:
|
||||
return value.compareTo(((IntegerItem) item).value);
|
||||
|
||||
case STRING_ITEM:
|
||||
return 1; // 1.1 > 1-sp
|
||||
|
||||
case LIST_ITEM:
|
||||
return 1; // 1.1 > 1-1
|
||||
|
||||
default:
|
||||
throw new RuntimeException("invalid item: " + item.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a string in the version item list, usually a qualifier.
|
||||
*/
|
||||
private static class StringItem implements Item {
|
||||
private static final String[] QUALIFIERS = { "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" };
|
||||
|
||||
private static final List<String> _QUALIFIERS = Arrays.asList(QUALIFIERS);
|
||||
|
||||
private static final Properties ALIASES = new Properties();
|
||||
static {
|
||||
ALIASES.put("ga", "");
|
||||
ALIASES.put("final", "");
|
||||
ALIASES.put("cr", "rc");
|
||||
}
|
||||
|
||||
/**
|
||||
* A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes
|
||||
* the version older than one without a qualifier, or more recent.
|
||||
*/
|
||||
private static final String RELEASE_VERSION_INDEX = String.valueOf(_QUALIFIERS.indexOf(""));
|
||||
|
||||
private String value;
|
||||
|
||||
public StringItem(String value, boolean followedByDigit) {
|
||||
if (followedByDigit && value.length() == 1) {
|
||||
// a1 = alpha-1, b1 = beta-1, m1 = milestone-1
|
||||
switch (value.charAt(0)) {
|
||||
case 'a':
|
||||
value = "alpha";
|
||||
break;
|
||||
case 'b':
|
||||
value = "beta";
|
||||
break;
|
||||
case 'm':
|
||||
value = "milestone";
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.value = ALIASES.getProperty(value, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return STRING_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return (comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comparable value for a qualifier.
|
||||
*
|
||||
* This method takes into account the ordering of known qualifiers then unknown qualifiers with lexical ordering.
|
||||
*
|
||||
* just returning an Integer with the index here is faster, but requires a lot of if/then/else to check for -1
|
||||
* or QUALIFIERS.size and then resort to lexical ordering. Most comparisons are decided by the first character,
|
||||
* so this is still fast. If more characters are needed then it requires a lexical sort anyway.
|
||||
*
|
||||
* @param qualifier
|
||||
* @return an equivalent value that can be used with lexical comparison
|
||||
*/
|
||||
public static String comparableQualifier(String qualifier) {
|
||||
int i = _QUALIFIERS.indexOf(qualifier);
|
||||
|
||||
return i == -1 ? (_QUALIFIERS.size() + "-" + qualifier) : String.valueOf(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Item item) {
|
||||
if (item == null) {
|
||||
// 1-rc < 1, 1-ga > 1
|
||||
return comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX);
|
||||
}
|
||||
switch (item.getType()) {
|
||||
case INTEGER_ITEM:
|
||||
return -1; // 1.any < 1.1 ?
|
||||
|
||||
case STRING_ITEM:
|
||||
return comparableQualifier(value).compareTo(comparableQualifier(((StringItem) item).value));
|
||||
|
||||
case LIST_ITEM:
|
||||
return -1; // 1.any < 1-1
|
||||
|
||||
default:
|
||||
throw new RuntimeException("invalid item: " + item.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a version list item. This class is used both for the global item list and for sub-lists (which start
|
||||
* with '-(number)' in the version specification).
|
||||
*/
|
||||
private static class ListItem extends ArrayList<Item> implements Item {
|
||||
private static final long serialVersionUID = 5914575811857700009L;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return LIST_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return (size() == 0);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
for (ListIterator<Item> iterator = listIterator(size()); iterator.hasPrevious();) {
|
||||
Item item = iterator.previous();
|
||||
if (item.isNull()) {
|
||||
iterator.remove(); // remove null trailing items: 0, "", empty list
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Item item) {
|
||||
if (item == null) {
|
||||
if (size() == 0) {
|
||||
return 0; // 1-0 = 1- (normalize) = 1
|
||||
}
|
||||
Item first = get(0);
|
||||
return first.compareTo(null);
|
||||
}
|
||||
switch (item.getType()) {
|
||||
case INTEGER_ITEM:
|
||||
return -1; // 1-1 < 1.0.x
|
||||
|
||||
case STRING_ITEM:
|
||||
return 1; // 1-1 > 1-sp
|
||||
|
||||
case LIST_ITEM:
|
||||
Iterator<Item> left = iterator();
|
||||
Iterator<Item> right = ((ListItem) item).iterator();
|
||||
|
||||
while (left.hasNext() || right.hasNext()) {
|
||||
Item l = left.hasNext() ? left.next() : null;
|
||||
Item r = right.hasNext() ? right.next() : null;
|
||||
|
||||
// if this is shorter, then invert the compare and mul with -1
|
||||
int result = l == null ? (r == null ? 0 : -1 * r.compareTo(l)) : l.compareTo(r);
|
||||
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("invalid item: " + item.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buffer = new StringBuilder("(");
|
||||
for (Iterator<Item> iter = iterator(); iter.hasNext();) {
|
||||
buffer.append(iter.next());
|
||||
if (iter.hasNext()) {
|
||||
buffer.append(',');
|
||||
}
|
||||
}
|
||||
buffer.append(')');
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public ComparableVersion(String version) {
|
||||
parseVersion(version);
|
||||
}
|
||||
|
||||
public final void parseVersion(String version) {
|
||||
this.value = version;
|
||||
|
||||
items = new ListItem();
|
||||
|
||||
version = version.toLowerCase(Locale.ENGLISH);
|
||||
|
||||
ListItem list = items;
|
||||
|
||||
Stack<Item> stack = new Stack<>();
|
||||
stack.push(list);
|
||||
|
||||
boolean isDigit = false;
|
||||
|
||||
int startIndex = 0;
|
||||
|
||||
for (int i = 0; i < version.length(); i++) {
|
||||
char c = version.charAt(i);
|
||||
|
||||
if (c == '.') {
|
||||
if (i == startIndex) {
|
||||
list.add(IntegerItem.ZERO);
|
||||
} else {
|
||||
list.add(parseItem(isDigit, version.substring(startIndex, i)));
|
||||
}
|
||||
startIndex = i + 1;
|
||||
} else if (c == '-') {
|
||||
if (i == startIndex) {
|
||||
list.add(IntegerItem.ZERO);
|
||||
} else {
|
||||
list.add(parseItem(isDigit, version.substring(startIndex, i)));
|
||||
}
|
||||
startIndex = i + 1;
|
||||
|
||||
if (isDigit) {
|
||||
list.normalize(); // 1.0-* = 1-*
|
||||
|
||||
if ((i + 1 < version.length()) && Character.isDigit(version.charAt(i + 1))) {
|
||||
// new ListItem only if previous were digits and new char is a digit,
|
||||
// ie need to differentiate only 1.1 from 1-1
|
||||
list.add(list = new ListItem());
|
||||
|
||||
stack.push(list);
|
||||
}
|
||||
}
|
||||
} else if (Character.isDigit(c)) {
|
||||
if (!isDigit && i > startIndex) {
|
||||
list.add(new StringItem(version.substring(startIndex, i), true));
|
||||
startIndex = i;
|
||||
}
|
||||
|
||||
isDigit = true;
|
||||
} else {
|
||||
if (isDigit && i > startIndex) {
|
||||
list.add(parseItem(true, version.substring(startIndex, i)));
|
||||
startIndex = i;
|
||||
}
|
||||
|
||||
isDigit = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (version.length() > startIndex) {
|
||||
list.add(parseItem(isDigit, version.substring(startIndex)));
|
||||
}
|
||||
|
||||
while (!stack.isEmpty()) {
|
||||
list = (ListItem) stack.pop();
|
||||
list.normalize();
|
||||
}
|
||||
|
||||
canonical = items.toString();
|
||||
}
|
||||
|
||||
private static Item parseItem(boolean isDigit, String buf) {
|
||||
return isDigit ? new IntegerItem(buf) : new StringItem(buf, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ComparableVersion o) {
|
||||
return items.compareTo(o.items);
|
||||
}
|
||||
|
||||
public int compareTo(String version) {
|
||||
return compareTo(new ComparableVersion(version));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String toCanonicalString() {
|
||||
return canonical;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof ComparableVersion) && canonical.equals(((ComparableVersion) o).canonical);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return canonical.hashCode();
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
// Taken from maven-artifact at
|
||||
// http://grepcode.com/file_/repo1.maven.org/maven2/org.apache.maven/maven-artifact/3.2.3/org/apache/maven/artifact/versioning/ComparableVersion.java/?v=source
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Generic implementation of version comparison.
|
||||
*
|
||||
* <p>Features:
|
||||
* <ul>
|
||||
* <li>mixing of '<code>-</code>' (dash) and '<code>.</code>' (dot) separators,</li>
|
||||
* <li>transition between characters and digits also constitutes a separator:
|
||||
* <code>1.0alpha1 => [1, 0, alpha, 1]</code></li>
|
||||
* <li>unlimited number of version components,</li>
|
||||
* <li>version components in the text can be digits or strings,</li>
|
||||
* <li>strings are checked for well-known qualifiers and the qualifier ordering is used for version ordering.
|
||||
* Well-known qualifiers (case insensitive) are:<ul>
|
||||
* <li><code>alpha</code> or <code>a</code></li>
|
||||
* <li><code>beta</code> or <code>b</code></li>
|
||||
* <li><code>milestone</code> or <code>m</code></li>
|
||||
* <li><code>rc</code> or <code>cr</code></li>
|
||||
* <li><code>snapshot</code></li>
|
||||
* <li><code>(the empty string)</code> or <code>ga</code> or <code>final</code></li>
|
||||
* <li><code>sp</code></li>
|
||||
* </ul>
|
||||
* Unknown qualifiers are considered after known qualifiers, with lexical order (always case insensitive),
|
||||
* </li>
|
||||
* <li>a dash usually precedes a qualifier, and is always less important than something preceded with a dot.</li>
|
||||
* </ul></p>
|
||||
*
|
||||
* @see <a href="https://cwiki.apache.org/confluence/display/MAVENOLD/Versioning">"Versioning" on Maven Wiki</a>
|
||||
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
|
||||
* @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
|
||||
*/
|
||||
public class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
private String value;
|
||||
|
||||
private String canonical;
|
||||
|
||||
private ListItem items;
|
||||
|
||||
private interface Item {
|
||||
int INTEGER_ITEM = 0;
|
||||
int STRING_ITEM = 1;
|
||||
int LIST_ITEM = 2;
|
||||
|
||||
int compareTo(Item item);
|
||||
|
||||
int getType();
|
||||
|
||||
boolean isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a numeric item in the version item list.
|
||||
*/
|
||||
private static class IntegerItem implements Item {
|
||||
private static final BigInteger BIG_INTEGER_ZERO = new BigInteger("0");
|
||||
|
||||
private final BigInteger value;
|
||||
|
||||
public static final IntegerItem ZERO = new IntegerItem();
|
||||
|
||||
private IntegerItem() {
|
||||
this.value = BIG_INTEGER_ZERO;
|
||||
}
|
||||
|
||||
public IntegerItem(String str) {
|
||||
this.value = new BigInteger(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return INTEGER_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return BIG_INTEGER_ZERO.equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Item item) {
|
||||
if (item == null) {
|
||||
return BIG_INTEGER_ZERO.equals(value) ? 0 : 1; // 1.0 == 1, 1.1 > 1
|
||||
}
|
||||
|
||||
switch (item.getType()) {
|
||||
case INTEGER_ITEM:
|
||||
return value.compareTo(((IntegerItem) item).value);
|
||||
|
||||
case STRING_ITEM:
|
||||
return 1; // 1.1 > 1-sp
|
||||
|
||||
case LIST_ITEM:
|
||||
return 1; // 1.1 > 1-1
|
||||
|
||||
default:
|
||||
throw new RuntimeException("invalid item: " + item.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a string in the version item list, usually a qualifier.
|
||||
*/
|
||||
private static class StringItem implements Item {
|
||||
private static final String[] QUALIFIERS = { "alpha", "beta", "milestone", "rc", "snapshot", "", "sp" };
|
||||
|
||||
private static final List<String> _QUALIFIERS = Arrays.asList(QUALIFIERS);
|
||||
|
||||
private static final Properties ALIASES = new Properties();
|
||||
static {
|
||||
ALIASES.put("ga", "");
|
||||
ALIASES.put("final", "");
|
||||
ALIASES.put("cr", "rc");
|
||||
}
|
||||
|
||||
/**
|
||||
* A comparable value for the empty-string qualifier. This one is used to determine if a given qualifier makes
|
||||
* the version older than one without a qualifier, or more recent.
|
||||
*/
|
||||
private static final String RELEASE_VERSION_INDEX = String.valueOf(_QUALIFIERS.indexOf(""));
|
||||
|
||||
private String value;
|
||||
|
||||
public StringItem(String value, boolean followedByDigit) {
|
||||
if (followedByDigit && value.length() == 1) {
|
||||
// a1 = alpha-1, b1 = beta-1, m1 = milestone-1
|
||||
switch (value.charAt(0)) {
|
||||
case 'a':
|
||||
value = "alpha";
|
||||
break;
|
||||
case 'b':
|
||||
value = "beta";
|
||||
break;
|
||||
case 'm':
|
||||
value = "milestone";
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.value = ALIASES.getProperty(value, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return STRING_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return (comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a comparable value for a qualifier.
|
||||
*
|
||||
* This method takes into account the ordering of known qualifiers then unknown qualifiers with lexical ordering.
|
||||
*
|
||||
* just returning an Integer with the index here is faster, but requires a lot of if/then/else to check for -1
|
||||
* or QUALIFIERS.size and then resort to lexical ordering. Most comparisons are decided by the first character,
|
||||
* so this is still fast. If more characters are needed then it requires a lexical sort anyway.
|
||||
*
|
||||
* @param qualifier
|
||||
* @return an equivalent value that can be used with lexical comparison
|
||||
*/
|
||||
public static String comparableQualifier(String qualifier) {
|
||||
int i = _QUALIFIERS.indexOf(qualifier);
|
||||
|
||||
return i == -1 ? (_QUALIFIERS.size() + "-" + qualifier) : String.valueOf(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Item item) {
|
||||
if (item == null) {
|
||||
// 1-rc < 1, 1-ga > 1
|
||||
return comparableQualifier(value).compareTo(RELEASE_VERSION_INDEX);
|
||||
}
|
||||
switch (item.getType()) {
|
||||
case INTEGER_ITEM:
|
||||
return -1; // 1.any < 1.1 ?
|
||||
|
||||
case STRING_ITEM:
|
||||
return comparableQualifier(value).compareTo(comparableQualifier(((StringItem) item).value));
|
||||
|
||||
case LIST_ITEM:
|
||||
return -1; // 1.any < 1-1
|
||||
|
||||
default:
|
||||
throw new RuntimeException("invalid item: " + item.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a version list item. This class is used both for the global item list and for sub-lists (which start
|
||||
* with '-(number)' in the version specification).
|
||||
*/
|
||||
private static class ListItem extends ArrayList<Item> implements Item {
|
||||
private static final long serialVersionUID = 5914575811857700009L;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return LIST_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNull() {
|
||||
return (size() == 0);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
for (ListIterator<Item> iterator = listIterator(size()); iterator.hasPrevious();) {
|
||||
Item item = iterator.previous();
|
||||
if (item.isNull()) {
|
||||
iterator.remove(); // remove null trailing items: 0, "", empty list
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Item item) {
|
||||
if (item == null) {
|
||||
if (size() == 0) {
|
||||
return 0; // 1-0 = 1- (normalize) = 1
|
||||
}
|
||||
Item first = get(0);
|
||||
return first.compareTo(null);
|
||||
}
|
||||
switch (item.getType()) {
|
||||
case INTEGER_ITEM:
|
||||
return -1; // 1-1 < 1.0.x
|
||||
|
||||
case STRING_ITEM:
|
||||
return 1; // 1-1 > 1-sp
|
||||
|
||||
case LIST_ITEM:
|
||||
Iterator<Item> left = iterator();
|
||||
Iterator<Item> right = ((ListItem) item).iterator();
|
||||
|
||||
while (left.hasNext() || right.hasNext()) {
|
||||
Item l = left.hasNext() ? left.next() : null;
|
||||
Item r = right.hasNext() ? right.next() : null;
|
||||
|
||||
// if this is shorter, then invert the compare and mul with -1
|
||||
int result = l == null ? (r == null ? 0 : -1 * r.compareTo(l)) : l.compareTo(r);
|
||||
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("invalid item: " + item.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buffer = new StringBuilder("(");
|
||||
for (Iterator<Item> iter = iterator(); iter.hasNext();) {
|
||||
buffer.append(iter.next());
|
||||
if (iter.hasNext()) {
|
||||
buffer.append(',');
|
||||
}
|
||||
}
|
||||
buffer.append(')');
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public ComparableVersion(String version) {
|
||||
parseVersion(version);
|
||||
}
|
||||
|
||||
public final void parseVersion(String version) {
|
||||
this.value = version;
|
||||
|
||||
items = new ListItem();
|
||||
|
||||
version = version.toLowerCase(Locale.ENGLISH);
|
||||
|
||||
ListItem list = items;
|
||||
|
||||
Stack<Item> stack = new Stack<>();
|
||||
stack.push(list);
|
||||
|
||||
boolean isDigit = false;
|
||||
|
||||
int startIndex = 0;
|
||||
|
||||
for (int i = 0; i < version.length(); i++) {
|
||||
char c = version.charAt(i);
|
||||
|
||||
if (c == '.') {
|
||||
if (i == startIndex) {
|
||||
list.add(IntegerItem.ZERO);
|
||||
} else {
|
||||
list.add(parseItem(isDigit, version.substring(startIndex, i)));
|
||||
}
|
||||
startIndex = i + 1;
|
||||
} else if (c == '-') {
|
||||
if (i == startIndex) {
|
||||
list.add(IntegerItem.ZERO);
|
||||
} else {
|
||||
list.add(parseItem(isDigit, version.substring(startIndex, i)));
|
||||
}
|
||||
startIndex = i + 1;
|
||||
|
||||
if (isDigit) {
|
||||
list.normalize(); // 1.0-* = 1-*
|
||||
|
||||
if ((i + 1 < version.length()) && Character.isDigit(version.charAt(i + 1))) {
|
||||
// new ListItem only if previous were digits and new char is a digit,
|
||||
// ie need to differentiate only 1.1 from 1-1
|
||||
list.add(list = new ListItem());
|
||||
|
||||
stack.push(list);
|
||||
}
|
||||
}
|
||||
} else if (Character.isDigit(c)) {
|
||||
if (!isDigit && i > startIndex) {
|
||||
list.add(new StringItem(version.substring(startIndex, i), true));
|
||||
startIndex = i;
|
||||
}
|
||||
|
||||
isDigit = true;
|
||||
} else {
|
||||
if (isDigit && i > startIndex) {
|
||||
list.add(parseItem(true, version.substring(startIndex, i)));
|
||||
startIndex = i;
|
||||
}
|
||||
|
||||
isDigit = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (version.length() > startIndex) {
|
||||
list.add(parseItem(isDigit, version.substring(startIndex)));
|
||||
}
|
||||
|
||||
while (!stack.isEmpty()) {
|
||||
list = (ListItem) stack.pop();
|
||||
list.normalize();
|
||||
}
|
||||
|
||||
canonical = items.toString();
|
||||
}
|
||||
|
||||
private static Item parseItem(boolean isDigit, String buf) {
|
||||
return isDigit ? new IntegerItem(buf) : new StringItem(buf, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ComparableVersion o) {
|
||||
return items.compareTo(o.items);
|
||||
}
|
||||
|
||||
public int compareTo(String version) {
|
||||
return compareTo(new ComparableVersion(version));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String toCanonicalString() {
|
||||
return canonical;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof ComparableVersion) && canonical.equals(((ComparableVersion) o).canonical);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return canonical.hashCode();
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +1,51 @@
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MySQLConnectionPool implements Closeable {
|
||||
|
||||
private final HikariDataSource ds;
|
||||
|
||||
public MySQLConnectionPool(String url, String user, String password, boolean useSSL, boolean requireSSL) {
|
||||
this.ds = new HikariDataSource();
|
||||
ds.setJdbcUrl(url);
|
||||
ds.setUsername(user);
|
||||
ds.setPassword(password);
|
||||
|
||||
ds.setMinimumIdle(2);
|
||||
ds.setMaximumPoolSize(15);
|
||||
ds.setPoolName("LogBlock-Connection-Pool");
|
||||
|
||||
ds.addDataSourceProperty("useUnicode", "true");
|
||||
ds.addDataSourceProperty("characterEncoding", "utf-8");
|
||||
ds.addDataSourceProperty("rewriteBatchedStatements", "true");
|
||||
|
||||
ds.addDataSourceProperty("cachePrepStmts", "true");
|
||||
ds.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
ds.addDataSourceProperty("useServerPrepStmts", "true");
|
||||
|
||||
ds.addDataSourceProperty("useSSL", Boolean.toString(useSSL));
|
||||
ds.addDataSourceProperty("requireSSL", Boolean.toString(requireSSL));
|
||||
ds.addDataSourceProperty("verifyServerCertificate", "false");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
ds.close();
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
Connection connection = ds.getConnection();
|
||||
if (Config.mb4) {
|
||||
connection.createStatement().executeUpdate("SET NAMES utf8mb4");
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
}
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import de.diddiz.LogBlock.config.Config;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MySQLConnectionPool implements Closeable {
|
||||
|
||||
private final HikariDataSource ds;
|
||||
|
||||
public MySQLConnectionPool(String url, String user, String password, boolean useSSL, boolean requireSSL) {
|
||||
this.ds = new HikariDataSource();
|
||||
ds.setJdbcUrl(url);
|
||||
ds.setUsername(user);
|
||||
ds.setPassword(password);
|
||||
|
||||
ds.setMinimumIdle(2);
|
||||
ds.setMaximumPoolSize(15);
|
||||
ds.setPoolName("LogBlock-Connection-Pool");
|
||||
|
||||
ds.addDataSourceProperty("useUnicode", "true");
|
||||
ds.addDataSourceProperty("characterEncoding", "utf-8");
|
||||
ds.addDataSourceProperty("rewriteBatchedStatements", "true");
|
||||
|
||||
ds.addDataSourceProperty("cachePrepStmts", "true");
|
||||
ds.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
ds.addDataSourceProperty("useServerPrepStmts", "true");
|
||||
|
||||
ds.addDataSourceProperty("useSSL", Boolean.toString(useSSL));
|
||||
ds.addDataSourceProperty("requireSSL", Boolean.toString(requireSSL));
|
||||
ds.addDataSourceProperty("verifyServerCertificate", "false");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
ds.close();
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
Connection connection = ds.getConnection();
|
||||
if (Config.mb4) {
|
||||
connection.createStatement().executeUpdate("SET NAMES utf8mb4");
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,61 +1,61 @@
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
// Adapted from https://gist.github.com/evilmidget38/26d70114b834f71fb3b4
|
||||
|
||||
public class UUIDFetcher {
|
||||
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
private static final Gson gson = new GsonBuilder().setLenient().create();
|
||||
|
||||
public static Map<String, UUID> getUUIDs(List<String> names) throws Exception {
|
||||
Map<String, UUID> uuidMap = new HashMap<>();
|
||||
HttpURLConnection connection = createConnection();
|
||||
String body = gson.toJson(names);
|
||||
writeBody(connection, body);
|
||||
JsonArray array = gson.fromJson(new InputStreamReader(connection.getInputStream()), JsonArray.class);
|
||||
for (JsonElement profile : array) {
|
||||
JsonObject jsonProfile = (JsonObject) profile;
|
||||
String id = jsonProfile.get("id").getAsString();
|
||||
String name = jsonProfile.get("name").getAsString();
|
||||
UUID uuid = getUUID(id);
|
||||
uuidMap.put(name, uuid);
|
||||
}
|
||||
return uuidMap;
|
||||
}
|
||||
|
||||
private static void writeBody(HttpURLConnection connection, String body) throws Exception {
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
private static HttpURLConnection createConnection() throws Exception {
|
||||
URL url = new URL(PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
return connection;
|
||||
}
|
||||
|
||||
private static UUID getUUID(String id) {
|
||||
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
// Adapted from https://gist.github.com/evilmidget38/26d70114b834f71fb3b4
|
||||
|
||||
public class UUIDFetcher {
|
||||
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
private static final Gson gson = new GsonBuilder().setLenient().create();
|
||||
|
||||
public static Map<String, UUID> getUUIDs(List<String> names) throws Exception {
|
||||
Map<String, UUID> uuidMap = new HashMap<>();
|
||||
HttpURLConnection connection = createConnection();
|
||||
String body = gson.toJson(names);
|
||||
writeBody(connection, body);
|
||||
JsonArray array = gson.fromJson(new InputStreamReader(connection.getInputStream()), JsonArray.class);
|
||||
for (JsonElement profile : array) {
|
||||
JsonObject jsonProfile = (JsonObject) profile;
|
||||
String id = jsonProfile.get("id").getAsString();
|
||||
String name = jsonProfile.get("name").getAsString();
|
||||
UUID uuid = getUUID(id);
|
||||
uuidMap.put(name, uuid);
|
||||
}
|
||||
return uuidMap;
|
||||
}
|
||||
|
||||
private static void writeBody(HttpURLConnection connection, String body) throws Exception {
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
private static HttpURLConnection createConnection() throws Exception {
|
||||
URL url = new URL(PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
return connection;
|
||||
}
|
||||
|
||||
private static UUID getUUID(String id) {
|
||||
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
||||
}
|
||||
}
|
||||
|
@ -1,298 +1,298 @@
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
|
||||
public class Utils {
|
||||
public static String newline = System.getProperty("line.separator");
|
||||
|
||||
public static boolean isInt(String str) {
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isShort(String str) {
|
||||
try {
|
||||
Short.parseShort(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isByte(String str) {
|
||||
try {
|
||||
Byte.parseByte(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String listing(String[] entries, String delimiter, String finalDelimiter) {
|
||||
final int len = entries.length;
|
||||
if (len == 0) {
|
||||
return "";
|
||||
}
|
||||
if (len == 1) {
|
||||
return entries[0];
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder(entries[0]);
|
||||
for (int i = 1; i < len - 1; i++) {
|
||||
builder.append(delimiter).append(entries[i]);
|
||||
}
|
||||
builder.append(finalDelimiter).append(entries[len - 1]);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String listing(List<?> entries, String delimiter, String finalDelimiter) {
|
||||
final int len = entries.size();
|
||||
if (len == 0) {
|
||||
return "";
|
||||
}
|
||||
if (len == 1) {
|
||||
return entries.get(0).toString();
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder(entries.get(0).toString());
|
||||
for (int i = 1; i < len - 1; i++) {
|
||||
builder.append(delimiter).append(entries.get(i).toString());
|
||||
}
|
||||
builder.append(finalDelimiter).append(entries.get(len - 1).toString());
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static int parseTimeSpec(String[] spec) {
|
||||
if (spec == null || spec.length < 1 || spec.length > 2) {
|
||||
return -1;
|
||||
}
|
||||
if (spec.length == 1 && isInt(spec[0])) {
|
||||
return Integer.valueOf(spec[0]);
|
||||
}
|
||||
if (!spec[0].contains(":") && !spec[0].contains(".")) {
|
||||
if (spec.length == 2) {
|
||||
if (!isInt(spec[0])) {
|
||||
return -1;
|
||||
}
|
||||
int min = Integer.parseInt(spec[0]);
|
||||
if (spec[1].startsWith("h")) {
|
||||
min *= 60;
|
||||
} else if (spec[1].startsWith("d")) {
|
||||
min *= 1440;
|
||||
}
|
||||
return min;
|
||||
} else if (spec.length == 1) {
|
||||
int days = 0, hours = 0, minutes = 0;
|
||||
int lastIndex = 0, currIndex = 1;
|
||||
while (currIndex <= spec[0].length()) {
|
||||
while (currIndex <= spec[0].length() && isInt(spec[0].substring(lastIndex, currIndex))) {
|
||||
currIndex++;
|
||||
}
|
||||
if (currIndex - 1 != lastIndex) {
|
||||
if (currIndex > spec[0].length()) {
|
||||
return -1;
|
||||
}
|
||||
final String param = spec[0].substring(currIndex - 1, currIndex).toLowerCase();
|
||||
if (param.equals("d")) {
|
||||
days = Integer.parseInt(spec[0].substring(lastIndex, currIndex - 1));
|
||||
} else if (param.equals("h")) {
|
||||
hours = Integer.parseInt(spec[0].substring(lastIndex, currIndex - 1));
|
||||
} else if (param.equals("m")) {
|
||||
minutes = Integer.parseInt(spec[0].substring(lastIndex, currIndex - 1));
|
||||
}
|
||||
}
|
||||
lastIndex = currIndex;
|
||||
currIndex++;
|
||||
}
|
||||
if (days == 0 && hours == 0 && minutes == 0) {
|
||||
return -1;
|
||||
}
|
||||
return minutes + hours * 60 + days * 1440;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
final String timestamp;
|
||||
if (spec.length == 1) {
|
||||
if (spec[0].contains(":")) {
|
||||
timestamp = new SimpleDateFormat("dd.MM.yyyy").format(System.currentTimeMillis()) + " " + spec[0];
|
||||
} else {
|
||||
timestamp = spec[0] + " 00:00:00";
|
||||
}
|
||||
} else {
|
||||
timestamp = spec[0] + " " + spec[1];
|
||||
}
|
||||
try {
|
||||
return (int) ((System.currentTimeMillis() - new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").parse(timestamp).getTime()) / 60000);
|
||||
} catch (final ParseException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static String spaces(int count) {
|
||||
final StringBuilder filled = new StringBuilder(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
filled.append(' ');
|
||||
}
|
||||
return filled.toString();
|
||||
}
|
||||
|
||||
public static String join(String[] s, String delimiter) {
|
||||
if (s == null || s.length == 0) {
|
||||
return "";
|
||||
}
|
||||
final int len = s.length;
|
||||
final StringBuilder builder = new StringBuilder(s[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
builder.append(delimiter).append(s[i]);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of arguments e.g ['lb', 'clearlog', 'world', '"my', 'world', 'of', 'swag"']
|
||||
* into a list of arguments with any text encapsulated by quotes treated as one word
|
||||
* For this particular example: ['lb', 'clearlog', 'world', '"my world of swag"']
|
||||
*
|
||||
* @param args The list of arguments
|
||||
* @return A new list with the quoted arguments parsed to single values
|
||||
*/
|
||||
public static List<String> parseQuotes(List<String> args) {
|
||||
List<String> newArguments = new ArrayList<>();
|
||||
String subjectString = join(args.toArray(new String[args.size()]), " ");
|
||||
|
||||
Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");
|
||||
Matcher regexMatcher = regex.matcher(subjectString);
|
||||
while (regexMatcher.find()) {
|
||||
newArguments.add(regexMatcher.group());
|
||||
}
|
||||
|
||||
return newArguments;
|
||||
}
|
||||
|
||||
public static class ExtensionFilenameFilter implements FilenameFilter {
|
||||
private final String ext;
|
||||
|
||||
public ExtensionFilenameFilter(String ext) {
|
||||
this.ext = "." + ext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.toLowerCase().endsWith(ext);
|
||||
}
|
||||
}
|
||||
|
||||
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
public static String mysqlEscapeBytes(byte[] bytes) {
|
||||
char[] hexChars = new char[bytes.length * 2 + 2];
|
||||
hexChars[0] = '0';
|
||||
hexChars[1] = 'x';
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
int v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2 + 2] = hexArray[v >>> 4];
|
||||
hexChars[j * 2 + 3] = hexArray[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars);
|
||||
}
|
||||
|
||||
public static String mysqlPrepareBytesForInsertAllowNull(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
return "null";
|
||||
}
|
||||
return "'" + mysqlEscapeBytes(bytes) + "'";
|
||||
}
|
||||
|
||||
public static String mysqlTextEscape(String untrusted) {
|
||||
return untrusted.replace("\\", "\\\\").replace("'", "\\'");
|
||||
}
|
||||
|
||||
public static ItemStack loadItemStack(byte[] data) {
|
||||
if (data == null || data.length == 0) {
|
||||
return null;
|
||||
}
|
||||
YamlConfiguration conf = deserializeYamlConfiguration(data);
|
||||
return conf == null ? null : conf.getItemStack("stack");
|
||||
}
|
||||
|
||||
public static byte[] saveItemStack(ItemStack stack) {
|
||||
if (stack == null || BukkitUtils.isEmpty(stack.getType())) {
|
||||
return null;
|
||||
}
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
conf.set("stack", stack);
|
||||
return serializeYamlConfiguration(conf);
|
||||
}
|
||||
|
||||
public static YamlConfiguration deserializeYamlConfiguration(byte[] data) {
|
||||
if (data == null || data.length == 0) {
|
||||
return null;
|
||||
}
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
try {
|
||||
InputStreamReader reader = new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), "UTF-8");
|
||||
conf.load(reader);
|
||||
reader.close();
|
||||
return conf;
|
||||
} catch (ZipException | InvalidConfigurationException e) {
|
||||
LogBlock.getInstance().getLogger().warning("Could not deserialize YamlConfiguration: " + e.getMessage());
|
||||
return conf;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("IOException should be impossible for ByteArrayInputStream", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] serializeYamlConfiguration(YamlConfiguration conf) {
|
||||
if (conf == null || conf.getKeys(false).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStreamWriter writer = new OutputStreamWriter(new GZIPOutputStream(baos), "UTF-8");
|
||||
writer.write(conf.saveToString());
|
||||
writer.close();
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("IOException should be impossible for ByteArrayOutputStream", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String serializeForSQL(YamlConfiguration conf) {
|
||||
return mysqlPrepareBytesForInsertAllowNull(serializeYamlConfiguration(conf));
|
||||
}
|
||||
|
||||
public static double warpDegrees(double degrees) {
|
||||
double d = degrees % 360.0;
|
||||
if (d >= 180.0) {
|
||||
d -= 360.0;
|
||||
}
|
||||
if (d < -180.0) {
|
||||
d += 360.0;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
package de.diddiz.LogBlock.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import de.diddiz.LogBlock.LogBlock;
|
||||
|
||||
public class Utils {
|
||||
public static String newline = System.getProperty("line.separator");
|
||||
|
||||
public static boolean isInt(String str) {
|
||||
try {
|
||||
Integer.parseInt(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isShort(String str) {
|
||||
try {
|
||||
Short.parseShort(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isByte(String str) {
|
||||
try {
|
||||
Byte.parseByte(str);
|
||||
return true;
|
||||
} catch (final NumberFormatException ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String listing(String[] entries, String delimiter, String finalDelimiter) {
|
||||
final int len = entries.length;
|
||||
if (len == 0) {
|
||||
return "";
|
||||
}
|
||||
if (len == 1) {
|
||||
return entries[0];
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder(entries[0]);
|
||||
for (int i = 1; i < len - 1; i++) {
|
||||
builder.append(delimiter).append(entries[i]);
|
||||
}
|
||||
builder.append(finalDelimiter).append(entries[len - 1]);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String listing(List<?> entries, String delimiter, String finalDelimiter) {
|
||||
final int len = entries.size();
|
||||
if (len == 0) {
|
||||
return "";
|
||||
}
|
||||
if (len == 1) {
|
||||
return entries.get(0).toString();
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder(entries.get(0).toString());
|
||||
for (int i = 1; i < len - 1; i++) {
|
||||
builder.append(delimiter).append(entries.get(i).toString());
|
||||
}
|
||||
builder.append(finalDelimiter).append(entries.get(len - 1).toString());
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static int parseTimeSpec(String[] spec) {
|
||||
if (spec == null || spec.length < 1 || spec.length > 2) {
|
||||
return -1;
|
||||
}
|
||||
if (spec.length == 1 && isInt(spec[0])) {
|
||||
return Integer.valueOf(spec[0]);
|
||||
}
|
||||
if (!spec[0].contains(":") && !spec[0].contains(".")) {
|
||||
if (spec.length == 2) {
|
||||
if (!isInt(spec[0])) {
|
||||
return -1;
|
||||
}
|
||||
int min = Integer.parseInt(spec[0]);
|
||||
if (spec[1].startsWith("h")) {
|
||||
min *= 60;
|
||||
} else if (spec[1].startsWith("d")) {
|
||||
min *= 1440;
|
||||
}
|
||||
return min;
|
||||
} else if (spec.length == 1) {
|
||||
int days = 0, hours = 0, minutes = 0;
|
||||
int lastIndex = 0, currIndex = 1;
|
||||
while (currIndex <= spec[0].length()) {
|
||||
while (currIndex <= spec[0].length() && isInt(spec[0].substring(lastIndex, currIndex))) {
|
||||
currIndex++;
|
||||
}
|
||||
if (currIndex - 1 != lastIndex) {
|
||||
if (currIndex > spec[0].length()) {
|
||||
return -1;
|
||||
}
|
||||
final String param = spec[0].substring(currIndex - 1, currIndex).toLowerCase();
|
||||
if (param.equals("d")) {
|
||||
days = Integer.parseInt(spec[0].substring(lastIndex, currIndex - 1));
|
||||
} else if (param.equals("h")) {
|
||||
hours = Integer.parseInt(spec[0].substring(lastIndex, currIndex - 1));
|
||||
} else if (param.equals("m")) {
|
||||
minutes = Integer.parseInt(spec[0].substring(lastIndex, currIndex - 1));
|
||||
}
|
||||
}
|
||||
lastIndex = currIndex;
|
||||
currIndex++;
|
||||
}
|
||||
if (days == 0 && hours == 0 && minutes == 0) {
|
||||
return -1;
|
||||
}
|
||||
return minutes + hours * 60 + days * 1440;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
final String timestamp;
|
||||
if (spec.length == 1) {
|
||||
if (spec[0].contains(":")) {
|
||||
timestamp = new SimpleDateFormat("dd.MM.yyyy").format(System.currentTimeMillis()) + " " + spec[0];
|
||||
} else {
|
||||
timestamp = spec[0] + " 00:00:00";
|
||||
}
|
||||
} else {
|
||||
timestamp = spec[0] + " " + spec[1];
|
||||
}
|
||||
try {
|
||||
return (int) ((System.currentTimeMillis() - new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").parse(timestamp).getTime()) / 60000);
|
||||
} catch (final ParseException ex) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static String spaces(int count) {
|
||||
final StringBuilder filled = new StringBuilder(count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
filled.append(' ');
|
||||
}
|
||||
return filled.toString();
|
||||
}
|
||||
|
||||
public static String join(String[] s, String delimiter) {
|
||||
if (s == null || s.length == 0) {
|
||||
return "";
|
||||
}
|
||||
final int len = s.length;
|
||||
final StringBuilder builder = new StringBuilder(s[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
builder.append(delimiter).append(s[i]);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of arguments e.g ['lb', 'clearlog', 'world', '"my', 'world', 'of', 'swag"']
|
||||
* into a list of arguments with any text encapsulated by quotes treated as one word
|
||||
* For this particular example: ['lb', 'clearlog', 'world', '"my world of swag"']
|
||||
*
|
||||
* @param args The list of arguments
|
||||
* @return A new list with the quoted arguments parsed to single values
|
||||
*/
|
||||
public static List<String> parseQuotes(List<String> args) {
|
||||
List<String> newArguments = new ArrayList<>();
|
||||
String subjectString = join(args.toArray(new String[args.size()]), " ");
|
||||
|
||||
Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");
|
||||
Matcher regexMatcher = regex.matcher(subjectString);
|
||||
while (regexMatcher.find()) {
|
||||
newArguments.add(regexMatcher.group());
|
||||
}
|
||||
|
||||
return newArguments;
|
||||
}
|
||||
|
||||
public static class ExtensionFilenameFilter implements FilenameFilter {
|
||||
private final String ext;
|
||||
|
||||
public ExtensionFilenameFilter(String ext) {
|
||||
this.ext = "." + ext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.toLowerCase().endsWith(ext);
|
||||
}
|
||||
}
|
||||
|
||||
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
public static String mysqlEscapeBytes(byte[] bytes) {
|
||||
char[] hexChars = new char[bytes.length * 2 + 2];
|
||||
hexChars[0] = '0';
|
||||
hexChars[1] = 'x';
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
int v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2 + 2] = hexArray[v >>> 4];
|
||||
hexChars[j * 2 + 3] = hexArray[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars);
|
||||
}
|
||||
|
||||
public static String mysqlPrepareBytesForInsertAllowNull(byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
return "null";
|
||||
}
|
||||
return "'" + mysqlEscapeBytes(bytes) + "'";
|
||||
}
|
||||
|
||||
public static String mysqlTextEscape(String untrusted) {
|
||||
return untrusted.replace("\\", "\\\\").replace("'", "\\'");
|
||||
}
|
||||
|
||||
public static ItemStack loadItemStack(byte[] data) {
|
||||
if (data == null || data.length == 0) {
|
||||
return null;
|
||||
}
|
||||
YamlConfiguration conf = deserializeYamlConfiguration(data);
|
||||
return conf == null ? null : conf.getItemStack("stack");
|
||||
}
|
||||
|
||||
public static byte[] saveItemStack(ItemStack stack) {
|
||||
if (stack == null || BukkitUtils.isEmpty(stack.getType())) {
|
||||
return null;
|
||||
}
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
conf.set("stack", stack);
|
||||
return serializeYamlConfiguration(conf);
|
||||
}
|
||||
|
||||
public static YamlConfiguration deserializeYamlConfiguration(byte[] data) {
|
||||
if (data == null || data.length == 0) {
|
||||
return null;
|
||||
}
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
try {
|
||||
InputStreamReader reader = new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(data)), "UTF-8");
|
||||
conf.load(reader);
|
||||
reader.close();
|
||||
return conf;
|
||||
} catch (ZipException | InvalidConfigurationException e) {
|
||||
LogBlock.getInstance().getLogger().warning("Could not deserialize YamlConfiguration: " + e.getMessage());
|
||||
return conf;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("IOException should be impossible for ByteArrayInputStream", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] serializeYamlConfiguration(YamlConfiguration conf) {
|
||||
if (conf == null || conf.getKeys(false).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStreamWriter writer = new OutputStreamWriter(new GZIPOutputStream(baos), "UTF-8");
|
||||
writer.write(conf.saveToString());
|
||||
writer.close();
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("IOException should be impossible for ByteArrayOutputStream", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String serializeForSQL(YamlConfiguration conf) {
|
||||
return mysqlPrepareBytesForInsertAllowNull(serializeYamlConfiguration(conf));
|
||||
}
|
||||
|
||||
public static double warpDegrees(double degrees) {
|
||||
double d = degrees % 360.0;
|
||||
if (d >= 180.0) {
|
||||
d -= 360.0;
|
||||
}
|
||||
if (d < -180.0) {
|
||||
d += 360.0;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user