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());
|
||||
try{
|
||||
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:")){
|
||||
getConfig().set("new_kit_default_save_mode_original", true);
|
||||
configFile.saveConfig();
|
||||
|
|
|
|||
|
|
@ -2,22 +2,47 @@ package pk.ajneb97.database;
|
|||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class HikariConnection {
|
||||
|
||||
private HikariDataSource hikari;
|
||||
|
||||
public HikariConnection(String ip, int port, String database, String username, String password) {
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setJdbcUrl("jdbc:mysql://" + ip + ":" + port + "/" + database);
|
||||
config.setUsername(username);
|
||||
config.setPassword(password);
|
||||
config.addDataSourceProperty("autoReconnect", "true");
|
||||
config.addDataSourceProperty("leakDetectionThreshold", "true");
|
||||
config.addDataSourceProperty("verifyServerCertificate", "false");
|
||||
config.addDataSourceProperty("useSSL", "false");
|
||||
config.setConnectionTimeout(5000);
|
||||
hikari = new HikariDataSource(config);
|
||||
public HikariConnection(FileConfiguration config) {
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
String path = "mysql_database";
|
||||
|
||||
String host = config.getString(path+".host");
|
||||
int port = config.getInt(path+".port");
|
||||
String database = config.getString(path+".database");
|
||||
String username = config.getString(path+".username");
|
||||
String password = config.getString(path+".password");
|
||||
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@ public class MySQLConnection {
|
|||
|
||||
private PlayerKits2 plugin;
|
||||
private HikariConnection connection;
|
||||
private String host;
|
||||
private String database;
|
||||
private String username;
|
||||
private String password;
|
||||
private int port;
|
||||
|
||||
public MySQLConnection(PlayerKits2 plugin){
|
||||
this.plugin = plugin;
|
||||
|
|
@ -31,12 +26,7 @@ public class MySQLConnection {
|
|||
public void setupMySql(){
|
||||
FileConfiguration config = plugin.getConfigsManager().getMainConfigManager().getConfig();
|
||||
try {
|
||||
host = config.getString("mysql_database.host");
|
||||
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 = new HikariConnection(config);
|
||||
connection.getHikari().getConnection();
|
||||
createTables();
|
||||
loadData();
|
||||
|
|
@ -46,11 +36,6 @@ public class MySQLConnection {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public String getDatabase() {
|
||||
return this.database;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
try {
|
||||
return connection.getHikari().getConnection();
|
||||
|
|
|
|||
|
|
@ -50,3 +50,9 @@ mysql_database:
|
|||
username: root
|
||||
password: root
|
||||
database: database
|
||||
pool:
|
||||
connectionTimeout: 5000
|
||||
advanced:
|
||||
verifyServerCertificate: false
|
||||
useSSL: true
|
||||
allowPublicKeyRetrieval: true
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
main: pk.ajneb97.PlayerKits2
|
||||
version: 1.17.4
|
||||
version: 1.17.5
|
||||
name: PlayerKits2
|
||||
api-version: 1.13
|
||||
softdepend: [Vault,PlaceholderAPI]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue