Reformat the entire project:

Use of braces is now enforced EVERYWHERE
Switched to 4spaces instead of tabs
This commit is contained in:
Ammar Askar
2015-03-22 20:15:04 +05:00
parent 7c52c10922
commit 9f41fffbc3
62 changed files with 7259 additions and 6939 deletions

320
pom.xml
View File

@@ -1,170 +1,170 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.diddiz</groupId>
<artifactId>logblock</artifactId>
<version>1.94-dev-SNAPSHOT</version>
<packaging>jar</packaging>
<groupId>de.diddiz</groupId>
<artifactId>logblock</artifactId>
<version>1.94-dev-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LogBlock</name>
<description>Logs blocks.</description>
<url>https://github.com/LogBlock/LogBlock</url>
<name>LogBlock</name>
<description>Logs blocks.</description>
<url>https://github.com/LogBlock/LogBlock</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build.number>${buildNumber}</build.number>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build.number>${buildNumber}</build.number>
</properties>
<scm>
<connection>scm:git:git://github.com/LogBlock/LogBlock.git</connection>
<developerConnection>scm:git:ssh://git@github.com:LogBlock/LogBlock.git</developerConnection>
<url>https://github.com/LogBlock/LogBlock</url>
</scm>
<scm>
<connection>scm:git:git://github.com/LogBlock/LogBlock.git</connection>
<developerConnection>scm:git:ssh://git@github.com:LogBlock/LogBlock.git</developerConnection>
<url>https://github.com/LogBlock/LogBlock</url>
</scm>
<ciManagement>
<system>jenkins</system>
<url>http://ci.kitteh.org/job/LogBlock</url>
</ciManagement>
<ciManagement>
<system>jenkins</system>
<url>http://ci.kitteh.org/job/LogBlock</url>
</ciManagement>
<distributionManagement>
<repository>
<id>md_5-releases</id>
<url>http://repo.md-5.net/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>md_5-snapshots</id>
<url>http://repo.md-5.net/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<distributionManagement>
<repository>
<id>md_5-releases</id>
<url>http://repo.md-5.net/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>md_5-snapshots</id>
<url>http://repo.md-5.net/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>questioner</artifactId>
<version>${project.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/LogBlockQuestioner.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.3.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repobo-snap</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>kitteh-repo</id>
<url>http://repo.kitteh.org/content/groups/public</url>
</repository>
</repositories>
<profiles>
<profile>
<id>static_build_number</id>
<activation>
<property>
<name>!env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<buildNumber>0</buildNumber>
<buildDescription>(manually compiled)</buildDescription>
</properties>
</profile>
<profile>
<id>dynamic_build_number</id>
<activation>
<property>
<name>env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<buildNumber>${env.BUILD_NUMBER}</buildNumber>
<buildDescription>(build #${env.BUILD_NUMBER})</buildDescription>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>questioner</artifactId>
<version>${project.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/LogBlockQuestioner.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>6.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java6</artifactId>
<version>2.3.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>repobo-snap</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>kitteh-repo</id>
<url>http://repo.kitteh.org/content/groups/public</url>
</repository>
</repositories>
<profiles>
<profile>
<id>static_build_number</id>
<activation>
<property>
<name>!env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<buildNumber>0</buildNumber>
<buildDescription>(manually compiled)</buildDescription>
</properties>
</profile>
<profile>
<id>dynamic_build_number</id>
<activation>
<property>
<name>env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<buildNumber>${env.BUILD_NUMBER}</buildNumber>
<buildDescription>(build #${env.BUILD_NUMBER})</buildDescription>
</properties>
</profile>
</profiles>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>minecraft.plugin.version</name>
<value>${project.version} ${buildDescription}</value>
<regex>[0-9\.]+ \(.+\)</regex>
<replacement>${project.version}</replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>minecraft.plugin.version</name>
<value>${project.version} ${buildDescription}</value>
<regex>[0-9\.]+ \(.+\)</regex>
<replacement>${project.version}</replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,99 +1,104 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.BukkitUtils.entityName;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import static de.diddiz.util.BukkitUtils.entityName;
public class Actor {
@Override
public int hashCode() {
int hash = 5;
hash = 79 * hash + (this.UUID != null ? this.UUID.hashCode() : 0);
return hash;
}
@Override
public int hashCode() {
int hash = 5;
hash = 79 * hash + (this.UUID != null ? this.UUID.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Actor other = (Actor) obj;
return ((this.UUID == null && other.UUID == null) || this.UUID.equals(other.UUID));
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (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 String name;
final String UUID;
public Actor(String name, String UUID) {
this.name = name;
this.UUID = UUID;
}
public Actor(String name, java.util.UUID UUID) {
this.name = name;
this.UUID = UUID.toString();
}
public Actor(String name, String UUID) {
this.name = name;
this.UUID = UUID;
public Actor(String name) {
this(name, generateUUID(name));
}
public Actor(ResultSet rs) throws SQLException {
this(rs.getString("playername"),rs.getString("UUID"));
}
public String getName() {
return name;
}
}
public String getUUID() {
return UUID;
}
public Actor(String name, java.util.UUID UUID) {
this.name = name;
this.UUID = UUID.toString();
public static Actor actorFromEntity(Entity entity) {
if (entity instanceof Player) {
return new Actor(entityName(entity),entity.getUniqueId());
} else {
return new Actor(entityName(entity));
}
}
public static Actor actorFromEntity(EntityType entity) {
return new Actor(entity.getName());
}
}
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());
public Actor(String name) {
this(name, generateUUID(name));
}
}
public static boolean isValidUUID(String uuid) {
try {
java.util.UUID.fromString(uuid);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
public Actor(ResultSet rs) throws SQLException {
this(rs.getString("playername"), rs.getString("UUID"));
}
public static String generateUUID(String name) {
return "log_" + name;
public String getName() {
return name;
}
}
public String getUUID() {
return UUID;
}
public static Actor actorFromEntity(Entity entity) {
if (entity instanceof Player) {
return new Actor(entityName(entity), entity.getUniqueId());
} else {
return new Actor(entityName(entity));
}
}
public static Actor actorFromEntity(EntityType entity) {
return new Actor(entity.getName());
}
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());
}
}
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;
}
}

View File

@@ -1,29 +1,28 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.autoClearLog;
import static org.bukkit.Bukkit.getConsoleSender;
import static org.bukkit.Bukkit.getLogger;
import static org.bukkit.Bukkit.getServer;
import java.util.Arrays;
import java.util.logging.Level;
public class AutoClearLog implements Runnable
{
private final LogBlock logblock;
import static de.diddiz.LogBlock.config.Config.autoClearLog;
import static org.bukkit.Bukkit.*;
AutoClearLog(LogBlock logblock) {
this.logblock = logblock;
}
public class AutoClearLog implements Runnable {
private final LogBlock logblock;
@Override
public void run() {
final CommandsHandler handler = logblock.getCommandsHandler();
for (final String paramStr : autoClearLog)
try {
final QueryParams params = new QueryParams(logblock, getConsoleSender(), Arrays.asList(paramStr.split(" ")));
handler.new CommandClearLog(getServer().getConsoleSender(), params, false);
} catch (final Exception ex) {
getLogger().log(Level.SEVERE, "Failed to schedule auto ClearLog: ", ex);
}
}
AutoClearLog(LogBlock logblock) {
this.logblock = logblock;
}
@Override
public void run() {
final CommandsHandler handler = logblock.getCommandsHandler();
for (final String paramStr : autoClearLog) {
try {
final QueryParams params = new QueryParams(logblock, getConsoleSender(), Arrays.asList(paramStr.split(" ")));
handler.new CommandClearLog(getServer().getConsoleSender(), params, false);
} catch (final Exception ex) {
getLogger().log(Level.SEVERE, "Failed to schedule auto ClearLog: ", ex);
}
}
}
}

View File

@@ -1,119 +1,128 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.MaterialName.materialName;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import java.sql.ResultSet;
import java.sql.SQLException;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Location;
import de.diddiz.LogBlock.config.Config;
import static de.diddiz.util.LoggingUtil.checkText;
import org.bukkit.Material;
import static de.diddiz.util.MaterialName.materialName;
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 replaced, type;
public final byte data;
public final String signtext;
public final ChestAccess ca;
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 replaced, type;
public final byte data;
public final String signtext;
public final ChestAccess ca;
public BlockChange(long date, Location loc, Actor actor, int replaced, int type, byte data, String signtext, ChestAccess ca) {
id = 0;
this.date = date;
this.loc = loc;
this.actor = actor;
this.replaced = replaced;
this.type = type;
this.data = data;
this.signtext = checkText(signtext);
this.ca = ca;
this.playerName = actor == null ? null : actor.getName();
}
public BlockChange(long date, Location loc, Actor actor, int replaced, int type, byte data, String signtext, ChestAccess ca) {
id = 0;
this.date = date;
this.loc = loc;
this.actor = actor;
this.replaced = replaced;
this.type = type;
this.data = data;
this.signtext = checkText(signtext);
this.ca = ca;
this.playerName = actor == null ? null : actor.getName();
}
public BlockChange(ResultSet rs, QueryParams p) throws SQLException {
id = p.needId ? rs.getInt("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;
replaced = p.needType ? rs.getInt("replaced") : 0;
type = p.needType ? rs.getInt("type") : 0;
data = p.needData ? rs.getByte("data") : (byte)0;
signtext = p.needSignText ? rs.getString("signtext") : null;
ca = p.needChestAccess && rs.getShort("itemtype") != 0 && rs.getShort("itemamount") != 0 ? new ChestAccess(rs.getShort("itemtype"), rs.getShort("itemamount"), rs.getShort("itemdata")) : null;
}
public BlockChange(ResultSet rs, QueryParams p) throws SQLException {
id = p.needId ? rs.getInt("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;
replaced = p.needType ? rs.getInt("replaced") : 0;
type = p.needType ? rs.getInt("type") : 0;
data = p.needData ? rs.getByte("data") : (byte) 0;
signtext = p.needSignText ? rs.getString("signtext") : null;
ca = p.needChestAccess && rs.getShort("itemtype") != 0 && rs.getShort("itemamount") != 0 ? new ChestAccess(rs.getShort("itemtype"), rs.getShort("itemamount"), rs.getShort("itemdata")) : null;
}
@Override
public String toString() {
final StringBuilder msg = new StringBuilder();
if (date > 0)
msg.append(Config.formatter.format(date)).append(" ");
if (actor != null)
msg.append(actor.getName()).append(" ");
if (signtext != null) {
final String action = type == 0 ? "destroyed " : "created ";
if (!signtext.contains("\0"))
msg.append(action).append(signtext);
else
msg.append(action).append(materialName(type != 0 ? type : replaced)).append(" [").append(signtext.replace("\0", "] [")).append("]");
} else if (type == replaced) {
if (type == 0)
msg.append("did an unspecified action");
else if (ca != null) {
if (ca.itemType == 0 || ca.itemAmount == 0)
msg.append("looked inside ").append(materialName(type));
else if (ca.itemAmount < 0)
msg.append("took ").append(-ca.itemAmount).append("x ").append(materialName(ca.itemType, ca.itemData)).append(" from ").append(materialName(type));
else
msg.append("put ").append(ca.itemAmount).append("x ").append(materialName(ca.itemType, ca.itemData)).append(" into ").append(materialName(type));
} else if (BukkitUtils.getContainerBlocks().contains(Material.getMaterial(type)))
msg.append("opened ").append(materialName(type));
else if (type == 64 || type == 71)
// This is a problem that will have to be addressed in LB 2,
// there is no way to tell from the top half of the block if
// the door is opened or closed.
msg.append("moved ").append(materialName(type));
// Trapdoor
else if (type == 96)
msg.append((data < 8 || data > 11) ? "opened" : "closed").append(" ").append(materialName(type));
// Fence gate
else if (type == 107)
msg.append(data > 3 ? "opened" : "closed").append(" ").append(materialName(type));
else if (type == 69)
msg.append("switched ").append(materialName(type));
else if (type == 77 || type == 143)
msg.append("pressed ").append(materialName(type));
else if (type == 92)
msg.append("ate a piece of ").append(materialName(type));
else if (type == 25 || type == 93 || type == 94 || type == 149 || type == 150)
msg.append("changed ").append(materialName(type));
else if (type == 70 || type == 72 || type == 147 || type == 148)
msg.append("stepped on ").append(materialName(type));
else if (type == 132)
msg.append("ran into ").append(materialName(type));
} else if (type == 0)
msg.append("destroyed ").append(materialName(replaced, data));
else if (replaced == 0)
msg.append("created ").append(materialName(type, data));
else
msg.append("replaced ").append(materialName(replaced, (byte)0)).append(" with ").append(materialName(type, data));
if (loc != null)
msg.append(" at ").append(loc.getBlockX()).append(":").append(loc.getBlockY()).append(":").append(loc.getBlockZ());
return msg.toString();
}
@Override
public String toString() {
final StringBuilder msg = new StringBuilder();
if (date > 0) {
msg.append(Config.formatter.format(date)).append(" ");
}
if (actor != null) {
msg.append(actor.getName()).append(" ");
}
if (signtext != null) {
final String action = type == 0 ? "destroyed " : "created ";
if (!signtext.contains("\0")) {
msg.append(action).append(signtext);
} else {
msg.append(action).append(materialName(type != 0 ? type : replaced)).append(" [").append(signtext.replace("\0", "] [")).append("]");
}
} else if (type == replaced) {
if (type == 0) {
msg.append("did an unspecified action");
} else if (ca != null) {
if (ca.itemType == 0 || ca.itemAmount == 0) {
msg.append("looked inside ").append(materialName(type));
} else if (ca.itemAmount < 0) {
msg.append("took ").append(-ca.itemAmount).append("x ").append(materialName(ca.itemType, ca.itemData)).append(" from ").append(materialName(type));
} else {
msg.append("put ").append(ca.itemAmount).append("x ").append(materialName(ca.itemType, ca.itemData)).append(" into ").append(materialName(type));
}
} else if (BukkitUtils.getContainerBlocks().contains(Material.getMaterial(type))) {
msg.append("opened ").append(materialName(type));
} else if (type == 64 || type == 71)
// This is a problem that will have to be addressed in LB 2,
// there is no way to tell from the top half of the block if
// the door is opened or closed.
{
msg.append("moved ").append(materialName(type));
}
// Trapdoor
else if (type == 96) {
msg.append((data < 8 || data > 11) ? "opened" : "closed").append(" ").append(materialName(type));
}
// Fence gate
else if (type == 107) {
msg.append(data > 3 ? "opened" : "closed").append(" ").append(materialName(type));
} else if (type == 69) {
msg.append("switched ").append(materialName(type));
} else if (type == 77 || type == 143) {
msg.append("pressed ").append(materialName(type));
} else if (type == 92) {
msg.append("ate a piece of ").append(materialName(type));
} else if (type == 25 || type == 93 || type == 94 || type == 149 || type == 150) {
msg.append("changed ").append(materialName(type));
} else if (type == 70 || type == 72 || type == 147 || type == 148) {
msg.append("stepped on ").append(materialName(type));
} else if (type == 132) {
msg.append("ran into ").append(materialName(type));
}
} else if (type == 0) {
msg.append("destroyed ").append(materialName(replaced, data));
} else if (replaced == 0) {
msg.append("created ").append(materialName(type, data));
} else {
msg.append("replaced ").append(materialName(replaced, (byte) 0)).append(" with ").append(materialName(type, data));
}
if (loc != null) {
msg.append(" at ").append(loc.getBlockX()).append(":").append(loc.getBlockY()).append(":").append(loc.getBlockZ());
}
return msg.toString();
}
@Override
public Location getLocation() {
return loc;
}
@Override
public Location getLocation() {
return loc;
}
@Override
public String getMessage() {
return toString();
}
@Override
public String getMessage() {
return toString();
}
}

View File

@@ -1,39 +1,40 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.LoggingUtil.checkText;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.Location;
public class ChatMessage implements LookupCacheElement
{
final long id, date;
final String playerName, message;
final Actor player;
import java.sql.ResultSet;
import java.sql.SQLException;
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();
}
import static de.diddiz.util.LoggingUtil.checkText;
public ChatMessage(ResultSet rs, QueryParams p) throws SQLException {
id = p.needId ? rs.getInt("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;
}
public class ChatMessage implements LookupCacheElement {
final long id, date;
final String playerName, message;
final Actor player;
@Override
public Location getLocation() {
return null;
}
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();
}
@Override
public String getMessage() {
return (player != null ? "<" + player.getName() + "> " : "") + (message != null ? message : "");
}
public ChatMessage(ResultSet rs, QueryParams p) throws SQLException {
id = p.needId ? rs.getInt("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 String getMessage() {
return (player != null ? "<" + player.getName() + "> " : "") + (message != null ? message : "");
}
}

View File

@@ -1,12 +1,11 @@
package de.diddiz.LogBlock;
public class ChestAccess
{
final short itemType, itemAmount, itemData;
public class ChestAccess {
final short itemType, itemAmount, itemData;
public ChestAccess(short itemType, short itemAmount, short itemData) {
this.itemType = itemType;
this.itemAmount = itemAmount;
this.itemData = itemData >= 0 ? itemData : 0;
}
public ChestAccess(short itemType, short itemAmount, short itemData) {
this.itemType = itemType;
this.itemAmount = itemAmount;
this.itemData = itemData >= 0 ? itemData : 0;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,70 +1,70 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.Utils.newline;
import static org.bukkit.Bukkit.getLogger;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import de.diddiz.util.Utils.ExtensionFilenameFilter;
import java.io.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import de.diddiz.util.Utils.ExtensionFilenameFilter;
public class DumpedLogImporter implements Runnable
{
private final LogBlock logblock;
import static de.diddiz.util.Utils.newline;
import static org.bukkit.Bukkit.getLogger;
DumpedLogImporter(LogBlock logblock) {
this.logblock = logblock;
}
public class DumpedLogImporter implements Runnable {
private final LogBlock logblock;
@Override
public void run() {
final File[] imports = new File("plugins/LogBlock/import/").listFiles(new ExtensionFilenameFilter("sql"));
if (imports != null && imports.length > 0) {
getLogger().info("Found " + imports.length + " imports.");
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;
for (final File sqlFile : imports) {
getLogger().info("Trying to import " + sqlFile.getName() + " ...");
final BufferedReader reader = new BufferedReader(new FileReader(sqlFile));
String line;
while ((line = reader.readLine()) != null)
try {
st.execute(line);
successes++;
} catch (final Exception ex) {
getLogger().warning("Error while importing: '" + line + "': " + ex.getMessage());
writer.write(line + newline);
errors++;
}
conn.commit();
reader.close();
sqlFile.delete();
getLogger().info("Successfully imported " + sqlFile.getName() + ".");
}
writer.close();
st.close();
getLogger().info("Successfully imported stored queue. (" + successes + " rows imported, " + errors + " errors)");
} catch (final Exception ex) {
getLogger().log(Level.WARNING, "Error while importing: ", ex);
} finally {
if (conn != null)
try {
conn.close();
} catch (final SQLException ex) {
}
}
}
}
DumpedLogImporter(LogBlock logblock) {
this.logblock = logblock;
}
@Override
public void run() {
final File[] imports = new File("plugins/LogBlock/import/").listFiles(new ExtensionFilenameFilter("sql"));
if (imports != null && imports.length > 0) {
getLogger().info("Found " + imports.length + " imports.");
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;
for (final File sqlFile : imports) {
getLogger().info("Trying to import " + sqlFile.getName() + " ...");
final BufferedReader reader = new BufferedReader(new FileReader(sqlFile));
String line;
while ((line = reader.readLine()) != null) {
try {
st.execute(line);
successes++;
} catch (final Exception ex) {
getLogger().warning("Error while importing: '" + line + "': " + ex.getMessage());
writer.write(line + newline);
errors++;
}
}
conn.commit();
reader.close();
sqlFile.delete();
getLogger().info("Successfully imported " + sqlFile.getName() + ".");
}
writer.close();
st.close();
getLogger().info("Successfully imported stored queue. (" + successes + " rows imported, " + errors + " errors)");
} catch (final Exception ex) {
getLogger().log(Level.WARNING, "Error while importing: ", ex);
} finally {
if (conn != null) {
try {
conn.close();
} catch (final SQLException ex) {
}
}
}
}
}
}

View File

@@ -1,65 +1,66 @@
package de.diddiz.LogBlock;
import java.sql.ResultSet;
import java.sql.SQLException;
import de.diddiz.LogBlock.config.Config;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;
import de.diddiz.LogBlock.config.Config;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Kill implements LookupCacheElement
{
final long id, date;
public final Location loc;
final String killerName, victimName;
final int weapon;
public class Kill implements LookupCacheElement {
final long id, date;
public final Location loc;
final String killerName, victimName;
final int weapon;
public Kill(String killerName, String victimName, int weapon, Location loc) {
id = 0;
date = System.currentTimeMillis() / 1000;
this.loc = loc;
this.killerName = killerName;
this.victimName = victimName;
this.weapon = weapon;
}
public Kill(String killerName, String victimName, int weapon, Location loc) {
id = 0;
date = System.currentTimeMillis() / 1000;
this.loc = loc;
this.killerName = killerName;
this.victimName = victimName;
this.weapon = weapon;
}
public Kill(ResultSet rs, QueryParams p) throws SQLException {
id = p.needId ? rs.getInt("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;
killerName = p.needKiller ? rs.getString("killer") : null;
victimName = p.needVictim ? rs.getString("victim") : null;
weapon = p.needWeapon ? rs.getInt("weapon") : 0;
}
public Kill(ResultSet rs, QueryParams p) throws SQLException {
id = p.needId ? rs.getInt("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;
killerName = p.needKiller ? rs.getString("killer") : null;
victimName = p.needVictim ? rs.getString("victim") : null;
weapon = p.needWeapon ? rs.getInt("weapon") : 0;
}
@Override
public String toString() {
final StringBuilder msg = new StringBuilder();
if (date > 0)
msg.append(Config.formatter.format(date)).append(" ");
msg.append(killerName).append(" killed ").append(victimName);
if (loc != null)
msg.append(" at ").append(loc.getBlockX()).append(":").append(loc.getBlockY()).append(":").append(loc.getBlockZ());
String weaponName = prettyItemName(new ItemStack(weapon));
msg.append(" with " + weaponName); // + ("aeiou".contains(weaponName.substring(0, 1)) ? "an " : "a " )
return msg.toString();
}
@Override
public String toString() {
final StringBuilder msg = new StringBuilder();
if (date > 0) {
msg.append(Config.formatter.format(date)).append(" ");
}
msg.append(killerName).append(" killed ").append(victimName);
if (loc != null) {
msg.append(" at ").append(loc.getBlockX()).append(":").append(loc.getBlockY()).append(":").append(loc.getBlockZ());
}
String weaponName = prettyItemName(new ItemStack(weapon));
msg.append(" with " + weaponName); // + ("aeiou".contains(weaponName.substring(0, 1)) ? "an " : "a " )
return msg.toString();
}
@Override
public Location getLocation() {
return loc;
}
@Override
public Location getLocation() {
return loc;
}
@Override
public String getMessage() {
return toString();
}
@Override
public String getMessage() {
return toString();
}
public String prettyItemName(ItemStack i) {
String item = i.getType().toString().replace('_', ' ' ).toLowerCase();
if(item.equals("air")) {
item = "fist";
}
return item;
}
public String prettyItemName(ItemStack i) {
String item = i.getType().toString().replace('_', ' ').toLowerCase();
if (item.equals("air")) {
item = "fist";
}
return item;
}
}

View File

@@ -1,28 +1,7 @@
package de.diddiz.LogBlock;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.LogBlock.listeners.BanListener;
import de.diddiz.LogBlock.listeners.BlockBreakLogging;
import de.diddiz.LogBlock.listeners.BlockBurnLogging;
import de.diddiz.LogBlock.listeners.BlockPlaceLogging;
import de.diddiz.LogBlock.listeners.BlockSpreadLogging;
import de.diddiz.LogBlock.listeners.ChatLogging;
import de.diddiz.LogBlock.listeners.ChestAccessLogging;
import de.diddiz.LogBlock.listeners.CreatureInteractLogging;
import de.diddiz.LogBlock.listeners.EndermenLogging;
import de.diddiz.LogBlock.listeners.ExplosionLogging;
import de.diddiz.LogBlock.listeners.FluidFlowLogging;
import de.diddiz.LogBlock.listeners.InteractLogging;
import de.diddiz.LogBlock.listeners.KillLogging;
import de.diddiz.LogBlock.listeners.LeavesDecayLogging;
import de.diddiz.LogBlock.listeners.LockedChestDecayLogging;
import de.diddiz.LogBlock.listeners.PlayerInfoLogging;
import de.diddiz.LogBlock.listeners.SignChangeLogging;
import de.diddiz.LogBlock.listeners.SnowFadeLogging;
import de.diddiz.LogBlock.listeners.SnowFormLogging;
import de.diddiz.LogBlock.listeners.StructureGrowLogging;
import de.diddiz.LogBlock.listeners.ToolListener;
import de.diddiz.LogBlock.listeners.WitherLogging;
import de.diddiz.LogBlock.listeners.*;
import de.diddiz.util.MySQLConnectionPool;
import de.diddiz.worldedit.WorldEditLoggingHook;
import org.bukkit.ChatColor;
@@ -48,269 +27,301 @@ import static de.diddiz.LogBlock.config.Config.*;
import static de.diddiz.util.MaterialName.materialName;
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 Updater updater = null;
private Timer timer = null;
private boolean errorAtLoading = false, noDb = false, connected = true;
public class LogBlock extends JavaPlugin {
private static LogBlock logblock = null;
private MySQLConnectionPool pool;
private Consumer consumer = null;
private CommandsHandler commandsHandler;
private Updater updater = null;
private Timer timer = null;
private boolean errorAtLoading = false, noDb = false, connected = true;
public static LogBlock getInstance() {
return logblock;
}
public static LogBlock getInstance() {
return logblock;
}
public Consumer getConsumer() {
return consumer;
}
public Consumer getConsumer() {
return consumer;
}
public CommandsHandler getCommandsHandler() {
return commandsHandler;
}
public CommandsHandler getCommandsHandler() {
return commandsHandler;
}
Updater getUpdater() {
return updater;
}
Updater getUpdater() {
return updater;
}
@Override
public void onLoad() {
logblock = this;
try {
updater = new Updater(this);
Config.load(this);
getLogger().info("Connecting to " + user + "@" + url + "...");
pool = new MySQLConnectionPool(url, user, password);
final Connection conn = getConnection();
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.executeQuery("SET NAMES utf8mb4;");
}
conn.close();
if (updater.update())
load(this);
updater.checkTables();
} catch (final NullPointerException ex) {
getLogger().log(Level.SEVERE, "Error while loading: ", ex);
} catch (final Exception ex) {
getLogger().severe("Error while loading: " + ex.getMessage());
errorAtLoading = true;
return;
}
consumer = new Consumer(this);
}
@Override
public void onLoad() {
logblock = this;
try {
updater = new Updater(this);
Config.load(this);
getLogger().info("Connecting to " + user + "@" + url + "...");
pool = new MySQLConnectionPool(url, user, password);
final Connection conn = getConnection();
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.executeQuery("SET NAMES utf8mb4;");
}
conn.close();
if (updater.update()) {
load(this);
}
updater.checkTables();
} catch (final NullPointerException ex) {
getLogger().log(Level.SEVERE, "Error while loading: ", ex);
} catch (final Exception ex) {
getLogger().severe("Error while loading: " + ex.getMessage());
errorAtLoading = true;
return;
}
consumer = new Consumer(this);
}
@Override
public void onEnable() {
materialName(0); // Force static code to run
final PluginManager pm = getPluginManager();
if (errorAtLoading) {
pm.disablePlugin(this);
return;
}
if (noDb)
return;
if (pm.getPlugin("WorldEdit") != null) {
if(Integer.parseInt(pm.getPlugin("WorldEdit").getDescription().getVersion().substring(0, 1)) > 5) {
new WorldEditLoggingHook(this).hook();
} else {
getLogger().warning("Failed to hook into WorldEdit. Your WorldEdit version seems to be outdated, please make sure WorldEdit is at least version 6.");
}
}
commandsHandler = new CommandsHandler(this);
getCommand("lb").setExecutor(commandsHandler);
if (enableAutoClearLog && autoClearLogDelay > 0)
getServer().getScheduler().runTaskTimerAsynchronously(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
getServer().getScheduler().runTaskAsynchronously(this, new DumpedLogImporter(this));
registerEvents();
if (useBukkitScheduler) {
if (getServer().getScheduler().runTaskTimerAsynchronously(this, consumer, delayBetweenRuns < 20 ? 20 : delayBetweenRuns, delayBetweenRuns).getTaskId() > 0)
getLogger().info("Scheduled consumer with bukkit scheduler.");
else {
getLogger().warning("Failed to schedule consumer with bukkit scheduler. Now trying schedule with timer.");
timer = new Timer();
timer.schedule(consumer, delayBetweenRuns < 20 ? 1000 : delayBetweenRuns * 50, delayBetweenRuns * 50);
}
} else {
timer = new Timer();
timer.schedule(consumer, delayBetweenRuns < 20 ? 1000 : delayBetweenRuns * 50, delayBetweenRuns * 50);
getLogger().info("Scheduled consumer with timer.");
}
getServer().getScheduler().runTaskAsynchronously(this, new Updater.PlayerCountChecker(this));
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);
}
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException ex) {
getLogger().info("Could not start metrics: " + ex.getMessage());
}
}
@Override
public void onEnable() {
materialName(0); // Force static code to run
final PluginManager pm = getPluginManager();
if (errorAtLoading) {
pm.disablePlugin(this);
return;
}
if (noDb) {
return;
}
if (pm.getPlugin("WorldEdit") != null) {
if (Integer.parseInt(pm.getPlugin("WorldEdit").getDescription().getVersion().substring(0, 1)) > 5) {
new WorldEditLoggingHook(this).hook();
} else {
getLogger().warning("Failed to hook into WorldEdit. Your WorldEdit version seems to be outdated, please make sure WorldEdit is at least version 6.");
}
}
commandsHandler = new CommandsHandler(this);
getCommand("lb").setExecutor(commandsHandler);
if (enableAutoClearLog && autoClearLogDelay > 0) {
getServer().getScheduler().runTaskTimerAsynchronously(this, new AutoClearLog(this), 6000, autoClearLogDelay * 60 * 20);
}
getServer().getScheduler().runTaskAsynchronously(this, new DumpedLogImporter(this));
registerEvents();
if (useBukkitScheduler) {
if (getServer().getScheduler().runTaskTimerAsynchronously(this, consumer, delayBetweenRuns < 20 ? 20 : delayBetweenRuns, delayBetweenRuns).getTaskId() > 0) {
getLogger().info("Scheduled consumer with bukkit scheduler.");
} else {
getLogger().warning("Failed to schedule consumer with bukkit scheduler. Now trying schedule with timer.");
timer = new Timer();
timer.schedule(consumer, delayBetweenRuns < 20 ? 1000 : delayBetweenRuns * 50, delayBetweenRuns * 50);
}
} else {
timer = new Timer();
timer.schedule(consumer, delayBetweenRuns < 20 ? 1000 : delayBetweenRuns * 50, delayBetweenRuns * 50);
getLogger().info("Scheduled consumer with timer.");
}
getServer().getScheduler().runTaskAsynchronously(this, new Updater.PlayerCountChecker(this));
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);
}
}
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException ex) {
getLogger().info("Could not start metrics: " + ex.getMessage());
}
}
private void registerEvents() {
final PluginManager pm = getPluginManager();
pm.registerEvents(new ToolListener(this), this);
pm.registerEvents(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.BLOCKPLACE) || 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.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.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))
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) || isLogging(Logging.BONEMEALSTRUCTUREGROW))
pm.registerEvents(new StructureGrowLogging(this), this);
if (isLogging(Logging.GRASSGROWTH) || isLogging(Logging.MYCELIUMSPREAD) || isLogging(Logging.VINEGROWTH) || isLogging(Logging.MUSHROOMSPREAD))
pm.registerEvents(new BlockSpreadLogging(this), this);
if (isLogging(Logging.LOCKEDCHESTDECAY))
pm.registerEvents(new LockedChestDecayLogging(this), this);
}
private void registerEvents() {
final PluginManager pm = getPluginManager();
pm.registerEvents(new ToolListener(this), this);
pm.registerEvents(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.BLOCKPLACE) || 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.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.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)) {
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) || isLogging(Logging.BONEMEALSTRUCTUREGROW)) {
pm.registerEvents(new StructureGrowLogging(this), this);
}
if (isLogging(Logging.GRASSGROWTH) || isLogging(Logging.MYCELIUMSPREAD) || isLogging(Logging.VINEGROWTH) || isLogging(Logging.MUSHROOMSPREAD)) {
pm.registerEvents(new BlockSpreadLogging(this), this);
}
if (isLogging(Logging.LOCKEDCHESTDECAY)) {
pm.registerEvents(new LockedChestDecayLogging(this), this);
}
}
@Override
public void onDisable() {
if (timer != null)
timer.cancel();
getServer().getScheduler().cancelTasks(this);
if (consumer != null) {
if (logPlayerInfo && getServer().getOnlinePlayers() != null)
for (final Player player : getServer().getOnlinePlayers())
consumer.queueLeave(player);
getLogger().info("Waiting for consumer ...");
consumer.run();
if (consumer.getQueueSize() > 0) {
int tries = 9;
while (consumer.getQueueSize() > 0) {
getLogger().info("Remaining queue size: " + consumer.getQueueSize());
if (tries > 0)
getLogger().info("Remaining tries: " + tries);
else {
getLogger().info("Unable to save queue to database. 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.");
break;
}
}
consumer.run();
tries--;
}
}
}
if (pool != null)
pool.close();
}
@Override
public void onDisable() {
if (timer != null) {
timer.cancel();
}
getServer().getScheduler().cancelTasks(this);
if (consumer != null) {
if (logPlayerInfo && getServer().getOnlinePlayers() != null) {
for (final Player player : getServer().getOnlinePlayers()) {
consumer.queueLeave(player);
}
}
getLogger().info("Waiting for consumer ...");
consumer.run();
if (consumer.getQueueSize() > 0) {
int tries = 9;
while (consumer.getQueueSize() > 0) {
getLogger().info("Remaining queue size: " + consumer.getQueueSize());
if (tries > 0) {
getLogger().info("Remaining tries: " + tries);
} else {
getLogger().info("Unable to save queue to database. 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.");
break;
}
}
consumer.run();
tries--;
}
}
}
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;
}
@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 boolean hasPermission(CommandSender sender, String permission) {
return sender.hasPermission(permission);
}
public Connection getConnection() {
try {
final Connection conn = pool.getConnection();
if (!connected) {
getLogger().info("MySQL connection rebuild");
connected = true;
}
return conn;
} catch (final Exception ex) {
if (connected) {
getLogger().log(Level.SEVERE, "Error while fetching connection: ", ex);
connected = false;
} else
getLogger().severe("MySQL connection lost");
return null;
}
}
public Connection getConnection() {
try {
final Connection conn = pool.getConnection();
if (!connected) {
getLogger().info("MySQL connection rebuild");
connected = true;
}
return conn;
} catch (final Exception ex) {
if (connected) {
getLogger().log(Level.SEVERE, "Error while fetching connection: ", ex);
connected = false;
} else {
getLogger().severe("MySQL connection lost");
}
return null;
}
}
/**
* @param params
* QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
*/
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<BlockChange>();
while (rs.next())
blockchanges.add(new BlockChange(rs, params));
return blockchanges;
} finally {
if (state != null)
state.close();
conn.close();
}
}
/**
* @param params QueryParams that contains the needed columns (all other will be filled with default values) and the params. World is required.
*/
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<BlockChange>();
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 {
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();
}
}
public int getCount(QueryParams params) throws SQLException {
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();
}
}
}

View File

@@ -1,28 +1,27 @@
package de.diddiz.LogBlock;
public enum Logging
{
BLOCKPLACE(true), BLOCKBREAK(true), SIGNTEXT, TNTEXPLOSION(true), CREEPEREXPLOSION(true),
GHASTFIREBALLEXPLOSION(true), ENDERDRAGON(true), MISCEXPLOSION, FIRE(true), LEAVESDECAY,
LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT,
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, COMPARATORINTERACT,
PRESUREPLATEINTERACT, TRIPWIREINTERACT, CREATURECROPTRAMPLE, CROPTRAMPLE,
NATURALSTRUCTUREGROW, GRASSGROWTH, MYCELIUMSPREAD, VINEGROWTH, MUSHROOMSPREAD,
WITHER(true), WITHER_SKULL(true), BONEMEALSTRUCTUREGROW,
WORLDEDIT, TNTMINECARTEXPLOSION(true), LOCKEDCHESTDECAY;
public enum Logging {
BLOCKPLACE(true), BLOCKBREAK(true), SIGNTEXT, TNTEXPLOSION(true), CREEPEREXPLOSION(true),
GHASTFIREBALLEXPLOSION(true), ENDERDRAGON(true), MISCEXPLOSION, FIRE(true), LEAVESDECAY,
LAVAFLOW, WATERFLOW, CHESTACCESS, KILL, CHAT, SNOWFORM, SNOWFADE, DOORINTERACT,
SWITCHINTERACT, CAKEEAT, ENDERMEN, NOTEBLOCKINTERACT, DIODEINTERACT, COMPARATORINTERACT,
PRESUREPLATEINTERACT, TRIPWIREINTERACT, CREATURECROPTRAMPLE, CROPTRAMPLE,
NATURALSTRUCTUREGROW, GRASSGROWTH, MYCELIUMSPREAD, VINEGROWTH, MUSHROOMSPREAD,
WITHER(true), WITHER_SKULL(true), BONEMEALSTRUCTUREGROW,
WORLDEDIT, TNTMINECARTEXPLOSION(true), LOCKEDCHESTDECAY;
public static final int length = Logging.values().length;
private final boolean defaultEnabled;
public static final int length = Logging.values().length;
private final boolean defaultEnabled;
private Logging() {
this(false);
}
private Logging() {
this(false);
}
private Logging(boolean defaultEnabled) {
this.defaultEnabled = defaultEnabled;
}
private Logging(boolean defaultEnabled) {
this.defaultEnabled = defaultEnabled;
}
public boolean isDefaultEnabled() {
return defaultEnabled;
}
public boolean isDefaultEnabled() {
return defaultEnabled;
}
}

View File

@@ -2,9 +2,8 @@ package de.diddiz.LogBlock;
import org.bukkit.Location;
public interface LookupCacheElement
{
public Location getLocation();
public interface LookupCacheElement {
public Location getLocation();
public String getMessage();
public String getMessage();
}

View File

@@ -1,30 +1,34 @@
package de.diddiz.LogBlock;
import java.sql.ResultSet;
import java.sql.SQLException;
import de.diddiz.LogBlock.QueryParams.BlockChangeType;
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
public class LookupCacheElementFactory
{
private final QueryParams params;
private final float spaceFactor;
import java.sql.ResultSet;
import java.sql.SQLException;
public LookupCacheElementFactory(QueryParams params, float spaceFactor) {
this.params = params;
this.spaceFactor = spaceFactor;
}
public class LookupCacheElementFactory {
private final QueryParams params;
private final float 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.sum == SummarizationMode.NONE)
return new BlockChange(rs, params);
return new SummedBlockChanges(rs, params, 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.sum == SummarizationMode.NONE) {
return new BlockChange(rs, params);
}
return new SummedBlockChanges(rs, params, spaceFactor);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,46 +1,49 @@
package de.diddiz.LogBlock;
import static de.diddiz.LogBlock.config.Config.toolsByType;
import static org.bukkit.Bukkit.getServer;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Session
{
private static final Map<String, Session> sessions = new HashMap<String, Session>();
public QueryParams lastQuery = null;
public LookupCacheElement[] lookupCache = null;
public int page = 1;
public Map<Tool, ToolData> toolData;
import java.util.HashMap;
import java.util.Map;
private Session(Player player) {
toolData = new HashMap<Tool, ToolData>();
final LogBlock logblock = LogBlock.getInstance();
if (player != null)
for (final Tool tool : toolsByType.values())
toolData.put(tool, new ToolData(tool, logblock, player));
}
import static de.diddiz.LogBlock.config.Config.toolsByType;
import static org.bukkit.Bukkit.getServer;
public static boolean hasSession(CommandSender sender) {
return sessions.containsKey(sender.getName().toLowerCase());
}
public class Session {
private static final Map<String, Session> sessions = new HashMap<String, Session>();
public QueryParams lastQuery = null;
public LookupCacheElement[] lookupCache = null;
public int page = 1;
public Map<Tool, ToolData> toolData;
public static boolean hasSession(String playerName) {
return sessions.containsKey(playerName.toLowerCase());
}
private Session(Player player) {
toolData = new HashMap<Tool, ToolData>();
final LogBlock logblock = LogBlock.getInstance();
if (player != null) {
for (final Tool tool : toolsByType.values()) {
toolData.put(tool, new ToolData(tool, logblock, player));
}
}
}
public static Session getSession(CommandSender sender) {
return getSession(sender.getName());
}
public static boolean hasSession(CommandSender sender) {
return sessions.containsKey(sender.getName().toLowerCase());
}
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;
}
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;
}
}

View File

@@ -1,35 +1,36 @@
package de.diddiz.LogBlock;
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
import org.bukkit.Location;
import java.sql.ResultSet;
import java.sql.SQLException;
import static de.diddiz.util.MaterialName.materialName;
import static de.diddiz.util.Utils.spaces;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.Location;
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
public class SummedBlockChanges implements LookupCacheElement
{
private final String group;
private final int created, destroyed;
private final float spaceFactor;
private final Actor actor;
public class SummedBlockChanges implements LookupCacheElement {
private final String group;
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;
group = actor == null ? materialName(rs.getInt("type")) : actor.getName();
created = rs.getInt("created");
destroyed = rs.getInt("destroyed");
this.spaceFactor = spaceFactor;
}
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;
group = actor == null ? materialName(rs.getInt("type")) : actor.getName();
created = rs.getInt("created");
destroyed = rs.getInt("destroyed");
this.spaceFactor = spaceFactor;
}
@Override
public Location getLocation() {
return null;
}
@Override
public Location getLocation() {
return null;
}
@Override
public String getMessage() {
return created + spaces((int)((10 - String.valueOf(created).length()) / spaceFactor)) + destroyed + spaces((int)((10 - String.valueOf(destroyed).length()) / spaceFactor)) + group;
}
@Override
public String getMessage() {
return created + spaces((int) ((10 - String.valueOf(created).length()) / spaceFactor)) + destroyed + spaces((int) ((10 - String.valueOf(destroyed).length()) / spaceFactor)) + group;
}
}

View File

@@ -1,30 +1,31 @@
package de.diddiz.LogBlock;
import static de.diddiz.util.Utils.spaces;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.Location;
public class SummedKills implements LookupCacheElement
{
private final Actor player;
private final int kills, killed;
private final float spaceFactor;
import java.sql.ResultSet;
import java.sql.SQLException;
public SummedKills(ResultSet rs, QueryParams p, float spaceFactor) throws SQLException {
player = new Actor(rs);
kills = rs.getInt("kills");
killed = rs.getInt("killed");
this.spaceFactor = spaceFactor;
}
import static de.diddiz.util.Utils.spaces;
@Override
public Location getLocation() {
return null;
}
public class SummedKills implements LookupCacheElement {
private final Actor player;
private final int kills, killed;
private final float spaceFactor;
@Override
public String getMessage() {
return kills + spaces((int)((6 - String.valueOf(kills).length()) / spaceFactor)) + killed + spaces((int)((7 - String.valueOf(killed).length()) / spaceFactor)) + player.getName();
}
public SummedKills(ResultSet rs, QueryParams p, float spaceFactor) throws SQLException {
player = new Actor(rs);
kills = rs.getInt("kills");
killed = rs.getInt("killed");
this.spaceFactor = spaceFactor;
}
@Override
public Location getLocation() {
return null;
}
@Override
public String getMessage() {
return kills + spaces((int) ((6 - String.valueOf(kills).length()) / spaceFactor)) + killed + spaces((int) ((7 - String.valueOf(killed).length()) / spaceFactor)) + player.getName();
}
}

View File

@@ -1,30 +1,30 @@
package de.diddiz.LogBlock;
import java.util.List;
import org.bukkit.permissions.PermissionDefault;
public class Tool
{
public final String name;
public final List<String> aliases;
public final ToolBehavior leftClickBehavior, rightClickBehavior;
public final boolean defaultEnabled;
public final int item;
public final boolean canDrop;
public final QueryParams params;
public final ToolMode mode;
public final PermissionDefault permissionDefault;
import java.util.List;
public Tool(String name, List<String> aliases, ToolBehavior leftClickBehavior, ToolBehavior rightClickBehavior, boolean defaultEnabled, int item, boolean canDrop, QueryParams params, ToolMode mode, PermissionDefault permissionDefault) {
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;
}
public class Tool {
public final String name;
public final List<String> aliases;
public final ToolBehavior leftClickBehavior, rightClickBehavior;
public final boolean defaultEnabled;
public final int item;
public final boolean canDrop;
public final QueryParams params;
public final ToolMode mode;
public final PermissionDefault permissionDefault;
public Tool(String name, List<String> aliases, ToolBehavior leftClickBehavior, ToolBehavior rightClickBehavior, boolean defaultEnabled, int item, boolean canDrop, QueryParams params, ToolMode mode, PermissionDefault permissionDefault) {
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;
}
}

View File

@@ -1,6 +1,5 @@
package de.diddiz.LogBlock;
public enum ToolBehavior
{
TOOL, BLOCK, NONE
public enum ToolBehavior {
TOOL, BLOCK, NONE
}

View File

@@ -2,15 +2,14 @@ package de.diddiz.LogBlock;
import org.bukkit.entity.Player;
public class ToolData
{
public boolean enabled;
public QueryParams params;
public ToolMode mode;
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;
}
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;
}
}

View File

@@ -1,15 +1,14 @@
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;
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;
}
private ToolMode(String permission) {
this.permission = permission;
}
public String getPermission() {
return permission;
}
public String getPermission() {
return permission;
}
}

View File

@@ -2,446 +2,464 @@ package de.diddiz.LogBlock;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.UUIDFetcher;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.*;
import java.util.logging.Level;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import static de.diddiz.LogBlock.config.Config.getLoggedWorlds;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import de.diddiz.util.UUIDFetcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
import static org.bukkit.Bukkit.getLogger;
class Updater
{
private final LogBlock logblock;
final int UUID_CONVERT_BATCH_SIZE = 100;
class Updater {
private final LogBlock logblock;
final int UUID_CONVERT_BATCH_SIZE = 100;
Updater(LogBlock logblock) {
this.logblock = logblock;
}
Updater(LogBlock logblock) {
this.logblock = logblock;
}
boolean update() {
final ConfigurationSection config = logblock.getConfig();
if (config.getString("version").compareTo(logblock.getDescription().getVersion()) >= 0)
return false;
if (config.getString("version").compareTo("1.27") < 0) {
getLogger().info("Updating tables to 1.27 ...");
if (isLogging(Logging.CHAT)) {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-chat` ENGINE = MyISAM, ADD FULLTEXT message (message)");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
config.set("version", "1.27");
}
if (config.getString("version").compareTo("1.30") < 0) {
getLogger().info("Updating config to 1.30 ...");
for (final String tool : config.getConfigurationSection("tools").getKeys(false))
if (config.get("tools." + tool + ".permissionDefault") == null)
config.set("tools." + tool + ".permissionDefault", "OP");
config.set("version", "1.30");
}
if (config.getString("version").compareTo("1.31") < 0) {
getLogger().info("Updating tables to 1.31 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD COLUMN lastlogin DATETIME NOT NULL, ADD COLUMN onlinetime TIME NOT NULL, ADD COLUMN ip VARCHAR(255) NOT NULL");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.31");
}
if (config.getString("version").compareTo("1.32") < 0) {
getLogger().info("Updating tables to 1.32 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD COLUMN firstlogin DATETIME NOT NULL AFTER playername");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.32");
}
if (config.getString("version").compareTo("1.40") < 0) {
getLogger().info("Updating config to 1.40 ...");
config.set("clearlog.keepLogDays", null);
config.set("version", "1.40");
}
if (config.getString("version").compareTo("1.42") < 0) {
getLogger().info("Updating config to 1.42 ...");
for (final String world : config.getStringList("loggedWorlds")) {
final File file = new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml");
final YamlConfiguration wcfg = YamlConfiguration.loadConfiguration(file);
if (wcfg.contains("logBlockCreations"))
wcfg.set("logging.BLOCKPLACE", wcfg.getBoolean("logBlockCreations"));
if (wcfg.contains("logBlockDestroyings"))
wcfg.set("logging.BLOCKBREAK", wcfg.getBoolean("logBlockDestroyings"));
if (wcfg.contains("logSignTexts"))
wcfg.set("logging.SIGNTEXT", wcfg.getBoolean("logSignTexts"));
if (wcfg.contains("logFire"))
wcfg.set("logging.FIRE", wcfg.getBoolean("logFire"));
if (wcfg.contains("logLeavesDecay"))
wcfg.set("logging.LEAVESDECAY", wcfg.getBoolean("logLeavesDecay"));
if (wcfg.contains("logLavaFlow"))
wcfg.set("logging.LAVAFLOW", wcfg.getBoolean("logLavaFlow"));
if (wcfg.contains("logWaterFlow"))
wcfg.set("logging.WATERFLOW", wcfg.getBoolean("logWaterFlow"));
if (wcfg.contains("logChestAccess"))
wcfg.set("logging.CHESTACCESS", wcfg.getBoolean("logChestAccess"));
if (wcfg.contains("logButtonsAndLevers"))
wcfg.set("logging.SWITCHINTERACT", wcfg.getBoolean("logButtonsAndLevers"));
if (wcfg.contains("logKills"))
wcfg.set("logging.KILL", wcfg.getBoolean("logKills"));
if (wcfg.contains("logChat"))
wcfg.set("logging.CHAT", wcfg.getBoolean("logChat"));
if (wcfg.contains("logSnowForm"))
wcfg.set("logging.SNOWFORM", wcfg.getBoolean("logSnowForm"));
if (wcfg.contains("logSnowFade"))
wcfg.set("logging.SNOWFADE", wcfg.getBoolean("logSnowFade"));
if (wcfg.contains("logDoors"))
wcfg.set("logging.DOORINTERACT", wcfg.getBoolean("logDoors"));
if (wcfg.contains("logCakes"))
wcfg.set("logging.CAKEEAT", wcfg.getBoolean("logCakes"));
if (wcfg.contains("logEndermen"))
wcfg.set("logging.ENDERMEN", wcfg.getBoolean("logEndermen"));
if (wcfg.contains("logExplosions")) {
final boolean logExplosions = wcfg.getBoolean("logExplosions");
wcfg.set("logging.TNTEXPLOSION", logExplosions);
wcfg.set("logging.MISCEXPLOSION", logExplosions);
wcfg.set("logging.CREEPEREXPLOSION", logExplosions);
wcfg.set("logging.GHASTFIREBALLEXPLOSION", logExplosions);
}
wcfg.set("logBlockCreations", null);
wcfg.set("logBlockDestroyings", null);
wcfg.set("logSignTexts", null);
wcfg.set("logExplosions", null);
wcfg.set("logFire", null);
wcfg.set("logLeavesDecay", null);
wcfg.set("logLavaFlow", null);
wcfg.set("logWaterFlow", null);
wcfg.set("logChestAccess", null);
wcfg.set("logButtonsAndLevers", null);
wcfg.set("logKills", null);
wcfg.set("logChat", null);
wcfg.set("logSnowForm", null);
wcfg.set("logSnowFade", null);
wcfg.set("logDoors", null);
wcfg.set("logCakes", null);
wcfg.set("logEndermen", null);
try {
wcfg.save(file);
} catch (final IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
}
}
config.set("clearlog.keepLogDays", null);
config.set("version", "1.42");
}
if (config.getString("version").compareTo("1.51") < 0) {
getLogger().info("Updating tables to 1.51 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds())
if (wcfg.isLogging(Logging.KILL))
st.execute("ALTER TABLE `" + wcfg.table + "-kills` ADD (x MEDIUMINT NOT NULL DEFAULT 0, y SMALLINT NOT NULL DEFAULT 0, z MEDIUMINT NOT NULL DEFAULT 0)");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.51");
}
if (config.getString("version").compareTo("1.52") < 0) {
getLogger().info("Updating tables to 1.52 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
final ResultSet rs = st.executeQuery("SHOW COLUMNS FROM `lb-players` WHERE field = 'onlinetime'");
if (rs.next() && rs.getString("Type").equalsIgnoreCase("time")) {
st.execute("ALTER TABLE `lb-players` ADD onlinetime2 INT UNSIGNED NOT NULL");
st.execute("UPDATE `lb-players` SET onlinetime2 = HOUR(onlinetime) * 3600 + MINUTE(onlinetime) * 60 + SECOND(onlinetime)");
st.execute("ALTER TABLE `lb-players` DROP onlinetime");
st.execute("ALTER TABLE `lb-players` CHANGE onlinetime2 onlinetime INT UNSIGNED NOT NULL");
} else
getLogger().info("Column lb-players was already modified, skipping it.");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.52");
}
if (config.getString("version").compareTo("1.81") < 0) {
getLogger().info("Updating tables to 1.81 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.CHESTACCESS)) {
st.execute("ALTER TABLE `"+wcfg.table+"-chest` CHANGE itemdata itemdata SMALLINT NOT NULL");
getLogger().info("Table "+wcfg.table+"-chest modified");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.81");
}
if (config.getString("version").compareTo("1.90") < 0) {
getLogger().info("Updating tables to 1.9 ...");
getLogger().info("Importing UUIDs for large databases may take some time");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD `UUID` VARCHAR(36) NOT NULL");
} catch (final SQLException ex) {
// Error 1060 is MySQL error "column already exists". We want to continue with import if we get that error
if (ex.getErrorCode() != 1060) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
try {
String unimportedPrefix="noimport_";
ResultSet rs;
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
if (config.getBoolean("logging.logPlayerInfo")) {
// Start by assuming anything with no onlinetime is not a player
st.execute("UPDATE `lb-players` SET UUID = CONCAT ('log_',playername) WHERE onlinetime=0 AND LENGTH(UUID) = 0");
} else {
// If we can't assume that, we must assume anything we can't look up is not a player
unimportedPrefix = "log_";
}
// Tell people how many are needing converted
rs = st.executeQuery("SELECT COUNT(playername) FROM `lb-players` WHERE LENGTH(UUID)=0");
rs.next();
String total = Integer.toString(rs.getInt(1));
getLogger().info(total + " players to convert");
int done = 0;
conn.setAutoCommit(false);
Map <String,Integer> players = new HashMap<String,Integer>();
List <String> names = new ArrayList<String>(UUID_CONVERT_BATCH_SIZE);
Map <String,UUID> response;
rs = st.executeQuery("SELECT playerid,playername FROM `lb-players` WHERE LENGTH(UUID)=0 LIMIT " + Integer.toString(UUID_CONVERT_BATCH_SIZE));
while (rs.next()) {
do {
players.put(rs.getString(2),rs.getInt(1));
names.add(rs.getString(2));
} while (rs.next());
if (names.size()>0) {
String theUUID;
response = UUIDFetcher.getUUIDs(names);
for (Map.Entry<String,Integer> entry : players.entrySet()) {
if (response.get(entry.getKey()) == null) {
theUUID = unimportedPrefix + entry.getKey();
getLogger().warning(entry.getKey() + " not found - giving UUID of " + theUUID);
} else {
theUUID = response.get(entry.getKey()).toString();
}
String thePID = entry.getValue().toString();
st.execute("UPDATE `lb-players` SET UUID = '" + theUUID + "' WHERE playerid = " + thePID);
done++;
}
conn.commit();
players.clear();
names.clear();
getLogger().info("Processed " + Integer.toString(done) + " out of " + total);
rs = st.executeQuery("SELECT playerid,playername FROM `lb-players` WHERE LENGTH(UUID)=0 LIMIT " + Integer.toString(UUID_CONVERT_BATCH_SIZE));
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "[UUID importer]", ex);
return false;
}
config.set("version", "1.90");
}
// Ensure charset for free-text fields is UTF-8, or UTF8-mb4 if possible
// As this may be an expensive operation and the database default may already be this, check on a table-by-table basis before converting
if (config.getString("version").compareTo("1.92") < 0) {
getLogger().info("Updating tables to 1.92 ...");
String charset = "utf8";
if ( Config.mb4) charset="utf8mb4";
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
if (isLogging(Logging.CHAT)) {
final ResultSet rs = st.executeQuery("SHOW FULL COLUMNS FROM `lb-chat` WHERE field = 'message'");
if (rs.next() && !rs.getString("Collation").substring(0,4).equalsIgnoreCase(charset)) {
st.execute("ALTER TABLE `lb-chat` CONVERT TO CHARSET " + charset);
getLogger().info("Table lb-chat modified");
} else {
getLogger().info("Table lb-chat already fine, skipping it");
}
}
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.SIGNTEXT)) {
final ResultSet rs = st.executeQuery("SHOW FULL COLUMNS FROM `"+wcfg.table+"-sign` WHERE field = 'signtext'");
if (rs.next() && !rs.getString("Collation").substring(0,4).equalsIgnoreCase(charset)) {
st.execute("ALTER TABLE `"+wcfg.table+"-sign` CONVERT TO CHARSET " + charset);
getLogger().info("Table "+wcfg.table+"-sign modified");
} else {
getLogger().info("Table "+wcfg.table+"-sign already fine, skipping it");
}
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.92");
}
if (config.getString("version").compareTo("1.94") < 0) {
getLogger().info("Updating tables to 1.94 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
// Need to wrap both these next two inside individual try/catch statements in case index does not exist
try {
st.execute("DROP INDEX UUID ON `lb-players`");
} catch (final SQLException ex) {
if (ex.getErrorCode() != 1091) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
try {
st.execute("DROP INDEX playername ON `lb-players`");
} catch (final SQLException ex) {
if (ex.getErrorCode() != 1091) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
st.execute("CREATE INDEX UUID ON `lb-players` (UUID);");
st.execute("CREATE INDEX playername ON `lb-players` (playername);");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.94");
}
boolean update() {
final ConfigurationSection config = logblock.getConfig();
if (config.getString("version").compareTo(logblock.getDescription().getVersion()) >= 0) {
return false;
}
if (config.getString("version").compareTo("1.27") < 0) {
getLogger().info("Updating tables to 1.27 ...");
if (isLogging(Logging.CHAT)) {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-chat` ENGINE = MyISAM, ADD FULLTEXT message (message)");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
config.set("version", "1.27");
}
if (config.getString("version").compareTo("1.30") < 0) {
getLogger().info("Updating config to 1.30 ...");
for (final String tool : config.getConfigurationSection("tools").getKeys(false)) {
if (config.get("tools." + tool + ".permissionDefault") == null) {
config.set("tools." + tool + ".permissionDefault", "OP");
}
}
config.set("version", "1.30");
}
if (config.getString("version").compareTo("1.31") < 0) {
getLogger().info("Updating tables to 1.31 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD COLUMN lastlogin DATETIME NOT NULL, ADD COLUMN onlinetime TIME NOT NULL, ADD COLUMN ip VARCHAR(255) NOT NULL");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.31");
}
if (config.getString("version").compareTo("1.32") < 0) {
getLogger().info("Updating tables to 1.32 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD COLUMN firstlogin DATETIME NOT NULL AFTER playername");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.32");
}
if (config.getString("version").compareTo("1.40") < 0) {
getLogger().info("Updating config to 1.40 ...");
config.set("clearlog.keepLogDays", null);
config.set("version", "1.40");
}
if (config.getString("version").compareTo("1.42") < 0) {
getLogger().info("Updating config to 1.42 ...");
for (final String world : config.getStringList("loggedWorlds")) {
final File file = new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml");
final YamlConfiguration wcfg = YamlConfiguration.loadConfiguration(file);
if (wcfg.contains("logBlockCreations")) {
wcfg.set("logging.BLOCKPLACE", wcfg.getBoolean("logBlockCreations"));
}
if (wcfg.contains("logBlockDestroyings")) {
wcfg.set("logging.BLOCKBREAK", wcfg.getBoolean("logBlockDestroyings"));
}
if (wcfg.contains("logSignTexts")) {
wcfg.set("logging.SIGNTEXT", wcfg.getBoolean("logSignTexts"));
}
if (wcfg.contains("logFire")) {
wcfg.set("logging.FIRE", wcfg.getBoolean("logFire"));
}
if (wcfg.contains("logLeavesDecay")) {
wcfg.set("logging.LEAVESDECAY", wcfg.getBoolean("logLeavesDecay"));
}
if (wcfg.contains("logLavaFlow")) {
wcfg.set("logging.LAVAFLOW", wcfg.getBoolean("logLavaFlow"));
}
if (wcfg.contains("logWaterFlow")) {
wcfg.set("logging.WATERFLOW", wcfg.getBoolean("logWaterFlow"));
}
if (wcfg.contains("logChestAccess")) {
wcfg.set("logging.CHESTACCESS", wcfg.getBoolean("logChestAccess"));
}
if (wcfg.contains("logButtonsAndLevers")) {
wcfg.set("logging.SWITCHINTERACT", wcfg.getBoolean("logButtonsAndLevers"));
}
if (wcfg.contains("logKills")) {
wcfg.set("logging.KILL", wcfg.getBoolean("logKills"));
}
if (wcfg.contains("logChat")) {
wcfg.set("logging.CHAT", wcfg.getBoolean("logChat"));
}
if (wcfg.contains("logSnowForm")) {
wcfg.set("logging.SNOWFORM", wcfg.getBoolean("logSnowForm"));
}
if (wcfg.contains("logSnowFade")) {
wcfg.set("logging.SNOWFADE", wcfg.getBoolean("logSnowFade"));
}
if (wcfg.contains("logDoors")) {
wcfg.set("logging.DOORINTERACT", wcfg.getBoolean("logDoors"));
}
if (wcfg.contains("logCakes")) {
wcfg.set("logging.CAKEEAT", wcfg.getBoolean("logCakes"));
}
if (wcfg.contains("logEndermen")) {
wcfg.set("logging.ENDERMEN", wcfg.getBoolean("logEndermen"));
}
if (wcfg.contains("logExplosions")) {
final boolean logExplosions = wcfg.getBoolean("logExplosions");
wcfg.set("logging.TNTEXPLOSION", logExplosions);
wcfg.set("logging.MISCEXPLOSION", logExplosions);
wcfg.set("logging.CREEPEREXPLOSION", logExplosions);
wcfg.set("logging.GHASTFIREBALLEXPLOSION", logExplosions);
}
wcfg.set("logBlockCreations", null);
wcfg.set("logBlockDestroyings", null);
wcfg.set("logSignTexts", null);
wcfg.set("logExplosions", null);
wcfg.set("logFire", null);
wcfg.set("logLeavesDecay", null);
wcfg.set("logLavaFlow", null);
wcfg.set("logWaterFlow", null);
wcfg.set("logChestAccess", null);
wcfg.set("logButtonsAndLevers", null);
wcfg.set("logKills", null);
wcfg.set("logChat", null);
wcfg.set("logSnowForm", null);
wcfg.set("logSnowFade", null);
wcfg.set("logDoors", null);
wcfg.set("logCakes", null);
wcfg.set("logEndermen", null);
try {
wcfg.save(file);
} catch (final IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
}
}
config.set("clearlog.keepLogDays", null);
config.set("version", "1.42");
}
if (config.getString("version").compareTo("1.51") < 0) {
getLogger().info("Updating tables to 1.51 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.KILL)) {
st.execute("ALTER TABLE `" + wcfg.table + "-kills` ADD (x MEDIUMINT NOT NULL DEFAULT 0, y SMALLINT NOT NULL DEFAULT 0, z MEDIUMINT NOT NULL DEFAULT 0)");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.51");
}
if (config.getString("version").compareTo("1.52") < 0) {
getLogger().info("Updating tables to 1.52 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
final ResultSet rs = st.executeQuery("SHOW COLUMNS FROM `lb-players` WHERE field = 'onlinetime'");
if (rs.next() && rs.getString("Type").equalsIgnoreCase("time")) {
st.execute("ALTER TABLE `lb-players` ADD onlinetime2 INT UNSIGNED NOT NULL");
st.execute("UPDATE `lb-players` SET onlinetime2 = HOUR(onlinetime) * 3600 + MINUTE(onlinetime) * 60 + SECOND(onlinetime)");
st.execute("ALTER TABLE `lb-players` DROP onlinetime");
st.execute("ALTER TABLE `lb-players` CHANGE onlinetime2 onlinetime INT UNSIGNED NOT NULL");
} else {
getLogger().info("Column lb-players was already modified, skipping it.");
}
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.52");
}
if (config.getString("version").compareTo("1.81") < 0) {
getLogger().info("Updating tables to 1.81 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.CHESTACCESS)) {
st.execute("ALTER TABLE `" + wcfg.table + "-chest` CHANGE itemdata itemdata SMALLINT NOT NULL");
getLogger().info("Table " + wcfg.table + "-chest modified");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.81");
}
logblock.saveConfig();
return true;
}
if (config.getString("version").compareTo("1.90") < 0) {
getLogger().info("Updating tables to 1.9 ...");
getLogger().info("Importing UUIDs for large databases may take some time");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD `UUID` VARCHAR(36) NOT NULL");
} catch (final SQLException ex) {
// Error 1060 is MySQL error "column already exists". We want to continue with import if we get that error
if (ex.getErrorCode() != 1060) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
try {
String unimportedPrefix = "noimport_";
ResultSet rs;
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
if (config.getBoolean("logging.logPlayerInfo")) {
// Start by assuming anything with no onlinetime is not a player
st.execute("UPDATE `lb-players` SET UUID = CONCAT ('log_',playername) WHERE onlinetime=0 AND LENGTH(UUID) = 0");
} else {
// If we can't assume that, we must assume anything we can't look up is not a player
unimportedPrefix = "log_";
}
// Tell people how many are needing converted
rs = st.executeQuery("SELECT COUNT(playername) FROM `lb-players` WHERE LENGTH(UUID)=0");
rs.next();
String total = Integer.toString(rs.getInt(1));
getLogger().info(total + " players to convert");
int done = 0;
void checkTables() throws SQLException {
final Connection conn = logblock.getConnection();
if (conn == null)
throw new SQLException("No connection");
final Statement state = conn.createStatement();
final DatabaseMetaData dbm = conn.getMetaData();
conn.setAutoCommit(true);
createTable(dbm, state, "lb-players", "(playerid INT UNSIGNED NOT NULL AUTO_INCREMENT, UUID varchar(36) NOT NULL, playername varchar(32) NOT NULL, firstlogin DATETIME NOT NULL, lastlogin DATETIME NOT NULL, onlinetime INT UNSIGNED NOT NULL, ip varchar(255) NOT NULL, PRIMARY KEY (playerid), INDEX (UUID), INDEX (playername))");
// Players table must not be empty or inserts won't work - bug #492
final ResultSet rs = state.executeQuery("SELECT NULL FROM `lb-players` LIMIT 1;");
if (!rs.next())
state.execute("INSERT IGNORE INTO `lb-players` (UUID,playername) VALUES ('log_dummy_record','dummy_record')");
if (isLogging(Logging.CHAT))
createTable(dbm, state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, message VARCHAR(255) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid), FULLTEXT message (message)) ENGINE=MyISAM DEFAULT CHARSET utf8");
for (final WorldConfig wcfg : getLoggedWorlds()) {
createTable(dbm, state, wcfg.table, "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, replaced TINYINT UNSIGNED NOT NULL, type TINYINT UNSIGNED NOT NULL, data TINYINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT UNSIGNED NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))");
createTable(dbm, state, wcfg.table + "-sign", "(id INT UNSIGNED NOT NULL, signtext VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET utf8");
createTable(dbm, state, wcfg.table + "-chest", "(id INT UNSIGNED NOT NULL, itemtype SMALLINT UNSIGNED NOT NULL, itemamount SMALLINT NOT NULL, itemdata SMALLINT NOT NULL, PRIMARY KEY (id))");
if (wcfg.isLogging(Logging.KILL))
createTable(dbm, state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer INT UNSIGNED, victim INT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id))");
}
state.close();
conn.close();
}
conn.setAutoCommit(false);
Map<String, Integer> players = new HashMap<String, Integer>();
List<String> names = new ArrayList<String>(UUID_CONVERT_BATCH_SIZE);
Map<String, UUID> response;
rs = st.executeQuery("SELECT playerid,playername FROM `lb-players` WHERE LENGTH(UUID)=0 LIMIT " + Integer.toString(UUID_CONVERT_BATCH_SIZE));
while (rs.next()) {
do {
players.put(rs.getString(2), rs.getInt(1));
names.add(rs.getString(2));
} while (rs.next());
if (names.size() > 0) {
String theUUID;
response = UUIDFetcher.getUUIDs(names);
for (Map.Entry<String, Integer> entry : players.entrySet()) {
if (response.get(entry.getKey()) == null) {
theUUID = unimportedPrefix + entry.getKey();
getLogger().warning(entry.getKey() + " not found - giving UUID of " + theUUID);
} else {
theUUID = response.get(entry.getKey()).toString();
}
String thePID = entry.getValue().toString();
st.execute("UPDATE `lb-players` SET UUID = '" + theUUID + "' WHERE playerid = " + thePID);
done++;
}
conn.commit();
players.clear();
names.clear();
getLogger().info("Processed " + Integer.toString(done) + " out of " + total);
rs = st.executeQuery("SELECT playerid,playername FROM `lb-players` WHERE LENGTH(UUID)=0 LIMIT " + Integer.toString(UUID_CONVERT_BATCH_SIZE));
}
}
st.close();
conn.close();
private static void createTable(DatabaseMetaData dbm, Statement state, String table, String query) throws SQLException {
if (!dbm.getTables(null, null, table, null).next()) {
getLogger().log(Level.INFO, "Creating table " + table + ".");
state.execute("CREATE TABLE `" + table + "` " + query);
if (!dbm.getTables(null, null, table, null).next())
throw new SQLException("Table " + table + " not found and failed to create");
}
}
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "[UUID importer]", ex);
return false;
}
config.set("version", "1.90");
}
// Ensure charset for free-text fields is UTF-8, or UTF8-mb4 if possible
// As this may be an expensive operation and the database default may already be this, check on a table-by-table basis before converting
if (config.getString("version").compareTo("1.92") < 0) {
getLogger().info("Updating tables to 1.92 ...");
String charset = "utf8";
if (Config.mb4) {
charset = "utf8mb4";
}
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
if (isLogging(Logging.CHAT)) {
final ResultSet rs = st.executeQuery("SHOW FULL COLUMNS FROM `lb-chat` WHERE field = 'message'");
if (rs.next() && !rs.getString("Collation").substring(0, 4).equalsIgnoreCase(charset)) {
st.execute("ALTER TABLE `lb-chat` CONVERT TO CHARSET " + charset);
getLogger().info("Table lb-chat modified");
} else {
getLogger().info("Table lb-chat already fine, skipping it");
}
}
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.SIGNTEXT)) {
final ResultSet rs = st.executeQuery("SHOW FULL COLUMNS FROM `" + wcfg.table + "-sign` WHERE field = 'signtext'");
if (rs.next() && !rs.getString("Collation").substring(0, 4).equalsIgnoreCase(charset)) {
st.execute("ALTER TABLE `" + wcfg.table + "-sign` CONVERT TO CHARSET " + charset);
getLogger().info("Table " + wcfg.table + "-sign modified");
} else {
getLogger().info("Table " + wcfg.table + "-sign already fine, skipping it");
}
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.92");
}
if (config.getString("version").compareTo("1.94") < 0) {
getLogger().info("Updating tables to 1.94 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
// Need to wrap both these next two inside individual try/catch statements in case index does not exist
try {
st.execute("DROP INDEX UUID ON `lb-players`");
} catch (final SQLException ex) {
if (ex.getErrorCode() != 1091) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
try {
st.execute("DROP INDEX playername ON `lb-players`");
} catch (final SQLException ex) {
if (ex.getErrorCode() != 1091) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
st.execute("CREATE INDEX UUID ON `lb-players` (UUID);");
st.execute("CREATE INDEX playername ON `lb-players` (playername);");
st.close();
conn.close();
} catch (final SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.94");
}
public static class PlayerCountChecker implements Runnable {
logblock.saveConfig();
return true;
}
private LogBlock logblock;
void checkTables() throws SQLException {
final Connection conn = logblock.getConnection();
if (conn == null) {
throw new SQLException("No connection");
}
final Statement state = conn.createStatement();
final DatabaseMetaData dbm = conn.getMetaData();
conn.setAutoCommit(true);
createTable(dbm, state, "lb-players", "(playerid INT UNSIGNED NOT NULL AUTO_INCREMENT, UUID varchar(36) NOT NULL, playername varchar(32) NOT NULL, firstlogin DATETIME NOT NULL, lastlogin DATETIME NOT NULL, onlinetime INT UNSIGNED NOT NULL, ip varchar(255) NOT NULL, PRIMARY KEY (playerid), INDEX (UUID), INDEX (playername))");
// Players table must not be empty or inserts won't work - bug #492
final ResultSet rs = state.executeQuery("SELECT NULL FROM `lb-players` LIMIT 1;");
if (!rs.next()) {
state.execute("INSERT IGNORE INTO `lb-players` (UUID,playername) VALUES ('log_dummy_record','dummy_record')");
}
if (isLogging(Logging.CHAT)) {
createTable(dbm, state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, message VARCHAR(255) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid), FULLTEXT message (message)) ENGINE=MyISAM DEFAULT CHARSET utf8");
}
for (final WorldConfig wcfg : getLoggedWorlds()) {
createTable(dbm, state, wcfg.table, "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, replaced TINYINT UNSIGNED NOT NULL, type TINYINT UNSIGNED NOT NULL, data TINYINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT UNSIGNED NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))");
createTable(dbm, state, wcfg.table + "-sign", "(id INT UNSIGNED NOT NULL, signtext VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET utf8");
createTable(dbm, state, wcfg.table + "-chest", "(id INT UNSIGNED NOT NULL, itemtype SMALLINT UNSIGNED NOT NULL, itemamount SMALLINT NOT NULL, itemdata SMALLINT NOT NULL, PRIMARY KEY (id))");
if (wcfg.isLogging(Logging.KILL)) {
createTable(dbm, state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer INT UNSIGNED, victim INT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id))");
}
}
state.close();
conn.close();
}
public PlayerCountChecker(LogBlock logblock) {
this.logblock = logblock;
}
private static void createTable(DatabaseMetaData dbm, Statement state, String table, String query) throws SQLException {
if (!dbm.getTables(null, null, table, null).next()) {
getLogger().log(Level.INFO, "Creating table " + table + ".");
state.execute("CREATE TABLE `" + table + "` " + query);
if (!dbm.getTables(null, null, table, null).next()) {
throw new SQLException("Table " + table + " not found and failed to create");
}
}
}
@Override
public void run() {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT auto_increment FROM information_schema.columns AS col join information_schema.tables AS tab ON (col.table_schema=tab.table_schema AND col.table_name=tab.table_name) WHERE col.table_name = 'lb-players' AND col.column_name = 'playerid' AND col.data_type = 'smallint' AND col.table_schema = DATABASE() AND auto_increment > 65000;");
if (rs.next()) {
for (int i = 0; i < 6; i++) {
logblock.getLogger().warning("Your server reached 65000 players. You should soon update your database table schema - see FAQ: https://github.com/LogBlock/LogBlock/wiki/FAQ#logblock-your-server-reached-65000-players-");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
}
}
}
public static class PlayerCountChecker implements Runnable {
private LogBlock logblock;
public PlayerCountChecker(LogBlock logblock) {
this.logblock = logblock;
}
@Override
public void run() {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT auto_increment FROM information_schema.columns AS col join information_schema.tables AS tab ON (col.table_schema=tab.table_schema AND col.table_name=tab.table_name) WHERE col.table_name = 'lb-players' AND col.column_name = 'playerid' AND col.data_type = 'smallint' AND col.table_schema = DATABASE() AND auto_increment > 65000;");
if (rs.next()) {
for (int i = 0; i < 6; i++) {
logblock.getLogger().warning("Your server reached 65000 players. You should soon update your database table schema - see FAQ: https://github.com/LogBlock/LogBlock/wiki/FAQ#logblock-your-server-reached-65000-players-");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
}
}
}
}

View File

@@ -2,6 +2,7 @@ package de.diddiz.LogBlock;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -10,7 +11,6 @@ import org.bukkit.block.Sign;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Material;
import org.bukkit.material.Bed;
import org.bukkit.material.PistonBaseMaterial;
import org.bukkit.material.PistonExtensionMaterial;
@@ -26,95 +26,93 @@ import java.util.logging.Level;
import static de.diddiz.LogBlock.config.Config.dontRollback;
import static de.diddiz.LogBlock.config.Config.replaceAnyway;
import static de.diddiz.util.BukkitUtils.equalTypes;
import static de.diddiz.util.BukkitUtils.getContainerBlocks;
import static de.diddiz.util.BukkitUtils.modifyContainer;
import static de.diddiz.util.BukkitUtils.*;
import static de.diddiz.util.MaterialName.materialName;
import static org.bukkit.Bukkit.getLogger;
public class WorldEditor implements Runnable
{
private final LogBlock logblock;
private final Queue<Edit> edits = new LinkedBlockingQueue<Edit>();
private final World world;
public class WorldEditor implements Runnable {
private final LogBlock logblock;
private final Queue<Edit> edits = new LinkedBlockingQueue<Edit>();
private final World world;
/**
* The player responsible for editing the world, used to report progress
*/
private CommandSender sender;
private int taskID;
private int successes = 0, blacklistCollisions = 0;
private long elapsedTime = 0;
public LookupCacheElement[] errors;
private int taskID;
private int successes = 0, blacklistCollisions = 0;
private long elapsedTime = 0;
public LookupCacheElement[] errors;
public WorldEditor(LogBlock logblock, World world) {
this.logblock = logblock;
this.world = world;
}
public WorldEditor(LogBlock logblock, World world) {
this.logblock = logblock;
this.world = world;
}
public int getSize() {
return edits.size();
}
public int getSize() {
return edits.size();
}
public int getSuccesses() {
return successes;
}
public int getSuccesses() {
return successes;
}
public int getErrors() {
return errors.length;
}
public int getErrors() {
return errors.length;
}
public int getBlacklistCollisions() {
return blacklistCollisions;
}
public int getBlacklistCollisions() {
return blacklistCollisions;
}
public void setSender(CommandSender sender) {
this.sender = sender;
}
public void queueEdit(int x, int y, int z, int replaced, int type, byte data, String signtext, short itemType, short itemAmount, short itemData) {
edits.add(new Edit(0, new Location(world, x, y, z), null, replaced, type, data, signtext, new ChestAccess(itemType, itemAmount, itemData)));
}
public void queueEdit(int x, int y, int z, int replaced, int type, byte data, String signtext, short itemType, short itemAmount, short itemData) {
edits.add(new Edit(0, new Location(world, x, y, z), null, replaced, type, data, signtext, new ChestAccess(itemType, itemAmount, itemData)));
}
public long getElapsedTime() {
return elapsedTime;
}
public long getElapsedTime() {
return elapsedTime;
}
synchronized public void start() throws Exception {
final long start = System.currentTimeMillis();
taskID = logblock.getServer().getScheduler().scheduleSyncRepeatingTask(logblock, this, 0, 1);
if (taskID == -1)
throw new Exception("Failed to schedule task");
try {
this.wait();
} catch (final InterruptedException ex) {
throw new Exception("Interrupted");
}
elapsedTime = System.currentTimeMillis() - start;
}
synchronized public void start() throws Exception {
final long start = System.currentTimeMillis();
taskID = logblock.getServer().getScheduler().scheduleSyncRepeatingTask(logblock, this, 0, 1);
if (taskID == -1) {
throw new Exception("Failed to schedule task");
}
try {
this.wait();
} catch (final InterruptedException ex) {
throw new Exception("Interrupted");
}
elapsedTime = System.currentTimeMillis() - start;
}
@Override
public synchronized void run() {
final List<WorldEditorException> errorList = new ArrayList<WorldEditorException>();
int counter = 0;
@Override
public synchronized void run() {
final List<WorldEditorException> errorList = new ArrayList<WorldEditorException>();
int counter = 0;
float size = edits.size();
while (!edits.isEmpty() && counter < 100) {
try {
switch (edits.poll().perform()) {
case SUCCESS:
successes++;
break;
case BLACKLISTED:
blacklistCollisions++;
break;
}
} catch (final WorldEditorException ex) {
errorList.add(ex);
} catch (final Exception ex) {
getLogger().log(Level.WARNING, "[WorldEditor] Exeption: ", ex);
}
counter++;
while (!edits.isEmpty() && counter < 100) {
try {
switch (edits.poll().perform()) {
case SUCCESS:
successes++;
break;
case BLACKLISTED:
blacklistCollisions++;
break;
}
} catch (final WorldEditorException ex) {
errorList.add(ex);
} catch (final Exception ex) {
getLogger().log(Level.WARNING, "[WorldEditor] Exeption: ", ex);
}
counter++;
if (sender != null) {
float percentage = ((size - edits.size()) / size) * 100.0F;
if (percentage % 20 == 0) {
@@ -122,131 +120,150 @@ public class WorldEditor implements Runnable
" Blocks edited: " + counter);
}
}
}
if (edits.isEmpty()) {
logblock.getServer().getScheduler().cancelTask(taskID);
if (errorList.size() > 0)
try {
final File file = new File("plugins/LogBlock/error/WorldEditor-" + new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis()) + ".log");
file.getParentFile().mkdirs();
final PrintWriter writer = new PrintWriter(file);
for (final LookupCacheElement err : errorList)
writer.println(err.getMessage());
writer.close();
} catch (final Exception ex) {
}
errors = errorList.toArray(new WorldEditorException[errorList.size()]);
notify();
}
}
}
if (edits.isEmpty()) {
logblock.getServer().getScheduler().cancelTask(taskID);
if (errorList.size() > 0) {
try {
final File file = new File("plugins/LogBlock/error/WorldEditor-" + new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis()) + ".log");
file.getParentFile().mkdirs();
final PrintWriter writer = new PrintWriter(file);
for (final LookupCacheElement err : errorList) {
writer.println(err.getMessage());
}
writer.close();
} catch (final Exception ex) {
}
}
errors = errorList.toArray(new WorldEditorException[errorList.size()]);
notify();
}
}
private static enum PerformResult
{
SUCCESS, BLACKLISTED, NO_ACTION
}
private static enum PerformResult {
SUCCESS, BLACKLISTED, NO_ACTION
}
private class Edit extends BlockChange
{
public Edit(long time, Location loc, Actor actor, int replaced, int type, byte data, String signtext, ChestAccess ca) {
super(time, loc, actor, replaced, type, data, signtext, ca);
}
private class Edit extends BlockChange {
public Edit(long time, Location loc, Actor actor, int replaced, int type, byte data, String signtext, ChestAccess ca) {
super(time, loc, actor, replaced, type, data, signtext, ca);
}
PerformResult perform() throws WorldEditorException {
if (dontRollback.contains(replaced))
return PerformResult.BLACKLISTED;
final Block block = loc.getBlock();
if (replaced == 0 && block.getTypeId() == 0)
return PerformResult.NO_ACTION;
final BlockState state = block.getState();
if (!world.isChunkLoaded(block.getChunk()))
world.loadChunk(block.getChunk());
if (type == replaced) {
if (type == 0) {
if (!block.setTypeId(0))
throw new WorldEditorException(block.getTypeId(), 0, block.getLocation());
} else if (ca != null) {
if (getContainerBlocks().contains(Material.getMaterial(type))) {
int leftover;
try {
leftover = modifyContainer(state, new ItemStack(ca.itemType, -ca.itemAmount, ca.itemData));
// Special-case blocks which might be double chests
if (leftover > 0 && (type == 54 || type == 146))
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST})
if (block.getRelative(face).getTypeId() == type)
leftover = modifyContainer(block.getRelative(face).getState(), new ItemStack(ca.itemType, ca.itemAmount < 0 ? leftover : -leftover, ca.itemData));
} catch (final Exception ex) {
throw new WorldEditorException(ex.getMessage(), block.getLocation());
}
if (!state.update())
throw new WorldEditorException("Failed to update inventory of " + materialName(block.getTypeId()), block.getLocation());
if (leftover > 0 && ca.itemAmount < 0)
throw new WorldEditorException("Not enough space left in " + materialName(block.getTypeId()), block.getLocation());
}
} else
return PerformResult.NO_ACTION;
return PerformResult.SUCCESS;
}
if (!(equalTypes(block.getTypeId(), type) || replaceAnyway.contains(block.getTypeId())))
return PerformResult.NO_ACTION;
if (state instanceof InventoryHolder) {
((InventoryHolder)state).getInventory().clear();
state.update();
}
if (block.getTypeId() == replaced) {
if (block.getData() != (type == 0 ? data : (byte)0))
block.setData(type == 0 ? data : (byte)0, true);
else
return PerformResult.NO_ACTION;
} else if (!block.setTypeIdAndData(replaced, type == 0 ? data : (byte)0, true))
throw new WorldEditorException(block.getTypeId(), replaced, block.getLocation());
final int curtype = block.getTypeId();
if (signtext != null && (curtype == 63 || curtype == 68)) {
final Sign sign = (Sign)block.getState();
final String[] lines = signtext.split("\0", 4);
if (lines.length < 4)
return PerformResult.NO_ACTION;
for (int i = 0; i < 4; i++)
sign.setLine(i, lines[i]);
if (!sign.update())
throw new WorldEditorException("Failed to update signtext of " + materialName(block.getTypeId()), block.getLocation());
} else if (curtype == 26) {
final Bed bed = (Bed)block.getState().getData();
final Block secBlock = bed.isHeadOfBed() ? block.getRelative(bed.getFacing().getOppositeFace()) : block.getRelative(bed.getFacing());
if (secBlock.getTypeId() == 0 && !secBlock.setTypeIdAndData(26, (byte)(bed.getData() | 8), true))
throw new WorldEditorException(secBlock.getTypeId(), 26, secBlock.getLocation());
} else if ((curtype == 29 || curtype == 33) && (block.getData() & 8) > 0) {
final PistonBaseMaterial piston = (PistonBaseMaterial)block.getState().getData();
final Block secBlock = block.getRelative(piston.getFacing());
if (secBlock.getTypeId() == 0 && !secBlock.setTypeIdAndData(34, curtype == 29 ? (byte)(block.getData() | 8) : (byte)(block.getData() & ~8), true))
throw new WorldEditorException(secBlock.getTypeId(), 34, secBlock.getLocation());
} else if (curtype == 34) {
final PistonExtensionMaterial piston = (PistonExtensionMaterial)block.getState().getData();
final Block secBlock = block.getRelative(piston.getFacing().getOppositeFace());
if (secBlock.getTypeId() == 0 && !secBlock.setTypeIdAndData(piston.isSticky() ? 29 : 33, (byte)(block.getData() | 8), true))
throw new WorldEditorException(secBlock.getTypeId(), piston.isSticky() ? 29 : 33, secBlock.getLocation());
} else if (curtype == 18 && (block.getData() & 8) > 0)
block.setData((byte)(block.getData() & 0xF7));
return PerformResult.SUCCESS;
}
}
PerformResult perform() throws WorldEditorException {
if (dontRollback.contains(replaced)) {
return PerformResult.BLACKLISTED;
}
final Block block = loc.getBlock();
if (replaced == 0 && block.getTypeId() == 0) {
return PerformResult.NO_ACTION;
}
final BlockState state = block.getState();
if (!world.isChunkLoaded(block.getChunk())) {
world.loadChunk(block.getChunk());
}
if (type == replaced) {
if (type == 0) {
if (!block.setTypeId(0)) {
throw new WorldEditorException(block.getTypeId(), 0, block.getLocation());
}
} else if (ca != null) {
if (getContainerBlocks().contains(Material.getMaterial(type))) {
int leftover;
try {
leftover = modifyContainer(state, new ItemStack(ca.itemType, -ca.itemAmount, ca.itemData));
// Special-case blocks which might be double chests
if (leftover > 0 && (type == 54 || type == 146)) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
if (block.getRelative(face).getTypeId() == type) {
leftover = modifyContainer(block.getRelative(face).getState(), new ItemStack(ca.itemType, ca.itemAmount < 0 ? leftover : -leftover, ca.itemData));
}
}
}
} catch (final Exception ex) {
throw new WorldEditorException(ex.getMessage(), block.getLocation());
}
if (!state.update()) {
throw new WorldEditorException("Failed to update inventory of " + materialName(block.getTypeId()), block.getLocation());
}
if (leftover > 0 && ca.itemAmount < 0) {
throw new WorldEditorException("Not enough space left in " + materialName(block.getTypeId()), block.getLocation());
}
}
} else {
return PerformResult.NO_ACTION;
}
return PerformResult.SUCCESS;
}
if (!(equalTypes(block.getTypeId(), type) || replaceAnyway.contains(block.getTypeId()))) {
return PerformResult.NO_ACTION;
}
if (state instanceof InventoryHolder) {
((InventoryHolder) state).getInventory().clear();
state.update();
}
if (block.getTypeId() == replaced) {
if (block.getData() != (type == 0 ? data : (byte) 0)) {
block.setData(type == 0 ? data : (byte) 0, true);
} else {
return PerformResult.NO_ACTION;
}
} else if (!block.setTypeIdAndData(replaced, type == 0 ? data : (byte) 0, true)) {
throw new WorldEditorException(block.getTypeId(), replaced, block.getLocation());
}
final int curtype = block.getTypeId();
if (signtext != null && (curtype == 63 || curtype == 68)) {
final Sign sign = (Sign) block.getState();
final String[] lines = signtext.split("\0", 4);
if (lines.length < 4) {
return PerformResult.NO_ACTION;
}
for (int i = 0; i < 4; i++) {
sign.setLine(i, lines[i]);
}
if (!sign.update()) {
throw new WorldEditorException("Failed to update signtext of " + materialName(block.getTypeId()), block.getLocation());
}
} else if (curtype == 26) {
final Bed bed = (Bed) block.getState().getData();
final Block secBlock = bed.isHeadOfBed() ? block.getRelative(bed.getFacing().getOppositeFace()) : block.getRelative(bed.getFacing());
if (secBlock.getTypeId() == 0 && !secBlock.setTypeIdAndData(26, (byte) (bed.getData() | 8), true)) {
throw new WorldEditorException(secBlock.getTypeId(), 26, secBlock.getLocation());
}
} else if ((curtype == 29 || curtype == 33) && (block.getData() & 8) > 0) {
final PistonBaseMaterial piston = (PistonBaseMaterial) block.getState().getData();
final Block secBlock = block.getRelative(piston.getFacing());
if (secBlock.getTypeId() == 0 && !secBlock.setTypeIdAndData(34, curtype == 29 ? (byte) (block.getData() | 8) : (byte) (block.getData() & ~8), true)) {
throw new WorldEditorException(secBlock.getTypeId(), 34, secBlock.getLocation());
}
} else if (curtype == 34) {
final PistonExtensionMaterial piston = (PistonExtensionMaterial) block.getState().getData();
final Block secBlock = block.getRelative(piston.getFacing().getOppositeFace());
if (secBlock.getTypeId() == 0 && !secBlock.setTypeIdAndData(piston.isSticky() ? 29 : 33, (byte) (block.getData() | 8), true)) {
throw new WorldEditorException(secBlock.getTypeId(), piston.isSticky() ? 29 : 33, secBlock.getLocation());
}
} else if (curtype == 18 && (block.getData() & 8) > 0) {
block.setData((byte) (block.getData() & 0xF7));
}
return PerformResult.SUCCESS;
}
}
@SuppressWarnings("serial")
public static class WorldEditorException extends Exception implements LookupCacheElement
{
private final Location loc;
@SuppressWarnings("serial")
public static class WorldEditorException extends Exception implements LookupCacheElement {
private final Location loc;
public WorldEditorException(int typeBefore, int typeAfter, Location loc) {
this("Failed to replace " + materialName(typeBefore) + " with " + materialName(typeAfter), loc);
}
public WorldEditorException(int typeBefore, int typeAfter, Location loc) {
this("Failed to replace " + materialName(typeBefore) + " with " + materialName(typeAfter), loc);
}
public WorldEditorException(String msg, Location loc) {
super(msg + " at " + loc.getWorld().getName() + ":" + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ());
this.loc = loc;
}
public WorldEditorException(String msg, Location loc) {
super(msg + " at " + loc.getWorld().getName() + ":" + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ());
this.loc = loc;
}
@Override
public Location getLocation() {
return loc;
}
}
@Override
public Location getLocation() {
return loc;
}
}
}

View File

@@ -18,265 +18,276 @@ import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import static de.diddiz.util.Utils.parseTimeSpec;
import static org.bukkit.Bukkit.*;
public class Config
{
private static LoggingEnabledMapping superWorldConfig;
private static Map<String, WorldConfig> worldConfigs;
public static String url, user, password;
public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
public static boolean fireCustomEvents;
public static boolean useBukkitScheduler;
public static int queueWarningSize;
public static boolean enableAutoClearLog;
public static List<String> autoClearLog;
public static int autoClearLogDelay;
public static boolean dumpDeletedLog;
public static boolean logCreeperExplosionsAsPlayerWhoTriggeredThese, logPlayerInfo;
public static LogKillsLevel logKillsLevel;
public static Set<Integer> dontRollback, replaceAnyway;
public static int rollbackMaxTime, rollbackMaxArea;
public static Map<String, Tool> toolsByName;
public static Map<Integer, Tool> toolsByType;
public static int defaultDist, defaultTime;
public static int linesPerPage, linesLimit;
public static boolean askRollbacks, askRedos, askClearLogs, askClearLogAfterRollback, askRollbackAfterBan;
public static String banPermission;
public static Set<Integer> hiddenBlocks;
public static Set<String> hiddenPlayers;
public static Set<String> ignoredChat;
public static SimpleDateFormat formatter;
public static boolean safetyIdCheck;
public static boolean debug;
public static boolean logEnvironmentalKills;
// Not loaded from config - checked at runtime
public static boolean mb4 = false;
public class Config {
private static LoggingEnabledMapping superWorldConfig;
private static Map<String, WorldConfig> worldConfigs;
public static String url, user, password;
public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
public static boolean fireCustomEvents;
public static boolean useBukkitScheduler;
public static int queueWarningSize;
public static boolean enableAutoClearLog;
public static List<String> autoClearLog;
public static int autoClearLogDelay;
public static boolean dumpDeletedLog;
public static boolean logCreeperExplosionsAsPlayerWhoTriggeredThese, logPlayerInfo;
public static LogKillsLevel logKillsLevel;
public static Set<Integer> dontRollback, replaceAnyway;
public static int rollbackMaxTime, rollbackMaxArea;
public static Map<String, Tool> toolsByName;
public static Map<Integer, Tool> toolsByType;
public static int defaultDist, defaultTime;
public static int linesPerPage, linesLimit;
public static boolean askRollbacks, askRedos, askClearLogs, askClearLogAfterRollback, askRollbackAfterBan;
public static String banPermission;
public static Set<Integer> hiddenBlocks;
public static Set<String> hiddenPlayers;
public static Set<String> ignoredChat;
public static SimpleDateFormat formatter;
public static boolean safetyIdCheck;
public static boolean debug;
public static boolean logEnvironmentalKills;
// Not loaded from config - checked at runtime
public static boolean mb4 = false;
public static enum LogKillsLevel
{
PLAYERS, MONSTERS, ANIMALS;
}
public static enum LogKillsLevel {
PLAYERS, MONSTERS, ANIMALS;
}
public static void load(LogBlock logblock) throws DataFormatException, IOException {
final ConfigurationSection config = logblock.getConfig();
final Map<String, Object> def = new HashMap<String, Object>();
def.put("version", logblock.getDescription().getVersion());
final List<String> worldNames = new ArrayList<String>();
for (final World world : getWorlds())
worldNames.add(world.getName());
if (worldNames.isEmpty()) {
worldNames.add("world");
worldNames.add("world_nether");
worldNames.add("world_the_end");
}
def.put("loggedWorlds", worldNames);
def.put("mysql.host", "localhost");
def.put("mysql.port", 3306);
def.put("mysql.database", "minecraft");
def.put("mysql.user", "username");
def.put("mysql.password", "pass");
def.put("consumer.delayBetweenRuns", 2);
def.put("consumer.forceToProcessAtLeast", 200);
def.put("consumer.timePerRun", 1000);
def.put("consumer.fireCustomEvents", false);
def.put("consumer.useBukkitScheduler", true);
def.put("consumer.queueWarningSize", 1000);
def.put("clearlog.dumpDeletedLog", false);
def.put("clearlog.enableAutoClearLog", false);
def.put("clearlog.auto", Arrays.asList("world \"world\" before 365 days all", "world \"world\" player lavaflow waterflow leavesdecay before 7 days all", "world world_nether before 365 days all", "world world_nether player lavaflow before 7 days all"));
def.put("clearlog.autoClearLogDelay", "6h");
def.put("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
def.put("logging.logKillsLevel", "PLAYERS");
def.put("logging.logEnvironmentalKills", false);
def.put("logging.logPlayerInfo", false);
def.put("logging.hiddenPlayers", new ArrayList<String>());
def.put("logging.hiddenBlocks", Arrays.asList(0));
def.put("logging.ignoredChat", Arrays.asList("/register", "/login"));
def.put("rollback.dontRollback", Arrays.asList(10, 11, 46, 51));
def.put("rollback.replaceAnyway", Arrays.asList(8, 9, 10, 11, 51));
def.put("rollback.maxTime", "2 days");
def.put("rollback.maxArea", 50);
def.put("lookup.defaultDist", 20);
def.put("lookup.defaultTime", "30 minutes");
def.put("lookup.linesPerPage", 15);
def.put("lookup.linesLimit", 1500);
try {
formatter = new SimpleDateFormat(config.getString("lookup.dateFormat", "MM-dd HH:mm:ss"));
} catch (IllegalArgumentException e) {
throw new DataFormatException("Invalid specification for date format, please see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html : " + e.getMessage());
}
def.put("lookup.dateFormat", "MM-dd HH:mm:ss");
def.put("questioner.askRollbacks", true);
def.put("questioner.askRedos", true);
def.put("questioner.askClearLogs", true);
def.put("questioner.askClearLogAfterRollback", true);
def.put("questioner.askRollbackAfterBan", false);
def.put("questioner.banPermission", "mcbans.ban.local");
def.put("tools.tool.aliases", Arrays.asList("t"));
def.put("tools.tool.leftClickBehavior", "NONE");
def.put("tools.tool.rightClickBehavior", "TOOL");
def.put("tools.tool.defaultEnabled", true);
def.put("tools.tool.item", 270);
def.put("tools.tool.canDrop", true);
def.put("tools.tool.params", "area 0 all sum none limit 15 desc silent");
def.put("tools.tool.mode", "LOOKUP");
def.put("tools.tool.permissionDefault", "OP");
def.put("tools.toolblock.aliases", Arrays.asList("tb"));
def.put("tools.toolblock.leftClickBehavior", "TOOL");
def.put("tools.toolblock.rightClickBehavior", "BLOCK");
def.put("tools.toolblock.defaultEnabled", true);
def.put("tools.toolblock.item", 7);
def.put("tools.toolblock.canDrop", false);
def.put("tools.toolblock.params", "area 0 all sum none limit 15 desc silent");
def.put("tools.toolblock.mode", "LOOKUP");
def.put("tools.toolblock.permissionDefault", "OP");
def.put("safety.id.check", true);
def.put("debug", false);
for (final Entry<String, Object> e : def.entrySet())
if (!config.contains(e.getKey()))
config.set(e.getKey(), e.getValue());
logblock.saveConfig();
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database");
user = getStringIncludingInts(config, "mysql.user");
password = getStringIncludingInts(config, "mysql.password");
delayBetweenRuns = config.getInt("consumer.delayBetweenRuns", 2);
forceToProcessAtLeast = config.getInt("consumer.forceToProcessAtLeast", 0);
timePerRun = config.getInt("consumer.timePerRun", 1000);
fireCustomEvents = config.getBoolean("consumer.fireCustomEvents", false);
useBukkitScheduler = config.getBoolean("consumer.useBukkitScheduler", true);
queueWarningSize = config.getInt("consumer.queueWarningSize", 1000);
enableAutoClearLog = config.getBoolean("clearlog.enableAutoClearLog");
autoClearLog = config.getStringList("clearlog.auto");
dumpDeletedLog = config.getBoolean("clearlog.dumpDeletedLog", false);
autoClearLogDelay = parseTimeSpec(config.getString("clearlog.autoClearLogDelay").split(" "));
logCreeperExplosionsAsPlayerWhoTriggeredThese = config.getBoolean("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
logPlayerInfo = config.getBoolean("logging.logPlayerInfo", true);
try {
logKillsLevel = LogKillsLevel.valueOf(config.getString("logging.logKillsLevel").toUpperCase());
} catch (final IllegalArgumentException ex) {
throw new DataFormatException("logging.logKillsLevel doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
}
logEnvironmentalKills = config.getBoolean("logging.logEnvironmentalKills", false);
hiddenPlayers = new HashSet<String>();
for (final String playerName : config.getStringList("logging.hiddenPlayers"))
hiddenPlayers.add(playerName.toLowerCase().trim());
hiddenBlocks = new HashSet<Integer>();
for (final Object blocktype : config.getList("logging.hiddenBlocks")) {
final Material mat = Material.matchMaterial(String.valueOf(blocktype));
if (mat != null)
hiddenBlocks.add(mat.getId());
else
throw new DataFormatException("Not a valid material: '" + blocktype + "'");
}
ignoredChat = new HashSet<String>();
for (String chatCommand : config.getStringList("logging.ignoredChat")) {
ignoredChat.add(chatCommand);
}
dontRollback = new HashSet<Integer>(config.getIntegerList("rollback.dontRollback"));
replaceAnyway = new HashSet<Integer>(config.getIntegerList("rollback.replaceAnyway"));
rollbackMaxTime = parseTimeSpec(config.getString("rollback.maxTime").split(" "));
rollbackMaxArea = config.getInt("rollback.maxArea", 50);
defaultDist = config.getInt("lookup.defaultDist", 20);
defaultTime = parseTimeSpec(config.getString("lookup.defaultTime").split(" "));
linesPerPage = config.getInt("lookup.linesPerPage", 15);
linesLimit = config.getInt("lookup.linesLimit", 1500);
askRollbacks = config.getBoolean("questioner.askRollbacks", true);
askRedos = config.getBoolean("questioner.askRedos", true);
askClearLogs = config.getBoolean("questioner.askClearLogs", true);
askClearLogAfterRollback = config.getBoolean("questioner.askClearLogAfterRollback", true);
askRollbackAfterBan = config.getBoolean("questioner.askRollbackAfterBan", false);
safetyIdCheck = config.getBoolean("safety.id.check", true);
debug = config.getBoolean("debug", false);
banPermission = config.getString("questioner.banPermission");
final List<Tool> tools = new ArrayList<Tool>();
final ConfigurationSection toolsSec = config.getConfigurationSection("tools");
for (final String toolName : toolsSec.getKeys(false))
try {
final ConfigurationSection tSec = toolsSec.getConfigurationSection(toolName);
final List<String> aliases = tSec.getStringList("aliases");
final ToolBehavior leftClickBehavior = ToolBehavior.valueOf(tSec.getString("leftClickBehavior").toUpperCase());
final ToolBehavior rightClickBehavior = ToolBehavior.valueOf(tSec.getString("rightClickBehavior").toUpperCase());
final boolean defaultEnabled = tSec.getBoolean("defaultEnabled", false);
final int item = tSec.getInt("item", 0);
final boolean canDrop = tSec.getBoolean("canDrop", false);
final QueryParams params = new QueryParams(logblock);
params.prepareToolQuery = true;
params.parseArgs(getConsoleSender(), Arrays.asList(tSec.getString("params").split(" ")));
final ToolMode mode = ToolMode.valueOf(tSec.getString("mode").toUpperCase());
final PermissionDefault pdef = PermissionDefault.valueOf(tSec.getString("permissionDefault").toUpperCase());
tools.add(new Tool(toolName, aliases, leftClickBehavior, rightClickBehavior, defaultEnabled, item, canDrop, params, mode, pdef));
} catch (final Exception ex) {
getLogger().log(Level.WARNING, "Error at parsing tool '" + toolName + "': ", ex);
}
toolsByName = new HashMap<String, Tool>();
toolsByType = new HashMap<Integer, Tool>();
for (final Tool tool : tools) {
toolsByType.put(tool.item, tool);
toolsByName.put(tool.name.toLowerCase(), tool);
for (final String alias : tool.aliases)
toolsByName.put(alias, tool);
}
final List<String> loggedWorlds = config.getStringList("loggedWorlds");
worldConfigs = new HashMap<String, WorldConfig>();
if (loggedWorlds.isEmpty())
throw new DataFormatException("No worlds configured");
for (final String world : loggedWorlds)
worldConfigs.put(world, new WorldConfig(new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml")));
superWorldConfig = new LoggingEnabledMapping();
for (final WorldConfig wcfg : worldConfigs.values())
for (final Logging l : Logging.values())
if (wcfg.isLogging(l))
superWorldConfig.setLogging(l, true);
}
public static void load(LogBlock logblock) throws DataFormatException, IOException {
final ConfigurationSection config = logblock.getConfig();
final Map<String, Object> def = new HashMap<String, Object>();
def.put("version", logblock.getDescription().getVersion());
final List<String> worldNames = new ArrayList<String>();
for (final World world : getWorlds()) {
worldNames.add(world.getName());
}
if (worldNames.isEmpty()) {
worldNames.add("world");
worldNames.add("world_nether");
worldNames.add("world_the_end");
}
def.put("loggedWorlds", worldNames);
def.put("mysql.host", "localhost");
def.put("mysql.port", 3306);
def.put("mysql.database", "minecraft");
def.put("mysql.user", "username");
def.put("mysql.password", "pass");
def.put("consumer.delayBetweenRuns", 2);
def.put("consumer.forceToProcessAtLeast", 200);
def.put("consumer.timePerRun", 1000);
def.put("consumer.fireCustomEvents", false);
def.put("consumer.useBukkitScheduler", true);
def.put("consumer.queueWarningSize", 1000);
def.put("clearlog.dumpDeletedLog", false);
def.put("clearlog.enableAutoClearLog", false);
def.put("clearlog.auto", Arrays.asList("world \"world\" before 365 days all", "world \"world\" player lavaflow waterflow leavesdecay before 7 days all", "world world_nether before 365 days all", "world world_nether player lavaflow before 7 days all"));
def.put("clearlog.autoClearLogDelay", "6h");
def.put("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
def.put("logging.logKillsLevel", "PLAYERS");
def.put("logging.logEnvironmentalKills", false);
def.put("logging.logPlayerInfo", false);
def.put("logging.hiddenPlayers", new ArrayList<String>());
def.put("logging.hiddenBlocks", Arrays.asList(0));
def.put("logging.ignoredChat", Arrays.asList("/register", "/login"));
def.put("rollback.dontRollback", Arrays.asList(10, 11, 46, 51));
def.put("rollback.replaceAnyway", Arrays.asList(8, 9, 10, 11, 51));
def.put("rollback.maxTime", "2 days");
def.put("rollback.maxArea", 50);
def.put("lookup.defaultDist", 20);
def.put("lookup.defaultTime", "30 minutes");
def.put("lookup.linesPerPage", 15);
def.put("lookup.linesLimit", 1500);
try {
formatter = new SimpleDateFormat(config.getString("lookup.dateFormat", "MM-dd HH:mm:ss"));
} catch (IllegalArgumentException e) {
throw new DataFormatException("Invalid specification for date format, please see http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html : " + e.getMessage());
}
def.put("lookup.dateFormat", "MM-dd HH:mm:ss");
def.put("questioner.askRollbacks", true);
def.put("questioner.askRedos", true);
def.put("questioner.askClearLogs", true);
def.put("questioner.askClearLogAfterRollback", true);
def.put("questioner.askRollbackAfterBan", false);
def.put("questioner.banPermission", "mcbans.ban.local");
def.put("tools.tool.aliases", Arrays.asList("t"));
def.put("tools.tool.leftClickBehavior", "NONE");
def.put("tools.tool.rightClickBehavior", "TOOL");
def.put("tools.tool.defaultEnabled", true);
def.put("tools.tool.item", 270);
def.put("tools.tool.canDrop", true);
def.put("tools.tool.params", "area 0 all sum none limit 15 desc silent");
def.put("tools.tool.mode", "LOOKUP");
def.put("tools.tool.permissionDefault", "OP");
def.put("tools.toolblock.aliases", Arrays.asList("tb"));
def.put("tools.toolblock.leftClickBehavior", "TOOL");
def.put("tools.toolblock.rightClickBehavior", "BLOCK");
def.put("tools.toolblock.defaultEnabled", true);
def.put("tools.toolblock.item", 7);
def.put("tools.toolblock.canDrop", false);
def.put("tools.toolblock.params", "area 0 all sum none limit 15 desc silent");
def.put("tools.toolblock.mode", "LOOKUP");
def.put("tools.toolblock.permissionDefault", "OP");
def.put("safety.id.check", true);
def.put("debug", false);
for (final Entry<String, Object> e : def.entrySet()) {
if (!config.contains(e.getKey())) {
config.set(e.getKey(), e.getValue());
}
}
logblock.saveConfig();
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database");
user = getStringIncludingInts(config, "mysql.user");
password = getStringIncludingInts(config, "mysql.password");
delayBetweenRuns = config.getInt("consumer.delayBetweenRuns", 2);
forceToProcessAtLeast = config.getInt("consumer.forceToProcessAtLeast", 0);
timePerRun = config.getInt("consumer.timePerRun", 1000);
fireCustomEvents = config.getBoolean("consumer.fireCustomEvents", false);
useBukkitScheduler = config.getBoolean("consumer.useBukkitScheduler", true);
queueWarningSize = config.getInt("consumer.queueWarningSize", 1000);
enableAutoClearLog = config.getBoolean("clearlog.enableAutoClearLog");
autoClearLog = config.getStringList("clearlog.auto");
dumpDeletedLog = config.getBoolean("clearlog.dumpDeletedLog", false);
autoClearLogDelay = parseTimeSpec(config.getString("clearlog.autoClearLogDelay").split(" "));
logCreeperExplosionsAsPlayerWhoTriggeredThese = config.getBoolean("logging.logCreeperExplosionsAsPlayerWhoTriggeredThese", false);
logPlayerInfo = config.getBoolean("logging.logPlayerInfo", true);
try {
logKillsLevel = LogKillsLevel.valueOf(config.getString("logging.logKillsLevel").toUpperCase());
} catch (final IllegalArgumentException ex) {
throw new DataFormatException("logging.logKillsLevel doesn't appear to be a valid log level. Allowed are 'PLAYERS', 'MONSTERS' and 'ANIMALS'");
}
logEnvironmentalKills = config.getBoolean("logging.logEnvironmentalKills", false);
hiddenPlayers = new HashSet<String>();
for (final String playerName : config.getStringList("logging.hiddenPlayers")) {
hiddenPlayers.add(playerName.toLowerCase().trim());
}
hiddenBlocks = new HashSet<Integer>();
for (final Object blocktype : config.getList("logging.hiddenBlocks")) {
final Material mat = Material.matchMaterial(String.valueOf(blocktype));
if (mat != null) {
hiddenBlocks.add(mat.getId());
} else {
throw new DataFormatException("Not a valid material: '" + blocktype + "'");
}
}
ignoredChat = new HashSet<String>();
for (String chatCommand : config.getStringList("logging.ignoredChat")) {
ignoredChat.add(chatCommand);
}
dontRollback = new HashSet<Integer>(config.getIntegerList("rollback.dontRollback"));
replaceAnyway = new HashSet<Integer>(config.getIntegerList("rollback.replaceAnyway"));
rollbackMaxTime = parseTimeSpec(config.getString("rollback.maxTime").split(" "));
rollbackMaxArea = config.getInt("rollback.maxArea", 50);
defaultDist = config.getInt("lookup.defaultDist", 20);
defaultTime = parseTimeSpec(config.getString("lookup.defaultTime").split(" "));
linesPerPage = config.getInt("lookup.linesPerPage", 15);
linesLimit = config.getInt("lookup.linesLimit", 1500);
askRollbacks = config.getBoolean("questioner.askRollbacks", true);
askRedos = config.getBoolean("questioner.askRedos", true);
askClearLogs = config.getBoolean("questioner.askClearLogs", true);
askClearLogAfterRollback = config.getBoolean("questioner.askClearLogAfterRollback", true);
askRollbackAfterBan = config.getBoolean("questioner.askRollbackAfterBan", false);
safetyIdCheck = config.getBoolean("safety.id.check", true);
debug = config.getBoolean("debug", false);
banPermission = config.getString("questioner.banPermission");
final List<Tool> tools = new ArrayList<Tool>();
final ConfigurationSection toolsSec = config.getConfigurationSection("tools");
for (final String toolName : toolsSec.getKeys(false)) {
try {
final ConfigurationSection tSec = toolsSec.getConfigurationSection(toolName);
final List<String> aliases = tSec.getStringList("aliases");
final ToolBehavior leftClickBehavior = ToolBehavior.valueOf(tSec.getString("leftClickBehavior").toUpperCase());
final ToolBehavior rightClickBehavior = ToolBehavior.valueOf(tSec.getString("rightClickBehavior").toUpperCase());
final boolean defaultEnabled = tSec.getBoolean("defaultEnabled", false);
final int item = tSec.getInt("item", 0);
final boolean canDrop = tSec.getBoolean("canDrop", false);
final QueryParams params = new QueryParams(logblock);
params.prepareToolQuery = true;
params.parseArgs(getConsoleSender(), Arrays.asList(tSec.getString("params").split(" ")));
final ToolMode mode = ToolMode.valueOf(tSec.getString("mode").toUpperCase());
final PermissionDefault pdef = PermissionDefault.valueOf(tSec.getString("permissionDefault").toUpperCase());
tools.add(new Tool(toolName, aliases, leftClickBehavior, rightClickBehavior, defaultEnabled, item, canDrop, params, mode, pdef));
} catch (final Exception ex) {
getLogger().log(Level.WARNING, "Error at parsing tool '" + toolName + "': ", ex);
}
}
toolsByName = new HashMap<String, Tool>();
toolsByType = new HashMap<Integer, Tool>();
for (final Tool tool : tools) {
toolsByType.put(tool.item, tool);
toolsByName.put(tool.name.toLowerCase(), tool);
for (final String alias : tool.aliases) {
toolsByName.put(alias, tool);
}
}
final List<String> loggedWorlds = config.getStringList("loggedWorlds");
worldConfigs = new HashMap<String, WorldConfig>();
if (loggedWorlds.isEmpty()) {
throw new DataFormatException("No worlds configured");
}
for (final String world : loggedWorlds) {
worldConfigs.put(world, new WorldConfig(new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml")));
}
superWorldConfig = new LoggingEnabledMapping();
for (final WorldConfig wcfg : worldConfigs.values()) {
for (final Logging l : Logging.values()) {
if (wcfg.isLogging(l)) {
superWorldConfig.setLogging(l, true);
}
}
}
}
private static String getStringIncludingInts(ConfigurationSection cfg, String key) {
String str = cfg.getString(key);
if (str == null)
str = String.valueOf(cfg.getInt(key));
if (str == null)
str = "No value set for '" + key + "'";
return str;
}
private static String getStringIncludingInts(ConfigurationSection cfg, String key) {
String str = cfg.getString(key);
if (str == null) {
str = String.valueOf(cfg.getInt(key));
}
if (str == null) {
str = "No value set for '" + key + "'";
}
return str;
}
public static boolean isLogging(World world, Logging l) {
final WorldConfig wcfg = worldConfigs.get(world.getName());
return wcfg != null && wcfg.isLogging(l);
}
public static boolean isLogging(World world, Logging l) {
final WorldConfig wcfg = worldConfigs.get(world.getName());
return wcfg != null && wcfg.isLogging(l);
}
public static boolean isLogging(String worldName, Logging l) {
final WorldConfig wcfg = worldConfigs.get(worldName);
return wcfg != null && wcfg.isLogging(l);
}
public static boolean isLogging(String worldName, Logging l) {
final WorldConfig wcfg = worldConfigs.get(worldName);
return wcfg != null && wcfg.isLogging(l);
}
public static boolean isLogged(World world) {
return worldConfigs.containsKey(world.getName());
}
public static boolean isLogged(World world) {
return worldConfigs.containsKey(world.getName());
}
public static WorldConfig getWorldConfig(World world) {
return worldConfigs.get(world.getName());
}
public static WorldConfig getWorldConfig(World world) {
return worldConfigs.get(world.getName());
}
public static WorldConfig getWorldConfig(String world) {
return worldConfigs.get(world);
}
public static WorldConfig getWorldConfig(String world) {
return worldConfigs.get(world);
}
public static boolean isLogging(Logging l) {
return superWorldConfig.isLogging(l);
}
public static boolean isLogging(Logging l) {
return superWorldConfig.isLogging(l);
}
public static Collection<WorldConfig> getLoggedWorlds() {
return worldConfigs.values();
}
public static Collection<WorldConfig> getLoggedWorlds() {
return worldConfigs.values();
}
}
class LoggingEnabledMapping
{
private final boolean[] logging = new boolean[Logging.length];
class LoggingEnabledMapping {
private final boolean[] logging = new boolean[Logging.length];
public void setLogging(Logging l, boolean enabled) {
logging[l.ordinal()] = enabled;
}
public void setLogging(Logging l, boolean enabled) {
logging[l.ordinal()] = enabled;
}
public boolean isLogging(Logging l) {
return logging[l.ordinal()];
}
public boolean isLogging(Logging l) {
return logging[l.ordinal()];
}
}

View File

@@ -1,31 +1,35 @@
package de.diddiz.LogBlock.config;
import de.diddiz.LogBlock.Logging;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.configuration.file.YamlConfiguration;
import de.diddiz.LogBlock.Logging;
public class WorldConfig extends LoggingEnabledMapping
{
public final String table;
public class WorldConfig extends LoggingEnabledMapping {
public final String table;
public WorldConfig(File file) throws IOException {
final Map<String, Object> def = new HashMap<String, Object>();
// "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());
config.save(file);
table = config.getString("table");
for (final Logging l : Logging.values())
setLogging(l, config.getBoolean("logging." + l.toString()));
}
public WorldConfig(File file) throws IOException {
final Map<String, Object> def = new HashMap<String, Object>();
// "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());
}
}
config.save(file);
table = config.getString("table");
for (final Logging l : Logging.values()) {
setLogging(l, config.getBoolean("logging." + l.toString()));
}
}
}

View File

@@ -1,4 +1,5 @@
package de.diddiz.LogBlock.events;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.ChestAccess;
import org.apache.commons.lang.Validate;
@@ -7,111 +8,117 @@ import org.bukkit.event.HandlerList;
public class BlockChangePreLogEvent extends PreLogEvent {
private static final HandlerList handlers = new HandlerList();
private Location location;
private int typeBefore, typeAfter;
private byte data;
private String signText;
private ChestAccess chestAccess;
private static final HandlerList handlers = new HandlerList();
private Location location;
private int typeBefore, typeAfter;
private byte data;
private String signText;
private ChestAccess chestAccess;
public BlockChangePreLogEvent(Actor owner, Location location, int typeBefore, int typeAfter, byte data,
String signText, ChestAccess chestAccess) {
public BlockChangePreLogEvent(Actor owner, Location location, int typeBefore, int typeAfter, byte data,
String signText, ChestAccess chestAccess) {
super(owner);
this.location = location;
this.typeBefore = typeBefore;
this.typeAfter = typeAfter;
this.data = data;
this.signText = signText;
this.chestAccess = chestAccess;
}
super(owner);
this.location = location;
this.typeBefore = typeBefore;
this.typeAfter = typeAfter;
this.data = data;
this.signText = signText;
this.chestAccess = chestAccess;
}
public Location getLocation() {
public Location getLocation() {
return location;
}
return location;
}
public void setLocation(Location location) {
public void setLocation(Location location) {
this.location = location;
}
this.location = location;
}
public int getTypeBefore() {
public int getTypeBefore() {
return typeBefore;
}
return typeBefore;
}
public void setTypeBefore(int typeBefore) {
public void setTypeBefore(int typeBefore) {
this.typeBefore = typeBefore;
}
this.typeBefore = typeBefore;
}
public int getTypeAfter() {
public int getTypeAfter() {
return typeAfter;
}
return typeAfter;
}
public void setTypeAfter(int typeAfter) {
public void setTypeAfter(int typeAfter) {
this.typeAfter = typeAfter;
}
this.typeAfter = typeAfter;
}
public byte getData() {
public byte getData() {
return data;
}
return data;
}
public void setData(byte data) {
public void setData(byte data) {
this.data = data;
}
this.data = data;
}
public String getSignText() {
public String getSignText() {
return signText;
}
return signText;
}
public void setSignText(String[] signText) {
public void setSignText(String[] signText) {
if (signText != null) {
// Check for block
Validate.isTrue(isValidSign(), "Must be valid sign block");
if (signText != null) {
// Check for block
Validate.isTrue(isValidSign(), "Must be valid sign block");
// Check for problems
Validate.noNullElements(signText, "No null lines");
Validate.isTrue(signText.length == 4, "Sign text must be 4 strings");
// Check for problems
Validate.noNullElements(signText, "No null lines");
Validate.isTrue(signText.length == 4, "Sign text must be 4 strings");
this.signText = signText[0] + "\0" + signText[1] + "\0" + signText[2] + "\0" + signText[3];
} else {
this.signText = null;
}
}
this.signText = signText[0] + "\0" + signText[1] + "\0" + signText[2] + "\0" + signText[3];
} else {
this.signText = null;
}
}
private boolean isValidSign() {
private boolean isValidSign() {
if ((typeAfter == 63 || typeAfter == 68) && typeBefore == 0) return true;
if ((typeBefore == 63 || typeBefore == 68) && typeAfter == 0) return true;
if ((typeAfter == 63 || typeAfter == 68) && typeBefore == typeAfter) return true;
return false;
}
if ((typeAfter == 63 || typeAfter == 68) && typeBefore == 0) {
return true;
}
if ((typeBefore == 63 || typeBefore == 68) && typeAfter == 0) {
return true;
}
if ((typeAfter == 63 || typeAfter == 68) && typeBefore == typeAfter) {
return true;
}
return false;
}
public ChestAccess getChestAccess() {
public ChestAccess getChestAccess() {
return chestAccess;
}
return chestAccess;
}
public void setChestAccess(ChestAccess chestAccess) {
public void setChestAccess(ChestAccess chestAccess) {
this.chestAccess = chestAccess;
}
this.chestAccess = chestAccess;
}
public HandlerList getHandlers() {
public HandlerList getHandlers() {
return handlers;
}
return handlers;
}
public static HandlerList getHandlerList() {
public static HandlerList getHandlerList() {
return handlers;
}
return handlers;
}
}

View File

@@ -1,56 +1,57 @@
package de.diddiz.LogBlock.events;
import de.diddiz.LogBlock.Actor;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
public abstract class PreLogEvent extends Event implements Cancellable {
protected boolean cancelled = false;
protected Actor owner;
protected boolean cancelled = false;
protected Actor owner;
public PreLogEvent(Actor owner) {
public PreLogEvent(Actor owner) {
this.owner = owner;
}
this.owner = owner;
}
/**
* Returns the player/monster/cause involved in this event
*
* @return Player/monster/cause who is involved in this event
* @deprecated {@link #getOwnerActor() } returns an object encapsulating
* name and uuid. Names are not guaranteed to be unique.
*/
public String getOwner() {
/**
* Returns the player/monster/cause involved in this event
*
* @return Player/monster/cause who is involved in this event
* @deprecated {@link #getOwnerActor() } returns an object encapsulating
* name and uuid. Names are not guaranteed to be unique.
*/
public String getOwner() {
return owner.getName();
}
/**
* Returns the player/monster/cause involved in this event
*
* @return Player/monster/cause who is involved in this event
*/
public Actor getOwnerActor() {
return owner;
}
return owner.getName();
}
/**
* Sets the player/monster/cause involved in this event
*
* @param owner The player/monster/cause who is involved in this event
*/
public void setOwner(Actor owner) {
/**
* Returns the player/monster/cause involved in this event
*
* @return Player/monster/cause who is involved in this event
*/
public Actor getOwnerActor() {
return owner;
}
this.owner = owner;
}
/**
* Sets the player/monster/cause involved in this event
*
* @param owner The player/monster/cause who is involved in this event
*/
public void setOwner(Actor owner) {
public boolean isCancelled() {
this.owner = owner;
}
return cancelled;
}
public boolean isCancelled() {
public void setCancelled(boolean cancelled) {
return cancelled;
}
this.cancelled = cancelled;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@@ -1,48 +1,48 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.banPermission;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static org.bukkit.Bukkit.getScheduler;
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 de.diddiz.LogBlock.CommandsHandler;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.QueryParams;
public class BanListener implements Listener
{
private final CommandsHandler handler;
private final LogBlock logblock;
import static de.diddiz.LogBlock.config.Config.banPermission;
import static de.diddiz.LogBlock.config.Config.isLogged;
import static org.bukkit.Bukkit.getScheduler;
public BanListener(LogBlock logblock) {
this.logblock = logblock;
handler = logblock.getCommandsHandler();
}
public class BanListener implements Listener {
private final CommandsHandler handler;
private final LogBlock logblock;
@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().scheduleAsyncDelayedTask(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) {
}
}
}
});
}
}
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().scheduleAsyncDelayedTask(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) {
}
}
}
}
});
}
}
}

View File

@@ -1,10 +1,10 @@
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.LoggingUtil.smartLogBlockBreak;
import static de.diddiz.util.LoggingUtil.smartLogFallables;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.BukkitUtils;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -13,50 +13,52 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.BukkitUtils;
public class BlockBreakLogging extends LoggingListener
{
public BlockBreakLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.LoggingUtil.smartLogBlockBreak;
import static de.diddiz.util.LoggingUtil.smartLogFallables;
@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;
public class BlockBreakLogging extends LoggingListener {
public BlockBreakLogging(LogBlock lb) {
super(lb);
}
final Actor actor = Actor.actorFromEntity(event.getPlayer());
final Block origin = event.getBlock();
final int typeId = origin.getTypeId();
final Material type = origin.getType();
@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;
}
if (wcfg.isLogging(Logging.SIGNTEXT) && (typeId == 63 || typeId == 68)) {
consumer.queueSignBreak(actor, (Sign) origin.getState());
} else if (wcfg.isLogging(Logging.CHESTACCESS) && BukkitUtils.getContainerBlocks().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)) {
consumer.queueBlockBreak(actor, origin.getState());
} else {
consumer.queueBlockReplace(actor, origin.getState(), 9, (byte) 0);
}
} else {
smartLogBlockBreak(consumer, actor, origin);
}
smartLogFallables(consumer, actor, origin);
}
}
final Actor actor = Actor.actorFromEntity(event.getPlayer());
final Block origin = event.getBlock();
final int typeId = origin.getTypeId();
final Material type = origin.getType();
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
if (isLogging(event.getBlockClicked().getWorld(), Logging.BLOCKBREAK)) {
consumer.queueBlockBreak(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getState());
}
}
if (wcfg.isLogging(Logging.SIGNTEXT) && (typeId == 63 || typeId == 68)) {
consumer.queueSignBreak(actor, (Sign) origin.getState());
} else if (wcfg.isLogging(Logging.CHESTACCESS) && BukkitUtils.getContainerBlocks().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)) {
consumer.queueBlockBreak(actor, origin.getState());
} else {
consumer.queueBlockReplace(actor, origin.getState(), 9, (byte) 0);
}
} 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)) {
consumer.queueBlockBreak(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getState());
}
}
}

View File

@@ -1,12 +1,10 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.LoggingUtil.smartLogBlockBreak;
import static de.diddiz.util.LoggingUtil.smartLogFallables;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -14,34 +12,33 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.LoggingUtil.smartLogBlockBreak;
import static de.diddiz.util.LoggingUtil.smartLogFallables;
public class BlockBurnLogging extends LoggingListener
{
public BlockBurnLogging(LogBlock lb) {
super(lb);
}
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)) {
smartLogBlockBreak(consumer, new Actor("Fire"), event.getBlock());
smartLogFallables(consumer, new Actor("Fire"), event.getBlock());
}
}
@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);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBurn(BlockBurnEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.FIRE)) {
smartLogBlockBreak(consumer, new Actor("Fire"), event.getBlock());
smartLogFallables(consumer, new Actor("Fire"), event.getBlock());
}
}
@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);
}
}
}
}

View File

@@ -1,9 +1,10 @@
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogging;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
@@ -12,79 +13,80 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.BukkitUtils;
public class BlockPlaceLogging extends LoggingListener
{
public BlockPlaceLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.isLogging;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
if (wcfg != null && wcfg.isLogging(Logging.BLOCKPLACE)) {
final Material type = event.getBlock().getType();
final BlockState before = event.getBlockReplacedState();
final BlockState after = event.getBlockPlaced().getState();
final Actor actor = Actor.actorFromEntity(event.getPlayer());
public class BlockPlaceLogging extends LoggingListener {
public BlockPlaceLogging(LogBlock lb) {
super(lb);
}
//Handle falling blocks
if (BukkitUtils.getRelativeTopFallables().contains(type)) {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
if (wcfg != null && wcfg.isLogging(Logging.BLOCKPLACE)) {
final Material type = event.getBlock().getType();
final BlockState before = event.getBlockReplacedState();
final BlockState after = event.getBlockPlaced().getState();
final Actor actor = Actor.actorFromEntity(event.getPlayer());
// Catch placed blocks overwriting something
if (before.getType() != Material.AIR) {
consumer.queueBlockBreak(actor, before);
}
//Handle falling blocks
if (BukkitUtils.getRelativeTopFallables().contains(type)) {
Location loc = event.getBlock().getLocation();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
// Blocks only fall if they have a chance to start a velocity
if (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) {
while (y > 0 && BukkitUtils.canFall(loc.getWorld(), x, (y - 1), z)) {
y--;
}
}
// If y is 0 then the sand block fell out of the world :(
if (y != 0) {
Location finalLoc = new Location(loc.getWorld(), x, y, z);
// Run this check to avoid false positives
if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
if (finalLoc.getBlock().getType() == Material.AIR || finalLoc.equals(event.getBlock().getLocation())) {
consumer.queueBlockPlace(actor, finalLoc, type.getId(), event.getBlock().getData());
} else {
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getTypeId(), finalLoc.getBlock().getData(), type.getId(), event.getBlock().getData());
}
}
}
return;
}
// Catch placed blocks overwriting something
if (before.getType() != Material.AIR) {
consumer.queueBlockBreak(actor, before);
}
//Sign logging is handled elsewhere
if (wcfg.isLogging(Logging.SIGNTEXT) && (type.getId() == 63 || type.getId() == 68)) return;
Location loc = event.getBlock().getLocation();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
// Blocks only fall if they have a chance to start a velocity
if (event.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR) {
while (y > 0 && BukkitUtils.canFall(loc.getWorld(), x, (y - 1), z)) {
y--;
}
}
// If y is 0 then the sand block fell out of the world :(
if (y != 0) {
Location finalLoc = new Location(loc.getWorld(), x, y, z);
// Run this check to avoid false positives
if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
if (finalLoc.getBlock().getType() == Material.AIR || finalLoc.equals(event.getBlock().getLocation())) {
consumer.queueBlockPlace(actor, finalLoc, type.getId(), event.getBlock().getData());
} else {
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getTypeId(), finalLoc.getBlock().getData(), type.getId(), event.getBlock().getData());
}
}
}
return;
}
//Delay queuing by one tick to allow data to be updated
LogBlock.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(LogBlock.getInstance(), new Runnable()
{
@Override
public void run() {
if (before.getTypeId() == 0)
consumer.queueBlockPlace(actor, after);
else
consumer.queueBlockReplace(actor, before, after);
}
}, 1L);
}
}
//Sign logging is handled elsewhere
if (wcfg.isLogging(Logging.SIGNTEXT) && (type.getId() == 63 || type.getId() == 68)) {
return;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
if (isLogging(event.getPlayer().getWorld(), Logging.BLOCKPLACE))
consumer.queueBlockPlace(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getRelative(event.getBlockFace()).getLocation(), event.getBucket() == Material.WATER_BUCKET ? 9 : 11, (byte)0);
}
//Delay queuing by one tick to allow data to be updated
LogBlock.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(LogBlock.getInstance(), new Runnable() {
@Override
public void run() {
if (before.getTypeId() == 0) {
consumer.queueBlockPlace(actor, after);
} else {
consumer.queueBlockReplace(actor, before, after);
}
}
}, 1L);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
if (isLogging(event.getPlayer().getWorld(), Logging.BLOCKPLACE)) {
consumer.queueBlockPlace(Actor.actorFromEntity(event.getPlayer()), event.getBlockClicked().getRelative(event.getBlockFace()).getLocation(), event.getBucket() == Material.WATER_BUCKET ? 9 : 11, (byte) 0);
}
}
}

View File

@@ -3,50 +3,58 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockSpreadEvent;
public class BlockSpreadLogging extends LoggingListener
{
import static de.diddiz.LogBlock.config.Config.isLogging;
public BlockSpreadLogging(LogBlock lb) {
super(lb);
}
public class BlockSpreadLogging extends LoggingListener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockSpread(BlockSpreadEvent event) {
public BlockSpreadLogging(LogBlock lb) {
super(lb);
}
String name;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockSpread(BlockSpreadEvent event) {
World world = event.getBlock().getWorld();
Material type = event.getSource().getType();
String name;
switch (type) {
case GRASS:
if (!isLogging(world, Logging.GRASSGROWTH)) return;
name = "GrassGrowth";
break;
case MYCEL:
if (!isLogging(world, Logging.MYCELIUMSPREAD)) return;
name = "MyceliumSpread";
break;
case VINE:
if (!isLogging(world, Logging.VINEGROWTH)) return;
name = "VineGrowth";
break;
case RED_MUSHROOM:
case BROWN_MUSHROOM:
if (!isLogging(world, Logging.MUSHROOMSPREAD)) return;
name = "MushroomSpread";
break;
default:
return;
}
World world = event.getBlock().getWorld();
Material type = event.getSource().getType();
consumer.queueBlockReplace(new Actor(name), event.getBlock().getState(), event.getNewState());
}
switch (type) {
case GRASS:
if (!isLogging(world, Logging.GRASSGROWTH)) {
return;
}
name = "GrassGrowth";
break;
case MYCEL:
if (!isLogging(world, Logging.MYCELIUMSPREAD)) {
return;
}
name = "MyceliumSpread";
break;
case VINE:
if (!isLogging(world, Logging.VINEGROWTH)) {
return;
}
name = "VineGrowth";
break;
case RED_MUSHROOM:
case BROWN_MUSHROOM:
if (!isLogging(world, Logging.MUSHROOMSPREAD)) {
return;
}
name = "MushroomSpread";
break;
default:
return;
}
consumer.queueBlockReplace(new Actor(name), event.getBlock().getState(), event.getNewState());
}
}

View File

@@ -3,33 +3,35 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
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;
public class ChatLogging extends LoggingListener
{
public ChatLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.isLogging;
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (isLogging(event.getPlayer().getWorld(), Logging.CHAT))
consumer.queueChat(Actor.actorFromEntity(event.getPlayer()), event.getMessage());
}
public class ChatLogging extends LoggingListener {
public ChatLogging(LogBlock lb) {
super(lb);
}
@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 onPlayerCommandPreprocess(PlayerCommandPreprocessEvent 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) {
consumer.queueChat(new Actor("Console"), "/" + event.getCommand());
}
@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) {
consumer.queueChat(new Actor("Console"), "/" + event.getCommand());
}
}

View File

@@ -1,15 +1,7 @@
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.compareInventories;
import static de.diddiz.util.BukkitUtils.compressInventory;
import static de.diddiz.util.BukkitUtils.getInventoryHolderLocation;
import static de.diddiz.util.BukkitUtils.getInventoryHolderType;
import static de.diddiz.util.BukkitUtils.rawData;
import java.util.HashMap;
import java.util.Map;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import org.bukkit.Location;
import org.bukkit.block.BlockState;
@@ -21,47 +13,55 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import de.diddiz.LogBlock.LogBlock;
public class ChestAccessLogging extends LoggingListener
{
private final Map<HumanEntity, ItemStack[]> containers = new HashMap<HumanEntity, ItemStack[]>();
import java.util.HashMap;
import java.util.Map;
public ChestAccessLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.*;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClose(InventoryCloseEvent event) {
public class ChestAccessLogging extends LoggingListener {
private final Map<HumanEntity, ItemStack[]> containers = new HashMap<HumanEntity, ItemStack[]>();
if (!isLogging(event.getPlayer().getWorld(), Logging.CHESTACCESS)) return;
InventoryHolder holder = event.getInventory().getHolder();
if (holder instanceof BlockState || holder instanceof DoubleChest) {
final HumanEntity player = event.getPlayer();
final ItemStack[] before = containers.get(player);
if (before != null) {
final ItemStack[] after = compressInventory(event.getInventory().getContents());
final ItemStack[] diff = compareInventories(before, after);
final Location loc = getInventoryHolderLocation(holder);
for (final ItemStack item : diff) {
consumer.queueChestAccess(Actor.actorFromEntity(player), loc, loc.getWorld().getBlockTypeIdAt(loc), (short)item.getTypeId(), (short)item.getAmount(), rawData(item));
}
containers.remove(player);
}
}
}
public ChestAccessLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClose(InventoryCloseEvent event) {
if (!isLogging(event.getPlayer().getWorld(), Logging.CHESTACCESS)) return;
if (event.getInventory() != null) {
InventoryHolder holder = event.getInventory().getHolder();
if (holder instanceof BlockState || holder instanceof DoubleChest) {
if (getInventoryHolderType(holder) != 58) {
containers.put(event.getPlayer(), compressInventory(event.getInventory().getContents()));
}
}
}
}
if (!isLogging(event.getPlayer().getWorld(), Logging.CHESTACCESS)) {
return;
}
InventoryHolder holder = event.getInventory().getHolder();
if (holder instanceof BlockState || holder instanceof DoubleChest) {
final HumanEntity player = event.getPlayer();
final ItemStack[] before = containers.get(player);
if (before != null) {
final ItemStack[] after = compressInventory(event.getInventory().getContents());
final ItemStack[] diff = compareInventories(before, after);
final Location loc = getInventoryHolderLocation(holder);
for (final ItemStack item : diff) {
consumer.queueChestAccess(Actor.actorFromEntity(player), loc, loc.getWorld().getBlockTypeIdAt(loc), (short) item.getTypeId(), (short) item.getAmount(), rawData(item));
}
containers.remove(player);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) {
if (!isLogging(event.getPlayer().getWorld(), Logging.CHESTACCESS)) {
return;
}
if (event.getInventory() != null) {
InventoryHolder holder = event.getInventory().getHolder();
if (holder instanceof BlockState || holder instanceof DoubleChest) {
if (getInventoryHolderType(holder) != 58) {
containers.put(event.getPlayer(), compressInventory(event.getInventory().getContents()));
}
}
}
}
}

View File

@@ -3,7 +3,6 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Location;
@@ -16,42 +15,45 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityInteractEvent;
public class CreatureInteractLogging extends LoggingListener
{
public CreatureInteractLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityInteract(EntityInteractEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getEntity().getWorld());
public class CreatureInteractLogging extends LoggingListener {
public CreatureInteractLogging(LogBlock lb) {
super(lb);
}
final EntityType entityType = event.getEntityType();
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityInteract(EntityInteractEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getEntity().getWorld());
// Mobs only
if (event.getEntity() instanceof Player || entityType == null) return;
final EntityType entityType = event.getEntityType();
if (wcfg != null) {
final Block clicked = event.getBlock();
final Material type = clicked.getType();
final int typeId = type.getId();
final byte blockData = clicked.getData();
final Location loc = clicked.getLocation();
// Mobs only
if (event.getEntity() instanceof Player || entityType == null) {
return;
}
switch (type) {
case SOIL:
if (wcfg.isLogging(Logging.CREATURECROPTRAMPLE)) {
// 3 = Dirt ID
consumer.queueBlock(Actor.actorFromEntity(entityType), loc, typeId, 3, blockData);
// Log the crop on top as being broken
Block trampledCrop = clicked.getRelative(BlockFace.UP);
if (BukkitUtils.getCropBlocks().contains(trampledCrop.getType())) {
consumer.queueBlockBreak(new Actor("CreatureTrample"), trampledCrop.getState());
}
}
break;
}
}
}
if (wcfg != null) {
final Block clicked = event.getBlock();
final Material type = clicked.getType();
final int typeId = type.getId();
final byte blockData = clicked.getData();
final Location loc = clicked.getLocation();
switch (type) {
case SOIL:
if (wcfg.isLogging(Logging.CREATURECROPTRAMPLE)) {
// 3 = Dirt ID
consumer.queueBlock(Actor.actorFromEntity(entityType), loc, typeId, 3, blockData);
// Log the crop on top as being broken
Block trampledCrop = clicked.getRelative(BlockFace.UP);
if (BukkitUtils.getCropBlocks().contains(trampledCrop.getType())) {
consumer.queueBlockBreak(new Actor("CreatureTrample"), trampledCrop.getState());
}
}
break;
}
}
}
}

View File

@@ -3,21 +3,22 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.entity.Enderman;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityChangeBlockEvent;
public class EndermenLogging extends LoggingListener
{
public EndermenLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.isLogging;
@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.getTo().getId(), (byte)0); // Figure out how to get the data of the placed block;
}
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.getTo().getId(), (byte) 0); // Figure out how to get the data of the placed block;
}
}
}

View File

@@ -1,105 +1,105 @@
package de.diddiz.LogBlock.listeners;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.logCreeperExplosionsAsPlayerWhoTriggeredThese;
import static de.diddiz.util.BukkitUtils.getContainerBlocks;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Ghast;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Wither;
import org.bukkit.entity.WitherSkull;
import org.bukkit.entity.*;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.projectiles.ProjectileSource;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.logCreeperExplosionsAsPlayerWhoTriggeredThese;
import static de.diddiz.util.BukkitUtils.getContainerBlocks;
public class ExplosionLogging extends LoggingListener
{
public ExplosionLogging(LogBlock lb) {
super(lb);
}
public class ExplosionLogging extends LoggingListener {
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
new Actor("Creeper");
} else if (source instanceof Fireball) {
Fireball fireball = (Fireball) source;
ProjectileSource shooter = fireball.getShooter();
if (shooter == null) {
return;
}
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 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 (!wcfg.isLogging(Logging.MISCEXPLOSION))
return;
}
for (final Block block : event.blockList()) {
final int type = block.getTypeId();
if (wcfg.isLogging(Logging.SIGNTEXT) & (type == 63 || type == 68))
consumer.queueSignBreak(actor, (Sign)block.getState());
else if (wcfg.isLogging(Logging.CHESTACCESS) && (getContainerBlocks().contains(Material.getMaterial(type))))
consumer.queueContainerBreak(actor, block.getState());
else
consumer.queueBlockBreak(actor, block.getState());
}
}
}
@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 {
new Actor("Creeper");
}
} else if (source instanceof Fireball) {
Fireball fireball = (Fireball) source;
ProjectileSource shooter = fireball.getShooter();
if (shooter == null) {
return;
}
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 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 (!wcfg.isLogging(Logging.MISCEXPLOSION)) {
return;
}
}
for (final Block block : event.blockList()) {
final int type = block.getTypeId();
if (wcfg.isLogging(Logging.SIGNTEXT) & (type == 63 || type == 68)) {
consumer.queueSignBreak(actor, (Sign) block.getState());
} else if (wcfg.isLogging(Logging.CHESTACCESS) && (getContainerBlocks().contains(Material.getMaterial(type)))) {
consumer.queueContainerBreak(actor, block.getState());
} else {
consumer.queueBlockBreak(actor, block.getState());
}
}
}
}
}

View File

@@ -3,80 +3,81 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import de.diddiz.LogBlock.config.WorldConfig;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFromToEvent;
public class FluidFlowLogging extends LoggingListener
{
private static final Set<Integer> nonFluidProofBlocks = new HashSet<Integer>(Arrays.asList(27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94, 104, 105, 106));
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public FluidFlowLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getBlock().getWorld());
if (wcfg != null) {
final Block to = event.getToBlock();
final int typeFrom = event.getBlock().getTypeId();
final int typeTo = to.getTypeId();
final boolean canFlow = typeTo == 0 || nonFluidProofBlocks.contains(typeTo);
if (typeFrom == 10 || typeFrom == 11) {
if (canFlow && wcfg.isLogging(Logging.LAVAFLOW)) {
if (isSurroundedByWater(to) && event.getBlock().getData() <= 2)
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 4, (byte)0);
else if (typeTo == 0) {
consumer.queueBlockPlace(new Actor("LavaFlow"), to.getLocation(), 10, (byte)(event.getBlock().getData() + 1));
} else {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 10, (byte)(event.getBlock().getData() + 1));
}
} else if (typeTo == 8 || typeTo == 9) {
if (event.getFace() == BlockFace.DOWN) {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 1, (byte)0);
} else {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 4, (byte)0);
}
}
} else if ((typeFrom == 8 || typeFrom == 9) && wcfg.isLogging(Logging.WATERFLOW)) {
if (typeTo == 0) {
consumer.queueBlockPlace(new Actor("WaterFlow"), to.getLocation(), 8, (byte)(event.getBlock().getData() + 1));
} else if (nonFluidProofBlocks.contains(typeTo)) {
consumer.queueBlockReplace(new Actor("WaterFlow"), to.getState(), 8, (byte)(event.getBlock().getData() + 1));
}
else if (typeTo == 10 || typeTo == 11) {
if (to.getData() == 0) {
consumer.queueBlockReplace(new Actor("WaterFlow"), to.getState(), 49, (byte)0);
} else if (event.getFace() == BlockFace.DOWN) {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 1, (byte)0);
}
}
if (typeTo == 0 || nonFluidProofBlocks.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.getTypeId() == 10 || lower.getTypeId() == 11) {
consumer.queueBlockReplace(new Actor("WaterFlow"), lower.getState(), lower.getData() == 0 ? 49 : 4, (byte)0);
}
}
}
}
}
}
public class FluidFlowLogging extends LoggingListener {
private static final Set<Integer> nonFluidProofBlocks = new HashSet<Integer>(Arrays.asList(27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94, 104, 105, 106));
private static boolean isSurroundedByWater(Block block) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH}) {
final int type = block.getRelative(face).getTypeId();
if (type == 8 || type == 9)
return true;
}
return false;
}
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) {
final Block to = event.getToBlock();
final int typeFrom = event.getBlock().getTypeId();
final int typeTo = to.getTypeId();
final boolean canFlow = typeTo == 0 || nonFluidProofBlocks.contains(typeTo);
if (typeFrom == 10 || typeFrom == 11) {
if (canFlow && wcfg.isLogging(Logging.LAVAFLOW)) {
if (isSurroundedByWater(to) && event.getBlock().getData() <= 2) {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 4, (byte) 0);
} else if (typeTo == 0) {
consumer.queueBlockPlace(new Actor("LavaFlow"), to.getLocation(), 10, (byte) (event.getBlock().getData() + 1));
} else {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 10, (byte) (event.getBlock().getData() + 1));
}
} else if (typeTo == 8 || typeTo == 9) {
if (event.getFace() == BlockFace.DOWN) {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 1, (byte) 0);
} else {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 4, (byte) 0);
}
}
} else if ((typeFrom == 8 || typeFrom == 9) && wcfg.isLogging(Logging.WATERFLOW)) {
if (typeTo == 0) {
consumer.queueBlockPlace(new Actor("WaterFlow"), to.getLocation(), 8, (byte) (event.getBlock().getData() + 1));
} else if (nonFluidProofBlocks.contains(typeTo)) {
consumer.queueBlockReplace(new Actor("WaterFlow"), to.getState(), 8, (byte) (event.getBlock().getData() + 1));
} else if (typeTo == 10 || typeTo == 11) {
if (to.getData() == 0) {
consumer.queueBlockReplace(new Actor("WaterFlow"), to.getState(), 49, (byte) 0);
} else if (event.getFace() == BlockFace.DOWN) {
consumer.queueBlockReplace(new Actor("LavaFlow"), to.getState(), 1, (byte) 0);
}
}
if (typeTo == 0 || nonFluidProofBlocks.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.getTypeId() == 10 || lower.getTypeId() == 11) {
consumer.queueBlockReplace(new Actor("WaterFlow"), lower.getState(), lower.getData() == 0 ? 49 : 4, (byte) 0);
}
}
}
}
}
}
private static boolean isSurroundedByWater(Block block) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH}) {
final int type = block.getRelative(face).getTypeId();
if (type == 8 || type == 9) {
return true;
}
}
return false;
}
}

View File

@@ -1,8 +1,9 @@
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.BukkitUtils;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -13,86 +14,90 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.WorldConfig;
import org.bukkit.entity.EntityType;
public class InteractLogging extends LoggingListener
{
public InteractLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
@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 Material type = clicked.getType();
final int typeId = type.getId();
final byte blockData = clicked.getData();
final Player player = event.getPlayer();
final Location loc = clicked.getLocation();
public class InteractLogging extends LoggingListener {
public InteractLogging(LogBlock lb) {
super(lb);
}
switch (type) {
case LEVER:
case WOOD_BUTTON:
case STONE_BUTTON:
if (wcfg.isLogging(Logging.SWITCHINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
break;
case FENCE_GATE:
case WOODEN_DOOR:
case TRAP_DOOR:
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
break;
case CAKE_BLOCK:
if (wcfg.isLogging(Logging.CAKEEAT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getFoodLevel() < 20)
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
break;
case NOTE_BLOCK:
if (wcfg.isLogging(Logging.NOTEBLOCKINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
break;
case DIODE_BLOCK_OFF:
case DIODE_BLOCK_ON:
if (wcfg.isLogging(Logging.DIODEINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK)
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
break;
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON:
if (wcfg.isLogging(Logging.COMPARATORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case WOOD_PLATE:
case STONE_PLATE:
case IRON_PLATE:
case GOLD_PLATE:
if (wcfg.isLogging(Logging.PRESUREPLATEINTERACT) && event.getAction() == Action.PHYSICAL) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case TRIPWIRE:
if (wcfg.isLogging(Logging.TRIPWIREINTERACT) && event.getAction() == Action.PHYSICAL) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case SOIL:
if (wcfg.isLogging(Logging.CROPTRAMPLE) && event.getAction() == Action.PHYSICAL) {
// 3 = Dirt ID
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, 3, blockData);
// 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());
}
}
break;
}
}
}
@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 Material type = clicked.getType();
final int typeId = type.getId();
final byte blockData = clicked.getData();
final Player player = event.getPlayer();
final Location loc = clicked.getLocation();
switch (type) {
case LEVER:
case WOOD_BUTTON:
case STONE_BUTTON:
if (wcfg.isLogging(Logging.SWITCHINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case FENCE_GATE:
case WOODEN_DOOR:
case TRAP_DOOR:
if (wcfg.isLogging(Logging.DOORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case CAKE_BLOCK:
if (wcfg.isLogging(Logging.CAKEEAT) && event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getFoodLevel() < 20) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case NOTE_BLOCK:
if (wcfg.isLogging(Logging.NOTEBLOCKINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case DIODE_BLOCK_OFF:
case DIODE_BLOCK_ON:
if (wcfg.isLogging(Logging.DIODEINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON:
if (wcfg.isLogging(Logging.COMPARATORINTERACT) && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case WOOD_PLATE:
case STONE_PLATE:
case IRON_PLATE:
case GOLD_PLATE:
if (wcfg.isLogging(Logging.PRESUREPLATEINTERACT) && event.getAction() == Action.PHYSICAL) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case TRIPWIRE:
if (wcfg.isLogging(Logging.TRIPWIREINTERACT) && event.getAction() == Action.PHYSICAL) {
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, typeId, blockData);
}
break;
case SOIL:
if (wcfg.isLogging(Logging.CROPTRAMPLE) && event.getAction() == Action.PHYSICAL) {
// 3 = Dirt ID
consumer.queueBlock(Actor.actorFromEntity(player), loc, typeId, 3, blockData);
// 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());
}
}
break;
}
}
}
}

View File

@@ -3,10 +3,7 @@ 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.LogKillsLevel;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.LogBlock.config.Config.logEnvironmentalKills;
import static de.diddiz.LogBlock.config.Config.logKillsLevel;
import de.diddiz.LogBlock.config.Config.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
@@ -17,34 +14,37 @@ 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);
}
public class KillLogging extends LoggingListener {
@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 (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);
}
}
}
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 (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);
}
}
}
}

View File

@@ -3,24 +3,24 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.LoggingUtil.smartLogBlockBreak;
import static de.diddiz.util.LoggingUtil.smartLogFallables;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.LeavesDecayEvent;
public class LeavesDecayLogging extends LoggingListener
{
public LeavesDecayLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.LoggingUtil.smartLogBlockBreak;
import static de.diddiz.util.LoggingUtil.smartLogFallables;
@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());
}
}
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());
}
}
}

View File

@@ -3,23 +3,24 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFadeEvent;
public class LockedChestDecayLogging extends LoggingListener
{
public LockedChestDecayLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.isLogging;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFade(BlockFadeEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.LOCKEDCHESTDECAY)) {
final int type = event.getBlock().getTypeId();
if (type == 95)
consumer.queueBlockReplace(new Actor("LockedChestDecay"), event.getBlock().getState(), event.getNewState());
}
}
public class LockedChestDecayLogging extends LoggingListener {
public LockedChestDecayLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFade(BlockFadeEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.LOCKEDCHESTDECAY)) {
final int type = event.getBlock().getTypeId();
if (type == 95) {
consumer.queueBlockReplace(new Actor("LockedChestDecay"), event.getBlock().getState(), event.getNewState());
}
}
}
}

View File

@@ -1,14 +1,13 @@
package de.diddiz.LogBlock.listeners;
import org.bukkit.event.Listener;
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 class LoggingListener implements Listener {
protected final Consumer consumer;
public LoggingListener(LogBlock lb) {
consumer = lb.getConsumer();
}
public LoggingListener(LogBlock lb) {
consumer = lb.getConsumer();
}
}

View File

@@ -1,24 +1,23 @@
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.LogBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import de.diddiz.LogBlock.LogBlock;
public class PlayerInfoLogging extends LoggingListener
{
public PlayerInfoLogging(LogBlock lb) {
super(lb);
}
public class PlayerInfoLogging extends LoggingListener {
public PlayerInfoLogging(LogBlock lb) {
super(lb);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
consumer.queueJoin(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
consumer.queueJoin(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
consumer.queueLeave(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
consumer.queueLeave(event.getPlayer());
}
}

View File

@@ -3,21 +3,21 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.SignChangeEvent;
public class SignChangeLogging extends LoggingListener
{
public SignChangeLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.isLogging;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSignChange(SignChangeEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.SIGNTEXT))
consumer.queueSignPlace(Actor.actorFromEntity(event.getPlayer()), event.getBlock().getLocation(), event.getBlock().getTypeId(), event.getBlock().getData(), event.getLines());
}
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)) {
consumer.queueSignPlace(Actor.actorFromEntity(event.getPlayer()), event.getBlock().getLocation(), event.getBlock().getTypeId(), event.getBlock().getData(), event.getLines());
}
}
}

View File

@@ -3,23 +3,24 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFadeEvent;
public class SnowFadeLogging extends LoggingListener
{
public SnowFadeLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.isLogging;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFade(BlockFadeEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFADE)) {
final int type = event.getBlock().getTypeId();
if (type == 78 || type == 79)
consumer.queueBlockReplace(new Actor("SnowFade"), event.getBlock().getState(), event.getNewState());
}
}
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 int type = event.getBlock().getTypeId();
if (type == 78 || type == 79) {
consumer.queueBlockReplace(new Actor("SnowFade"), event.getBlock().getState(), event.getNewState());
}
}
}
}

View File

@@ -3,17 +3,16 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.isLogging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.LeavesDecayEvent;
public class SnowFormLogging extends LoggingListener
{
public SnowFormLogging(LogBlock lb) {
super(lb);
}
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 onLeavesDecay(LeavesDecayEvent event) {
@@ -21,12 +20,13 @@ public class SnowFormLogging extends LoggingListener
// consumer.queueBlockBreak("LeavesDecay", event.getBlock().getState());
// }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFORM)) {
final int type = event.getNewState().getTypeId();
if (type == 78 || type == 79)
consumer.queueBlockReplace(new Actor("SnowForm"), event.getBlock().getState(), event.getNewState());
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockForm(BlockFormEvent event) {
if (isLogging(event.getBlock().getWorld(), Logging.SNOWFORM)) {
final int type = event.getNewState().getTypeId();
if (type == 78 || type == 79) {
consumer.queueBlockReplace(new Actor("SnowForm"), event.getBlock().getState(), event.getNewState());
}
}
}
}

View File

@@ -3,35 +3,38 @@ package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
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;
public class StructureGrowLogging extends LoggingListener
{
public StructureGrowLogging(LogBlock lb) {
super(lb);
}
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
final WorldConfig wcfg = getWorldConfig(event.getWorld());
if (wcfg != null) {
final Actor actor;
if (event.getPlayer() != null) {
if (!wcfg.isLogging(Logging.BONEMEALSTRUCTUREGROW))
return;
actor = Actor.actorFromEntity(event.getPlayer());
} else {
if (!wcfg.isLogging(Logging.NATURALSTRUCTUREGROW))
return;
actor = new Actor("NaturalGrow");
}
for (final BlockState state : event.getBlocks())
consumer.queueBlockReplace(actor, state.getBlock().getState(), state);
}
}
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) {
final Actor actor;
if (event.getPlayer() != null) {
if (!wcfg.isLogging(Logging.BONEMEALSTRUCTUREGROW)) {
return;
}
actor = Actor.actorFromEntity(event.getPlayer());
} else {
if (!wcfg.isLogging(Logging.NATURALSTRUCTUREGROW)) {
return;
}
actor = new Actor("NaturalGrow");
}
for (final BlockState state : event.getBlocks()) {
consumer.queueBlockReplace(actor, state.getBlock().getState(), state);
}
}
}
}

View File

@@ -1,13 +1,6 @@
package de.diddiz.LogBlock.listeners;
import de.diddiz.LogBlock.CommandsHandler;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.QueryParams;
import de.diddiz.LogBlock.Session;
import de.diddiz.LogBlock.Tool;
import de.diddiz.LogBlock.ToolBehavior;
import de.diddiz.LogBlock.ToolData;
import de.diddiz.LogBlock.ToolMode;
import de.diddiz.LogBlock.*;
import de.diddiz.worldedit.RegionContainer;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
@@ -28,104 +21,104 @@ 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 class ToolListener implements Listener {
private final CommandsHandler handler;
private final LogBlock logblock;
public ToolListener(LogBlock logblock) {
this.logblock = logblock;
handler = logblock.getCommandsHandler();
}
public ToolListener(LogBlock logblock) {
this.logblock = logblock;
handler = logblock.getCommandsHandler();
}
@EventHandler(ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getMaterial() != null) {
final Action action = event.getAction();
final int type = event.getMaterial().getId();
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;
params.loc = null;
params.sel = null;
if (behavior == ToolBehavior.BLOCK)
params.setLocation(block.getRelative(event.getBlockFace()).getLocation());
else if ((block.getTypeId() != 54 && block.getTypeId() != 146) || tool.params.radius != 0)
params.setLocation(block.getLocation());
else {
if (logblock.getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
if (block.getRelative(face).getTypeId() == block.getTypeId()) {
params.setSelection(RegionContainer.fromCorners(event.getPlayer().getWorld(),
block.getLocation(), block.getRelative(face).getLocation()));
}
}
}
if (params.sel == null) {
params.setLocation(block.getLocation());
}
}
try {
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);
}
}
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getMaterial() != null) {
final Action action = event.getAction();
final int type = event.getMaterial().getId();
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;
params.loc = null;
params.sel = null;
if (behavior == ToolBehavior.BLOCK) {
params.setLocation(block.getRelative(event.getBlockFace()).getLocation());
} else if ((block.getTypeId() != 54 && block.getTypeId() != 146) || tool.params.radius != 0) {
params.setLocation(block.getLocation());
} else {
if (logblock.getServer().getPluginManager().isPluginEnabled("WorldEdit")) {
for (final BlockFace face : new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST}) {
if (block.getRelative(face).getTypeId() == block.getTypeId()) {
params.setSelection(RegionContainer.fromCorners(event.getPlayer().getWorld(),
block.getLocation(), block.getRelative(face).getLocation()));
}
}
}
if (params.sel == null) {
params.setLocation(block.getLocation());
}
}
try {
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);
}
}
}
}
@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;
player.getInventory().removeItem(new ItemStack(tool.item, 1));
player.sendMessage(ChatColor.GREEN + "Tool disabled.");
}
}
}
}
@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;
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 int item = event.getItemDrop().getItemStack().getTypeId();
if (item == tool.item && toolData.enabled && !tool.canDrop) {
player.sendMessage(ChatColor.RED + "You cannot drop this tool.");
event.setCancelled(true);
}
}
}
}
@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 int item = event.getItemDrop().getItemStack().getTypeId();
if (item == tool.item && toolData.enabled && !tool.canDrop) {
player.sendMessage(ChatColor.RED + "You cannot drop this tool.");
event.setCancelled(true);
}
}
}
}
}

View File

@@ -10,15 +10,15 @@ 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);
}
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.getTo().getId(), event.getData()); // Wither walked through a block.
}
@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.getTo().getId(), event.getData()); // Wither walked through a block.
}
}
}

View File

@@ -2,35 +2,33 @@ package de.diddiz.util;
import java.util.List;
public class Block
{
private int block;
private int data;
public class Block {
private int block;
private int data;
/**
* @param block The id of the block
* @param data The data for the block, -1 for any data
*
*/
public Block(int block, int data) {
this.block = block;
this.data = data;
}
/**
* @param block The id of the block
* @param data The data for the block, -1 for any data
*/
public Block(int block, int data) {
this.block = block;
this.data = data;
}
public int getBlock() {
return this.block;
}
public int getBlock() {
return this.block;
}
public int getData() {
return this.data;
}
public int getData() {
return this.data;
}
public static boolean inList(List<Block> types, int blockID) {
for (Block block : types) {
if (block.getBlock() == blockID) {
return true;
}
}
return false;
}
public static boolean inList(List<Block> types, int blockID) {
for (Block block : types) {
if (block.getBlock() == blockID) {
return true;
}
}
return false;
}
}

View File

@@ -1,22 +1,6 @@
package de.diddiz.util;
import static de.diddiz.util.MaterialName.materialName;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
@@ -28,405 +12,424 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
public class BukkitUtils
{
private static final Set<Set<Integer>> blockEquivalents;
private static final Set<Material> relativeBreakable;
private static final Set<Material> relativeTopBreakable;
private static final Set<Material> relativeTopFallables;
private static final Set<Material> fallingEntityKillers;
import java.io.File;
import java.util.*;
private static final Set<Material> cropBlocks;
private static final Set<Material> containerBlocks;
import static de.diddiz.util.MaterialName.materialName;
private static final Map<EntityType,Integer> projectileItems;
public class BukkitUtils {
private static final Set<Set<Integer>> blockEquivalents;
private static final Set<Material> relativeBreakable;
private static final Set<Material> relativeTopBreakable;
private static final Set<Material> relativeTopFallables;
private static final Set<Material> fallingEntityKillers;
static {
blockEquivalents = new HashSet<Set<Integer>>(7);
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(2, 3, 60)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(8, 9, 79)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(10, 11)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(61, 62)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(73, 74)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(75, 76)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(93, 94)));
private static final Set<Material> cropBlocks;
private static final Set<Material> containerBlocks;
// Blocks that break when they are attached to a block
relativeBreakable = new HashSet<Material>(11);
relativeBreakable.add(Material.WALL_SIGN);
relativeBreakable.add(Material.LADDER);
relativeBreakable.add(Material.STONE_BUTTON);
relativeBreakable.add(Material.WOOD_BUTTON);
relativeBreakable.add(Material.REDSTONE_TORCH_ON);
relativeBreakable.add(Material.REDSTONE_TORCH_OFF);
relativeBreakable.add(Material.LEVER);
relativeBreakable.add(Material.TORCH);
relativeBreakable.add(Material.TRAP_DOOR);
relativeBreakable.add(Material.TRIPWIRE_HOOK);
relativeBreakable.add(Material.COCOA);
private static final Map<EntityType, Integer> projectileItems;
// Blocks that break when they are on top of a block
relativeTopBreakable = new HashSet<Material>(33);
relativeTopBreakable.add(Material.SAPLING);
relativeTopBreakable.add(Material.LONG_GRASS);
relativeTopBreakable.add(Material.DEAD_BUSH);
relativeTopBreakable.add(Material.YELLOW_FLOWER);
relativeTopBreakable.add(Material.RED_ROSE);
relativeTopBreakable.add(Material.BROWN_MUSHROOM);
relativeTopBreakable.add(Material.RED_MUSHROOM);
relativeTopBreakable.add(Material.CROPS);
relativeTopBreakable.add(Material.POTATO);
relativeTopBreakable.add(Material.CARROT);
relativeTopBreakable.add(Material.WATER_LILY);
relativeTopBreakable.add(Material.CACTUS);
relativeTopBreakable.add(Material.SUGAR_CANE_BLOCK);
relativeTopBreakable.add(Material.FLOWER_POT);
relativeTopBreakable.add(Material.POWERED_RAIL);
relativeTopBreakable.add(Material.DETECTOR_RAIL);
relativeTopBreakable.add(Material.ACTIVATOR_RAIL);
relativeTopBreakable.add(Material.RAILS);
relativeTopBreakable.add(Material.REDSTONE_WIRE);
relativeTopBreakable.add(Material.SIGN_POST);
relativeTopBreakable.add(Material.STONE_PLATE);
relativeTopBreakable.add(Material.WOOD_PLATE);
relativeTopBreakable.add(Material.IRON_PLATE);
relativeTopBreakable.add(Material.GOLD_PLATE);
relativeTopBreakable.add(Material.SNOW);
relativeTopBreakable.add(Material.DIODE_BLOCK_ON);
relativeTopBreakable.add(Material.DIODE_BLOCK_OFF);
relativeTopBreakable.add(Material.REDSTONE_COMPARATOR_ON);
relativeTopBreakable.add(Material.REDSTONE_COMPARATOR_OFF);
relativeTopBreakable.add(Material.WOODEN_DOOR);
relativeTopBreakable.add(Material.IRON_DOOR_BLOCK);
relativeTopBreakable.add(Material.CARPET);
relativeTopBreakable.add(Material.DOUBLE_PLANT);
static {
blockEquivalents = new HashSet<Set<Integer>>(7);
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(2, 3, 60)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(8, 9, 79)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(10, 11)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(61, 62)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(73, 74)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(75, 76)));
blockEquivalents.add(new HashSet<Integer>(Arrays.asList(93, 94)));
// Blocks that fall
relativeTopFallables = new HashSet<Material>(4);
relativeTopFallables.add(Material.SAND);
relativeTopFallables.add(Material.GRAVEL);
relativeTopFallables.add(Material.DRAGON_EGG);
relativeTopFallables.add(Material.ANVIL);
// Blocks that break when they are attached to a block
relativeBreakable = new HashSet<Material>(11);
relativeBreakable.add(Material.WALL_SIGN);
relativeBreakable.add(Material.LADDER);
relativeBreakable.add(Material.STONE_BUTTON);
relativeBreakable.add(Material.WOOD_BUTTON);
relativeBreakable.add(Material.REDSTONE_TORCH_ON);
relativeBreakable.add(Material.REDSTONE_TORCH_OFF);
relativeBreakable.add(Material.LEVER);
relativeBreakable.add(Material.TORCH);
relativeBreakable.add(Material.TRAP_DOOR);
relativeBreakable.add(Material.TRIPWIRE_HOOK);
relativeBreakable.add(Material.COCOA);
// Blocks that break falling entities
fallingEntityKillers = new HashSet<Material>(32);
fallingEntityKillers.add(Material.SIGN_POST);
fallingEntityKillers.add(Material.WALL_SIGN);
fallingEntityKillers.add(Material.STONE_PLATE);
fallingEntityKillers.add(Material.WOOD_PLATE);
fallingEntityKillers.add(Material.IRON_PLATE);
fallingEntityKillers.add(Material.GOLD_PLATE);
fallingEntityKillers.add(Material.SAPLING);
fallingEntityKillers.add(Material.YELLOW_FLOWER);
fallingEntityKillers.add(Material.RED_ROSE);
fallingEntityKillers.add(Material.CROPS);
fallingEntityKillers.add(Material.CARROT);
fallingEntityKillers.add(Material.POTATO);
fallingEntityKillers.add(Material.RED_MUSHROOM);
fallingEntityKillers.add(Material.BROWN_MUSHROOM);
fallingEntityKillers.add(Material.STEP);
fallingEntityKillers.add(Material.WOOD_STEP);
fallingEntityKillers.add(Material.TORCH);
fallingEntityKillers.add(Material.FLOWER_POT);
fallingEntityKillers.add(Material.POWERED_RAIL);
fallingEntityKillers.add(Material.DETECTOR_RAIL);
fallingEntityKillers.add(Material.ACTIVATOR_RAIL);
fallingEntityKillers.add(Material.RAILS);
fallingEntityKillers.add(Material.LEVER);
fallingEntityKillers.add(Material.REDSTONE_WIRE);
fallingEntityKillers.add(Material.REDSTONE_TORCH_ON);
fallingEntityKillers.add(Material.REDSTONE_TORCH_OFF);
fallingEntityKillers.add(Material.DIODE_BLOCK_ON);
fallingEntityKillers.add(Material.DIODE_BLOCK_OFF);
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_ON);
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_OFF);
fallingEntityKillers.add(Material.DAYLIGHT_DETECTOR);
fallingEntityKillers.add(Material.CARPET);
// Blocks that break when they are on top of a block
relativeTopBreakable = new HashSet<Material>(33);
relativeTopBreakable.add(Material.SAPLING);
relativeTopBreakable.add(Material.LONG_GRASS);
relativeTopBreakable.add(Material.DEAD_BUSH);
relativeTopBreakable.add(Material.YELLOW_FLOWER);
relativeTopBreakable.add(Material.RED_ROSE);
relativeTopBreakable.add(Material.BROWN_MUSHROOM);
relativeTopBreakable.add(Material.RED_MUSHROOM);
relativeTopBreakable.add(Material.CROPS);
relativeTopBreakable.add(Material.POTATO);
relativeTopBreakable.add(Material.CARROT);
relativeTopBreakable.add(Material.WATER_LILY);
relativeTopBreakable.add(Material.CACTUS);
relativeTopBreakable.add(Material.SUGAR_CANE_BLOCK);
relativeTopBreakable.add(Material.FLOWER_POT);
relativeTopBreakable.add(Material.POWERED_RAIL);
relativeTopBreakable.add(Material.DETECTOR_RAIL);
relativeTopBreakable.add(Material.ACTIVATOR_RAIL);
relativeTopBreakable.add(Material.RAILS);
relativeTopBreakable.add(Material.REDSTONE_WIRE);
relativeTopBreakable.add(Material.SIGN_POST);
relativeTopBreakable.add(Material.STONE_PLATE);
relativeTopBreakable.add(Material.WOOD_PLATE);
relativeTopBreakable.add(Material.IRON_PLATE);
relativeTopBreakable.add(Material.GOLD_PLATE);
relativeTopBreakable.add(Material.SNOW);
relativeTopBreakable.add(Material.DIODE_BLOCK_ON);
relativeTopBreakable.add(Material.DIODE_BLOCK_OFF);
relativeTopBreakable.add(Material.REDSTONE_COMPARATOR_ON);
relativeTopBreakable.add(Material.REDSTONE_COMPARATOR_OFF);
relativeTopBreakable.add(Material.WOODEN_DOOR);
relativeTopBreakable.add(Material.IRON_DOOR_BLOCK);
relativeTopBreakable.add(Material.CARPET);
relativeTopBreakable.add(Material.DOUBLE_PLANT);
// Crop Blocks
cropBlocks = new HashSet<Material>(5);
cropBlocks.add(Material.CROPS);
cropBlocks.add(Material.MELON_STEM);
cropBlocks.add(Material.PUMPKIN_STEM);
cropBlocks.add(Material.CARROT);
cropBlocks.add(Material.POTATO);
// Blocks that fall
relativeTopFallables = new HashSet<Material>(4);
relativeTopFallables.add(Material.SAND);
relativeTopFallables.add(Material.GRAVEL);
relativeTopFallables.add(Material.DRAGON_EGG);
relativeTopFallables.add(Material.ANVIL);
// Container Blocks
containerBlocks = new HashSet<Material>(6);
containerBlocks.add(Material.CHEST);
containerBlocks.add(Material.TRAPPED_CHEST);
containerBlocks.add(Material.DISPENSER);
containerBlocks.add(Material.DROPPER);
containerBlocks.add(Material.HOPPER);
containerBlocks.add(Material.BREWING_STAND);
containerBlocks.add(Material.FURNACE);
containerBlocks.add(Material.BURNING_FURNACE);
containerBlocks.add(Material.BEACON);
// Doesn't actually have a block inventory
// containerBlocks.add(Material.ENDER_CHEST);
// Blocks that break falling entities
fallingEntityKillers = new HashSet<Material>(32);
fallingEntityKillers.add(Material.SIGN_POST);
fallingEntityKillers.add(Material.WALL_SIGN);
fallingEntityKillers.add(Material.STONE_PLATE);
fallingEntityKillers.add(Material.WOOD_PLATE);
fallingEntityKillers.add(Material.IRON_PLATE);
fallingEntityKillers.add(Material.GOLD_PLATE);
fallingEntityKillers.add(Material.SAPLING);
fallingEntityKillers.add(Material.YELLOW_FLOWER);
fallingEntityKillers.add(Material.RED_ROSE);
fallingEntityKillers.add(Material.CROPS);
fallingEntityKillers.add(Material.CARROT);
fallingEntityKillers.add(Material.POTATO);
fallingEntityKillers.add(Material.RED_MUSHROOM);
fallingEntityKillers.add(Material.BROWN_MUSHROOM);
fallingEntityKillers.add(Material.STEP);
fallingEntityKillers.add(Material.WOOD_STEP);
fallingEntityKillers.add(Material.TORCH);
fallingEntityKillers.add(Material.FLOWER_POT);
fallingEntityKillers.add(Material.POWERED_RAIL);
fallingEntityKillers.add(Material.DETECTOR_RAIL);
fallingEntityKillers.add(Material.ACTIVATOR_RAIL);
fallingEntityKillers.add(Material.RAILS);
fallingEntityKillers.add(Material.LEVER);
fallingEntityKillers.add(Material.REDSTONE_WIRE);
fallingEntityKillers.add(Material.REDSTONE_TORCH_ON);
fallingEntityKillers.add(Material.REDSTONE_TORCH_OFF);
fallingEntityKillers.add(Material.DIODE_BLOCK_ON);
fallingEntityKillers.add(Material.DIODE_BLOCK_OFF);
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_ON);
fallingEntityKillers.add(Material.REDSTONE_COMPARATOR_OFF);
fallingEntityKillers.add(Material.DAYLIGHT_DETECTOR);
fallingEntityKillers.add(Material.CARPET);
// It doesn't seem like you could injure people with some of these, but they exist, so....
projectileItems = new EnumMap<EntityType,Integer>(EntityType.class);
projectileItems.put(EntityType.ARROW,262);
projectileItems.put(EntityType.EGG,344);
projectileItems.put(EntityType.ENDER_PEARL,368);
projectileItems.put(EntityType.SMALL_FIREBALL,385); // Fire charge
projectileItems.put(EntityType.FIREBALL,385); // Fire charge
projectileItems.put(EntityType.FISHING_HOOK,346);
projectileItems.put(EntityType.SNOWBALL,332);
projectileItems.put(EntityType.SPLASH_POTION,373);
projectileItems.put(EntityType.THROWN_EXP_BOTTLE,384);
projectileItems.put(EntityType.WITHER_SKULL,397);
// Crop Blocks
cropBlocks = new HashSet<Material>(5);
cropBlocks.add(Material.CROPS);
cropBlocks.add(Material.MELON_STEM);
cropBlocks.add(Material.PUMPKIN_STEM);
cropBlocks.add(Material.CARROT);
cropBlocks.add(Material.POTATO);
}
// Container Blocks
containerBlocks = new HashSet<Material>(6);
containerBlocks.add(Material.CHEST);
containerBlocks.add(Material.TRAPPED_CHEST);
containerBlocks.add(Material.DISPENSER);
containerBlocks.add(Material.DROPPER);
containerBlocks.add(Material.HOPPER);
containerBlocks.add(Material.BREWING_STAND);
containerBlocks.add(Material.FURNACE);
containerBlocks.add(Material.BURNING_FURNACE);
containerBlocks.add(Material.BEACON);
// Doesn't actually have a block inventory
// containerBlocks.add(Material.ENDER_CHEST);
private static final BlockFace[] relativeBlockFaces = new BlockFace[] {
BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN
};
// It doesn't seem like you could injure people with some of these, but they exist, so....
projectileItems = new EnumMap<EntityType, Integer>(EntityType.class);
projectileItems.put(EntityType.ARROW, 262);
projectileItems.put(EntityType.EGG, 344);
projectileItems.put(EntityType.ENDER_PEARL, 368);
projectileItems.put(EntityType.SMALL_FIREBALL, 385); // Fire charge
projectileItems.put(EntityType.FIREBALL, 385); // Fire charge
projectileItems.put(EntityType.FISHING_HOOK, 346);
projectileItems.put(EntityType.SNOWBALL, 332);
projectileItems.put(EntityType.SPLASH_POTION, 373);
projectileItems.put(EntityType.THROWN_EXP_BOTTLE, 384);
projectileItems.put(EntityType.WITHER_SKULL, 397);
/**
* Returns a list of block locations around the block that are of the type specified by the integer list parameter
*
* @param block
* @param type
* @return List of block locations around the block that are of the type specified by the integer list parameter
*/
public static List<Location> getBlocksNearby(org.bukkit.block.Block block, Set<Material> type) {
ArrayList<Location> blocks = new ArrayList<Location>();
for (BlockFace blockFace : relativeBlockFaces) {
if (type.contains(block.getRelative(blockFace).getType())) {
blocks.add(block.getRelative(blockFace).getLocation());
}
}
return blocks;
}
}
public static boolean isTop(Material mat, byte data) {
private static final BlockFace[] relativeBlockFaces = new BlockFace[]{
BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.DOWN
};
switch (mat) {
case DOUBLE_PLANT:
return data > 5;
case IRON_DOOR_BLOCK:
case WOODEN_DOOR:
return data == 8 || data == 9;
default:
return false;
}
}
/**
* Returns a list of block locations around the block that are of the type specified by the integer list parameter
*
* @param block
* @param type
* @return List of block locations around the block that are of the type specified by the integer list parameter
*/
public static List<Location> getBlocksNearby(org.bukkit.block.Block block, Set<Material> type) {
ArrayList<Location> blocks = new ArrayList<Location>();
for (BlockFace blockFace : relativeBlockFaces) {
if (type.contains(block.getRelative(blockFace).getType())) {
blocks.add(block.getRelative(blockFace).getLocation());
}
}
return blocks;
}
public static int getInventoryHolderType(InventoryHolder holder) {
if (holder instanceof DoubleChest) {
return ((DoubleChest)holder).getLocation().getBlock().getTypeId();
} else if (holder instanceof BlockState) {
return ((BlockState)holder).getTypeId();
} else {
return -1;
}
}
public static boolean isTop(Material mat, byte data) {
public static Location getInventoryHolderLocation(InventoryHolder holder) {
if (holder instanceof DoubleChest) {
return ((DoubleChest)holder).getLocation();
} else if (holder instanceof BlockState) {
return ((BlockState)holder).getLocation();
} else {
return null;
}
}
switch (mat) {
case DOUBLE_PLANT:
return data > 5;
case IRON_DOOR_BLOCK:
case WOODEN_DOOR:
return data == 8 || data == 9;
default:
return false;
}
}
public static ItemStack[] compareInventories(ItemStack[] items1, ItemStack[] items2) {
final ItemStackComparator comperator = new ItemStackComparator();
final ArrayList<ItemStack> diff = new ArrayList<ItemStack>();
final int l1 = items1.length, l2 = items2.length;
int c1 = 0, c2 = 0;
while (c1 < l1 || c2 < l2) {
if (c1 >= l1) {
diff.add(items2[c2]);
c2++;
continue;
}
if (c2 >= l2) {
items1[c1].setAmount(items1[c1].getAmount() * -1);
diff.add(items1[c1]);
c1++;
continue;
}
final int comp = comperator.compare(items1[c1], items2[c2]);
if (comp < 0) {
items1[c1].setAmount(items1[c1].getAmount() * -1);
diff.add(items1[c1]);
c1++;
} else if (comp > 0) {
diff.add(items2[c2]);
c2++;
} else {
final int amount = items2[c2].getAmount() - items1[c1].getAmount();
if (amount != 0) {
items1[c1].setAmount(amount);
diff.add(items1[c1]);
}
c1++;
c2++;
}
}
return diff.toArray(new ItemStack[diff.size()]);
}
public static int getInventoryHolderType(InventoryHolder holder) {
if (holder instanceof DoubleChest) {
return ((DoubleChest) holder).getLocation().getBlock().getTypeId();
} else if (holder instanceof BlockState) {
return ((BlockState) holder).getTypeId();
} else {
return -1;
}
}
public static ItemStack[] compressInventory(ItemStack[] items) {
final ArrayList<ItemStack> compressed = new ArrayList<ItemStack>();
for (final ItemStack item : items)
if (item != null) {
final int type = item.getTypeId();
final short data = rawData(item);
boolean found = false;
for (final ItemStack item2 : compressed)
if (type == item2.getTypeId() && data == rawData(item2)) {
item2.setAmount(item2.getAmount() + item.getAmount());
found = true;
break;
}
if (!found)
compressed.add(new ItemStack(type, item.getAmount(), data));
}
Collections.sort(compressed, new ItemStackComparator());
return compressed.toArray(new ItemStack[compressed.size()]);
}
public static Location getInventoryHolderLocation(InventoryHolder holder) {
if (holder instanceof DoubleChest) {
return ((DoubleChest) holder).getLocation();
} else if (holder instanceof BlockState) {
return ((BlockState) holder).getLocation();
} else {
return null;
}
}
public static boolean equalTypes(int type1, int type2) {
if (type1 == type2)
return true;
for (final Set<Integer> equivalent : blockEquivalents)
if (equivalent.contains(type1) && equivalent.contains(type2))
return true;
return false;
}
public static ItemStack[] compareInventories(ItemStack[] items1, ItemStack[] items2) {
final ItemStackComparator comperator = new ItemStackComparator();
final ArrayList<ItemStack> diff = new ArrayList<ItemStack>();
final int l1 = items1.length, l2 = items2.length;
int c1 = 0, c2 = 0;
while (c1 < l1 || c2 < l2) {
if (c1 >= l1) {
diff.add(items2[c2]);
c2++;
continue;
}
if (c2 >= l2) {
items1[c1].setAmount(items1[c1].getAmount() * -1);
diff.add(items1[c1]);
c1++;
continue;
}
final int comp = comperator.compare(items1[c1], items2[c2]);
if (comp < 0) {
items1[c1].setAmount(items1[c1].getAmount() * -1);
diff.add(items1[c1]);
c1++;
} else if (comp > 0) {
diff.add(items2[c2]);
c2++;
} else {
final int amount = items2[c2].getAmount() - items1[c1].getAmount();
if (amount != 0) {
items1[c1].setAmount(amount);
diff.add(items1[c1]);
}
c1++;
c2++;
}
}
return diff.toArray(new ItemStack[diff.size()]);
}
public static String friendlyWorldname(String worldName) {
return new File(worldName).getName();
}
public static ItemStack[] compressInventory(ItemStack[] items) {
final ArrayList<ItemStack> compressed = new ArrayList<ItemStack>();
for (final ItemStack item : items) {
if (item != null) {
final int type = item.getTypeId();
final short data = rawData(item);
boolean found = false;
for (final ItemStack item2 : compressed) {
if (type == item2.getTypeId() && data == rawData(item2)) {
item2.setAmount(item2.getAmount() + item.getAmount());
found = true;
break;
}
}
if (!found) {
compressed.add(new ItemStack(type, item.getAmount(), data));
}
}
}
Collections.sort(compressed, new ItemStackComparator());
return compressed.toArray(new ItemStack[compressed.size()]);
}
public static Set<Set<Integer>> getBlockEquivalents() {
return blockEquivalents;
}
public static boolean equalTypes(int type1, int type2) {
if (type1 == type2) {
return true;
}
for (final Set<Integer> equivalent : blockEquivalents) {
if (equivalent.contains(type1) && equivalent.contains(type2)) {
return true;
}
}
return false;
}
public static Set<Material> getRelativeBreakables() {
return relativeBreakable;
}
public static String friendlyWorldname(String worldName) {
return new File(worldName).getName();
}
public static Set<Material> getRelativeTopBreakabls() {
return relativeTopBreakable;
}
public static Set<Set<Integer>> getBlockEquivalents() {
return blockEquivalents;
}
public static Set<Material> getRelativeTopFallables() {
return relativeTopFallables;
}
public static Set<Material> getRelativeBreakables() {
return relativeBreakable;
}
public static Set<Material> getFallingEntityKillers() {
return fallingEntityKillers;
}
public static Set<Material> getRelativeTopBreakabls() {
return relativeTopBreakable;
}
public static Set<Material> getCropBlocks() {
return cropBlocks;
}
public static Set<Material> getRelativeTopFallables() {
return relativeTopFallables;
}
public static Set<Material> getContainerBlocks() {
return containerBlocks;
}
public static Set<Material> getFallingEntityKillers() {
return fallingEntityKillers;
}
public static String entityName(Entity entity) {
if (entity instanceof Player)
return ((Player)entity).getName();
if (entity instanceof TNTPrimed)
return "TNT";
return entity.getClass().getSimpleName().substring(5);
}
public static Set<Material> getCropBlocks() {
return cropBlocks;
}
public static void giveTool(Player player, int type) {
final Inventory inv = player.getInventory();
if (inv.contains(type))
player.sendMessage(ChatColor.RED + "You have already a " + materialName(type));
else {
final int free = inv.firstEmpty();
if (free >= 0) {
if (player.getItemInHand() != null && player.getItemInHand().getTypeId() != 0)
inv.setItem(free, player.getItemInHand());
player.setItemInHand(new ItemStack(type, 1));
player.sendMessage(ChatColor.GREEN + "Here's your " + materialName(type));
} else
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
}
}
public static Set<Material> getContainerBlocks() {
return containerBlocks;
}
public static short rawData(ItemStack item) {
return item.getType() != null ? item.getData() != null ? item.getDurability() : 0 : 0;
}
public static String entityName(Entity entity) {
if (entity instanceof Player) {
return ((Player) entity).getName();
}
if (entity instanceof TNTPrimed) {
return "TNT";
}
return entity.getClass().getSimpleName().substring(5);
}
public static int saveSpawnHeight(Location loc) {
final World world = loc.getWorld();
final Chunk chunk = world.getChunkAt(loc);
if (!world.isChunkLoaded(chunk))
world.loadChunk(chunk);
final int x = loc.getBlockX(), z = loc.getBlockZ();
int y = loc.getBlockY();
boolean lower = world.getBlockTypeIdAt(x, y, z) == 0, upper = world.getBlockTypeIdAt(x, y + 1, z) == 0;
while ((!lower || !upper) && y != 127) {
lower = upper;
upper = world.getBlockTypeIdAt(x, ++y, z) == 0;
}
while (world.getBlockTypeIdAt(x, y - 1, z) == 0 && y != 0)
y--;
return y;
}
public static void giveTool(Player player, int type) {
final Inventory inv = player.getInventory();
if (inv.contains(type)) {
player.sendMessage(ChatColor.RED + "You have already a " + materialName(type));
} else {
final int free = inv.firstEmpty();
if (free >= 0) {
if (player.getItemInHand() != null && player.getItemInHand().getTypeId() != 0) {
inv.setItem(free, player.getItemInHand());
}
player.setItemInHand(new ItemStack(type, 1));
player.sendMessage(ChatColor.GREEN + "Here's your " + materialName(type));
} else {
player.sendMessage(ChatColor.RED + "You have no empty slot in your inventory");
}
}
}
public static int modifyContainer(BlockState b, ItemStack item) {
if (b instanceof InventoryHolder) {
final Inventory inv = ((InventoryHolder)b).getInventory();
if (item.getAmount() < 0) {
item.setAmount(-item.getAmount());
final ItemStack tmp = inv.removeItem(item).get(0);
return tmp != null ? tmp.getAmount() : 0;
} else if (item.getAmount() > 0) {
final ItemStack tmp = inv.addItem(item).get(0);
return tmp != null ? tmp.getAmount() : 0;
}
}
return 0;
}
public static short rawData(ItemStack item) {
return item.getType() != null ? item.getData() != null ? item.getDurability() : 0 : 0;
}
public static boolean canFall(World world, int x, int y, int z) {
Material mat = world.getBlockAt(x, y, z).getType();
public static int saveSpawnHeight(Location loc) {
final World world = loc.getWorld();
final Chunk chunk = world.getChunkAt(loc);
if (!world.isChunkLoaded(chunk)) {
world.loadChunk(chunk);
}
final int x = loc.getBlockX(), z = loc.getBlockZ();
int y = loc.getBlockY();
boolean lower = world.getBlockTypeIdAt(x, y, z) == 0, upper = world.getBlockTypeIdAt(x, y + 1, z) == 0;
while ((!lower || !upper) && y != 127) {
lower = upper;
upper = world.getBlockTypeIdAt(x, ++y, z) == 0;
}
while (world.getBlockTypeIdAt(x, y - 1, z) == 0 && y != 0) {
y--;
}
return y;
}
// Air
if (mat == Material.AIR) {
return true;
} else if (mat == Material.WATER || mat == Material.STATIONARY_WATER || mat == Material.LAVA || mat == Material.STATIONARY_LAVA) { // Fluids
return true;
} else if (getFallingEntityKillers().contains(mat) || mat == Material.FIRE || mat == Material.VINE || mat == Material.LONG_GRASS || mat == Material.DEAD_BUSH) { // Misc.
return true;
}
return false;
}
public static int modifyContainer(BlockState b, ItemStack item) {
if (b instanceof InventoryHolder) {
final Inventory inv = ((InventoryHolder) b).getInventory();
if (item.getAmount() < 0) {
item.setAmount(-item.getAmount());
final ItemStack tmp = inv.removeItem(item).get(0);
return tmp != null ? tmp.getAmount() : 0;
} else if (item.getAmount() > 0) {
final ItemStack tmp = inv.addItem(item).get(0);
return tmp != null ? tmp.getAmount() : 0;
}
}
return 0;
}
public static class ItemStackComparator implements Comparator<ItemStack>
{
@Override
public int compare(ItemStack a, ItemStack b) {
final int aType = a.getTypeId(), bType = b.getTypeId();
if (aType < bType)
return -1;
if (aType > bType)
return 1;
final short aData = rawData(a), bData = rawData(b);
if (aData < bData)
return -1;
if (aData > bData)
return 1;
return 0;
}
}
public static boolean canFall(World world, int x, int y, int z) {
Material mat = world.getBlockAt(x, y, z).getType();
public static int itemIDfromProjectileEntity(Entity e) {
Integer i = projectileItems.get(e.getType());
return (i == null) ? 0 : i;
}
// Air
if (mat == Material.AIR) {
return true;
} else if (mat == Material.WATER || mat == Material.STATIONARY_WATER || mat == Material.LAVA || mat == Material.STATIONARY_LAVA) { // Fluids
return true;
} else if (getFallingEntityKillers().contains(mat) || mat == Material.FIRE || mat == Material.VINE || mat == Material.LONG_GRASS || mat == Material.DEAD_BUSH) { // Misc.
return true;
}
return false;
}
public static class ItemStackComparator implements Comparator<ItemStack> {
@Override
public int compare(ItemStack a, ItemStack b) {
final int aType = a.getTypeId(), bType = b.getTypeId();
if (aType < bType) {
return -1;
}
if (aType > bType) {
return 1;
}
final short aData = rawData(a), bData = rawData(b);
if (aData < bData) {
return -1;
}
if (aData > bData) {
return 1;
}
return 0;
}
}
public static int itemIDfromProjectileEntity(Entity e) {
Integer i = projectileItems.get(e.getType());
return (i == null) ? 0 : i;
}
}

View File

@@ -3,208 +3,212 @@ package de.diddiz.util;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.Consumer;
import de.diddiz.LogBlock.Logging;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.mb4;
import de.diddiz.LogBlock.config.WorldConfig;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.material.Button;
import org.bukkit.material.CocoaPlant;
import org.bukkit.material.Ladder;
import org.bukkit.material.Lever;
import org.bukkit.material.MaterialData;
import org.bukkit.material.RedstoneTorch;
import org.bukkit.material.Torch;
import org.bukkit.material.TrapDoor;
import org.bukkit.material.TripwireHook;
import org.bukkit.material.*;
import java.util.List;
import static de.diddiz.LogBlock.config.Config.getWorldConfig;
import static de.diddiz.LogBlock.config.Config.mb4;
public class LoggingUtil {
public static void smartLogFallables(Consumer consumer, Actor actor, Block origin) {
public static void smartLogFallables(Consumer consumer, Actor actor, Block origin) {
WorldConfig wcfg = getWorldConfig(origin.getWorld());
if (wcfg == null) return;
WorldConfig wcfg = getWorldConfig(origin.getWorld());
if (wcfg == null) {
return;
}
//Handle falling blocks
Block checkBlock = origin.getRelative(BlockFace.UP);
int up = 0;
final int highestBlock = checkBlock.getWorld().getHighestBlockYAt(checkBlock.getLocation());
while (BukkitUtils.getRelativeTopFallables().contains(checkBlock.getType())) {
//Handle falling blocks
Block checkBlock = origin.getRelative(BlockFace.UP);
int up = 0;
final int highestBlock = checkBlock.getWorld().getHighestBlockYAt(checkBlock.getLocation());
while (BukkitUtils.getRelativeTopFallables().contains(checkBlock.getType())) {
// Record this block as falling
consumer.queueBlockBreak(actor, checkBlock.getState());
// Record this block as falling
consumer.queueBlockBreak(actor, checkBlock.getState());
// Guess where the block is going (This could be thrown of by explosions, but it is better than nothing)
Location loc = origin.getLocation();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
while (y > 0 && BukkitUtils.canFall(loc.getWorld(), x, (y - 1), z)) {
y--;
}
// If y is 0 then the sand block fell out of the world :(
if (y != 0) {
Location finalLoc = new Location(loc.getWorld(), x, y, z);
// Run this check to avoid false positives
if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
finalLoc.add(0, up, 0); // Add this here after checking for block breakers
if (finalLoc.getBlock().getType() == Material.AIR || BukkitUtils.getRelativeTopFallables().contains(finalLoc.getBlock().getType())) {
consumer.queueBlockPlace(actor, finalLoc, checkBlock.getTypeId(), checkBlock.getData());
} else {
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getTypeId(), finalLoc.getBlock().getData(), checkBlock.getTypeId(), checkBlock.getData());
}
up++;
}
}
if (checkBlock.getY() >= highestBlock) break;
checkBlock = checkBlock.getRelative(BlockFace.UP);
}
}
// Guess where the block is going (This could be thrown of by explosions, but it is better than nothing)
Location loc = origin.getLocation();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
while (y > 0 && BukkitUtils.canFall(loc.getWorld(), x, (y - 1), z)) {
y--;
}
// If y is 0 then the sand block fell out of the world :(
if (y != 0) {
Location finalLoc = new Location(loc.getWorld(), x, y, z);
// Run this check to avoid false positives
if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
finalLoc.add(0, up, 0); // Add this here after checking for block breakers
if (finalLoc.getBlock().getType() == Material.AIR || BukkitUtils.getRelativeTopFallables().contains(finalLoc.getBlock().getType())) {
consumer.queueBlockPlace(actor, finalLoc, checkBlock.getTypeId(), checkBlock.getData());
} else {
consumer.queueBlockReplace(actor, finalLoc, finalLoc.getBlock().getTypeId(), finalLoc.getBlock().getData(), checkBlock.getTypeId(), checkBlock.getData());
}
up++;
}
}
if (checkBlock.getY() >= highestBlock) {
break;
}
checkBlock = checkBlock.getRelative(BlockFace.UP);
}
}
public static void smartLogBlockBreak(Consumer consumer, Actor actor, Block origin) {
public static void smartLogBlockBreak(Consumer consumer, Actor actor, Block origin) {
WorldConfig wcfg = getWorldConfig(origin.getWorld());
if (wcfg == null) return;
WorldConfig wcfg = getWorldConfig(origin.getWorld());
if (wcfg == null) {
return;
}
Block checkBlock = origin.getRelative(BlockFace.UP);
if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getType())) {
if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
consumer.queueSignBreak(actor, (Sign) checkBlock.getState());
} else if (checkBlock.getType() == Material.IRON_DOOR_BLOCK || checkBlock.getType() == Material.WOODEN_DOOR) {
Block doorBlock = checkBlock;
// If the doorBlock is the top half a door the player simply punched a door
// this will be handled later.
if (!BukkitUtils.isTop(doorBlock.getType(), doorBlock.getData())) {
doorBlock = doorBlock.getRelative(BlockFace.UP);
// Fall back check just in case the top half wasn't a door
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
consumer.queueBlockBreak(actor, doorBlock.getState());
}
consumer.queueBlockBreak(actor, checkBlock.getState());
}
} else if (checkBlock.getType() == Material.DOUBLE_PLANT) {
Block plantBlock = checkBlock;
// If the plantBlock is the top half of a double plant the player simply
// punched the plant this will be handled later.
if (!BukkitUtils.isTop(plantBlock.getType(), plantBlock.getData())) {
plantBlock = plantBlock.getRelative(BlockFace.UP);
// Fall back check just in case the top half wasn't a plant
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
consumer.queueBlockBreak(actor, plantBlock.getState());
}
consumer.queueBlockBreak(actor, checkBlock.getState());
}
} else {
consumer.queueBlockBreak(actor, checkBlock.getState());
}
}
Block checkBlock = origin.getRelative(BlockFace.UP);
if (BukkitUtils.getRelativeTopBreakabls().contains(checkBlock.getType())) {
if (wcfg.isLogging(Logging.SIGNTEXT) && checkBlock.getType() == Material.SIGN_POST) {
consumer.queueSignBreak(actor, (Sign) checkBlock.getState());
} else if (checkBlock.getType() == Material.IRON_DOOR_BLOCK || checkBlock.getType() == Material.WOODEN_DOOR) {
Block doorBlock = checkBlock;
// If the doorBlock is the top half a door the player simply punched a door
// this will be handled later.
if (!BukkitUtils.isTop(doorBlock.getType(), doorBlock.getData())) {
doorBlock = doorBlock.getRelative(BlockFace.UP);
// Fall back check just in case the top half wasn't a door
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
consumer.queueBlockBreak(actor, doorBlock.getState());
}
consumer.queueBlockBreak(actor, checkBlock.getState());
}
} else if (checkBlock.getType() == Material.DOUBLE_PLANT) {
Block plantBlock = checkBlock;
// If the plantBlock is the top half of a double plant the player simply
// punched the plant this will be handled later.
if (!BukkitUtils.isTop(plantBlock.getType(), plantBlock.getData())) {
plantBlock = plantBlock.getRelative(BlockFace.UP);
// Fall back check just in case the top half wasn't a plant
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
consumer.queueBlockBreak(actor, plantBlock.getState());
}
consumer.queueBlockBreak(actor, checkBlock.getState());
}
} else {
consumer.queueBlockBreak(actor, checkBlock.getState());
}
}
List<Location> relativeBreakables = BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
if (relativeBreakables.size() != 0) {
for (Location location : relativeBreakables) {
final Material blockType = location.getBlock().getType();
final BlockState blockState = location.getBlock().getState();
final MaterialData data = blockState.getData();
switch (blockType) {
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
if (blockState.getBlock().getRelative(((RedstoneTorch) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case TORCH:
if (blockState.getBlock().getRelative(((Torch) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case COCOA:
if (blockState.getBlock().getRelative(((CocoaPlant) data).getAttachedFace().getOppositeFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case LADDER:
if (blockState.getBlock().getRelative(((Ladder) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case LEVER:
if (blockState.getBlock().getRelative(((Lever) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case TRIPWIRE_HOOK:
if (blockState.getBlock().getRelative(((TripwireHook) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case WOOD_BUTTON:
case STONE_BUTTON:
if (blockState.getBlock().getRelative(((Button) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case WALL_SIGN:
if (blockState.getBlock().getRelative(((org.bukkit.material.Sign) data).getAttachedFace()).equals(origin)) {
if (wcfg.isLogging(Logging.SIGNTEXT)) {
consumer.queueSignBreak(actor, (Sign) blockState);
} else {
consumer.queueBlockBreak(actor, blockState);
}
}
break;
case TRAP_DOOR:
if (blockState.getBlock().getRelative(((TrapDoor) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
default:
consumer.queueBlockBreak(actor, blockState);
break;
}
}
}
List<Location> relativeBreakables = BukkitUtils.getBlocksNearby(origin, BukkitUtils.getRelativeBreakables());
if (relativeBreakables.size() != 0) {
for (Location location : relativeBreakables) {
final Material blockType = location.getBlock().getType();
final BlockState blockState = location.getBlock().getState();
final MaterialData data = blockState.getData();
switch (blockType) {
case REDSTONE_TORCH_ON:
case REDSTONE_TORCH_OFF:
if (blockState.getBlock().getRelative(((RedstoneTorch) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case TORCH:
if (blockState.getBlock().getRelative(((Torch) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case COCOA:
if (blockState.getBlock().getRelative(((CocoaPlant) data).getAttachedFace().getOppositeFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case LADDER:
if (blockState.getBlock().getRelative(((Ladder) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case LEVER:
if (blockState.getBlock().getRelative(((Lever) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case TRIPWIRE_HOOK:
if (blockState.getBlock().getRelative(((TripwireHook) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case WOOD_BUTTON:
case STONE_BUTTON:
if (blockState.getBlock().getRelative(((Button) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
case WALL_SIGN:
if (blockState.getBlock().getRelative(((org.bukkit.material.Sign) data).getAttachedFace()).equals(origin)) {
if (wcfg.isLogging(Logging.SIGNTEXT)) {
consumer.queueSignBreak(actor, (Sign) blockState);
} else {
consumer.queueBlockBreak(actor, blockState);
}
}
break;
case TRAP_DOOR:
if (blockState.getBlock().getRelative(((TrapDoor) data).getAttachedFace()).equals(origin)) {
consumer.queueBlockBreak(actor, blockState);
}
break;
default:
consumer.queueBlockBreak(actor, blockState);
break;
}
}
}
// Special door check
if (origin.getType() == Material.IRON_DOOR_BLOCK || origin.getType() == Material.WOODEN_DOOR) {
Block doorBlock = origin;
// Special door check
if (origin.getType() == Material.IRON_DOOR_BLOCK || origin.getType() == Material.WOODEN_DOOR) {
Block doorBlock = origin;
// Up or down?
if (!BukkitUtils.isTop(doorBlock.getType(), doorBlock.getData())) {
doorBlock = doorBlock.getRelative(BlockFace.UP);
} else {
doorBlock = doorBlock.getRelative(BlockFace.DOWN);
}
// Up or down?
if (!BukkitUtils.isTop(doorBlock.getType(), doorBlock.getData())) {
doorBlock = doorBlock.getRelative(BlockFace.UP);
} else {
doorBlock = doorBlock.getRelative(BlockFace.DOWN);
}
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
consumer.queueBlockBreak(actor, doorBlock.getState());
}
} else if (origin.getType() == Material.DOUBLE_PLANT) { // Special double plant check
Block plantBlock = origin;
if (doorBlock.getType() == Material.IRON_DOOR_BLOCK || doorBlock.getType() == Material.WOODEN_DOOR) {
consumer.queueBlockBreak(actor, doorBlock.getState());
}
} else if (origin.getType() == Material.DOUBLE_PLANT) { // Special double plant check
Block plantBlock = origin;
// Up or down?
if (!BukkitUtils.isTop(origin.getType(), origin.getData())) {
plantBlock = plantBlock.getRelative(BlockFace.UP);
} else {
plantBlock = plantBlock.getRelative(BlockFace.DOWN);
}
// Up or down?
if (!BukkitUtils.isTop(origin.getType(), origin.getData())) {
plantBlock = plantBlock.getRelative(BlockFace.UP);
} else {
plantBlock = plantBlock.getRelative(BlockFace.DOWN);
}
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
consumer.queueBlockBreak(actor, plantBlock.getState());
}
}
if (plantBlock.getType() == Material.DOUBLE_PLANT) {
consumer.queueBlockBreak(actor, plantBlock.getState());
}
}
// Do this down here so that the block is added after blocks sitting on it
consumer.queueBlockBreak(actor, origin.getState());
}
public static String checkText(String text) {
if (text==null) return text;
if (mb4) return text;
return text.replaceAll("[^\\u0000-\\uFFFF]", "?");
}
// Do this down here so that the block is added after blocks sitting on it
consumer.queueBlockBreak(actor, origin.getState());
}
public static String checkText(String text) {
if (text == null) {
return text;
}
if (mb4) {
return text;
}
return text.replaceAll("[^\\u0000-\\uFFFF]", "?");
}
}

View File

@@ -1,258 +1,270 @@
package de.diddiz.util;
import static de.diddiz.util.Utils.isInt;
import static de.diddiz.util.Utils.isShort;
import static org.bukkit.Bukkit.getLogger;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.material.MaterialData;
public class MaterialName
{
private static final String[] COLORS = {"white","orange","magenta","light blue","yellow","lime","pink","gray","silver","cyan","purple","blue","brown","green","red","black"};
private static final Map<Integer, String> materialNames = new HashMap<Integer, String>();
private static final Map<Integer, Map<Short, String>> materialDataNames = new HashMap<Integer, Map<Short, String>>();
private static final Map<String, Integer> nameTypes = new HashMap<String, Integer>();
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
static {
// Add all known materials
for (final Material mat : Material.values())
materialNames.put(mat.getId(), mat.toString().replace('_', ' ').toLowerCase());
// Load config
final File file = new File("plugins/LogBlock/materials.yml");
final YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
if (cfg.getKeys(false).isEmpty()) {
// Generate defaults
cfg.options().header("Add block or item names you want to be overridden or also names for custom blocks");
cfg.set("1.1", "granite");
cfg.set("1.2", "polished granite");
cfg.set("1.3", "diorite");
cfg.set("1.4", "polished diorite");
cfg.set("1.5", "andesite");
cfg.set("1.6", "polished andesite");
cfg.set("5.0", "oak wood");
cfg.set("5.1", "spruce wood");
cfg.set("5.2", "birch wood");
cfg.set("5.3", "jungle wood");
cfg.set("5.4", "acacia wood");
cfg.set("5.5", "dark oak wood");
cfg.set("3.1", "coarse dirt");
cfg.set("3.2", "podzol");
cfg.set("6.1", "redwood sapling");
cfg.set("6.2", "birch sapling");
cfg.set("6.3", "jungle sapling");
cfg.set("6.4", "acacia sapling");
cfg.set("6.5", "dark oak sapling");
cfg.set("9", "water");
cfg.set("11", "lava");
cfg.set("12.1", "red sand");
cfg.set("17.0", "oak log");
cfg.set("17.1", "spruce log");
cfg.set("17.2", "birch log");
cfg.set("17.3", "jungle log");
cfg.set("17.4", "oak log");
cfg.set("17.5", "spruce log");
cfg.set("17.6", "birch log");
cfg.set("17.7", "jungle log");
cfg.set("17.8", "oak log");
cfg.set("17.9", "spruce log");
cfg.set("17.10", "birch log");
cfg.set("17.11", "jungle log");
cfg.set("17.12", "oak log");
cfg.set("17.13", "spruce log");
cfg.set("17.14", "birch log");
cfg.set("17.15", "jungle log");
cfg.set("18.1", "spruce leaves");
cfg.set("18.2", "birch leaves");
cfg.set("18.3", "jungle leaves");
cfg.set("18.4", "oak leaves");
cfg.set("18.5", "spruce leaves");
cfg.set("18.6", "birch leaves");
cfg.set("18.7", "jungle leaves");
cfg.set("18.8", "oak leaves");
cfg.set("18.9", "spruce leaves");
cfg.set("18.10", "birch leaves");
cfg.set("18.11", "jungle leaves");
cfg.set("18.12", "oak leaves");
cfg.set("18.13", "spruce leaves");
cfg.set("18.14", "birch leaves");
cfg.set("18.15", "jungle leaves");
cfg.set("19.1", "wet sponge");
cfg.set("37.0", "dandelion");
cfg.set("38.0", "poppy");
cfg.set("38.1", "blue orchid");
cfg.set("38.2", "allium");
cfg.set("38.3", "azure bluet");
cfg.set("38.4", "red tulip");
cfg.set("38.5", "orange tulip");
cfg.set("38.6", "white tulip");
cfg.set("38.7", "pink tulip");
cfg.set("38.8", "oxeye daisy");
cfg.set("24.1", "chiseled sandstone");
cfg.set("24.2", "smooth sandstone");
cfg.set("31.0", "dead bush");
cfg.set("31.1", "tall grass");
cfg.set("31.2", "fern");
cfg.set("98.0", "stone brick");
cfg.set("98.1", "mossy stone brick");
cfg.set("98.2", "cracked stone brick");
cfg.set("98.3", "chiseled stone brick");
cfg.set("125.0","oak double step");
cfg.set("125.1","spruce double step");
cfg.set("125.2","birch double step");
cfg.set("125.3","jungle double step");
cfg.set("125.4","acacia double step");
cfg.set("125.5","dark oak double step");
cfg.set("126.0", "oak step");
cfg.set("126.1", "spruce step");
cfg.set("126.2", "birch step");
cfg.set("126.3", "jungle step");
cfg.set("126.4", "acacia step");
cfg.set("126.5", "dark oak step");
cfg.set("126.8", "oak step");
cfg.set("126.9", "spruce step");
cfg.set("126.10", "birch step");
cfg.set("126.11", "jungle step");
cfg.set("126.12", "acacia step");
cfg.set("126.13", "dark oak step");
cfg.set("139.1", "mossy cobble wall");
cfg.set("155.1", "chiseled quartz block");
cfg.set("155.2", "pillar quartz block");
cfg.set("155.3", "pillar quartz block");
cfg.set("155.4", "pillar quartz block");
cfg.set("161.0", "acacia leaves");
cfg.set("161.1", "dark oak leaves");
cfg.set("161.4", "acacia leaves");
cfg.set("161.5", "dark oak leaves");
cfg.set("161.8", "acacia leaves");
cfg.set("161.9", "dark oak leaves");
cfg.set("161.12", "acacia leaves");
cfg.set("161.13", "dark oak leaves");
cfg.set("162.0", "acacia log");
cfg.set("162.1", "dark oak log");
cfg.set("162.4", "acacia log");
cfg.set("162.5", "dark oak log");
cfg.set("162.8", "acacia log");
cfg.set("162.9", "dark oak log");
cfg.set("162.12", "acacia log");
cfg.set("162.13", "dark oak log");
cfg.set("168.1", "prismarine brick");
cfg.set("168.2", "dark prismarine");
cfg.set("181.0", "red sandstone double step");
cfg.set("181.8", "smooth red sandstone double step");
cfg.set("162.13", "dark oak log");
cfg.set("175.0", "sunflower");
cfg.set("175.1", "lilac");
cfg.set("175.2", "double tall grass");
cfg.set("175.3", "large fern");
cfg.set("175.4", "rose bush");
cfg.set("175.5", "peony");
cfg.set("175.8", "sunflower");
cfg.set("175.9", "lilac");
cfg.set("175.10", "double tall grass");
cfg.set("175.11", "large fern");
cfg.set("175.12", "rose bush");
cfg.set("175.13", "peony");
cfg.set("179.1", "chiseled sandstone");
cfg.set("179.2", "smooth sandstone");
cfg.set("263.1", "charcoal");
for (byte i = 0; i < 10; i++) {
cfg.set("43." + i, toReadable(Material.DOUBLE_STEP.getNewData(i)));
}
cfg.set("43.8", "stone double step");
cfg.set("43.9", "sandstone double step");
cfg.set("43.15", "quartz double step");
for (byte i = 0; i < 8; i++) {
cfg.set("44." + i, toReadable(Material.STEP.getNewData(i)));
// The second half of this data list should read the same as the first half
cfg.set("44." + (i+7), toReadable(Material.STEP.getNewData(i)));
}
for (byte i = 0; i < 16; i++) {
cfg.set("351." + i, toReadable(Material.INK_SACK.getNewData(i)));
cfg.set("35." + i, COLORS[i] + " wool");
cfg.set("159." + i, COLORS[i] + " stained clay");
cfg.set("95." + i, COLORS[i] + " stained glass");
cfg.set("160." + i, COLORS[i] + " stained glass pane");
cfg.set("171." + i, COLORS[i] + " carpet");
}
for (byte i = 0; i < 6; i++) {
cfg.set("125." + i, toReadable(Material.WOOD_DOUBLE_STEP.getNewData(i)));
cfg.set("126." + i, toReadable(Material.WOOD_STEP.getNewData(i)));
cfg.set("126." + i+8, toReadable(Material.WOOD_STEP.getNewData(i)));
}
try {
cfg.save(file);
} catch (final IOException ex) {
getLogger().log(Level.WARNING, "Unable to save material.yml: ", ex);
}
}
if (cfg.getString("263.1") == null) {
getLogger().info("[Logblock-names] Logblock's default materials.yml file has been updated with more names");
getLogger().info("[Logblock-names] Consider deleting your current materials.yml file to allow it to be recreated");
}
for (final String entry : cfg.getKeys(false))
if (isInt(entry)) {
if (cfg.isString(entry)) {
materialNames.put(Integer.valueOf(entry), cfg.getString(entry));
nameTypes.put(cfg.getString(entry), Integer.valueOf(entry));
}
else if (cfg.isConfigurationSection(entry)) {
final Map<Short, String> dataNames = new HashMap<Short, String>();
materialDataNames.put(Integer.valueOf(entry), dataNames);
final ConfigurationSection sec = cfg.getConfigurationSection(entry);
for (final String data : sec.getKeys(false))
if (isShort(data)) {
if (sec.isString(data)) {
dataNames.put(Short.valueOf(data), sec.getString(data));
nameTypes.put(sec.getString(data), Integer.valueOf(entry));
}
else
getLogger().warning("Parsing materials.yml: '" + data + "' is not a string.");
} else
getLogger().warning("Parsing materials.yml: '" + data + "' is no valid material data");
} else
getLogger().warning("Parsing materials.yml: '" + entry + "' is neither a string nor a section.");
} else
getLogger().warning("Parsing materials.yml: '" + entry + "' is no valid material id");
}
import static de.diddiz.util.Utils.isInt;
import static de.diddiz.util.Utils.isShort;
import static org.bukkit.Bukkit.getLogger;
/**
* @return Name of the material, or if it's unknown, the id.
*/
public static String materialName(int type) {
return materialNames.containsKey(type) ? materialNames.get(type) : String.valueOf(type);
}
public class MaterialName {
private static final String[] COLORS = {"white", "orange", "magenta", "light blue", "yellow", "lime", "pink", "gray", "silver", "cyan", "purple", "blue", "brown", "green", "red", "black"};
private static final Map<Integer, String> materialNames = new HashMap<Integer, String>();
private static final Map<Integer, Map<Short, String>> materialDataNames = new HashMap<Integer, Map<Short, String>>();
private static final Map<String, Integer> nameTypes = new HashMap<String, Integer>();
/**
* @return Name of the material regarding it's data, or if it's unknown, the basic name.
*/
public static String materialName(int type, short data) {
final Map<Short, String> dataNames = materialDataNames.get(type);
if (dataNames != null)
if (dataNames.containsKey(data))
return dataNames.get(data);
return materialName(type);
}
public static Integer typeFromName(String name) {
Integer answer = nameTypes.get(toReadable(name));
if (answer != null) return answer;
final Material mat = Material.matchMaterial(name);
if (mat == null) throw new IllegalArgumentException("No material matching: '" + name + "'");
return mat.getId();
}
static {
// Add all known materials
for (final Material mat : Material.values()) {
materialNames.put(mat.getId(), mat.toString().replace('_', ' ').toLowerCase());
}
// Load config
final File file = new File("plugins/LogBlock/materials.yml");
final YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
if (cfg.getKeys(false).isEmpty()) {
// Generate defaults
cfg.options().header("Add block or item names you want to be overridden or also names for custom blocks");
cfg.set("1.1", "granite");
cfg.set("1.2", "polished granite");
cfg.set("1.3", "diorite");
cfg.set("1.4", "polished diorite");
cfg.set("1.5", "andesite");
cfg.set("1.6", "polished andesite");
cfg.set("5.0", "oak wood");
cfg.set("5.1", "spruce wood");
cfg.set("5.2", "birch wood");
cfg.set("5.3", "jungle wood");
cfg.set("5.4", "acacia wood");
cfg.set("5.5", "dark oak wood");
cfg.set("3.1", "coarse dirt");
cfg.set("3.2", "podzol");
cfg.set("6.1", "redwood sapling");
cfg.set("6.2", "birch sapling");
cfg.set("6.3", "jungle sapling");
cfg.set("6.4", "acacia sapling");
cfg.set("6.5", "dark oak sapling");
cfg.set("9", "water");
cfg.set("11", "lava");
cfg.set("12.1", "red sand");
cfg.set("17.0", "oak log");
cfg.set("17.1", "spruce log");
cfg.set("17.2", "birch log");
cfg.set("17.3", "jungle log");
cfg.set("17.4", "oak log");
cfg.set("17.5", "spruce log");
cfg.set("17.6", "birch log");
cfg.set("17.7", "jungle log");
cfg.set("17.8", "oak log");
cfg.set("17.9", "spruce log");
cfg.set("17.10", "birch log");
cfg.set("17.11", "jungle log");
cfg.set("17.12", "oak log");
cfg.set("17.13", "spruce log");
cfg.set("17.14", "birch log");
cfg.set("17.15", "jungle log");
cfg.set("18.1", "spruce leaves");
cfg.set("18.2", "birch leaves");
cfg.set("18.3", "jungle leaves");
cfg.set("18.4", "oak leaves");
cfg.set("18.5", "spruce leaves");
cfg.set("18.6", "birch leaves");
cfg.set("18.7", "jungle leaves");
cfg.set("18.8", "oak leaves");
cfg.set("18.9", "spruce leaves");
cfg.set("18.10", "birch leaves");
cfg.set("18.11", "jungle leaves");
cfg.set("18.12", "oak leaves");
cfg.set("18.13", "spruce leaves");
cfg.set("18.14", "birch leaves");
cfg.set("18.15", "jungle leaves");
cfg.set("19.1", "wet sponge");
cfg.set("37.0", "dandelion");
cfg.set("38.0", "poppy");
cfg.set("38.1", "blue orchid");
cfg.set("38.2", "allium");
cfg.set("38.3", "azure bluet");
cfg.set("38.4", "red tulip");
cfg.set("38.5", "orange tulip");
cfg.set("38.6", "white tulip");
cfg.set("38.7", "pink tulip");
cfg.set("38.8", "oxeye daisy");
cfg.set("24.1", "chiseled sandstone");
cfg.set("24.2", "smooth sandstone");
cfg.set("31.0", "dead bush");
cfg.set("31.1", "tall grass");
cfg.set("31.2", "fern");
cfg.set("98.0", "stone brick");
cfg.set("98.1", "mossy stone brick");
cfg.set("98.2", "cracked stone brick");
cfg.set("98.3", "chiseled stone brick");
cfg.set("125.0", "oak double step");
cfg.set("125.1", "spruce double step");
cfg.set("125.2", "birch double step");
cfg.set("125.3", "jungle double step");
cfg.set("125.4", "acacia double step");
cfg.set("125.5", "dark oak double step");
cfg.set("126.0", "oak step");
cfg.set("126.1", "spruce step");
cfg.set("126.2", "birch step");
cfg.set("126.3", "jungle step");
cfg.set("126.4", "acacia step");
cfg.set("126.5", "dark oak step");
cfg.set("126.8", "oak step");
cfg.set("126.9", "spruce step");
cfg.set("126.10", "birch step");
cfg.set("126.11", "jungle step");
cfg.set("126.12", "acacia step");
cfg.set("126.13", "dark oak step");
cfg.set("139.1", "mossy cobble wall");
cfg.set("155.1", "chiseled quartz block");
cfg.set("155.2", "pillar quartz block");
cfg.set("155.3", "pillar quartz block");
cfg.set("155.4", "pillar quartz block");
cfg.set("161.0", "acacia leaves");
cfg.set("161.1", "dark oak leaves");
cfg.set("161.4", "acacia leaves");
cfg.set("161.5", "dark oak leaves");
cfg.set("161.8", "acacia leaves");
cfg.set("161.9", "dark oak leaves");
cfg.set("161.12", "acacia leaves");
cfg.set("161.13", "dark oak leaves");
cfg.set("162.0", "acacia log");
cfg.set("162.1", "dark oak log");
cfg.set("162.4", "acacia log");
cfg.set("162.5", "dark oak log");
cfg.set("162.8", "acacia log");
cfg.set("162.9", "dark oak log");
cfg.set("162.12", "acacia log");
cfg.set("162.13", "dark oak log");
cfg.set("168.1", "prismarine brick");
cfg.set("168.2", "dark prismarine");
cfg.set("181.0", "red sandstone double step");
cfg.set("181.8", "smooth red sandstone double step");
cfg.set("162.13", "dark oak log");
cfg.set("175.0", "sunflower");
cfg.set("175.1", "lilac");
cfg.set("175.2", "double tall grass");
cfg.set("175.3", "large fern");
cfg.set("175.4", "rose bush");
cfg.set("175.5", "peony");
cfg.set("175.8", "sunflower");
cfg.set("175.9", "lilac");
cfg.set("175.10", "double tall grass");
cfg.set("175.11", "large fern");
cfg.set("175.12", "rose bush");
cfg.set("175.13", "peony");
cfg.set("179.1", "chiseled sandstone");
cfg.set("179.2", "smooth sandstone");
cfg.set("263.1", "charcoal");
for (byte i = 0; i < 10; i++) {
cfg.set("43." + i, toReadable(Material.DOUBLE_STEP.getNewData(i)));
}
cfg.set("43.8", "stone double step");
cfg.set("43.9", "sandstone double step");
cfg.set("43.15", "quartz double step");
for (byte i = 0; i < 8; i++) {
cfg.set("44." + i, toReadable(Material.STEP.getNewData(i)));
// The second half of this data list should read the same as the first half
cfg.set("44." + (i + 7), toReadable(Material.STEP.getNewData(i)));
}
for (byte i = 0; i < 16; i++) {
cfg.set("351." + i, toReadable(Material.INK_SACK.getNewData(i)));
cfg.set("35." + i, COLORS[i] + " wool");
cfg.set("159." + i, COLORS[i] + " stained clay");
cfg.set("95." + i, COLORS[i] + " stained glass");
cfg.set("160." + i, COLORS[i] + " stained glass pane");
cfg.set("171." + i, COLORS[i] + " carpet");
}
for (byte i = 0; i < 6; i++) {
cfg.set("125." + i, toReadable(Material.WOOD_DOUBLE_STEP.getNewData(i)));
cfg.set("126." + i, toReadable(Material.WOOD_STEP.getNewData(i)));
cfg.set("126." + i + 8, toReadable(Material.WOOD_STEP.getNewData(i)));
}
try {
cfg.save(file);
} catch (final IOException ex) {
getLogger().log(Level.WARNING, "Unable to save material.yml: ", ex);
}
}
if (cfg.getString("263.1") == null) {
getLogger().info("[Logblock-names] Logblock's default materials.yml file has been updated with more names");
getLogger().info("[Logblock-names] Consider deleting your current materials.yml file to allow it to be recreated");
}
for (final String entry : cfg.getKeys(false)) {
if (isInt(entry)) {
if (cfg.isString(entry)) {
materialNames.put(Integer.valueOf(entry), cfg.getString(entry));
nameTypes.put(cfg.getString(entry), Integer.valueOf(entry));
} else if (cfg.isConfigurationSection(entry)) {
final Map<Short, String> dataNames = new HashMap<Short, String>();
materialDataNames.put(Integer.valueOf(entry), dataNames);
final ConfigurationSection sec = cfg.getConfigurationSection(entry);
for (final String data : sec.getKeys(false)) {
if (isShort(data)) {
if (sec.isString(data)) {
dataNames.put(Short.valueOf(data), sec.getString(data));
nameTypes.put(sec.getString(data), Integer.valueOf(entry));
} else {
getLogger().warning("Parsing materials.yml: '" + data + "' is not a string.");
}
} else {
getLogger().warning("Parsing materials.yml: '" + data + "' is no valid material data");
}
}
} else {
getLogger().warning("Parsing materials.yml: '" + entry + "' is neither a string nor a section.");
}
} else {
getLogger().warning("Parsing materials.yml: '" + entry + "' is no valid material id");
}
}
}
private static String toReadable(MaterialData matData) {
return matData.toString().toLowerCase().replace('_', ' ').replaceAll("[^a-z ]", "");
}
/**
* @return Name of the material, or if it's unknown, the id.
*/
public static String materialName(int type) {
return materialNames.containsKey(type) ? materialNames.get(type) : String.valueOf(type);
}
private static String toReadable(String matData) {
return matData.toLowerCase().replace('_', ' ').replaceAll("[^a-z ]", "");
}
/**
* @return Name of the material regarding it's data, or if it's unknown, the basic name.
*/
public static String materialName(int type, short data) {
final Map<Short, String> dataNames = materialDataNames.get(type);
if (dataNames != null) {
if (dataNames.containsKey(data)) {
return dataNames.get(data);
}
}
return materialName(type);
}
public static Integer typeFromName(String name) {
Integer answer = nameTypes.get(toReadable(name));
if (answer != null) {
return answer;
}
final Material mat = Material.matchMaterial(name);
if (mat == null) {
throw new IllegalArgumentException("No material matching: '" + name + "'");
}
return mat.getId();
}
private static String toReadable(MaterialData matData) {
return matData.toString().toLowerCase().replace('_', ' ').replaceAll("[^a-z ]", "");
}
private static String toReadable(String matData) {
return matData.toLowerCase().replace('_', ' ').replaceAll("[^a-z ]", "");
}
}

View File

@@ -7,40 +7,39 @@ import java.io.Closeable;
import java.sql.Connection;
import java.sql.SQLException;
public class MySQLConnectionPool implements Closeable
{
public class MySQLConnectionPool implements Closeable {
private final HikariDataSource ds;
private final HikariDataSource ds;
public MySQLConnectionPool(String url, String user, String password) throws ClassNotFoundException {
this.ds = new HikariDataSource();
ds.setJdbcUrl(url);
ds.setUsername(user);
ds.setPassword(password);
public MySQLConnectionPool(String url, String user, String password) throws ClassNotFoundException {
this.ds = new HikariDataSource();
ds.setJdbcUrl(url);
ds.setUsername(user);
ds.setPassword(password);
ds.setMinimumIdle(2);
ds.setPoolName("LogBlock-Connection-Pool");
ds.setMinimumIdle(2);
ds.setPoolName("LogBlock-Connection-Pool");
ds.addDataSourceProperty("useUnicode", "true");
ds.addDataSourceProperty("characterEncoding", "utf-8");
ds.addDataSourceProperty("rewriteBatchedStatements", "true");
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("cachePrepStmts", "true");
ds.addDataSourceProperty("prepStmtCacheSize", "250");
ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
}
@Override
public void close() {
ds.close();
}
@Override
public void close() {
ds.close();
}
public Connection getConnection() throws SQLException {
Connection connection = ds.getConnection();
if (Config.mb4) {
connection.createStatement().executeQuery("SET NAMES utf8mb4");
}
return connection;
}
public Connection getConnection() throws SQLException {
Connection connection = ds.getConnection();
if (Config.mb4) {
connection.createStatement().executeQuery("SET NAMES utf8mb4");
}
return connection;
}
}

View File

@@ -18,62 +18,62 @@ import java.util.UUID;
public class UUIDFetcher {
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private static final JSONParser jsonParser = new JSONParser();
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
private static final JSONParser jsonParser = new JSONParser();
public static Map<String, UUID> getUUIDs(List<String> names) throws Exception {
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(names);
writeBody(connection, body);
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array) {
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
String name = (String) jsonProfile.get("name");
UUID uuid = UUIDFetcher.getUUID(id);
uuidMap.put(name, uuid);
}
return uuidMap;
}
public static Map<String, UUID> getUUIDs(List<String> names) throws Exception {
Map<String, UUID> uuidMap = new HashMap<String, UUID>();
HttpURLConnection connection = createConnection();
String body = JSONArray.toJSONString(names);
writeBody(connection, body);
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
for (Object profile : array) {
JSONObject jsonProfile = (JSONObject) profile;
String id = (String) jsonProfile.get("id");
String name = (String) jsonProfile.get("name");
UUID uuid = UUIDFetcher.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 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 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));
}
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));
}
public static byte[] toBytes(UUID uuid) {
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
public static byte[] toBytes(UUID uuid) {
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
byteBuffer.putLong(uuid.getMostSignificantBits());
byteBuffer.putLong(uuid.getLeastSignificantBits());
return byteBuffer.array();
}
public static UUID fromBytes(byte[] array) {
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
}
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
long mostSignificant = byteBuffer.getLong();
long leastSignificant = byteBuffer.getLong();
return new UUID(mostSignificant, leastSignificant);
}
public static UUID fromBytes(byte[] array) {
if (array.length != 16) {
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
}
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
long mostSignificant = byteBuffer.getLong();
long leastSignificant = byteBuffer.getLong();
return new UUID(mostSignificant, leastSignificant);
}
}

View File

@@ -9,166 +9,186 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Utils
{
public static String newline = System.getProperty("line.separator");
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 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 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 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(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 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 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 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();
}
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>();
String subjectString = join(args.toArray(new String[args.size()]), " ");
/**
* 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>();
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());
}
Pattern regex = Pattern.compile("[^\\s\"']+|\"[^\"]*\"|'[^']*'");
Matcher regexMatcher = regex.matcher(subjectString);
while (regexMatcher.find()) {
newArguments.add(regexMatcher.group());
}
return newArguments;
}
return newArguments;
}
public static class ExtensionFilenameFilter implements FilenameFilter
{
private final String ext;
public static class ExtensionFilenameFilter implements FilenameFilter {
private final String ext;
public ExtensionFilenameFilter(String ext) {
this.ext = ext;
}
public ExtensionFilenameFilter(String ext) {
this.ext = ext;
}
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(ext);
}
}
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(ext);
}
}
}

View File

@@ -10,32 +10,32 @@ import org.bukkit.plugin.Plugin;
public class RegionContainer {
private Selection selection;
private Selection selection;
public RegionContainer(Selection sel) {
this.selection = sel;
}
public RegionContainer(Selection sel) {
this.selection = sel;
}
public static RegionContainer fromPlayerSelection(Player player, Plugin plugin) {
final Selection selection = ((WorldEditPlugin) plugin).getSelection(player);
if (selection == null) {
throw new IllegalArgumentException("No selection defined");
}
if (!(selection instanceof CuboidSelection)) {
throw new IllegalArgumentException("You have to define a cuboid selection");
}
return new RegionContainer(selection);
}
public static RegionContainer fromPlayerSelection(Player player, Plugin plugin) {
final Selection selection = ((WorldEditPlugin) plugin).getSelection(player);
if (selection == null) {
throw new IllegalArgumentException("No selection defined");
}
if (!(selection instanceof CuboidSelection)) {
throw new IllegalArgumentException("You have to define a cuboid selection");
}
return new RegionContainer(selection);
}
public static RegionContainer fromCorners(World world, Location first, Location second) {
return new RegionContainer(new CuboidSelection(world, first, second));
}
public static RegionContainer fromCorners(World world, Location first, Location second) {
return new RegionContainer(new CuboidSelection(world, first, second));
}
public Selection getSelection() {
return selection;
}
public Selection getSelection() {
return selection;
}
public void setSelection(Selection selection) {
this.selection = selection;
}
public void setSelection(Selection selection) {
this.selection = selection;
}
}

View File

@@ -6,14 +6,12 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
//...so they ALSO have a class called Actor... need to fully-qualify when we use ours
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import de.diddiz.LogBlock.LogBlock;
import de.diddiz.LogBlock.Logging;
import de.diddiz.LogBlock.config.Config;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -22,93 +20,103 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import java.util.logging.Level;
//...so they ALSO have a class called Actor... need to fully-qualify when we use ours
public class WorldEditLoggingHook {
private LogBlock plugin;
private LogBlock plugin;
public WorldEditLoggingHook(LogBlock plugin) {
this.plugin = plugin;
}
public WorldEditLoggingHook(LogBlock plugin) {
this.plugin = plugin;
}
// Convert WE Actor to LB Actor
private de.diddiz.LogBlock.Actor AtoA(Actor weActor) {
if (weActor.isPlayer()) {
return new de.diddiz.LogBlock.Actor(weActor.getName(),weActor.getUniqueId());
}
return new de.diddiz.LogBlock.Actor(weActor.getName());
}
// Convert WE Actor to LB Actor
private de.diddiz.LogBlock.Actor AtoA(Actor weActor) {
if (weActor.isPlayer()) {
return new de.diddiz.LogBlock.Actor(weActor.getName(), weActor.getUniqueId());
}
return new de.diddiz.LogBlock.Actor(weActor.getName());
}
private World adapt(com.sk89q.worldedit.world.World weWorld) {
if (weWorld == null) {
throw new NullPointerException("[Logblock-Worldedit] The provided world was null.");
}
if (weWorld instanceof BukkitWorld) return ((BukkitWorld) weWorld).getWorld();
World world = Bukkit.getServer().getWorld(weWorld.getName());
if (world == null) throw new IllegalArgumentException("Can't find a Bukkit world for " + weWorld);
return world;
}
private World adapt(com.sk89q.worldedit.world.World weWorld) {
if (weWorld == null) {
throw new NullPointerException("[Logblock-Worldedit] The provided world was null.");
}
if (weWorld instanceof BukkitWorld) {
return ((BukkitWorld) weWorld).getWorld();
}
World world = Bukkit.getServer().getWorld(weWorld.getName());
if (world == null) {
throw new IllegalArgumentException("Can't find a Bukkit world for " + weWorld);
}
return world;
}
public void hook() {
WorldEdit.getInstance().getEventBus().register(new Object() {
@Subscribe
public void wrapForLogging(final EditSessionEvent event) {
final Actor actor = event.getActor();
if (actor == null ) return;
final de.diddiz.LogBlock.Actor lbActor = AtoA(actor);
public void hook() {
WorldEdit.getInstance().getEventBus().register(new Object() {
@Subscribe
public void wrapForLogging(final EditSessionEvent event) {
final Actor actor = event.getActor();
if (actor == null) {
return;
}
final de.diddiz.LogBlock.Actor lbActor = AtoA(actor);
// Check to ensure the world should be logged
final World world;
final com.sk89q.worldedit.world.World k = event.getWorld();
try {
world = adapt(k);
} catch (RuntimeException ex) {
plugin.getLogger().warning("Failed to register logging for WorldEdit!");
plugin.getLogger().log(Level.WARNING, ex.getMessage(),ex);
return;
}
// Check to ensure the world should be logged
final World world;
final com.sk89q.worldedit.world.World k = event.getWorld();
try {
world = adapt(k);
} catch (RuntimeException ex) {
plugin.getLogger().warning("Failed to register logging for WorldEdit!");
plugin.getLogger().log(Level.WARNING, ex.getMessage(), ex);
return;
}
// If config becomes reloadable, this check should be moved
if (!(Config.isLogging(world, Logging.WORLDEDIT))) {
return;
}
event.setExtent(new AbstractLoggingExtent(event.getExtent()) {
@Override
protected void onBlockChange(Vector pt, BaseBlock block) {
// If config becomes reloadable, this check should be moved
if (!(Config.isLogging(world, Logging.WORLDEDIT))) {
return;
}
if (event.getStage() != EditSession.Stage.BEFORE_CHANGE) {
return;
}
event.setExtent(new AbstractLoggingExtent(event.getExtent()) {
@Override
protected void onBlockChange(Vector pt, BaseBlock block) {
Location location = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
Block origin = location.getBlock();
int typeBefore = origin.getTypeId();
byte dataBefore = origin.getData();
// If we're dealing with a sign, store the block state to read the text off
BlockState stateBefore = null;
if (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId()) {
stateBefore = origin.getState();
}
if (event.getStage() != EditSession.Stage.BEFORE_CHANGE) {
return;
}
// Check to see if we've broken a sign
if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId())) {
plugin.getConsumer().queueSignBreak(lbActor, (Sign) stateBefore);
if (block.getType() != Material.AIR.getId()) {
plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
}
} else {
if (dataBefore != 0) {
plugin.getConsumer().queueBlockBreak(lbActor, location, typeBefore, dataBefore);
if (block.getType() != Material.AIR.getId()) {
plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
}
} else {
plugin.getConsumer().queueBlock(lbActor, location, typeBefore, block.getType(), (byte) block.getData());
}
}
}
});
}
});
}
Location location = new Location(world, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
Block origin = location.getBlock();
int typeBefore = origin.getTypeId();
byte dataBefore = origin.getData();
// If we're dealing with a sign, store the block state to read the text off
BlockState stateBefore = null;
if (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId()) {
stateBefore = origin.getState();
}
// Check to see if we've broken a sign
if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId())) {
plugin.getConsumer().queueSignBreak(lbActor, (Sign) stateBefore);
if (block.getType() != Material.AIR.getId()) {
plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
}
} else {
if (dataBefore != 0) {
plugin.getConsumer().queueBlockBreak(lbActor, location, typeBefore, dataBefore);
if (block.getType() != Material.AIR.getId()) {
plugin.getConsumer().queueBlockPlace(lbActor, location, block.getType(), (byte) block.getData());
}
} else {
plugin.getConsumer().queueBlock(lbActor, location, typeBefore, block.getType(), (byte) block.getData());
}
}
}
});
}
});
}
}

View File

@@ -10,12 +10,12 @@ import java.util.List;
public class QueryParsingTest {
@Test
public void testParseQuotes() {
// input = /lb clearlog world "my world of swag" player "player"
List<String> input = Arrays.asList("lb", "clearlog", "world", "\"my", "world", "of", "swag\"", "player", "\"player\"");
List<String> expectedOut = Arrays.asList("lb", "clearlog", "world", "\"my world of swag\"", "player", "\"player\"");
Assert.assertEquals(Utils.parseQuotes(input), expectedOut);
}
@Test
public void testParseQuotes() {
// input = /lb clearlog world "my world of swag" player "player"
List<String> input = Arrays.asList("lb", "clearlog", "world", "\"my", "world", "of", "swag\"", "player", "\"player\"");
List<String> expectedOut = Arrays.asList("lb", "clearlog", "world", "\"my world of swag\"", "player", "\"player\"");
Assert.assertEquals(Utils.parseQuotes(input), expectedOut);
}
}