Archived
1.19 Update - experimental
This commit is contained in:
1 parent
4d3eccd106
commit
e8db523433
32 files changed
+2551
-1785
No files matched your search
+5
-1
@@ -3,4 +3,8 @@ build/
|
||||
.idea/
|
||||
.gradle/
|
||||
*.iml
|
||||
*.class
|
||||
*.class
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
bin/
|
||||
+61
-27
@@ -1,40 +1,68 @@
|
||||
plugins {
|
||||
id "java"
|
||||
id "java-library"
|
||||
id "com.github.johnrengelman.shadow" version "7.1.2" // Import utility to package libraries into .jar file.
|
||||
|
||||
id 'java' // Tell gradle this is a java project.
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1' // Import utility to package libraries into .jar file.
|
||||
id 'eclipse' // Import eclipse plugin for IDE integration.
|
||||
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
// Declare java version.
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
}
|
||||
|
||||
group = 'uk.hotten'
|
||||
version = '1.0-beta'
|
||||
|
||||
def apiVersion = "1.19" // Declare minecraft server target version.
|
||||
|
||||
processResources {
|
||||
|
||||
def props = [
|
||||
version: version,
|
||||
apiVersion: apiVersion,
|
||||
]
|
||||
|
||||
inputs.properties props // Indicates to rerun if version changes.
|
||||
|
||||
filesMatching("plugin.yml") {
|
||||
|
||||
expand props
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
||||
mavenCentral()
|
||||
|
||||
maven {
|
||||
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
|
||||
|
||||
content {
|
||||
includeGroup 'org.bukkit'
|
||||
includeGroup 'org.spigotmc'
|
||||
}
|
||||
url "https://repo.purpurmc.org/snapshots" // Get purpur API from purpur maven repository.
|
||||
|
||||
}
|
||||
|
||||
maven {
|
||||
|
||||
url "https://jitpack.io"
|
||||
|
||||
}
|
||||
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
|
||||
|
||||
dependencies {
|
||||
api 'com.google.code.gson:gson:2.10.1'
|
||||
api 'commons-io:commons-io:2.11.0'
|
||||
api 'org.apache.commons:commons-pool2:2.11.1'
|
||||
api 'org.jooq:jooq:3.18.4'
|
||||
api 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
|
||||
api 'org.mariadb.jdbc:mariadb-java-client:3.1.3'
|
||||
api 'mysql:mysql-connector-java:8.0.32'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
|
||||
compileOnly "com.github.MilkBowl:VaultAPI:1.7"
|
||||
compileOnly 'com.google.code.gson:gson:2.10.1'
|
||||
compileOnly 'commons-io:commons-io:2.11.0'
|
||||
compileOnly 'org.apache.commons:commons-pool2:2.11.1'
|
||||
compileOnly 'org.jooq:jooq:3.18.4'
|
||||
compileOnly 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
|
||||
compileOnly 'org.mariadb.jdbc:mariadb-java-client:3.1.3'
|
||||
compileOnly 'mysql:mysql-connector-java:8.0.32'
|
||||
compileOnly 'org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
compileOnly 'org.projectlombok:lombok:1.18.22'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.22'
|
||||
}
|
||||
@@ -81,12 +109,18 @@ shadowJar {
|
||||
}
|
||||
}
|
||||
|
||||
jar.dependsOn shadowJar
|
||||
tasks.shadowJar.configure {
|
||||
|
||||
archiveClassifier = null
|
||||
|
||||
compileJava {
|
||||
options.compilerArgs += ["-parameters"]
|
||||
options.fork = true
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
compileJava.dependsOn updatePluginYmlVersion
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
|
||||
options.compilerArgs += ["-parameters"]
|
||||
options.encoding = 'UTF-8' // Override the system character set with a universal set.
|
||||
options.fork = true // Enable compilation in a separate daemon process.
|
||||
|
||||
}
|
||||
|
||||
compileJava.dependsOn updatePluginYmlVersion
|
||||
Vendored
BIN
Binary file not shown.
+2
-2
@@ -1,6 +1,6 @@
|
||||
#Fri May 12 20:46:04 BST 2023
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -55,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -80,10 +80,10 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
@@ -143,12 +143,16 @@ fi
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
@@ -205,6 +209,12 @@ set -- \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
|
||||
Vendored
+92
-89
@@ -1,89 +1,92 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -1,10 +1,16 @@
|
||||
package uk.hotten.staffog;
|
||||
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import uk.hotten.staffog.commands.*;
|
||||
import uk.hotten.staffog.commands.ChatReportCommand;
|
||||
import uk.hotten.staffog.commands.KickCommand;
|
||||
import uk.hotten.staffog.commands.LinkPanelCommand;
|
||||
import uk.hotten.staffog.commands.PermPunishCommand;
|
||||
import uk.hotten.staffog.commands.TempPunishCommand;
|
||||
import uk.hotten.staffog.commands.UnpunishCommand;
|
||||
import uk.hotten.staffog.data.DatabaseManager;
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.security.SecurityManager;
|
||||
@@ -13,59 +19,93 @@ import uk.hotten.staffog.utils.Console;
|
||||
|
||||
public class StaffOGPlugin extends JavaPlugin {
|
||||
|
||||
@Getter private static Permission vaultPerms;
|
||||
public static Permission getVaultPerms() {
|
||||
return vaultPerms;
|
||||
}
|
||||
|
||||
@Getter private static String reportWebAddress;
|
||||
@Getter private static String appealWebAddress;
|
||||
public static String getReportWebAddress() {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Console.info("Setting up Staff-OG...");
|
||||
return reportWebAddress;
|
||||
|
||||
// Tell JOOQ to STFU
|
||||
System.setProperty("org.jooq.no-tips", "true");
|
||||
}
|
||||
|
||||
this.saveDefaultConfig();
|
||||
// Declare variable to hold class for passing.
|
||||
private static StaffOGPlugin plugin;
|
||||
|
||||
if (!setupVaultPerms()) {
|
||||
Console.error("Vault not found. Plugin will be disabled.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
private static Permission vaultPerms;
|
||||
|
||||
reportWebAddress = this.getConfig().getString("reportWebAddress");
|
||||
appealWebAddress = this.getConfig().getString("appealWebAddress");
|
||||
private static String reportWebAddress;
|
||||
@Getter private static String appealWebAddress;
|
||||
|
||||
DatabaseManager databaseManager = new DatabaseManager(this);
|
||||
PunishManager punishManager = new PunishManager(this);
|
||||
SecurityManager securityManager = new SecurityManager(this);
|
||||
TaskManager taskManager = new TaskManager(this);
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
getCommand("linkpanel").setExecutor(new LinkPanelCommand());
|
||||
getCommand("chatreport").setExecutor(new ChatReportCommand());
|
||||
Console.info("Setting up Staff-OG...");
|
||||
|
||||
getCommand("permban").setExecutor(new PermPunishCommand());
|
||||
getCommand("tempban").setExecutor(new TempPunishCommand());
|
||||
getCommand("unban").setExecutor(new UnpunishCommand());
|
||||
getCommand("permmute").setExecutor(new PermPunishCommand());
|
||||
getCommand("tempmute").setExecutor(new TempPunishCommand());
|
||||
getCommand("unmute").setExecutor(new UnpunishCommand());
|
||||
getCommand("kick").setExecutor(new KickCommand());
|
||||
// Assign the plugin variable to the main class instance.
|
||||
plugin = this;
|
||||
|
||||
databaseManager.setStatEntry("server_status", "online");
|
||||
// Tell JOOQ to STFU
|
||||
System.setProperty("org.jooq.no-tips", "true");
|
||||
|
||||
Console.info("Staff-OG is ready!");
|
||||
}
|
||||
this.saveDefaultConfig();
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
DatabaseManager.getInstance().setStatEntry("server_status", "offline");
|
||||
DatabaseManager.getInstance().setStatEntry("player_count", "0");
|
||||
DatabaseManager.getInstance().setStatEntry("staff_count", "0");
|
||||
}
|
||||
if (! setupVaultPerms()) {
|
||||
|
||||
private boolean setupVaultPerms() {
|
||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||
vaultPerms = rsp.getProvider();
|
||||
return vaultPerms != null;
|
||||
}
|
||||
}
|
||||
Console.error("Vault not found. Plugin will be disabled.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
|
||||
}
|
||||
|
||||
reportWebAddress = this.getConfig().getString("reportWebAddress");
|
||||
appealWebAddress = this.getConfig().getString("appealWebAddress");
|
||||
|
||||
DatabaseManager databaseManager = new DatabaseManager(this);
|
||||
new PunishManager(this);
|
||||
new SecurityManager(this);
|
||||
new TaskManager(this);
|
||||
|
||||
getCommand("linkpanel").setExecutor(new LinkPanelCommand());
|
||||
getCommand("chatreport").setExecutor(new ChatReportCommand());
|
||||
|
||||
getCommand("permban").setExecutor(new PermPunishCommand());
|
||||
getCommand("tempban").setExecutor(new TempPunishCommand());
|
||||
getCommand("unban").setExecutor(new UnpunishCommand());
|
||||
getCommand("permmute").setExecutor(new PermPunishCommand());
|
||||
getCommand("tempmute").setExecutor(new TempPunishCommand());
|
||||
getCommand("unmute").setExecutor(new UnpunishCommand());
|
||||
getCommand("kick").setExecutor(new KickCommand());
|
||||
|
||||
databaseManager.setStatEntry("server_status", "online");
|
||||
|
||||
Console.info("Staff-OG is ready!");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
DatabaseManager.getInstance().setStatEntry("server_status", "offline");
|
||||
DatabaseManager.getInstance().setStatEntry("player_count", "0");
|
||||
DatabaseManager.getInstance().setStatEntry("staff_count", "0");
|
||||
|
||||
}
|
||||
|
||||
private boolean setupVaultPerms() {
|
||||
|
||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||
vaultPerms = rsp.getProvider();
|
||||
|
||||
return vaultPerms != null;
|
||||
|
||||
}
|
||||
|
||||
// Class constructor.
|
||||
public static StaffOGPlugin getPlugin() {
|
||||
|
||||
// Pass instance of main to other classes.
|
||||
return plugin;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,69 +1,82 @@
|
||||
package uk.hotten.staffog.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import uk.hotten.staffog.StaffOGPlugin;
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.security.SecurityManager;
|
||||
import uk.hotten.staffog.security.data.StaffIPInfo;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.hotten.staffog.StaffOGPlugin;
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
|
||||
public class ChatReportCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "You cannot run this command!"));
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
if (args == null || args.length < 2) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /chatreport <player> <reason>"));
|
||||
return true;
|
||||
}
|
||||
if (! (sender instanceof Player player)) {
|
||||
|
||||
PunishManager pm = PunishManager.getInstance();
|
||||
if (!pm.isIncludedInCurrentChatReport(args[0])) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + args[0] + " has not used chat in the past two minutes."));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("ERROR: Only players can run this command!");
|
||||
return true;
|
||||
|
||||
UUID reported = pm.getUUIDFromChatReport(args[0]);
|
||||
}
|
||||
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
if (args == null || args.length < 2) {
|
||||
|
||||
String chatReportId = pm.exportChatReport(player.getUniqueId(), reported);
|
||||
if (chatReportId == null) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Failed to generate chat report. Please try again."));
|
||||
return true;
|
||||
}
|
||||
Message.staffOGMessage(player, "&6Correct Usage: &e/chatreport <player> <reason>");
|
||||
return true;
|
||||
|
||||
String staffReportId = pm.createReportFromCR(player.getUniqueId(), reported, Integer.parseInt(chatReportId), reason);
|
||||
if (staffReportId == null) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Failed to create a report to staff, however a chat log was successfully exported with ID " +
|
||||
ChatColor.WHITE + "#" + chatReportId + ChatColor.RED + ". Please create a manual report quoting this Chat Report ID on " +
|
||||
ChatColor.WHITE + StaffOGPlugin.getReportWebAddress()));
|
||||
} else {
|
||||
player.sendMessage(Message.format(ChatColor.GREEN + "Thanks for your report! Your report reference is " +
|
||||
ChatColor.WHITE + "#" + staffReportId + ChatColor.GREEN + ". Your chat report ID is " +
|
||||
ChatColor.WHITE + "#" + chatReportId + ChatColor.GREEN + " and has been included in your report."));
|
||||
player.sendMessage(Message.format(ChatColor.DARK_GREEN + "You can check the status of your report at " +
|
||||
ChatColor.WHITE + StaffOGPlugin.getReportWebAddress()));
|
||||
}
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification("REPORT", "New Mutable Offences report #" + staffReportId + " by " + player.getName() + " against " + args[0]));
|
||||
}
|
||||
PunishManager pm = PunishManager.getInstance();
|
||||
if (! pm.isIncludedInCurrentChatReport(args[0])) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Message.staffOGMessage(player, ("&c" + args[0] + " has not used chat in the past two minutes."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
UUID reported = pm.getUUIDFromChatReport(args[0]);
|
||||
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
|
||||
String chatReportId = pm.exportChatReport(player.getUniqueId(), reported);
|
||||
if (chatReportId == null) {
|
||||
|
||||
Message.staffOGMessage(player, "&c Failed to generate chat report. Please try again.");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
String staffReportId = pm.createReportFromCR(player.getUniqueId(), reported, Integer.parseInt(chatReportId), reason);
|
||||
if (staffReportId == null) {
|
||||
|
||||
Message.staffOGMessage(player, ("&cFailed to create a report to staff, however a chat log was successfully exported with ID " +
|
||||
"&f" + "#" + chatReportId + "&c" + ". Please create a manual report quoting this Chat Report ID on " +
|
||||
"&f" + StaffOGPlugin.getReportWebAddress()));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Message.staffOGMessage(player, ("&a Thanks for your report! Your report reference is " +
|
||||
"&f" + "#" + staffReportId + "&a" + ". Your chat report ID is " +
|
||||
"&f" + "#" + chatReportId + "&a" + " and has been included in your report."));
|
||||
|
||||
Message.staffOGMessage(player, ("&2" + "You can check the status of your report at " +
|
||||
"&f" + StaffOGPlugin.getReportWebAddress()));
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification("REPORT", "New Mutable Offences report #" + staffReportId + " by " + player.getName() + " against " + args[0]));
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +1,60 @@
|
||||
package uk.hotten.staffog.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.punish.data.KickPunishEntry;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
import uk.hotten.staffog.utils.TimeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.punish.data.KickPunishEntry;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
|
||||
public class KickCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args == null || args.length < 1) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /kick <player> [reason]"));
|
||||
return true;
|
||||
}
|
||||
if (args == null || args.length < 1) {
|
||||
|
||||
Player toKick = Bukkit.getServer().getPlayer(args[0]);
|
||||
if (toKick == null) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + args[0] + " is not online!"));
|
||||
return true;
|
||||
}
|
||||
Message.staffOGMessage((Player) sender, "&6Correct Usage: &e/kick <player> [reason]");
|
||||
return true;
|
||||
|
||||
KickPunishEntry entry = new KickPunishEntry();
|
||||
entry.setUuid(toKick.getUniqueId());
|
||||
entry.setName(toKick.getName());
|
||||
entry.setPlayer(toKick);
|
||||
entry.setByUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "NCP");
|
||||
entry.setByName((sender instanceof Player) ? ((Player) sender).getName() : "NCP");
|
||||
entry.setTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (args.length >= 2) {
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setReason(reason);
|
||||
} else {
|
||||
entry.setReason("No reason specified");
|
||||
}
|
||||
Player toKick = Bukkit.getServer().getPlayer(args[0]);
|
||||
if (toKick == null) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&c" + args[0] + " is not online!"));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
KickPunishEntry entry = new KickPunishEntry();
|
||||
entry.setUuid(toKick.getUniqueId());
|
||||
entry.setName(toKick.getName());
|
||||
entry.setPlayer(toKick);
|
||||
entry.setByUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "NCP");
|
||||
entry.setByName((sender instanceof Player) ? ((Player) sender).getName() : "NCP");
|
||||
entry.setTime(System.currentTimeMillis());
|
||||
|
||||
if (args.length >= 2) {
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setReason(reason);
|
||||
}
|
||||
else {
|
||||
entry.setReason("No reason specified");
|
||||
}
|
||||
|
||||
PunishManager.getInstance().newKickPunishment(entry);
|
||||
Message.staffOGMessage((Player) sender, ("&7" + "You have kicked " + entry.getName() + "."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
PunishManager.getInstance().newKickPunishment(entry);
|
||||
sender.sendMessage(Message.format(ChatColor.GRAY + "You have kicked " + entry.getName() + "."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package uk.hotten.staffog.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.hotten.staffog.StaffOGPlugin;
|
||||
import uk.hotten.staffog.security.SecurityManager;
|
||||
import uk.hotten.staffog.security.data.StaffIPInfo;
|
||||
@@ -12,39 +12,51 @@ import uk.hotten.staffog.utils.Message;
|
||||
|
||||
public class LinkPanelCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "You cannot run this command!"));
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (! (sender instanceof Player player)) {
|
||||
|
||||
SecurityManager sm = SecurityManager.getInstance();
|
||||
sender.sendMessage("ERROR: Only players can run this command!");
|
||||
return true;
|
||||
|
||||
if (!sm.getStaffIPInfos().containsKey(player.getUniqueId())) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Required data is missing, please re-log."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
StaffIPInfo ipInfo = sm.getStaffIPInfos().get(player.getUniqueId());
|
||||
if (ipInfo.isPanelVerified()) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Your IP has already been verified on the panel."));
|
||||
return true;
|
||||
}
|
||||
SecurityManager sm = SecurityManager.getInstance();
|
||||
|
||||
String doesHaveCode = sm.doesPlayerHaveLinkCode(player.getUniqueId());
|
||||
if (doesHaveCode != null) {
|
||||
player.sendMessage(Message.format("Your activation code is " + ChatColor.YELLOW + doesHaveCode));
|
||||
return true;
|
||||
}
|
||||
if (! sm.getStaffIPInfos().containsKey(player.getUniqueId())) {
|
||||
|
||||
String code = sm.createLinkCode(player.getUniqueId(), StaffOGPlugin.getVaultPerms().has(player, "staffog.paneladmin"));
|
||||
if (code == null) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Failed to create activation code. Please contact an administrator."));
|
||||
return true;
|
||||
}
|
||||
Message.staffOGMessage(player, "&cRequired data is missing, please re-log.");
|
||||
return true;
|
||||
|
||||
player.sendMessage(Message.format("Your activation code is " + ChatColor.YELLOW + code));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StaffIPInfo ipInfo = sm.getStaffIPInfos().get(player.getUniqueId());
|
||||
if (ipInfo.isPanelVerified()) {
|
||||
|
||||
Message.staffOGMessage(player, ("&6Your IP has already been verified on the panel."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
String doesHaveCode = sm.doesPlayerHaveLinkCode(player.getUniqueId());
|
||||
if (doesHaveCode != null) {
|
||||
|
||||
Message.staffOGMessage(player, ("&6Your activation code is &e" + doesHaveCode));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
String code = sm.createLinkCode(player.getUniqueId(), StaffOGPlugin.getVaultPerms().has(player, "staffog.paneladmin"));
|
||||
if (code == null) {
|
||||
|
||||
Message.staffOGMessage(player, ("&cERROR: Failed to create activation code. Please contact an administrator."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
Message.staffOGMessage(player, ("&6Your activation code is: &e" + code));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +1,95 @@
|
||||
package uk.hotten.staffog.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
import uk.hotten.staffog.utils.TimeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PermPunishCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args == null || args.length < 2) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /" + label + " <player> <reason>"));
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
PunishType commandType;
|
||||
if (label.toLowerCase().contains("permban"))
|
||||
commandType = PunishType.BAN;
|
||||
else if (label.toLowerCase().contains("permmute"))
|
||||
commandType = PunishType.MUTE;
|
||||
else {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Unsupported type for command."));
|
||||
return true;
|
||||
}
|
||||
if (args == null || args.length < 2) {
|
||||
|
||||
UUID uuid = PunishManager.getInstance().getUUIDFromName(args[0]);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + args[0] + " has never joined the server!"));
|
||||
return true;
|
||||
}
|
||||
Message.staffOGMessage((Player) sender, ("&6Correct Usage: &e/" + label + " <player> <reason>"));
|
||||
return true;
|
||||
|
||||
PunishEntry isPunished = PunishManager.getInstance().checkActivePunishment(commandType, uuid);
|
||||
if (isPunished != null) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + args[0] + " is already " + commandType.getBroadcastMessage() + " for " + TimeUtils.formatMillisecondTime(isPunished.calculateRemaining())) + ".");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
PunishType commandType;
|
||||
if (label.toLowerCase().contains("permban")) {
|
||||
|
||||
PunishEntry entry = new PunishEntry(commandType);
|
||||
commandType = PunishType.BAN;
|
||||
|
||||
entry.setUuid(uuid);
|
||||
entry.setName(player.getName());
|
||||
if (player.isOnline())
|
||||
entry.setPlayer(player.getPlayer());
|
||||
entry.setByUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "NCP");
|
||||
entry.setByName((sender instanceof Player) ? ((Player) sender).getName() : "NCP");
|
||||
entry.setTime(System.currentTimeMillis());
|
||||
entry.setUntil(-1);
|
||||
entry.setActive(true);
|
||||
}
|
||||
else if (label.toLowerCase().contains("permmute")) {
|
||||
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setReason(reason);
|
||||
commandType = PunishType.MUTE;
|
||||
|
||||
PunishManager.getInstance().newPunishment(entry);
|
||||
sender.sendMessage(Message.format(ChatColor.GRAY + "You have " + commandType.getBroadcastMessage() + " " + entry.getName() + " for permanent."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&cERROR: Unsupported type for command."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
UUID uuid = PunishManager.getInstance().getUUIDFromName(args[0]);
|
||||
if (uuid == null) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&c" + args[0] + " has never joined the server!"));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
PunishEntry isPunished = PunishManager.getInstance().checkActivePunishment(commandType, uuid);
|
||||
if (isPunished != null) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&c" + args[0] + " is already " + commandType.getBroadcastMessage() + " for " + TimeUtils.formatMillisecondTime(isPunished.calculateRemaining())) + ".");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
PunishEntry entry = new PunishEntry(commandType);
|
||||
|
||||
entry.setUuid(uuid);
|
||||
entry.setName(player.getName());
|
||||
if (player.isOnline()) {
|
||||
|
||||
entry.setPlayer(player.getPlayer());
|
||||
|
||||
}
|
||||
entry.setByUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "NCP");
|
||||
entry.setByName((sender instanceof Player) ? ((Player) sender).getName() : "NCP");
|
||||
entry.setTime(System.currentTimeMillis());
|
||||
entry.setUntil(-1);
|
||||
entry.setActive(true);
|
||||
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setReason(reason);
|
||||
|
||||
PunishManager.getInstance().newPunishment(entry);
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&7You have " + commandType.getBroadcastMessage() + " " + entry.getName() + " for permanent."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,116 +1,143 @@
|
||||
package uk.hotten.staffog.commands;
|
||||
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
import uk.hotten.staffog.utils.TimeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
import uk.hotten.staffog.utils.TimeUtils;
|
||||
|
||||
public class TempPunishCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args == null || args.length < 4) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /" + label + " <player> <unit> <amount> <reason>"));
|
||||
return true;
|
||||
}
|
||||
if (args == null || args.length < 4) {
|
||||
|
||||
int amount;
|
||||
try {
|
||||
amount = Integer.parseInt(args[2]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(Message.format(Message.format(ChatColor.RED + "The amount of units must be a number!")));
|
||||
return true;
|
||||
}
|
||||
Message.staffOGMessage((Player) sender, ("&6Correct Usage: &e/" + label + " <player> <unit> <amount> <reason>"));
|
||||
return true;
|
||||
|
||||
Date currentTime = new Date(System.currentTimeMillis());
|
||||
long untilTime;
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "d": {
|
||||
untilTime = DateUtils.addDays(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
case "w": {
|
||||
untilTime = DateUtils.addWeeks(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
int amount;
|
||||
try {
|
||||
|
||||
case "m": {
|
||||
untilTime = DateUtils.addMonths(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
amount = Integer.parseInt(args[2]);
|
||||
|
||||
case "y": {
|
||||
untilTime = DateUtils.addYears(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
default: {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Invalid time unit, please supply: (d)ay, (w)eek, (m)onth or (y)ear."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Message.staffOGMessage((Player) sender, ("&cERROR: The amount of units must be a number!"));
|
||||
return true;
|
||||
|
||||
PunishType commandType;
|
||||
if (label.toLowerCase().contains("tempban"))
|
||||
commandType = PunishType.BAN;
|
||||
else if (label.toLowerCase().contains("tempmute"))
|
||||
commandType = PunishType.MUTE;
|
||||
else {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Unsupported type for command."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
UUID uuid = PunishManager.getInstance().getUUIDFromName(args[0]);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + args[0] + " has never joined the server!"));
|
||||
return true;
|
||||
}
|
||||
Date currentTime = new Date(System.currentTimeMillis());
|
||||
long untilTime;
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "d": {
|
||||
untilTime = DateUtils.addDays(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
|
||||
case "w": {
|
||||
untilTime = DateUtils.addWeeks(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
|
||||
case "m": {
|
||||
untilTime = DateUtils.addMonths(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
|
||||
case "y": {
|
||||
untilTime = DateUtils.addYears(currentTime, amount).getTime();
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&cERROR: Invalid time unit. &6Please supply: &e(d)ay, (w)eek, (m)onth or (y)ear&6."));
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
PunishEntry isPunished = PunishManager.getInstance().checkActivePunishment(commandType, uuid);
|
||||
if (isPunished != null) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + args[0] + " is already " + commandType.getBroadcastMessage() + " for " + TimeUtils.formatMillisecondTime(isPunished.calculateRemaining())) + ".");
|
||||
return true;
|
||||
}
|
||||
PunishType commandType;
|
||||
if (label.toLowerCase().contains("tempban")) {
|
||||
|
||||
OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
commandType = PunishType.BAN;
|
||||
|
||||
PunishEntry entry = new PunishEntry(commandType);
|
||||
}
|
||||
else if (label.toLowerCase().contains("tempmute")) {
|
||||
|
||||
entry.setUuid(uuid);
|
||||
entry.setName(player.getName());
|
||||
if (player.isOnline())
|
||||
entry.setPlayer(player.getPlayer());
|
||||
entry.setByUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "NCP");
|
||||
entry.setByName((sender instanceof Player) ? ((Player) sender).getName() : "NCP");
|
||||
entry.setTime(currentTime.getTime());
|
||||
entry.setUntil(untilTime);
|
||||
entry.setActive(true);
|
||||
commandType = PunishType.MUTE;
|
||||
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
preReason.remove(0);
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setReason(reason);
|
||||
}
|
||||
else {
|
||||
|
||||
PunishManager.getInstance().newPunishment(entry);
|
||||
sender.sendMessage(Message.format(ChatColor.GRAY + "You have " + commandType.getBroadcastMessage() + " " + entry.getName() + " for " + TimeUtils.formatMillisecondTime(entry.calculateDuration()) + "."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Message.staffOGMessage((Player) sender, ("&cERROR: Unsupported type for command."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
UUID uuid = PunishManager.getInstance().getUUIDFromName(args[0]);
|
||||
if (uuid == null) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&c" + args[0] + " has never joined the server!"));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
PunishEntry isPunished = PunishManager.getInstance().checkActivePunishment(commandType, uuid);
|
||||
if (isPunished != null) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&c" + args[0] + " is already " + commandType.getBroadcastMessage() + " for " + TimeUtils.formatMillisecondTime(isPunished.calculateRemaining())) + ".");
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
|
||||
PunishEntry entry = new PunishEntry(commandType);
|
||||
|
||||
entry.setUuid(uuid);
|
||||
entry.setName(player.getName());
|
||||
if (player.isOnline()) {
|
||||
|
||||
entry.setPlayer(player.getPlayer());
|
||||
|
||||
}
|
||||
entry.setByUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "NCP");
|
||||
entry.setByName((sender instanceof Player) ? ((Player) sender).getName() : "NCP");
|
||||
entry.setTime(currentTime.getTime());
|
||||
entry.setUntil(untilTime);
|
||||
entry.setActive(true);
|
||||
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
preReason.remove(0);
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setReason(reason);
|
||||
|
||||
PunishManager.getInstance().newPunishment(entry);
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&7" + "You have " + commandType.getBroadcastMessage() + " " + entry.getName() + " for " + TimeUtils.formatMillisecondTime(entry.calculateDuration()) + "."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +1,78 @@
|
||||
package uk.hotten.staffog.commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
import uk.hotten.staffog.utils.TimeUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
|
||||
public class UnpunishCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args == null || args.length < 2) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /" + label + " <player> <reason>"));
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
if (args == null || args.length < 2) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&6Correct Usage: &e/" + label + " <player> <reason>"));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
PunishType commandType;
|
||||
if (label.toLowerCase().contains("unban"))
|
||||
commandType = PunishType.BAN;
|
||||
else if (label.toLowerCase().contains("unmute"))
|
||||
commandType = PunishType.MUTE;
|
||||
else {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "Unsupported type for command."));
|
||||
return true;
|
||||
}
|
||||
PunishType commandType;
|
||||
if (label.toLowerCase().contains("unban")) {
|
||||
|
||||
commandType = PunishType.BAN;
|
||||
|
||||
}
|
||||
else if (label.toLowerCase().contains("unmute")) {
|
||||
|
||||
commandType = PunishType.MUTE;
|
||||
|
||||
UUID uuid = PunishManager.getInstance().getUUIDFromName(args[0]);
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + args[0] + " has never joined the server!"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&cERROR: Unsupported type for command."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
PunishEntry entry = PunishManager.getInstance().checkActivePunishment(commandType, uuid);
|
||||
if (entry == null) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + args[0] + " is not currently " + commandType.getBroadcastMessage() + "."));
|
||||
return true;
|
||||
}
|
||||
UUID uuid = PunishManager.getInstance().getUUIDFromName(args[0]);
|
||||
if (uuid == null) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&e" + args[0] + " has never joined the server!"));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
entry.setRemovedUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "Console");
|
||||
entry.setRemovedName((sender instanceof Player) ? ((Player) sender).getName() : "Console");
|
||||
PunishEntry entry = PunishManager.getInstance().checkActivePunishment(commandType, uuid);
|
||||
if (entry == null) {
|
||||
|
||||
Message.staffOGMessage((Player) sender, ("&c" + args[0] + " is not currently " + commandType.getBroadcastMessage() + "."));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setRemovedReason(reason);
|
||||
entry.setRemovedUuid((sender instanceof Player) ? ((Player) sender).getUniqueId().toString() : "Console");
|
||||
entry.setRemovedName((sender instanceof Player) ? ((Player) sender).getName() : "Console");
|
||||
|
||||
PunishManager.getInstance().removePunishment(entry);
|
||||
sender.sendMessage(Message.format(ChatColor.GRAY + "You have un" + commandType.getBroadcastMessage() + " " + entry.getName() + "."));
|
||||
ArrayList<String> preReason = new ArrayList<>(Arrays.asList(args));
|
||||
preReason.remove(0);
|
||||
String reason = String.join(" ", preReason);
|
||||
entry.setRemovedReason(reason);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
PunishManager.getInstance().removePunishment(entry);
|
||||
Message.staffOGMessage((Player) sender, ("&7You have un" + commandType.getBroadcastMessage() + " " + entry.getName() + "."));
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,30 +10,40 @@ import uk.hotten.staffog.StaffOGPlugin;
|
||||
|
||||
public class DataEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
updatePlayerCounts();
|
||||
}
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
Bukkit.getServer().getScheduler().runTaskLater(DatabaseManager.getInstance().getPlugin(), this::updatePlayerCounts, 10);
|
||||
}
|
||||
updatePlayerCounts();
|
||||
|
||||
private void updatePlayerCounts() {
|
||||
DatabaseManager dbm = DatabaseManager.getInstance();
|
||||
}
|
||||
|
||||
// All players
|
||||
dbm.setStatEntry("player_count", String.valueOf(Bukkit.getServer().getOnlinePlayers().size()));
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
|
||||
// Staff
|
||||
int amount = 0;
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (StaffOGPlugin.getVaultPerms().has(p, "staffog.isstaff")) {
|
||||
amount++;
|
||||
}
|
||||
}
|
||||
Bukkit.getServer().getScheduler().runTaskLater(DatabaseManager.getPlugin(), this::updatePlayerCounts, 10);
|
||||
|
||||
dbm.setStatEntry("staff_count", String.valueOf(amount));
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePlayerCounts() {
|
||||
|
||||
DatabaseManager dbm = DatabaseManager.getInstance();
|
||||
|
||||
// All players
|
||||
dbm.setStatEntry("player_count", String.valueOf(Bukkit.getServer().getOnlinePlayers().size()));
|
||||
|
||||
// Staff
|
||||
int amount = 0;
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
|
||||
if (StaffOGPlugin.getVaultPerms().has(p, "staffog.isstaff")) {
|
||||
|
||||
amount++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dbm.setStatEntry("staff_count", String.valueOf(amount));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,484 +1,498 @@
|
||||
package uk.hotten.staffog.data;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.impl.DSL;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Console;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
import static uk.hotten.staffog.data.jooq.Tables.STAFFOG_STAT;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Console;
|
||||
|
||||
public class DatabaseManager {
|
||||
|
||||
@Getter private JavaPlugin plugin;
|
||||
@Getter private static DatabaseManager instance;
|
||||
|
||||
private String driver, driverUrl, host, username, password, database;
|
||||
private int port;
|
||||
|
||||
public DatabaseManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
instance = this;
|
||||
|
||||
String sqlType = plugin.getConfig().getString("sqlType");
|
||||
if (sqlType == null) {
|
||||
Console.error("NO SQL TYPE SELECTED. DEFAULTING TO MYSQL.");
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
driverUrl = "mysql";
|
||||
} else {
|
||||
if (sqlType.equalsIgnoreCase("mysql")) {
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
driverUrl = "mysql";
|
||||
} else if (sqlType.equals("mariadb")) {
|
||||
driver = "org.mariadb.jdbc.Driver";
|
||||
driverUrl = "mariadb";
|
||||
} else {
|
||||
Console.error("INVALID SQL TYPE, PLEASE USE EITHER MYSQL OR MARIADB. DEFAULTING TO MYSQL.");
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
driverUrl = "mysql";
|
||||
}
|
||||
}
|
||||
|
||||
host = plugin.getConfig().getString("sqlHost");
|
||||
username = plugin.getConfig().getString("sqlUsername");
|
||||
password = plugin.getConfig().getString("sqlPassword");
|
||||
database = plugin.getConfig().getString("sqlDatabase");
|
||||
port = plugin.getConfig().getInt("sqlPort");
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new DataEventListener(), plugin);
|
||||
|
||||
for (PunishType pt : PunishType.values()) checkPunishmentTable(pt.getTable());
|
||||
checkKickTable();
|
||||
checkNameHistoryTable();
|
||||
checkTaskTable();
|
||||
checkStatTable();
|
||||
checkWebTable();
|
||||
checkLinkCodeTable();
|
||||
checkStaffIpTable();
|
||||
checkAuditTable();
|
||||
checkAppealTable();
|
||||
checkReportTable();
|
||||
checkChatReportTable();
|
||||
}
|
||||
|
||||
public Connection createConnection() throws SQLException, ClassNotFoundException {
|
||||
synchronized (this) {
|
||||
Class.forName(driver);
|
||||
return DriverManager.getConnection("jdbc:" + driverUrl + "://" + host + ":" + port + "/" + database + "?userSSL=false", username, password);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPunishmentTable(String table) {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, table, new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `" + table + "` (" +
|
||||
" `id` bigint(20) NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `reason` varchar(2048) NOT NULL," +
|
||||
" `by_uuid` varchar(36) DEFAULT NULL," +
|
||||
" `by_name` varchar(128) DEFAULT NULL," +
|
||||
" `removed_uuid` varchar(36) DEFAULT NULL," +
|
||||
" `removed_name` varchar(128) DEFAULT NULL," +
|
||||
" `removed_reason` varchar(2048) DEFAULT NULL," +
|
||||
" `removed_time` bigint(20) DEFAULT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" `until` bigint(20) NOT NULL," +
|
||||
" `active` bit(1) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created '" + table + "' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check '" + table + "' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkKickTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_kick", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_kick` (" +
|
||||
" `id` bigint(20) NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `reason` varchar(2048) NOT NULL," +
|
||||
" `by_uuid` varchar(36) NOT NULL," +
|
||||
" `by_name` varchar(128) NOT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_kick' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_kick' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNameHistoryTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_history", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_history` (" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT," +
|
||||
" `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" `name` varchar(16) NOT NULL," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_history' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_history' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkTaskTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_task", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_task` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `task` varchar(2048) NOT NULL," +
|
||||
" `data` varchar(2048) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_task' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_task' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStatTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_stat", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_stat` (" +
|
||||
" `name` varchar(2048) NOT NULL," +
|
||||
" `stat` varchar(2048) NOT NULL," +
|
||||
" UNIQUE KEY `name` (`name`) USING HASH" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_stat' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_stat' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doesStatIncludeEntry(String entry) {
|
||||
try (Connection connection = createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
return dsl.fetchExists(dsl.selectFrom(STAFFOG_STAT)
|
||||
.where(STAFFOG_STAT.NAME.eq(entry)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatEntry(String entry, String stat) {
|
||||
try (Connection connection = createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (!doesStatIncludeEntry(entry)) {
|
||||
dsl.insertInto(STAFFOG_STAT)
|
||||
.set(STAFFOG_STAT.NAME, entry)
|
||||
.set(STAFFOG_STAT.STAT, stat)
|
||||
.execute();
|
||||
} else {
|
||||
dsl.update(STAFFOG_STAT)
|
||||
.set(STAFFOG_STAT.STAT, stat)
|
||||
.where(STAFFOG_STAT.NAME.eq(entry))
|
||||
.execute();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkWebTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_web", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_web` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `username` varchar(128) NOT NULL," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `password` varchar(2048) NOT NULL," +
|
||||
" `active` bit(1) NOT NULL DEFAULT b'1'," +
|
||||
" `admin` bit(1) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)," +
|
||||
" UNIQUE KEY `username` (`username`,`uuid`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_web' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_web' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkLinkCodeTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_linkcode", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_linkcode` (" +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `code` varchar(5) NOT NULL," +
|
||||
" `admin` bit(1) NOT NULL," +
|
||||
" UNIQUE KEY `uuid` (`uuid`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_linkcode' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_linkcode' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStaffIpTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_staffip", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_staffip` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `ip` varchar(15) NOT NULL," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `initial` bit(1) NOT NULL," +
|
||||
" `panel_acknowledged` bit(1) NOT NULL," +
|
||||
" `panel_verified` bit(1) NOT NULL," +
|
||||
" `game_verified` bit(1) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_staffip' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_staffip' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAuditTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_audit", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_audit` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `type` varchar(2048) NOT NULL," +
|
||||
" `data` varchar(2048) NOT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_audit' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_audit' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAppealTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_appeal", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_appeal` (" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `time` bigint NOT NULL," +
|
||||
" `type` varchar(128) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `pid` int NOT NULL," +
|
||||
" `reason` varchar(2048) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `evidence` varchar(2048) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '[]'," +
|
||||
" `open` bit(1) NOT NULL DEFAULT b'1'," +
|
||||
" `assigned` varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" `verdict` bit(1) DEFAULT NULL," +
|
||||
" `verdict_time` bigint DEFAULT NULL," +
|
||||
" `comment` varchar(2048) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_appeal' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_appeal' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkReportTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_report", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_report` (" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `by_uuid` varchar(36) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `time` bigint NOT NULL," +
|
||||
" `type` varchar(128) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `reason` varchar(2048) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `evidence` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '[]'," +
|
||||
" `crid` int DEFAULT NULL," +
|
||||
" `open` bit(1) NOT NULL DEFAULT b'1'," +
|
||||
" `assigned` varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" `verdict` bit(1) DEFAULT NULL," +
|
||||
" `verdict_time` bigint DEFAULT NULL," +
|
||||
" `comment` varchar(2048) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_report' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_report' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkChatReportTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_chatreport", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_chatreport` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `by_uuid` varchar(36) NOT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" `messages` varchar(2048) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_chatreport' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_chatreport' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private static JavaPlugin plugin;
|
||||
|
||||
public static JavaPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
private static DatabaseManager instance;
|
||||
|
||||
private String driver, driverUrl, host, username, password, database;
|
||||
private int port;
|
||||
|
||||
public DatabaseManager(JavaPlugin plugin) {
|
||||
DatabaseManager.plugin = plugin;
|
||||
instance = this;
|
||||
|
||||
String sqlType = plugin.getConfig().getString("sqlType");
|
||||
if (sqlType == null) {
|
||||
Console.error("NO SQL TYPE SELECTED. DEFAULTING TO MYSQL.");
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
driverUrl = "mysql";
|
||||
} else {
|
||||
if (sqlType.equalsIgnoreCase("mysql")) {
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
driverUrl = "mysql";
|
||||
} else if (sqlType.equals("mariadb")) {
|
||||
driver = "org.mariadb.jdbc.Driver";
|
||||
driverUrl = "mariadb";
|
||||
} else {
|
||||
Console.error("INVALID SQL TYPE, PLEASE USE EITHER MYSQL OR MARIADB. DEFAULTING TO MYSQL.");
|
||||
driver = "com.mysql.jdbc.Driver";
|
||||
driverUrl = "mysql";
|
||||
}
|
||||
}
|
||||
|
||||
host = plugin.getConfig().getString("sqlHost");
|
||||
username = plugin.getConfig().getString("sqlUsername");
|
||||
password = plugin.getConfig().getString("sqlPassword");
|
||||
database = plugin.getConfig().getString("sqlDatabase");
|
||||
port = plugin.getConfig().getInt("sqlPort");
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new DataEventListener(), plugin);
|
||||
|
||||
for (PunishType pt : PunishType.values()) checkPunishmentTable(pt.getTable());
|
||||
checkKickTable();
|
||||
checkNameHistoryTable();
|
||||
checkTaskTable();
|
||||
checkStatTable();
|
||||
checkWebTable();
|
||||
checkLinkCodeTable();
|
||||
checkStaffIpTable();
|
||||
checkAuditTable();
|
||||
checkAppealTable();
|
||||
checkReportTable();
|
||||
checkChatReportTable();
|
||||
}
|
||||
|
||||
public static DatabaseManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Connection createConnection() throws SQLException, ClassNotFoundException {
|
||||
synchronized (this) {
|
||||
Class.forName(driver);
|
||||
return DriverManager.getConnection("jdbc:" + driverUrl + "://" + host + ":" + port + "/" + database + "?userSSL=false", username, password);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPunishmentTable(String table) {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, table, new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `" + table + "` (" +
|
||||
" `id` bigint(20) NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `reason` varchar(2048) NOT NULL," +
|
||||
" `by_uuid` varchar(36) DEFAULT NULL," +
|
||||
" `by_name` varchar(128) DEFAULT NULL," +
|
||||
" `removed_uuid` varchar(36) DEFAULT NULL," +
|
||||
" `removed_name` varchar(128) DEFAULT NULL," +
|
||||
" `removed_reason` varchar(2048) DEFAULT NULL," +
|
||||
" `removed_time` bigint(20) DEFAULT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" `until` bigint(20) NOT NULL," +
|
||||
" `active` bit(1) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created '" + table + "' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check '" + table + "' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkKickTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_kick", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_kick` (" +
|
||||
" `id` bigint(20) NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `reason` varchar(2048) NOT NULL," +
|
||||
" `by_uuid` varchar(36) NOT NULL," +
|
||||
" `by_name` varchar(128) NOT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_kick' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_kick' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNameHistoryTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_history", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_history` (" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT," +
|
||||
" `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," +
|
||||
" `name` varchar(16) NOT NULL," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_history' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_history' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkTaskTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_task", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_task` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `task` varchar(2048) NOT NULL," +
|
||||
" `data` varchar(2048) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_task' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_task' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStatTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_stat", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_stat` (" +
|
||||
" `name` varchar(2048) NOT NULL," +
|
||||
" `stat` varchar(2048) NOT NULL," +
|
||||
" UNIQUE KEY `name` (`name`) USING HASH" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_stat' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_stat' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doesStatIncludeEntry(String entry) {
|
||||
try (Connection connection = createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
return dsl.fetchExists(dsl.selectFrom(STAFFOG_STAT)
|
||||
.where(STAFFOG_STAT.NAME.eq(entry)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setStatEntry(String entry, String stat) {
|
||||
try (Connection connection = createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (!doesStatIncludeEntry(entry)) {
|
||||
dsl.insertInto(STAFFOG_STAT)
|
||||
.set(STAFFOG_STAT.NAME, entry)
|
||||
.set(STAFFOG_STAT.STAT, stat)
|
||||
.execute();
|
||||
} else {
|
||||
dsl.update(STAFFOG_STAT)
|
||||
.set(STAFFOG_STAT.STAT, stat)
|
||||
.where(STAFFOG_STAT.NAME.eq(entry))
|
||||
.execute();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkWebTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_web", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_web` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `username` varchar(128) NOT NULL," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `password` varchar(2048) NOT NULL," +
|
||||
" `active` bit(1) NOT NULL DEFAULT b'1'," +
|
||||
" `admin` bit(1) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)," +
|
||||
" UNIQUE KEY `username` (`username`,`uuid`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_web' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_web' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkLinkCodeTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_linkcode", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_linkcode` (" +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `code` varchar(5) NOT NULL," +
|
||||
" `admin` bit(1) NOT NULL," +
|
||||
" UNIQUE KEY `uuid` (`uuid`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_linkcode' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_linkcode' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStaffIpTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_staffip", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_staffip` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `ip` varchar(15) NOT NULL," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `initial` bit(1) NOT NULL," +
|
||||
" `panel_acknowledged` bit(1) NOT NULL," +
|
||||
" `panel_verified` bit(1) NOT NULL," +
|
||||
" `game_verified` bit(1) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_staffip' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_staffip' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAuditTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_audit", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_audit` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `type` varchar(2048) NOT NULL," +
|
||||
" `data` varchar(2048) NOT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_audit' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_audit' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAppealTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_appeal", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_appeal` (" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `time` bigint NOT NULL," +
|
||||
" `type` varchar(128) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `pid` int NOT NULL," +
|
||||
" `reason` varchar(2048) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `evidence` varchar(2048) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '[]'," +
|
||||
" `open` bit(1) NOT NULL DEFAULT b'1'," +
|
||||
" `assigned` varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" `verdict` bit(1) DEFAULT NULL," +
|
||||
" `verdict_time` bigint DEFAULT NULL," +
|
||||
" `comment` varchar(2048) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_appeal' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_appeal' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkReportTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_report", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_report` (" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `by_uuid` varchar(36) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `time` bigint NOT NULL," +
|
||||
" `type` varchar(128) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `reason` varchar(2048) COLLATE utf8mb4_general_ci NOT NULL," +
|
||||
" `evidence` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '[]'," +
|
||||
" `crid` int DEFAULT NULL," +
|
||||
" `open` bit(1) NOT NULL DEFAULT b'1'," +
|
||||
" `assigned` varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" `verdict` bit(1) DEFAULT NULL," +
|
||||
" `verdict_time` bigint DEFAULT NULL," +
|
||||
" `comment` varchar(2048) COLLATE utf8mb4_general_ci DEFAULT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_report' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_report' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkChatReportTable() {
|
||||
try (Connection connection = createConnection()) {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, "staffog_chatreport", new String[] {"TABLE"});
|
||||
|
||||
if (resultSet.next()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Table does not exist
|
||||
Statement statement = connection.createStatement();
|
||||
|
||||
String sql = "CREATE TABLE `staffog_chatreport` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `by_uuid` varchar(36) NOT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" `messages` varchar(2048) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
|
||||
|
||||
statement.executeUpdate(sql);
|
||||
Console.info("Created 'staffog_chatreport' table, was missing.");
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check 'staffog_chatreport' table.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package uk.hotten.staffog.punish;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import uk.hotten.staffog.punish.data.ChatReportEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
@@ -16,46 +18,74 @@ import uk.hotten.staffog.utils.TimeUtils;
|
||||
|
||||
public class PunishEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
PunishManager.getInstance().checkNameToUuid(event.getPlayer().getName(), event.getPlayer().getUniqueId());
|
||||
}
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncPreJoin(AsyncPlayerPreLoginEvent event) {
|
||||
PunishEntry entry = PunishManager.getInstance().checkActivePunishment(PunishType.BAN, event.getUniqueId());
|
||||
PunishManager.getInstance().checkNameToUuid(event.getPlayer().getName(), event.getPlayer().getUniqueId());
|
||||
|
||||
if (entry == null)
|
||||
return;
|
||||
}
|
||||
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
|
||||
event.setKickMessage(ChatColor.RED + "You have been banned for: \n" +
|
||||
ChatColor.WHITE + entry.getReason() + "\n\n" +
|
||||
ChatColor.RED + "Your ban " + (entry.getUntil() == -1 ? "does not expire." : "will expire in:\n"
|
||||
+ ChatColor.WHITE + TimeUtils.formatMillisecondTime(entry.calculateRemaining())));
|
||||
}
|
||||
@EventHandler
|
||||
public void onAsyncPreJoin(AsyncPlayerPreLoginEvent event) {
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncChat(AsyncPlayerChatEvent event) {
|
||||
PunishEntry entry = PunishManager.getInstance().checkActivePunishment(PunishType.MUTE, event.getPlayer().getUniqueId());
|
||||
PunishEntry entry = PunishManager.getInstance().checkActivePunishment(PunishType.BAN, event.getUniqueId());
|
||||
|
||||
if (entry == null)
|
||||
return;
|
||||
if (entry == null)
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(Message.format(ChatColor.RED + "You have been muted for " + ChatColor.WHITE + entry.getReason()));
|
||||
event.getPlayer().sendMessage(Message.format(ChatColor.RED + "Your mute " + (entry.getUntil() == -1 ? "does not expire." : "will expire in: "
|
||||
+ ChatColor.WHITE + TimeUtils.formatMillisecondTime(entry.calculateRemaining()))));
|
||||
}
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST )
|
||||
public void onAsyncChatReport(AsyncPlayerChatEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
String messageString = "&cYou have been banned for: \n" +
|
||||
"&f" + entry.getReason() + "\n\n" +
|
||||
"&c" + "Your ban " + (entry.getUntil() == -1 ? "does not expire." : "will expire in:\n"
|
||||
+ "&f" + TimeUtils.formatMillisecondTime(entry.calculateRemaining()));
|
||||
|
||||
PunishManager pm = PunishManager.getInstance();
|
||||
ChatReportEntry entry = new ChatReportEntry(event.getPlayer().getUniqueId(), event.getPlayer().getName(), event.getMessage(), System.currentTimeMillis());
|
||||
pm.getChatReportEntries().add(entry);
|
||||
Bukkit.getServer().getScheduler().runTaskLater(pm.getPlugin(), () -> pm.getChatReportEntries().remove(entry), 2400); // remove 2m later
|
||||
}
|
||||
}
|
||||
// Create a MiniMessage instance.
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
// Deserialize the string into a TextComponent.å
|
||||
Component kickMessage = miniMessage.deserialize(messageString);
|
||||
|
||||
event.kickMessage(kickMessage);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncChat(AsyncChatEvent event) {
|
||||
|
||||
PunishEntry entry = PunishManager.getInstance().checkActivePunishment(PunishType.MUTE, event.getPlayer().getUniqueId());
|
||||
|
||||
if (entry != null) {
|
||||
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage(Message.format("&c" + "You have been muted for " + "&6" + entry.getReason()));
|
||||
event.getPlayer().sendMessage(Message.format("&c" + "Your mute " + (entry.getUntil() == -1 ? "does not expire." : "will expire in: " + "&f" + TimeUtils.formatMillisecondTime(entry.calculateRemaining()))));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST )
|
||||
public void onAsyncChatReport(AsyncChatEvent event) {
|
||||
|
||||
if (event.isCancelled()) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
String eventMessage = MiniMessage.miniMessage().serialize(event.message());
|
||||
|
||||
PunishManager pm = PunishManager.getInstance();
|
||||
ChatReportEntry entry = new ChatReportEntry(event.getPlayer().getUniqueId(), event.getPlayer().getName(), eventMessage, System.currentTimeMillis());
|
||||
|
||||
pm.getChatReportEntries().add(entry);
|
||||
Bukkit.getServer().getScheduler().runTaskLater(pm.getPlugin(), () -> pm.getChatReportEntries().remove(entry), 2400); // remove 2m later
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,25 @@
|
||||
package uk.hotten.staffog.punish;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import static uk.hotten.staffog.data.jooq.Tables.STAFFOG_BAN;
|
||||
import static uk.hotten.staffog.data.jooq.Tables.STAFFOG_CHATREPORT;
|
||||
import static uk.hotten.staffog.data.jooq.Tables.STAFFOG_HISTORY;
|
||||
import static uk.hotten.staffog.data.jooq.Tables.STAFFOG_KICK;
|
||||
import static uk.hotten.staffog.data.jooq.Tables.STAFFOG_MUTE;
|
||||
import static uk.hotten.staffog.data.jooq.Tables.STAFFOG_REPORT;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import uk.hotten.staffog.data.DatabaseManager;
|
||||
import uk.hotten.staffog.data.jooq.tables.records.StaffogBanRecord;
|
||||
import uk.hotten.staffog.data.jooq.tables.records.StaffogChatreportRecord;
|
||||
@@ -21,427 +34,473 @@ import uk.hotten.staffog.utils.Console;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
import uk.hotten.staffog.utils.TimeUtils;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import static uk.hotten.staffog.data.jooq.Tables.*;
|
||||
|
||||
public class PunishManager {
|
||||
|
||||
@Getter private JavaPlugin plugin;
|
||||
@Getter private static PunishManager instance;
|
||||
|
||||
@Getter private ArrayList<ChatReportEntry> chatReportEntries;
|
||||
|
||||
|
||||
public PunishManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
instance = this;
|
||||
chatReportEntries = new ArrayList<>();
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new PunishEventListener(), plugin);
|
||||
}
|
||||
|
||||
public void checkNameToUuid(String name, UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
|
||||
boolean exists = dsl.fetchExists(dsl.select(STAFFOG_HISTORY.ID)
|
||||
.from(STAFFOG_HISTORY)
|
||||
.where(STAFFOG_HISTORY.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_HISTORY.NAME.eq(name)));
|
||||
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
dsl.insertInto(STAFFOG_HISTORY)
|
||||
.set(STAFFOG_HISTORY.UUID, uuid.toString())
|
||||
.set(STAFFOG_HISTORY.NAME, name)
|
||||
.execute();
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to check username to uuid.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getNameFromUUID(UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
|
||||
return dsl.select(STAFFOG_HISTORY.NAME)
|
||||
.from(STAFFOG_HISTORY)
|
||||
.where(STAFFOG_HISTORY.UUID.eq(uuid.toString()))
|
||||
.orderBy(STAFFOG_HISTORY.ID.desc())
|
||||
.limit(1)
|
||||
.fetchOne(STAFFOG_HISTORY.NAME);
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get name from uuid. " + uuid.toString());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUUIDFromName(String name) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
String uuidString = dsl.select(STAFFOG_HISTORY.UUID)
|
||||
.from(STAFFOG_HISTORY)
|
||||
.where(STAFFOG_HISTORY.NAME.eq(name))
|
||||
.orderBy(STAFFOG_HISTORY.ID.desc())
|
||||
.limit(1)
|
||||
.fetchOne(STAFFOG_HISTORY.UUID);
|
||||
|
||||
if (uuidString == null)
|
||||
return null;
|
||||
|
||||
return UUID.fromString(uuidString);
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get name from name. " + name);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void newPunishment(PunishEntry entry) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (entry.getType() == PunishType.BAN) {
|
||||
dsl.insertInto(STAFFOG_BAN)
|
||||
.set(STAFFOG_BAN.UUID, entry.getUuid().toString())
|
||||
.set(STAFFOG_BAN.REASON, entry.getReason())
|
||||
.set(STAFFOG_BAN.BY_UUID, entry.getByUuid())
|
||||
.set(STAFFOG_BAN.BY_NAME, entry.getByName())
|
||||
.set(STAFFOG_BAN.TIME, entry.getTime())
|
||||
.set(STAFFOG_BAN.UNTIL, entry.getUntil())
|
||||
.set(STAFFOG_BAN.ACTIVE, entry.isActive())
|
||||
.execute();
|
||||
} else {
|
||||
dsl.insertInto(STAFFOG_MUTE)
|
||||
.set(STAFFOG_MUTE.UUID, entry.getUuid().toString())
|
||||
.set(STAFFOG_MUTE.REASON, entry.getReason())
|
||||
.set(STAFFOG_MUTE.BY_UUID, entry.getByUuid())
|
||||
.set(STAFFOG_MUTE.BY_NAME, entry.getByName())
|
||||
.set(STAFFOG_MUTE.TIME, entry.getTime())
|
||||
.set(STAFFOG_MUTE.UNTIL, entry.getUntil())
|
||||
.set(STAFFOG_MUTE.ACTIVE, entry.isActive())
|
||||
.execute();
|
||||
}
|
||||
|
||||
String duration = TimeUtils.formatMillisecondTime(entry.calculateDuration());
|
||||
if (entry.getPlayer() != null && entry.getPlayer().isOnline()) {
|
||||
switch (entry.getType()) {
|
||||
case BAN -> {
|
||||
entry.getPlayer().kickPlayer(ChatColor.RED + "You have been banned for:\n" +
|
||||
ChatColor.WHITE + entry.getReason() + "\n\n" +
|
||||
ChatColor.RED + "Your ban " + (entry.getUntil() == -1 ? "does not expire." : "will expire in: \n"
|
||||
+ ChatColor.WHITE + duration));
|
||||
}
|
||||
case MUTE -> {
|
||||
entry.getPlayer().sendMessage(Message.format(ChatColor.RED + "You have been muted for " + ChatColor.WHITE + entry.getReason()));
|
||||
entry.getPlayer().sendMessage(Message.format(ChatColor.RED + "Your mute " + (entry.getUntil() == -1 ? "does not expire." : "will expire in: \n"
|
||||
+ ChatColor.WHITE + duration)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getServer().broadcastMessage(Message.formatNotification(
|
||||
entry.getType().toString(),
|
||||
"New " + entry.getType().toString().toLowerCase()
|
||||
+ " on " + entry.getName() + " for "
|
||||
+ duration + " by " + entry.getByName()));
|
||||
|
||||
SecurityManager.getInstance().checkAndDeactivateStaffAccount(entry.getUuid());
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to create punishment.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public PunishEntry getPunishment(PunishType type, int id) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
PunishEntry entry = new PunishEntry(type);
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (type == PunishType.BAN) {
|
||||
StaffogBanRecord record = dsl.select(STAFFOG_BAN.asterisk())
|
||||
.from(STAFFOG_BAN)
|
||||
.where(STAFFOG_BAN.ID.eq((long) id))
|
||||
.fetchOneInto(STAFFOG_BAN);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
if (!entry.isActive()) {
|
||||
entry.setRemovedUuid(record.getRemovedUuid());
|
||||
entry.setRemovedName(record.getRemovedName());
|
||||
entry.setRemovedTime(record.getRemovedTime());
|
||||
entry.setRemovedReason(record.getRemovedReason());
|
||||
}
|
||||
} else {
|
||||
StaffogMuteRecord record = dsl.select(STAFFOG_MUTE.asterisk())
|
||||
.from(STAFFOG_MUTE)
|
||||
.where(STAFFOG_MUTE.ID.eq((long) id))
|
||||
.fetchOneInto(STAFFOG_MUTE);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
if (!entry.isActive()) {
|
||||
entry.setRemovedUuid(record.getRemovedUuid());
|
||||
entry.setRemovedName(record.getRemovedName());
|
||||
entry.setRemovedTime(record.getRemovedTime());
|
||||
entry.setRemovedReason(record.getRemovedReason());
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.checkDurationOver()) {
|
||||
expirePunishment(entry);
|
||||
return null;
|
||||
}
|
||||
|
||||
return entry;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get punishment info for id " + id);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public PunishEntry checkActivePunishment(PunishType type, UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
PunishEntry entry = new PunishEntry(type);
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (type == PunishType.BAN) {
|
||||
StaffogBanRecord record = dsl.select(STAFFOG_BAN.asterisk())
|
||||
.from(STAFFOG_BAN)
|
||||
.where(STAFFOG_BAN.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_BAN.ACTIVE.eq(true))
|
||||
.fetchOneInto(STAFFOG_BAN);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
} else {
|
||||
StaffogMuteRecord record = dsl.select(STAFFOG_MUTE.asterisk())
|
||||
.from(STAFFOG_MUTE)
|
||||
.where(STAFFOG_MUTE.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_MUTE.ACTIVE.eq(true))
|
||||
.fetchOneInto(STAFFOG_MUTE);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
}
|
||||
|
||||
if (entry.checkDurationOver()) {
|
||||
expirePunishment(entry);
|
||||
return null;
|
||||
}
|
||||
|
||||
return entry;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get punishment info for " + uuid);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void expirePunishment(PunishEntry entry) {
|
||||
entry.setRemovedUuid("Expired");
|
||||
entry.setRemovedName("Expired");
|
||||
entry.setRemovedReason("Punishment Expired");
|
||||
entry.setActive(false);
|
||||
removePunishment(entry);
|
||||
}
|
||||
|
||||
public void removePunishment(PunishEntry entry) {
|
||||
entry.setActive(false);
|
||||
entry.setRemovedTime(System.currentTimeMillis());
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
if (entry.getName() == null)
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (entry.getType() == PunishType.BAN) {
|
||||
dsl.update(STAFFOG_BAN)
|
||||
.set(STAFFOG_BAN.REMOVED_UUID, entry.getRemovedUuid())
|
||||
.set(STAFFOG_BAN.REMOVED_NAME, entry.getRemovedName())
|
||||
.set(STAFFOG_BAN.REMOVED_REASON, entry.getRemovedReason())
|
||||
.set(STAFFOG_BAN.REMOVED_TIME, entry.getRemovedTime())
|
||||
.set(STAFFOG_BAN.ACTIVE, false)
|
||||
.where(STAFFOG_BAN.ID.eq(entry.getId()))
|
||||
.execute();
|
||||
} else {
|
||||
dsl.update(STAFFOG_MUTE)
|
||||
.set(STAFFOG_MUTE.REMOVED_UUID, entry.getRemovedUuid())
|
||||
.set(STAFFOG_MUTE.REMOVED_NAME, entry.getRemovedName())
|
||||
.set(STAFFOG_MUTE.REMOVED_REASON, entry.getRemovedReason())
|
||||
.set(STAFFOG_MUTE.REMOVED_TIME, entry.getRemovedTime())
|
||||
.set(STAFFOG_MUTE.ACTIVE, false)
|
||||
.where(STAFFOG_MUTE.ID.eq(entry.getId()))
|
||||
.execute();
|
||||
}
|
||||
|
||||
if (entry.getType() == PunishType.MUTE && Bukkit.getServer().getPlayer(entry.getUuid()) != null) {
|
||||
Bukkit.getServer().getPlayer(entry.getUuid()).sendMessage(Message.format(ChatColor.GREEN + "You have been unmuted."));
|
||||
}
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification("UN" + entry.getType(), entry.getName() + " has been un" + entry.getType().getBroadcastMessage() + " by " + entry.getRemovedName()));
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to remove punishment.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void visualRemovePunishment(PunishEntry entry) {
|
||||
if (entry.getType() == PunishType.MUTE && Bukkit.getServer().getPlayer(entry.getUuid()) != null) {
|
||||
Bukkit.getServer().getPlayer(entry.getUuid()).sendMessage(Message.format(ChatColor.GREEN + "You have been unmuted."));
|
||||
}
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification("UN" + entry.getType(), entry.getName() + " has been un" + entry.getType().getBroadcastMessage() + " by " + entry.getRemovedName()));
|
||||
}
|
||||
|
||||
public void newKickPunishment(KickPunishEntry entry) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.insertInto(STAFFOG_KICK)
|
||||
.set(STAFFOG_KICK.UUID, entry.getUuid().toString())
|
||||
.set(STAFFOG_KICK.REASON, entry.getReason())
|
||||
.set(STAFFOG_KICK.BY_UUID, entry.getByUuid())
|
||||
.set(STAFFOG_KICK.BY_NAME, entry.getByName())
|
||||
.set(STAFFOG_KICK.TIME, entry.getTime())
|
||||
.execute();
|
||||
|
||||
if (entry.getPlayer() != null && entry.getPlayer().isOnline()) {
|
||||
entry.getPlayer().kickPlayer(ChatColor.RED + "You have been kicked for:\n" +
|
||||
ChatColor.WHITE + entry.getReason() + "\n\n" +
|
||||
ChatColor.RED + "Please read our rules when you rejoin by running /rules");
|
||||
}
|
||||
|
||||
Bukkit.getServer().broadcastMessage(Message.formatNotification(
|
||||
"KICK", entry.getName() + " has been kicked by " + entry.getByName()));
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to create kick punishment.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIncludedInCurrentChatReport(String name) {
|
||||
for (ChatReportEntry entry : chatReportEntries) {
|
||||
if (name.equalsIgnoreCase(entry.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public UUID getUUIDFromChatReport(String name) {
|
||||
for (ChatReportEntry entry : chatReportEntries) {
|
||||
if (name.equalsIgnoreCase(entry.getName())) {
|
||||
return entry.getUuid();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String exportChatReport(UUID by, UUID reported) {
|
||||
Gson gson = new Gson();
|
||||
String data = gson.toJson(chatReportEntries);
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogChatreportRecord record = dsl.insertInto(STAFFOG_CHATREPORT)
|
||||
.set(STAFFOG_CHATREPORT.UUID, reported.toString())
|
||||
.set(STAFFOG_CHATREPORT.BY_UUID, by.toString())
|
||||
.set(STAFFOG_CHATREPORT.TIME, System.currentTimeMillis())
|
||||
.set(STAFFOG_CHATREPORT.MESSAGES, data)
|
||||
.returning(STAFFOG_CHATREPORT.ID)
|
||||
.fetchOne();
|
||||
|
||||
return "" + record.getId();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String createReportFromCR(UUID by, UUID reported, int crid, String reason) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogReportRecord record = dsl.insertInto(STAFFOG_REPORT)
|
||||
.set(STAFFOG_REPORT.UUID, reported.toString())
|
||||
.set(STAFFOG_REPORT.BY_UUID, by.toString())
|
||||
.set(STAFFOG_REPORT.TIME, System.currentTimeMillis())
|
||||
.set(STAFFOG_REPORT.TYPE, "CHAT")
|
||||
.set(STAFFOG_REPORT.REASON, reason)
|
||||
.set(STAFFOG_REPORT.CRID, crid)
|
||||
.returning(STAFFOG_REPORT.ID)
|
||||
.fetchOne();
|
||||
|
||||
return "" + record.getId();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private JavaPlugin plugin;
|
||||
|
||||
public JavaPlugin getPlugin() {
|
||||
|
||||
return plugin;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<ChatReportEntry> getChatReportEntries() {
|
||||
|
||||
return chatReportEntries;
|
||||
|
||||
}
|
||||
|
||||
private static PunishManager instance;
|
||||
|
||||
public static PunishManager getInstance() {
|
||||
|
||||
return instance;
|
||||
|
||||
}
|
||||
|
||||
private ArrayList<ChatReportEntry> chatReportEntries;
|
||||
|
||||
public PunishManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
instance = this;
|
||||
chatReportEntries = new ArrayList<>();
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new PunishEventListener(), plugin);
|
||||
}
|
||||
|
||||
public void checkNameToUuid(String name, UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
|
||||
boolean exists = dsl.fetchExists(dsl.select(STAFFOG_HISTORY.ID)
|
||||
.from(STAFFOG_HISTORY)
|
||||
.where(STAFFOG_HISTORY.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_HISTORY.NAME.eq(name)));
|
||||
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
dsl.insertInto(STAFFOG_HISTORY)
|
||||
.set(STAFFOG_HISTORY.UUID, uuid.toString())
|
||||
.set(STAFFOG_HISTORY.NAME, name)
|
||||
.execute();
|
||||
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
Console.error("Failed to check username to uuid.");
|
||||
error.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getNameFromUUID(UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
|
||||
return dsl.select(STAFFOG_HISTORY.NAME)
|
||||
.from(STAFFOG_HISTORY)
|
||||
.where(STAFFOG_HISTORY.UUID.eq(uuid.toString()))
|
||||
.orderBy(STAFFOG_HISTORY.ID.desc())
|
||||
.limit(1)
|
||||
.fetchOne(STAFFOG_HISTORY.NAME);
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get name from uuid. " + uuid.toString());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUUIDFromName(String name) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
String uuidString = dsl.select(STAFFOG_HISTORY.UUID)
|
||||
.from(STAFFOG_HISTORY)
|
||||
.where(STAFFOG_HISTORY.NAME.eq(name))
|
||||
.orderBy(STAFFOG_HISTORY.ID.desc())
|
||||
.limit(1)
|
||||
.fetchOne(STAFFOG_HISTORY.UUID);
|
||||
|
||||
if (uuidString == null)
|
||||
return null;
|
||||
|
||||
return UUID.fromString(uuidString);
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get name from name. " + name);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void newPunishment(PunishEntry entry) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (entry.getType() == PunishType.BAN) {
|
||||
dsl.insertInto(STAFFOG_BAN)
|
||||
.set(STAFFOG_BAN.UUID, entry.getUuid().toString())
|
||||
.set(STAFFOG_BAN.REASON, entry.getReason())
|
||||
.set(STAFFOG_BAN.BY_UUID, entry.getByUuid())
|
||||
.set(STAFFOG_BAN.BY_NAME, entry.getByName())
|
||||
.set(STAFFOG_BAN.TIME, entry.getTime())
|
||||
.set(STAFFOG_BAN.UNTIL, entry.getUntil())
|
||||
.set(STAFFOG_BAN.ACTIVE, entry.isActive())
|
||||
.execute();
|
||||
} else {
|
||||
dsl.insertInto(STAFFOG_MUTE)
|
||||
.set(STAFFOG_MUTE.UUID, entry.getUuid().toString())
|
||||
.set(STAFFOG_MUTE.REASON, entry.getReason())
|
||||
.set(STAFFOG_MUTE.BY_UUID, entry.getByUuid())
|
||||
.set(STAFFOG_MUTE.BY_NAME, entry.getByName())
|
||||
.set(STAFFOG_MUTE.TIME, entry.getTime())
|
||||
.set(STAFFOG_MUTE.UNTIL, entry.getUntil())
|
||||
.set(STAFFOG_MUTE.ACTIVE, entry.isActive())
|
||||
.execute();
|
||||
}
|
||||
|
||||
String duration = TimeUtils.formatMillisecondTime(entry.calculateDuration());
|
||||
if (entry.getPlayer() != null && entry.getPlayer().isOnline()) {
|
||||
switch (entry.getType()) {
|
||||
case BAN -> {
|
||||
|
||||
String messageString = ("&c" + "You have been banned for:\n" +
|
||||
"&f" + entry.getReason() + "\n\n" +
|
||||
"&c" + "Your ban " + (entry.getUntil() == -1 ? "does not expire." : "will expire in: \n"
|
||||
+ "&f" + duration));
|
||||
|
||||
// Create a MiniMessage instance.
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
// Deserialize the string into a TextComponent.å
|
||||
Component kickMessage = miniMessage.deserialize(messageString);
|
||||
|
||||
entry.getPlayer().kick(kickMessage);
|
||||
|
||||
}
|
||||
case MUTE -> {
|
||||
entry.getPlayer().sendMessage(Message.format("&cYou have been muted for &f" + entry.getReason()));
|
||||
entry.getPlayer().sendMessage(Message.format("&cYour mute " + (entry.getUntil() == -1 ? "does not expire." : "will expire in: \n"
|
||||
+ "&f" + duration)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification(
|
||||
entry.getType().toString(),
|
||||
"New " + entry.getType().toString().toLowerCase()
|
||||
+ " on " + entry.getName() + " for "
|
||||
+ duration + " by " + entry.getByName()));
|
||||
|
||||
SecurityManager.getInstance().checkAndDeactivateStaffAccount(entry.getUuid());
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to create punishment.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public PunishEntry getPunishment(PunishType type, int id) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
PunishEntry entry = new PunishEntry(type);
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (type == PunishType.BAN) {
|
||||
StaffogBanRecord record = dsl.select(STAFFOG_BAN.asterisk())
|
||||
.from(STAFFOG_BAN)
|
||||
.where(STAFFOG_BAN.ID.eq((long) id))
|
||||
.fetchOneInto(STAFFOG_BAN);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
if (! entry.isActive()) {
|
||||
entry.setRemovedUuid(record.getRemovedUuid());
|
||||
entry.setRemovedName(record.getRemovedName());
|
||||
entry.setRemovedTime(record.getRemovedTime());
|
||||
entry.setRemovedReason(record.getRemovedReason());
|
||||
}
|
||||
} else {
|
||||
StaffogMuteRecord record = dsl.select(STAFFOG_MUTE.asterisk())
|
||||
.from(STAFFOG_MUTE)
|
||||
.where(STAFFOG_MUTE.ID.eq((long) id))
|
||||
.fetchOneInto(STAFFOG_MUTE);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
if (!entry.isActive()) {
|
||||
entry.setRemovedUuid(record.getRemovedUuid());
|
||||
entry.setRemovedName(record.getRemovedName());
|
||||
entry.setRemovedTime(record.getRemovedTime());
|
||||
entry.setRemovedReason(record.getRemovedReason());
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.checkDurationOver()) {
|
||||
expirePunishment(entry);
|
||||
return null;
|
||||
}
|
||||
|
||||
return entry;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get punishment info for id " + id);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public PunishEntry checkActivePunishment(PunishType type, UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
PunishEntry entry = new PunishEntry(type);
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (type == PunishType.BAN) {
|
||||
StaffogBanRecord record = dsl.select(STAFFOG_BAN.asterisk())
|
||||
.from(STAFFOG_BAN)
|
||||
.where(STAFFOG_BAN.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_BAN.ACTIVE.eq(true))
|
||||
.fetchOneInto(STAFFOG_BAN);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
} else {
|
||||
StaffogMuteRecord record = dsl.select(STAFFOG_MUTE.asterisk())
|
||||
.from(STAFFOG_MUTE)
|
||||
.where(STAFFOG_MUTE.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_MUTE.ACTIVE.eq(true))
|
||||
.fetchOneInto(STAFFOG_MUTE);
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
|
||||
entry.setId(record.getId());
|
||||
entry.setUuid(UUID.fromString(record.getUuid()));
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
entry.setReason(record.getReason());
|
||||
entry.setByUuid(record.getByUuid());
|
||||
entry.setByName(record.getByName());
|
||||
entry.setTime(record.getTime());
|
||||
entry.setUntil(record.getUntil());
|
||||
entry.setActive(record.getActive());
|
||||
}
|
||||
|
||||
if (entry.checkDurationOver()) {
|
||||
expirePunishment(entry);
|
||||
return null;
|
||||
}
|
||||
|
||||
return entry;
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to get punishment info for " + uuid);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void expirePunishment(PunishEntry entry) {
|
||||
entry.setRemovedUuid("Expired");
|
||||
entry.setRemovedName("Expired");
|
||||
entry.setRemovedReason("Punishment Expired");
|
||||
entry.setActive(false);
|
||||
removePunishment(entry);
|
||||
}
|
||||
|
||||
public void removePunishment(PunishEntry entry) {
|
||||
entry.setActive(false);
|
||||
entry.setRemovedTime(System.currentTimeMillis());
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
if (entry.getName() == null)
|
||||
entry.setName(getNameFromUUID(entry.getUuid()));
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
if (entry.getType() == PunishType.BAN) {
|
||||
dsl.update(STAFFOG_BAN)
|
||||
.set(STAFFOG_BAN.REMOVED_UUID, entry.getRemovedUuid())
|
||||
.set(STAFFOG_BAN.REMOVED_NAME, entry.getRemovedName())
|
||||
.set(STAFFOG_BAN.REMOVED_REASON, entry.getRemovedReason())
|
||||
.set(STAFFOG_BAN.REMOVED_TIME, entry.getRemovedTime())
|
||||
.set(STAFFOG_BAN.ACTIVE, false)
|
||||
.where(STAFFOG_BAN.ID.eq(entry.getId()))
|
||||
.execute();
|
||||
} else {
|
||||
dsl.update(STAFFOG_MUTE)
|
||||
.set(STAFFOG_MUTE.REMOVED_UUID, entry.getRemovedUuid())
|
||||
.set(STAFFOG_MUTE.REMOVED_NAME, entry.getRemovedName())
|
||||
.set(STAFFOG_MUTE.REMOVED_REASON, entry.getRemovedReason())
|
||||
.set(STAFFOG_MUTE.REMOVED_TIME, entry.getRemovedTime())
|
||||
.set(STAFFOG_MUTE.ACTIVE, false)
|
||||
.where(STAFFOG_MUTE.ID.eq(entry.getId()))
|
||||
.execute();
|
||||
}
|
||||
|
||||
if (entry.getType() == PunishType.MUTE && Bukkit.getServer().getPlayer(entry.getUuid()) != null) {
|
||||
|
||||
Bukkit.getServer().getPlayer(entry.getUuid()).sendMessage(Message.format("&aYou have been unmuted."));
|
||||
|
||||
}
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification("UN" + entry.getType(), entry.getName() + " has been un" + entry.getType().getBroadcastMessage() + " by " + entry.getRemovedName()));
|
||||
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
Console.error("Failed to remove punishment.");
|
||||
error.printStackTrace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void visualRemovePunishment(PunishEntry entry) {
|
||||
|
||||
if (entry.getType() == PunishType.MUTE && Bukkit.getServer().getPlayer(entry.getUuid()) != null) {
|
||||
|
||||
Bukkit.getServer().getPlayer(entry.getUuid()).sendMessage(Message.format("&aYou have been unmuted."));
|
||||
|
||||
}
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification("UN" + entry.getType(), entry.getName() + " has been un" + entry.getType().getBroadcastMessage() + " by " + entry.getRemovedName()));
|
||||
|
||||
}
|
||||
|
||||
public void newKickPunishment(KickPunishEntry entry) {
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.insertInto(STAFFOG_KICK)
|
||||
.set(STAFFOG_KICK.UUID, entry.getUuid().toString())
|
||||
.set(STAFFOG_KICK.REASON, entry.getReason())
|
||||
.set(STAFFOG_KICK.BY_UUID, entry.getByUuid())
|
||||
.set(STAFFOG_KICK.BY_NAME, entry.getByName())
|
||||
.set(STAFFOG_KICK.TIME, entry.getTime())
|
||||
.execute();
|
||||
|
||||
if (entry.getPlayer() != null && entry.getPlayer().isOnline()) {
|
||||
|
||||
String messageString = "&cYou have been kicked for:\n" +
|
||||
"&f" + entry.getReason() + "\n\n" +
|
||||
"&c" + "Please read our rules when you rejoin by running /rules";
|
||||
|
||||
// Create a MiniMessage instance.
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
// Deserialize the string into a TextComponent.å
|
||||
Component kickMessage = miniMessage.deserialize(messageString);
|
||||
|
||||
entry.getPlayer().kick(kickMessage);
|
||||
|
||||
}
|
||||
|
||||
Message.staffBroadcast(Message.formatNotification("KICK", entry.getName() + " has been kicked by " + entry.getByName()));
|
||||
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
Console.error("Failed to create kick punishment.");
|
||||
error.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isIncludedInCurrentChatReport(String name) {
|
||||
for (ChatReportEntry entry : chatReportEntries) {
|
||||
if (name.equalsIgnoreCase(entry.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public UUID getUUIDFromChatReport(String name) {
|
||||
for (ChatReportEntry entry : chatReportEntries) {
|
||||
if (name.equalsIgnoreCase(entry.getName())) {
|
||||
return entry.getUuid();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String exportChatReport(UUID by, UUID reported) {
|
||||
Gson gson = new Gson();
|
||||
String data = gson.toJson(chatReportEntries);
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogChatreportRecord record = dsl.insertInto(STAFFOG_CHATREPORT)
|
||||
.set(STAFFOG_CHATREPORT.UUID, reported.toString())
|
||||
.set(STAFFOG_CHATREPORT.BY_UUID, by.toString())
|
||||
.set(STAFFOG_CHATREPORT.TIME, System.currentTimeMillis())
|
||||
.set(STAFFOG_CHATREPORT.MESSAGES, data)
|
||||
.returning(STAFFOG_CHATREPORT.ID)
|
||||
.fetchOne();
|
||||
|
||||
return "" + record.getId();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String createReportFromCR(UUID by, UUID reported, int crid, String reason) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogReportRecord record = dsl.insertInto(STAFFOG_REPORT)
|
||||
.set(STAFFOG_REPORT.UUID, reported.toString())
|
||||
.set(STAFFOG_REPORT.BY_UUID, by.toString())
|
||||
.set(STAFFOG_REPORT.TIME, System.currentTimeMillis())
|
||||
.set(STAFFOG_REPORT.TYPE, "CHAT")
|
||||
.set(STAFFOG_REPORT.REASON, reason)
|
||||
.set(STAFFOG_REPORT.CRID, crid)
|
||||
.returning(STAFFOG_REPORT.ID)
|
||||
.fetchOne();
|
||||
|
||||
return "" + record.getId();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,15 @@ import java.util.UUID;
|
||||
|
||||
public class ChatReportEntry {
|
||||
|
||||
@Getter private UUID uuid;
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Getter private UUID uuid;
|
||||
@Getter private String name;
|
||||
@Getter private String message;
|
||||
@Getter private long time;
|
||||
@@ -20,4 +28,4 @@ public class ChatReportEntry {
|
||||
|
||||
public ChatReportEntry() { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,64 @@ import java.util.UUID;
|
||||
|
||||
public class KickPunishEntry {
|
||||
|
||||
@Getter @Setter private Player player;
|
||||
@Getter @Setter private String name;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Getter @Setter private Player player;
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public String getByUuid() {
|
||||
return byUuid;
|
||||
}
|
||||
|
||||
public String getByName() {
|
||||
return byName;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setByUuid(String byUuid) {
|
||||
this.byUuid = byUuid;
|
||||
}
|
||||
|
||||
public void setByName(String byName) {
|
||||
this.byName = byName;
|
||||
}
|
||||
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Getter @Setter private String name;
|
||||
|
||||
// Data stored in DB
|
||||
@Getter @Setter private int id;
|
||||
|
||||
@@ -9,7 +9,91 @@ import java.util.*;
|
||||
|
||||
public class PunishEntry {
|
||||
|
||||
// None DB data
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public PunishType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getRemovedUuid() {
|
||||
return removedUuid;
|
||||
}
|
||||
|
||||
public String getRemovedName() {
|
||||
return removedName;
|
||||
}
|
||||
|
||||
public String getRemovedReason() {
|
||||
return removedReason;
|
||||
}
|
||||
|
||||
public long getRemovedTime() {
|
||||
return removedTime;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setRemovedTime(long removedTime) {
|
||||
this.removedTime = removedTime;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public String getByUuid() {
|
||||
return byUuid;
|
||||
}
|
||||
|
||||
public String getByName() {
|
||||
return byName;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public long getUntil() {
|
||||
return until;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void setRemovedUuid(String removedUuid) {
|
||||
this.removedUuid = removedUuid;
|
||||
}
|
||||
|
||||
public void setRemovedName(String removedName) {
|
||||
this.removedName = removedName;
|
||||
}
|
||||
|
||||
public void setRemovedReason(String removedReason) {
|
||||
this.removedReason = removedReason;
|
||||
}
|
||||
|
||||
// None DB data
|
||||
@Getter @Setter private PunishType type;
|
||||
@Getter @Setter private Player player;
|
||||
@Getter @Setter private String name;
|
||||
@@ -23,7 +107,39 @@ public class PunishEntry {
|
||||
@Getter @Setter private String byName;
|
||||
|
||||
@Getter @Setter private String removedUuid;
|
||||
@Getter @Setter private String removedName;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public void setByUuid(String byUuid) {
|
||||
this.byUuid = byUuid;
|
||||
}
|
||||
|
||||
public void setByName(String byName) {
|
||||
this.byName = byName;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public void setUntil(long until) {
|
||||
this.until = until;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Getter @Setter private String removedName;
|
||||
@Getter @Setter private String removedReason;
|
||||
@Getter @Setter private long removedTime;
|
||||
|
||||
|
||||
@@ -4,15 +4,23 @@ import lombok.Getter;
|
||||
|
||||
public enum PunishType {
|
||||
|
||||
BAN("staffog_ban", "banned"),
|
||||
MUTE("staffog_mute", "muted");
|
||||
BAN("staffog_ban", "banned"),
|
||||
MUTE("staffog_mute", "muted");
|
||||
|
||||
@Getter private String table;
|
||||
@Getter private String broadcastMessage;
|
||||
public String getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
private PunishType(String table, String broadcastMessage) {
|
||||
this.table = table;
|
||||
this.broadcastMessage = broadcastMessage;
|
||||
}
|
||||
public String getBroadcastMessage() {
|
||||
return broadcastMessage;
|
||||
}
|
||||
|
||||
@Getter private String table;
|
||||
@Getter private String broadcastMessage;
|
||||
|
||||
private PunishType(String table, String broadcastMessage) {
|
||||
this.table = table;
|
||||
this.broadcastMessage = broadcastMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,61 +1,84 @@
|
||||
package uk.hotten.staffog.security;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import uk.hotten.staffog.StaffOGPlugin;
|
||||
import uk.hotten.staffog.security.data.StaffIPInfo;
|
||||
import uk.hotten.staffog.utils.Console;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class SecurityEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPreJoin(AsyncPlayerPreLoginEvent event) {
|
||||
SecurityManager sm = SecurityManager.getInstance();
|
||||
UUID uuid = event.getUniqueId();
|
||||
@EventHandler
|
||||
public void onPreJoin(AsyncPlayerPreLoginEvent event) {
|
||||
|
||||
if (!StaffOGPlugin.getVaultPerms().playerHas("world", Bukkit.getOfflinePlayer(uuid), "staffog.panelaccess")) {
|
||||
return;
|
||||
}
|
||||
SecurityManager sm = SecurityManager.getInstance();
|
||||
UUID uuid = event.getUniqueId();
|
||||
|
||||
String ip = event.getAddress().getHostAddress();
|
||||
if (! StaffOGPlugin.getVaultPerms().playerHas("world", Bukkit.getOfflinePlayer(uuid), "staffog.panelaccess")) {
|
||||
|
||||
if (!sm.hasUUIDGotIp(event.getUniqueId())) {
|
||||
StaffIPInfo ipInfo = new StaffIPInfo(-1, uuid, ip, true, false, false, true);
|
||||
sm.createIpEntry(ipInfo);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
StaffIPInfo ipInfo = sm.isIpRecognised(event.getUniqueId(), event.getAddress().getHostAddress());
|
||||
if (ipInfo == null) {
|
||||
ipInfo = new StaffIPInfo(-1, uuid, ip, false, false, false, true);
|
||||
sm.createIpEntry(ipInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ipInfo.isPanelAcknowledged() && !ipInfo.isInitial()) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(ChatColor.RED + "New IP address detected!\n" +
|
||||
ChatColor.WHITE + "Please login to the staff panel to authenticate your new IP address.\n\n" +
|
||||
ChatColor.RED + "If you are using a VPN, please disconnect it and try again.");
|
||||
return;
|
||||
}
|
||||
String ip = event.getAddress().getHostAddress();
|
||||
|
||||
if (!ipInfo.isGameVerified()) {
|
||||
ipInfo.setGameVerified(true);
|
||||
sm.updateIpEntry(ipInfo);
|
||||
}
|
||||
if (! sm.hasUUIDGotIp(event.getUniqueId())) {
|
||||
|
||||
sm.getStaffIPInfos().put(uuid, ipInfo);
|
||||
}
|
||||
StaffIPInfo ipInfo = new StaffIPInfo(-1, uuid, ip, true, false, false, true);
|
||||
sm.createIpEntry(ipInfo);
|
||||
return;
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
SecurityManager.getInstance().getStaffIPInfos().remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
StaffIPInfo ipInfo = sm.isIpRecognised(event.getUniqueId(), event.getAddress().getHostAddress());
|
||||
if (ipInfo == null) {
|
||||
|
||||
ipInfo = new StaffIPInfo(-1, uuid, ip, false, false, false, true);
|
||||
sm.createIpEntry(ipInfo);
|
||||
|
||||
}
|
||||
|
||||
if (! ipInfo.isPanelAcknowledged() && !ipInfo.isInitial()) {
|
||||
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
|
||||
String messageString = "&cNew IP address detected!\n" +
|
||||
"&6Please login to the staff panel to authenticate your new IP address.\n\n" +
|
||||
"&cIf you are using a VPN, please disconnect it and try again.";
|
||||
|
||||
// Create a MiniMessage instance.
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
// Deserialize the string into a TextComponent.å
|
||||
Component kickMessage = miniMessage.deserialize(messageString);
|
||||
|
||||
event.kickMessage(kickMessage);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (! ipInfo.isGameVerified()) {
|
||||
|
||||
ipInfo.setGameVerified(true);
|
||||
sm.updateIpEntry(ipInfo);
|
||||
|
||||
}
|
||||
|
||||
sm.getStaffIPInfos().put(uuid, ipInfo);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
|
||||
SecurityManager.getInstance().getStaffIPInfos().remove(event.getPlayer().getUniqueId());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,189 +19,256 @@ import static uk.hotten.staffog.data.jooq.Tables.*;
|
||||
|
||||
public class SecurityManager {
|
||||
|
||||
@Getter private static SecurityManager instance;
|
||||
private JavaPlugin plugin;
|
||||
public HashMap<UUID, StaffIPInfo> getStaffIPInfos() {
|
||||
|
||||
@Getter private HashMap<UUID, StaffIPInfo> staffIPInfos;
|
||||
return staffIPInfos;
|
||||
|
||||
public SecurityManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
instance = this;
|
||||
staffIPInfos = new HashMap<>();
|
||||
}
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new SecurityEventListener(), plugin);
|
||||
}
|
||||
public static SecurityManager getInstance() {
|
||||
|
||||
public StaffIPInfo isIpRecognised(UUID uuid, String ip) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
return instance;
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogStaffipRecord record = dsl.select(STAFFOG_STAFFIP.asterisk())
|
||||
.from(STAFFOG_STAFFIP)
|
||||
.where(STAFFOG_STAFFIP.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_STAFFIP.IP.eq(ip))
|
||||
.fetchOneInto(STAFFOG_STAFFIP);
|
||||
}
|
||||
|
||||
if (record == null)
|
||||
return null;
|
||||
private static SecurityManager instance;
|
||||
private HashMap<UUID, StaffIPInfo> staffIPInfos;
|
||||
|
||||
return new StaffIPInfo(
|
||||
record.getId(),
|
||||
UUID.fromString(record.getUuid()),
|
||||
record.getIp(),
|
||||
record.getInitial(),
|
||||
record.getPanelAcknowledged(),
|
||||
record.getPanelVerified(),
|
||||
record.getGameVerified()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public SecurityManager(JavaPlugin plugin) {
|
||||
|
||||
public boolean hasUUIDGotIp(UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
instance = this;
|
||||
staffIPInfos = new HashMap<>();
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
return dsl.fetchExists(dsl.selectFrom(STAFFOG_STAFFIP)
|
||||
.where(STAFFOG_STAFFIP.UUID.eq(uuid.toString())));
|
||||
plugin.getServer().getPluginManager().registerEvents(new SecurityEventListener(), plugin);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createIpEntry(StaffIPInfo info) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
public StaffIPInfo isIpRecognised(UUID uuid, String ip) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.insertInto(STAFFOG_STAFFIP)
|
||||
.set(STAFFOG_STAFFIP.IP, info.getIp())
|
||||
.set(STAFFOG_STAFFIP.UUID, info.getUuid().toString())
|
||||
.set(STAFFOG_STAFFIP.INITIAL, info.isInitial())
|
||||
.set(STAFFOG_STAFFIP.PANEL_ACKNOWLEDGED, info.isPanelAcknowledged())
|
||||
.set(STAFFOG_STAFFIP.PANEL_VERIFIED, info.isPanelVerified())
|
||||
.set(STAFFOG_STAFFIP.GAME_VERIFIED, info.isGameVerified())
|
||||
.execute();
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to create ip entry.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogStaffipRecord record = dsl.select(STAFFOG_STAFFIP.asterisk())
|
||||
.from(STAFFOG_STAFFIP)
|
||||
.where(STAFFOG_STAFFIP.UUID.eq(uuid.toString()))
|
||||
.and(STAFFOG_STAFFIP.IP.eq(ip))
|
||||
.fetchOneInto(STAFFOG_STAFFIP);
|
||||
|
||||
public void updateIpEntry(StaffIPInfo info) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
if (record == null) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.update(STAFFOG_STAFFIP)
|
||||
.set(STAFFOG_STAFFIP.IP, info.getIp())
|
||||
.set(STAFFOG_STAFFIP.UUID, info.getUuid().toString())
|
||||
.set(STAFFOG_STAFFIP.INITIAL, info.isInitial())
|
||||
.set(STAFFOG_STAFFIP.PANEL_ACKNOWLEDGED, info.isPanelAcknowledged())
|
||||
.set(STAFFOG_STAFFIP.PANEL_VERIFIED, info.isPanelVerified())
|
||||
.set(STAFFOG_STAFFIP.GAME_VERIFIED, info.isGameVerified())
|
||||
.where(STAFFOG_STAFFIP.ID.eq(info.getId()))
|
||||
.execute();
|
||||
return null;
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to update ip entry.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doesLinkCodeExist(String code) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
return new StaffIPInfo(
|
||||
record.getId(),
|
||||
UUID.fromString(record.getUuid()),
|
||||
record.getIp(),
|
||||
record.getInitial(),
|
||||
record.getPanelAcknowledged(),
|
||||
record.getPanelVerified(),
|
||||
record.getGameVerified()
|
||||
);
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
return dsl.fetchExists(dsl.selectFrom(STAFFOG_LINKCODE)
|
||||
.where(STAFFOG_LINKCODE.CODE.eq(code)));
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String doesPlayerHaveLinkCode(UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
}
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogLinkcodeRecord record = dsl.select(STAFFOG_LINKCODE.asterisk())
|
||||
.from(STAFFOG_LINKCODE)
|
||||
.where(STAFFOG_LINKCODE.UUID.eq(uuid.toString()))
|
||||
.fetchOneInto(STAFFOG_LINKCODE);
|
||||
public boolean hasUUIDGotIp(UUID uuid) {
|
||||
|
||||
if (record == null) {
|
||||
return null;
|
||||
}
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
return record.getCode();
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
return dsl.fetchExists(dsl.selectFrom(STAFFOG_STAFFIP)
|
||||
.where(STAFFOG_STAFFIP.UUID.eq(uuid.toString())));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
public String createLinkCode(UUID uuid, boolean admin) {
|
||||
String code = "";
|
||||
String possibleChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
+ "0123456789"
|
||||
+ "abcdefghijklmnopqrstuvxyz";
|
||||
error.printStackTrace();
|
||||
return false;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (code.equals("")) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int index = (int)(possibleChars.length() * Math.random());
|
||||
}
|
||||
|
||||
// add Character one by one in end of sb
|
||||
sb.append(possibleChars.charAt(index));
|
||||
}
|
||||
}
|
||||
|
||||
if (!doesLinkCodeExist(sb.toString()))
|
||||
code = sb.toString();
|
||||
}
|
||||
public void createIpEntry(StaffIPInfo info) {
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.insertInto(STAFFOG_LINKCODE)
|
||||
.set(STAFFOG_LINKCODE.UUID, uuid.toString())
|
||||
.set(STAFFOG_LINKCODE.CODE, code)
|
||||
.set(STAFFOG_LINKCODE.ADMIN, admin)
|
||||
.execute();
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.insertInto(STAFFOG_STAFFIP)
|
||||
.set(STAFFOG_STAFFIP.IP, info.getIp())
|
||||
.set(STAFFOG_STAFFIP.UUID, info.getUuid().toString())
|
||||
.set(STAFFOG_STAFFIP.INITIAL, info.isInitial())
|
||||
.set(STAFFOG_STAFFIP.PANEL_ACKNOWLEDGED, info.isPanelAcknowledged())
|
||||
.set(STAFFOG_STAFFIP.PANEL_VERIFIED, info.isPanelVerified())
|
||||
.set(STAFFOG_STAFFIP.GAME_VERIFIED, info.isGameVerified())
|
||||
.execute();
|
||||
|
||||
} catch (Exception e) {
|
||||
Console.error("Failed to create link code.");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
return code;
|
||||
}
|
||||
Console.error("Failed to create ip entry.");
|
||||
error.printStackTrace();
|
||||
|
||||
public void checkAndDeactivateStaffAccount(UUID uuid) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
}
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
}
|
||||
|
||||
StaffogWebRecord record = dsl.select(STAFFOG_WEB.asterisk())
|
||||
.from(STAFFOG_WEB)
|
||||
.where(STAFFOG_WEB.UUID.eq(uuid.toString()))
|
||||
.fetchOneInto(STAFFOG_WEB);
|
||||
public void updateIpEntry(StaffIPInfo info) {
|
||||
|
||||
if (record == null)
|
||||
return;
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
dsl.update(STAFFOG_WEB)
|
||||
.set(STAFFOG_WEB.ACTIVE, false)
|
||||
.where(STAFFOG_WEB.UUID.eq(uuid.toString()))
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.update(STAFFOG_STAFFIP)
|
||||
.set(STAFFOG_STAFFIP.IP, info.getIp())
|
||||
.set(STAFFOG_STAFFIP.UUID, info.getUuid().toString())
|
||||
.set(STAFFOG_STAFFIP.INITIAL, info.isInitial())
|
||||
.set(STAFFOG_STAFFIP.PANEL_ACKNOWLEDGED, info.isPanelAcknowledged())
|
||||
.set(STAFFOG_STAFFIP.PANEL_VERIFIED, info.isPanelVerified())
|
||||
.set(STAFFOG_STAFFIP.GAME_VERIFIED, info.isGameVerified())
|
||||
.where(STAFFOG_STAFFIP.ID.eq(info.getId()))
|
||||
.execute();
|
||||
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
Console.error("Failed to update ip entry.");
|
||||
error.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean doesLinkCodeExist(String code) {
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
return dsl.fetchExists(dsl.selectFrom(STAFFOG_LINKCODE)
|
||||
.where(STAFFOG_LINKCODE.CODE.eq(code)));
|
||||
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
error.printStackTrace();
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String doesPlayerHaveLinkCode(UUID uuid) {
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
StaffogLinkcodeRecord record = dsl.select(STAFFOG_LINKCODE.asterisk())
|
||||
.from(STAFFOG_LINKCODE)
|
||||
.where(STAFFOG_LINKCODE.UUID.eq(uuid.toString()))
|
||||
.fetchOneInto(STAFFOG_LINKCODE);
|
||||
|
||||
if (record == null) {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
return record.getCode();
|
||||
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String createLinkCode(UUID uuid, boolean admin) {
|
||||
|
||||
String code = "";
|
||||
String possibleChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
+ "0123456789"
|
||||
+ "abcdefghijklmnopqrstuvxyz";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
while (code.equals("")) {
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
int index = (int)(possibleChars.length() * Math.random());
|
||||
|
||||
// add Character one by one in end of sb
|
||||
sb.append(possibleChars.charAt(index));
|
||||
|
||||
}
|
||||
|
||||
if (! doesLinkCodeExist(sb.toString())) {
|
||||
|
||||
code = sb.toString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.insertInto(STAFFOG_LINKCODE)
|
||||
.set(STAFFOG_LINKCODE.UUID, uuid.toString())
|
||||
.set(STAFFOG_LINKCODE.CODE, code)
|
||||
.set(STAFFOG_LINKCODE.ADMIN, admin)
|
||||
.execute();
|
||||
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
Console.error("Failed to create link code.");
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
public void checkAndDeactivateStaffAccount(UUID uuid) {
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
|
||||
StaffogWebRecord record = dsl.select(STAFFOG_WEB.asterisk())
|
||||
.from(STAFFOG_WEB)
|
||||
.where(STAFFOG_WEB.UUID.eq(uuid.toString()))
|
||||
.fetchOneInto(STAFFOG_WEB);
|
||||
|
||||
if (record == null) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
dsl.update(STAFFOG_WEB)
|
||||
.set(STAFFOG_WEB.ACTIVE, false)
|
||||
.where(STAFFOG_WEB.UUID.eq(uuid.toString()))
|
||||
.execute();
|
||||
}
|
||||
catch (Exception error) {
|
||||
|
||||
error.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,31 +7,65 @@ import java.util.UUID;
|
||||
|
||||
public class StaffIPInfo {
|
||||
|
||||
@Getter private int id;
|
||||
@Getter private UUID uuid;
|
||||
@Getter private String ip;
|
||||
@Getter @Setter private boolean initial;
|
||||
@Getter @Setter private boolean panelAcknowledged;
|
||||
@Getter @Setter private boolean panelVerified;
|
||||
@Getter @Setter private boolean gameVerified;
|
||||
public void setGameVerified(boolean gameVerified) {
|
||||
this.gameVerified = gameVerified;
|
||||
}
|
||||
|
||||
public StaffIPInfo(int id, UUID uuid, String ip, boolean initial, boolean panelAcknowledged, boolean panelVerified, boolean gameVerified) {
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
this.ip = ip;
|
||||
this.initial = initial;
|
||||
this.panelAcknowledged = panelAcknowledged;
|
||||
this.panelVerified = panelVerified;
|
||||
this.gameVerified = gameVerified;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public StaffIPInfo(int id, UUID uuid, String ip) {
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
this.ip = ip;
|
||||
this.initial = false;
|
||||
this.panelVerified = false;
|
||||
this.gameVerified = false;
|
||||
}
|
||||
public boolean isPanelVerified() {
|
||||
|
||||
return panelVerified;
|
||||
|
||||
}
|
||||
|
||||
@Getter private int id;
|
||||
@Getter private UUID uuid;
|
||||
@Getter private String ip;
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public boolean isInitial() {
|
||||
return initial;
|
||||
}
|
||||
|
||||
public boolean isPanelAcknowledged() {
|
||||
return panelAcknowledged;
|
||||
}
|
||||
|
||||
public boolean isGameVerified() {
|
||||
return gameVerified;
|
||||
}
|
||||
|
||||
@Getter @Setter private boolean initial;
|
||||
@Getter @Setter private boolean panelAcknowledged;
|
||||
@Getter @Setter private boolean panelVerified;
|
||||
@Getter @Setter private boolean gameVerified;
|
||||
|
||||
public StaffIPInfo(int id, UUID uuid, String ip, boolean initial, boolean panelAcknowledged, boolean panelVerified, boolean gameVerified) {
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
this.ip = ip;
|
||||
this.initial = initial;
|
||||
this.panelAcknowledged = panelAcknowledged;
|
||||
this.panelVerified = panelVerified;
|
||||
this.gameVerified = gameVerified;
|
||||
}
|
||||
|
||||
public StaffIPInfo(int id, UUID uuid, String ip) {
|
||||
this.id = id;
|
||||
this.uuid = uuid;
|
||||
this.ip = ip;
|
||||
this.initial = false;
|
||||
this.panelVerified = false;
|
||||
this.gameVerified = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,93 +22,100 @@ import java.util.ArrayList;
|
||||
|
||||
public class TaskManager {
|
||||
|
||||
@Getter private JavaPlugin plugin;
|
||||
@Getter private JavaPlugin plugin;
|
||||
|
||||
public TaskManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
public TaskManager(JavaPlugin plugin) {
|
||||
|
||||
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
|
||||
for (TaskEntry entry : checkForTasks()) {
|
||||
switch (entry.getTask()) {
|
||||
case "unpunish": {
|
||||
processUnpunish(entry);
|
||||
deleteTask(entry.getId());
|
||||
break;
|
||||
}
|
||||
case "newreport": {
|
||||
processNewReport(entry);
|
||||
deleteTask(entry.getId());
|
||||
}
|
||||
case "newappeal": {
|
||||
processNewAppeal(entry);
|
||||
deleteTask(entry.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 0, 200);
|
||||
}
|
||||
this.plugin = plugin;
|
||||
|
||||
private ArrayList<TaskEntry> checkForTasks() {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()){
|
||||
ArrayList<TaskEntry> toReturn = new ArrayList<>();
|
||||
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
|
||||
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
Result<StaffogTaskRecord> result = dsl.select(Tables.STAFFOG_TASK.asterisk())
|
||||
.from(Tables.STAFFOG_TASK)
|
||||
.fetchInto(Tables.STAFFOG_TASK);
|
||||
for (TaskEntry entry : checkForTasks()) {
|
||||
|
||||
for (StaffogTaskRecord record : result) {
|
||||
TaskEntry entry = new TaskEntry();
|
||||
entry.setId(record.getId());
|
||||
entry.setTask(record.getTask());
|
||||
entry.setData(record.getData());
|
||||
toReturn.add(entry);
|
||||
}
|
||||
switch (entry.getTask()) {
|
||||
case "unpunish": {
|
||||
processUnpunish(entry);
|
||||
deleteTask(entry.getId());
|
||||
break;
|
||||
}
|
||||
case "newreport": {
|
||||
processNewReport(entry);
|
||||
deleteTask(entry.getId());
|
||||
}
|
||||
case "newappeal": {
|
||||
processNewAppeal(entry);
|
||||
deleteTask(entry.getId());
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processUnpunish(TaskEntry entry) {
|
||||
if (!entry.getTask().equals("unpunish"))
|
||||
return;
|
||||
}, 0, 200);
|
||||
|
||||
Gson gson = new Gson();
|
||||
UnpunishTask task = gson.fromJson(entry.getData(), UnpunishTask.class);
|
||||
PunishEntry punishEntry = PunishManager.getInstance().getPunishment(task.getType(), task.getId());
|
||||
PunishManager.getInstance().visualRemovePunishment(punishEntry);
|
||||
}
|
||||
}
|
||||
|
||||
private void processNewReport(TaskEntry entry) {
|
||||
if (!entry.getTask().equals("newreport"))
|
||||
return;
|
||||
private ArrayList<TaskEntry> checkForTasks() {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()){
|
||||
ArrayList<TaskEntry> toReturn = new ArrayList<>();
|
||||
|
||||
Gson gson = new Gson();
|
||||
NewReportTask task = gson.fromJson(entry.getData(), NewReportTask.class);
|
||||
Message.staffBroadcast(Message.formatNotification("REPORT", "New " + task.getType() + " report #" + task.getId() + " by " + task.getBy() + " against " + task.getOffender()));
|
||||
}
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
Result<StaffogTaskRecord> result = dsl.select(Tables.STAFFOG_TASK.asterisk())
|
||||
.from(Tables.STAFFOG_TASK)
|
||||
.fetchInto(Tables.STAFFOG_TASK);
|
||||
|
||||
private void processNewAppeal(TaskEntry entry) {
|
||||
if (!entry.getTask().equals("newappeal"))
|
||||
return;
|
||||
for (StaffogTaskRecord record : result) {
|
||||
TaskEntry entry = new TaskEntry();
|
||||
entry.setId(record.getId());
|
||||
entry.setTask(record.getTask());
|
||||
entry.setData(record.getData());
|
||||
toReturn.add(entry);
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
NewAppealTask task = gson.fromJson(entry.getData(), NewAppealTask.class);
|
||||
Message.staffBroadcast(Message.formatNotification("APPEAL", "New " + task.getType().toLowerCase() + " appeal #" + task.getId() + " by " + task.getBy()));
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
catch (Exception error) {
|
||||
error.printStackTrace();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteTask(int id) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()){
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.delete(Tables.STAFFOG_TASK)
|
||||
.where(Tables.STAFFOG_TASK.ID.eq(id))
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void processUnpunish(TaskEntry entry) {
|
||||
if (! entry.getTask().equals("unpunish"))
|
||||
return;
|
||||
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
UnpunishTask task = gson.fromJson(entry.getData(), UnpunishTask.class);
|
||||
PunishEntry punishEntry = PunishManager.getInstance().getPunishment(task.getType(), task.getId());
|
||||
PunishManager.getInstance().visualRemovePunishment(punishEntry);
|
||||
}
|
||||
|
||||
private void processNewReport(TaskEntry entry) {
|
||||
if (!entry.getTask().equals("newreport"))
|
||||
return;
|
||||
|
||||
Gson gson = new Gson();
|
||||
NewReportTask task = gson.fromJson(entry.getData(), NewReportTask.class);
|
||||
Message.staffBroadcast(Message.formatNotification("REPORT", "New " + task.getType() + " report #" + task.getId() + " by " + task.getBy() + " against " + task.getOffender()));
|
||||
}
|
||||
|
||||
private void processNewAppeal(TaskEntry entry) {
|
||||
if (!entry.getTask().equals("newappeal"))
|
||||
return;
|
||||
|
||||
Gson gson = new Gson();
|
||||
NewAppealTask task = gson.fromJson(entry.getData(), NewAppealTask.class);
|
||||
Message.staffBroadcast(Message.formatNotification("APPEAL", "New " + task.getType().toLowerCase() + " appeal #" + task.getId() + " by " + task.getBy()));
|
||||
}
|
||||
|
||||
private void deleteTask(int id) {
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()){
|
||||
DSLContext dsl = DSL.using(connection);
|
||||
dsl.delete(Tables.STAFFOG_TASK)
|
||||
.where(Tables.STAFFOG_TASK.ID.eq(id))
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,17 @@ import lombok.Setter;
|
||||
|
||||
public class NewAppealTask {
|
||||
|
||||
@Getter @Setter private int id;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public String getBy() {
|
||||
return by;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@Getter @Setter private int id;
|
||||
@Getter @Setter private String by;
|
||||
@Getter @Setter private String type;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,21 @@ import lombok.Setter;
|
||||
|
||||
public class NewReportTask {
|
||||
|
||||
@Getter @Setter private int id;
|
||||
public String getOffender() {
|
||||
return offender;
|
||||
}
|
||||
public String getBy() {
|
||||
return by;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@Getter @Setter private int id;
|
||||
@Getter @Setter private String offender;
|
||||
@Getter @Setter private String by;
|
||||
@Getter @Setter private String type;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,26 @@ import lombok.Setter;
|
||||
|
||||
public class TaskEntry {
|
||||
|
||||
@Getter @Setter private int id;
|
||||
@Getter @Setter private String task;
|
||||
@Getter @Setter private String data;
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
@Getter @Setter private int id;
|
||||
@Getter @Setter private String task;
|
||||
@Getter @Setter private String data;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setTask(String task) {
|
||||
this.task = task;
|
||||
}
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
public String getTask() {
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,25 @@ package uk.hotten.staffog.tasks.data;
|
||||
import lombok.Getter;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UnpunishTask {
|
||||
|
||||
@Getter private PunishType type;
|
||||
@Getter private int id;
|
||||
@Getter private String name;
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public UnpunishTask(String type, int id) {
|
||||
this.type = PunishType.valueOf(type);
|
||||
this.id = id;
|
||||
}
|
||||
public PunishType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public UnpunishTask() { }
|
||||
@Getter private PunishType type;
|
||||
@Getter private int id;
|
||||
@Getter private String name;
|
||||
|
||||
}
|
||||
public UnpunishTask(String type, int id) {
|
||||
|
||||
this.type = PunishType.valueOf(type);
|
||||
this.id = id;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,25 @@
|
||||
package uk.hotten.staffog.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Console {
|
||||
|
||||
public static void info(String message) { Bukkit.getServer().getConsoleSender().sendMessage("" + ChatColor.WHITE + "[Staff-OG] " + message); }
|
||||
public static void info(String message) {
|
||||
|
||||
public static void warn(String message) { Bukkit.getServer().getConsoleSender().sendMessage("" + ChatColor.YELLOW + "[Staff-OG: WARN] " + message); }
|
||||
Bukkit.getServer().getConsoleSender().sendMessage("[Staff-OG] " + message);
|
||||
|
||||
public static void error(String message) { Bukkit.getServer().getConsoleSender().sendMessage("" + ChatColor.RED + "[Staff-OG: ERROR] " + message); }
|
||||
}
|
||||
|
||||
}
|
||||
public static void warn(String message) {
|
||||
|
||||
Bukkit.getServer().getConsoleSender().sendMessage("[Staff-OG: WARNING] " + message);
|
||||
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
|
||||
Bukkit.getServer().getConsoleSender().sendMessage("[Staff-OG: ERROR] " + message);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +1,115 @@
|
||||
package uk.hotten.staffog.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class Message {
|
||||
|
||||
public static String format(String message) {
|
||||
return "" + ChatColor.GRAY + "[" + ChatColor.YELLOW + "Staff-OG" + ChatColor.GRAY + "] " + ChatColor.RESET + message;
|
||||
}
|
||||
public static String format(String message) {
|
||||
|
||||
public static String formatNotification(String prefix, String message) {
|
||||
return "" + ChatColor.RED + prefix.toUpperCase() + " | " + ChatColor.AQUA + "Notification " + ChatColor.DARK_GRAY + "> " + ChatColor.RESET + message;
|
||||
}
|
||||
return "" + "&7" + "[" + "&e" + "Staff-OG" + "&7" + "] " + "&r" + message;
|
||||
|
||||
public static void staffBroadcast(String message) {
|
||||
Bukkit.getServer().getOnlinePlayers().forEach(p -> {
|
||||
if (p.hasPermission("staffog.seebroadcast")) p.sendMessage(message);
|
||||
});
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public static String formatNotification(String prefix, String message) {
|
||||
|
||||
return "" + "&c" + prefix.toUpperCase() + " | " + "&B" + "Notification " + "&8" + "> " + "&r" + message;
|
||||
|
||||
}
|
||||
|
||||
public static void staffBroadcast(String message) {
|
||||
|
||||
Bukkit.getServer().getOnlinePlayers().forEach(p -> {
|
||||
|
||||
if (p.hasPermission("staffog.seebroadcast")) p.sendMessage(message);
|
||||
|
||||
});
|
||||
|
||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||
|
||||
}
|
||||
|
||||
// Sends a formatted message to the player (including name replacement).
|
||||
public static void staffOGMessage(Player p, String message) {
|
||||
|
||||
p.sendMessage(legacySerializerAnyCase(format(message)));
|
||||
|
||||
}
|
||||
|
||||
public static TextComponent legacySerializerAnyCase(String subject) {
|
||||
|
||||
int count = 0;
|
||||
// Count the number of '&' characters to determine the size of the array
|
||||
for (char c : subject.toCharArray()) {
|
||||
|
||||
if (c == '&') {
|
||||
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create an array to store the positions of '&' characters
|
||||
int[] positions = new int[count];
|
||||
int index = 0;
|
||||
// Find the positions of '&' characters and store in the array
|
||||
for (int i = 0; i < subject.length(); i++) {
|
||||
|
||||
if (subject.charAt(i) == '&') {
|
||||
|
||||
if (isUpperBukkitCode(subject.charAt(i + 1))) {
|
||||
|
||||
subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1)));
|
||||
|
||||
}
|
||||
|
||||
positions[index++] = i;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(subject);
|
||||
|
||||
}
|
||||
|
||||
private static boolean isUpperBukkitCode(char input) {
|
||||
|
||||
char[] bukkitColorCodes = {'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R'};
|
||||
boolean match = false;
|
||||
|
||||
// Loop through each character in the array.
|
||||
for (char c : bukkitColorCodes) {
|
||||
// Check if the current character in the array is equal to the input character.
|
||||
if (c == input) {
|
||||
|
||||
match = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return match;
|
||||
|
||||
}
|
||||
|
||||
private static String replaceCharAtIndex(String original, int index, char newChar) {
|
||||
|
||||
// Check if the index is valid
|
||||
if (index >= 0 && index < original.length()) {
|
||||
|
||||
// Create a new string with the replaced character
|
||||
return original.substring(0, index) + newChar + original.substring(index + 1);
|
||||
|
||||
}
|
||||
|
||||
// If the index is invalid, return the original string
|
||||
return original;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
name: Staff-OG
|
||||
main: uk.hotten.staffog.StaffOGPlugin
|
||||
version: 1.0-beta
|
||||
api-version: 1.18
|
||||
version: 1.0-beta-master
|
||||
api-version: 1.19
|
||||
author: Gxorge
|
||||
description: Punishment system for TrueOG.
|
||||
depend: [Vault]
|
||||
|
||||
Reference in new issue
Block a user