Moved it to Yaml file infrastructure

This commit is contained in:
Laura
2026-01-18 18:10:18 +01:00
parent 59b9611c45
commit 5dcf29c5f5
8 changed files with 202 additions and 270 deletions
+6 -25
View File
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -13,44 +14,24 @@
<maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.softwarerat.com/api/v4/projects/8/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.softwarerat.com/api/v4/projects/8/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>gitlab-zyonic</id>
<url>https://gitlab.zyonicsoftware.com/api/v4/projects/119/packages/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.20-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
<version>1.18.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.mint</groupId>
<artifactId>AsyncMySQLPoolHandler</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies>
</project>
+15 -9
View File
@@ -1,24 +1,30 @@
package com.softwarerat;
import org.bukkit.plugin.java.JavaPlugin;
import com.softwarerat.MySQL.Ban;
import com.softwarerat.MySQL.Login;
import com.softwarerat.MySQL.Report;
import com.softwarerat.MySQL.SQLHandler;
import lombok.Getter;
import com.softwarerat.MySQL.Mute;
import com.softwarerat.MySQL.Report;
import com.softwarerat.yml.Yaml;
import lombok.Getter;
@Getter
public class Bansystem {
Ban ban;
Report report;
Mute mute;
SQLHandler sqlHandler;
Login login;
public void enableAPI(String user,String pw,String host,String db){
Yaml data;
String path;
public void enableAPI(String filename, String path){
data = new Yaml(path, filename);
login = new Login();
sqlHandler = new SQLHandler(host,user, db, pw);
ban = new Ban(sqlHandler);
report = new Report(sqlHandler);
mute = new Mute(sqlHandler);
ban = new Ban(data);
report = new Report(data);
mute = new Mute(data);
}
+33 -64
View File
@@ -1,86 +1,55 @@
package com.softwarerat.MySQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.softwarerat.yml.Yaml;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
// Class containing all SQL things for the Ban Topic
public class Ban {
SQLHandler sqlHandler;
public Ban(SQLHandler sqlHandler) {
this.sqlHandler = sqlHandler;
private final Yaml yaml;
public Ban(Yaml yaml) {
this.yaml = yaml;
}
public void addPunishment(String uuid, String Reason ,String punisher,long time) {
public void addPunishment(String uuid, String reason, String punisher, long time) {
String banId = UUID.randomUUID().toString();
System.out.println("Neuer Datenabruf");
String BanID = UUID.randomUUID().toString();
System.out.println("INSERT INTO Ban (UUID, BanID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');");
try {
sqlHandler.executeUpdate("INSERT INTO Ban (UUID, BanID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
String basePath = "bans." + uuid;
yaml.set(basePath + ".ban-id", banId);
yaml.set(basePath + ".reason", reason);
yaml.set(basePath + ".punisher", punisher);
yaml.set(basePath + ".time", time);
}
public Long getBanTime(String uuid){
ResultSet resultSet = null;
System.out.println("Neuer Datenabruf");
try {
System.out.println("SELECT * FROM Ban WHERE UUID = '"+uuid+"';");
resultSet = sqlHandler.executeQuery("SELECT * FROM Ban WHERE UUID = '"+uuid+"';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (resultSet != null) {
try {
resultSet.next();
return resultSet.getLong("Time");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return null;
public Long getBanTime(String uuid) {
if (!isBanned(uuid)) return null;
return yaml.getConfig().getLong("bans." + uuid + ".time");
}
public String getBanUUID(String UUID) {
System.out.println("Loading Kit");
ResultSet resultSet = null;
try {
resultSet = sqlHandler.executeQuery("SELECT * FROM Ban WHERE UUID = '"+UUID+"';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
public String getBanUUID(String uuid) {
if (!isBanned(uuid)) return null;
return uuid;
}
if (resultSet != null) {
try {
resultSet.next();
return resultSet.getString("UUID");
} catch (SQLException e) {
throw new RuntimeException(e);
public String getReason(String uuid) {
if (!isBanned(uuid)) return null;
return yaml.getString("bans." + uuid + ".reason");
}
public String getPunisher(String uuid) {
if (!isBanned(uuid)) return null;
return yaml.getString("bans." + uuid + ".punisher");
}
System.out.println("Loaded Kit");
return null;
public boolean isBanned(String uuid) {
return yaml.getConfig().contains("bans." + uuid);
}
public void deletePunishment(String uuid) {
System.out.println("Neuer Datenabruf");
try {
sqlHandler.executeUpdate("DELETE FROM Ban WHERE UUID = '"+ uuid + "';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
yaml.set("bans." + uuid, null);
}
}
+32 -64
View File
@@ -1,88 +1,56 @@
package com.softwarerat.MySQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.softwarerat.yml.Yaml;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
// Class containing all SQL things for the Ban Topic
public class Mute {
SQLHandler sqlHandler;
private final Yaml yaml;
public Mute(SQLHandler sqlHandler) {
this.sqlHandler = sqlHandler;
public Mute(Yaml yaml) {
this.yaml = yaml;
}
public void addPunishment(String uuid, String Reason , String punisher, long time) {
public void addPunishment(String uuid, String reason, String punisher, long time) {
String muteId = UUID.randomUUID().toString();
System.out.println("Neuer Datenabruf");
String BanID = UUID.randomUUID().toString();
System.out.println("INSERT INTO Mute (UUID, MuteID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');");
try {
sqlHandler.executeUpdate("INSERT INTO Mute (UUID, MuteID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
String basePath = "mutes." + uuid;
yaml.set(basePath + ".mute-id", muteId);
yaml.set(basePath + ".reason", reason);
yaml.set(basePath + ".punisher", punisher);
yaml.set(basePath + ".time", time);
}
public Long getMuteTime(String uuid){
ResultSet resultSet = null;
System.out.println("Neuer Datenabruf");
try {
System.out.println("SELECT * FROM Mute WHERE UUID = '"+uuid+"';");
resultSet = sqlHandler.executeQuery("SELECT * FROM Mute WHERE UUID = '"+uuid+"';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (resultSet != null) {
try {
resultSet.next();
return resultSet.getLong("Time");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
return null;
public Long getMuteTime(String uuid) {
if (!isMuted(uuid)) return null;
return yaml.getConfig().getLong("mutes." + uuid + ".time");
}
public String getMuteUUID(String UUID) {
System.out.println("Loading Kit");
ResultSet resultSet = null;
try {
resultSet = sqlHandler.executeQuery("SELECT * FROM Mute WHERE UUID = '"+UUID+"';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
public String getMuteUUID(String uuid) {
if (!isMuted(uuid)) return null;
return uuid;
}
if (resultSet != null) {
try {
resultSet.next();
return resultSet.getString("UUID");
} catch (SQLException e) {
throw new RuntimeException(e);
public String getReason(String uuid) {
if (!isMuted(uuid)) return null;
return yaml.getString("mutes." + uuid + ".reason");
}
public String getPunisher(String uuid) {
if (!isMuted(uuid)) return null;
return yaml.getString("mutes." + uuid + ".punisher");
}
System.out.println("Loaded Kit");
return null;
public boolean isMuted(String uuid) {
return yaml.getConfig().contains("mutes." + uuid);
}
public void deletePunishment(String uuid) {
System.out.println("Neuer Datenabruf");
try {
sqlHandler.executeUpdate("DELETE FROM Mute WHERE UUID = '"+ uuid + "';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
yaml.set("mutes." + uuid, null);
}
}
+37 -47
View File
@@ -1,70 +1,60 @@
package com.softwarerat.MySQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.softwarerat.yml.Yaml;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
public class Report {
SQLHandler sqlHandler;
private final Yaml yaml;
public Report(SQLHandler sqlHandler) {
this.sqlHandler = sqlHandler;
public Report(Yaml yaml) {
this.yaml = yaml;
}
public void addReport(String uuid, String Reason , String reporter) {
public void addReport(String targetUuid, String reason, String reporter) {
String reportId = UUID.randomUUID().toString();
System.out.println("Neuer Datenabruf");
String BanID = UUID.randomUUID().toString();
System.out.println("INSERT INTO Report (UUID, ReportID ,Name , Reason) VALUES ('"+uuid+"','"+BanID+"','"+reporter+"','"+Reason+"');");
try {
sqlHandler.executeUpdate("INSERT INTO Report (UUID, ReportID ,Name , Reason) VALUES ('"+uuid+"','"+BanID+"','"+reporter+"','"+Reason+"');");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
String basePath = "reports." + reportId;
yaml.set(basePath + ".target", targetUuid);
yaml.set(basePath + ".reason", reason);
yaml.set(basePath + ".reporter", reporter);
}
}
public List<String> getReports() {
List<String> reportIDs = new ArrayList<>();
System.out.println("Loading Kit");
ResultSet resultSet = null;
try {
resultSet = sqlHandler.executeQuery("SELECT * FROM Report;");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (resultSet != null) {
try {
while (resultSet.next()){
reportIDs.add(resultSet.getString("ReportID"));
List<String> reportIds = new ArrayList<>();
if (!yaml.getConfig().contains("reports")) {
return reportIds;
}
Set<String> keys = yaml.getConfig().getConfigurationSection("reports").getKeys(false);
reportIds.addAll(keys);
} catch (SQLException e) {
throw new RuntimeException(e);
return reportIds;
}
}
System.out.println("Loaded Kit");
return null;
}
public void deleteReport(String uuid) {
System.out.println("Neuer Datenabruf");
try {
sqlHandler.executeUpdate("DELETE FROM Report WHERE ReportID = '"+ uuid + "';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
public String getTarget(String reportId) {
return yaml.getString("reports." + reportId + ".target");
}
public String getReason(String reportId) {
return yaml.getString("reports." + reportId + ".reason");
}
public String getReporter(String reportId) {
return yaml.getString("reports." + reportId + ".reporter");
}
public boolean reportExists(String reportId) {
return yaml.getConfig().contains("reports." + reportId);
}
public void deleteReport(String reportId) {
yaml.set("reports." + reportId, null);
}
}
@@ -1,37 +0,0 @@
package com.softwarerat.MySQL;
import de.mint.asyncmysqlpoolhandler.configservice.ConfigBuilder;
import de.mint.asyncmysqlpoolhandler.configservice.ConfigPoolFramework;
import de.mint.asyncmysqlpoolhandler.enumservice.EnumPoolFramework;
import de.mint.asyncmysqlpoolhandler.mainservice.AsyncMySQLPoolHandler;
import java.sql.ResultSet;
import java.util.concurrent.ExecutionException;
public class SQLHandler {
private final AsyncMySQLPoolHandler MySQLPoolHandler;
private final ConfigPoolFramework configPoolFramework = ConfigBuilder.getConfigBuilder().build();
public SQLHandler(String hostname, String user, String pw, String DB) {
this.MySQLPoolHandler = new AsyncMySQLPoolHandler(hostname, user, pw, DB, EnumPoolFramework.HIKARICP, configPoolFramework);
this.openConnection();
}
private void openConnection() {
this.MySQLPoolHandler.openPool();
}
// Basic SQL Things
protected ResultSet executeQuery(String sql) throws ExecutionException, InterruptedException {
return this.MySQLPoolHandler.executeQueryAsync(sql).get();
}
protected void executeUpdate(String sql) throws ExecutionException, InterruptedException {
this.MySQLPoolHandler.executeUpdateAsync(sql).get();
}
}
@@ -1,8 +0,0 @@
package com.softwarerat.Netty;
//because of Client Server communication to the discord bot, netty will be the easiest Client for that.
public class SyncDiscord {
}
@@ -0,0 +1,63 @@
package com.softwarerat.yml;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
public class Yaml {
private final File file;
private FileConfiguration config;
public Yaml(String path, String fileName) {
this.file = new File(path, fileName); // FIX HERE
load();
}
public void load() {
this.config = YamlConfiguration.loadConfiguration(file);
}
public void save() {
try {
config.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public void reload() {
load();
}
public FileConfiguration getConfig() {
return config;
}
public void set(String path, Object value) {
config.set(path, value);
save();
}
public Object get(String path) {
return config.get(path);
}
public String getString(String path) {
return config.getString(path);
}
public int getInt(String path) {
return config.getInt(path);
}
public boolean getBoolean(String path) {
return config.getBoolean(path);
}
}