mirror of
https://github.com/songoda/EpicFarming.git
synced 2024-09-30 15:47:31 +02:00
Merge branch 'development'
This commit is contained in:
commit
22c5a44134
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>EpicFarming</artifactId>
|
<artifactId>EpicFarming</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.3.0</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean install</defaultGoal>
|
<defaultGoal>clean install</defaultGoal>
|
||||||
@ -124,7 +124,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.songoda</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>SongodaCore</artifactId>
|
<artifactId>SongodaCore</artifactId>
|
||||||
<version>2.6.13</version>
|
<version>2.6.16</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.songoda.core.compatibility.ServerVersion;
|
|||||||
import com.songoda.core.configuration.Config;
|
import com.songoda.core.configuration.Config;
|
||||||
import com.songoda.core.database.DataMigrationManager;
|
import com.songoda.core.database.DataMigrationManager;
|
||||||
import com.songoda.core.database.DatabaseConnector;
|
import com.songoda.core.database.DatabaseConnector;
|
||||||
|
import com.songoda.core.database.MySQLConnector;
|
||||||
import com.songoda.core.database.SQLiteConnector;
|
import com.songoda.core.database.SQLiteConnector;
|
||||||
import com.songoda.core.gui.GuiManager;
|
import com.songoda.core.gui.GuiManager;
|
||||||
import com.songoda.core.hooks.EconomyManager;
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
@ -136,8 +137,27 @@ public class EpicFarming extends SongodaPlugin {
|
|||||||
new CommandSettings(this)
|
new CommandSettings(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Database stuff.
|
||||||
|
try {
|
||||||
|
if (Settings.MYSQL_ENABLED.getBoolean()) {
|
||||||
|
String hostname = Settings.MYSQL_HOSTNAME.getString();
|
||||||
|
int port = Settings.MYSQL_PORT.getInt();
|
||||||
|
String database = Settings.MYSQL_DATABASE.getString();
|
||||||
|
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, poolSize);
|
||||||
|
this.getLogger().info("Data handler connected using MySQL.");
|
||||||
|
} else {
|
||||||
this.databaseConnector = new SQLiteConnector(this);
|
this.databaseConnector = new SQLiteConnector(this);
|
||||||
this.getLogger().info("Data handler connected using SQLite.");
|
this.getLogger().info("Data handler connected using SQLite.");
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
this.getLogger().severe("Fatal error trying to connect to database. Please make sure all your connection settings are correct and try again. Plugin has been disabled.");
|
||||||
|
this.emergencyStop();
|
||||||
|
}
|
||||||
|
|
||||||
this.dataManager = new DataManager(this.databaseConnector, this);
|
this.dataManager = new DataManager(this.databaseConnector, this);
|
||||||
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
|
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
|
||||||
@ -252,7 +272,7 @@ public class EpicFarming extends SongodaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final boolean finalConverted = converted;
|
final boolean finalConverted = converted;
|
||||||
dataManager.queueAsync(() -> {
|
dataManager.runAsync(() -> {
|
||||||
if (finalConverted) {
|
if (finalConverted) {
|
||||||
console.sendMessage("[" + getDescription().getName() + "] " + ChatColor.GREEN + "Conversion complete :)");
|
console.sendMessage("[" + getDescription().getName() + "] " + ChatColor.GREEN + "Conversion complete :)");
|
||||||
}
|
}
|
||||||
@ -261,7 +281,7 @@ public class EpicFarming extends SongodaPlugin {
|
|||||||
this.farmManager.addFarms(farms.values());
|
this.farmManager.addFarms(farms.values());
|
||||||
this.dataManager.getBoosts((boosts) -> this.boostManager.addBoosts(boosts));
|
this.dataManager.getBoosts((boosts) -> this.boostManager.addBoosts(boosts));
|
||||||
});
|
});
|
||||||
}, "create");
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
@ -30,7 +31,8 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void createBoost(BoostData boostData) {
|
public void createBoost(BoostData boostData) {
|
||||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
this.runAsync(() -> {
|
||||||
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String createBoostedPlayer = "INSERT INTO " + this.getTablePrefix() + "boosted_players (player, multiplier, end_time) VALUES (?, ?, ?)";
|
String createBoostedPlayer = "INSERT INTO " + this.getTablePrefix() + "boosted_players (player, multiplier, end_time) VALUES (?, ?, ?)";
|
||||||
try (PreparedStatement statement = connection.prepareStatement(createBoostedPlayer)) {
|
try (PreparedStatement statement = connection.prepareStatement(createBoostedPlayer)) {
|
||||||
statement.setString(1, boostData.getPlayer().toString());
|
statement.setString(1, boostData.getPlayer().toString());
|
||||||
@ -38,13 +40,17 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
statement.setLong(3, boostData.getEndTime());
|
statement.setLong(3, boostData.getEndTime());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
}
|
||||||
}));
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getBoosts(Consumer<List<BoostData>> callback) {
|
public void getBoosts(Consumer<List<BoostData>> callback) {
|
||||||
List<BoostData> boosts = new ArrayList<>();
|
List<BoostData> boosts = new ArrayList<>();
|
||||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
this.runAsync(() -> {
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
String selectBoostedPlayers = "SELECT * FROM " + this.getTablePrefix() + "boosted_players";
|
String selectBoostedPlayers = "SELECT * FROM " + this.getTablePrefix() + "boosted_players";
|
||||||
ResultSet result = statement.executeQuery(selectBoostedPlayers);
|
ResultSet result = statement.executeQuery(selectBoostedPlayers);
|
||||||
while (result.next()) {
|
while (result.next()) {
|
||||||
@ -53,24 +59,30 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
long endTime = result.getLong("end_time");
|
long endTime = result.getLong("end_time");
|
||||||
boosts.add(new BoostData(multiplier, endTime, player));
|
boosts.add(new BoostData(multiplier, endTime, player));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.sync(() -> callback.accept(boosts));
|
this.sync(() -> callback.accept(boosts));
|
||||||
}));
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteBoost(BoostData boostData) {
|
public void deleteBoost(BoostData boostData) {
|
||||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
this.runAsync(() -> {
|
||||||
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String deleteBoost = "DELETE FROM " + this.getTablePrefix() + "boosted_players WHERE end_time = ?";
|
String deleteBoost = "DELETE FROM " + this.getTablePrefix() + "boosted_players WHERE end_time = ?";
|
||||||
try (PreparedStatement statement = connection.prepareStatement(deleteBoost)) {
|
PreparedStatement statement = connection.prepareStatement(deleteBoost);
|
||||||
statement.setLong(1, boostData.getEndTime());
|
statement.setLong(1, boostData.getEndTime());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createFarm(Farm farm) {
|
public void createFarm(Farm farm) {
|
||||||
this.queueAsync(() -> this.databaseConnector.connect(connection -> {
|
this.runAsync(() -> {
|
||||||
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String createFarm = "INSERT INTO " + this.getTablePrefix() + "active_farms (farm_type, level, placed_by, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
String createFarm = "INSERT INTO " + this.getTablePrefix() + "active_farms (farm_type, level, placed_by, world, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
||||||
try (PreparedStatement statement = connection.prepareStatement(createFarm)) {
|
try (PreparedStatement statement = connection.prepareStatement(createFarm)) {
|
||||||
statement.setString(1, farm.getFarmType().name());
|
statement.setString(1, farm.getFarmType().name());
|
||||||
@ -96,7 +108,10 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
}
|
}
|
||||||
statement.executeBatch();
|
statement.executeBatch();
|
||||||
}
|
}
|
||||||
}), "create");
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createFarms(List<Farm> farms) {
|
public void createFarms(List<Farm> farms) {
|
||||||
@ -106,19 +121,23 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateFarm(Farm farm) {
|
public void updateFarm(Farm farm) {
|
||||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
this.runAsync(() -> {
|
||||||
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String updateFarm = "UPDATE " + this.getTablePrefix() + "active_farms SET level = ?, farm_type = ? WHERE id = ?";
|
String updateFarm = "UPDATE " + this.getTablePrefix() + "active_farms SET level = ?, farm_type = ? WHERE id = ?";
|
||||||
try (PreparedStatement statement = connection.prepareStatement(updateFarm)) {
|
PreparedStatement statement = connection.prepareStatement(updateFarm);
|
||||||
statement.setInt(1, farm.getLevel().getLevel());
|
statement.setInt(1, farm.getLevel().getLevel());
|
||||||
statement.setString(2, farm.getFarmType().name());
|
statement.setString(2, farm.getFarmType().name());
|
||||||
statement.setInt(3, farm.getId());
|
statement.setInt(3, farm.getId());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteFarm(Farm farm) {
|
public void deleteFarm(Farm farm) {
|
||||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
this.runAsync(() -> {
|
||||||
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String deleteFarm = "DELETE FROM " + this.getTablePrefix() + "active_farms WHERE id = ?";
|
String deleteFarm = "DELETE FROM " + this.getTablePrefix() + "active_farms WHERE id = ?";
|
||||||
try (PreparedStatement statement = connection.prepareStatement(deleteFarm)) {
|
try (PreparedStatement statement = connection.prepareStatement(deleteFarm)) {
|
||||||
statement.setInt(1, farm.getId());
|
statement.setInt(1, farm.getId());
|
||||||
@ -130,15 +149,18 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
statement.setInt(1, farm.getId());
|
statement.setInt(1, farm.getId());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
}
|
||||||
}));
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItemsAsync(Farm farm) {
|
public void updateItemsAsync(Farm farm) {
|
||||||
this.async(() -> updateItems(farm));
|
this.runAsync(() -> updateItems(farm));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItems(Farm farm) {
|
public void updateItems(Farm farm) {
|
||||||
this.databaseConnector.connect(connection -> {
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
String deleteItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE farm_id = ?";
|
String deleteItems = "DELETE FROM " + this.getTablePrefix() + "items WHERE farm_id = ?";
|
||||||
try (PreparedStatement statement = connection.prepareStatement(deleteItems)) {
|
try (PreparedStatement statement = connection.prepareStatement(deleteItems)) {
|
||||||
statement.setInt(1, farm.getId());
|
statement.setInt(1, farm.getId());
|
||||||
@ -155,12 +177,15 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
}
|
}
|
||||||
statement.executeBatch();
|
statement.executeBatch();
|
||||||
}
|
}
|
||||||
});
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
farm.setNeedsToBeSaved(false);
|
farm.setNeedsToBeSaved(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getFarms(Consumer<Map<Integer, Farm>> callback) {
|
public void getFarms(Consumer<Map<Integer, Farm>> callback) {
|
||||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
this.runAsync(() -> {
|
||||||
|
try (Connection connection = this.databaseConnector.getConnection()) {
|
||||||
Map<Integer, Farm> farms = new HashMap<>();
|
Map<Integer, Farm> farms = new HashMap<>();
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = connection.createStatement()) {
|
||||||
String selectFarms = "SELECT * FROM " + this.getTablePrefix() + "active_farms";
|
String selectFarms = "SELECT * FROM " + this.getTablePrefix() + "active_farms";
|
||||||
@ -211,6 +236,9 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.sync(() -> callback.accept(farms));
|
this.sync(() -> callback.accept(farms));
|
||||||
}));
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,15 @@ public class Settings {
|
|||||||
"The enabled language file.",
|
"The enabled language file.",
|
||||||
"More language files (if available) can be found in the plugins data folder.");
|
"More language files (if available) can be found in the plugins data folder.");
|
||||||
|
|
||||||
|
public static final ConfigSetting MYSQL_ENABLED = new ConfigSetting(config, "MySQL.Enabled", false, "Set to 'true' to use MySQL instead of SQLite for data storage.");
|
||||||
|
public static final ConfigSetting MYSQL_HOSTNAME = new ConfigSetting(config, "MySQL.Hostname", "localhost");
|
||||||
|
public static final ConfigSetting MYSQL_PORT = new ConfigSetting(config, "MySQL.Port", 3306);
|
||||||
|
public static final ConfigSetting MYSQL_DATABASE = new ConfigSetting(config, "MySQL.Database", "your-database");
|
||||||
|
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.");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In order to set dynamic economy comment correctly, this needs to be
|
* In order to set dynamic economy comment correctly, this needs to be
|
||||||
* called after EconomyManager load
|
* called after EconomyManager load
|
||||||
|
Loading…
Reference in New Issue
Block a user