mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-04 16:56:40 +00:00
Compare commits
80 Commits
brigadier
...
6b7c076c41
Author | SHA1 | Date | |
---|---|---|---|
6b7c076c41 | |||
7b56bd70e9 | |||
fbd36161d4 | |||
912dff0ec9 | |||
aab5083f78 | |||
adb0d070a4 | |||
e22f079062 | |||
8f713fd30c | |||
72467de5ce | |||
c9d954d1c0 | |||
b168029df1 | |||
f34df4f296 | |||
79206d9354 | |||
7bca348587 | |||
b35bf63ba4 | |||
8c5c058292 | |||
3d70100119 | |||
6a8228947b | |||
187226ff45 | |||
6d80d5f4e3 | |||
d4710f1808 | |||
bee4268d51 | |||
7254097ae4 | |||
20765403f4 | |||
9650685796 | |||
1cf262ff91 | |||
4de796781d | |||
b82747b0bf | |||
029cd40124 | |||
360775bac3 | |||
37ac71b6ee | |||
88f10ef9cc | |||
3608e8e825 | |||
3e9be76aa2 | |||
2364ab33ff | |||
28c57f3a52 | |||
5929fd9ddc | |||
14d859ef75 | |||
bc8c89449e | |||
709ed50748 | |||
cc9967f9c2 | |||
b0c19a14ab | |||
475169b36a | |||
bb019abd89 | |||
a7ed86549d | |||
ba23129b15 | |||
c51d8da5b7 | |||
2a2152603b | |||
2c7440804c | |||
b7db18284a | |||
91e09d982d | |||
15b12e6299 | |||
4b37497a14 | |||
b0a8b463cb | |||
1f48dc1e60 | |||
95c4da338e | |||
cea84884fc | |||
2331cb9f80 | |||
e4f18a24cc | |||
668460f486 | |||
7336cc8feb | |||
bc5d0476ee | |||
7ff6bdb171 | |||
175c7db23d | |||
f97411ce09 | |||
b0240ef46e | |||
4887960463 | |||
295e16b6c5 | |||
72d9e0817c | |||
28ec8e1d2d | |||
9d0e7bf6d6 | |||
96b0c81fed | |||
7dea0bcb72 | |||
8344e3596e | |||
37a649fa7a | |||
d7df923e5c | |||
d54325304e | |||
bc6dbb1052 | |||
ecbd9c02da | |||
77dc95ae29 |
72
build.gradle
72
build.gradle
@ -1,72 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id "java"
|
|
||||||
id "maven-publish"
|
|
||||||
id "com.github.johnrengelman.shadow" version "8.1.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = "dev.plex"
|
|
||||||
version = "1.3-SNAPSHOT"
|
|
||||||
description = "Plex"
|
|
||||||
|
|
||||||
subprojects {
|
|
||||||
apply plugin: "java"
|
|
||||||
apply plugin: "maven-publish"
|
|
||||||
apply plugin: "com.github.johnrengelman.shadow"
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
url = uri("https://repo.papermc.io/repository/maven-public/")
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url = uri("https://repository.apache.org/content/repositories/snapshots/")
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url = uri("https://repo.maven.apache.org/maven2/")
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
|
||||||
url = uri("https://jitpack.io")
|
|
||||||
content {
|
|
||||||
includeGroup("com.github.MilkBowl")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
options.encoding = "UTF-8"
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
maven {
|
|
||||||
def releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
|
|
||||||
def snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
|
|
||||||
url = rootProject.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
|
||||||
credentials {
|
|
||||||
username = System.getenv("plexUser")
|
|
||||||
password = System.getenv("plexPassword")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clean {
|
|
||||||
dependsOn(":server:clean")
|
|
||||||
dependsOn(":proxy:clean")
|
|
||||||
}
|
|
||||||
|
|
||||||
task copyJars(type: Copy, dependsOn: subprojects.jar) {
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
||||||
from(subprojects.jar)
|
|
||||||
from(subprojects.shadowJar)
|
|
||||||
into project.file('build/libs')
|
|
||||||
}
|
|
90
build.gradle.kts
Normal file
90
build.gradle.kts
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
plugins {
|
||||||
|
id("java")
|
||||||
|
id("maven-publish")
|
||||||
|
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
|
||||||
|
id("net.kyori.blossom") version "2.1.0"
|
||||||
|
id("com.github.johnrengelman.shadow") version "8.1.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "dev.plex"
|
||||||
|
version = "1.4-SNAPSHOT"
|
||||||
|
description = "Plex"
|
||||||
|
|
||||||
|
subprojects {
|
||||||
|
apply(plugin = "java")
|
||||||
|
apply(plugin = "maven-publish")
|
||||||
|
apply(plugin = "org.jetbrains.gradle.plugin.idea-ext")
|
||||||
|
apply(plugin = "net.kyori.blossom")
|
||||||
|
apply(plugin = "com.github.johnrengelman.shadow")
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri("https://repository.apache.org/content/repositories/snapshots/")
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri("https://repo.maven.apache.org/maven2/")
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url = uri("https://jitpack.io")
|
||||||
|
content {
|
||||||
|
includeGroup("com.github.MilkBowl")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
compileJava {
|
||||||
|
options.encoding = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
javadoc {
|
||||||
|
options.encoding = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
processResources {
|
||||||
|
filteringCharset = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
val releasesRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-releases/")
|
||||||
|
val snapshotsRepoUrl = uri("https://nexus.telesphoreo.me/repository/plex-snapshots/")
|
||||||
|
url = if (rootProject.version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
|
||||||
|
credentials {
|
||||||
|
username = System.getenv("plexUser")
|
||||||
|
password = System.getenv("plexPassword")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.clean {
|
||||||
|
dependsOn(subprojects.map {
|
||||||
|
it.project.tasks.clean
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.create<Copy>("copyJars") {
|
||||||
|
dependsOn(tasks.jar)
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
from(subprojects.map {
|
||||||
|
it.project.tasks.shadowJar
|
||||||
|
})
|
||||||
|
from(subprojects.map {
|
||||||
|
it.project.tasks.jar
|
||||||
|
})
|
||||||
|
into(file("build/libs"))
|
||||||
|
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
29
gradlew
vendored
29
gradlew
vendored
@ -83,10 +83,8 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && 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"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@ -133,18 +131,21 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@ -152,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
plugins {
|
|
||||||
id("net.kyori.blossom") version "1.3.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = rootProject.group
|
group = rootProject.group
|
||||||
version = rootProject.version
|
version = rootProject.version
|
||||||
description = "Plex-Velocity"
|
description = "Plex-Velocity"
|
||||||
@ -24,8 +20,14 @@ tasks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
blossom {
|
blossom {
|
||||||
replaceToken("@version@", rootProject.version)
|
javaSources {
|
||||||
|
property("version", project.version.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
@ -37,9 +39,9 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.projectlombok:lombok:1.18.28")
|
compileOnly("org.projectlombok:lombok:1.18.30")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.28")
|
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
||||||
compileOnly("org.json:json:20230227")
|
compileOnly("org.json:json:20231013")
|
||||||
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||||
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||||
}
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package dev.plex;
|
||||||
|
|
||||||
|
class BuildParameters {
|
||||||
|
public static final String VERSION = "{{ version }}";
|
||||||
|
}
|
@ -28,7 +28,7 @@ import java.util.logging.Logger;
|
|||||||
@Plugin(
|
@Plugin(
|
||||||
name = "Plex",
|
name = "Plex",
|
||||||
id = "plex",
|
id = "plex",
|
||||||
version = "@version@",
|
version = BuildParameters.VERSION,
|
||||||
url = "https://plex.us.org",
|
url = "https://plex.us.org",
|
||||||
description = "Plex provides a new experience for freedom servers.",
|
description = "Plex provides a new experience for freedom servers.",
|
||||||
authors = {"Telesphoreo", "Taah"}
|
authors = {"Telesphoreo", "Taah"}
|
||||||
|
@ -1,145 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id "net.minecrell.plugin-yml.paper" version "0.6.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
library "org.projectlombok:lombok:1.18.28"
|
|
||||||
annotationProcessor "org.projectlombok:lombok:1.18.28"
|
|
||||||
library "org.json:json:20230618"
|
|
||||||
library "commons-io:commons-io:2.13.0"
|
|
||||||
library "dev.morphia.morphia:morphia-core:2.3.5"
|
|
||||||
library "redis.clients:jedis:5.0.0-beta2"
|
|
||||||
library "org.mariadb.jdbc:mariadb-java-client:3.1.4"
|
|
||||||
library "com.zaxxer:HikariCP:5.0.1"
|
|
||||||
library "org.apache.maven.resolver:maven-resolver-transport-http:1.9.13"
|
|
||||||
compileOnly "io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT"
|
|
||||||
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
|
|
||||||
exclude group: "org.bukkit", module: "bukkit"
|
|
||||||
}
|
|
||||||
implementation "org.bstats:bstats-base:3.0.2"
|
|
||||||
implementation "org.bstats:bstats-bukkit:3.0.2"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = rootProject.group
|
|
||||||
version = rootProject.version
|
|
||||||
description = "Plex-Server"
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
archiveBaseName.set("Plex")
|
|
||||||
archiveClassifier.set("")
|
|
||||||
relocate "org.bstats", "dev.plex"
|
|
||||||
}
|
|
||||||
|
|
||||||
paper {
|
|
||||||
name = "Plex"
|
|
||||||
version = project.version
|
|
||||||
description = "Plex provides a new experience for freedom servers."
|
|
||||||
main = "dev.plex.Plex"
|
|
||||||
loader = "dev.plex.PlexLibraryManager"
|
|
||||||
website = "https://plex.us.org"
|
|
||||||
authors = ["Telesphoreo", "taahanis", "supernt"]
|
|
||||||
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
|
|
||||||
apiVersion = "1.19"
|
|
||||||
generateLibrariesJson = true
|
|
||||||
serverDependencies {
|
|
||||||
'BukkitTelnet' {
|
|
||||||
required = false
|
|
||||||
load = 'BEFORE'
|
|
||||||
}
|
|
||||||
'LibsDisguises' {
|
|
||||||
required = false
|
|
||||||
load = 'BEFORE'
|
|
||||||
}
|
|
||||||
'Vault' {
|
|
||||||
required = false
|
|
||||||
load = 'BEFORE'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String getGitHash() {
|
|
||||||
def stdout = new ByteArrayOutputStream()
|
|
||||||
try {
|
|
||||||
exec {
|
|
||||||
commandLine "git", "rev-parse", "--short", "HEAD"
|
|
||||||
standardOutput = stdout
|
|
||||||
ignoreExitValue = true
|
|
||||||
}
|
|
||||||
} catch (GradleException e) {
|
|
||||||
logger.error("Couldn't determine Git head because Git is not installed. " + e.getMessage())
|
|
||||||
}
|
|
||||||
return stdout.size() > 0 ? stdout.toString().trim() : "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
String getBuildNumber() {
|
|
||||||
def stdout = new ByteArrayOutputStream()
|
|
||||||
try {
|
|
||||||
exec {
|
|
||||||
commandLine "git", "rev-list", "HEAD", "--count"
|
|
||||||
standardOutput = stdout
|
|
||||||
ignoreExitValue = true
|
|
||||||
}
|
|
||||||
} catch (GradleException e) {
|
|
||||||
logger.error("Couldn't determine build number because Git is not installed. " + e.getMessage())
|
|
||||||
}
|
|
||||||
return stdout.size() ? stdout.toString().trim() + " (local)" : "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
static def getDate() {
|
|
||||||
return new Date().format("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z")
|
|
||||||
}
|
|
||||||
|
|
||||||
task buildProperties {
|
|
||||||
ant.propertyfile(file: "$project.projectDir/src/main/resources/build.properties") {
|
|
||||||
entry(key: "buildAuthor", default: System.getenv("JENKINS_URL") != null ? "jenkins" : "unknown")
|
|
||||||
entry(key: "buildNumber", value: System.getenv("JENKINS_URL") != null ? System.getenv("BUILD_NUMBER") + " (Jenkins)" : getBuildNumber())
|
|
||||||
entry(key: "buildDate", value: getDate())
|
|
||||||
entry(key: "buildHead", value: getGitHash())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
build {
|
|
||||||
dependsOn(shadowJar)
|
|
||||||
finalizedBy(buildProperties)
|
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
|
||||||
enabled = false
|
|
||||||
}
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
finalizedBy(rootProject.tasks.copyJars)
|
|
||||||
}
|
|
||||||
|
|
||||||
javadoc {
|
|
||||||
options.memberLevel = JavadocMemberLevel.PRIVATE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
publications {
|
|
||||||
maven(MavenPublication) {
|
|
||||||
pom.withXml {
|
|
||||||
def dependenciesNode = asNode().appendNode("dependencies")
|
|
||||||
configurations.getByName("library").getAllDependencies().each { dependency ->
|
|
||||||
dependenciesNode.appendNode("dependency").with {
|
|
||||||
it.appendNode("groupId", dependency.group)
|
|
||||||
it.appendNode("artifactId", dependency.name)
|
|
||||||
it.appendNode("version", dependency.version)
|
|
||||||
it.appendNode("scope", "provided")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
configurations.getByName("implementation").getAllDependencies().each { dependency ->
|
|
||||||
dependenciesNode.appendNode("dependency").with {
|
|
||||||
it.appendNode("groupId", dependency.group)
|
|
||||||
it.appendNode("artifactId", dependency.name)
|
|
||||||
it.appendNode("version", dependency.version)
|
|
||||||
it.appendNode("scope", "runtime")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
artifacts = [shadowJar]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
158
server/build.gradle.kts
Normal file
158
server/build.gradle.kts
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
import net.minecrell.pluginyml.paper.PaperPluginDescription
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("net.kyori.indra.git") version "3.1.3"
|
||||||
|
id("net.minecrell.plugin-yml.paper") version "0.6.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven(url = uri("https://maven.playpro.com"))
|
||||||
|
maven(url = uri("https://nexus.telesphoreo.me/repository/plex-modules/"))
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
library("org.projectlombok:lombok:1.18.30")
|
||||||
|
library("org.json:json:20231013")
|
||||||
|
library("commons-io:commons-io:2.15.1")
|
||||||
|
library("redis.clients:jedis:5.1.0")
|
||||||
|
library("org.mariadb.jdbc:mariadb-java-client:3.3.1")
|
||||||
|
library("com.zaxxer:HikariCP:5.1.0")
|
||||||
|
library("org.apache.maven.resolver:maven-resolver-transport-http:1.9.18")
|
||||||
|
library("org.jetbrains:annotations:24.1.0")
|
||||||
|
|
||||||
|
compileOnly("dev.folia:folia-api:1.20.2-R0.1-SNAPSHOT")
|
||||||
|
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
|
||||||
|
exclude("org.bukkit", "bukkit")
|
||||||
|
}
|
||||||
|
compileOnly("net.coreprotect:coreprotect:22.2")
|
||||||
|
compileOnly("network.darkhelmet.prism:Prism-Api:1.0.0")
|
||||||
|
|
||||||
|
implementation("org.bstats:bstats-base:3.0.2")
|
||||||
|
implementation("org.bstats:bstats-bukkit:3.0.2")
|
||||||
|
|
||||||
|
annotationProcessor("org.projectlombok:lombok:1.18.30")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = rootProject.group
|
||||||
|
version = rootProject.version
|
||||||
|
description = "Plex-Server"
|
||||||
|
|
||||||
|
paper {
|
||||||
|
name = "Plex"
|
||||||
|
version = rootProject.version.toString()
|
||||||
|
description = "Plex provides a new experience for freedom servers."
|
||||||
|
main = "dev.plex.Plex"
|
||||||
|
loader = "dev.plex.PlexLibraryManager"
|
||||||
|
website = "https://plex.us.org"
|
||||||
|
authors = listOf("Telesphoreo", "taahanis", "supernt")
|
||||||
|
apiVersion = "1.19"
|
||||||
|
foliaSupported = true
|
||||||
|
generateLibrariesJson = true
|
||||||
|
// Load BukkitTelnet and LibsDisguises before Plex so the modules register properly
|
||||||
|
serverDependencies {
|
||||||
|
register("BukkitTelnet") {
|
||||||
|
required = false
|
||||||
|
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
|
||||||
|
}
|
||||||
|
register("Essentials") {
|
||||||
|
required = false
|
||||||
|
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
|
||||||
|
}
|
||||||
|
register("LibsDisguises") {
|
||||||
|
required = false
|
||||||
|
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
|
||||||
|
}
|
||||||
|
register("Prism") {
|
||||||
|
required = false
|
||||||
|
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
|
||||||
|
}
|
||||||
|
register("CoreProtect") {
|
||||||
|
required = false
|
||||||
|
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
|
||||||
|
}
|
||||||
|
register("SlimeWorldManager") {
|
||||||
|
required = false
|
||||||
|
load = PaperPluginDescription.RelativeLoadOrder.AFTER
|
||||||
|
}
|
||||||
|
register("Vault") {
|
||||||
|
required = false
|
||||||
|
load = PaperPluginDescription.RelativeLoadOrder.BEFORE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBuildNumber(): String {
|
||||||
|
val stdout = ByteArrayOutputStream()
|
||||||
|
try {
|
||||||
|
exec {
|
||||||
|
commandLine("git", "rev-list", "HEAD", "--count")
|
||||||
|
standardOutput = stdout
|
||||||
|
isIgnoreExitValue = true
|
||||||
|
}
|
||||||
|
} catch (e: GradleException) {
|
||||||
|
logger.error("Couldn't determine build number because Git is not installed. " + e.message)
|
||||||
|
}
|
||||||
|
return if (stdout.size() > 0) stdout.toString().trim() else "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
build {
|
||||||
|
dependsOn(shadowJar)
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
blossom {
|
||||||
|
resources {
|
||||||
|
property("author", if (System.getenv("JENKINS_URL") != null) "jenkins" else System.getProperty("user.name"))
|
||||||
|
property("buildNumber", if (System.getenv("BUILD_NUMBER") != null) System.getenv("BUILD_NUMBER") else getBuildNumber())
|
||||||
|
property("date", SimpleDateFormat("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z").format(Date()))
|
||||||
|
property("gitCommit", indraGit.commit()?.name?.take(7))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
archiveBaseName.set("Plex")
|
||||||
|
archiveClassifier.set("")
|
||||||
|
relocate("org.bstats", "dev.plex")
|
||||||
|
finalizedBy(rootProject.tasks["copyJars"])
|
||||||
|
}
|
||||||
|
|
||||||
|
javadoc {
|
||||||
|
options.memberLevel = JavadocMemberLevel.PRIVATE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
create<MavenPublication>("maven") {
|
||||||
|
pom.withXml {
|
||||||
|
val dependenciesNode = asNode().appendNode("dependencies")
|
||||||
|
configurations.getByName("library").allDependencies.configureEach {
|
||||||
|
dependenciesNode.appendNode("dependency")
|
||||||
|
.appendNode("groupId", group).parent()
|
||||||
|
.appendNode("artifactId", name).parent()
|
||||||
|
.appendNode("version", version).parent()
|
||||||
|
.appendNode("scope", "provided").parent()
|
||||||
|
}
|
||||||
|
configurations.getByName("implementation").allDependencies.configureEach {
|
||||||
|
dependenciesNode.appendNode("dependency")
|
||||||
|
.appendNode("groupId", group).parent()
|
||||||
|
.appendNode("artifactId", name).parent()
|
||||||
|
.appendNode("version", version).parent()
|
||||||
|
.appendNode("scope", "provided").parent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
artifacts.artifact(tasks.shadowJar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +1,30 @@
|
|||||||
package dev.plex;
|
package dev.plex;
|
||||||
|
|
||||||
import dev.plex.admin.Admin;
|
|
||||||
import dev.plex.admin.AdminList;
|
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.cache.PlayerCache;
|
import dev.plex.cache.PlayerCache;
|
||||||
import dev.plex.config.Config;
|
import dev.plex.config.Config;
|
||||||
import dev.plex.handlers.CommandHandler;
|
import dev.plex.handlers.CommandHandler;
|
||||||
import dev.plex.handlers.ListenerHandler;
|
import dev.plex.handlers.ListenerHandler;
|
||||||
|
import dev.plex.hook.CoreProtectHook;
|
||||||
|
import dev.plex.hook.PrismHook;
|
||||||
import dev.plex.module.ModuleManager;
|
import dev.plex.module.ModuleManager;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.PunishmentManager;
|
import dev.plex.punishment.PunishmentManager;
|
||||||
import dev.plex.rank.RankManager;
|
|
||||||
import dev.plex.services.ServiceManager;
|
import dev.plex.services.ServiceManager;
|
||||||
import dev.plex.storage.MongoConnection;
|
|
||||||
import dev.plex.storage.RedisConnection;
|
import dev.plex.storage.RedisConnection;
|
||||||
import dev.plex.storage.SQLConnection;
|
import dev.plex.storage.SQLConnection;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.StorageType;
|
||||||
import dev.plex.storage.permission.SQLPermissions;
|
|
||||||
import dev.plex.storage.player.MongoPlayerData;
|
|
||||||
import dev.plex.storage.player.SQLPlayerData;
|
import dev.plex.storage.player.SQLPlayerData;
|
||||||
import dev.plex.storage.punishment.SQLNotes;
|
import dev.plex.storage.punishment.SQLNotes;
|
||||||
import dev.plex.storage.punishment.SQLPunishment;
|
import dev.plex.storage.punishment.SQLPunishment;
|
||||||
import dev.plex.util.*;
|
import dev.plex.util.BuildInfo;
|
||||||
|
import dev.plex.util.BungeeUtil;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.UpdateChecker;
|
||||||
import dev.plex.util.redis.MessageUtil;
|
import dev.plex.util.redis.MessageUtil;
|
||||||
import dev.plex.world.CustomWorld;
|
import dev.plex.world.CustomWorld;
|
||||||
|
import java.io.File;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
@ -33,8 +34,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class Plex extends JavaPlugin
|
public class Plex extends JavaPlugin
|
||||||
@ -49,30 +48,25 @@ public class Plex extends JavaPlugin
|
|||||||
public File modulesFolder;
|
public File modulesFolder;
|
||||||
private StorageType storageType = StorageType.SQLITE;
|
private StorageType storageType = StorageType.SQLITE;
|
||||||
private SQLConnection sqlConnection;
|
private SQLConnection sqlConnection;
|
||||||
private MongoConnection mongoConnection;
|
|
||||||
private RedisConnection redisConnection;
|
private RedisConnection redisConnection;
|
||||||
|
|
||||||
private PlayerCache playerCache;
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
private MongoPlayerData mongoPlayerData;
|
|
||||||
private SQLPlayerData sqlPlayerData;
|
private SQLPlayerData sqlPlayerData;
|
||||||
|
|
||||||
private SQLPunishment sqlPunishment;
|
private SQLPunishment sqlPunishment;
|
||||||
private SQLNotes sqlNotes;
|
private SQLNotes sqlNotes;
|
||||||
private SQLPermissions sqlPermissions;
|
|
||||||
|
|
||||||
private ModuleManager moduleManager;
|
private ModuleManager moduleManager;
|
||||||
private RankManager rankManager;
|
|
||||||
private ServiceManager serviceManager;
|
private ServiceManager serviceManager;
|
||||||
private PunishmentManager punishmentManager;
|
private PunishmentManager punishmentManager;
|
||||||
|
|
||||||
private AdminList adminList;
|
|
||||||
private UpdateChecker updateChecker;
|
private UpdateChecker updateChecker;
|
||||||
private String system;
|
|
||||||
|
|
||||||
private Permission permissions;
|
private Permission permissions;
|
||||||
private Chat chat;
|
private Chat chat;
|
||||||
|
|
||||||
|
private CoreProtectHook coreProtectHook;
|
||||||
|
private PrismHook prismHook;
|
||||||
|
|
||||||
public static Plex get()
|
public static Plex get()
|
||||||
{
|
{
|
||||||
return plugin;
|
return plugin;
|
||||||
@ -115,13 +109,11 @@ public class Plex extends JavaPlugin
|
|||||||
commands.load(false);
|
commands.load(false);
|
||||||
|
|
||||||
sqlConnection = new SQLConnection();
|
sqlConnection = new SQLConnection();
|
||||||
mongoConnection = new MongoConnection();
|
// mongoConnection = new MongoConnection();
|
||||||
redisConnection = new RedisConnection();
|
redisConnection = new RedisConnection();
|
||||||
|
|
||||||
playerCache = new PlayerCache();
|
playerCache = new PlayerCache();
|
||||||
|
|
||||||
system = config.getString("system");
|
|
||||||
|
|
||||||
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.db"));
|
PlexLog.log("Attempting to connect to DB: {0}", plugin.config.getString("data.central.db"));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -134,15 +126,31 @@ public class Plex extends JavaPlugin
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (system.equals("permissions"))
|
|
||||||
{
|
|
||||||
if (!getServer().getPluginManager().isPluginEnabled("Vault"))
|
if (!getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
throw new RuntimeException("Vault is required to run on the server alongside a permissions plugin, we recommend LuckPerms!");
|
||||||
}
|
}
|
||||||
|
|
||||||
permissions = setupPermissions();
|
permissions = setupPermissions();
|
||||||
chat = setupChat();
|
chat = setupChat();
|
||||||
|
|
||||||
|
if (plugin.getServer().getPluginManager().isPluginEnabled("CoreProtect"))
|
||||||
|
{
|
||||||
|
PlexLog.log("Hooked into CoreProtect!");
|
||||||
|
coreProtectHook = new CoreProtectHook(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlexLog.debug("Not hooking into CoreProtect");
|
||||||
|
}
|
||||||
|
if (plugin.getServer().getPluginManager().isPluginEnabled("Prism"))
|
||||||
|
{
|
||||||
|
PlexLog.log("Hooked into Prism!");
|
||||||
|
prismHook = new PrismHook(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlexLog.debug("Not hooking into Prism");
|
||||||
}
|
}
|
||||||
|
|
||||||
updateChecker = new UpdateChecker();
|
updateChecker = new UpdateChecker();
|
||||||
@ -164,32 +172,22 @@ public class Plex extends JavaPlugin
|
|||||||
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storageType == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
mongoPlayerData = new MongoPlayerData();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sqlPlayerData = new SQLPlayerData();
|
sqlPlayerData = new SQLPlayerData();
|
||||||
sqlPunishment = new SQLPunishment();
|
sqlPunishment = new SQLPunishment();
|
||||||
sqlNotes = new SQLNotes();
|
sqlNotes = new SQLNotes();
|
||||||
sqlPermissions = new SQLPermissions();
|
|
||||||
}
|
|
||||||
|
|
||||||
new ListenerHandler();
|
new ListenerHandler();
|
||||||
new CommandHandler();
|
new CommandHandler();
|
||||||
|
|
||||||
rankManager = new RankManager();
|
|
||||||
rankManager.generateDefaultRanks();
|
|
||||||
rankManager.importDefaultRanks();
|
|
||||||
adminList = new AdminList();
|
|
||||||
PlexLog.log("Rank Manager initialized");
|
|
||||||
|
|
||||||
punishmentManager = new PunishmentManager();
|
punishmentManager = new PunishmentManager();
|
||||||
punishmentManager.mergeIndefiniteBans();
|
punishmentManager.mergeIndefiniteBans();
|
||||||
PlexLog.log("Punishment System initialized");
|
PlexLog.log("Punishment System initialized");
|
||||||
|
|
||||||
|
if (!PlexUtils.isFolia())
|
||||||
|
{
|
||||||
|
// World generation is not supported on Folia yet
|
||||||
generateWorlds();
|
generateWorlds();
|
||||||
|
}
|
||||||
|
|
||||||
serviceManager = new ServiceManager();
|
serviceManager = new ServiceManager();
|
||||||
PlexLog.log("Service Manager initialized");
|
PlexLog.log("Service Manager initialized");
|
||||||
@ -215,20 +213,7 @@ public class Plex extends JavaPlugin
|
|||||||
Bukkit.getOnlinePlayers().forEach(player ->
|
Bukkit.getOnlinePlayers().forEach(player ->
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = playerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
PlexPlayer plexPlayer = playerCache.getPlexPlayerMap().get(player.getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
||||||
|
|
||||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mongoPlayerData != null) //back to mongo checking
|
|
||||||
{
|
|
||||||
mongoPlayerData.update(plexPlayer); //update the player's document
|
|
||||||
}
|
|
||||||
else if (sqlPlayerData != null) //sql checking
|
|
||||||
{
|
|
||||||
sqlPlayerData.update(plexPlayer);
|
sqlPlayerData.update(plexPlayer);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
|
if (redisConnection != null && redisConnection.isEnabled() && redisConnection.getJedis().isConnected())
|
||||||
{
|
{
|
||||||
@ -257,13 +242,6 @@ public class Plex extends JavaPlugin
|
|||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||||
playerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
playerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
||||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
Admin admin = new Admin(plexPlayer.getUuid());
|
|
||||||
admin.setRank(plexPlayer.getRankFromString());
|
|
||||||
|
|
||||||
plugin.getAdminList().addToCache(admin);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,17 +22,16 @@ public class PlexLibraryManager implements PluginLoader
|
|||||||
@Override
|
@Override
|
||||||
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder)
|
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder)
|
||||||
{
|
{
|
||||||
|
|
||||||
MavenLibraryResolver resolver = new MavenLibraryResolver();
|
MavenLibraryResolver resolver = new MavenLibraryResolver();
|
||||||
PluginLibraries pluginLibraries = load();
|
PluginLibraries pluginLibraries = load();
|
||||||
pluginLibraries.asDependencies().forEach(resolver::addDependency);
|
pluginLibraries.asDependencies().forEach(resolver::addDependency);
|
||||||
pluginLibraries.asRepositories().forEach(resolver::addRepository);
|
pluginLibraries.asRepositories().forEach(resolver::addRepository);
|
||||||
// The plugin is null, a hacky way to check whether to load Jetty or not
|
// The plugin is null, a hacky way to check whether to load Jetty or not
|
||||||
if (new File("plugins/Plex/modules/Plex-HTTPD.jar").isFile())
|
if (new File("plugins/Plex/modules/Module-HTTPD.jar").isFile())
|
||||||
{
|
{
|
||||||
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-server:11.0.15"), null));
|
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-server:11.0.19"), null));
|
||||||
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-servlet:11.0.15"), null));
|
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-servlet:11.0.19"), null));
|
||||||
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-proxy:11.0.15"), null));
|
resolver.addDependency(new Dependency(new DefaultArtifact("org.eclipse.jetty:jetty-proxy:11.0.19"), null));
|
||||||
}
|
}
|
||||||
classpathBuilder.addLibrary(resolver);
|
classpathBuilder.addLibrary(resolver);
|
||||||
}
|
}
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
package dev.plex.admin;
|
|
||||||
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Admin object to handle cached admins
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class Admin
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Gets the unique ID of an admin (immutable)
|
|
||||||
*/
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
private UUID uuid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the rank of the admin
|
|
||||||
* <br>
|
|
||||||
* Contains a #setRank and #getRank by lombok
|
|
||||||
*/
|
|
||||||
private Rank rank;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the admin has command spy or not
|
|
||||||
* <br>
|
|
||||||
* Contains a #isCommandSpy and #setCommandSpy by Lombok
|
|
||||||
*/
|
|
||||||
private boolean commandSpy = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns if the admin has admin chat toggled or not
|
|
||||||
* <br>
|
|
||||||
* Contains a #isAdminChat and #setAdminChat by Lombok
|
|
||||||
*/
|
|
||||||
private boolean adminChat = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an admin with the ADMIN rank as the default rank
|
|
||||||
*
|
|
||||||
* @param uuid
|
|
||||||
* @see UUID
|
|
||||||
* @see Rank
|
|
||||||
*/
|
|
||||||
public Admin(UUID uuid)
|
|
||||||
{
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.rank = Rank.ADMIN;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,151 +0,0 @@
|
|||||||
package dev.plex.admin;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import dev.morphia.Datastore;
|
|
||||||
import dev.morphia.query.Query;
|
|
||||||
import dev.plex.PlexBase;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.storage.StorageType;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cached storage for Admin objects
|
|
||||||
*
|
|
||||||
* @see Admin
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class AdminList implements PlexBase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Key / Value storage, where the key is the unique ID of the admin
|
|
||||||
*/
|
|
||||||
private final Map<UUID, Admin> admins = Maps.newHashMap();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the admin to cache
|
|
||||||
*
|
|
||||||
* @param admin The admin object
|
|
||||||
*/
|
|
||||||
public void addToCache(Admin admin)
|
|
||||||
{
|
|
||||||
admins.put(admin.getUuid(), admin);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an admin from the cache
|
|
||||||
*
|
|
||||||
* @param uuid The unique ID of the admin
|
|
||||||
* @see UUID
|
|
||||||
*/
|
|
||||||
public void removeFromCache(UUID uuid)
|
|
||||||
{
|
|
||||||
admins.remove(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gathers every admins username (cached and in the database)
|
|
||||||
*
|
|
||||||
* @return An array list of the names of every admin
|
|
||||||
*/
|
|
||||||
public List<String> getAllAdmins()
|
|
||||||
{
|
|
||||||
List<String> admins = Lists.newArrayList();
|
|
||||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
|
||||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
|
||||||
admins.addAll(query.stream().filter(plexPlayer -> plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive()).map(PlexPlayer::getName).toList());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
try (Connection con = plugin.getSqlConnection().getCon())
|
|
||||||
{
|
|
||||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
|
|
||||||
statement.setString(1, Rank.ADMIN.name().toLowerCase());
|
|
||||||
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
|
|
||||||
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
|
|
||||||
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
while (set.next())
|
|
||||||
{
|
|
||||||
admins.add(set.getString("name"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
|
||||||
throwables.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return admins;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gathers every admin (cached and in the database)
|
|
||||||
*
|
|
||||||
* @return An array list of the names of every admin
|
|
||||||
*/
|
|
||||||
public List<PlexPlayer> getAllAdminPlayers()
|
|
||||||
{
|
|
||||||
List<PlexPlayer> plexPlayers = Lists.newArrayList();
|
|
||||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
Datastore store = plugin.getMongoConnection().getDatastore();
|
|
||||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
|
||||||
return query.stream().toList().stream().filter(player -> plugin.getRankManager().isAdmin(player)).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
try (Connection con = plugin.getSqlConnection().getCon())
|
|
||||||
{
|
|
||||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?) AND adminActive=true");
|
|
||||||
statement.setString(1, Rank.ADMIN.name().toLowerCase());
|
|
||||||
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
|
|
||||||
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
|
|
||||||
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
while (set.next())
|
|
||||||
{
|
|
||||||
String uuid = set.getString("uuid");
|
|
||||||
String name = set.getString("name");
|
|
||||||
String loginMSG = set.getString("login_msg");
|
|
||||||
String prefix = set.getString("prefix");
|
|
||||||
String rankName = set.getString("rank").toUpperCase();
|
|
||||||
long coins = set.getLong("coins");
|
|
||||||
boolean vanished = set.getBoolean("vanished");
|
|
||||||
boolean commandspy = set.getBoolean("commandspy");
|
|
||||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
|
||||||
{
|
|
||||||
}.getType());
|
|
||||||
|
|
||||||
PlexPlayer plexPlayer = new PlexPlayer(UUID.fromString(uuid));
|
|
||||||
plexPlayer.setName(name);
|
|
||||||
plexPlayer.setLoginMessage(loginMSG);
|
|
||||||
plexPlayer.setPrefix(prefix);
|
|
||||||
plexPlayer.setRank(rankName);
|
|
||||||
plexPlayer.setIps(ips);
|
|
||||||
plexPlayer.setCoins(coins);
|
|
||||||
plexPlayer.setVanished(vanished);
|
|
||||||
plexPlayer.setCommandSpy(commandspy);
|
|
||||||
plexPlayers.add(plexPlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException throwables)
|
|
||||||
{
|
|
||||||
throwables.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return plexPlayers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,28 +19,14 @@ public class DataUtils
|
|||||||
* @return true if the player is registered in the database
|
* @return true if the player is registered in the database
|
||||||
*/
|
*/
|
||||||
public static boolean hasPlayedBefore(UUID uuid)
|
public static boolean hasPlayedBefore(UUID uuid)
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().exists(uuid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return Plex.get().getSqlPlayerData().exists(uuid);
|
return Plex.get().getSqlPlayerData().exists(uuid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasPlayedBefore(String username)
|
public static boolean hasPlayedBefore(String username)
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().exists(username);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return Plex.get().getSqlPlayerData().exists(username);
|
return Plex.get().getSqlPlayerData().exists(username);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a player from cache or from the database
|
* Gets a player from cache or from the database
|
||||||
@ -61,15 +47,8 @@ public class DataUtils
|
|||||||
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
|
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().getByUUID(uuid);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
|
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static PlexPlayer getPlayer(String username)
|
public static PlexPlayer getPlayer(String username)
|
||||||
{
|
{
|
||||||
@ -84,15 +63,8 @@ public class DataUtils
|
|||||||
return plexPlayer.get();
|
return plexPlayer.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().getByName(username);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
|
return Plex.get().getSqlPlayerData().getByName(username, loadExtraData);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a player from cache or from the database
|
* Gets a player from cache or from the database
|
||||||
@ -109,15 +81,8 @@ public class DataUtils
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
return Plex.get().getMongoPlayerData().getByIP(ip);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Plex.get().getSqlPlayerData().getByIP(ip);
|
return Plex.get().getSqlPlayerData().getByIP(ip);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a player's information in the database
|
* Updates a player's information in the database
|
||||||
@ -126,16 +91,9 @@ public class DataUtils
|
|||||||
* @see PlexPlayer
|
* @see PlexPlayer
|
||||||
*/
|
*/
|
||||||
public static void update(PlexPlayer plexPlayer)
|
public static void update(PlexPlayer plexPlayer)
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
Plex.get().getMongoPlayerData().update(plexPlayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Plex.get().getSqlPlayerData().update(plexPlayer);
|
Plex.get().getSqlPlayerData().update(plexPlayer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a player's information in the database
|
* Inserts a player's information in the database
|
||||||
@ -144,17 +102,8 @@ public class DataUtils
|
|||||||
* @see PlexPlayer
|
* @see PlexPlayer
|
||||||
*/
|
*/
|
||||||
public static void insert(PlexPlayer plexPlayer)
|
public static void insert(PlexPlayer plexPlayer)
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
Plex.get().getMongoPlayerData().save(plexPlayer);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.plex.command;
|
package dev.plex.command;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
@ -7,7 +8,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.exception.*;
|
import dev.plex.command.exception.*;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
@ -15,14 +15,15 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,11 +46,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
*/
|
*/
|
||||||
private final CommandPermissions perms;
|
private final CommandPermissions perms;
|
||||||
|
|
||||||
/**
|
|
||||||
* Minimum required rank fetched from the permissions
|
|
||||||
*/
|
|
||||||
private final Rank level;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required command source fetched from the permissions
|
* Required command source fetched from the permissions
|
||||||
*/
|
*/
|
||||||
@ -67,16 +63,27 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
setName(this.params.name());
|
setName(this.params.name());
|
||||||
setLabel(this.params.name());
|
setLabel(this.params.name());
|
||||||
setDescription(params.description());
|
setDescription(params.description());
|
||||||
|
setPermission(this.perms.permission());
|
||||||
setUsage(params.usage().replace("<command>", this.params.name()));
|
setUsage(params.usage().replace("<command>", this.params.name()));
|
||||||
if (params.aliases().split(",").length > 0)
|
if (params.aliases().split(",").length > 0)
|
||||||
{
|
{
|
||||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||||
}
|
}
|
||||||
this.level = perms.level();
|
|
||||||
this.commandSource = perms.source();
|
this.commandSource = perms.source();
|
||||||
|
|
||||||
if (register)
|
if (register)
|
||||||
{
|
{
|
||||||
|
if (getMap().getKnownCommands().containsKey(this.getName().toLowerCase()))
|
||||||
|
{
|
||||||
|
getMap().getKnownCommands().remove(this.getName().toLowerCase());
|
||||||
|
}
|
||||||
|
this.getAliases().forEach(s ->
|
||||||
|
{
|
||||||
|
if (getMap().getKnownCommands().containsKey(s.toLowerCase()))
|
||||||
|
{
|
||||||
|
getMap().getKnownCommands().remove(s.toLowerCase());
|
||||||
|
}
|
||||||
|
});
|
||||||
getMap().register("plex", this);
|
getMap().register("plex", this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,73 +137,23 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
|
||||||
{
|
|
||||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
|
||||||
{
|
|
||||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
|
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
|
||||||
{
|
{
|
||||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
|
||||||
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet
|
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
||||||
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
|
||||||
{
|
|
||||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (getLevel().isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
|
||||||
{
|
|
||||||
send(sender, messageComponent("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMessage())));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission()))
|
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission()))
|
||||||
{
|
{
|
||||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
PlexLog.error("Neither permissions or ranks were selected to be used in the configuration file!");
|
|
||||||
send(sender, "There is a server misconfiguration. Please alert a developer or the owner");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
|
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
|
||||||
@ -213,6 +170,17 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public abstract List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
List<String> list = smartTabComplete(sender, alias, args);
|
||||||
|
return StringUtil.copyPartialMatches(args[args.length - 1], list, Lists.newArrayList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the String given is a matching command
|
* Checks if the String given is a matching command
|
||||||
*
|
*
|
||||||
@ -276,111 +244,31 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
* Checks whether a sender has enough permissions or is high enough a rank
|
* Checks whether a sender has enough permissions or is high enough a rank
|
||||||
*
|
*
|
||||||
* @param sender A CommandSender
|
* @param sender A CommandSender
|
||||||
* @param rank The rank to check (if the server is using ranks)
|
* @param permission The permission to check
|
||||||
* @param permission The permission to check (if the server is using permissions)
|
|
||||||
* @return true if the sender has enough permissions
|
* @return true if the sender has enough permissions
|
||||||
* @see Rank
|
|
||||||
*/
|
*/
|
||||||
protected boolean checkRank(CommandSender sender, Rank rank, String permission)
|
protected boolean checkPermission(CommandSender sender, String permission)
|
||||||
{
|
{
|
||||||
if (!isConsole(sender))
|
if (!isConsole(sender))
|
||||||
{
|
{
|
||||||
return checkRank((Player) sender, rank, permission);
|
return checkPermission((Player) sender, permission);
|
||||||
}
|
|
||||||
if (!sender.getName().equalsIgnoreCase("console"))
|
|
||||||
{
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(sender.getName());
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(rank))
|
|
||||||
{
|
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
|
||||||
}
|
|
||||||
if (rank.isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
|
||||||
{
|
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getOfflinePlayer(plexPlayer.getName()), perms.permission()))
|
|
||||||
{
|
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether a player has enough permissions or is high enough a rank
|
|
||||||
*
|
|
||||||
* @param player The player object
|
|
||||||
* @param rank The rank to check (if the server is using ranks)
|
|
||||||
* @param permission The permission to check (if the server is using permissions)
|
|
||||||
* @return true if the sender has enough permissions
|
|
||||||
* @see Rank
|
|
||||||
*/
|
|
||||||
protected boolean checkRank(Player player, Rank rank, String permission)
|
|
||||||
{
|
|
||||||
if (player instanceof ConsoleCommandSender)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
if (!plexPlayer.getRankFromString().isAtLeast(rank))
|
|
||||||
{
|
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
|
||||||
}
|
|
||||||
if (rank.isAtLeast(Rank.ADMIN) && !plexPlayer.isAdminActive())
|
|
||||||
{
|
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionRank", ChatColor.stripColor(rank.getLoginMessage())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
|
|
||||||
{
|
|
||||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean silentCheckRank(Player player, Rank rank, String permission)
|
|
||||||
{
|
|
||||||
if (player instanceof ConsoleCommandSender)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
return !perms.permission().isEmpty() && player.hasPermission(permission);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a sender has enough permissions or is high enough a rank
|
* Checks whether a sender has enough permissions or is high enough a rank
|
||||||
*
|
*
|
||||||
* @param sender The player object
|
* @param sender A CommandSender
|
||||||
* @param rank The rank to check (if the server is using ranks)
|
* @param permission The permission to check
|
||||||
* @param permission The permission to check (if the server is using permissions)
|
|
||||||
* @return true if the sender has enough permissions
|
* @return true if the sender has enough permissions
|
||||||
* @see Rank
|
|
||||||
*/
|
*/
|
||||||
protected boolean checkTab(CommandSender sender, Rank rank, String permission)
|
protected boolean silentCheckPermission(CommandSender sender, String permission)
|
||||||
{
|
{
|
||||||
|
PlexLog.debug("Checking {0} with {1}", sender.getName(), permission);
|
||||||
if (!isConsole(sender))
|
if (!isConsole(sender))
|
||||||
{
|
{
|
||||||
return checkTab((Player) sender, rank, permission);
|
return silentCheckPermission((Player) sender, permission);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -389,79 +277,25 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
* Checks whether a player has enough permissions or is high enough a rank
|
* Checks whether a player has enough permissions or is high enough a rank
|
||||||
*
|
*
|
||||||
* @param player The player object
|
* @param player The player object
|
||||||
* @param rank The rank to check (if the server is using ranks)
|
* @param permission The permission to check
|
||||||
* @param permission The permission to check (if the server is using permissions)
|
|
||||||
* @return true if the sender has enough permissions
|
* @return true if the sender has enough permissions
|
||||||
* @see Rank
|
|
||||||
*/
|
*/
|
||||||
protected boolean checkTab(Player player, Rank rank, String permission)
|
protected boolean checkPermission(Player player, String permission)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
if (player instanceof ConsoleCommandSender)
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
{
|
||||||
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
|
return true;
|
||||||
}
|
}
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
if (!permission.isEmpty() && !player.hasPermission(permission))
|
||||||
{
|
{
|
||||||
return !perms.permission().isEmpty() && player.hasPermission(permission);
|
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected boolean silentCheckPermission(Player player, String permission)
|
||||||
* Checks if a player is an admin
|
|
||||||
*
|
|
||||||
* @param plexPlayer The PlexPlayer object
|
|
||||||
* @return true if the player is an admin
|
|
||||||
* @see PlexPlayer
|
|
||||||
*/
|
|
||||||
protected boolean isAdmin(PlexPlayer plexPlayer)
|
|
||||||
{
|
{
|
||||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
return !permission.isEmpty() && player.hasPermission(permission);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a sender is an admin
|
|
||||||
*
|
|
||||||
* @param sender A command sender
|
|
||||||
* @return true if the sender is an admin or if console
|
|
||||||
*/
|
|
||||||
protected boolean isAdmin(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (!(sender instanceof Player player))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
|
||||||
return plugin.getRankManager().isAdmin(plexPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a username is an admin
|
|
||||||
*
|
|
||||||
* @param name The username
|
|
||||||
* @return true if the username is an admin
|
|
||||||
*/
|
|
||||||
protected boolean isAdmin(String name)
|
|
||||||
{
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(name);
|
|
||||||
return plugin.getRankManager().isAdmin(plexPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a sender is a senior admin
|
|
||||||
*
|
|
||||||
* @param sender A command sender
|
|
||||||
* @return true if the sender is a senior admin or if console
|
|
||||||
*/
|
|
||||||
protected boolean isSeniorAdmin(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (!(sender instanceof Player player))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlexPlayer plexPlayer = getPlexPlayer(player);
|
|
||||||
return plugin.getRankManager().isSeniorAdmin(plexPlayer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -639,11 +473,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
|
|||||||
return PlexUtils.mmDeserialize(s);
|
return PlexUtils.mmDeserialize(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rank getLevel()
|
|
||||||
{
|
|
||||||
return level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandMap getMap()
|
public CommandMap getMap()
|
||||||
{
|
{
|
||||||
return Plex.get().getServer().getCommandMap();
|
return Plex.get().getServer().getCommandMap();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package dev.plex.command.annotation;
|
package dev.plex.command.annotation;
|
||||||
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@ -12,14 +11,6 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CommandPermissions
|
public @interface CommandPermissions
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Minimum rank required
|
|
||||||
*
|
|
||||||
* @return Minimum rank required for the command
|
|
||||||
* @see Rank
|
|
||||||
*/
|
|
||||||
Rank level() default Rank.IMPOSTOR;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required command source
|
* Required command source
|
||||||
*
|
*
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package dev.plex.command.annotation;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface System
|
|
||||||
{
|
|
||||||
String value() default "";
|
|
||||||
|
|
||||||
boolean debug() default false;
|
|
||||||
}
|
|
@ -1,187 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.annotation.System;
|
|
||||||
import dev.plex.command.exception.ConsoleOnlyException;
|
|
||||||
import dev.plex.command.exception.PlayerNotFoundException;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
|
||||||
import dev.plex.event.AdminAddEvent;
|
|
||||||
import dev.plex.event.AdminRemoveEvent;
|
|
||||||
import dev.plex.event.AdminSetRankEvent;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
|
||||||
@CommandParameters(name = "admin", usage = "/<command> <add <player> | remove <player> | setrank <player> <rank> | list>", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
|
||||||
@System(value = "ranks")
|
|
||||||
public class AdminCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
//TODO: Better return messages
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
||||||
{
|
|
||||||
if (args.length == 0)
|
|
||||||
{
|
|
||||||
return usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("add"))
|
|
||||||
{
|
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
return usage("/admin add <player>");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isConsole(sender))
|
|
||||||
{
|
|
||||||
throw new ConsoleOnlyException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*UUID targetUUID = PlexUtils.getFromName(args[1]);
|
|
||||||
|
|
||||||
if (targetUUID != null)
|
|
||||||
{
|
|
||||||
PlexLog.debug("Admin Adding UUID: " + targetUUID);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
|
||||||
{
|
|
||||||
throw new PlayerNotFoundException();
|
|
||||||
}
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
|
||||||
|
|
||||||
if (isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
return messageComponent("playerIsAdmin");
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (args[0].equalsIgnoreCase("remove"))
|
|
||||||
{
|
|
||||||
if (args.length != 2)
|
|
||||||
{
|
|
||||||
return usage("/admin remove <player>");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isConsole(sender))
|
|
||||||
{
|
|
||||||
throw new ConsoleOnlyException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
|
||||||
|
|
||||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
|
||||||
{
|
|
||||||
throw new PlayerNotFoundException();
|
|
||||||
}
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
|
||||||
|
|
||||||
if (!isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
return messageComponent("playerNotAdmin");
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("setrank"))
|
|
||||||
{
|
|
||||||
if (args.length != 3)
|
|
||||||
{
|
|
||||||
return usage("/admin setrank <player> <rank>");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isConsole(sender))
|
|
||||||
{
|
|
||||||
throw new ConsoleOnlyException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// UUID targetUUID = PlexUtils.getFromName(args[1]);
|
|
||||||
|
|
||||||
if (!DataUtils.hasPlayedBefore(args[1]))
|
|
||||||
{
|
|
||||||
throw new PlayerNotFoundException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rankExists(args[2]))
|
|
||||||
{
|
|
||||||
return messageComponent("rankNotFound");
|
|
||||||
}
|
|
||||||
|
|
||||||
Rank rank = Rank.valueOf(args[2].toUpperCase());
|
|
||||||
|
|
||||||
if (!rank.isAtLeast(Rank.ADMIN))
|
|
||||||
{
|
|
||||||
return messageComponent("rankMustBeHigherThanAdmin");
|
|
||||||
}
|
|
||||||
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(args[1]);
|
|
||||||
|
|
||||||
if (!isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
return messageComponent("playerNotAdmin");
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("list"))
|
|
||||||
{
|
|
||||||
if (args.length != 1)
|
|
||||||
{
|
|
||||||
return usage("/admin list");
|
|
||||||
}
|
|
||||||
|
|
||||||
return componentFromString("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
||||||
{
|
|
||||||
if (args.length == 1)
|
|
||||||
{
|
|
||||||
return Arrays.asList("add", "remove", "setrank", "list");
|
|
||||||
}
|
|
||||||
else if (args.length == 2 && !args[0].equalsIgnoreCase("list"))
|
|
||||||
{
|
|
||||||
return PlexUtils.getPlayerNameList();
|
|
||||||
}
|
|
||||||
return ImmutableList.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean rankExists(String rank)
|
|
||||||
{
|
|
||||||
for (Rank ranks : Rank.values())
|
|
||||||
{
|
|
||||||
if (ranks.name().equalsIgnoreCase(rank))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
|
import dev.plex.hook.VaultHook;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
import dev.plex.util.redis.MessageUtil;
|
import dev.plex.util.redis.MessageUtil;
|
||||||
@ -18,29 +18,49 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminchat", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.adminchat", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
|
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
|
||||||
public class AdminChatCMD extends PlexCommand
|
public class AdminChatCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
{
|
{
|
||||||
|
PlexPlayer player;
|
||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
if (playerSender != null)
|
if (playerSender != null)
|
||||||
{
|
{
|
||||||
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
|
player = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||||
player.setStaffChat(!player.isStaffChat());
|
player.setStaffChat(!player.isStaffChat());
|
||||||
return messageComponent("adminChatToggled", BooleanUtils.toStringOnOff(player.isStaffChat()));
|
return messageComponent("adminChatToggled", BooleanUtils.toStringOnOff(player.isStaffChat()));
|
||||||
}
|
}
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String prefix;
|
||||||
|
if (playerSender != null)
|
||||||
|
{
|
||||||
|
player = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||||
|
prefix = PlexUtils.mmSerialize(VaultHook.getPrefix(player));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prefix = "<dark_gray>[<dark_purple>Console<dark_gray>]";
|
||||||
|
}
|
||||||
|
PlexLog.debug("admin chat prefix: {0}", prefix);
|
||||||
String message = StringUtils.join(args, " ");
|
String message = StringUtils.join(args, " ");
|
||||||
plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), message));
|
plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), prefix, message));
|
||||||
MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), message).toArray(UUID[]::new));
|
MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), prefix, message).toArray(UUID[]::new));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
|
||||||
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
|
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
|
||||||
public class AdminworldCMD extends PlexCommand
|
public class AdminworldCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -30,4 +32,10 @@ public class AdminworldCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.GameModeUpdateEvent;
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -19,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode")
|
@CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode")
|
||||||
public class AdventureCMD extends PlexCommand
|
public class AdventureCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -36,8 +35,7 @@ public class AdventureCMD extends PlexCommand
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
checkPermission(sender, "plex.gamemode.adventure.others");
|
||||||
{
|
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||||
@ -51,14 +49,13 @@ public class AdventureCMD extends PlexCommand
|
|||||||
|
|
||||||
Player nPlayer = getNonNullPlayer(args[0]);
|
Player nPlayer = getNonNullPlayer(args[0]);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.ADVENTURE));
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.ADVENTURE));
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.adventure.others"))
|
if (silentCheckPermission(sender, "plex.gamemode.adventure.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
@ -11,9 +10,21 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.util.BungeeUtil;
|
||||||
import dev.plex.util.*;
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import network.darkhelmet.prism.api.PrismParameters;
|
||||||
|
import network.darkhelmet.prism.api.Result;
|
||||||
|
import network.darkhelmet.prism.api.actions.PrismProcessType;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -21,13 +32,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
@CommandParameters(name = "ban", usage = "/<command> <player> [-nrb] [reason] [-nrb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||||
import java.time.ZonedDateTime;
|
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
|
||||||
|
|
||||||
public class BanCMD extends PlexCommand
|
public class BanCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -39,32 +45,16 @@ public class BanCMD extends PlexCommand
|
|||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
final PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (plexPlayer == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
|
||||||
Player player = Bukkit.getPlayer(targetUUID);
|
|
||||||
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
Player player = Bukkit.getPlayer(plexPlayer.getUuid());
|
||||||
{
|
|
||||||
if (isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
if (!isConsole(sender))
|
|
||||||
{
|
|
||||||
assert playerSender != null;
|
|
||||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
|
||||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
|
||||||
{
|
|
||||||
return messageComponent("higherRankThanYou");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) ->
|
plugin.getPunishmentManager().isAsyncBanned(plexPlayer.getUuid()).whenComplete((aBoolean, throwable) ->
|
||||||
{
|
{
|
||||||
if (aBoolean)
|
if (aBoolean)
|
||||||
{
|
{
|
||||||
@ -72,12 +62,15 @@ public class BanCMD extends PlexCommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String reason;
|
String reason;
|
||||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||||
punishment.setType(PunishmentType.BAN);
|
punishment.setType(PunishmentType.BAN);
|
||||||
|
boolean rollBack = true;
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
reason = StringUtils.join(args, " ", 1, args.length);
|
reason = StringUtils.join(args, " ", 1, args.length);
|
||||||
punishment.setReason(reason);
|
String newReason = StringUtils.normalizeSpace(reason.replace("-nrb", ""));
|
||||||
|
punishment.setReason(newReason.trim().isEmpty() ? "No reason provided." : newReason);
|
||||||
|
rollBack = !reason.startsWith("-nrb") && !reason.endsWith("-nrb");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -87,11 +80,8 @@ public class BanCMD extends PlexCommand
|
|||||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||||
punishment.setEndDate(date.plusDays(1));
|
punishment.setEndDate(date.plusDays(1));
|
||||||
punishment.setCustomTime(false);
|
punishment.setCustomTime(false);
|
||||||
punishment.setActive(!isAdmin(plexPlayer));
|
punishment.setActive(true);
|
||||||
if (player != null)
|
punishment.setIp(player != null ? player.getAddress().getAddress().getHostAddress().trim() : plexPlayer.getIps().get(plexPlayer.getIps().size() - 1));
|
||||||
{
|
|
||||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
|
||||||
}
|
|
||||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||||
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||||
Bukkit.getScheduler().runTask(Plex.get(), () ->
|
Bukkit.getScheduler().runTask(Plex.get(), () ->
|
||||||
@ -102,14 +92,59 @@ public class BanCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + plexPlayer.getUuid());
|
PlexLog.debug("(From /ban command) PunishedPlayer UUID: " + plexPlayer.getUuid());
|
||||||
|
|
||||||
|
if (rollBack)
|
||||||
|
{
|
||||||
|
if (plugin.getPrismHook().hasPrism())
|
||||||
|
{
|
||||||
|
PrismParameters parameters = plugin.getPrismHook().prismApi().createParameters();
|
||||||
|
parameters.addActionType("block-place");
|
||||||
|
parameters.addActionType("block-break");
|
||||||
|
parameters.addActionType("block-burn");
|
||||||
|
parameters.addActionType("entity-spawn");
|
||||||
|
parameters.addActionType("entity-kill");
|
||||||
|
parameters.addActionType("entity-explode");
|
||||||
|
parameters.addPlayerName(plexPlayer.getName());
|
||||||
|
parameters.setBeforeTime(Instant.now().toEpochMilli());
|
||||||
|
parameters.setProcessType(PrismProcessType.ROLLBACK);
|
||||||
|
final Future<Result> result = plugin.getPrismHook().prismApi().performLookup(parameters, sender);
|
||||||
|
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Result done = result.get();
|
||||||
|
}
|
||||||
|
catch (InterruptedException | ExecutionException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (plugin.getCoreProtectHook().hasCoreProtect())
|
||||||
|
{
|
||||||
|
PlexLog.debug("Testing coreprotect");
|
||||||
|
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
|
||||||
|
{
|
||||||
|
plugin.getCoreProtectHook().coreProtectAPI().performRollback(86400, Collections.singletonList(plexPlayer.getName()), null, null, null, null, 0, null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||||
|
{
|
||||||
|
return PlexUtils.getPlayerNameList();
|
||||||
|
}
|
||||||
|
if (args.length != 1 && silentCheckPermission(sender, this.getPermission()))
|
||||||
|
{
|
||||||
|
return Collections.singletonList("-nrb");
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.listener.impl.BlockListener;
|
import dev.plex.listener.impl.BlockListener;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -13,7 +12,12 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.blockedit")
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.blockedit")
|
||||||
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
|
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
|
||||||
public class BlockEditCMD extends PlexCommand
|
public class BlockEditCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -63,7 +67,7 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
for (final Player player : Bukkit.getOnlinePlayers())
|
for (final Player player : Bukkit.getOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (!silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
if (!silentCheckPermission(player, "plex.blockedit"))
|
||||||
{
|
{
|
||||||
bl.blockedPlayers.add(player.getName());
|
bl.blockedPlayers.add(player.getName());
|
||||||
++count;
|
++count;
|
||||||
@ -76,7 +80,7 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
final Player player = getNonNullPlayer(args[0]);
|
final Player player = getNonNullPlayer(args[0]);
|
||||||
if (!bl.blockedPlayers.contains(player.getName()))
|
if (!bl.blockedPlayers.contains(player.getName()))
|
||||||
{
|
{
|
||||||
if (silentCheckRank(player, Rank.ADMIN, "plex.blockedit"))
|
if (silentCheckPermission(player, "plex.blockedit"))
|
||||||
{
|
{
|
||||||
send(sender, messageComponent("higherRankThanYou"));
|
send(sender, messageComponent("higherRankThanYou"));
|
||||||
return null;
|
return null;
|
||||||
@ -95,4 +99,20 @@ public class BlockEditCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (silentCheckPermission(sender, this.getPermission()))
|
||||||
|
{
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
options.addAll(Arrays.asList("list", "purge", "all"));
|
||||||
|
options.addAll(PlexUtils.getPlayerNameList());
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,16 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
|
||||||
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
|
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
|
||||||
public class CommandSpyCMD extends PlexCommand
|
public class CommandSpyCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -31,4 +33,10 @@ public class CommandSpyCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||||
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||||
public class ConsoleSayCMD extends PlexCommand
|
public class ConsoleSayCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -28,4 +30,10 @@ public class ConsoleSayCMD extends PlexCommand
|
|||||||
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.GameModeUpdateEvent;
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -19,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
|
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
|
||||||
public class CreativeCMD extends PlexCommand
|
public class CreativeCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -39,8 +38,7 @@ public class CreativeCMD extends PlexCommand
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
checkPermission(sender, "plex.gamemode.creative.others");
|
||||||
{
|
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||||
@ -56,13 +54,11 @@ public class CreativeCMD extends PlexCommand
|
|||||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE));
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.creative.others"))
|
if (silentCheckPermission(sender, "plex.gamemode.creative.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,7 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.annotation.System;
|
import dev.plex.menu.impl.MaterialMenu;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.GameRuleUtil;
|
import dev.plex.util.GameRuleUtil;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
@ -24,8 +23,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
||||||
@CommandPermissions(level = Rank.EXECUTIVE, permission = "plex.debug")
|
@CommandPermissions(permission = "plex.debug")
|
||||||
@System(debug = true)
|
|
||||||
public class DebugCMD extends PlexCommand
|
public class DebugCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -79,12 +77,21 @@ public class DebugCMD extends PlexCommand
|
|||||||
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
|
return mmString("<aqua>Aliases for " + commandName + " are: " + Arrays.toString(command.getAliases().toArray(new String[0])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (args[0].equalsIgnoreCase("pagination"))
|
||||||
|
{
|
||||||
|
if (playerSender == null)
|
||||||
|
{
|
||||||
|
return messageComponent("noPermissionConsole");
|
||||||
|
}
|
||||||
|
new MaterialMenu().open(playerSender);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,31 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.annotation.System;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
@CommandParameters(name = "deopall", description = "Deop everyone on the server", aliases = "deopa")
|
|
||||||
@CommandPermissions(level = Rank.ADMIN)
|
|
||||||
@System(value = "ranks")
|
|
||||||
public class DeopAllCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
||||||
{
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
player.setOp(false);
|
|
||||||
}
|
|
||||||
PlexUtils.broadcast(messageComponent("deoppedAllPlayers", sender.getName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.annotation.System;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandParameters(name = "deop", description = "Deop a player on the server", usage = "/<command> <player>")
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.deop")
|
|
||||||
@System(value = "ranks")
|
|
||||||
public class DeopCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
||||||
{
|
|
||||||
if (args.length != 1)
|
|
||||||
{
|
|
||||||
return usage();
|
|
||||||
}
|
|
||||||
Player player = getNonNullPlayer(args[0]);
|
|
||||||
player.setOp(false);
|
|
||||||
PlexUtils.broadcast(messageComponent("deoppedPlayer", sender.getName(), player.getName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
||||||
{
|
|
||||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -18,8 +18,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [name]", aliases = "ew,rd")
|
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [entity] [radius]", aliases = "ew,rd")
|
||||||
public class EntityWipeCMD extends PlexCommand
|
public class EntityWipeCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -29,6 +29,22 @@ public class EntityWipeCMD extends PlexCommand
|
|||||||
|
|
||||||
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
|
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
|
||||||
|
|
||||||
|
boolean radiusSpecified = !entityWhitelist.isEmpty() && isNumeric(entityWhitelist.get(entityWhitelist.size() - 1)); // try and detect if the last argument of the command is a number
|
||||||
|
boolean useBlacklist = args.length == 0 || (args.length == 1 && radiusSpecified); // if there are no arguments or the one argument is a number
|
||||||
|
int radius = 0;
|
||||||
|
|
||||||
|
PlexLog.debug("using blacklist: " + useBlacklist);
|
||||||
|
PlexLog.debug("radius specified: " + radiusSpecified);
|
||||||
|
|
||||||
|
if (radiusSpecified)
|
||||||
|
{
|
||||||
|
radius = parseInt(sender, args[entityWhitelist.size() - 1]); // get the args length as the size of the list
|
||||||
|
radius *= radius;
|
||||||
|
entityWhitelist.remove(entityWhitelist.size() - 1); // remove the radius from the list
|
||||||
|
}
|
||||||
|
|
||||||
|
PlexLog.debug("radius: " + radius);
|
||||||
|
|
||||||
EntityType[] entityTypes = EntityType.values();
|
EntityType[] entityTypes = EntityType.values();
|
||||||
entityWhitelist.removeIf(name ->
|
entityWhitelist.removeIf(name ->
|
||||||
{
|
{
|
||||||
@ -40,8 +56,6 @@ public class EntityWipeCMD extends PlexCommand
|
|||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
|
|
||||||
boolean useBlacklist = args.length == 0;
|
|
||||||
|
|
||||||
HashMap<String, Integer> entityCounts = new HashMap<>();
|
HashMap<String, Integer> entityCounts = new HashMap<>();
|
||||||
|
|
||||||
for (World world : Bukkit.getWorlds())
|
for (World world : Bukkit.getWorlds())
|
||||||
@ -54,6 +68,16 @@ public class EntityWipeCMD extends PlexCommand
|
|||||||
|
|
||||||
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type)))
|
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type)))
|
||||||
{
|
{
|
||||||
|
if (radius > 0)
|
||||||
|
{
|
||||||
|
PlexLog.debug("we got here, radius is > 0");
|
||||||
|
if (playerSender != null && entity.getWorld() == playerSender.getWorld() && playerSender.getLocation().distanceSquared(entity.getLocation()) > radius)
|
||||||
|
{
|
||||||
|
PlexLog.debug("continuing");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlexLog.debug("removed entity: " + entity.getType().name());
|
||||||
entity.remove();
|
entity.remove();
|
||||||
|
|
||||||
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
|
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
|
||||||
@ -82,7 +106,9 @@ public class EntityWipeCMD extends PlexCommand
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (silentCheckPermission(sender, this.getPermission()))
|
||||||
{
|
{
|
||||||
List<String> entities = new ArrayList<>();
|
List<String> entities = new ArrayList<>();
|
||||||
for (World world : Bukkit.getWorlds())
|
for (World world : Bukkit.getWorlds())
|
||||||
@ -97,4 +123,36 @@ public class EntityWipeCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return entities.stream().toList();
|
return entities.stream().toList();
|
||||||
}
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer parseInt(CommandSender sender, String string)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Integer.parseInt(string);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
sender.sendMessage(mmString("<red>" + string + "<red> is not a valid number!"));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNumeric(String string)
|
||||||
|
{
|
||||||
|
if (string == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int num = Integer.parseInt(string);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
|
||||||
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
||||||
public class FlatlandsCMD extends PlexCommand
|
public class FlatlandsCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -29,4 +31,10 @@ public class FlatlandsCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -21,7 +20,7 @@ import java.time.ZonedDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.freeze")
|
@CommandPermissions(permission = "plex.freeze")
|
||||||
public class FreezeCMD extends PlexCommand
|
public class FreezeCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -39,19 +38,6 @@ public class FreezeCMD extends PlexCommand
|
|||||||
return messageComponent("playerFrozen");
|
return messageComponent("playerFrozen");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAdmin(getPlexPlayer(player)))
|
|
||||||
{
|
|
||||||
if (!isConsole(sender))
|
|
||||||
{
|
|
||||||
assert playerSender != null;
|
|
||||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
|
||||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()) && getPlexPlayer(player).isAdminActive())
|
|
||||||
{
|
|
||||||
return messageComponent("higherRankThanYou");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||||
punishment.setCustomTime(false);
|
punishment.setCustomTime(false);
|
||||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||||
@ -67,8 +53,8 @@ public class FreezeCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.GameModeUpdateEvent;
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -21,7 +20,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt")
|
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt")
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
||||||
public class GamemodeCMD extends PlexCommand
|
public class GamemodeCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
private GameMode gamemode;
|
private GameMode gamemode;
|
||||||
@ -62,14 +61,14 @@ public class GamemodeCMD extends PlexCommand
|
|||||||
case "spectator", "sp", "3", "6" ->
|
case "spectator", "sp", "3", "6" ->
|
||||||
{
|
{
|
||||||
gamemode = GameMode.SPECTATOR;
|
gamemode = GameMode.SPECTATOR;
|
||||||
checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator");
|
checkPermission(sender, "plex.gamemode.spectator");
|
||||||
update(sender, playerSender, GameMode.SPECTATOR);
|
update(sender, playerSender, GameMode.SPECTATOR);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
checkRank(sender, Rank.ADMIN, "plex.gamemode.others");
|
checkPermission(sender, "plex.gamemode.others");
|
||||||
Player player = getNonNullPlayer(args[1]);
|
Player player = getNonNullPlayer(args[1]);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode));
|
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode));
|
||||||
}
|
}
|
||||||
@ -89,16 +88,19 @@ public class GamemodeCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
return Arrays.asList("creative", "survival", "adventure", "spectator", "default");
|
return Arrays.asList("creative", "survival", "adventure", "spectator", "default");
|
||||||
}
|
}
|
||||||
if (args.length == 2)
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
if (silentCheckPermission(sender, "plex.gamemode.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
@ -9,11 +10,9 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.BungeeUtil;
|
import dev.plex.util.BungeeUtil;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.WebUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -24,10 +23,10 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.UUID;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||||
public class KickCMD extends PlexCommand
|
public class KickCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -38,21 +37,20 @@ public class KickCMD extends PlexCommand
|
|||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
PlexPlayer plexPlayer = DataUtils.getPlayer(args[0]);
|
||||||
String reason = "No reason provided";
|
String reason = "No reason provided";
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (plexPlayer == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
Player player = Bukkit.getPlayer(plexPlayer.getUuid());
|
||||||
Player player = Bukkit.getPlayer(targetUUID);
|
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||||
punishment.setType(PunishmentType.KICK);
|
punishment.setType(PunishmentType.KICK);
|
||||||
if (args.length > 1)
|
if (args.length > 1)
|
||||||
{
|
{
|
||||||
@ -67,7 +65,13 @@ public class KickCMD extends PlexCommand
|
|||||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||||
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
||||||
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
BungeeUtil.kickPlayer(player, Punishment.generateKickMessage(punishment));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.hook.VaultHook;
|
import dev.plex.hook.VaultHook;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -14,10 +13,11 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit,who,playerlist,online")
|
@CommandParameters(name = "list", description = "Show a list of all online players", usage = "/<command> [-d]", aliases = "lsit,who,playerlist,online")
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.list")
|
@CommandPermissions(permission = "plex.list")
|
||||||
public class ListCMD extends PlexCommand
|
public class ListCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -37,20 +37,25 @@ public class ListCMD extends PlexCommand
|
|||||||
.append(Component.space())
|
.append(Component.space())
|
||||||
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
|
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
|
||||||
send(sender, header);
|
send(sender, header);
|
||||||
if (players.size() == 0)
|
if (players.isEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < players.size(); i++)
|
for (int i = 0; i < players.size(); i++)
|
||||||
{
|
{
|
||||||
Player player = players.get(i);
|
Player player = players.get(i);
|
||||||
if (plugin.getSystem().equals("ranks"))
|
Component prefix = VaultHook.getPrefix(getPlexPlayer(player));
|
||||||
|
if (prefix != null && !prefix.equals(Component.empty()) && !prefix.equals(Component.space()))
|
||||||
{
|
{
|
||||||
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
list = list.append(prefix).append(Component.space());
|
||||||
}
|
}
|
||||||
else
|
list = list.append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||||
|
if (args.length > 0 && args[0].equalsIgnoreCase("-d"))
|
||||||
{
|
{
|
||||||
list = list.append(VaultHook.getPrefix(getPlexPlayer(player))).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
list = list.append(Component.space());
|
||||||
|
list = list.append(Component.text("(").color(NamedTextColor.WHITE));
|
||||||
|
list = list.append(player.displayName());
|
||||||
|
list = list.append(Component.text(")").color(NamedTextColor.WHITE));
|
||||||
}
|
}
|
||||||
if (i != players.size() - 1)
|
if (i != players.size() - 1)
|
||||||
{
|
{
|
||||||
@ -59,4 +64,13 @@ public class ListCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||||
|
{
|
||||||
|
return Collections.singletonList("-d");
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,18 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
|
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
|
@CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
|
||||||
public class LocalSpawnCMD extends PlexCommand
|
public class LocalSpawnCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -22,4 +25,10 @@ public class LocalSpawnCMD extends PlexCommand
|
|||||||
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
|
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
|
||||||
return messageComponent("teleportedToWorldSpawn");
|
return messageComponent("teleportedToWorldSpawn");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -16,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
|
@CommandParameters(name = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.lockup")
|
@CommandPermissions(permission = "plex.lockup")
|
||||||
public class LockupCMD extends PlexCommand
|
public class LockupCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -29,19 +28,6 @@ public class LockupCMD extends PlexCommand
|
|||||||
Player player = getNonNullPlayer(args[0]);
|
Player player = getNonNullPlayer(args[0]);
|
||||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||||
|
|
||||||
if (isAdmin(getPlexPlayer(player)))
|
|
||||||
{
|
|
||||||
if (!isConsole(sender))
|
|
||||||
{
|
|
||||||
assert playerSender != null;
|
|
||||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
|
||||||
if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString()))
|
|
||||||
{
|
|
||||||
return messageComponent("higherRankThanYou");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
|
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
|
||||||
if (punishedPlayer.isLockedUp())
|
if (punishedPlayer.isLockedUp())
|
||||||
{
|
{
|
||||||
@ -52,8 +38,8 @@ public class LockupCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -13,7 +13,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
|
||||||
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||||
public class MasterbuilderworldCMD extends PlexCommand
|
public class MasterbuilderworldCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -30,4 +33,10 @@ public class MasterbuilderworldCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,50 +4,119 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.apache.commons.lang3.text.WordUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Mob;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command>", aliases = "mp")
|
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command> [mob]", aliases = "mp")
|
||||||
public class MobPurgeCMD extends PlexCommand
|
public class MobPurgeCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
|
private final List<EntityType> MOB_TYPES = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||||
{
|
{
|
||||||
HashMap<String, Integer> entityCounts = new HashMap<>();
|
EntityType type = null;
|
||||||
|
String mobName = null;
|
||||||
for (World world : Bukkit.getWorlds())
|
if (args.length > 0)
|
||||||
{
|
{
|
||||||
for (Entity entity : world.getEntities())
|
try
|
||||||
{
|
{
|
||||||
if (entity instanceof Mob)
|
type = EntityType.valueOf(args[0].toUpperCase());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
String type = entity.getType().name();
|
PlexLog.debug("A genius tried and failed removing the following invalid mob: " + args[0].toUpperCase());
|
||||||
entity.remove();
|
send(sender, messageComponent("notAValidMob"));
|
||||||
|
return null;
|
||||||
entityCounts.put(type, entityCounts.getOrDefault(type, 0) + 1);
|
|
||||||
}
|
}
|
||||||
}
|
if (!MOB_TYPES.contains(type))
|
||||||
}
|
{
|
||||||
|
PlexLog.debug(Arrays.deepToString(MOB_TYPES.toArray()));
|
||||||
int entityCount = entityCounts.values().stream().mapToInt(a -> a).sum();
|
PlexLog.debug("A genius tried to remove a mob that doesn't exist: " + args[0].toUpperCase());
|
||||||
|
sender.sendMessage(messageComponent("notAValidMobButValidEntity"));
|
||||||
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), entityCount));
|
|
||||||
|
|
||||||
/*entityCounts.forEach((entityName, numRemoved) -> {
|
|
||||||
sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName));
|
|
||||||
});*/
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
mobName = WordUtils.capitalizeFully(type.name().replace("_", " "));
|
||||||
|
PlexLog.debug("The args aren't null so the mob is: " + mobName);
|
||||||
|
}
|
||||||
|
int count = purgeMobs(type);
|
||||||
|
if (type != null)
|
||||||
|
{
|
||||||
|
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), count, mobName));
|
||||||
|
PlexLog.debug("All " + count + " of " + mobName + " were removed");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), count));
|
||||||
|
PlexLog.debug("All " + count + " valid mobs were removed");
|
||||||
|
}
|
||||||
|
sender.sendMessage(messageComponent("amountOfMobsRemoved", count, (type != null ? mobName : "mob") + multipleS(count)));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String multipleS(int count)
|
||||||
|
{
|
||||||
|
return (count == 1 ? "" : "s");
|
||||||
|
}
|
||||||
|
|
||||||
|
private int purgeMobs(EntityType type)
|
||||||
|
{
|
||||||
|
int removed = 0;
|
||||||
|
for (World world : Bukkit.getWorlds())
|
||||||
|
{
|
||||||
|
for (Entity entity : world.getLivingEntities())
|
||||||
|
{
|
||||||
|
if (entity instanceof LivingEntity && !(entity instanceof Player))
|
||||||
|
{
|
||||||
|
if (type != null && !entity.getType().equals(type))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
entity.remove();
|
||||||
|
removed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getAllMobs()
|
||||||
|
{
|
||||||
|
List<String> mobs = new ArrayList<>();
|
||||||
|
Arrays.stream(EntityType.values()).filter(EntityType::isAlive).filter(EntityType::isSpawnable).forEach(MOB_TYPES::add);
|
||||||
|
for (EntityType entityType : MOB_TYPES)
|
||||||
|
{
|
||||||
|
mobs.add(entityType.name());
|
||||||
|
}
|
||||||
|
return mobs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||||
|
{
|
||||||
|
return getAllMobs();
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -21,7 +20,7 @@ import java.time.ZonedDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
|
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.mute")
|
@CommandPermissions(permission = "plex.mute")
|
||||||
public class MuteCMD extends PlexCommand
|
public class MuteCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -39,7 +38,7 @@ public class MuteCMD extends PlexCommand
|
|||||||
return messageComponent("playerMuted");
|
return messageComponent("playerMuted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (silentCheckRank(player, Rank.ADMIN, "plex.mute"))
|
if (silentCheckPermission(player, "plex.mute"))
|
||||||
{
|
{
|
||||||
send(sender, messageComponent("higherRankThanYou"));
|
send(sender, messageComponent("higherRankThanYou"));
|
||||||
return null;
|
return null;
|
||||||
@ -60,8 +59,8 @@ public class MuteCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,68 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.*;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.namehistory")
|
|
||||||
public class NameHistoryCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
||||||
{
|
|
||||||
if (args.length != 1)
|
|
||||||
{
|
|
||||||
return usage();
|
|
||||||
}
|
|
||||||
String username = args[0];
|
|
||||||
|
|
||||||
AshconInfo info = MojangUtils.getInfo(username);
|
|
||||||
if (info == null)
|
|
||||||
{
|
|
||||||
return messageComponent("nameHistoryDoesntExist");
|
|
||||||
}
|
|
||||||
PlexLog.debug("NameHistory UUID: " + info.getUuid());
|
|
||||||
PlexLog.debug("NameHistory Size: " + info.getUsernameHistories().length);
|
|
||||||
List<Component> historyList = Lists.newArrayList();
|
|
||||||
Arrays.stream(info.getUsernameHistories()).forEach(history ->
|
|
||||||
{
|
|
||||||
if (history.getZonedDateTime() != null)
|
|
||||||
{
|
|
||||||
historyList.add(
|
|
||||||
messageComponent("nameHistoryBody",
|
|
||||||
history.getUsername(),
|
|
||||||
TimeUtils.useTimezone(history.getZonedDateTime())));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
historyList.add(
|
|
||||||
Component.text(history.getUsername()).color(NamedTextColor.GOLD)
|
|
||||||
.append(Component.space()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
send(sender, messageComponent("nameHistoryTitle", username));
|
|
||||||
send(sender, messageComponent("nameHistorySeparator"));
|
|
||||||
historyList.forEach(component -> send(sender, component));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
||||||
{
|
|
||||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,8 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.extra.Note;
|
import dev.plex.punishment.extra.Note;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.storage.StorageType;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -27,7 +25,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
|
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.notes")
|
@CommandPermissions(permission = "plex.notes")
|
||||||
public class NotesCMD extends PlexCommand
|
public class NotesCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -48,8 +46,6 @@ public class NotesCMD extends PlexCommand
|
|||||||
switch (args[1].toLowerCase())
|
switch (args[1].toLowerCase())
|
||||||
{
|
{
|
||||||
case "list":
|
case "list":
|
||||||
{
|
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
{
|
||||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||||
{
|
{
|
||||||
@ -60,16 +56,6 @@ public class NotesCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
readNotes(sender, plexPlayer, notes);
|
readNotes(sender, plexPlayer, notes);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
List<Note> notes = plexPlayer.getNotes();
|
|
||||||
if (notes.size() == 0)
|
|
||||||
{
|
|
||||||
return messageComponent("noNotes");
|
|
||||||
}
|
|
||||||
readNotes(sender, plexPlayer, notes);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case "add":
|
case "add":
|
||||||
@ -83,14 +69,7 @@ public class NotesCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||||
plexPlayer.getNotes().add(note);
|
plexPlayer.getNotes().add(note);
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
plugin.getSqlNotes().addNote(note);
|
plugin.getSqlNotes().addNote(note);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
}
|
|
||||||
return messageComponent("noteAdded");
|
return messageComponent("noteAdded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,8 +88,6 @@ public class NotesCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
return messageComponent("unableToParseNumber", args[2]);
|
return messageComponent("unableToParseNumber", args[2]);
|
||||||
}
|
}
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||||
{
|
{
|
||||||
boolean deleted = false;
|
boolean deleted = false;
|
||||||
@ -129,40 +106,15 @@ public class NotesCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (plexPlayer.getNotes().removeIf(note -> note.getId() == id))
|
|
||||||
{
|
|
||||||
return messageComponent("removedNote", id);
|
|
||||||
}
|
|
||||||
return messageComponent("noteNotFound");
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
{
|
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
|
||||||
{
|
|
||||||
for (Note note : notes)
|
|
||||||
{
|
|
||||||
plugin.getSqlNotes().deleteNote(note.getId(), plexPlayer.getUuid());
|
|
||||||
}
|
|
||||||
plexPlayer.getNotes().clear();
|
|
||||||
send(sender, messageComponent("clearedNotes", notes.size()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
int count = plexPlayer.getNotes().size();
|
int count = plexPlayer.getNotes().size();
|
||||||
plexPlayer.getNotes().clear();
|
plexPlayer.getNotes().clear();
|
||||||
DataUtils.update(plexPlayer);
|
DataUtils.update(plexPlayer);
|
||||||
return messageComponent("clearedNotes", count);
|
return messageComponent("clearedNotes", count);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
return usage();
|
return usage();
|
||||||
@ -184,7 +136,9 @@ public class NotesCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (silentCheckPermission(sender, this.getPermission()))
|
||||||
{
|
{
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
@ -196,4 +150,6 @@ public class NotesCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,31 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.annotation.System;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
@CommandParameters(name = "opall", description = "Op everyone on the server", aliases = "opa")
|
|
||||||
@CommandPermissions(level = Rank.ADMIN)
|
|
||||||
@System(value = "ranks")
|
|
||||||
public class OpAllCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
||||||
{
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
player.setOp(true);
|
|
||||||
}
|
|
||||||
PlexUtils.broadcast(messageComponent("oppedAllPlayers", sender.getName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.annotation.System;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandParameters(name = "op", description = "Op a player on the server", usage = "/<command> <player>")
|
|
||||||
@CommandPermissions(level = Rank.OP)
|
|
||||||
@System(value = "ranks")
|
|
||||||
public class OpCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
||||||
{
|
|
||||||
if (args.length != 1)
|
|
||||||
{
|
|
||||||
return usage();
|
|
||||||
}
|
|
||||||
Player player = getNonNullPlayer(args[0]);
|
|
||||||
player.setOp(true);
|
|
||||||
PlexUtils.broadcast(messageComponent("oppedPlayer", sender.getName(), player.getName()));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
||||||
{
|
|
||||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ import dev.plex.command.exception.CommandFailException;
|
|||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.module.PlexModule;
|
import dev.plex.module.PlexModule;
|
||||||
import dev.plex.module.PlexModuleFile;
|
import dev.plex.module.PlexModuleFile;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.BuildInfo;
|
import dev.plex.util.BuildInfo;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
@ -25,7 +24,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.IMPOSTOR, source = RequiredCommandSource.ANY)
|
@CommandPermissions(source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
|
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | modules [reload]]", description = "Show information about Plex or reload it")
|
||||||
public class PlexCMD extends PlexCommand
|
public class PlexCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -36,7 +35,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
if (args.length == 0)
|
if (args.length == 0)
|
||||||
{
|
{
|
||||||
send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
|
send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
|
||||||
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.getHead()));
|
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getDescription().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.getCommit()));
|
||||||
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
||||||
send(sender, mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate()));
|
send(sender, mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate()));
|
||||||
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
||||||
@ -45,7 +44,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("reload"))
|
if (args[0].equalsIgnoreCase("reload"))
|
||||||
{
|
{
|
||||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload");
|
checkPermission(sender, "plex.reload");
|
||||||
plugin.config.load();
|
plugin.config.load();
|
||||||
send(sender, "Reloaded config file");
|
send(sender, "Reloaded config file");
|
||||||
plugin.messages.load();
|
plugin.messages.load();
|
||||||
@ -55,10 +54,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
send(sender, "Reloaded indefinite bans");
|
send(sender, "Reloaded indefinite bans");
|
||||||
plugin.commands.load();
|
plugin.commands.load();
|
||||||
send(sender, "Reloaded blocked commands file");
|
send(sender, "Reloaded blocked commands file");
|
||||||
plugin.getRankManager().importDefaultRanks();
|
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||||
send(sender, "Imported ranks");
|
|
||||||
plugin.setSystem(plugin.config.getString("system"));
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("permissions") && !plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
|
||||||
{
|
{
|
||||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||||
}
|
}
|
||||||
@ -72,7 +68,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("redis"))
|
else if (args[0].equalsIgnoreCase("redis"))
|
||||||
{
|
{
|
||||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.redis");
|
checkPermission(sender, "plex.redis");
|
||||||
if (!plugin.getRedisConnection().isEnabled())
|
if (!plugin.getRedisConnection().isEnabled())
|
||||||
{
|
{
|
||||||
throw new CommandFailException("&cRedis is not enabled.");
|
throw new CommandFailException("&cRedis is not enabled.");
|
||||||
@ -91,7 +87,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
if (args[1].equalsIgnoreCase("reload"))
|
if (args[1].equalsIgnoreCase("reload"))
|
||||||
{
|
{
|
||||||
checkRank(sender, Rank.EXECUTIVE, "plex.modules.reload");
|
checkPermission(sender, "plex.modules.reload");
|
||||||
plugin.getModuleManager().reloadModules();
|
plugin.getModuleManager().reloadModules();
|
||||||
return mmString("<green>All modules reloaded!");
|
return mmString("<green>All modules reloaded!");
|
||||||
}
|
}
|
||||||
@ -99,7 +95,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (!hasUpdateAccess(playerSender, sender))
|
if (!hasUpdateAccess(playerSender, sender))
|
||||||
{
|
{
|
||||||
return messageComponent("noPermissionRank", "an Owner or Developer");
|
return messageComponent("noPermissionRank", "a Developer");
|
||||||
}
|
}
|
||||||
for (PlexModule module : plugin.getModuleManager().getModules())
|
for (PlexModule module : plugin.getModuleManager().getModules())
|
||||||
{
|
{
|
||||||
@ -113,7 +109,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (!hasUpdateAccess(playerSender, sender))
|
if (!hasUpdateAccess(playerSender, sender))
|
||||||
{
|
{
|
||||||
return messageComponent("noPermissionRank", "an Owner or Developer");
|
return messageComponent("noPermissionRank", "a Developer");
|
||||||
}
|
}
|
||||||
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0))
|
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0))
|
||||||
{
|
{
|
||||||
@ -130,7 +126,7 @@ public class PlexCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
@ -156,13 +152,11 @@ public class PlexCMD extends PlexCommand
|
|||||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender.getName());
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender.getName());
|
||||||
if (offlinePlayer.hasPlayedBefore())
|
if (offlinePlayer.hasPlayedBefore())
|
||||||
{
|
{
|
||||||
return PlexUtils.DEVELOPERS.contains(offlinePlayer.getUniqueId().toString())
|
return PlexUtils.DEVELOPERS.contains(offlinePlayer.getUniqueId().toString());
|
||||||
|| plugin.config.getStringList("titles.owners").contains(sender.getName());
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
assert player != null;
|
assert player != null;
|
||||||
return PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString())
|
return PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString());
|
||||||
|| plugin.config.getStringList("titles.owners").contains(player.getName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,19 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import dev.plex.command.exception.PlayerNotFoundException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.menu.PunishmentMenu;
|
import dev.plex.menu.impl.PunishedPlayerMenu;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.menu.impl.PunishmentMenu;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -17,19 +22,35 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
|
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
|
@CommandPermissions(permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
|
||||||
public class PunishmentsCMD extends PlexCommand
|
public class PunishmentsCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
{
|
{
|
||||||
new PunishmentMenu().openInv(playerSender, 0);
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
new PunishmentMenu().open(playerSender);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!DataUtils.hasPlayedBefore(args[0]))
|
||||||
|
{
|
||||||
|
throw new PlayerNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[0]);
|
||||||
|
final PlexPlayer player = offlinePlayer.isOnline() ? getOnlinePlexPlayer(args[0]) : getOfflinePlexPlayer(offlinePlayer.getUniqueId());
|
||||||
|
|
||||||
|
new PunishedPlayerMenu(player).open(playerSender);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.annotation.System;
|
|
||||||
import dev.plex.command.exception.CommandFailException;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.rank", source = RequiredCommandSource.ANY)
|
|
||||||
@CommandParameters(name = "rank", description = "Displays your rank")
|
|
||||||
@System(value = "ranks")
|
|
||||||
public class RankCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
||||||
{
|
|
||||||
if (args.length == 0)
|
|
||||||
{
|
|
||||||
if (isConsole(sender))
|
|
||||||
{
|
|
||||||
throw new CommandFailException("<red>When using the console, you must specify a player's rank.");
|
|
||||||
}
|
|
||||||
if (!(playerSender == null))
|
|
||||||
{
|
|
||||||
Rank rank = getPlexPlayer(playerSender).getRankFromString();
|
|
||||||
return messageComponent("yourRank", rank.isAtLeast(Rank.ADMIN) && !getPlexPlayer(playerSender).isAdminActive() ? (playerSender.isOp() ? Rank.OP.getReadable() : Rank.NONOP.getReadable()) : rank.getReadable());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Player player = getNonNullPlayer(args[0]);
|
|
||||||
Rank rank = getPlexPlayer(player).getRankFromString();
|
|
||||||
return messageComponent("otherRank", player.getName(), rank.isAtLeast(Rank.ADMIN) && !getPlexPlayer(player).isAdminActive() ? (player.isOp() ? Rank.OP.getReadable() : Rank.NONOP.getReadable()) : rank.getReadable());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
||||||
{
|
|
||||||
if (args.length == 1)
|
|
||||||
{
|
|
||||||
return PlexUtils.getPlayerNameList();
|
|
||||||
}
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -13,7 +13,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, permission = "plex.rawsay", source = RequiredCommandSource.ANY)
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.rawsay", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
|
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
|
||||||
public class RawSayCMD extends PlexCommand
|
public class RawSayCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -28,4 +31,10 @@ public class RawSayCMD extends PlexCommand
|
|||||||
PlexUtils.broadcast(StringUtils.join(args, " "));
|
PlexUtils.broadcast(StringUtils.join(args, " "));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,19 +1,22 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
|
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
|
||||||
public class RemoveLoginMessageCMD extends PlexCommand
|
public class RemoveLoginMessageCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -31,7 +34,7 @@ public class RemoveLoginMessageCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
else if (args[0].equalsIgnoreCase("-o"))
|
else if (args[0].equalsIgnoreCase("-o"))
|
||||||
{
|
{
|
||||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.removeloginmessage.others");
|
checkPermission(sender, "plex.removeloginmessage.others");
|
||||||
|
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
{
|
{
|
||||||
@ -52,4 +55,17 @@ public class RemoveLoginMessageCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
if (silentCheckPermission(sender, "plex.removeloginmessage.others"))
|
||||||
|
{
|
||||||
|
return List.of("-o");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return args.length == 2 && silentCheckPermission(sender, "plex.removeloginmessage.others") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -13,7 +12,10 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.say", source = RequiredCommandSource.ANY)
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.say", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
|
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
|
||||||
public class SayCMD extends PlexCommand
|
public class SayCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -28,4 +30,10 @@ public class SayCMD extends PlexCommand
|
|||||||
PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
@ -7,21 +8,23 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
|
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
|
||||||
public class SetLoginMessageCMD extends PlexCommand
|
public class SetLoginMessageCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name");
|
private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name");
|
||||||
private final boolean rankRequired = plugin.getConfig().getBoolean("loginmessages.rank");
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
@ -34,7 +37,7 @@ public class SetLoginMessageCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
if (args[0].equals("-o"))
|
if (args[0].equals("-o"))
|
||||||
{
|
{
|
||||||
checkRank(sender, Rank.SENIOR_ADMIN, "plex.setloginmessage.others");
|
checkPermission(sender, "plex.setloginmessage.others");
|
||||||
|
|
||||||
if (args.length < 2)
|
if (args.length < 2)
|
||||||
{
|
{
|
||||||
@ -54,21 +57,18 @@ public class SetLoginMessageCMD extends PlexCommand
|
|||||||
validateMessage(message);
|
validateMessage(message);
|
||||||
plexPlayer.setLoginMessage(message);
|
plexPlayer.setLoginMessage(message);
|
||||||
return messageComponent("setOtherPlayersLoginMessage", plexPlayer.getName(),
|
return messageComponent("setOtherPlayersLoginMessage", plexPlayer.getName(),
|
||||||
message.replace("%player%", plexPlayer.getName())
|
MiniMessage.miniMessage().serialize(PlexUtils.stringToComponent(message.replace("%player%", plexPlayer.getName()))));
|
||||||
.replace("%rank%", plexPlayer.getRank()));
|
|
||||||
}
|
}
|
||||||
if (isConsole(sender))
|
if (isConsole(sender))
|
||||||
{
|
{
|
||||||
return messageComponent("noPermissionConsole");
|
return messageComponent("noPermissionConsole");
|
||||||
}
|
}
|
||||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||||
String message = StringUtils.join(args, " ", 0, args.length);
|
String message = StringUtils.join(args, " ", 0, args.length)
|
||||||
message = message.replace(plexPlayer.getName(), "%player%");
|
.replace(plexPlayer.getName(), "%player%");
|
||||||
validateMessage(message);
|
validateMessage(message);
|
||||||
plexPlayer.setLoginMessage(message);
|
plexPlayer.setLoginMessage(message);
|
||||||
return messageComponent("setOwnLoginMessage",
|
return messageComponent("setOwnLoginMessage", PlexUtils.stringToComponent(message.replace("%player%", plexPlayer.getName())));
|
||||||
message.replace("%player%", plexPlayer.getName())
|
|
||||||
.replace("%rank%", plexPlayer.getRank()));
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -80,10 +80,18 @@ public class SetLoginMessageCMD extends PlexCommand
|
|||||||
PlexLog.debug("Validating login message has a valid name in it");
|
PlexLog.debug("Validating login message has a valid name in it");
|
||||||
throw new CommandFailException(messageString("nameRequired"));
|
throw new CommandFailException(messageString("nameRequired"));
|
||||||
}
|
}
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks") && rankRequired && !message.contains("%rank%"))
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
PlexLog.debug("Validating login message has a valid rank in it");
|
if (args.length == 1)
|
||||||
throw new CommandFailException(messageString("rankRequired"));
|
{
|
||||||
|
if (silentCheckPermission(sender, "plex.setloginmessage"))
|
||||||
|
{
|
||||||
|
return List.of("-o");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return args.length == 2 && args[0].equalsIgnoreCase("-o") && silentCheckPermission(sender, "plex.setloginmessage") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
|
}
|
||||||
}
|
}
|
@ -7,7 +7,6 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -28,7 +27,7 @@ import java.time.ZonedDateTime;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.smite", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.smite", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
|
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
|
||||||
public class SmiteCMD extends PlexCommand
|
public class SmiteCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -96,12 +95,6 @@ public class SmiteCMD extends PlexCommand
|
|||||||
send(sender, "Smitten " + player.getName() + " quietly.");
|
send(sender, "Smitten " + player.getName() + " quietly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deop
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
player.setOp(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set gamemode to survival
|
// Set gamemode to survival
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
@ -142,9 +135,9 @@ public class SmiteCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (checkTab(sender, Rank.ADMIN, "plex.smite") && args.length == 1)
|
if (silentCheckPermission(sender, this.getPermission()) && args.length == 1)
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.GameModeUpdateEvent;
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode")
|
@CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode")
|
||||||
public class SpectatorCMD extends PlexCommand
|
public class SpectatorCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -36,7 +36,7 @@ public class SpectatorCMD extends PlexCommand
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
if (checkPermission(sender,"plex.gamemode.spectator.others"))
|
||||||
{
|
{
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
@ -56,9 +56,9 @@ public class SpectatorCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.spectator.others"))
|
if (silentCheckPermission(sender,"plex.gamemode.spectator.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import dev.plex.command.annotation.CommandPermissions;
|
|||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.event.GameModeUpdateEvent;
|
import dev.plex.event.GameModeUpdateEvent;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode")
|
@CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode")
|
||||||
public class SurvivalCMD extends PlexCommand
|
public class SurvivalCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -36,7 +36,7 @@ public class SurvivalCMD extends PlexCommand
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRank(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
if (checkPermission(sender,"plex.gamemode.survival.others"))
|
||||||
{
|
{
|
||||||
if (args[0].equals("-a"))
|
if (args[0].equals("-a"))
|
||||||
{
|
{
|
||||||
@ -57,9 +57,9 @@ public class SurvivalCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (checkTab(sender, Rank.ADMIN, "plex.gamemode.survival.others"))
|
if (silentCheckPermission(sender,"plex.gamemode.survival.others"))
|
||||||
{
|
{
|
||||||
return PlexUtils.getPlayerNameList();
|
return PlexUtils.getPlayerNameList();
|
||||||
}
|
}
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
package dev.plex.command.impl;
|
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
|
||||||
import dev.plex.command.PlexCommand;
|
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.inventory.Book;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandParameters(name = "totalfreedommod", description = "You can't simpy do that.", aliases = "tfm")
|
|
||||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
|
||||||
|
|
||||||
public class TFMCMD extends PlexCommand
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
|
||||||
{
|
|
||||||
if (playerSender != null)
|
|
||||||
{
|
|
||||||
String simpy = "It's not about credit or discredit, it's about copyright of TFM. Looking at Plex's source code, it looks like a bunch of copy-pasted source code from TFM and Aero (utility plugin). You just put it under a different license and pretended it's yours. You can't simpy do that. You have to remove all parts which infringe on the TFM license (as per the TFM repository) and the Aero License (as per the Aero repository) or otherwise comply to the license requirements.";
|
|
||||||
List<String> pages = Splitter.fixedLength(256).splitToList(simpy);
|
|
||||||
List<Component> pageComponents = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String page : pages)
|
|
||||||
{
|
|
||||||
pageComponents.add(PlexUtils.mmDeserialize("<rainbow>" + page + "</rainbow>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
playerSender.openBook(Book.builder()
|
|
||||||
.title(Component.text("TFM License"))
|
|
||||||
.author(Component.text("Prozza"))
|
|
||||||
.pages(pageComponents));
|
|
||||||
}
|
|
||||||
|
|
||||||
return PlexUtils.mmDeserialize("<rainbow>It's not about credit or discredit, it's about copyright of TFM.<br>Looking at Plex's source code, it looks like a bunch of copy-pasted source code from TFM and Aero (utility plugin). You just put it under a different license and pretended it's yours.<br>You can't simpy do that. You have to remove all parts which infringe on the TFM license (as per the TFM repository) and the Aero License (as per the Aero repository) or otherwise comply to the license requirements.</rainbow>");
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -19,7 +18,11 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.tag", source = RequiredCommandSource.ANY)
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.tag", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
|
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
|
||||||
public class TagCMD extends PlexCommand
|
public class TagCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -47,16 +50,15 @@ public class TagCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
return usage("/tag set <prefix>");
|
return usage("/tag set <prefix>");
|
||||||
}
|
}
|
||||||
String prefix = PlexUtils.cleanString(StringUtils.join(args, " ", 1, args.length));
|
|
||||||
|
|
||||||
Component convertedComponent = SafeMiniMessage.mmDeserializeWithoutEvents(prefix);
|
Component convertedComponent = PlexUtils.stringToComponent(StringUtils.join(args, " ", 1, args.length));
|
||||||
|
|
||||||
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
|
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
|
||||||
{
|
{
|
||||||
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
|
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setPrefix(prefix);
|
player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent));
|
||||||
DataUtils.update(player);
|
DataUtils.update(player);
|
||||||
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
|
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
|
||||||
}
|
}
|
||||||
@ -76,20 +78,39 @@ public class TagCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
|
PlexPlayer player = DataUtils.getPlayer(playerSender.getUniqueId());
|
||||||
player.setPrefix("");
|
player.setPrefix(null);
|
||||||
DataUtils.update(player);
|
DataUtils.update(player);
|
||||||
return messageComponent("prefixCleared");
|
return messageComponent("prefixCleared");
|
||||||
}
|
}
|
||||||
|
checkPermission(sender, "plex.tag.clear.others");
|
||||||
checkRank(sender, Rank.ADMIN, "plex.tag.clear.others");
|
|
||||||
Player target = getNonNullPlayer(args[1]);
|
Player target = getNonNullPlayer(args[1]);
|
||||||
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
|
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
|
||||||
plexTarget.setPrefix("");
|
plexTarget.setPrefix(null);
|
||||||
DataUtils.update(plexTarget);
|
DataUtils.update(plexTarget);
|
||||||
return messageComponent("otherPrefixCleared", target.getName());
|
return messageComponent("otherPrefixCleared", target.getName());
|
||||||
}
|
}
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
|
return Arrays.asList("set", "clear");
|
||||||
|
}
|
||||||
|
if (args.length == 2)
|
||||||
|
{
|
||||||
|
if (args[0].equalsIgnoreCase("clear"))
|
||||||
|
{
|
||||||
|
if (silentCheckPermission(sender, "plex.tag.clear.others"))
|
||||||
|
{
|
||||||
|
return PlexUtils.getPlayerNameList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,11 +10,10 @@ import dev.plex.command.source.RequiredCommandSource;
|
|||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.BungeeUtil;
|
import dev.plex.util.BungeeUtil;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.WebUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -23,11 +22,11 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player")
|
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
||||||
|
|
||||||
public class TempbanCMD extends PlexCommand
|
public class TempbanCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -39,65 +38,87 @@ public class TempbanCMD extends PlexCommand
|
|||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
PlexPlayer target = DataUtils.getPlayer(args[0]);
|
||||||
String reason;
|
String reason;
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (target == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
|
Player player = Bukkit.getPlayer(target.getUuid());
|
||||||
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
if (plugin.getPunishmentManager().isBanned(target.getUuid()))
|
||||||
Player player = Bukkit.getPlayer(targetUUID);
|
|
||||||
|
|
||||||
if (isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
if (!isConsole(sender))
|
|
||||||
{
|
|
||||||
assert playerSender != null;
|
|
||||||
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
|
||||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()) && plexPlayer.isAdminActive())
|
|
||||||
{
|
|
||||||
return messageComponent("higherRankThanYou");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.getPunishmentManager().isBanned(targetUUID))
|
|
||||||
{
|
{
|
||||||
return messageComponent("playerBanned");
|
return messageComponent("playerBanned");
|
||||||
}
|
}
|
||||||
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
Punishment punishment = new Punishment(target.getUuid(), getUUID(sender));
|
||||||
punishment.setType(PunishmentType.TEMPBAN);
|
punishment.setType(PunishmentType.TEMPBAN);
|
||||||
|
boolean rollBack = true;
|
||||||
if (args.length > 2)
|
if (args.length > 2)
|
||||||
{
|
{
|
||||||
reason = StringUtils.join(args, " ", 2, args.length);
|
reason = StringUtils.join(args, " ", 2, args.length);
|
||||||
punishment.setReason(reason);
|
String newReason = StringUtils.normalizeSpace(reason.replace("-nrb", ""));
|
||||||
|
punishment.setReason(newReason.trim().isEmpty() ? "No reason provided." : newReason);
|
||||||
|
rollBack = !reason.startsWith("-nrb") && !reason.endsWith("-nrb");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
punishment.setReason("No reason provided.");
|
punishment.setReason("No reason provided.");
|
||||||
}
|
}
|
||||||
punishment.setPunishedUsername(plexPlayer.getName());
|
punishment.setPunishedUsername(target.getName());
|
||||||
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
||||||
punishment.setCustomTime(false);
|
punishment.setCustomTime(false);
|
||||||
punishment.setActive(!isAdmin(plexPlayer));
|
punishment.setActive(true);
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||||
}
|
}
|
||||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
plugin.getPunishmentManager().punish(target, punishment);
|
||||||
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), target.getName()));
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
||||||
}
|
}
|
||||||
|
if (rollBack)
|
||||||
|
{
|
||||||
|
/*if (plugin.getPrismHook().hasPrism()) {
|
||||||
|
PrismParameters parameters = plugin.getPrismHook().prismApi().createParameters();
|
||||||
|
parameters.addActionType("block-place");
|
||||||
|
parameters.addActionType("block-break");
|
||||||
|
parameters.addActionType("block-burn");
|
||||||
|
parameters.addActionType("entity-spawn");
|
||||||
|
parameters.addActionType("entity-kill");
|
||||||
|
parameters.addActionType("entity-explode");
|
||||||
|
parameters.addPlayerName(plexPlayer.getName());
|
||||||
|
parameters.setBeforeTime(Instant.now().toEpochMilli());
|
||||||
|
parameters.setProcessType(PrismProcessType.ROLLBACK);
|
||||||
|
final Future<Result> result = plugin.getPrismHook().prismApi().performLookup(parameters, sender);
|
||||||
|
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask -> {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Result done = result.get();
|
||||||
|
} catch (InterruptedException | ExecutionException e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else */
|
||||||
|
if (plugin.getCoreProtectHook().hasCoreProtect())
|
||||||
|
{
|
||||||
|
PlexLog.debug("Testing coreprotect");
|
||||||
|
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
|
||||||
|
{
|
||||||
|
plugin.getCoreProtectHook().coreProtectAPI().performRollback(86400, Collections.singletonList(target.getName()), null, null, null, null, 0, null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@ import dev.plex.command.PlexCommand;
|
|||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.menu.ToggleMenu;
|
import dev.plex.menu.impl.ToggleMenu;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
@ -18,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandParameters(name = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles")
|
@CommandParameters(name = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.toggle", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.toggle", source = RequiredCommandSource.ANY)
|
||||||
public class ToggleCMD extends PlexCommand
|
public class ToggleCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -59,14 +58,14 @@ public class ToggleCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new ToggleMenu().openInv(playerSender, 0);
|
new ToggleMenu().open(playerSender);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String status(String toggle)
|
private String status(String toggle)
|
||||||
|
@ -9,9 +9,7 @@ import dev.plex.command.exception.PlayerNotBannedException;
|
|||||||
import dev.plex.command.exception.PlayerNotFoundException;
|
import dev.plex.command.exception.PlayerNotFoundException;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.WebUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -19,10 +17,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||||
|
|
||||||
public class UnbanCMD extends PlexCommand
|
public class UnbanCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -36,31 +33,30 @@ public class UnbanCMD extends PlexCommand
|
|||||||
|
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
UUID targetUUID = WebUtils.getFromName(args[0]);
|
PlexPlayer target = DataUtils.getPlayer(args[0]);
|
||||||
|
|
||||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
if (target == null)
|
||||||
{
|
{
|
||||||
throw new PlayerNotFoundException();
|
throw new PlayerNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) ->
|
plugin.getPunishmentManager().isAsyncBanned(target.getUuid()).whenComplete((aBoolean, throwable) ->
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID);
|
|
||||||
if (!aBoolean)
|
if (!aBoolean)
|
||||||
{
|
{
|
||||||
send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
|
send(sender, PlexUtils.mmDeserialize(new PlayerNotBannedException().getMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.getPunishmentManager().unban(targetUUID);
|
plugin.getPunishmentManager().unban(target.getUuid());
|
||||||
PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), plexPlayer.getName()));
|
PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), target.getName()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -16,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.unfreeze")
|
@CommandPermissions(permission = "plex.unfreeze")
|
||||||
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
|
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
|
||||||
public class UnfreezeCMD extends PlexCommand
|
public class UnfreezeCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -39,8 +38,8 @@ public class UnfreezeCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
|
|||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.exception.CommandFailException;
|
import dev.plex.command.exception.CommandFailException;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -16,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.ADMIN, permission = "plex.unmute")
|
@CommandPermissions(permission = "plex.unmute")
|
||||||
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>")
|
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>")
|
||||||
public class UnmuteCMD extends PlexCommand
|
public class UnmuteCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
@ -39,8 +38,8 @@ public class UnmuteCMD extends PlexCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
server/src/main/java/dev/plex/command/impl/WhoHasCMD.java
Normal file
52
server/src/main/java/dev/plex/command/impl/WhoHasCMD.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import dev.plex.command.PlexCommand;
|
||||||
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.JoinConfiguration;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@CommandPermissions(permission = "plex.whohas")
|
||||||
|
@CommandParameters(name = "whohas", description = "Returns a list of players with a specific item in their inventory.", usage = "/<command> <material>", aliases = "wh")
|
||||||
|
public class WhoHasCMD extends PlexCommand
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||||
|
{
|
||||||
|
if (args.length == 0)
|
||||||
|
{
|
||||||
|
return usage();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Material material = Material.getMaterial(args[0].toUpperCase());
|
||||||
|
|
||||||
|
if (material == null)
|
||||||
|
{
|
||||||
|
return messageComponent("materialNotFound", args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<TextComponent> players = Bukkit.getOnlinePlayers().stream().filter(player ->
|
||||||
|
player.getInventory().contains(material)).map(player -> Component.text(player.getName())).toList();
|
||||||
|
|
||||||
|
return players.isEmpty() ? messageComponent("nobodyHasThatMaterial") :
|
||||||
|
messageComponent("playersWithMaterial", Component.text(material.name()),
|
||||||
|
Component.join(JoinConfiguration.commas(true), players));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? Arrays.stream(Material.values()).map(Enum::name).toList() : ImmutableList.of();
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,13 @@
|
|||||||
package dev.plex.command.impl;
|
package dev.plex.command.impl;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.Lists;
|
||||||
|
import dev.plex.Plex;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.CommandParameters;
|
import dev.plex.command.annotation.CommandParameters;
|
||||||
import dev.plex.command.annotation.CommandPermissions;
|
import dev.plex.command.annotation.CommandPermissions;
|
||||||
import dev.plex.command.source.RequiredCommandSource;
|
import dev.plex.command.source.RequiredCommandSource;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -16,12 +15,15 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.world", source = RequiredCommandSource.IN_GAME)
|
@CommandPermissions(permission = "plex.world", source = RequiredCommandSource.IN_GAME)
|
||||||
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
|
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
|
||||||
public class WorldCMD extends PlexCommand
|
public class WorldCMD extends PlexCommand
|
||||||
{
|
{
|
||||||
|
private static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||||
{
|
{
|
||||||
@ -30,18 +32,44 @@ public class WorldCMD extends PlexCommand
|
|||||||
{
|
{
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = getNonNullWorld(args[0]);
|
World world = getNonNullWorld(args[0]);
|
||||||
playerSender.teleportAsync(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
|
boolean playerWorld = args[0].matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
|
||||||
|
if (playerWorld && Plex.get().getModuleManager().getModules().stream().anyMatch(plexModule -> plexModule.getPlexModuleFile().getName().equalsIgnoreCase("Module-TFMExtras")))
|
||||||
|
{
|
||||||
|
checkPermission(playerSender, "plex.world.playerworlds");
|
||||||
|
}
|
||||||
|
playerSender.teleportAsync(world.getSpawnLocation());
|
||||||
return messageComponent("playerWorldTeleport", world.getName());
|
return messageComponent("playerWorldTeleport", world.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (args.length == 1)
|
final List<String> completions = Lists.newArrayList();
|
||||||
|
final Player player = (Player) sender;
|
||||||
|
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||||
{
|
{
|
||||||
return Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList());
|
@NotNull List<World> worlds = Bukkit.getWorlds();
|
||||||
}
|
for (World world : worlds)
|
||||||
return ImmutableList.of();
|
{
|
||||||
|
String worldName = world.getName();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final UUID uuid = UUID.fromString(worldName);
|
||||||
|
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player, "plex.world.playerworlds"))
|
||||||
|
{
|
||||||
|
completions.add(worldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
completions.add(worldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return completions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package dev.plex.event;
|
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event that is run when a player is added to the admin list
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Data
|
|
||||||
public class AdminAddEvent extends Event
|
|
||||||
{
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The sender who added the player
|
|
||||||
*/
|
|
||||||
private final CommandSender sender;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The PlexPlayer that was added
|
|
||||||
*/
|
|
||||||
private final PlexPlayer plexPlayer;
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package dev.plex.event;
|
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event that is run when a player is removed from the admin list
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Data
|
|
||||||
public class AdminRemoveEvent extends Event
|
|
||||||
{
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The sender who added the player
|
|
||||||
*/
|
|
||||||
private final CommandSender sender;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The PlexPlayer that was removed
|
|
||||||
*/
|
|
||||||
private final PlexPlayer plexPlayer;
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package dev.plex.event;
|
|
||||||
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event that is run when an admins rank is set
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Data
|
|
||||||
public class AdminSetRankEvent extends Event
|
|
||||||
{
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The sender who added the player
|
|
||||||
*/
|
|
||||||
private final CommandSender sender;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The PlexPlayer that was removed
|
|
||||||
*/
|
|
||||||
private final PlexPlayer plexPlayer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The rank the player was set to
|
|
||||||
*/
|
|
||||||
private final Rank rank;
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers()
|
|
||||||
{
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,7 @@ package dev.plex.handlers;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import dev.plex.PlexBase;
|
import dev.plex.PlexBase;
|
||||||
import dev.plex.command.PlexCommand;
|
import dev.plex.command.PlexCommand;
|
||||||
import dev.plex.command.annotation.System;
|
import dev.plex.command.impl.DebugCMD;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.ReflectionsUtil;
|
import dev.plex.util.ReflectionsUtil;
|
||||||
|
|
||||||
@ -22,19 +22,10 @@ public class CommandHandler implements PlexBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (clazz.isAnnotationPresent(System.class))
|
if (plugin.config.getBoolean("debug") && DebugCMD.class.isAssignableFrom(clazz))
|
||||||
{
|
|
||||||
System annotation = clazz.getDeclaredAnnotation(System.class);
|
|
||||||
if (annotation.value().equalsIgnoreCase(plugin.getSystem().toLowerCase()))
|
|
||||||
{
|
{
|
||||||
commands.add(clazz.getConstructor().newInstance());
|
commands.add(clazz.getConstructor().newInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.config.getBoolean("debug") && annotation.debug())
|
|
||||||
{
|
|
||||||
commands.add(clazz.getConstructor().newInstance());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
commands.add(clazz.getConstructor().newInstance());
|
commands.add(clazz.getConstructor().newInstance());
|
||||||
|
63
server/src/main/java/dev/plex/hook/CoreProtectHook.java
Normal file
63
server/src/main/java/dev/plex/hook/CoreProtectHook.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package dev.plex.hook;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
|
import net.coreprotect.CoreProtect;
|
||||||
|
import net.coreprotect.CoreProtectAPI;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.milkbowl.vault.chat.Chat;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class CoreProtectHook
|
||||||
|
{
|
||||||
|
private CoreProtectAPI coreProtectAPI;
|
||||||
|
private boolean hasApi;
|
||||||
|
|
||||||
|
public CoreProtectHook(Plex plex)
|
||||||
|
{
|
||||||
|
Plugin plugin = plex.getServer().getPluginManager().getPlugin("CoreProtect");
|
||||||
|
|
||||||
|
// Check that CoreProtect is loaded
|
||||||
|
if (!(plugin instanceof CoreProtect))
|
||||||
|
{
|
||||||
|
PlexLog.debug("Plugin was not CoreProtect.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the API is enabled
|
||||||
|
CoreProtectAPI coreProtectAPI = ((CoreProtect) plugin).getAPI();
|
||||||
|
this.hasApi = coreProtectAPI.isEnabled();
|
||||||
|
if (!hasApi)
|
||||||
|
{
|
||||||
|
PlexLog.debug("CoreProtect API was disabled.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that a compatible version of the API is loaded
|
||||||
|
if (coreProtectAPI.APIVersion() < 9)
|
||||||
|
{
|
||||||
|
PlexLog.debug("CoreProtect API version is: {0}", coreProtectAPI.APIVersion());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.coreProtectAPI = coreProtectAPI;
|
||||||
|
this.coreProtectAPI.testAPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCoreProtect() {
|
||||||
|
return hasApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CoreProtectAPI coreProtectAPI()
|
||||||
|
{
|
||||||
|
return coreProtectAPI;
|
||||||
|
}
|
||||||
|
}
|
34
server/src/main/java/dev/plex/hook/PrismHook.java
Normal file
34
server/src/main/java/dev/plex/hook/PrismHook.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package dev.plex.hook;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import network.darkhelmet.prism.api.PrismApi;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class PrismHook
|
||||||
|
{
|
||||||
|
private PrismApi prismApi;
|
||||||
|
|
||||||
|
public PrismHook(Plex plex)
|
||||||
|
{
|
||||||
|
Plugin plugin = plex.getServer().getPluginManager().getPlugin("Prism");
|
||||||
|
|
||||||
|
// Check that Prism is loaded
|
||||||
|
if (!plugin.isEnabled())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the API is enabled
|
||||||
|
this.prismApi = (PrismApi) plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPrism() {
|
||||||
|
return prismApi != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrismApi prismApi()
|
||||||
|
{
|
||||||
|
return prismApi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,18 @@
|
|||||||
package dev.plex.hook;
|
package dev.plex.hook;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
||||||
import net.milkbowl.vault.chat.Chat;
|
import net.milkbowl.vault.chat.Chat;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class VaultHook
|
public class VaultHook
|
||||||
{
|
{
|
||||||
private static Chat CHAT;
|
private static Chat CHAT;
|
||||||
@ -51,20 +54,36 @@ public class VaultHook
|
|||||||
return PERMISSIONS;
|
return PERMISSIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Component getPrefix(UUID uuid)
|
||||||
|
{
|
||||||
|
return getPrefix(Bukkit.getOfflinePlayer(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
public static Component getPrefix(PlexPlayer plexPlayer)
|
public static Component getPrefix(PlexPlayer plexPlayer)
|
||||||
|
{
|
||||||
|
return getPrefix(Bukkit.getOfflinePlayer(plexPlayer.getUuid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component getPrefix(OfflinePlayer player)
|
||||||
{
|
{
|
||||||
if (VaultHook.getChat() == null || VaultHook.getPermission() == null)
|
if (VaultHook.getChat() == null || VaultHook.getPermission() == null)
|
||||||
{
|
{
|
||||||
return null;
|
return Component.empty();
|
||||||
}
|
}
|
||||||
if (Plex.get().getRankManager().getConfigPrefixes(plexPlayer) != null)
|
if (PlexUtils.DEVELOPERS.contains(player.getUniqueId().toString()))
|
||||||
{
|
{
|
||||||
return Plex.get().getRankManager().getConfigPrefixes(plexPlayer);
|
return PlexUtils.mmDeserialize("<dark_gray>[<dark_purple>Developer<dark_gray>]");
|
||||||
}
|
}
|
||||||
Player bukkitPlayer = Bukkit.getPlayer(plexPlayer.getUuid());
|
String group = VaultHook.getPermission().getPrimaryGroup(null, player);
|
||||||
String group = VaultHook.getPermission().getPrimaryGroup(bukkitPlayer);
|
if (group == null || group.isEmpty()) {
|
||||||
String vaultPrefix = VaultHook.getChat().getGroupPrefix(bukkitPlayer.getWorld(), group);
|
return Component.empty();
|
||||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(vaultPrefix);
|
}
|
||||||
|
String vaultPrefix = VaultHook.getChat().getGroupPrefix((String) null, group);
|
||||||
|
if (vaultPrefix == null || vaultPrefix.isEmpty()) {
|
||||||
|
return Component.empty();
|
||||||
|
}
|
||||||
|
PlexLog.debug("prefix: {0}", SafeMiniMessage.mmSerializeWithoutEvents(PlexUtils.stringToComponent(vaultPrefix)).replace("<", "\\<"));
|
||||||
|
return PlexUtils.stringToComponent(vaultPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Permission getPermission()
|
public static Permission getPermission()
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
package dev.plex.listener.impl;
|
|
||||||
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.event.AdminAddEvent;
|
|
||||||
import dev.plex.event.AdminRemoveEvent;
|
|
||||||
import dev.plex.event.AdminSetRankEvent;
|
|
||||||
import dev.plex.listener.PlexListener;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
|
|
||||||
import static dev.plex.util.PlexUtils.messageComponent;
|
|
||||||
|
|
||||||
public class AdminListener extends PlexListener
|
|
||||||
{
|
|
||||||
@EventHandler
|
|
||||||
public void onAdminAdd(AdminAddEvent event)
|
|
||||||
{
|
|
||||||
String userSender = event.getSender().getName();
|
|
||||||
PlexPlayer target = event.getPlexPlayer();
|
|
||||||
if (target.getRankFromString().isAtLeast(Rank.ADMIN))
|
|
||||||
{
|
|
||||||
PlexUtils.broadcast(messageComponent("adminReadded", userSender, target.getName(), target.getRankFromString().getReadable()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
target.setRank(Rank.ADMIN.name());
|
|
||||||
PlexUtils.broadcast(messageComponent("newAdminAdded", userSender, target.getName()));
|
|
||||||
}
|
|
||||||
target.setAdminActive(true);
|
|
||||||
DataUtils.update(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onAdminRemove(AdminRemoveEvent event)
|
|
||||||
{
|
|
||||||
String userSender = event.getSender().getName();
|
|
||||||
PlexPlayer target = event.getPlexPlayer();
|
|
||||||
target.setAdminActive(false);
|
|
||||||
DataUtils.update(target);
|
|
||||||
PlexUtils.broadcast(messageComponent("adminRemoved", userSender, target.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onAdminSetRank(AdminSetRankEvent event)
|
|
||||||
{
|
|
||||||
String userSender = event.getSender().getName();
|
|
||||||
PlexPlayer target = event.getPlexPlayer();
|
|
||||||
Rank newRank = event.getRank();
|
|
||||||
target.setRank(newRank.name().toLowerCase());
|
|
||||||
DataUtils.update(target);
|
|
||||||
PlexUtils.broadcast(messageComponent("adminSetRank", userSender, target.getName(), newRank.getReadable()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,15 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
|
import dev.plex.punishment.PunishmentManager;
|
||||||
import dev.plex.punishment.PunishmentType;
|
import dev.plex.punishment.PunishmentType;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
|
|
||||||
@ -13,33 +18,53 @@ public class BanListener extends PlexListener
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
||||||
{
|
{
|
||||||
if (plugin.getPunishmentManager().isIndefUUIDBanned(event.getUniqueId()))
|
final PunishmentManager.IndefiniteBan uuidBan = plugin.getPunishmentManager().getIndefiniteBanByUUID(event.getUniqueId());
|
||||||
|
if (uuidBan != null)
|
||||||
{
|
{
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateIndefBanMessage("UUID"));
|
!uuidBan.getReason().isEmpty() ? Punishment.generateIndefBanMessageWithReason("UUID", uuidBan.getReason()) : Punishment.generateIndefBanMessage("UUID"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getPunishmentManager().isIndefIPBanned(event.getAddress().getHostAddress()))
|
final PunishmentManager.IndefiniteBan ipBan = plugin.getPunishmentManager().getIndefiniteBanByIP(event.getAddress().getHostAddress());
|
||||||
|
if (ipBan != null)
|
||||||
{
|
{
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateIndefBanMessage("IP"));
|
!ipBan.getReason().isEmpty() ? Punishment.generateIndefBanMessageWithReason("IP", ipBan.getReason()) : Punishment.generateIndefBanMessage("IP"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getPunishmentManager().isIndefUserBanned(event.getName()))
|
final PunishmentManager.IndefiniteBan userBan = plugin.getPunishmentManager().getIndefiniteBanByUsername(event.getName());
|
||||||
|
|
||||||
|
if (userBan != null)
|
||||||
{
|
{
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateIndefBanMessage("username"));
|
!userBan.getReason().isEmpty() ? Punishment.generateIndefBanMessageWithReason("username", userBan.getReason()) : Punishment.generateIndefBanMessage("username"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
|
if (plugin.getPunishmentManager().isBanned(event.getUniqueId()))
|
||||||
{
|
{
|
||||||
|
if (Plex.get().getPermissions() != null && Plex.get().getPermissions().playerHas(null, Bukkit.getOfflinePlayer(event.getUniqueId()), "plex.ban.bypass"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
PlexPlayer player = DataUtils.getPlayer(event.getUniqueId());
|
PlexPlayer player = DataUtils.getPlayer(event.getUniqueId());
|
||||||
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
|
player.getPunishments().stream().filter(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive()).findFirst().ifPresent(punishment ->
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
Punishment.generateBanMessage(punishment)));
|
Punishment.generateBanMessage(punishment)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Punishment ipBannedPunishment = plugin.getPunishmentManager().getBanByIP(event.getAddress().getHostAddress());
|
||||||
|
if (ipBannedPunishment != null)
|
||||||
|
{
|
||||||
|
// Don't check if the other account that's banned has bypass abilities, check if current has only
|
||||||
|
if (Plex.get().getPermissions() != null && Plex.get().getPermissions().playerHas(null, Bukkit.getOfflinePlayer(event.getUniqueId()), "plex.ban.bypass"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED,
|
||||||
|
Punishment.generateBanMessage(ipBannedPunishment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class BookListener extends PlexListener
|
public class BookListener extends PlexListener
|
||||||
{
|
{
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onBookEdit(PlayerEditBookEvent event)
|
public void onBookEdit(PlayerEditBookEvent event)
|
||||||
{
|
{
|
||||||
List<Component> pages = new ArrayList<>();
|
List<Component> pages = new ArrayList<>();
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.hook.VaultHook;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.listener.annotation.Toggleable;
|
import dev.plex.listener.annotation.Toggleable;
|
||||||
|
import dev.plex.meta.PlayerMeta;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
@ -15,15 +17,16 @@ import net.kyori.adventure.text.event.ClickEvent;
|
|||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Toggleable("chat.enabled")
|
@Toggleable("chat.enabled")
|
||||||
public class ChatListener extends PlexListener
|
public class ChatListener extends PlexListener
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig
|
public static final TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig
|
||||||
.builder()
|
.builder()
|
||||||
.match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]")
|
.match("(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]")
|
||||||
@ -32,22 +35,24 @@ public class ChatListener extends PlexListener
|
|||||||
.clickEvent(ClickEvent.openUrl(
|
.clickEvent(ClickEvent.openUrl(
|
||||||
matchResult.group()
|
matchResult.group()
|
||||||
))).build();
|
))).build();
|
||||||
|
public static BiConsumer<AsyncChatEvent, PlexPlayer> PRE_RENDERER = ChatListener::defaultChatProcessing;
|
||||||
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
private final PlexChatRenderer renderer = new PlexChatRenderer();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onChat(AsyncChatEvent event)
|
public void onChat(AsyncChatEvent event)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||||
if (plexPlayer.isStaffChat())
|
if (plexPlayer.isStaffChat())
|
||||||
{
|
{
|
||||||
MessageUtil.sendStaffChat(event.getPlayer(), event.message(), PlexUtils.adminChat(event.getPlayer().getName(), SafeMiniMessage.mmSerialize(event.message())).toArray(UUID[]::new));
|
String prefix = PlexUtils.mmSerialize(VaultHook.getPrefix(event.getPlayer())); // Don't use PlexPlayer#getPrefix because that returns their custom set prefix and not their group's
|
||||||
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", event.getPlayer().getName(), SafeMiniMessage.mmSerialize(event.message())).replaceText(URL_REPLACEMENT_CONFIG));
|
MessageUtil.sendStaffChat(event.getPlayer(), event.message(), PlexUtils.adminChat(event.getPlayer().getName(), prefix, SafeMiniMessage.mmSerialize(event.message())).toArray(UUID[]::new));
|
||||||
|
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", event.getPlayer().getName(), prefix, SafeMiniMessage.mmSerialize(event.message().replaceText(URL_REPLACEMENT_CONFIG))));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Component prefix = plugin.getRankManager().getPrefix(plexPlayer);
|
Component prefix = PlayerMeta.getPrefix(plexPlayer);
|
||||||
|
|
||||||
if (prefix != null)
|
if (prefix != null && !prefix.equals(Component.empty()) && !prefix.equals(Component.space()))
|
||||||
{
|
{
|
||||||
renderer.hasPrefix = true;
|
renderer.hasPrefix = true;
|
||||||
renderer.prefix = prefix;
|
renderer.prefix = prefix;
|
||||||
@ -58,6 +63,8 @@ public class ChatListener extends PlexListener
|
|||||||
renderer.prefix = null;
|
renderer.prefix = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRE_RENDERER.accept(event, plexPlayer);
|
||||||
|
|
||||||
event.renderer(renderer);
|
event.renderer(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +77,6 @@ public class ChatListener extends PlexListener
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
|
public @NotNull Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer)
|
||||||
{
|
{
|
||||||
String text = PlexUtils.cleanString(PlexUtils.getTextFromComponent(message));
|
|
||||||
|
|
||||||
Component component = Component.empty();
|
Component component = Component.empty();
|
||||||
|
|
||||||
if (before != null)
|
if (before != null)
|
||||||
@ -92,8 +97,14 @@ public class ChatListener extends PlexListener
|
|||||||
.append(Component.space())
|
.append(Component.space())
|
||||||
.append(Component.text("»").color(NamedTextColor.GRAY))
|
.append(Component.text("»").color(NamedTextColor.GRAY))
|
||||||
.append(Component.space())
|
.append(Component.space())
|
||||||
.append(SafeMiniMessage.mmDeserializeWithoutEvents(text))
|
.append(message)
|
||||||
.replaceText(URL_REPLACEMENT_CONFIG);
|
.replaceText(URL_REPLACEMENT_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void defaultChatProcessing(AsyncChatEvent event, PlexPlayer plexPlayer)
|
||||||
|
{
|
||||||
|
String text = PlexUtils.getTextFromComponent(event.message());
|
||||||
|
event.message(PlexUtils.stringToComponent(text));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.command.blocking.BlockedCommand;
|
import dev.plex.command.blocking.BlockedCommand;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.services.impl.CommandBlockerService;
|
import dev.plex.services.impl.CommandBlockerService;
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -46,6 +47,7 @@ public class CommandListener extends PlexListener
|
|||||||
{
|
{
|
||||||
String command = "/" + event.getMessage().replaceFirst("/", "").trim();
|
String command = "/" + event.getMessage().replaceFirst("/", "").trim();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
if (Plex.get().getPermissions() != null && Plex.get().getPermissions().has(player, "plex.commandblocker.bypass")) return;
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||||
String commandName = StringUtils.normalizeSpace(command).split(" ")[0].replaceFirst("/", "");
|
String commandName = StringUtils.normalizeSpace(command).split(" ")[0].replaceFirst("/", "");
|
||||||
String arguments = StringUtils.normalizeSpace(StringUtils.normalizeSpace(command).replace(command.split(" ")[0], ""));
|
String arguments = StringUtils.normalizeSpace(StringUtils.normalizeSpace(command).replace(command.split(" ")[0], ""));
|
||||||
@ -106,7 +108,10 @@ public class CommandListener extends PlexListener
|
|||||||
if (cmdRef.get() != null)
|
if (cmdRef.get() != null)
|
||||||
{
|
{
|
||||||
BlockedCommand cmd = cmdRef.get();
|
BlockedCommand cmd = cmdRef.get();
|
||||||
switch (cmd.getRequiredLevel().toLowerCase(Locale.ROOT))
|
event.setCancelled(true);
|
||||||
|
event.getPlayer().sendMessage(cmd.getMessage());
|
||||||
|
//TODO: Look into removing this or fixing it so they require permissions instead
|
||||||
|
/*switch (cmd.getRequiredLevel().toLowerCase(Locale.ROOT))
|
||||||
{
|
{
|
||||||
case "e" ->
|
case "e" ->
|
||||||
{
|
{
|
||||||
@ -131,20 +136,12 @@ public class CommandListener extends PlexListener
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage(cmd.getMessage());
|
event.getPlayer().sendMessage(cmd.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasCommandSpy(PlexPlayer plexPlayer)
|
private boolean hasCommandSpy(PlexPlayer plexPlayer)
|
||||||
{
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
return plexPlayer.isAdminActive();
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
{
|
||||||
return plexPlayer.getPlayer().hasPermission("plex.commandspy");
|
return plexPlayer.getPlayer().hasPermission("plex.commandspy");
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.menu.AbstractMenu;
|
||||||
|
import dev.plex.menu.pagination.PageableMenu;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taah
|
||||||
|
* @since 7:01 AM [02-09-2023]
|
||||||
|
*/
|
||||||
|
public class MenuListener extends PlexListener
|
||||||
|
{
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onClick(InventoryClickEvent event)
|
||||||
|
{
|
||||||
|
if (event.getClickedInventory() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getCurrentItem() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(event.getWhoClicked() instanceof Player player))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractMenu.INVENTORIES.entrySet().stream().filter(entry -> entry.getKey().equals(event.getView().title()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(entry ->
|
||||||
|
{
|
||||||
|
if (entry.getValue() instanceof PageableMenu.Page page)
|
||||||
|
{
|
||||||
|
final ItemMeta meta = event.getCurrentItem().getItemMeta();
|
||||||
|
if (meta != null && meta.displayName() != null)
|
||||||
|
{
|
||||||
|
if (meta.displayName().equals(PageableMenu.PREVIOUS.getItemMeta().displayName()))
|
||||||
|
{
|
||||||
|
page.parent().currentPage(page.parent().currentPage() - 1);
|
||||||
|
page.parent().open(player, page.parent().currentPage());
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (meta.displayName().equals(PageableMenu.NEXT.getItemMeta().displayName()))
|
||||||
|
{
|
||||||
|
page.parent().currentPage(page.parent().currentPage() + 1);
|
||||||
|
page.parent().open(player, page.parent().currentPage());
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (meta.displayName().equals(PageableMenu.CLOSE.getItemMeta().displayName()))
|
||||||
|
{
|
||||||
|
player.closeInventory();
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.setCancelled(entry.getValue().onClick(event.getView(), event.getClickedInventory(), player, event.getCurrentItem()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Ageable;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
@ -53,6 +54,7 @@ public class MobListener extends PlexListener
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntitySpawn(EntitySpawnEvent event)
|
public void onEntitySpawn(EntitySpawnEvent event)
|
||||||
{
|
{
|
||||||
|
if (event.isCancelled()) return;
|
||||||
if (event.getEntity().getEntitySpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG)
|
if (event.getEntity().getEntitySpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG)
|
||||||
{
|
{
|
||||||
// for the future, we can instead filter and restrict nbt tags right here.
|
// for the future, we can instead filter and restrict nbt tags right here.
|
||||||
@ -84,12 +86,14 @@ public class MobListener extends PlexListener
|
|||||||
{
|
{
|
||||||
blockLoc.getWorld().spawnEntity(blockLoc, eggType);
|
blockLoc.getWorld().spawnEntity(blockLoc, eggType);
|
||||||
}
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityClick(PlayerInteractEntityEvent event)
|
public void onEntityClick(PlayerInteractEntityEvent event)
|
||||||
{
|
{
|
||||||
|
if (event.isCancelled()) return;
|
||||||
Material handItem = event.getPlayer().getEquipment().getItem(event.getHand()).getType();
|
Material handItem = event.getPlayer().getEquipment().getItem(event.getHand()).getType();
|
||||||
if (event.getRightClicked() instanceof Ageable entity)
|
if (event.getRightClicked() instanceof Ageable entity)
|
||||||
{
|
{
|
||||||
@ -111,6 +115,8 @@ public class MobListener extends PlexListener
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event)
|
public void onPlayerInteract(PlayerInteractEvent event)
|
||||||
{
|
{
|
||||||
|
if (event.useItemInHand() == Event.Result.DENY) return;
|
||||||
|
if (event.useInteractedBlock() == Event.Result.DENY) return;
|
||||||
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
||||||
{
|
{
|
||||||
if (SPAWN_EGGS.contains(event.getMaterial()))
|
if (SPAWN_EGGS.contains(event.getMaterial()))
|
||||||
|
@ -2,9 +2,8 @@ package dev.plex.listener.impl;
|
|||||||
|
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.meta.PlayerMeta;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.storage.StorageType;
|
|
||||||
import dev.plex.util.PermissionsUtil;
|
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -30,17 +29,6 @@ public class PlayerListener<T> extends PlexListener
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlexPlayer plexPlayer;
|
PlexPlayer plexPlayer;
|
||||||
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
player.setOp(true);
|
|
||||||
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
|
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
player.setOp(false);
|
|
||||||
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DataUtils.hasPlayedBefore(player.getUniqueId()))
|
if (!DataUtils.hasPlayedBefore(player.getUniqueId()))
|
||||||
{
|
{
|
||||||
PlexLog.log("A player with this name has not joined the server before, creating new entry.");
|
PlexLog.log("A player with this name has not joined the server before, creating new entry.");
|
||||||
@ -74,49 +62,30 @@ public class PlayerListener<T> extends PlexListener
|
|||||||
player.openInventory(player.getInventory());
|
player.openInventory(player.getInventory());
|
||||||
}
|
}
|
||||||
|
|
||||||
String loginMessage = plugin.getRankManager().getLoginMessage(plexPlayer);
|
String loginMessage = PlayerMeta.getLoginMessage(plexPlayer);
|
||||||
if (!loginMessage.isEmpty())
|
if (!loginMessage.isEmpty())
|
||||||
{
|
{
|
||||||
PlexUtils.broadcast(loginMessage);
|
PlexUtils.broadcast(PlexUtils.stringToComponent(loginMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
PermissionsUtil.setupPermissions(player);
|
|
||||||
|
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
plexPlayer.loadNotes();
|
plexPlayer.loadNotes();
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
plexPlayer.loadPunishments();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||||
{
|
{
|
||||||
String plural = notes.size() == 1 ? "note." : "notes.";
|
String plural = notes.size() == 1 ? "note." : "notes.";
|
||||||
if (!notes.isEmpty())
|
if (!notes.isEmpty())
|
||||||
{
|
{
|
||||||
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD));
|
PlexUtils.broadcastToAdmins(Component.text(plexPlayer.getName() + " has " + notes.size() + " " + plural).color(NamedTextColor.GOLD), "plex.notes.notify");
|
||||||
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD));
|
PlexUtils.broadcastToAdmins(Component.text("Click to view their " + plural).clickEvent(ClickEvent.runCommand("/notes " + plexPlayer.getName() + " list")).color(NamedTextColor.GOLD), "plex.notes.notify");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// saving the player's data
|
// saving the player's data
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerSave(PlayerQuitEvent event)
|
public void onPlayerSave(PlayerQuitEvent event)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
||||||
|
|
||||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
plugin.getAdminList().removeFromCache(plexPlayer.getUuid());
|
|
||||||
}
|
|
||||||
|
|
||||||
DataUtils.update(plexPlayer);
|
DataUtils.update(plexPlayer);
|
||||||
plugin.getPlayerCache().getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
plugin.getPlayerCache().getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package dev.plex.listener.impl;
|
|
||||||
|
|
||||||
import dev.plex.listener.PlexListener;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
|
||||||
|
|
||||||
public class SignListener extends PlexListener
|
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onSignEdit(SignChangeEvent event)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < event.lines().size(); i++)
|
|
||||||
{
|
|
||||||
event.line(i, SafeMiniMessage.mmDeserialize(PlexUtils.getTextFromComponent(event.line(i))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,12 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.event.AdminAddEvent;
|
import dev.plex.hook.VaultHook;
|
||||||
import dev.plex.event.AdminRemoveEvent;
|
|
||||||
import dev.plex.event.AdminSetRankEvent;
|
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
|
import dev.plex.meta.PlayerMeta;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import net.kyori.adventure.text.Component;
|
import dev.plex.util.PlexUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -19,42 +19,6 @@ public class TabListener extends PlexListener
|
|||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
PlexPlayer plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
player.playerListName(PlexUtils.mmDeserialize(PlayerMeta.getColor(plexPlayer) + player.getName()));
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onAdminAdd(AdminAddEvent event)
|
|
||||||
{
|
|
||||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
|
||||||
Player player = event.getPlexPlayer().getPlayer();
|
|
||||||
if (player == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onAdminRemove(AdminRemoveEvent event)
|
|
||||||
{
|
|
||||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
|
||||||
Player player = event.getPlexPlayer().getPlayer();
|
|
||||||
if (player == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onAdminSetRank(AdminSetRankEvent event)
|
|
||||||
{
|
|
||||||
PlexPlayer plexPlayer = event.getPlexPlayer();
|
|
||||||
Player player = event.getPlexPlayer().getPlayer();
|
|
||||||
if (player == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.playerListName(Component.text(player.getName()).color(plugin.getRankManager().getColor(plexPlayer)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package dev.plex.listener.impl;
|
|||||||
|
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.block.BlockExplodeEvent;
|
||||||
import org.bukkit.event.block.BlockFromToEvent;
|
import org.bukkit.event.block.BlockFromToEvent;
|
||||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
@ -11,10 +12,20 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
|||||||
public class TogglesListener extends PlexListener
|
public class TogglesListener extends PlexListener
|
||||||
{
|
{
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockExplode(ExplosionPrimeEvent event)
|
public void onExplosionPrime(ExplosionPrimeEvent event)
|
||||||
{
|
{
|
||||||
if (!plugin.toggles.getBoolean("explosions"))
|
if (!plugin.toggles.getBoolean("explosions"))
|
||||||
{
|
{
|
||||||
|
event.getEntity().remove();
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockExplode(BlockExplodeEvent event) {
|
||||||
|
if (!plugin.toggles.getBoolean("explosions"))
|
||||||
|
{
|
||||||
|
event.getBlock().breakNaturally();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,6 +35,7 @@ public class TogglesListener extends PlexListener
|
|||||||
{
|
{
|
||||||
if (!plugin.toggles.getBoolean("explosions"))
|
if (!plugin.toggles.getBoolean("explosions"))
|
||||||
{
|
{
|
||||||
|
event.getEntity().remove();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.listener.PlexListener;
|
import dev.plex.listener.PlexListener;
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.rank.enums.Title;
|
|
||||||
import dev.plex.util.PlexLog;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.data.Openable;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -20,20 +15,18 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class WorldListener extends PlexListener
|
public class WorldListener extends PlexListener
|
||||||
{
|
{
|
||||||
private final List<String> EDIT_COMMANDS = Arrays.asList("bigtree", "ebigtree", "largetree", "elargetree", "break", "ebreak", "antioch", "nuke", "editsign", "tree", "etree");
|
private final List<String> EDIT_COMMANDS = Arrays.asList("bigtree", "ebigtree", "largetree", "elargetree", "break", "ebreak", "antioch", "nuke", "editsign", "tree", "etree");
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onBlockPlace(BlockPlaceEvent event)
|
public void onBlockPlace(BlockPlaceEvent event)
|
||||||
{
|
{
|
||||||
if (!canModifyWorld(event.getPlayer(), true))
|
if (!canModifyWorld(event.getPlayer(), true))
|
||||||
@ -42,7 +35,7 @@ public class WorldListener extends PlexListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onBlockBreak(BlockBreakEvent event)
|
public void onBlockBreak(BlockBreakEvent event)
|
||||||
{
|
{
|
||||||
if (!canModifyWorld(event.getPlayer(), true))
|
if (!canModifyWorld(event.getPlayer(), true))
|
||||||
@ -51,7 +44,45 @@ public class WorldListener extends PlexListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onInteractWorld(PlayerInteractEvent event)
|
||||||
|
{
|
||||||
|
if (event.getInteractionPoint() != null && event.getInteractionPoint().getBlock().getBlockData() instanceof Openable) return;
|
||||||
|
if (!canModifyWorld(event.getPlayer(), true))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onInteractWorld(PlayerInteractEntityEvent event)
|
||||||
|
{
|
||||||
|
if (!canModifyWorld(event.getPlayer(), true))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onInteractWorld(PlayerItemDamageEvent event)
|
||||||
|
{
|
||||||
|
if (!canModifyWorld(event.getPlayer(), true))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onInteractWorld(EntityDamageByEntityEvent event)
|
||||||
|
{
|
||||||
|
if (!(event.getDamager() instanceof Player player)) return;
|
||||||
|
if (!canModifyWorld(player, true))
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onEntitySpawn(EntitySpawnEvent event)
|
public void onEntitySpawn(EntitySpawnEvent event)
|
||||||
{
|
{
|
||||||
if (event.getEntityType() != EntityType.SLIME)
|
if (event.getEntityType() != EntityType.SLIME)
|
||||||
@ -87,56 +118,15 @@ public class WorldListener extends PlexListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onWorldTeleport(PlayerTeleportEvent event)
|
public void onWorldTeleport(PlayerTeleportEvent event)
|
||||||
{
|
{
|
||||||
if (!canEnterWorld(event.getPlayer()))
|
if (!canEnterWorld(event.getPlayer(), event.getTo().getWorld()))
|
||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkLevel(PlexPlayer player, String[] requiredList)
|
|
||||||
{
|
|
||||||
PlexLog.debug("Checking world required levels " + Arrays.toString(requiredList));
|
|
||||||
boolean hasAccess = false;
|
|
||||||
for (String required : requiredList)
|
|
||||||
{
|
|
||||||
PlexLog.debug("Checking if player has " + required);
|
|
||||||
if (required.startsWith("Title"))
|
|
||||||
{
|
|
||||||
String titleString = required.split("\\.")[1];
|
|
||||||
Title title = Title.valueOf(titleString.toUpperCase(Locale.ROOT));
|
|
||||||
switch (title)
|
|
||||||
{
|
|
||||||
case DEV ->
|
|
||||||
{
|
|
||||||
hasAccess = PlexUtils.DEVELOPERS.contains(player.getUuid().toString());
|
|
||||||
}
|
|
||||||
case MASTER_BUILDER ->
|
|
||||||
{
|
|
||||||
hasAccess = Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName());
|
|
||||||
}
|
|
||||||
case OWNER ->
|
|
||||||
{
|
|
||||||
hasAccess = Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName());
|
|
||||||
}
|
|
||||||
default ->
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (required.startsWith("Rank"))
|
|
||||||
{
|
|
||||||
String rankString = required.split("\\.")[1];
|
|
||||||
Rank rank = Rank.valueOf(rankString.toUpperCase(Locale.ROOT));
|
|
||||||
hasAccess = rank.isAtLeast(Rank.ADMIN) ? player.isAdminActive() && player.getRankFromString().isAtLeast(rank) : player.getRankFromString().isAtLeast(rank);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasAccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a Player has the ability to modify the world they are in
|
* Check if a Player has the ability to modify the world they are in
|
||||||
*
|
*
|
||||||
@ -146,10 +136,7 @@ public class WorldListener extends PlexListener
|
|||||||
*/
|
*/
|
||||||
private boolean canModifyWorld(Player player, boolean showMessage)
|
private boolean canModifyWorld(Player player, boolean showMessage)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
|
||||||
World world = player.getWorld();
|
World world = player.getWorld();
|
||||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".modification.permission");
|
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".modification.permission");
|
||||||
if (permission == null)
|
if (permission == null)
|
||||||
{
|
{
|
||||||
@ -159,22 +146,6 @@ public class WorldListener extends PlexListener
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".modification.requiredLevels"))
|
|
||||||
{
|
|
||||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".modification.requiredLevels");
|
|
||||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showMessage)
|
if (showMessage)
|
||||||
{
|
{
|
||||||
@ -193,13 +164,9 @@ public class WorldListener extends PlexListener
|
|||||||
* @param player The player who wants to enter the world
|
* @param player The player who wants to enter the world
|
||||||
* @return Returns true if the person has the ability to enter the world
|
* @return Returns true if the person has the ability to enter the world
|
||||||
*/
|
*/
|
||||||
private boolean canEnterWorld(Player player)
|
private boolean canEnterWorld(Player player, World destination)
|
||||||
{
|
{
|
||||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
String permission = plugin.config.getString("worlds." + destination.getName().toLowerCase() + ".entry.permission");
|
||||||
World world = player.getWorld();
|
|
||||||
if (plugin.getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".entry.permission");
|
|
||||||
if (permission == null)
|
if (permission == null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@ -208,24 +175,8 @@ public class WorldListener extends PlexListener
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
|
|
||||||
{
|
|
||||||
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".entry.requiredLevels"))
|
|
||||||
{
|
|
||||||
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".entry.requiredLevels");
|
|
||||||
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String noEntry = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".entry.message");
|
String noEntry = plugin.config.getString("worlds." + destination.getName().toLowerCase() + ".entry.message");
|
||||||
if (noEntry != null)
|
if (noEntry != null)
|
||||||
{
|
{
|
||||||
player.sendMessage(MiniMessage.miniMessage().deserialize(noEntry));
|
player.sendMessage(MiniMessage.miniMessage().deserialize(noEntry));
|
||||||
|
66
server/src/main/java/dev/plex/menu/AbstractMenu.java
Normal file
66
server/src/main/java/dev/plex/menu/AbstractMenu.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package dev.plex.menu;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taah
|
||||||
|
* @since 6:49 AM [02-09-2023]
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public abstract class AbstractMenu
|
||||||
|
{
|
||||||
|
public static final Map<Component, AbstractMenu> INVENTORIES = Maps.newHashMap();
|
||||||
|
private final Component name;
|
||||||
|
private final Inventory inventory;
|
||||||
|
|
||||||
|
public AbstractMenu(Component name, Rows rows)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.inventory = Bukkit.createInventory(null, rows.slots, name);
|
||||||
|
|
||||||
|
INVENTORIES.put(name, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractMenu(String name, Rows rows)
|
||||||
|
{
|
||||||
|
this(SafeMiniMessage.mmDeserializeWithoutEvents(name), rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean onClick(InventoryView view, Inventory inventory, Player player, ItemStack clicked);
|
||||||
|
|
||||||
|
public void open(Player player)
|
||||||
|
{
|
||||||
|
player.openInventory(this.inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Rows
|
||||||
|
{
|
||||||
|
ONE(9), TWO(18), THREE(27), FOUR(36), FIVE(45), SIX(54);
|
||||||
|
|
||||||
|
private final int slots;
|
||||||
|
|
||||||
|
Rows(int slots)
|
||||||
|
{
|
||||||
|
this.slots = slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int slots()
|
||||||
|
{
|
||||||
|
return this.slots;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,192 +0,0 @@
|
|||||||
package dev.plex.menu;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.punishment.Punishment;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import dev.plex.util.menu.AbstractMenu;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PunishedPlayerMenu extends AbstractMenu
|
|
||||||
{
|
|
||||||
private final PlexPlayer punishedPlayer;
|
|
||||||
|
|
||||||
private final List<Inventory> inventories = Lists.newArrayList();
|
|
||||||
|
|
||||||
public PunishedPlayerMenu(PlexPlayer player)
|
|
||||||
{
|
|
||||||
super("§c§lPunishments");
|
|
||||||
this.punishedPlayer = player;
|
|
||||||
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
|
||||||
{
|
|
||||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
|
||||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
|
||||||
ItemMeta meta = nextPage.getItemMeta();
|
|
||||||
meta.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
|
||||||
nextPage.setItemMeta(meta);
|
|
||||||
|
|
||||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
|
||||||
ItemMeta meta2 = previousPage.getItemMeta();
|
|
||||||
meta2.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
|
||||||
previousPage.setItemMeta(meta2);
|
|
||||||
|
|
||||||
ItemStack back = new ItemStack(Material.BARRIER);
|
|
||||||
ItemMeta meta3 = back.getItemMeta();
|
|
||||||
meta3.displayName(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE));
|
|
||||||
back.setItemMeta(meta3);
|
|
||||||
|
|
||||||
inventory.setItem(50, nextPage);
|
|
||||||
inventory.setItem(49, back);
|
|
||||||
inventory.setItem(48, previousPage);
|
|
||||||
inventories.add(inventory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Inventory> getInventory()
|
|
||||||
{
|
|
||||||
return inventories;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openInv(Player player, int index)
|
|
||||||
{
|
|
||||||
int currentItemIndex = 0;
|
|
||||||
int currentInvIndex = 0;
|
|
||||||
for (Punishment punishment : punishedPlayer.getPunishments())
|
|
||||||
{
|
|
||||||
Inventory inv = inventories.get(currentInvIndex);
|
|
||||||
if (currentInvIndex > inventories.size() - 1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentItemIndex == inv.getSize() - 1)
|
|
||||||
{
|
|
||||||
currentInvIndex++;
|
|
||||||
currentItemIndex = 0;
|
|
||||||
inv = inventories.get(currentInvIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ItemStack item = new ItemStack(Material.NETHER_STAR);
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
meta.displayName(Component.text(punishment.getType().name().toUpperCase()).color(NamedTextColor.RED));
|
|
||||||
meta.lore(Collections.singletonList(Component.text("Reason: ").color(NamedTextColor.YELLOW).append(Component.newline()).append(Component.text(punishment.getReason()).color(NamedTextColor.GRAY))));
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
inv.setItem(currentItemIndex, item);
|
|
||||||
|
|
||||||
currentItemIndex++;
|
|
||||||
}
|
|
||||||
player.openInventory(inventories.get(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onClick(InventoryClickEvent event)
|
|
||||||
{
|
|
||||||
if (event.getClickedInventory() == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Inventory inv = event.getClickedInventory();
|
|
||||||
if (!isValidInventory(inv))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.getCurrentItem() == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ItemStack item = event.getCurrentItem();
|
|
||||||
if (!item.hasItemMeta())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!item.getItemMeta().hasDisplayName())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (item.getType() == Material.FEATHER)
|
|
||||||
{
|
|
||||||
if (item.getItemMeta().displayName().equals(Component.text("Next Page").color(NamedTextColor.LIGHT_PURPLE)))
|
|
||||||
{
|
|
||||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
|
||||||
}
|
|
||||||
else if (item.getItemMeta().displayName().equals(Component.text("Previous Page").color(NamedTextColor.LIGHT_PURPLE)))
|
|
||||||
{
|
|
||||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (item.getType() == Material.BARRIER)
|
|
||||||
{
|
|
||||||
new PunishmentMenu().openInv((Player) event.getWhoClicked(), 0);
|
|
||||||
}
|
|
||||||
else if (item.getType() == Material.PLAYER_HEAD)
|
|
||||||
{
|
|
||||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
|
||||||
OfflinePlayer player = meta.getOwningPlayer();
|
|
||||||
assert player != null;
|
|
||||||
PlexPlayer punishedPlayer = DataUtils.getPlayer(player.getUniqueId()) == null ? null : Plex.get().getPlayerCache().getPlexPlayer(player.getUniqueId());
|
|
||||||
if (punishedPlayer == null)
|
|
||||||
{
|
|
||||||
event.getWhoClicked().sendMessage(Component.text("This player does not exist. Try doing /punishments <player> instead.").color(NamedTextColor.RED));
|
|
||||||
event.getWhoClicked().closeInventory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentInventoryIndex(Inventory inventory)
|
|
||||||
{
|
|
||||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
|
||||||
{
|
|
||||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValidInventory(Inventory inventory)
|
|
||||||
{
|
|
||||||
return inventories.contains(inventory);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,179 +0,0 @@
|
|||||||
package dev.plex.menu;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import dev.plex.cache.DataUtils;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import dev.plex.util.menu.AbstractMenu;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.bukkit.inventory.meta.SkullMeta;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PunishmentMenu extends AbstractMenu
|
|
||||||
{
|
|
||||||
|
|
||||||
private final List<Inventory> inventories = Lists.newArrayList();
|
|
||||||
|
|
||||||
public PunishmentMenu()
|
|
||||||
{
|
|
||||||
super("§c§lPunishments");
|
|
||||||
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
|
||||||
{
|
|
||||||
Inventory inventory = Bukkit.createInventory(null, 54, PlexUtils.mmDeserialize("Punishments Page " + (i + 1)));
|
|
||||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
|
||||||
ItemMeta meta = nextPage.getItemMeta();
|
|
||||||
meta.displayName(PlexUtils.mmDeserialize("<light_purple>Next Page"));
|
|
||||||
nextPage.setItemMeta(meta);
|
|
||||||
|
|
||||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
|
||||||
ItemMeta meta2 = previousPage.getItemMeta();
|
|
||||||
meta2.displayName(PlexUtils.mmDeserialize("<light_purple>Previous Page"));
|
|
||||||
previousPage.setItemMeta(meta2);
|
|
||||||
|
|
||||||
inventory.setItem(50, nextPage);
|
|
||||||
inventory.setItem(48, previousPage);
|
|
||||||
inventories.add(inventory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Inventory> getInventory()
|
|
||||||
{
|
|
||||||
return inventories;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openInv(Player player, int index)
|
|
||||||
{
|
|
||||||
int currentItemIndex = 0;
|
|
||||||
int currentInvIndex = 0;
|
|
||||||
for (Player players : Bukkit.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
Inventory inv = inventories.get(currentInvIndex);
|
|
||||||
if (currentInvIndex > inventories.size() - 1)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentItemIndex == inv.getSize() - 1)
|
|
||||||
{
|
|
||||||
currentInvIndex++;
|
|
||||||
currentItemIndex = 0;
|
|
||||||
inv = inventories.get(currentInvIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
|
||||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
|
||||||
meta.setOwningPlayer(players);
|
|
||||||
meta.displayName(PlexUtils.mmDeserialize("<!italic><yellow>" + players.getName()));
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
inv.setItem(currentItemIndex, item);
|
|
||||||
|
|
||||||
currentItemIndex++;
|
|
||||||
}
|
|
||||||
player.openInventory(inventories.get(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onClick(InventoryClickEvent event)
|
|
||||||
{
|
|
||||||
if (event.getClickedInventory() == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Inventory inv = event.getClickedInventory();
|
|
||||||
if (!isValidInventory(inv))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.getCurrentItem() == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!event.getCurrentItem().hasItemMeta())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!event.getCurrentItem().getItemMeta().hasDisplayName())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ItemStack item = event.getCurrentItem();
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (item.getType() == Material.FEATHER)
|
|
||||||
{
|
|
||||||
if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Next Page")))
|
|
||||||
{
|
|
||||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
|
||||||
}
|
|
||||||
else if (item.getItemMeta().displayName().equals(PlexUtils.mmDeserialize("<light_purple>Previous Page")))
|
|
||||||
{
|
|
||||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (item.getType() == Material.PLAYER_HEAD)
|
|
||||||
{
|
|
||||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
|
||||||
OfflinePlayer player = meta.getOwningPlayer();
|
|
||||||
assert player != null;
|
|
||||||
PlexPlayer punishedPlayer = DataUtils.getPlayer(player.getUniqueId());
|
|
||||||
if (punishedPlayer == null)
|
|
||||||
{
|
|
||||||
event.getWhoClicked().sendMessage(Component.text("This player does not exist. Try doing /punishments <player> instead.").color(NamedTextColor.RED));
|
|
||||||
event.getWhoClicked().closeInventory();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
new PunishedPlayerMenu(punishedPlayer).openInv((Player) event.getWhoClicked(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentInventoryIndex(Inventory inventory)
|
|
||||||
{
|
|
||||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
|
||||||
{
|
|
||||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValidInventory(Inventory inventory)
|
|
||||||
{
|
|
||||||
return inventories.contains(inventory);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,146 +0,0 @@
|
|||||||
package dev.plex.menu;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import dev.plex.PlexBase;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import dev.plex.util.menu.AbstractMenu;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ToggleMenu extends AbstractMenu implements PlexBase
|
|
||||||
{
|
|
||||||
private final List<Inventory> inventories = Lists.newArrayList();
|
|
||||||
|
|
||||||
public ToggleMenu()
|
|
||||||
{
|
|
||||||
super("§a§lToggles");
|
|
||||||
Inventory inventory = Bukkit.createInventory(null, 9, PlexUtils.mmDeserialize("Toggles"));
|
|
||||||
resetExplosionItem(inventory);
|
|
||||||
resetFluidspreadItem(inventory);
|
|
||||||
resetDropsItem(inventory);
|
|
||||||
resetRedstoneItem(inventory);
|
|
||||||
inventories.add(inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void openInv(Player player, int index)
|
|
||||||
{
|
|
||||||
player.openInventory(inventories.get(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onClick(InventoryClickEvent event)
|
|
||||||
{
|
|
||||||
if (event.getClickedInventory() == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Inventory inv = event.getClickedInventory();
|
|
||||||
if (!isValidInventory(inv))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.getCurrentItem() == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!event.getCurrentItem().hasItemMeta())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!event.getCurrentItem().getItemMeta().hasDisplayName())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ItemStack item = event.getCurrentItem();
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (item.getType() == Material.TNT)
|
|
||||||
{
|
|
||||||
plugin.toggles.set("explosions", !plugin.toggles.getBoolean("explosions"));
|
|
||||||
resetExplosionItem(inv);
|
|
||||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled explosions."));
|
|
||||||
}
|
|
||||||
if (item.getType() == Material.WATER_BUCKET)
|
|
||||||
{
|
|
||||||
plugin.toggles.set("fluidspread", !plugin.toggles.getBoolean("fluidspread"));
|
|
||||||
resetFluidspreadItem(inv);
|
|
||||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled fluid spread."));
|
|
||||||
}
|
|
||||||
if (item.getType() == Material.FEATHER)
|
|
||||||
{
|
|
||||||
plugin.toggles.set("drops", !plugin.toggles.getBoolean("drops"));
|
|
||||||
resetDropsItem(inv);
|
|
||||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled drops."));
|
|
||||||
}
|
|
||||||
if (item.getType() == Material.REDSTONE)
|
|
||||||
{
|
|
||||||
plugin.toggles.set("redstone", !plugin.toggles.getBoolean("redstone"));
|
|
||||||
resetRedstoneItem(inv);
|
|
||||||
event.getWhoClicked().sendMessage(PlexUtils.mmDeserialize("<gray>Toggled redstone."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentInventoryIndex(Inventory inventory)
|
|
||||||
{
|
|
||||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
|
||||||
{
|
|
||||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValidInventory(Inventory inventory)
|
|
||||||
{
|
|
||||||
return inventories.contains(inventory);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetExplosionItem(Inventory inventory)
|
|
||||||
{
|
|
||||||
ItemStack explosions = new ItemStack(Material.TNT);
|
|
||||||
ItemMeta explosionsItemMeta = explosions.getItemMeta();
|
|
||||||
explosionsItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Toggle explosions"));
|
|
||||||
explosionsItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Explosions are " + (plugin.toggles.getBoolean("explosions") ? "<red>enabled" : "<green>disabled"))));
|
|
||||||
explosions.setItemMeta(explosionsItemMeta);
|
|
||||||
inventory.setItem(0, explosions);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetFluidspreadItem(Inventory inventory)
|
|
||||||
{
|
|
||||||
ItemStack water = new ItemStack(Material.WATER_BUCKET);
|
|
||||||
ItemMeta waterItemMeta = water.getItemMeta();
|
|
||||||
waterItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Toggle fluid spread"));
|
|
||||||
waterItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Fluid spread is " + (plugin.toggles.getBoolean("fluidspread") ? "<green>enabled" : "<red>disabled"))));
|
|
||||||
water.setItemMeta(waterItemMeta);
|
|
||||||
inventory.setItem(1, water);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetDropsItem(Inventory inventory)
|
|
||||||
{
|
|
||||||
ItemStack feather = new ItemStack(Material.FEATHER);
|
|
||||||
ItemMeta featherItemMeta = feather.getItemMeta();
|
|
||||||
featherItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Toggle drops"));
|
|
||||||
featherItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Drops are " + (plugin.toggles.getBoolean("drops") ? "<green>enabled" : "<red>disabled"))));
|
|
||||||
feather.setItemMeta(featherItemMeta);
|
|
||||||
inventory.setItem(2, feather);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetRedstoneItem(Inventory inventory)
|
|
||||||
{
|
|
||||||
ItemStack redstone = new ItemStack(Material.REDSTONE);
|
|
||||||
ItemMeta redstoneItemMeta = redstone.getItemMeta();
|
|
||||||
redstoneItemMeta.displayName(PlexUtils.mmDeserialize("<light_purple>Redstone"));
|
|
||||||
redstoneItemMeta.lore(List.of(PlexUtils.mmDeserialize("<yellow>Redstone is " + (plugin.toggles.getBoolean("redstone") ? "<green>enabled" : "<red>disabled"))));
|
|
||||||
redstone.setItemMeta(redstoneItemMeta);
|
|
||||||
inventory.setItem(3, redstone);
|
|
||||||
}
|
|
||||||
}
|
|
40
server/src/main/java/dev/plex/menu/impl/MaterialMenu.java
Normal file
40
server/src/main/java/dev/plex/menu/impl/MaterialMenu.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package dev.plex.menu.impl;
|
||||||
|
|
||||||
|
import dev.plex.menu.AbstractMenu;
|
||||||
|
import dev.plex.menu.pagination.PageableMenu;
|
||||||
|
import dev.plex.util.item.ItemBuilder;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taah
|
||||||
|
* @since 8:44 AM [02-09-2023]
|
||||||
|
*/
|
||||||
|
public class MaterialMenu extends PageableMenu<Material>
|
||||||
|
{
|
||||||
|
public MaterialMenu()
|
||||||
|
{
|
||||||
|
super("<dark_aqua><bold>Materials", AbstractMenu.Rows.SIX);
|
||||||
|
onClick((inventoryView, inventory, player, itemStack) ->
|
||||||
|
{
|
||||||
|
player.sendMessage(itemStack.displayName());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ItemStack toItem(Material object)
|
||||||
|
{
|
||||||
|
return new ItemBuilder(object).displayName("<blue>" + object.name()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Material> list()
|
||||||
|
{
|
||||||
|
return Arrays.stream(Material.values()).filter(material -> !material.isAir()).toList();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package dev.plex.menu.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.menu.AbstractMenu;
|
||||||
|
import dev.plex.menu.pagination.PageableMenu;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.punishment.Punishment;
|
||||||
|
import dev.plex.util.TimeUtils;
|
||||||
|
import dev.plex.util.item.ItemBuilder;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PunishedPlayerMenu extends PageableMenu<Punishment>
|
||||||
|
{
|
||||||
|
private final PlexPlayer punishedPlayer;
|
||||||
|
public PunishedPlayerMenu(PlexPlayer player)
|
||||||
|
{
|
||||||
|
super("<red><bold>Punishments - " + player.getName(), AbstractMenu.Rows.SIX);
|
||||||
|
this.punishedPlayer = player;
|
||||||
|
onClick((inventoryView, itemStacks, player1, itemStack) -> true);
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ItemStack toItem(Punishment object)
|
||||||
|
{
|
||||||
|
return new ItemBuilder(Material.PAPER).displayName("<!italic><red>" + object.getType().name()).lore("<!italic><red>By: <gold>" + (object.getPunisher() == null ? "CONSOLE" : Plex.get().getSqlPlayerData().getNameByUUID(object.getPunished())), "<!italic><red>Expire(d/s): <gold>" + TimeUtils.useTimezone(object.getEndDate()), "<!italic><red>Reason: <gold>" + object.getReason()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Punishment> list()
|
||||||
|
{
|
||||||
|
return this.punishedPlayer.getPunishments();
|
||||||
|
}
|
||||||
|
}
|
63
server/src/main/java/dev/plex/menu/impl/PunishmentMenu.java
Normal file
63
server/src/main/java/dev/plex/menu/impl/PunishmentMenu.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package dev.plex.menu.impl;
|
||||||
|
|
||||||
|
import dev.plex.cache.DataUtils;
|
||||||
|
import dev.plex.menu.AbstractMenu;
|
||||||
|
import dev.plex.menu.pagination.PageableMenu;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.util.PlexLog;
|
||||||
|
import dev.plex.util.item.ItemBuilder;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taah
|
||||||
|
* @since 9:27 AM [02-09-2023]
|
||||||
|
*/
|
||||||
|
public class PunishmentMenu extends PageableMenu<Player>
|
||||||
|
{
|
||||||
|
public PunishmentMenu()
|
||||||
|
{
|
||||||
|
super("<aqua><bold>Punishments", AbstractMenu.Rows.SIX);
|
||||||
|
PlexLog.debug("list: {0}", list().size());
|
||||||
|
onClick((inventoryView, itemStacks, player, itemStack) ->
|
||||||
|
{
|
||||||
|
if (itemStack.getType() != Material.PLAYER_HEAD) return true;
|
||||||
|
final SkullMeta meta = (SkullMeta) itemStack.getItemMeta();
|
||||||
|
if (meta.getOwningPlayer() == null)
|
||||||
|
{
|
||||||
|
meta.setOwningPlayer(Bukkit.getOfflinePlayer("markbyron"));
|
||||||
|
}
|
||||||
|
PlexPlayer punishedPlayer = DataUtils.getPlayer(meta.getOwningPlayer().getUniqueId());
|
||||||
|
if (punishedPlayer == null)
|
||||||
|
{
|
||||||
|
player.sendMessage(Component.text("This player does not exist. Try doing /punishments <player> instead.").color(NamedTextColor.RED));
|
||||||
|
player.closeInventory();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
new PunishedPlayerMenu(punishedPlayer).open(player);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ItemStack toItem(Player object)
|
||||||
|
{
|
||||||
|
return new ItemBuilder(Material.PLAYER_HEAD).owner(object).displayName("<!italic><yellow>" + object.getName()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Player> list()
|
||||||
|
{
|
||||||
|
return Bukkit.getOnlinePlayers().stream().map(OfflinePlayer::getPlayer).toList();
|
||||||
|
}
|
||||||
|
}
|
98
server/src/main/java/dev/plex/menu/impl/ToggleMenu.java
Normal file
98
server/src/main/java/dev/plex/menu/impl/ToggleMenu.java
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package dev.plex.menu.impl;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.menu.AbstractMenu;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ToggleMenu extends AbstractMenu
|
||||||
|
{
|
||||||
|
private final Plex plugin;
|
||||||
|
|
||||||
|
public ToggleMenu()
|
||||||
|
{
|
||||||
|
super("<green><bold>Toggles", Rows.ONE);
|
||||||
|
this.plugin = Plex.get();
|
||||||
|
resetExplosionItem(this.inventory());
|
||||||
|
resetFluidspreadItem(this.inventory());
|
||||||
|
resetDropsItem(this.inventory());
|
||||||
|
resetRedstoneItem(this.inventory());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetExplosionItem(Inventory inventory)
|
||||||
|
{
|
||||||
|
ItemStack explosions = new ItemStack(Material.TNT);
|
||||||
|
ItemMeta explosionsItemMeta = explosions.getItemMeta();
|
||||||
|
explosionsItemMeta.displayName(PlexUtils.mmDeserialize("<!italic><light_purple>Toggle explosions"));
|
||||||
|
explosionsItemMeta.lore(List.of(PlexUtils.mmDeserialize("<!italic><yellow>Explosions are " + (plugin.toggles.getBoolean("explosions") ? "<red>enabled" : "<green>disabled"))));
|
||||||
|
explosions.setItemMeta(explosionsItemMeta);
|
||||||
|
inventory.setItem(0, explosions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetFluidspreadItem(Inventory inventory)
|
||||||
|
{
|
||||||
|
ItemStack water = new ItemStack(Material.WATER_BUCKET);
|
||||||
|
ItemMeta waterItemMeta = water.getItemMeta();
|
||||||
|
waterItemMeta.displayName(PlexUtils.mmDeserialize("<!italic><light_purple>Toggle fluid spread"));
|
||||||
|
waterItemMeta.lore(List.of(PlexUtils.mmDeserialize("<!italic><yellow>Fluid spread is " + (plugin.toggles.getBoolean("fluidspread") ? "<green>enabled" : "<red>disabled"))));
|
||||||
|
water.setItemMeta(waterItemMeta);
|
||||||
|
inventory.setItem(1, water);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetDropsItem(Inventory inventory)
|
||||||
|
{
|
||||||
|
ItemStack feather = new ItemStack(Material.FEATHER);
|
||||||
|
ItemMeta featherItemMeta = feather.getItemMeta();
|
||||||
|
featherItemMeta.displayName(PlexUtils.mmDeserialize("<!italic><light_purple>Toggle drops"));
|
||||||
|
featherItemMeta.lore(List.of(PlexUtils.mmDeserialize("<!italic><yellow>Drops are " + (plugin.toggles.getBoolean("drops") ? "<green>enabled" : "<red>disabled"))));
|
||||||
|
feather.setItemMeta(featherItemMeta);
|
||||||
|
inventory.setItem(2, feather);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetRedstoneItem(Inventory inventory)
|
||||||
|
{
|
||||||
|
ItemStack redstone = new ItemStack(Material.REDSTONE);
|
||||||
|
ItemMeta redstoneItemMeta = redstone.getItemMeta();
|
||||||
|
redstoneItemMeta.displayName(PlexUtils.mmDeserialize("<!italic><light_purple>Redstone"));
|
||||||
|
redstoneItemMeta.lore(List.of(PlexUtils.mmDeserialize("<!italic><yellow>Redstone is " + (plugin.toggles.getBoolean("redstone") ? "<green>enabled" : "<red>disabled"))));
|
||||||
|
redstone.setItemMeta(redstoneItemMeta);
|
||||||
|
inventory.setItem(3, redstone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onClick(InventoryView view, Inventory inventory, Player player, ItemStack clicked)
|
||||||
|
{
|
||||||
|
if (clicked.getType() == Material.TNT)
|
||||||
|
{
|
||||||
|
plugin.toggles.set("explosions", !plugin.toggles.getBoolean("explosions"));
|
||||||
|
resetExplosionItem(inventory);
|
||||||
|
player.sendMessage(PlexUtils.mmDeserialize("<gray>Toggled explosions."));
|
||||||
|
}
|
||||||
|
if (clicked.getType() == Material.WATER_BUCKET)
|
||||||
|
{
|
||||||
|
plugin.toggles.set("fluidspread", !plugin.toggles.getBoolean("fluidspread"));
|
||||||
|
resetFluidspreadItem(inventory);
|
||||||
|
player.sendMessage(PlexUtils.mmDeserialize("<gray>Toggled fluid spread."));
|
||||||
|
}
|
||||||
|
if (clicked.getType() == Material.FEATHER)
|
||||||
|
{
|
||||||
|
plugin.toggles.set("drops", !plugin.toggles.getBoolean("drops"));
|
||||||
|
resetDropsItem(inventory);
|
||||||
|
player.sendMessage(PlexUtils.mmDeserialize("<gray>Toggled drops."));
|
||||||
|
}
|
||||||
|
if (clicked.getType() == Material.REDSTONE)
|
||||||
|
{
|
||||||
|
plugin.toggles.set("redstone", !plugin.toggles.getBoolean("redstone"));
|
||||||
|
resetRedstoneItem(inventory);
|
||||||
|
player.sendMessage(PlexUtils.mmDeserialize("<gray>Toggled redstone."));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
176
server/src/main/java/dev/plex/menu/pagination/PageableMenu.java
Normal file
176
server/src/main/java/dev/plex/menu/pagination/PageableMenu.java
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
package dev.plex.menu.pagination;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import dev.plex.menu.AbstractMenu;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.function.ConditionalQuadConsumer;
|
||||||
|
import dev.plex.util.item.ItemBuilder;
|
||||||
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taah
|
||||||
|
* @since 8:04 AM [02-09-2023]
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public abstract class PageableMenu<T>
|
||||||
|
{
|
||||||
|
public static final ItemStack NEXT = new ItemBuilder(Material.FEATHER).displayName("<light_purple>Next Page").build();
|
||||||
|
public static final ItemStack PREVIOUS = new ItemBuilder(Material.FEATHER).displayName("<light_purple>Previous Page").build();
|
||||||
|
public static final ItemStack CLOSE = new ItemBuilder(Material.BARRIER).displayName("<red>Close").build();
|
||||||
|
protected final Map<Integer, Page> pages = Maps.newHashMap();
|
||||||
|
private final Component name;
|
||||||
|
private final AbstractMenu.Rows rows;
|
||||||
|
private final Inventory inventory;
|
||||||
|
private int currentPage;
|
||||||
|
private boolean initialized;
|
||||||
|
|
||||||
|
@Setter(AccessLevel.NONE)
|
||||||
|
private ConditionalQuadConsumer<InventoryView, Inventory, Player, ItemStack> onClick;
|
||||||
|
|
||||||
|
public PageableMenu(Component name, AbstractMenu.Rows rows)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.rows = rows;
|
||||||
|
this.inventory = Bukkit.createInventory(null, rows.slots(), name);
|
||||||
|
|
||||||
|
if (rows.slots() < AbstractMenu.Rows.TWO.slots())
|
||||||
|
{
|
||||||
|
throw new RuntimeException("A pageable menu must have at least two rows to compensate for the navigation!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void init()
|
||||||
|
{
|
||||||
|
this.initialized = true;
|
||||||
|
// Preload all needed pages, a better solution is probably just to dynamically create the pages as they go but no!
|
||||||
|
if (list().size() < (rows.slots() - 9))
|
||||||
|
{
|
||||||
|
final Page page = new Page(name.append(Component.space()).append(PlexUtils.mmDeserialize("(1)")), rows);
|
||||||
|
page.parent = this;
|
||||||
|
page.inventory().setItem(rows.slots() - 5, CLOSE);
|
||||||
|
this.pages.put(0, page);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Math.ceil(list().size() / (double) (rows.slots() - 9)); i++)
|
||||||
|
{
|
||||||
|
final Page page = new Page(name.append(Component.space()).append(PlexUtils.mmDeserialize("(" + (i + 1) + ")")), rows);
|
||||||
|
page.parent = this;
|
||||||
|
if (i > 0) // If not first page set previous page button
|
||||||
|
{
|
||||||
|
page.inventory().setItem(rows.slots() - 6, PREVIOUS);
|
||||||
|
}
|
||||||
|
page.inventory().setItem(rows.slots() - 5, CLOSE);
|
||||||
|
if (i < (list().size() / (rows.slots() - 9)) - 1) // If not last page set next page button
|
||||||
|
{
|
||||||
|
page.inventory().setItem(rows.slots() - 4, NEXT);
|
||||||
|
}
|
||||||
|
this.pages.put(i, page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int currentSlotIndex = 0;
|
||||||
|
int currentPageIndex = 0;
|
||||||
|
int currentIndex = 0;
|
||||||
|
while (currentSlotIndex < rows.slots() - 9 && currentIndex < list().size())
|
||||||
|
{
|
||||||
|
final Page page = this.pages.get(currentPageIndex);
|
||||||
|
if (page == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
page.inventory().setItem(currentSlotIndex, toItem(list().get(currentIndex)));
|
||||||
|
currentIndex++;
|
||||||
|
currentSlotIndex++;
|
||||||
|
if (currentSlotIndex == rows.slots() - 9)
|
||||||
|
{
|
||||||
|
currentSlotIndex = 0;
|
||||||
|
currentPageIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (onClick != null) // To make sure this wasn't declared already
|
||||||
|
{
|
||||||
|
this.pages.forEach((integer, page) -> page.onClick(this.onClick));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageableMenu(String name, AbstractMenu.Rows rows)
|
||||||
|
{
|
||||||
|
this(SafeMiniMessage.mmDeserializeWithoutEvents(name), rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract ItemStack toItem(T object);
|
||||||
|
|
||||||
|
protected abstract List<T> list();
|
||||||
|
|
||||||
|
public void open(Player player)
|
||||||
|
{
|
||||||
|
open(player, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void open(Player player, int pageNum)
|
||||||
|
{
|
||||||
|
if (!this.initialized)
|
||||||
|
{
|
||||||
|
player.sendMessage(Component.text("Looks like this inventory was not initialized! Please contact a developer to report this.").color(NamedTextColor.RED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Page page = this.pages.get(pageNum);
|
||||||
|
if (page == null)
|
||||||
|
{
|
||||||
|
player.sendMessage(Component.text("Could not find a page to open").color(NamedTextColor.RED));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.openInventory(page.inventory());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(ConditionalQuadConsumer<InventoryView, Inventory, Player, ItemStack> onClick)
|
||||||
|
{
|
||||||
|
this.onClick = onClick;
|
||||||
|
this.pages.forEach((integer, page) -> page.onClick(this.onClick));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(fluent = true)
|
||||||
|
public static class Page extends AbstractMenu
|
||||||
|
{
|
||||||
|
private ConditionalQuadConsumer<InventoryView, Inventory, Player, ItemStack> onClick;
|
||||||
|
private PageableMenu<?> parent;
|
||||||
|
|
||||||
|
private Page(Component name, Rows rows)
|
||||||
|
{
|
||||||
|
super(name, rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Page(String name, AbstractMenu.Rows rows)
|
||||||
|
{
|
||||||
|
this(SafeMiniMessage.mmDeserializeWithoutEvents(name), rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onClick(InventoryView view, Inventory inventory, Player player, ItemStack clicked)
|
||||||
|
{
|
||||||
|
return onClick.accept(view, inventory, player, clicked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
server/src/main/java/dev/plex/meta/PlayerMeta.java
Normal file
66
server/src/main/java/dev/plex/meta/PlayerMeta.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package dev.plex.meta;
|
||||||
|
|
||||||
|
import dev.plex.Plex;
|
||||||
|
import dev.plex.hook.VaultHook;
|
||||||
|
import dev.plex.player.PlexPlayer;
|
||||||
|
import dev.plex.util.PlexUtils;
|
||||||
|
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class PlayerMeta
|
||||||
|
{
|
||||||
|
public static Component getPrefix(PlexPlayer plexPlayer)
|
||||||
|
{
|
||||||
|
if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty())
|
||||||
|
{
|
||||||
|
return SafeMiniMessage.mmDeserializeWithoutEvents(plexPlayer.getPrefix());
|
||||||
|
}
|
||||||
|
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||||
|
{
|
||||||
|
return PlexUtils.mmDeserialize("<dark_gray>[<dark_purple>Developer<dark_gray>]");
|
||||||
|
}
|
||||||
|
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||||
|
{
|
||||||
|
return VaultHook.getPrefix(plexPlayer);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLoginMessage(PlexPlayer plexPlayer)
|
||||||
|
{
|
||||||
|
String prepend;
|
||||||
|
// We don't want to prepend the "<player> is" if the login message is custom
|
||||||
|
if (!plexPlayer.getLoginMessage().isEmpty())
|
||||||
|
{
|
||||||
|
return plexPlayer.getLoginMessage()
|
||||||
|
.replace("%player%", plexPlayer.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prepend = MiniMessage.miniMessage().serialize(Component.text(plexPlayer.getName() + " is ").color(NamedTextColor.AQUA));
|
||||||
|
}
|
||||||
|
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||||
|
{
|
||||||
|
return prepend + "<aqua>a <dark_purple>Developer<reset>";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getColor(PlexPlayer plexPlayer)
|
||||||
|
{
|
||||||
|
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||||
|
{
|
||||||
|
return "<dark_purple>";
|
||||||
|
}
|
||||||
|
String group = VaultHook.getPermission().getPrimaryGroup(null, plexPlayer.getPlayer());
|
||||||
|
if (Plex.get().getConfig().isSet("colors." + group))
|
||||||
|
{
|
||||||
|
return PlexUtils.mmSerialize(PlexUtils.mmDeserialize(Plex.get().getConfig().getString("colors." + group)));
|
||||||
|
}
|
||||||
|
return "<white>";
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
package dev.plex.permission;
|
|
||||||
|
|
||||||
import dev.morphia.annotations.Entity;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
public class Permission
|
|
||||||
{
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String permission;
|
|
||||||
private boolean allowed = true;
|
|
||||||
}
|
|
@ -2,25 +2,22 @@ package dev.plex.player;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import dev.morphia.annotations.Entity;
|
|
||||||
import dev.morphia.annotations.Id;
|
|
||||||
import dev.morphia.annotations.IndexOptions;
|
|
||||||
import dev.morphia.annotations.Indexed;
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.permission.Permission;
|
|
||||||
import dev.plex.punishment.Punishment;
|
import dev.plex.punishment.Punishment;
|
||||||
import dev.plex.punishment.extra.Note;
|
import dev.plex.punishment.extra.Note;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.storage.annotation.MapObjectList;
|
||||||
import dev.plex.storage.StorageType;
|
import dev.plex.storage.annotation.PrimaryKey;
|
||||||
|
import dev.plex.storage.annotation.SQLTable;
|
||||||
|
import dev.plex.storage.annotation.VarcharLimit;
|
||||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,18 +25,16 @@ import java.util.UUID;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity(value = "players", useDiscriminator = false)
|
@SQLTable("players")
|
||||||
public class PlexPlayer
|
public class PlexPlayer
|
||||||
{
|
{
|
||||||
@Setter(AccessLevel.NONE)
|
@Setter(AccessLevel.NONE)
|
||||||
@Id
|
@PrimaryKey
|
||||||
private String id;
|
@NotNull
|
||||||
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
@Indexed(options = @IndexOptions(unique = true))
|
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
|
||||||
@Indexed
|
@VarcharLimit(16)
|
||||||
|
@NotNull
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String loginMessage;
|
private String loginMessage;
|
||||||
@ -54,29 +49,23 @@ public class PlexPlayer
|
|||||||
private transient boolean muted;
|
private transient boolean muted;
|
||||||
private transient boolean lockedUp;
|
private transient boolean lockedUp;
|
||||||
|
|
||||||
private boolean adminActive;
|
|
||||||
|
|
||||||
private long coins;
|
private long coins;
|
||||||
|
|
||||||
private String rank;
|
|
||||||
|
|
||||||
private List<String> ips = Lists.newArrayList();
|
private List<String> ips = Lists.newArrayList();
|
||||||
private List<Punishment> punishments = Lists.newArrayList();
|
|
||||||
private List<Note> notes = Lists.newArrayList();
|
|
||||||
private List<Permission> permissions = Lists.newArrayList();
|
|
||||||
|
|
||||||
private transient PermissionAttachment permissionAttachment;
|
@MapObjectList
|
||||||
|
private List<Punishment> punishments = Lists.newArrayList();
|
||||||
|
|
||||||
|
@MapObjectList
|
||||||
|
private List<Note> notes = Lists.newArrayList();
|
||||||
|
|
||||||
public PlexPlayer()
|
public PlexPlayer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlexPlayer(UUID playerUUID, boolean loadExtraData)
|
public PlexPlayer(UUID playerUUID, boolean loadPunishments)
|
||||||
{
|
{
|
||||||
this.uuid = playerUUID;
|
this.uuid = playerUUID;
|
||||||
|
|
||||||
this.id = uuid.toString().substring(0, 8);
|
|
||||||
|
|
||||||
this.name = "";
|
this.name = "";
|
||||||
|
|
||||||
this.loginMessage = "";
|
this.loginMessage = "";
|
||||||
@ -87,14 +76,10 @@ public class PlexPlayer
|
|||||||
|
|
||||||
this.coins = 0;
|
this.coins = 0;
|
||||||
|
|
||||||
this.rank = "";
|
if (loadPunishments)
|
||||||
if (loadExtraData)
|
|
||||||
{
|
{
|
||||||
this.loadPunishments();
|
this.loadPunishments();
|
||||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
// this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
|
||||||
{
|
|
||||||
this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,41 +93,15 @@ public class PlexPlayer
|
|||||||
return PlainTextComponentSerializer.plainText().serialize(getPlayer().displayName());
|
return PlainTextComponentSerializer.plainText().serialize(getPlayer().displayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rank getRankFromString()
|
|
||||||
{
|
|
||||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
|
||||||
if (rank.isEmpty() || !isAdminActive())
|
|
||||||
{
|
|
||||||
if (player.isOp())
|
|
||||||
{
|
|
||||||
return Rank.OP;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Rank.NONOP;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Rank.valueOf(rank.toUpperCase());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadPunishments()
|
public void loadPunishments()
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
{
|
||||||
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));
|
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void loadNotes()
|
public void loadNotes()
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
{
|
||||||
Plex.get().getSqlNotes().getNotes(this.getUuid());
|
Plex.get().getSqlNotes().getNotes(this.getUuid());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON()
|
public String toJSON()
|
||||||
{
|
{
|
||||||
|
@ -2,26 +2,27 @@ package dev.plex.punishment;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import dev.morphia.annotations.Entity;
|
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.util.MojangUtils;
|
import dev.plex.storage.annotation.SQLTable;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity
|
@SQLTable("punishments")
|
||||||
public class Punishment
|
public class Punishment
|
||||||
{
|
{
|
||||||
private static final Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create();
|
private static final Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).create();
|
||||||
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
|
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
|
||||||
|
@NotNull
|
||||||
private final UUID punished;
|
private final UUID punished;
|
||||||
private final UUID punisher;
|
private final UUID punisher;
|
||||||
private String ip;
|
private String ip;
|
||||||
@ -46,7 +47,17 @@ public class Punishment
|
|||||||
|
|
||||||
public static Component generateBanMessage(Punishment punishment)
|
public static Component generateBanMessage(Punishment punishment)
|
||||||
{
|
{
|
||||||
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : Plex.get().getSqlPlayerData().getNameByUUID(punishment.getPunisher()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component generateKickMessage(Punishment punishment)
|
||||||
|
{
|
||||||
|
return PlexUtils.messageComponent("kickMessage", punishment.getReason(), punishment.getPunisher() == null ? "CONSOLE" : Plex.get().getSqlPlayerData().getNameByUUID(punishment.getPunisher()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component generateIndefBanMessageWithReason(String type, String reason)
|
||||||
|
{
|
||||||
|
return PlexUtils.messageComponent("indefBanMessageReason", type, banUrl, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component generateIndefBanMessage(String type)
|
public static Component generateIndefBanMessage(String type)
|
||||||
|
@ -3,20 +3,14 @@ package dev.plex.punishment;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.PlexBase;
|
import dev.plex.PlexBase;
|
||||||
import dev.plex.cache.DataUtils;
|
import dev.plex.cache.DataUtils;
|
||||||
import dev.plex.player.PlexPlayer;
|
import dev.plex.player.PlexPlayer;
|
||||||
import dev.plex.storage.StorageType;
|
|
||||||
import dev.plex.util.PlexLog;
|
import dev.plex.util.PlexLog;
|
||||||
import dev.plex.util.PlexUtils;
|
import dev.plex.util.PlexUtils;
|
||||||
import dev.plex.util.TimeUtils;
|
import dev.plex.util.TimeUtils;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -27,7 +21,17 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||||
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class PunishmentManager implements PlexBase
|
public class PunishmentManager implements PlexBase
|
||||||
{
|
{
|
||||||
@ -39,7 +43,7 @@ public class PunishmentManager implements PlexBase
|
|||||||
this.indefiniteBans.clear();
|
this.indefiniteBans.clear();
|
||||||
Plex.get().indefBans.getKeys(false).forEach(key ->
|
Plex.get().indefBans.getKeys(false).forEach(key ->
|
||||||
{
|
{
|
||||||
IndefiniteBan ban = new IndefiniteBan();
|
IndefiniteBan ban = new IndefiniteBan(Plex.get().getIndefBans().getString("reason", ""));
|
||||||
ban.ips.addAll(Plex.get().getIndefBans().getStringList(key + ".ips"));
|
ban.ips.addAll(Plex.get().getIndefBans().getStringList(key + ".ips"));
|
||||||
ban.usernames.addAll(Plex.get().getIndefBans().getStringList(key + ".users"));
|
ban.usernames.addAll(Plex.get().getIndefBans().getStringList(key + ".users"));
|
||||||
ban.uuids.addAll(Plex.get().getIndefBans().getStringList(key + ".uuids").stream().map(UUID::fromString).toList());
|
ban.uuids.addAll(Plex.get().getIndefBans().getStringList(key + ".uuids").stream().map(UUID::fromString).toList());
|
||||||
@ -58,7 +62,8 @@ public class PunishmentManager implements PlexBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIndefUUIDBanned(UUID uuid)
|
@Nullable
|
||||||
|
public IndefiniteBan getIndefiniteBanByUUID(UUID uuid)
|
||||||
{
|
{
|
||||||
if (Plex.get().getRedisConnection().isEnabled())
|
if (Plex.get().getRedisConnection().isEnabled())
|
||||||
{
|
{
|
||||||
@ -66,12 +71,12 @@ public class PunishmentManager implements PlexBase
|
|||||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
|
return bans.stream().filter(indefiniteBan -> indefiniteBan.getUuids().contains(uuid)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUuids().contains(uuid));
|
return this.indefiniteBans.stream().filter(indefiniteBan -> indefiniteBan.getUuids().contains(uuid)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIndefIPBanned(String ip)
|
public IndefiniteBan getIndefiniteBanByIP(String ip)
|
||||||
{
|
{
|
||||||
if (Plex.get().getRedisConnection().isEnabled())
|
if (Plex.get().getRedisConnection().isEnabled())
|
||||||
{
|
{
|
||||||
@ -79,12 +84,12 @@ public class PunishmentManager implements PlexBase
|
|||||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
|
return bans.stream().filter(indefiniteBan -> indefiniteBan.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getIps().contains(ip));
|
return this.indefiniteBans.stream().filter(indefiniteBan -> indefiniteBan.getIps().contains(ip)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIndefUserBanned(String username)
|
public IndefiniteBan getIndefiniteBanByUsername(String username)
|
||||||
{
|
{
|
||||||
if (Plex.get().getRedisConnection().isEnabled())
|
if (Plex.get().getRedisConnection().isEnabled())
|
||||||
{
|
{
|
||||||
@ -92,26 +97,16 @@ public class PunishmentManager implements PlexBase
|
|||||||
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
List<IndefiniteBan> bans = new Gson().fromJson(Plex.get().getRedisConnection().getJedis().get("indefbans"), new TypeToken<List<IndefiniteBan>>()
|
||||||
{
|
{
|
||||||
}.getType());
|
}.getType());
|
||||||
return bans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));
|
return bans.stream().filter(indefiniteBan -> indefiniteBan.getUsernames().contains(username)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
return this.indefiniteBans.stream().anyMatch(indefiniteBan -> indefiniteBan.getUsernames().contains(username));
|
return this.indefiniteBans.stream().filter(indefiniteBan -> indefiniteBan.getUsernames().contains(username)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void issuePunishment(PlexPlayer plexPlayer, Punishment punishment)
|
public void issuePunishment(PlexPlayer plexPlayer, Punishment punishment)
|
||||||
{
|
{
|
||||||
plexPlayer.getPunishments().add(punishment);
|
plexPlayer.getPunishments().add(punishment);
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
CompletableFuture.runAsync(() ->
|
|
||||||
{
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Plex.get().getSqlPunishment().insertPunishment(punishment);
|
Plex.get().getSqlPunishment().insertPunishment(punishment);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isNotEmpty(File file)
|
private boolean isNotEmpty(File file)
|
||||||
{
|
{
|
||||||
@ -143,7 +138,6 @@ public class PunishmentManager implements PlexBase
|
|||||||
|
|
||||||
public boolean isBanned(UUID uuid)
|
public boolean isBanned(UUID uuid)
|
||||||
{
|
{
|
||||||
// TODO: If a person is using MongoDB, this will error out because it is checking for bans on a player that doesn't exist yet
|
|
||||||
if (!DataUtils.hasPlayedBefore(uuid))
|
if (!DataUtils.hasPlayedBefore(uuid))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -151,22 +145,18 @@ public class PunishmentManager implements PlexBase
|
|||||||
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
|
return DataUtils.getPlayer(uuid).getPunishments().stream().anyMatch(punishment -> (punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN) && punishment.isActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Punishment getBanByIP(String ip)
|
||||||
|
{
|
||||||
|
final Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeAdapter()).setPrettyPrinting().create();
|
||||||
|
return plugin.getSqlPunishment().getPunishments(ip).stream().filter(punishment -> punishment.getType() == PunishmentType.TEMPBAN || punishment.getType() == PunishmentType.BAN).filter(Punishment::isActive).filter(punishment -> punishment.getIp().equals(ip)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isBanned(PlexPlayer player)
|
public boolean isBanned(PlexPlayer player)
|
||||||
{
|
{
|
||||||
return isBanned(player.getUuid());
|
return isBanned(player.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<List<Punishment>> getActiveBans()
|
public CompletableFuture<List<Punishment>> getActiveBans()
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
return CompletableFuture.supplyAsync(() ->
|
|
||||||
{
|
|
||||||
List<PlexPlayer> players = Plex.get().getMongoPlayerData().getPlayers();
|
|
||||||
return players.stream().map(PlexPlayer::getPunishments).flatMap(Collection::stream).filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN).toList();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
//PlexLog.debug("Checking active bans mysql");
|
//PlexLog.debug("Checking active bans mysql");
|
||||||
CompletableFuture<List<Punishment>> future = new CompletableFuture<>();
|
CompletableFuture<List<Punishment>> future = new CompletableFuture<>();
|
||||||
@ -179,7 +169,6 @@ public class PunishmentManager implements PlexBase
|
|||||||
});
|
});
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void unban(Punishment punishment)
|
public void unban(Punishment punishment)
|
||||||
{
|
{
|
||||||
@ -187,22 +176,9 @@ public class PunishmentManager implements PlexBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Void> unban(UUID uuid)
|
public CompletableFuture<Void> unban(UUID uuid)
|
||||||
{
|
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
|
||||||
{
|
|
||||||
return CompletableFuture.runAsync(() ->
|
|
||||||
{
|
|
||||||
PlexPlayer plexPlayer = DataUtils.getPlayer(uuid);
|
|
||||||
plexPlayer.setPunishments(plexPlayer.getPunishments().stream().filter(Punishment::isActive).filter(punishment -> punishment.getType() == PunishmentType.BAN || punishment.getType() == PunishmentType.TEMPBAN)
|
|
||||||
.peek(punishment -> punishment.setActive(false)).collect(Collectors.toList()));
|
|
||||||
DataUtils.update(plexPlayer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return Plex.get().getSqlPunishment().removeBan(uuid);
|
return Plex.get().getSqlPunishment().removeBan(uuid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void doPunishment(PlexPlayer player, Punishment punishment)
|
private void doPunishment(PlexPlayer player, Punishment punishment)
|
||||||
{
|
{
|
||||||
@ -262,5 +238,6 @@ public class PunishmentManager implements PlexBase
|
|||||||
private final List<String> usernames = Lists.newArrayList();
|
private final List<String> usernames = Lists.newArrayList();
|
||||||
private final List<UUID> uuids = Lists.newArrayList();
|
private final List<UUID> uuids = Lists.newArrayList();
|
||||||
private final List<String> ips = Lists.newArrayList();
|
private final List<String> ips = Lists.newArrayList();
|
||||||
|
private final String reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package dev.plex.punishment.extra;
|
package dev.plex.punishment.extra;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import dev.morphia.annotations.Entity;
|
import dev.plex.storage.annotation.NoLimit;
|
||||||
|
import dev.plex.storage.annotation.SQLTable;
|
||||||
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
import dev.plex.util.adapter.ZonedDateTimeAdapter;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@ -9,10 +10,12 @@ import java.time.ZonedDateTime;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@SQLTable("notes")
|
||||||
public class Note
|
public class Note
|
||||||
{
|
{
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
|
||||||
|
@NoLimit
|
||||||
private final String note;
|
private final String note;
|
||||||
private final UUID writtenBy;
|
private final UUID writtenBy;
|
||||||
private final ZonedDateTime timestamp;
|
private final ZonedDateTime timestamp;
|
||||||
|
@ -1,199 +0,0 @@
|
|||||||
package dev.plex.rank;
|
|
||||||
|
|
||||||
import dev.plex.Plex;
|
|
||||||
import dev.plex.hook.VaultHook;
|
|
||||||
import dev.plex.player.PlexPlayer;
|
|
||||||
import dev.plex.rank.enums.Rank;
|
|
||||||
import dev.plex.rank.enums.Title;
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.json.JSONTokener;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class RankManager
|
|
||||||
{
|
|
||||||
private final File options;
|
|
||||||
|
|
||||||
public RankManager()
|
|
||||||
{
|
|
||||||
File ranksFolder = new File(Plex.get().getDataFolder() + File.separator + "ranks");
|
|
||||||
if (!ranksFolder.exists())
|
|
||||||
{
|
|
||||||
ranksFolder.mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
options = new File(ranksFolder, "options.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public void generateDefaultRanks()
|
|
||||||
{
|
|
||||||
if (options.exists())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONObject object = new JSONObject();
|
|
||||||
object.put("ranks", new JSONArray().putAll(Arrays.stream(Rank.values()).map(Rank::toJSON).collect(Collectors.toList())));
|
|
||||||
object.put("titles", new JSONArray().putAll(Arrays.stream(Title.values()).map(Title::toJSON).collect(Collectors.toList())));
|
|
||||||
FileWriter writer = new FileWriter(options);
|
|
||||||
writer.append(object.toString(4));
|
|
||||||
writer.flush();
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rank getRankFromString(String rank)
|
|
||||||
{
|
|
||||||
return Rank.valueOf(rank.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void importDefaultRanks()
|
|
||||||
{
|
|
||||||
if (!options.exists())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (FileInputStream fis = new FileInputStream(options))
|
|
||||||
{
|
|
||||||
JSONTokener tokener = new JSONTokener(fis);
|
|
||||||
JSONObject object = new JSONObject(tokener);
|
|
||||||
|
|
||||||
JSONArray ranks = object.getJSONArray("ranks");
|
|
||||||
ranks.forEach(r ->
|
|
||||||
{
|
|
||||||
JSONObject rank = new JSONObject(r.toString());
|
|
||||||
String key = rank.keys().next();
|
|
||||||
Rank.valueOf(key).setLoginMessage(rank.getJSONObject(key).getString("loginMessage"));
|
|
||||||
Rank.valueOf(key).setPrefix(rank.getJSONObject(key).getString("prefix"));
|
|
||||||
});
|
|
||||||
|
|
||||||
JSONArray titles = object.getJSONArray("titles");
|
|
||||||
titles.forEach(t ->
|
|
||||||
{
|
|
||||||
JSONObject title = new JSONObject(t.toString());
|
|
||||||
String key = title.keys().next();
|
|
||||||
Title.valueOf(key).setLoginMessage(title.getJSONObject(key).getString("loginMessage"));
|
|
||||||
Title.valueOf(key).setPrefix(title.getJSONObject(key).getString("prefix"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getConfigPrefixes(PlexPlayer plexPlayer)
|
|
||||||
{
|
|
||||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
|
||||||
{
|
|
||||||
return Title.OWNER.getPrefix();
|
|
||||||
}
|
|
||||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
|
||||||
{
|
|
||||||
return Title.DEV.getPrefix();
|
|
||||||
}
|
|
||||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
|
||||||
{
|
|
||||||
return Title.MASTER_BUILDER.getPrefix();
|
|
||||||
}
|
|
||||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
return plexPlayer.getRankFromString().getPrefix();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getPrefix(PlexPlayer plexPlayer)
|
|
||||||
{
|
|
||||||
if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty())
|
|
||||||
{
|
|
||||||
return SafeMiniMessage.mmDeserializeWithoutEvents(plexPlayer.getPrefix());
|
|
||||||
}
|
|
||||||
if (getConfigPrefixes(plexPlayer) != null)
|
|
||||||
{
|
|
||||||
getConfigPrefixes(plexPlayer);
|
|
||||||
}
|
|
||||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault") && Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
|
||||||
{
|
|
||||||
return VaultHook.getPrefix(plexPlayer);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLoginMessage(PlexPlayer plexPlayer)
|
|
||||||
{
|
|
||||||
String prepend;
|
|
||||||
// We don't want to prepend the "<player> is" if the login message is custom
|
|
||||||
if (!plexPlayer.getLoginMessage().isEmpty())
|
|
||||||
{
|
|
||||||
return plexPlayer.getLoginMessage()
|
|
||||||
.replace("%player%", plexPlayer.getName())
|
|
||||||
.replace("%rank%", plexPlayer.getRank());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prepend = MiniMessage.miniMessage().serialize(Component.text(plexPlayer.getName() + " is ").color(NamedTextColor.AQUA));
|
|
||||||
}
|
|
||||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
|
||||||
{
|
|
||||||
return prepend + Title.OWNER.getLoginMessage();
|
|
||||||
}
|
|
||||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
|
||||||
{
|
|
||||||
return prepend + Title.DEV.getLoginMessage();
|
|
||||||
}
|
|
||||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
|
||||||
{
|
|
||||||
return prepend + Title.MASTER_BUILDER.getLoginMessage();
|
|
||||||
}
|
|
||||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
return prepend + plexPlayer.getRankFromString().getLoginMessage();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public NamedTextColor getColor(PlexPlayer plexPlayer)
|
|
||||||
{
|
|
||||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
|
||||||
{
|
|
||||||
return Title.OWNER.getColor();
|
|
||||||
}
|
|
||||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
|
||||||
{
|
|
||||||
return Title.DEV.getColor();
|
|
||||||
}
|
|
||||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
|
||||||
{
|
|
||||||
return Title.MASTER_BUILDER.getColor();
|
|
||||||
}
|
|
||||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
|
||||||
{
|
|
||||||
return plexPlayer.getRankFromString().getColor();
|
|
||||||
}
|
|
||||||
return NamedTextColor.WHITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAdmin(PlexPlayer plexPlayer)
|
|
||||||
{
|
|
||||||
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSeniorAdmin(PlexPlayer plexPlayer)
|
|
||||||
{
|
|
||||||
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.SENIOR_ADMIN) && plexPlayer.isAdminActive();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package dev.plex.rank.enums;
|
|
||||||
|
|
||||||
import dev.plex.util.PlexUtils;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public enum Rank
|
|
||||||
{
|
|
||||||
IMPOSTOR(-1, "<aqua>an <yellow>Impostor<reset>", "Impostor", "<dark_gray>[<yellow>Imp<dark_gray>]", NamedTextColor.YELLOW),
|
|
||||||
NONOP(0, "a <white>Non-Op<reset>", "Non-Op", "", NamedTextColor.WHITE),
|
|
||||||
OP(1, "an <green>Op<reset>", "Operator", "<dark_gray>[<green>OP<dark_gray>]", NamedTextColor.GREEN),
|
|
||||||
ADMIN(2, "an <dark_green>Admin<reset>", "Admin", "<dark_gray>[<green>Admin<dark_gray>]", NamedTextColor.DARK_GREEN),
|
|
||||||
SENIOR_ADMIN(3, "a <gold>Senior Admin<reset>", "Senior Admin", "<dark_gray>[<gold>SrA<dark_gray>]", NamedTextColor.GOLD),
|
|
||||||
EXECUTIVE(4, "an <red>Executive<reset>", "Executive", "<dark_gray>[<red>Exec<dark_gray>]", NamedTextColor.RED);
|
|
||||||
|
|
||||||
private final int level;
|
|
||||||
@Getter
|
|
||||||
private final NamedTextColor color;
|
|
||||||
@Setter
|
|
||||||
private String loginMessage;
|
|
||||||
@Setter
|
|
||||||
private String readable;
|
|
||||||
@Setter
|
|
||||||
private String prefix;
|
|
||||||
|
|
||||||
Rank(int level, String loginMessage, String readable, String prefix, NamedTextColor color)
|
|
||||||
{
|
|
||||||
this.level = level;
|
|
||||||
this.loginMessage = loginMessage;
|
|
||||||
this.readable = readable;
|
|
||||||
this.prefix = prefix;
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAtLeast(Rank rank)
|
|
||||||
{
|
|
||||||
return this.level >= rank.getLevel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getPrefix()
|
|
||||||
{
|
|
||||||
return PlexUtils.mmDeserialize(this.prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject toJSON()
|
|
||||||
{
|
|
||||||
JSONObject object = new JSONObject();
|
|
||||||
object.put("prefix", this.prefix);
|
|
||||||
object.put("loginMessage", this.loginMessage);
|
|
||||||
return new JSONObject().put(this.name(), object);
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user