mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-14 22:25:22 +01:00
Merge branch 'development'
This commit is contained in:
commit
f8684dc13b
17
pom.xml
17
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>2.2.2</version>
|
||||
<version>2.3.0</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>UltimateStacker-${project.version}</finalName>
|
||||
@ -11,11 +11,13 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.google.code.maven-replacer-plugin</groupId>
|
||||
<artifactId>replacer</artifactId>
|
||||
@ -38,10 +40,11 @@
|
||||
</replacements>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0-SNAPSHOT</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shaded</id>
|
||||
@ -80,12 +83,7 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>apache.snapshots</id>
|
||||
<url>https://repository.apache.org/snapshots/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>songoda-public</id>
|
||||
@ -102,6 +100,7 @@
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
@ -113,7 +112,7 @@
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>SongodaCore</artifactId>
|
||||
<version>2.6.14-DEV</version>
|
||||
<version>2.6.16</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -109,7 +109,6 @@ public class UltimateStacker extends SongodaPlugin {
|
||||
public void onPluginEnable() {
|
||||
// Run Songoda Updater
|
||||
SongodaCore.registerPlugin(this, 16, CompatibleMaterial.IRON_INGOT);
|
||||
|
||||
// Setup Config
|
||||
Settings.setupConfig();
|
||||
this.setLocale(Settings.LANGUGE_MODE.getString(), false);
|
||||
@ -209,8 +208,9 @@ public class UltimateStacker extends SongodaPlugin {
|
||||
String username = Settings.MYSQL_USERNAME.getString();
|
||||
String password = Settings.MYSQL_PASSWORD.getString();
|
||||
boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean();
|
||||
int poolSize = Settings.MYSQL_POOL_SIZE.getInt();
|
||||
|
||||
this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL);
|
||||
this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL, poolSize);
|
||||
this.getLogger().info("Data handler connected using MySQL.");
|
||||
} else {
|
||||
this.databaseConnector = new SQLiteConnector(this);
|
||||
|
@ -5,6 +5,7 @@ import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.stackable.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -54,7 +55,7 @@ public class CommandSpawn extends AbstractCommand {
|
||||
}
|
||||
sender.sendMessage(TextUtils.formatText("&6" + list));
|
||||
} else {
|
||||
LivingEntity entity = (LivingEntity)player.getWorld().spawnEntity(player.getTargetBlock((Set<Material>)null, 200).getLocation(), type);
|
||||
LivingEntity entity = (LivingEntity)player.getWorld().spawnEntity(player.getLocation(), type);
|
||||
EntityStack stack = plugin.getEntityStackManager().addStack(entity);
|
||||
stack.createDuplicates(((Methods.isInt(args[1])) ? Integer.parseInt(args[1]) : 1) - 1);
|
||||
stack.updateStack();
|
||||
|
@ -13,9 +13,12 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.checkerframework.common.returnsreceiver.qual.This;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -32,36 +35,41 @@ public class DataManager extends DataManagerAbstract {
|
||||
}
|
||||
|
||||
public void bulkUpdateSpawners(Collection<SpawnerStack> spawnerStacks) {
|
||||
this.databaseConnector.connect(connection -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String updateSpawner = "UPDATE " + this.getTablePrefix() + "spawners SET amount = ? WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(updateSpawner)) {
|
||||
for (SpawnerStack spawnerStack : spawnerStacks) {
|
||||
statement.setInt(1, spawnerStack.getAmount());
|
||||
statement.setInt(2, spawnerStack.getId());
|
||||
statement.addBatch();
|
||||
}
|
||||
PreparedStatement statement = connection.prepareStatement(updateSpawner);
|
||||
for (SpawnerStack spawnerStack : spawnerStacks) {
|
||||
statement.setInt(1, spawnerStack.getAmount());
|
||||
statement.setInt(2, spawnerStack.getId());
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
statement.executeBatch();
|
||||
public void updateSpawner(SpawnerStack spawnerStack) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
|
||||
String updateSpawner = "UPDATE " + this.getTablePrefix() + "spawners SET amount = ? WHERE id = ?";
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(updateSpawner);
|
||||
statement.setInt(1, spawnerStack.getAmount());
|
||||
statement.setInt(2, spawnerStack.getId());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateSpawner(SpawnerStack spawnerStack) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String updateSpawner = "UPDATE " + this.getTablePrefix() + "spawners SET amount = ? WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(updateSpawner)) {
|
||||
statement.setInt(1, spawnerStack.getAmount());
|
||||
statement.setInt(2, spawnerStack.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void createSpawner(SpawnerStack spawnerStack) {
|
||||
this.queueAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
|
||||
String createSpawner = "INSERT INTO " + this.getTablePrefix() + "spawners (amount, world, x, y, z) VALUES (?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createSpawner)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createSpawner = "INSERT INTO " + this.getTablePrefix() + "spawners (amount, world, x, y, z) VALUES (?, ?, ?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createSpawner);
|
||||
statement.setInt(1, spawnerStack.getAmount());
|
||||
|
||||
statement.setString(2, spawnerStack.getWorld().getName());
|
||||
@ -69,29 +77,34 @@ public class DataManager extends DataManagerAbstract {
|
||||
statement.setInt(4, spawnerStack.getY());
|
||||
statement.setInt(5, spawnerStack.getZ());
|
||||
statement.executeUpdate();
|
||||
int spawnerId = this.lastInsertedId(connection, "spawners");
|
||||
this.sync(() -> spawnerStack.setId(spawnerId));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
int spawnerId = this.lastInsertedId(connection, "spawners");
|
||||
this.sync(() -> spawnerStack.setId(spawnerId));
|
||||
}), "create");
|
||||
});
|
||||
}
|
||||
|
||||
public void updateBlock(BlockStack blockStack) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
if (blockStack.getAmount() == 0) return;
|
||||
String updateBlock = "UPDATE " + this.getTablePrefix() + "blocks SET amount = ? WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(updateBlock)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String updateBlock = "UPDATE " + this.getTablePrefix() + "blocks SET amount = ? WHERE id = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(updateBlock);
|
||||
if (blockStack.getAmount() == 0) return;
|
||||
statement.setInt(1, blockStack.getAmount());
|
||||
statement.setInt(2, blockStack.getId());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void createBlock(BlockStack blockStack) {
|
||||
this.queueAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
|
||||
String createSpawner = "INSERT INTO " + this.getTablePrefix() + "blocks (amount, material, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createSpawner)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createSpawner = "INSERT INTO " + this.getTablePrefix() + "blocks (amount, material, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createSpawner);
|
||||
statement.setInt(1, blockStack.getAmount());
|
||||
statement.setString(2, blockStack.getMaterial().name());
|
||||
|
||||
@ -100,43 +113,52 @@ public class DataManager extends DataManagerAbstract {
|
||||
statement.setInt(5, blockStack.getY());
|
||||
statement.setInt(6, blockStack.getZ());
|
||||
statement.executeUpdate();
|
||||
int blockId = this.lastInsertedId(connection, "blocks");
|
||||
this.sync(() -> blockStack.setId(blockId));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
int blockId = this.lastInsertedId(connection, "blocks");
|
||||
this.sync(() -> blockStack.setId(blockId));
|
||||
}), "create");
|
||||
});
|
||||
}
|
||||
|
||||
public void createHostEntity(ColdEntityStack stack) {
|
||||
this.queueAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
String createSerializedEntity = "INSERT INTO " + this.getTablePrefix() + "host_entities (uuid, create_duplicates) VALUES (?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createSerializedEntity)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createSerializedEntity = "INSERT INTO " + this.getTablePrefix() + "host_entities (uuid, create_duplicates) VALUES (?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createSerializedEntity);
|
||||
if (stack == null || stack.getHostUniqueId() == null) return;
|
||||
statement.setString(1, stack.getHostUniqueId().toString());
|
||||
statement.setInt(2, stack.getCreateDuplicates());
|
||||
statement.executeUpdate();
|
||||
int stackId = this.lastInsertedId(connection, "host_entities");
|
||||
this.sync(() -> stack.setId(stackId));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
int stackId = this.lastInsertedId(connection, "host_entities");
|
||||
this.sync(() -> stack.setId(stackId));
|
||||
}), "create");
|
||||
});
|
||||
}
|
||||
|
||||
public void createStackedEntity(EntityStack hostStack, StackedEntity stackedEntity) {
|
||||
this.queueAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
String createSerializedEntity = "INSERT INTO " + this.getTablePrefix() + "stacked_entities (uuid, host, serialized_entity) VALUES (?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createSerializedEntity)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()){
|
||||
String createSerializedEntity = "INSERT INTO " + this.getTablePrefix() + "stacked_entities (uuid, host, serialized_entity) VALUES (?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createSerializedEntity);
|
||||
if (hostStack.getHostUniqueId() == null) return;
|
||||
statement.setString(1, stackedEntity.getUniqueId().toString());
|
||||
statement.setInt(2, hostStack.getId());
|
||||
statement.setBytes(3, stackedEntity.getSerializedEntity());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}), "create");
|
||||
});
|
||||
}
|
||||
|
||||
public void createStackedEntities(ColdEntityStack hostStack, List<StackedEntity> stackedEntities) {
|
||||
this.queueAsync(() -> this.databaseConnector.connect(connection -> {
|
||||
String createSerializedEntity = "REPLACE INTO " + this.getTablePrefix() + "stacked_entities (uuid, host, serialized_entity) VALUES (?, ?, ?)";
|
||||
try (PreparedStatement statement = connection.prepareStatement(createSerializedEntity)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String createSerializedEntity = "REPLACE INTO " + this.getTablePrefix() + "stacked_entities (uuid, host, serialized_entity) VALUES (?, ?, ?)";
|
||||
PreparedStatement statement = connection.prepareStatement(createSerializedEntity);
|
||||
if (hostStack.getHostUniqueId() == null) return;
|
||||
for (StackedEntity entity : stackedEntities) {
|
||||
statement.setString(1, entity.getUniqueId().toString());
|
||||
@ -145,194 +167,225 @@ public class DataManager extends DataManagerAbstract {
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}), "create");
|
||||
});
|
||||
}
|
||||
|
||||
public void updateHost(ColdEntityStack hostStack) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String updateHost = "UPDATE " + this.getTablePrefix() + "host_entities SET uuid = ?, create_duplicates = ?, updated_at = current_timestamp WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(updateHost)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String updateHost = "UPDATE " + this.getTablePrefix() + "host_entities SET uuid = ?, create_duplicates = ?, updated_at = current_timestamp WHERE id = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(updateHost);
|
||||
if (hostStack.getHostUniqueId() == null) return;
|
||||
statement.setString(1, hostStack.getHostUniqueId().toString());
|
||||
statement.setInt(2, hostStack.getCreateDuplicates());
|
||||
statement.setInt(3, hostStack.getId());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteHost(ColdEntityStack stack) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String deleteHost = "DELETE FROM " + this.getTablePrefix() + "host_entities WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteHost)) {
|
||||
statement.setInt(1, stack.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteHost = "DELETE FROM " + this.getTablePrefix() + "host_entities WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteHost)) {
|
||||
statement.setInt(1, stack.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
String deleteStackedEntities = "DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE host = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteStackedEntities)) {
|
||||
statement.setInt(1, stack.getId());
|
||||
statement.executeUpdate();
|
||||
String deleteStackedEntities = "DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE host = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteStackedEntities)) {
|
||||
statement.setInt(1, stack.getId());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteStackedEntity(UUID uuid) {
|
||||
if (uuid == null)
|
||||
return;
|
||||
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String deleteStackedEntity = "DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE uuid = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteStackedEntity)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteStackedEntity = "DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE uuid = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(deleteStackedEntity);
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteStackedEntities(List<StackedEntity> entities) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String deleteStackedEntities = "DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE uuid = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteStackedEntities)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteStackedEntities = "DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE uuid = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(deleteStackedEntities);
|
||||
for (StackedEntity entity : entities) {
|
||||
if (entity == null) continue;
|
||||
statement.setString(1, entity.getUniqueId().toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
statement.executeBatch();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteSpawner(SpawnerStack spawnerStack) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String deleteSpawner = "DELETE FROM " + this.getTablePrefix() + "spawners WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteSpawner)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteSpawner = "DELETE FROM " + this.getTablePrefix() + "spawners WHERE id = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(deleteSpawner);
|
||||
statement.setInt(1, spawnerStack.getId());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteBlock(BlockStack blockStack) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String deleteBlock = "DELETE FROM " + this.getTablePrefix() + "blocks WHERE id = ?";
|
||||
try (PreparedStatement statement = connection.prepareStatement(deleteBlock)) {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String deleteBlock = "DELETE FROM " + this.getTablePrefix() + "blocks WHERE id = ?";
|
||||
PreparedStatement statement = connection.prepareStatement(deleteBlock);
|
||||
statement.setInt(1, blockStack.getId());
|
||||
statement.executeUpdate();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void getEntities(Consumer<Map<Integer, ColdEntityStack>> callback) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
|
||||
Map<Integer, ColdEntityStack> entities = new HashMap<>();
|
||||
Map<Integer, ColdEntityStack> entities = new HashMap<>();
|
||||
|
||||
boolean mysql = Settings.MYSQL_ENABLED.getBoolean();
|
||||
int databasePurge = Settings.DATABASE_PURGE.getInt();
|
||||
String whereStatement = mysql ? "WHERE updated_at < NOW() - INTERVAL " + databasePurge + " DAY" : "WHERE updated_at <= date('now','-" + databasePurge + " day')";
|
||||
String selectOldEntities = "SELECT * FROM " + this.getTablePrefix() + "host_entities " + whereStatement;
|
||||
boolean mysql = Settings.MYSQL_ENABLED.getBoolean();
|
||||
int databasePurge = Settings.DATABASE_PURGE.getInt();
|
||||
String whereStatement = mysql ? "WHERE updated_at < NOW() - INTERVAL " + databasePurge + " DAY" : "WHERE updated_at <= date('now','-" + databasePurge + " day')";
|
||||
String selectOldEntities = "SELECT * FROM " + this.getTablePrefix() + "host_entities " + whereStatement;
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
List<String> toDelete = new ArrayList<>();
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
List<String> toDelete = new ArrayList<>();
|
||||
|
||||
ResultSet result = statement.executeQuery(selectOldEntities);
|
||||
while (result.next()) {
|
||||
int hostId = result.getInt("id");
|
||||
toDelete.add(String.valueOf(hostId));
|
||||
ResultSet result = statement.executeQuery(selectOldEntities);
|
||||
while (result.next()) {
|
||||
int hostId = result.getInt("id");
|
||||
toDelete.add(String.valueOf(hostId));
|
||||
}
|
||||
|
||||
if (!toDelete.isEmpty()) {
|
||||
statement.execute("DELETE FROM " + this.getTablePrefix() + "host_entities " + whereStatement);
|
||||
statement.execute("DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE host IN (" + String.join(", ", toDelete) + ")");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!toDelete.isEmpty()) {
|
||||
statement.execute("DELETE FROM " + this.getTablePrefix() + "host_entities " + whereStatement);
|
||||
statement.execute("DELETE FROM " + this.getTablePrefix() + "stacked_entities WHERE host IN (" + String.join(", ", toDelete) + ")");
|
||||
|
||||
String selectEntities = "SELECT * FROM " + this.getTablePrefix() + "host_entities";
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(selectEntities);
|
||||
while (result.next()) {
|
||||
int hostId = result.getInt("id");
|
||||
|
||||
UUID host = UUID.fromString(result.getString("uuid"));
|
||||
|
||||
int createDuplicates = result.getInt("create_duplicates");
|
||||
|
||||
ColdEntityStack stack = new ColdEntityStack(host, hostId);
|
||||
stack.createDuplicates(createDuplicates);
|
||||
entities.put(hostId, stack);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
String selectStackedEntities = "SELECT * FROM " + this.getTablePrefix() + "stacked_entities";
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(selectStackedEntities);
|
||||
while (result.next()) {
|
||||
UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||
int hostId = result.getInt("host");
|
||||
byte[] serializedEntity = result.getBytes("serialized_entity");
|
||||
|
||||
ColdEntityStack stack = entities.get(hostId);
|
||||
if (stack == null) continue;
|
||||
stack.addEntityToStackSilently(new StackedEntity(uuid, serializedEntity));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.sync(() -> callback.accept(entities));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
String selectEntities = "SELECT * FROM " + this.getTablePrefix() + "host_entities";
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(selectEntities);
|
||||
while (result.next()) {
|
||||
int hostId = result.getInt("id");
|
||||
|
||||
UUID host = UUID.fromString(result.getString("uuid"));
|
||||
|
||||
int createDuplicates = result.getInt("create_duplicates");
|
||||
|
||||
ColdEntityStack stack = new ColdEntityStack(host, hostId);
|
||||
stack.createDuplicates(createDuplicates);
|
||||
entities.put(hostId, stack);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
String selectStackedEntities = "SELECT * FROM " + this.getTablePrefix() + "stacked_entities";
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(selectStackedEntities);
|
||||
while (result.next()) {
|
||||
UUID uuid = UUID.fromString(result.getString("uuid"));
|
||||
int hostId = result.getInt("host");
|
||||
byte[] serializedEntity = result.getBytes("serialized_entity");
|
||||
|
||||
ColdEntityStack stack = entities.get(hostId);
|
||||
if (stack == null) continue;
|
||||
stack.addEntityToStackSilently(new StackedEntity(uuid, serializedEntity));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.sync(() -> callback.accept(entities));
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void getSpawners(Consumer<Map<Location, SpawnerStack>> callback) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String selectSpawners = "SELECT * FROM " + this.getTablePrefix() + "spawners";
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()){
|
||||
String selectSpawners = "SELECT * FROM " + this.getTablePrefix() + "spawners";
|
||||
|
||||
Map<Location, SpawnerStack> spawners = new HashMap<>();
|
||||
Map<Location, SpawnerStack> spawners = new HashMap<>();
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(selectSpawners);
|
||||
while (result.next()) {
|
||||
World world = Bukkit.getWorld(result.getString("world"));
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(selectSpawners);
|
||||
while (result.next()) {
|
||||
World world = Bukkit.getWorld(result.getString("world"));
|
||||
|
||||
if (world == null)
|
||||
continue;
|
||||
if (world == null)
|
||||
continue;
|
||||
|
||||
int spawnerId = result.getInt("id");
|
||||
int spawnerId = result.getInt("id");
|
||||
|
||||
int amount = result.getInt("amount");
|
||||
int amount = result.getInt("amount");
|
||||
|
||||
int x = result.getInt("x");
|
||||
int y = result.getInt("y");
|
||||
int z = result.getInt("z");
|
||||
Location location = new Location(world, x, y, z);
|
||||
int x = result.getInt("x");
|
||||
int y = result.getInt("y");
|
||||
int z = result.getInt("z");
|
||||
Location location = new Location(world, x, y, z);
|
||||
|
||||
SpawnerStack spawnerStack = new SpawnerStack(location, amount);
|
||||
spawnerStack.setId(spawnerId);
|
||||
spawners.put(location, spawnerStack);
|
||||
SpawnerStack spawnerStack = new SpawnerStack(location, amount);
|
||||
spawnerStack.setId(spawnerId);
|
||||
spawners.put(location, spawnerStack);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.sync(() -> callback.accept(spawners));
|
||||
}));
|
||||
this.sync(() -> callback.accept(spawners));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getBlocks(Consumer<Map<Location, BlockStack>> callback) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
String selectBlocks = "SELECT * FROM " + this.getTablePrefix() + "blocks";
|
||||
this.runAsync(() -> {
|
||||
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||
String selectBlocks = "SELECT * FROM " + this.getTablePrefix() + "blocks";
|
||||
|
||||
Map<Location, BlockStack> blocks = new HashMap<>();
|
||||
Map<Location, BlockStack> blocks = new HashMap<>();
|
||||
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet result = statement.executeQuery(selectBlocks);
|
||||
while (result.next()) {
|
||||
World world = Bukkit.getWorld(result.getString("world"));
|
||||
@ -354,12 +407,12 @@ public class DataManager extends DataManagerAbstract {
|
||||
BlockStack blockStack = new BlockStack(material, location, amount);
|
||||
blockStack.setId(blockId);
|
||||
blocks.put(location, blockStack);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.sync(() -> callback.accept(blocks));
|
||||
}));
|
||||
this.sync(() -> callback.accept(blocks));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -283,6 +283,7 @@ public class Settings {
|
||||
public static final ConfigSetting MYSQL_USERNAME = new ConfigSetting(config, "MySQL.Username", "user");
|
||||
public static final ConfigSetting MYSQL_PASSWORD = new ConfigSetting(config, "MySQL.Password", "pass");
|
||||
public static final ConfigSetting MYSQL_USE_SSL = new ConfigSetting(config, "MySQL.Use SSL", false);
|
||||
public static final ConfigSetting MYSQL_POOL_SIZE = new ConfigSetting(config, "MySQL.Pool Size", 3, "Determines the number of connections the pool is using. Increase this value if you are getting timeout errors when more players online.");
|
||||
|
||||
public static void setupConfig() {
|
||||
config.load();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.ultimatestacker.stackable.entity;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.lootables.loot.Drop;
|
||||
import com.songoda.core.lootables.loot.DropUtils;
|
||||
@ -94,7 +95,6 @@ public class EntityStack extends ColdEntityStack {
|
||||
}
|
||||
|
||||
private void handleWholeStackDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp, EntityDeathEvent event) {
|
||||
plugin.getEntityStackManager().removeStack(event.getEntity());
|
||||
plugin.getDataManager().deleteHost(this);
|
||||
|
||||
List<Drop> preStackedDrops = new ArrayList<>();
|
||||
@ -124,6 +124,7 @@ public class EntityStack extends ColdEntityStack {
|
||||
|
||||
if (killed.getKiller() == null) return;
|
||||
plugin.addExp(killed.getKiller(), this);
|
||||
plugin.getEntityStackManager().removeStack(event.getEntity());
|
||||
}
|
||||
|
||||
private void handleSingleStackDeath(LivingEntity killed, List<Drop> drops, int droppedExp, EntityDeathEvent event) {
|
||||
|
Loading…
Reference in New Issue
Block a user