mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-08 16:44:42 +02:00
Compare commits
2 Commits
chore/sqli
...
7.1.0
Author | SHA1 | Date | |
---|---|---|---|
c7bfd48a21 | |||
dc13783db8 |
@ -385,9 +385,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link #restoreBreedable(Breedable)} instead
|
* @deprecated Use {@link #restoreBreedable(Breedable)} instead
|
||||||
* @since TODO
|
* @since 7.1.0
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true, since = "TODO")
|
@Deprecated(forRemoval = true, since = "7.1.0")
|
||||||
private void restoreAgeable(Ageable entity) {
|
private void restoreAgeable(Ageable entity) {
|
||||||
if (!this.aged.adult) {
|
if (!this.aged.adult) {
|
||||||
entity.setBaby();
|
entity.setBaby();
|
||||||
@ -400,9 +400,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link #storeBreedable(Breedable)} instead
|
* @deprecated Use {@link #storeBreedable(Breedable)} instead
|
||||||
* @since TODO
|
* @since 7.1.0
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true, since = "TODO")
|
@Deprecated(forRemoval = true, since = "7.1.0")
|
||||||
public void storeAgeable(Ageable aged) {
|
public void storeAgeable(Ageable aged) {
|
||||||
this.aged = new AgeableStats();
|
this.aged = new AgeableStats();
|
||||||
this.aged.age = aged.getAge();
|
this.aged.age = aged.getAge();
|
||||||
@ -411,7 +411,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since TODO
|
* @since 7.1.0
|
||||||
*/
|
*/
|
||||||
private void restoreBreedable(Breedable entity) {
|
private void restoreBreedable(Breedable entity) {
|
||||||
if (!this.aged.adult) {
|
if (!this.aged.adult) {
|
||||||
@ -424,7 +424,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since TODO
|
* @since 7.1.0
|
||||||
*/
|
*/
|
||||||
private void storeBreedable(Breedable breedable) {
|
private void storeBreedable(Breedable breedable) {
|
||||||
this.aged = new AgeableStats();
|
this.aged = new AgeableStats();
|
||||||
|
@ -130,6 +130,7 @@ public class SQLManager implements AbstractDB {
|
|||||||
public volatile ConcurrentHashMap<PlotCluster, Queue<UniqueStatement>> clusterTasks;
|
public volatile ConcurrentHashMap<PlotCluster, Queue<UniqueStatement>> clusterTasks;
|
||||||
// Private
|
// Private
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
private boolean supportsGetGeneratedKeys;
|
||||||
private boolean closed = false;
|
private boolean closed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,6 +155,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
this.worldConfiguration = worldConfiguration;
|
this.worldConfiguration = worldConfiguration;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.connection = database.openConnection();
|
this.connection = database.openConnection();
|
||||||
|
final DatabaseMetaData databaseMetaData = this.connection.getMetaData();
|
||||||
|
this.supportsGetGeneratedKeys = databaseMetaData.supportsGetGeneratedKeys();
|
||||||
this.mySQL = database instanceof MySQL;
|
this.mySQL = database instanceof MySQL;
|
||||||
this.globalTasks = new ConcurrentLinkedQueue<>();
|
this.globalTasks = new ConcurrentLinkedQueue<>();
|
||||||
this.notifyTasks = new ConcurrentLinkedQueue<>();
|
this.notifyTasks = new ConcurrentLinkedQueue<>();
|
||||||
@ -161,6 +164,14 @@ public class SQLManager implements AbstractDB {
|
|||||||
this.playerTasks = new ConcurrentHashMap<>();
|
this.playerTasks = new ConcurrentHashMap<>();
|
||||||
this.clusterTasks = new ConcurrentHashMap<>();
|
this.clusterTasks = new ConcurrentHashMap<>();
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
|
|
||||||
|
if (mySQL && !supportsGetGeneratedKeys) {
|
||||||
|
String driver = databaseMetaData.getDriverName();
|
||||||
|
String driverVersion = databaseMetaData.getDriverVersion();
|
||||||
|
throw new SQLException("Database Driver for MySQL does not support Statement#getGeneratedKeys - which breaks " +
|
||||||
|
"PlotSquared functionality (Using " + driver + ":" + driverVersion + ")");
|
||||||
|
}
|
||||||
|
|
||||||
this.SET_OWNER = "UPDATE `" + this.prefix
|
this.SET_OWNER = "UPDATE `" + this.prefix
|
||||||
+ "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND `world` = ?";
|
+ "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ? AND `world` = ?";
|
||||||
this.GET_ALL_PLOTS =
|
this.GET_ALL_PLOTS =
|
||||||
@ -171,20 +182,32 @@ public class SQLManager implements AbstractDB {
|
|||||||
"INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
|
"INSERT INTO `" + this.prefix + "plot_settings` (`plot_plot_id`) values ";
|
||||||
this.CREATE_TIERS =
|
this.CREATE_TIERS =
|
||||||
"INSERT INTO `" + this.prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values ";
|
"INSERT INTO `" + this.prefix + "plot_%tier%` (`plot_plot_id`, `user_uuid`) values ";
|
||||||
this.CREATE_PLOT = "INSERT INTO `" + this.prefix
|
String tempCreatePlot = "INSERT INTO `" + this.prefix
|
||||||
+ "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) VALUES(?, ?, ?, ?, ?)";
|
+ "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) VALUES(?, ?, ?, ?, ?)";
|
||||||
|
if (!supportsGetGeneratedKeys) {
|
||||||
|
tempCreatePlot += " RETURNING `id`";
|
||||||
|
}
|
||||||
|
this.CREATE_PLOT = tempCreatePlot;
|
||||||
if (mySQL) {
|
if (mySQL) {
|
||||||
this.CREATE_PLOT_SAFE = "INSERT IGNORE INTO `" + this.prefix
|
this.CREATE_PLOT_SAFE = "INSERT IGNORE INTO `" + this.prefix
|
||||||
+ "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) SELECT ?, ?, ?, ?, ? FROM DUAL WHERE NOT EXISTS (SELECT null FROM `"
|
+ "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) SELECT ?, ?, ?, ?, ? FROM DUAL WHERE NOT EXISTS (SELECT null FROM `"
|
||||||
+ this.prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?)";
|
+ this.prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?)";
|
||||||
} else {
|
} else {
|
||||||
this.CREATE_PLOT_SAFE = "INSERT INTO `" + this.prefix
|
String tempCreatePlotSafe = "INSERT INTO `" + this.prefix
|
||||||
+ "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT null FROM `"
|
+ "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`, `timestamp`) SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT null FROM `"
|
||||||
+ this.prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?)";
|
+ this.prefix + "plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?)";
|
||||||
|
if (!supportsGetGeneratedKeys) {
|
||||||
|
tempCreatePlotSafe += " RETURNING `id`";
|
||||||
}
|
}
|
||||||
this.CREATE_CLUSTER = "INSERT INTO `" + this.prefix
|
this.CREATE_PLOT_SAFE = tempCreatePlotSafe;
|
||||||
|
}
|
||||||
|
String tempCreateCluster = "INSERT INTO `" + this.prefix
|
||||||
+ "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
|
+ "cluster`(`pos1_x`, `pos1_z`, `pos2_x`, `pos2_z`, `owner`, `world`) VALUES(?, ?, ?, ?, ?, ?)";
|
||||||
|
if (!supportsGetGeneratedKeys) {
|
||||||
|
tempCreateCluster += " RETURNING `id`";
|
||||||
|
}
|
||||||
|
this.CREATE_CLUSTER = tempCreateCluster;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
createTables();
|
createTables();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -1073,9 +1096,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBatch(PreparedStatement statement) throws SQLException {
|
public void addBatch(PreparedStatement statement) throws SQLException {
|
||||||
int inserted = statement.executeUpdate();
|
if (statement.execute() || statement.getUpdateCount() > 0) {
|
||||||
if (inserted > 0) {
|
try (ResultSet keys = supportsGetGeneratedKeys ? statement.getGeneratedKeys() : statement.getResultSet()) {
|
||||||
try (ResultSet keys = statement.getGeneratedKeys()) {
|
|
||||||
if (keys.next()) {
|
if (keys.next()) {
|
||||||
plot.temp = keys.getInt(1);
|
plot.temp = keys.getInt(1);
|
||||||
addPlotTask(plot, new UniqueStatement(
|
addPlotTask(plot, new UniqueStatement(
|
||||||
@ -1145,8 +1167,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBatch(PreparedStatement statement) throws SQLException {
|
public void addBatch(PreparedStatement statement) throws SQLException {
|
||||||
statement.executeUpdate();
|
statement.execute();
|
||||||
try (ResultSet keys = statement.getGeneratedKeys()) {
|
try (ResultSet keys = supportsGetGeneratedKeys ? statement.getGeneratedKeys() : statement.getResultSet()) {
|
||||||
if (keys.next()) {
|
if (keys.next()) {
|
||||||
plot.temp = keys.getInt(1);
|
plot.temp = keys.getInt(1);
|
||||||
}
|
}
|
||||||
@ -3058,8 +3080,8 @@ public class SQLManager implements AbstractDB {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBatch(PreparedStatement statement) throws SQLException {
|
public void addBatch(PreparedStatement statement) throws SQLException {
|
||||||
statement.executeUpdate();
|
statement.execute();
|
||||||
try (ResultSet keys = statement.getGeneratedKeys()) {
|
try (ResultSet keys = supportsGetGeneratedKeys ? statement.getGeneratedKeys() : statement.getResultSet()) {
|
||||||
if (keys.next()) {
|
if (keys.next()) {
|
||||||
cluster.temp = keys.getInt(1);
|
cluster.temp = keys.getInt(1);
|
||||||
}
|
}
|
||||||
|
@ -960,7 +960,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
|
|||||||
* @param caption Caption to send
|
* @param caption Caption to send
|
||||||
* @param asyncReplacement Async variable replacement
|
* @param asyncReplacement Async variable replacement
|
||||||
* @return A Future to be resolved, after the message was sent
|
* @return A Future to be resolved, after the message was sent
|
||||||
* @since TODO
|
* @since 7.1.0
|
||||||
*/
|
*/
|
||||||
public final CompletableFuture<Void> sendMessage(
|
public final CompletableFuture<Void> sendMessage(
|
||||||
@NonNull Caption caption,
|
@NonNull Caption caption,
|
||||||
@ -976,7 +976,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
|
|||||||
* @param asyncReplacements Async variable replacements
|
* @param asyncReplacements Async variable replacements
|
||||||
* @param replacements Sync variable replacements
|
* @param replacements Sync variable replacements
|
||||||
* @return A Future to be resolved, after the message was sent
|
* @return A Future to be resolved, after the message was sent
|
||||||
* @since TODO
|
* @since 7.1.0
|
||||||
*/
|
*/
|
||||||
public final CompletableFuture<Void> sendMessage(
|
public final CompletableFuture<Void> sendMessage(
|
||||||
@NonNull Caption caption,
|
@NonNull Caption caption,
|
||||||
|
@ -174,7 +174,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
* @since 6.4.0
|
* @since 6.4.0
|
||||||
* @deprecated Don't unnecessarily block threads and utilize playerMap - see {@link #getUsernameCaption(UUID)}
|
* @deprecated Don't unnecessarily block threads and utilize playerMap - see {@link #getUsernameCaption(UUID)}
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "TODO")
|
@Deprecated(since = "7.1.0")
|
||||||
public static @NonNull Caption resolveName(final @Nullable UUID owner) {
|
public static @NonNull Caption resolveName(final @Nullable UUID owner) {
|
||||||
return resolveName(owner, true);
|
return resolveName(owner, true);
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
* @since 6.4.0
|
* @since 6.4.0
|
||||||
* @deprecated Don't unnecessarily block threads and utilize playerMap - see {@link #getUsernameCaption(UUID)}
|
* @deprecated Don't unnecessarily block threads and utilize playerMap - see {@link #getUsernameCaption(UUID)}
|
||||||
*/
|
*/
|
||||||
@Deprecated(since = "TODO")
|
@Deprecated(since = "7.1.0")
|
||||||
public static @NonNull Caption resolveName(final @Nullable UUID owner, final boolean blocking) {
|
public static @NonNull Caption resolveName(final @Nullable UUID owner, final boolean blocking) {
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
return TranslatableCaption.of("info.none");
|
return TranslatableCaption.of("info.none");
|
||||||
@ -237,7 +237,7 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
*
|
*
|
||||||
* @param uuid The UUID of the player (for example provided by {@link Plot#getOwner()}
|
* @param uuid The UUID of the player (for example provided by {@link Plot#getOwner()}
|
||||||
* @return A CompletableFuture resolving to a Caption representing the players name of the uuid
|
* @return A CompletableFuture resolving to a Caption representing the players name of the uuid
|
||||||
* @since TODO
|
* @since 7.1.0
|
||||||
*/
|
*/
|
||||||
@Contract("_->!null")
|
@Contract("_->!null")
|
||||||
public @NonNull CompletableFuture<Caption> getUsernameCaption(@Nullable UUID uuid) {
|
public @NonNull CompletableFuture<Caption> getUsernameCaption(@Nullable UUID uuid) {
|
||||||
|
@ -22,7 +22,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.intellectualsites.plotsquared"
|
group = "com.intellectualsites.plotsquared"
|
||||||
version = "7.0.1-SNAPSHOT"
|
version = "7.1.0"
|
||||||
|
|
||||||
if (!File("$rootDir/.git").exists()) {
|
if (!File("$rootDir/.git").exists()) {
|
||||||
logger.lifecycle("""
|
logger.lifecycle("""
|
||||||
|
Reference in New Issue
Block a user