Added MariaDB driver support

This commit is contained in:
BuildTools 2023-08-14 22:39:01 -05:00
parent 0785e82284
commit 291db3fe4a
11 changed files with 79 additions and 85 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
@ -24,7 +24,7 @@
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
@ -57,43 +57,14 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>commons-lang</artifactId>
<groupId>commons-lang</groupId>
</exclusion>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
<exclusion>
<artifactId>snakeyaml</artifactId>
<groupId>org.yaml</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bukkit</artifactId>
<groupId>org.bukkit</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

34
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.fpghoti</groupId>
<artifactId>FPChat</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>
<repositories>
<repository>
<id>spigot-repo</id>
@ -57,28 +57,38 @@
</build>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
<scope>compile</scope>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.1.0</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -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();

View File

@ -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()) {

View File

@ -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()){

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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?");

View File

@ -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);

View File

@ -165,7 +165,7 @@ public class FPlayer {
}
}
}
if(FPChat.getPlugin().getMainConfig().mySQLEnabled()) {
if(FPChat.getPlugin().getMainConfig().isSQLEnabled()) {
this.badgeData = new BadgeData(this);
}
}