forked from LogBlock/LogBlock
Merge remote-tracking branch 'remotes/origin/master' into pretty-chat
This commit is contained in:
@@ -72,7 +72,7 @@ public class LogBlock extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
getLogger().info("Connecting to " + user + "@" + url + "...");
|
getLogger().info("Connecting to " + user + "@" + url + "...");
|
||||||
pool = new MySQLConnectionPool(url, user, password, mysqlRequireSSL);
|
pool = new MySQLConnectionPool(url, user, password, mysqlUseSSL, mysqlRequireSSL);
|
||||||
final Connection conn = getConnection(true);
|
final Connection conn = getConnection(true);
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
noDb = true;
|
noDb = true;
|
||||||
|
@@ -2,8 +2,8 @@ package de.diddiz.LogBlock;
|
|||||||
|
|
||||||
import de.diddiz.LogBlock.config.Config;
|
import de.diddiz.LogBlock.config.Config;
|
||||||
import de.diddiz.util.BukkitUtils;
|
import de.diddiz.util.BukkitUtils;
|
||||||
|
import de.diddiz.util.CuboidRegion;
|
||||||
import de.diddiz.util.Utils;
|
import de.diddiz.util.Utils;
|
||||||
import de.diddiz.worldedit.CuboidRegion;
|
|
||||||
import de.diddiz.worldedit.WorldEditHelper;
|
import de.diddiz.worldedit.WorldEditHelper;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -792,11 +792,7 @@ public final class QueryParams implements Cloneable {
|
|||||||
if (player == null) {
|
if (player == null) {
|
||||||
throw new IllegalArgumentException("You have to be a player to use selection");
|
throw new IllegalArgumentException("You have to be a player to use selection");
|
||||||
}
|
}
|
||||||
if (WorldEditHelper.hasWorldEdit()) {
|
setSelection(WorldEditHelper.getSelectedRegion(player));
|
||||||
setSelection(CuboidRegion.fromPlayerSelection(player));
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("WorldEdit not found!");
|
|
||||||
}
|
|
||||||
} else if (param.equals("time") || param.equals("since")) {
|
} else if (param.equals("time") || param.equals("since")) {
|
||||||
since = values.length > 0 ? parseTimeSpec(values) : defaultTime;
|
since = values.length > 0 ? parseTimeSpec(values) : defaultTime;
|
||||||
if (since == -1) {
|
if (since == -1) {
|
||||||
|
@@ -25,6 +25,7 @@ public class Config {
|
|||||||
private static LoggingEnabledMapping superWorldConfig;
|
private static LoggingEnabledMapping superWorldConfig;
|
||||||
private static Map<String, WorldConfig> worldConfigs;
|
private static Map<String, WorldConfig> worldConfigs;
|
||||||
public static String url, user, password;
|
public static String url, user, password;
|
||||||
|
public static boolean mysqlUseSSL;
|
||||||
public static boolean mysqlRequireSSL;
|
public static boolean mysqlRequireSSL;
|
||||||
public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
|
public static int delayBetweenRuns, forceToProcessAtLeast, timePerRun;
|
||||||
public static boolean fireCustomEvents;
|
public static boolean fireCustomEvents;
|
||||||
@@ -82,6 +83,7 @@ public class Config {
|
|||||||
def.put("mysql.database", "minecraft");
|
def.put("mysql.database", "minecraft");
|
||||||
def.put("mysql.user", "username");
|
def.put("mysql.user", "username");
|
||||||
def.put("mysql.password", "pass");
|
def.put("mysql.password", "pass");
|
||||||
|
def.put("mysql.useSSL", true);
|
||||||
def.put("mysql.requireSSL", false);
|
def.put("mysql.requireSSL", false);
|
||||||
def.put("consumer.delayBetweenRuns", 2);
|
def.put("consumer.delayBetweenRuns", 2);
|
||||||
def.put("consumer.forceToProcessAtLeast", 200);
|
def.put("consumer.forceToProcessAtLeast", 200);
|
||||||
@@ -167,6 +169,7 @@ public class Config {
|
|||||||
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database");
|
url = "jdbc:mysql://" + config.getString("mysql.host") + ":" + config.getInt("mysql.port") + "/" + getStringIncludingInts(config, "mysql.database");
|
||||||
user = getStringIncludingInts(config, "mysql.user");
|
user = getStringIncludingInts(config, "mysql.user");
|
||||||
password = getStringIncludingInts(config, "mysql.password");
|
password = getStringIncludingInts(config, "mysql.password");
|
||||||
|
mysqlUseSSL = config.getBoolean("mysql.useSSL", true);
|
||||||
mysqlRequireSSL = config.getBoolean("mysql.requireSSL", false);
|
mysqlRequireSSL = config.getBoolean("mysql.requireSSL", false);
|
||||||
delayBetweenRuns = config.getInt("consumer.delayBetweenRuns", 2);
|
delayBetweenRuns = config.getInt("consumer.delayBetweenRuns", 2);
|
||||||
forceToProcessAtLeast = config.getInt("consumer.forceToProcessAtLeast", 0);
|
forceToProcessAtLeast = config.getInt("consumer.forceToProcessAtLeast", 0);
|
||||||
|
@@ -2,7 +2,7 @@ package de.diddiz.LogBlock.listeners;
|
|||||||
|
|
||||||
import de.diddiz.LogBlock.*;
|
import de.diddiz.LogBlock.*;
|
||||||
import de.diddiz.util.BukkitUtils;
|
import de.diddiz.util.BukkitUtils;
|
||||||
import de.diddiz.worldedit.CuboidRegion;
|
import de.diddiz.util.CuboidRegion;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
@@ -1,16 +1,7 @@
|
|||||||
package de.diddiz.worldedit;
|
package de.diddiz.util;
|
||||||
|
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
|
||||||
import com.sk89q.worldedit.LocalSession;
|
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
|
|
||||||
public class CuboidRegion implements Cloneable {
|
public class CuboidRegion implements Cloneable {
|
||||||
@@ -29,31 +20,6 @@ public class CuboidRegion implements Cloneable {
|
|||||||
this.max.setZ(Math.max(first.getBlockZ(), second.getBlockZ()));
|
this.max.setZ(Math.max(first.getBlockZ(), second.getBlockZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CuboidRegion fromPlayerSelection(Player player) {
|
|
||||||
Plugin worldEditPlugin = player.getServer().getPluginManager().getPlugin("WorldEdit");
|
|
||||||
LocalSession session = ((WorldEditPlugin) worldEditPlugin).getSession(player);
|
|
||||||
World world = player.getWorld();
|
|
||||||
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(world);
|
|
||||||
if (!weWorld.equals(session.getSelectionWorld())) {
|
|
||||||
throw new IllegalArgumentException("No selection defined");
|
|
||||||
}
|
|
||||||
Region selection;
|
|
||||||
try {
|
|
||||||
selection = session.getSelection(weWorld);
|
|
||||||
} catch (IncompleteRegionException e) {
|
|
||||||
throw new IllegalArgumentException("No selection defined");
|
|
||||||
}
|
|
||||||
if (selection == null) {
|
|
||||||
throw new IllegalArgumentException("No selection defined");
|
|
||||||
}
|
|
||||||
if (!(selection instanceof com.sk89q.worldedit.regions.CuboidRegion)) {
|
|
||||||
throw new IllegalArgumentException("You have to define a cuboid selection");
|
|
||||||
}
|
|
||||||
BlockVector3 min = selection.getMinimumPoint();
|
|
||||||
BlockVector3 max = selection.getMaximumPoint();
|
|
||||||
return new CuboidRegion(world, new BlockVector(min.getBlockX(), min.getBlockY(), min.getBlockZ()), new BlockVector(max.getBlockX(), max.getBlockY(), max.getBlockZ()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CuboidRegion fromCorners(World world, Location first, Location second) {
|
public static CuboidRegion fromCorners(World world, Location first, Location second) {
|
||||||
return new CuboidRegion(world, new BlockVector(first.getBlockX(), first.getBlockY(), first.getBlockZ()), new BlockVector(second.getBlockX(), second.getBlockY(), second.getBlockZ()));
|
return new CuboidRegion(world, new BlockVector(first.getBlockX(), first.getBlockY(), first.getBlockZ()), new BlockVector(second.getBlockX(), second.getBlockY(), second.getBlockZ()));
|
||||||
}
|
}
|
@@ -11,7 +11,7 @@ public class MySQLConnectionPool implements Closeable {
|
|||||||
|
|
||||||
private final HikariDataSource ds;
|
private final HikariDataSource ds;
|
||||||
|
|
||||||
public MySQLConnectionPool(String url, String user, String password, boolean requireSSL) {
|
public MySQLConnectionPool(String url, String user, String password, boolean useSSL, boolean requireSSL) {
|
||||||
this.ds = new HikariDataSource();
|
this.ds = new HikariDataSource();
|
||||||
ds.setJdbcUrl(url);
|
ds.setJdbcUrl(url);
|
||||||
ds.setUsername(user);
|
ds.setUsername(user);
|
||||||
@@ -30,7 +30,7 @@ public class MySQLConnectionPool implements Closeable {
|
|||||||
ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||||
ds.addDataSourceProperty("useServerPrepStmts", "true");
|
ds.addDataSourceProperty("useServerPrepStmts", "true");
|
||||||
|
|
||||||
ds.addDataSourceProperty("useSSL", "true");
|
ds.addDataSourceProperty("useSSL", Boolean.toString(useSSL));
|
||||||
ds.addDataSourceProperty("requireSSL", Boolean.toString(requireSSL));
|
ds.addDataSourceProperty("requireSSL", Boolean.toString(requireSSL));
|
||||||
ds.addDataSourceProperty("verifyServerCertificate", "false");
|
ds.addDataSourceProperty("verifyServerCertificate", "false");
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,6 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -31,7 +30,7 @@ public class UUIDFetcher {
|
|||||||
JSONObject jsonProfile = (JSONObject) profile;
|
JSONObject jsonProfile = (JSONObject) profile;
|
||||||
String id = (String) jsonProfile.get("id");
|
String id = (String) jsonProfile.get("id");
|
||||||
String name = (String) jsonProfile.get("name");
|
String name = (String) jsonProfile.get("name");
|
||||||
UUID uuid = UUIDFetcher.getUUID(id);
|
UUID uuid = getUUID(id);
|
||||||
uuidMap.put(name, uuid);
|
uuidMap.put(name, uuid);
|
||||||
}
|
}
|
||||||
return uuidMap;
|
return uuidMap;
|
||||||
@@ -58,22 +57,4 @@ public class UUIDFetcher {
|
|||||||
private static UUID getUUID(String id) {
|
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));
|
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 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -11,10 +11,12 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.util.BlockVector;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.DoubleTag;
|
import com.sk89q.jnbt.DoubleTag;
|
||||||
import com.sk89q.jnbt.FloatTag;
|
import com.sk89q.jnbt.FloatTag;
|
||||||
@@ -24,11 +26,15 @@ import com.sk89q.jnbt.NBTOutputStream;
|
|||||||
import com.sk89q.jnbt.NamedTag;
|
import com.sk89q.jnbt.NamedTag;
|
||||||
import com.sk89q.jnbt.ShortTag;
|
import com.sk89q.jnbt.ShortTag;
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import de.diddiz.LogBlock.LogBlock;
|
import de.diddiz.LogBlock.LogBlock;
|
||||||
|
import de.diddiz.util.CuboidRegion;
|
||||||
|
|
||||||
public class WorldEditHelper {
|
public class WorldEditHelper {
|
||||||
private static boolean checkedForWorldEdit;
|
private static boolean checkedForWorldEdit;
|
||||||
@@ -58,9 +64,19 @@ public class WorldEditHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Entity restoreEntity(Location location, EntityType type, byte[] serialized) {
|
public static Entity restoreEntity(Location location, EntityType type, byte[] serialized) {
|
||||||
|
if (!hasWorldEdit()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return Internal.restoreEntity(location, type, serialized);
|
return Internal.restoreEntity(location, type, serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CuboidRegion getSelectedRegion(Player player) throws IllegalArgumentException {
|
||||||
|
if (!hasWorldEdit()) {
|
||||||
|
throw new IllegalArgumentException("WorldEdit not found!");
|
||||||
|
}
|
||||||
|
return Internal.getSelectedRegion(player);
|
||||||
|
}
|
||||||
|
|
||||||
private static class Internal {
|
private static class Internal {
|
||||||
private static WorldEditPlugin worldEdit;
|
private static WorldEditPlugin worldEdit;
|
||||||
private static Method getBukkitImplAdapter;
|
private static Method getBukkitImplAdapter;
|
||||||
@@ -133,5 +149,28 @@ public class WorldEditHelper {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CuboidRegion getSelectedRegion(Player player) throws IllegalArgumentException {
|
||||||
|
LocalSession session = worldEdit.getSession(player);
|
||||||
|
World world = player.getWorld();
|
||||||
|
com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(world);
|
||||||
|
if (!weWorld.equals(session.getSelectionWorld())) {
|
||||||
|
throw new IllegalArgumentException("No selection defined");
|
||||||
|
}
|
||||||
|
Region selection;
|
||||||
|
try {
|
||||||
|
selection = session.getSelection(weWorld);
|
||||||
|
} catch (IncompleteRegionException e) {
|
||||||
|
throw new IllegalArgumentException("No selection defined");
|
||||||
|
}
|
||||||
|
if (selection == null) {
|
||||||
|
throw new IllegalArgumentException("No selection defined");
|
||||||
|
}
|
||||||
|
if (!(selection instanceof com.sk89q.worldedit.regions.CuboidRegion)) {
|
||||||
|
throw new IllegalArgumentException("You have to define a cuboid selection");
|
||||||
|
}
|
||||||
|
BlockVector3 min = selection.getMinimumPoint();
|
||||||
|
BlockVector3 max = selection.getMaximumPoint();
|
||||||
|
return new CuboidRegion(world, new BlockVector(min.getBlockX(), min.getBlockY(), min.getBlockZ()), new BlockVector(max.getBlockX(), max.getBlockY(), max.getBlockZ()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user