1.17.5
This commit is contained in:
parent
4dece13680
commit
a838423a94
5 changed files with 52 additions and 30 deletions
|
|
@ -63,7 +63,13 @@ public class MainConfigManager {
|
||||||
Path pathConfig = Paths.get(configFile.getRoute());
|
Path pathConfig = Paths.get(configFile.getRoute());
|
||||||
try{
|
try{
|
||||||
String text = new String(Files.readAllBytes(pathConfig));
|
String text = new String(Files.readAllBytes(pathConfig));
|
||||||
|
if(!text.contains("verifyServerCertificate:")){
|
||||||
|
getConfig().set("mysql_database.pool.connectionTimeout",5000);
|
||||||
|
getConfig().set("mysql_database.advanced.verifyServerCertificate",false);
|
||||||
|
getConfig().set("mysql_database.advanced.useSSL",true);
|
||||||
|
getConfig().set("mysql_database.advanced.allowPublicKeyRetrieval",true);
|
||||||
|
configFile.saveConfig();
|
||||||
|
}
|
||||||
if(!text.contains("new_kit_default_save_mode_original:")){
|
if(!text.contains("new_kit_default_save_mode_original:")){
|
||||||
getConfig().set("new_kit_default_save_mode_original", true);
|
getConfig().set("new_kit_default_save_mode_original", true);
|
||||||
configFile.saveConfig();
|
configFile.saveConfig();
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,47 @@ package pk.ajneb97.database;
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
public class HikariConnection {
|
public class HikariConnection {
|
||||||
|
|
||||||
private HikariDataSource hikari;
|
private HikariDataSource hikari;
|
||||||
|
|
||||||
public HikariConnection(String ip, int port, String database, String username, String password) {
|
public HikariConnection(FileConfiguration config) {
|
||||||
HikariConfig config = new HikariConfig();
|
HikariConfig hikariConfig = new HikariConfig();
|
||||||
config.setJdbcUrl("jdbc:mysql://" + ip + ":" + port + "/" + database);
|
String path = "mysql_database";
|
||||||
config.setUsername(username);
|
|
||||||
config.setPassword(password);
|
String host = config.getString(path+".host");
|
||||||
config.addDataSourceProperty("autoReconnect", "true");
|
int port = config.getInt(path+".port");
|
||||||
config.addDataSourceProperty("leakDetectionThreshold", "true");
|
String database = config.getString(path+".database");
|
||||||
config.addDataSourceProperty("verifyServerCertificate", "false");
|
String username = config.getString(path+".username");
|
||||||
config.addDataSourceProperty("useSSL", "false");
|
String password = config.getString(path+".password");
|
||||||
config.setConnectionTimeout(5000);
|
|
||||||
hikari = new HikariDataSource(config);
|
hikariConfig.setJdbcUrl("jdbc:mysql://" + host + ":" + port + "/" + database);
|
||||||
|
hikariConfig.setUsername(username);
|
||||||
|
hikariConfig.setPassword(password);
|
||||||
|
|
||||||
|
if(config.contains(path+".pool.connectionTimeout")){
|
||||||
|
hikariConfig.setConnectionTimeout(config.getLong(path+".pool.connectionTimeout"));
|
||||||
|
}
|
||||||
|
if(config.contains(path+".pool.maximumPoolSize")){
|
||||||
|
hikariConfig.setMaximumPoolSize(config.getInt(path+".pool.maximumPoolSize"));
|
||||||
|
}
|
||||||
|
if(config.contains(path+".pool.connectionTimeout")){
|
||||||
|
hikariConfig.setKeepaliveTime(config.getLong(path+".pool.keepaliveTime"));
|
||||||
|
}
|
||||||
|
if(config.contains(path+".pool.idleTimeout")){
|
||||||
|
hikariConfig.setIdleTimeout(config.getLong(path+".pool.idleTimeout"));
|
||||||
|
}
|
||||||
|
if(config.contains(path+".pool.maxLifetime")){
|
||||||
|
hikariConfig.setMaxLifetime(config.getLong(path+".pool.maxLifetime"));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String key : config.getConfigurationSection(path+".advanced").getKeys(false)){
|
||||||
|
hikariConfig.addDataSourceProperty(key,config.get(path+".advanced."+key));
|
||||||
|
}
|
||||||
|
|
||||||
|
hikari = new HikariDataSource(hikariConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HikariDataSource getHikari() {
|
public HikariDataSource getHikari() {
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,6 @@ public class MySQLConnection {
|
||||||
|
|
||||||
private PlayerKits2 plugin;
|
private PlayerKits2 plugin;
|
||||||
private HikariConnection connection;
|
private HikariConnection connection;
|
||||||
private String host;
|
|
||||||
private String database;
|
|
||||||
private String username;
|
|
||||||
private String password;
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
public MySQLConnection(PlayerKits2 plugin){
|
public MySQLConnection(PlayerKits2 plugin){
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
@ -31,12 +26,7 @@ public class MySQLConnection {
|
||||||
public void setupMySql(){
|
public void setupMySql(){
|
||||||
FileConfiguration config = plugin.getConfigsManager().getMainConfigManager().getConfig();
|
FileConfiguration config = plugin.getConfigsManager().getMainConfigManager().getConfig();
|
||||||
try {
|
try {
|
||||||
host = config.getString("mysql_database.host");
|
connection = new HikariConnection(config);
|
||||||
port = Integer.valueOf(config.getString("mysql_database.port"));
|
|
||||||
database = config.getString("mysql_database.database");
|
|
||||||
username = config.getString("mysql_database.username");
|
|
||||||
password = config.getString("mysql_database.password");
|
|
||||||
connection = new HikariConnection(host,port,database,username,password);
|
|
||||||
connection.getHikari().getConnection();
|
connection.getHikari().getConnection();
|
||||||
createTables();
|
createTables();
|
||||||
loadData();
|
loadData();
|
||||||
|
|
@ -46,11 +36,6 @@ public class MySQLConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getDatabase() {
|
|
||||||
return this.database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConnection() {
|
public Connection getConnection() {
|
||||||
try {
|
try {
|
||||||
return connection.getHikari().getConnection();
|
return connection.getHikari().getConnection();
|
||||||
|
|
|
||||||
|
|
@ -50,3 +50,9 @@ mysql_database:
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
database: database
|
database: database
|
||||||
|
pool:
|
||||||
|
connectionTimeout: 5000
|
||||||
|
advanced:
|
||||||
|
verifyServerCertificate: false
|
||||||
|
useSSL: true
|
||||||
|
allowPublicKeyRetrieval: true
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
main: pk.ajneb97.PlayerKits2
|
main: pk.ajneb97.PlayerKits2
|
||||||
version: 1.17.4
|
version: 1.17.5
|
||||||
name: PlayerKits2
|
name: PlayerKits2
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
softdepend: [Vault,PlaceholderAPI]
|
softdepend: [Vault,PlaceholderAPI]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue