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"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> 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> <maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </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> <repositories>
<repository> <repository>
<id>papermc-repo</id> <id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url> <url>https://repo.papermc.io/repository/maven-public/</url>
</repository> </repository>
<repository>
<id>gitlab-zyonic</id>
<url>https://gitlab.zyonicsoftware.com/api/v4/projects/119/packages/maven</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.github.waterfallmc</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>waterfall-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.20-R0.1-SNAPSHOT</version> <version>1.21.11-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>RELEASE</version> <version>1.18.42</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>de.mint</groupId>
<artifactId>AsyncMySQLPoolHandler</artifactId>
<version>1.0.5</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
+15 -9
View File
@@ -1,24 +1,30 @@
package com.softwarerat; package com.softwarerat;
import org.bukkit.plugin.java.JavaPlugin;
import com.softwarerat.MySQL.Ban; import com.softwarerat.MySQL.Ban;
import com.softwarerat.MySQL.Login; 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.Mute;
import com.softwarerat.MySQL.Report;
import com.softwarerat.yml.Yaml;
import lombok.Getter;
@Getter @Getter
public class Bansystem { public class Bansystem {
Ban ban; Ban ban;
Report report; Report report;
Mute mute; Mute mute;
SQLHandler sqlHandler;
Login login; 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(); login = new Login();
sqlHandler = new SQLHandler(host,user, db, pw); ban = new Ban(data);
ban = new Ban(sqlHandler); report = new Report(data);
report = new Report(sqlHandler); mute = new Mute(data);
mute = new Mute(sqlHandler);
} }
+32 -63
View File
@@ -1,86 +1,55 @@
package com.softwarerat.MySQL; package com.softwarerat.MySQL;
import java.sql.ResultSet; import com.softwarerat.yml.Yaml;
import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException;
// Class containing all SQL things for the Ban Topic // Class containing all SQL things for the Ban Topic
public class Ban { public class Ban {
SQLHandler sqlHandler;
public Ban(SQLHandler sqlHandler) { private final Yaml yaml;
this.sqlHandler = sqlHandler;
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 basePath = "bans." + uuid;
String BanID = UUID.randomUUID().toString();
System.out.println("INSERT INTO Ban (UUID, BanID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');"); yaml.set(basePath + ".ban-id", banId);
try { yaml.set(basePath + ".reason", reason);
sqlHandler.executeUpdate("INSERT INTO Ban (UUID, BanID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');"); yaml.set(basePath + ".punisher", punisher);
} catch (ExecutionException e) { yaml.set(basePath + ".time", time);
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} }
public Long getBanTime(String uuid) { public Long getBanTime(String uuid) {
ResultSet resultSet = null; if (!isBanned(uuid)) return null;
System.out.println("Neuer Datenabruf"); return yaml.getConfig().getLong("bans." + uuid + ".time");
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 String getBanUUID(String UUID) { public String getBanUUID(String uuid) {
System.out.println("Loading Kit"); if (!isBanned(uuid)) return null;
ResultSet resultSet = null; return uuid;
try {
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 { public String getReason(String uuid) {
resultSet.next(); if (!isBanned(uuid)) return null;
return resultSet.getString("UUID"); return yaml.getString("bans." + uuid + ".reason");
} catch (SQLException e) {
throw new RuntimeException(e);
} }
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) { public void deletePunishment(String uuid) {
yaml.set("bans." + uuid, null);
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);
}
} }
} }
+31 -63
View File
@@ -1,88 +1,56 @@
package com.softwarerat.MySQL; package com.softwarerat.MySQL;
import java.sql.ResultSet; import com.softwarerat.yml.Yaml;
import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException;
// Class containing all SQL things for the Ban Topic // Class containing all SQL things for the Ban Topic
public class Mute { public class Mute {
SQLHandler sqlHandler;
private final Yaml yaml;
public Mute(SQLHandler sqlHandler) { public Mute(Yaml yaml) {
this.sqlHandler = sqlHandler; 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 basePath = "mutes." + uuid;
String BanID = UUID.randomUUID().toString();
System.out.println("INSERT INTO Mute (UUID, MuteID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');"); yaml.set(basePath + ".mute-id", muteId);
try { yaml.set(basePath + ".reason", reason);
sqlHandler.executeUpdate("INSERT INTO Mute (UUID, MuteID ,Name , Reason, Time) VALUES ('"+uuid+"','"+BanID+"','"+punisher+"','"+Reason+"','"+time+"');"); yaml.set(basePath + ".punisher", punisher);
} catch (ExecutionException e) { yaml.set(basePath + ".time", time);
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} }
public Long getMuteTime(String uuid) { public Long getMuteTime(String uuid) {
ResultSet resultSet = null; if (!isMuted(uuid)) return null;
System.out.println("Neuer Datenabruf"); return yaml.getConfig().getLong("mutes." + uuid + ".time");
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 String getMuteUUID(String UUID) { public String getMuteUUID(String uuid) {
System.out.println("Loading Kit"); if (!isMuted(uuid)) return null;
ResultSet resultSet = null; return uuid;
try {
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 { public String getReason(String uuid) {
resultSet.next(); if (!isMuted(uuid)) return null;
return resultSet.getString("UUID"); return yaml.getString("mutes." + uuid + ".reason");
} catch (SQLException e) {
throw new RuntimeException(e);
} }
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) { public void deletePunishment(String uuid) {
yaml.set("mutes." + uuid, null);
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);
}
} }
} }
+37 -47
View File
@@ -1,70 +1,60 @@
package com.softwarerat.MySQL; package com.softwarerat.MySQL;
import java.sql.ResultSet; import com.softwarerat.yml.Yaml;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException;
public class Report { public class Report {
SQLHandler sqlHandler; private final Yaml yaml;
public Report(SQLHandler sqlHandler) { public Report(Yaml yaml) {
this.sqlHandler = sqlHandler; 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 basePath = "reports." + reportId;
String BanID = UUID.randomUUID().toString();
System.out.println("INSERT INTO Report (UUID, ReportID ,Name , Reason) VALUES ('"+uuid+"','"+BanID+"','"+reporter+"','"+Reason+"');"); yaml.set(basePath + ".target", targetUuid);
try { yaml.set(basePath + ".reason", reason);
sqlHandler.executeUpdate("INSERT INTO Report (UUID, ReportID ,Name , Reason) VALUES ('"+uuid+"','"+BanID+"','"+reporter+"','"+Reason+"');"); yaml.set(basePath + ".reporter", reporter);
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} }
}
public List<String> getReports() { public List<String> getReports() {
List<String> reportIDs = new ArrayList<>(); List<String> reportIds = new ArrayList<>();
System.out.println("Loading Kit");
ResultSet resultSet = null; if (!yaml.getConfig().contains("reports")) {
try { return reportIds;
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"));
} }
Set<String> keys = yaml.getConfig().getConfigurationSection("reports").getKeys(false);
reportIds.addAll(keys);
} catch (SQLException e) { return reportIds;
throw new RuntimeException(e);
} }
}
System.out.println("Loaded Kit");
return null;
}
public void deleteReport(String uuid) {
System.out.println("Neuer Datenabruf"); public String getTarget(String reportId) {
try { return yaml.getString("reports." + reportId + ".target");
sqlHandler.executeUpdate("DELETE FROM Report WHERE ReportID = '"+ uuid + "';");
} catch (ExecutionException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} }
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);
}
}