Added MariaDB driver support
This commit is contained in:
@@ -74,7 +74,7 @@ public class FPChat extends JavaPlugin {
|
||||
vault.setupPermissions();
|
||||
config = new MainConfig(this);
|
||||
pluginTag = config.getPluginTag();
|
||||
if(config.mySQLEnabled()) {
|
||||
if(config.isSQLEnabled()) {
|
||||
sql = new MySQLConnection(this);
|
||||
sql.generate();
|
||||
startTimers();
|
||||
@@ -100,7 +100,7 @@ public class FPChat extends JavaPlugin {
|
||||
for(FPlayer p : FPlayer.getPlayers()) {
|
||||
p.cleanup();
|
||||
}
|
||||
if(config.mySQLEnabled()) {
|
||||
if(config.isSQLEnabled()) {
|
||||
sql.disconnect();
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class FPChat extends JavaPlugin {
|
||||
refresh.cancel();
|
||||
}
|
||||
|
||||
if(config.mySQLEnabled()) {
|
||||
if(config.isSQLEnabled()) {
|
||||
sql.disconnect();
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class FPChat extends JavaPlugin {
|
||||
FPlayer.purge();
|
||||
config = new MainConfig(this);
|
||||
pluginTag = config.getPluginTag();
|
||||
if(config.mySQLEnabled()) {
|
||||
if(config.isSQLEnabled()) {
|
||||
sql = new MySQLConnection(this);
|
||||
sql.generate();
|
||||
startTimers();
|
||||
|
||||
@@ -34,7 +34,7 @@ public class BadgeData {
|
||||
}
|
||||
|
||||
public Badge getBadge(int slot) {
|
||||
if(slot <= 0 || !FPChat.getPlugin().getMainConfig().mySQLEnabled() || slot > FPChat.getPlugin().getMainConfig().getMaxBadgeSlots()) {
|
||||
if(slot <= 0 || !FPChat.getPlugin().getMainConfig().isSQLEnabled() || slot > FPChat.getPlugin().getMainConfig().getMaxBadgeSlots()) {
|
||||
return null;
|
||||
}
|
||||
return slots.get(slot);
|
||||
@@ -56,7 +56,7 @@ public class BadgeData {
|
||||
|
||||
/**Will equip the badge regardless of the user's permissions.**/
|
||||
public BadgeEquipResult setBadge(int slot, Badge badge) {
|
||||
if(!FPChat.getPlugin().getMainConfig().mySQLEnabled()) {
|
||||
if(!FPChat.getPlugin().getMainConfig().isSQLEnabled()) {
|
||||
return BadgeEquipResult.NO_SQL;
|
||||
}
|
||||
if(slot <= 0 || slot > FPChat.getPlugin().getMainConfig().getMaxBadgeSlots()) {
|
||||
|
||||
@@ -299,7 +299,7 @@ public abstract class ChatChannel {
|
||||
if(Permission.isStaff(p)){
|
||||
stf = FPChat.getPlugin().getMainConfig().getStaffBadge();
|
||||
}
|
||||
if(plugin.getMainConfig().mySQLEnabled()){
|
||||
if(plugin.getMainConfig().isSQLEnabled()){
|
||||
badges = p.getBadgeData().getAppearanceString();
|
||||
}
|
||||
if(plugin.getMainConfig().chatFilterEnabled()){
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BadgeClearCommand extends Commands {
|
||||
}
|
||||
|
||||
|
||||
if(!plugin.getMainConfig().mySQLEnabled()) {
|
||||
if(!plugin.getMainConfig().isSQLEnabled()) {
|
||||
FPlayer.errMsg(null, "MySQL is not enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class BadgeEquipCommand extends Commands {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!plugin.getMainConfig().mySQLEnabled()) {
|
||||
if(!plugin.getMainConfig().isSQLEnabled()) {
|
||||
FPlayer.errMsg(null, "MySQL is not enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class BadgeListCommand extends Commands {
|
||||
p = FPlayer.getPlayer((Player)sender);
|
||||
}
|
||||
|
||||
if(!plugin.getMainConfig().mySQLEnabled()) {
|
||||
if(!plugin.getMainConfig().isSQLEnabled()) {
|
||||
FPlayer.errMsg(null, "MySQL is not enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,13 @@ public class MainConfig {
|
||||
}
|
||||
|
||||
private void generate(){
|
||||
if (config.get("MySQL")==null) {
|
||||
config.createSection("MySQL");
|
||||
config.set("MySQL", false);
|
||||
if (config.get("SQL")==null) {
|
||||
config.createSection("SQL");
|
||||
config.set("SQL", false);
|
||||
}
|
||||
if (config.get("UseMariaDBDriver")==null){
|
||||
config.createSection("UseMariaDBDriver");
|
||||
config.set("UseMariaDBDriver", true);
|
||||
}
|
||||
if (config.get("Host")==null) {
|
||||
config.createSection("Host");
|
||||
@@ -133,12 +137,16 @@ public class MainConfig {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean mySQLEnabled() {
|
||||
return config.getBoolean("MySQL");
|
||||
public boolean isSQLEnabled() {
|
||||
return config.getBoolean("SQL");
|
||||
}
|
||||
|
||||
public boolean useMariaDBDriver() {
|
||||
return config.getBoolean("UseMariaDBDriver");
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
if(mySQLEnabled()) {
|
||||
if(isSQLEnabled()) {
|
||||
return config.getString("Host");
|
||||
}else {
|
||||
plugin.getLogger().log(Level.SEVERE, "Null SQL host. Is MySQL disabled?");
|
||||
@@ -147,7 +155,7 @@ public class MainConfig {
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
if(mySQLEnabled()) {
|
||||
if(isSQLEnabled()) {
|
||||
return config.getString("Port");
|
||||
}else {
|
||||
plugin.getLogger().log(Level.SEVERE, "Null SQL port. Is MySQL disabled?");
|
||||
@@ -156,7 +164,7 @@ public class MainConfig {
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
if(mySQLEnabled()) {
|
||||
if(isSQLEnabled()) {
|
||||
return config.getString("User");
|
||||
}else {
|
||||
plugin.getLogger().log(Level.SEVERE, "Null SQL user. Is MySQL disabled?");
|
||||
@@ -165,7 +173,7 @@ public class MainConfig {
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
if(mySQLEnabled()) {
|
||||
if(isSQLEnabled()) {
|
||||
return config.getString("Password");
|
||||
}else {
|
||||
plugin.getLogger().log(Level.SEVERE, "Null SQL password. Is MySQL disabled?");
|
||||
@@ -174,7 +182,7 @@ public class MainConfig {
|
||||
}
|
||||
|
||||
public String getDatabase() {
|
||||
if(mySQLEnabled()) {
|
||||
if(isSQLEnabled()) {
|
||||
return config.getString("Database");
|
||||
}else {
|
||||
plugin.getLogger().log(Level.SEVERE, "Null SQL database. Is MySQL disabled?");
|
||||
@@ -183,7 +191,7 @@ public class MainConfig {
|
||||
}
|
||||
|
||||
public String getChatFeatureTable() {
|
||||
if(mySQLEnabled()) {
|
||||
if(isSQLEnabled()) {
|
||||
return config.getString("Chat-Feature-Table");
|
||||
}else {
|
||||
plugin.getLogger().log(Level.SEVERE, "Null SQL chat feature table. Is MySQL disabled?");
|
||||
@@ -192,7 +200,7 @@ public class MainConfig {
|
||||
}
|
||||
|
||||
public String getPermSyncTable() {
|
||||
if(mySQLEnabled()) {
|
||||
if(isSQLEnabled()) {
|
||||
return config.getString("PermSync-Table");
|
||||
}else {
|
||||
plugin.getLogger().log(Level.SEVERE, "Null SQL perm sync table. Is MySQL disabled?");
|
||||
|
||||
@@ -29,16 +29,21 @@ public class MySQLConnection{
|
||||
port = config.getPort();
|
||||
hikari = new HikariDataSource();
|
||||
hikari.setMaximumPoolSize(10);
|
||||
hikari.setDataSourceClassName("com.mysql.cj.jdbc.MysqlDataSource");
|
||||
hikari.addDataSourceProperty("serverName", host);
|
||||
hikari.addDataSourceProperty("user", user);
|
||||
hikari.addDataSourceProperty("password", password);
|
||||
hikari.addDataSourceProperty("databaseName", database);
|
||||
hikari.addDataSourceProperty("port", port);
|
||||
if(config.useMariaDBDriver()) {
|
||||
hikari.setDataSourceClassName("org.mariadb.jdbc.MariaDbDataSource");
|
||||
hikari.addDataSourceProperty("url", "jdbc:mariadb://"+ host + ":" + port + "/" + database);
|
||||
}else {
|
||||
hikari.setDataSourceClassName("com.mysql.cj.jdbc.MysqlDataSource");
|
||||
hikari.addDataSourceProperty("serverName", host);
|
||||
hikari.addDataSourceProperty("databaseName", database);
|
||||
hikari.addDataSourceProperty("port", port);
|
||||
}
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
if(config.mySQLEnabled()){
|
||||
if(config.isSQLEnabled()){
|
||||
plugin.log(Level.INFO, "Connecting to MySQL...");
|
||||
Connection connection = null;
|
||||
try {
|
||||
@@ -91,24 +96,24 @@ public class MySQLConnection{
|
||||
if (input == null){
|
||||
return;
|
||||
}
|
||||
Statement statement;
|
||||
Connection connection = null;
|
||||
Statement statement;
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = hikari.getConnection();
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate(input);
|
||||
statement.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
connection = hikari.getConnection();
|
||||
statement = connection.createStatement();
|
||||
statement.executeUpdate(input);
|
||||
statement.close();
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void asyncUpdate(String input){
|
||||
CompletableFuture.runAsync(() -> {
|
||||
update(input);
|
||||
|
||||
@@ -165,7 +165,7 @@ public class FPlayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(FPChat.getPlugin().getMainConfig().mySQLEnabled()) {
|
||||
if(FPChat.getPlugin().getMainConfig().isSQLEnabled()) {
|
||||
this.badgeData = new BadgeData(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user