From 59b9611c4558bcdc8394bd3ef764df95198408ea Mon Sep 17 00:00:00 2001 From: Laura Date: Sun, 18 Jan 2026 15:07:36 +0100 Subject: [PATCH] initial commit --- .gitignore | 38 ++++++ .gitlab-ci.yml | 80 +++++++++++ .idea/.gitignore | 3 + .idea/encodings.xml | 7 + .idea/misc.xml | 18 +++ .idea/uiDesigner.xml | 124 ++++++++++++++++++ .idea/vcs.xml | 6 + README.md | 81 ++++++++++++ ci_settings.xml | 15 +++ pom.xml | 56 ++++++++ settings.xml | 15 +++ src/main/java/com/softwarerat/Bansystem.java | 26 ++++ src/main/java/com/softwarerat/MySQL/Ban.java | 86 ++++++++++++ .../java/com/softwarerat/MySQL/Login.java | 11 ++ src/main/java/com/softwarerat/MySQL/Mute.java | 88 +++++++++++++ .../java/com/softwarerat/MySQL/Report.java | 70 ++++++++++ .../com/softwarerat/MySQL/SQLHandler.java | 37 ++++++ .../com/softwarerat/Netty/SyncDiscord.java | 8 ++ 18 files changed, 769 insertions(+) create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 README.md create mode 100644 ci_settings.xml create mode 100644 pom.xml create mode 100644 settings.xml create mode 100644 src/main/java/com/softwarerat/Bansystem.java create mode 100644 src/main/java/com/softwarerat/MySQL/Ban.java create mode 100644 src/main/java/com/softwarerat/MySQL/Login.java create mode 100644 src/main/java/com/softwarerat/MySQL/Mute.java create mode 100644 src/main/java/com/softwarerat/MySQL/Report.java create mode 100644 src/main/java/com/softwarerat/MySQL/SQLHandler.java create mode 100644 src/main/java/com/softwarerat/Netty/SyncDiscord.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..05a350b --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,80 @@ + # To contribute improvements to CI/CD templates, please follow the Development guide at: +# https://docs.gitlab.com/ee/development/cicd/templates.html +# This specific template is located at: +# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Maven.gitlab-ci.yml + +# Build JAVA applications using Apache Maven (http://maven.apache.org) +# For docker image tags see https://hub.docker.com/_/maven/ +# +# For general lifecycle information see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html + +# This template will build and test your projects +# * Caches downloaded dependencies and plugins between invocation. +# * Verify but don't deploy merge requests. +# * Deploy built artifacts from master branch only. + +variables: + # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work. + MAVEN_OPTS: >- + -Dhttps.protocols=TLSv1.2 + -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository + -Dorg.slf4j.simpleLogger.showDateTime=true + -Djava.awt.headless=true + + # As of Maven 3.3.0 instead of this you MAY define these options in `.mvn/maven.config` so the same config is used + # when running from the command line. + # As of Maven 3.6.1, the use of `--no-tranfer-progress` (or `-ntp`) suppresses download and upload messages. The use + # of the `Slf4jMavenTransferListener` is no longer necessary. + # `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins. + MAVEN_CLI_OPTS: >- + --batch-mode + --errors + --fail-at-end + --show-version + --no-transfer-progress + -DinstallAtEnd=true + -DdeployAtEnd=true + +# This template uses the latest Maven 3 release, e.g., 3.8.6, and OpenJDK 8 (LTS) +# for verifying and deploying images +# Maven 3.8.x REQUIRES HTTPS repositories. +# See https://maven.apache.org/docs/3.8.1/release-notes.html#how-to-fix-when-i-get-a-http-repository-blocked for more. +image: maven:3-openjdk-20 + +# Cache downloaded dependencies and plugins between builds. +# To keep cache across branches add 'key: "$CI_JOB_NAME"' +# Be aware that `mvn deploy` will install the built jar into this repository. If you notice your cache size +# increasing, consider adding `-Dmaven.install.skip=true` to `MAVEN_OPTS` or in `.mvn/maven.config` +cache: + paths: + - .m2/repository + +# For merge requests do not `deploy` but only run `verify`. +# See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html +.verify: + stage: test + script: + - 'mvn $MAVEN_CLI_OPTS verify' + except: + variables: + - $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + +# Verify merge requests using JDK8 +verify:jdk20: + extends: + - .verify + +# To deploy packages from CI, create a `ci_settings.xml` file +# For deploying packages to GitLab's Maven Repository: See https://docs.gitlab.com/ee/user/packages/maven_repository/index.html#create-maven-packages-with-gitlab-cicd for more details. +# Please note: The GitLab Maven Repository is currently only available in GitLab Premium / Ultimate. +# For `master` or `main` branch run `mvn deploy` automatically. +deploy:jdk20: + stage: deploy + script: + - if [ ! -f ci_settings.xml ]; then + echo "CI settings missing\! If deploying to GitLab Maven Repository, please see https://docs.gitlab.com/ee/user/packages/maven_repository/index.html#create-maven-packages-with-gitlab-cicd for instructions."; + fi + - 'mvn $MAVEN_CLI_OPTS deploy --settings ci_settings.xml' + only: + variables: + - $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dc95718 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1dccefc --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +# Bansystem API + +## Benutzung +## Vorraussetzungen + - Eine Datenbank inkl. Ban Table(Struktur siehe Code) + - Einen MariaDB Server MySQL ansich wird NICHT unterstützt. + + +### initialisierung des Basis API Codes + +```java + public void onEnable(){ + Bansystem bansystem = new Bansystem(); + bansystem.enableAPI("Benutzer","Passwort","Host","Datenbank"); + ban = bansystem.getBan(); + } + ``` + +### Spieler Bannen +```java +public class BanPlayer{ + Ban ban; + public BanPlayer(Ban ban) { + this.ban = ban; + } + public void test(String UUID,String Reason, String Punisher, Long Time){ + ban.addPunishment(UUID(String),Reason(String) ,Punisher(String) ,Time(Long)); + + } +} + +``` + ### der Spieler sollte aktuell optional vom server gekickt werden (bald wird über Netty ein Packet an den Discord Bot server gesendet welches dem ProxySystem sagt das es den Spieler kicken soll) + +### Spieler entbannen +```java +public class BanPlayer{ + //Initialize Class + Ban ban; + public BanPlayer(Ban ban) { + this.ban = ban; + } + public void test(String UUID){ +// deletes the Punishment(s) from the following UUID + ban.deletePunishment(args[0]); + } +} +``` +### Spieler auf Banzeit checken +```java +public class PlayerJoin { + + Ban ban; + + public PlayerJoin(Ban ban) { + this.ban = ban; + } + + @EventHandler + public void onPostLogin(PostLoginEvent event) { + + System.out.println("neuer Join erkannt"); + UUID player = event.getPlayer().getUniqueId(); + ProxiedPlayer proxiedPlayer = event.getPlayer(); + + + System.out.println("Joinevent | Neuer Datenabruf"); + //Spieler mittels Banzeit joinen lassen oder nicht, die != 0 muss so sein weil sonst ne OutOfBounds kommen wird + if (ban.getBanTime(player.toString()) != 0) { + if (ban.getBanTime(player.toString()) >= System.currentTimeMillis()) { + proxiedPlayer.disconnect("du wurdest gebannt grund siehste im discord"); + } + } else { + System.out.println("Spieler nit gebannt"); + } + } +} +``` + + + diff --git a/ci_settings.xml b/ci_settings.xml new file mode 100644 index 0000000..82c1ab3 --- /dev/null +++ b/ci_settings.xml @@ -0,0 +1,15 @@ + + + + gitlab-maven + + + + Job-Token + ${CI_JOB_TOKEN} + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..88017f1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + com.softwarerat + BansystemAPI + 1.6.7-BETA + + + 18 + 18 + UTF-8 + + + + gitlab-maven + https://gitlab.softwarerat.com/api/v4/projects/8/packages/maven + + + gitlab-maven + https://gitlab.softwarerat.com/api/v4/projects/8/packages/maven + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + gitlab-zyonic + https://gitlab.zyonicsoftware.com/api/v4/projects/119/packages/maven + + + + + io.github.waterfallmc + waterfall-api + 1.20-R0.1-SNAPSHOT + provided + + + org.projectlombok + lombok + RELEASE + compile + + + de.mint + AsyncMySQLPoolHandler + 1.0.5 + + + + \ No newline at end of file diff --git a/settings.xml b/settings.xml new file mode 100644 index 0000000..82c1ab3 --- /dev/null +++ b/settings.xml @@ -0,0 +1,15 @@ + + + + gitlab-maven + + + + Job-Token + ${CI_JOB_TOKEN} + + + + + + \ No newline at end of file diff --git a/src/main/java/com/softwarerat/Bansystem.java b/src/main/java/com/softwarerat/Bansystem.java new file mode 100644 index 0000000..9982e6a --- /dev/null +++ b/src/main/java/com/softwarerat/Bansystem.java @@ -0,0 +1,26 @@ +package com.softwarerat; + +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; +@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){ + login = new Login(); + sqlHandler = new SQLHandler(host,user, db, pw); + ban = new Ban(sqlHandler); + report = new Report(sqlHandler); + mute = new Mute(sqlHandler); + } + + + +} \ No newline at end of file diff --git a/src/main/java/com/softwarerat/MySQL/Ban.java b/src/main/java/com/softwarerat/MySQL/Ban.java new file mode 100644 index 0000000..2a39657 --- /dev/null +++ b/src/main/java/com/softwarerat/MySQL/Ban.java @@ -0,0 +1,86 @@ +package com.softwarerat.MySQL; + +import java.sql.ResultSet; +import java.sql.SQLException; +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; + } + + public void addPunishment(String uuid, String Reason ,String punisher,long time) { + + 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); + } + } + + 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 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); + } + if (resultSet != null) { + try { + resultSet.next(); + return resultSet.getString("UUID"); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + System.out.println("Loaded Kit"); + return null; + } + 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); + } + } + +} diff --git a/src/main/java/com/softwarerat/MySQL/Login.java b/src/main/java/com/softwarerat/MySQL/Login.java new file mode 100644 index 0000000..c98c916 --- /dev/null +++ b/src/main/java/com/softwarerat/MySQL/Login.java @@ -0,0 +1,11 @@ +package com.softwarerat.MySQL; + +import lombok.Getter; + +@Getter +public class Login { + String hostname = "127.0.0.1"; + String database = "Ban"; + String username = "BanSystem"; + String password = "GGoders0"; +} diff --git a/src/main/java/com/softwarerat/MySQL/Mute.java b/src/main/java/com/softwarerat/MySQL/Mute.java new file mode 100644 index 0000000..f8ba64c --- /dev/null +++ b/src/main/java/com/softwarerat/MySQL/Mute.java @@ -0,0 +1,88 @@ +package com.softwarerat.MySQL; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +// Class containing all SQL things for the Ban Topic +public class Mute { + + SQLHandler sqlHandler; + + + public Mute(SQLHandler sqlHandler) { + this.sqlHandler = sqlHandler; + } + + public void addPunishment(String uuid, String Reason , String punisher, long time) { + + 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); + } + } + + 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 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); + } + if (resultSet != null) { + try { + resultSet.next(); + return resultSet.getString("UUID"); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + System.out.println("Loaded Kit"); + return null; + } + 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); + } + } + +} diff --git a/src/main/java/com/softwarerat/MySQL/Report.java b/src/main/java/com/softwarerat/MySQL/Report.java new file mode 100644 index 0000000..f212d04 --- /dev/null +++ b/src/main/java/com/softwarerat/MySQL/Report.java @@ -0,0 +1,70 @@ +package com.softwarerat.MySQL; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; + +public class Report { + + SQLHandler sqlHandler; + + public Report(SQLHandler sqlHandler) { + this.sqlHandler = sqlHandler; + } + + public void addReport(String uuid, String Reason , String reporter) { + + 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); + } + } + + + + public List getReports() { + List 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")); + } + + + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + 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); + } + } +} diff --git a/src/main/java/com/softwarerat/MySQL/SQLHandler.java b/src/main/java/com/softwarerat/MySQL/SQLHandler.java new file mode 100644 index 0000000..a159b49 --- /dev/null +++ b/src/main/java/com/softwarerat/MySQL/SQLHandler.java @@ -0,0 +1,37 @@ +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(); + } + + + + +} diff --git a/src/main/java/com/softwarerat/Netty/SyncDiscord.java b/src/main/java/com/softwarerat/Netty/SyncDiscord.java new file mode 100644 index 0000000..0d18b02 --- /dev/null +++ b/src/main/java/com/softwarerat/Netty/SyncDiscord.java @@ -0,0 +1,8 @@ +package com.softwarerat.Netty; + + +//because of Client Server communication to the discord bot, netty will be the easiest Client for that. +public class SyncDiscord { + + +}