Compare commits
1
Commits
1.2.1
..
development
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a330c82bde |
No files matched your search
+28
-13
@@ -1,13 +1,28 @@
|
||||
gradle.properties
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
# Compiled class file
|
||||
*.class
|
||||
/target
|
||||
/.idea
|
||||
/out
|
||||
|
||||
*.iml
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
@@ -1,63 +1,34 @@
|
||||

|
||||
|
||||
# SudoSigns-OG
|
||||
|
||||
A modern fork of SudoSigns: A Spigot plugin used to run commands by interacting with a sign. Some inspiration for commands has been taken from [Nokorbis' Command Signs](https://www.spigotmc.org/resources/command-signs.10512/). MylesMor implemented a convenient inventory-based GUI. NotAlexNoyle updated the plugin for 1.19 on behalf of [TrueOG Network](https://true-og.net).
|
||||
|
||||
# SudoSigns
|
||||
A Spigot plugin used to run commands by interacting with a sign. Some inspiration for commands has been taken from [Nokorbis' Command Signs](https://www.spigotmc.org/resources/command-signs.10512/), but all the code is my own, and I have also implemented a convenient inventory-based GUI.
|
||||
This allows you to perform actions on SudoSigns such as:
|
||||
* Editing the sign's text
|
||||
* Adding permissions that a player must have to run the sign's commands
|
||||
* Adding either player or console commands to a sign
|
||||
* Adding messages which are shown to the player
|
||||
* Use color codes (`&`) on the sign for coloured text
|
||||
* Use colour codes (`&`) on the sign for coloured text
|
||||
* Adding delays to commands/messages
|
||||
* (Vault Economy) Setting the price of running a sign
|
||||
|
||||
For in-depth details on the command, permissions and features of this plugin, visit the [Wiki](https://github.com/MylesMor/SudoSigns/wiki)!
|
||||
|
||||
## Installation
|
||||
1. Clone the git repository: [https://github.com/NotAlexNoyle/SudoSigns-OG](https://github.com/NotAlexNoyle/SudoSigns-OG).
|
||||
2. Build the plugin with `./gradlew build`
|
||||
3. Place the JAR file from SudoSigns-OG/build/libs inside your server's `./plugins` directory.
|
||||
4. Reload or restart the server.
|
||||
1. Download the Spigot plugin [HERE](https://www.spigotmc.org/resources/sudosigns-commands-messages-on-signs.80758/).
|
||||
2. Place the JAR file inside your `./plugins` directory.
|
||||
3. Reload or restart the server.
|
||||
|
||||
## Getting Started
|
||||
Visit the [Getting Started](https://github.com/MylesMor/SudoSigns/wiki/Getting-Started) page to find out how to setup your first SudoSign!
|
||||
|
||||
## Issues
|
||||
Contact the developer in #plugin-help on the [TrueOG Network Discord](https://discord.gg/ma9pMYpBU6).
|
||||
The best course of action would be opening an issue [here](https://github.com/MylesMor/SudoSigns/issues), but I will also try to keep up-to-date with the Spigot comments section.
|
||||
|
||||
In your issue report, please include as much information as possible including:
|
||||
* The Spigot version.
|
||||
* Any errors in the console (please copy these in full).
|
||||
* The steps to reproduce the issue.
|
||||
* The Spigot version
|
||||
* Any errors in the console (please copy these in full)
|
||||
* The steps to reproduce the issue
|
||||
|
||||
## Planned Features
|
||||
|
||||
- Fix messages being sent to chat that should only be captured by SudoSigns.
|
||||
|
||||
- Add an option to change or completely disable the prefix in config file (Fix [#5](https://github.com/MylesMor/SudoSigns/issues/5) upstream).
|
||||
|
||||
- Add a config option to change the currency symbol, and its placement.
|
||||
|
||||
## Changelog:
|
||||
|
||||
**1.2.1:**
|
||||
|
||||
- Uppercase color code support.
|
||||
|
||||
- Fixed NullPointerException with unrecognized commands.
|
||||
|
||||
**1.2.0:**
|
||||
|
||||
- 1.19.4 Support.
|
||||
|
||||
- Convert from maven to gradle.
|
||||
|
||||
- Removed spigot update checker.
|
||||
|
||||
- Ignore formatting codes when calculating the maximum line length (Adopt [#4](https://github.com/MylesMor/SudoSigns/pull/4) upstream).
|
||||
|
||||
- Lowercase color code support.
|
||||
|
||||
- Fixed errors when missing command parameters.
|
||||
## Upcoming Features
|
||||
These features will be available in future updates!
|
||||
* None currently planned, send me suggestions!
|
||||
@@ -1,89 +0,0 @@
|
||||
plugins {
|
||||
|
||||
id 'java' // Tell gradle this is a java project.
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1' // Import utility to package libraries into .jar file.
|
||||
id 'eclipse' // Import eclipse plugin for IDE integration.
|
||||
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
// Declare java version.
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
}
|
||||
|
||||
group = "dev.mylesmor.sudosigns" // Declare bundle identifier.
|
||||
version = "1.2.1" // Declare plugin version (will be in .jar).
|
||||
|
||||
def apiVersion = "1.19" // Declare minecraft server target version.
|
||||
|
||||
processResources {
|
||||
|
||||
def props = [
|
||||
version: version,
|
||||
apiVersion: apiVersion,
|
||||
]
|
||||
|
||||
inputs.properties props // Indicates to rerun if version changes.
|
||||
|
||||
filesMatching("plugin.yml") {
|
||||
|
||||
expand props
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
||||
mavenCentral()
|
||||
|
||||
maven {
|
||||
|
||||
url "https://repo.purpurmc.org/snapshots" // Get purpur API from purpur maven repository.
|
||||
|
||||
}
|
||||
|
||||
maven {
|
||||
|
||||
url "https://jitpack.io"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
compileOnly "org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT" // Declare purpur API version to be packaged.
|
||||
compileOnly "com.github.MilkBowl:VaultAPI:1.7" // Declare Vault APi version to be packaged.
|
||||
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
|
||||
minimize()
|
||||
|
||||
}
|
||||
|
||||
jar.dependsOn shadowJar
|
||||
|
||||
tasks.jar.configure {
|
||||
|
||||
archiveClassifier = "part"
|
||||
|
||||
}
|
||||
|
||||
tasks.shadowJar.configure {
|
||||
|
||||
archiveClassifier = null
|
||||
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
|
||||
options.compilerArgs += ["-parameters"]
|
||||
options.encoding = 'UTF-8' // Override the system character set with a universal set.
|
||||
options.fork = true // Enable compilation in a separate daemon process.
|
||||
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
-7
@@ -1,7 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,249 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# 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
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
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
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# 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"'
|
||||
|
||||
# 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 -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
-92
@@ -1,92 +0,0 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<groupId>dev.mylesmor.sudosigns</groupId>
|
||||
<artifactId>SudoSigns</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.1</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.9</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1 +0,0 @@
|
||||
rootProject.name = "SudoSigns-OG"
|
||||
@@ -1,15 +1,5 @@
|
||||
package dev.mylesmor.sudosigns;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import dev.mylesmor.sudosigns.commands.Commands;
|
||||
import dev.mylesmor.sudosigns.commands.SudoSignsTabCompleter;
|
||||
import dev.mylesmor.sudosigns.config.ConfigManager;
|
||||
@@ -19,7 +9,16 @@ import dev.mylesmor.sudosigns.listeners.ChatListener;
|
||||
import dev.mylesmor.sudosigns.listeners.InventoryListener;
|
||||
import dev.mylesmor.sudosigns.listeners.PlayerListener;
|
||||
import dev.mylesmor.sudosigns.listeners.SignListener;
|
||||
import dev.mylesmor.sudosigns.util.UpdateChecker;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Main class for SudoSigns.
|
||||
@@ -28,51 +27,74 @@ import net.milkbowl.vault.economy.Economy;
|
||||
*/
|
||||
public class SudoSigns extends JavaPlugin {
|
||||
|
||||
public static Map<String, SudoSign> signs = new HashMap<>();
|
||||
public static ArrayList<String> invalidSigns = new ArrayList<>();
|
||||
public static Map<String, SudoSign> signs = new HashMap<>();
|
||||
public static ArrayList<String> invalidSigns = new ArrayList<>();
|
||||
|
||||
public static Map<UUID, SudoUser> users = new HashMap<>();
|
||||
public static Map<UUID, SudoUser> users = new HashMap<>();
|
||||
|
||||
public static ConfigManager config;
|
||||
public static ConfigManager config;
|
||||
|
||||
public static Plugin sudoSignsPlugin;
|
||||
public static Plugin sudoSignsPlugin;
|
||||
|
||||
public static String version;
|
||||
public static String version;
|
||||
|
||||
public static Economy econ = null;
|
||||
public static Economy econ = null;
|
||||
public static boolean papi = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
setupEconomy();
|
||||
String version = getServer().getVersion().split("MC: ")[1];
|
||||
SudoSigns.version = version.substring(0, version.length()-1);
|
||||
getServer().getPluginManager().registerEvents(new SignListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new ChatListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
sudoSignsPlugin = this;
|
||||
config = new ConfigManager();
|
||||
config.loadModules();
|
||||
this.getCommand("sudosigns").setExecutor(new Commands());
|
||||
this.getCommand("sudosigns").setTabCompleter(new SudoSignsTabCompleter());
|
||||
}
|
||||
|
||||
public boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Vault not found, sign prices disabled...");
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] No compatible economy plugin found, sign prices disabled...");
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void onEnable() {
|
||||
setupEconomy();
|
||||
setupPapi();
|
||||
new UpdateChecker(this, 80758).getVersion(version -> {
|
||||
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
|
||||
Bukkit.getLogger().info("[SUDOSIGNS] SudoSigns is up-to-date.");
|
||||
} else {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] There is a new update available (" + version + ")! Please update for all the latest features, bug fixes and improvements! https://www.spigotmc.org/resources/sudosigns-commands-messages-on-signs.80758/");
|
||||
}
|
||||
});
|
||||
String version = getServer().getVersion().split("MC: ")[1];
|
||||
SudoSigns.version = version.substring(0, version.length()-1);
|
||||
getServer().getPluginManager().registerEvents(new SignListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new ChatListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
||||
sudoSignsPlugin = this;
|
||||
config = new ConfigManager();
|
||||
config.loadModules();
|
||||
this.getCommand("sudosigns").setExecutor(new Commands());
|
||||
this.getCommand("sudosigns").setTabCompleter(new SudoSignsTabCompleter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
/**
|
||||
* Setup Vault economy if compatible plugins found.
|
||||
* @return Vault Economy object or null.
|
||||
*/
|
||||
public boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Vault not found, sign prices disabled...");
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] No compatible economy plugin found, sign prices disabled...");
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Allow PlaceholderAPI to be used if plugin found.
|
||||
*/
|
||||
public void setupPapi() {
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] PlaceholderAPI found! Integration enabled.");
|
||||
papi = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() { }
|
||||
}
|
||||
@@ -1,104 +1,60 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
|
||||
public class Commands implements CommandExecutor {
|
||||
|
||||
Map<String, BiConsumer<Player, String[]>> commands = new HashMap<>();
|
||||
Map<String, BiConsumer<Player, String[]>> commands = new HashMap<>();
|
||||
|
||||
public Commands() {
|
||||
public Commands() {
|
||||
commands.put("help", Help::help);
|
||||
commands.put("near", Near::near);
|
||||
commands.put("list", List::list);
|
||||
commands.put("delete", Delete::delete);
|
||||
commands.put("edit", Edit::edit);
|
||||
commands.put("view", View::view);
|
||||
commands.put("run", Run::run);
|
||||
commands.put("confirmdelete", Delete::confirmDelete);
|
||||
commands.put("reload", Reload::reload);
|
||||
commands.put("create", Create::create);
|
||||
commands.put("tp", Teleport::tp);
|
||||
commands.put("copy", Copy::copy);
|
||||
commands.put("select", Select::select);
|
||||
commands.put("purge", Purge::purge);
|
||||
commands.put("confirmpurge", Purge::confirmPurge);
|
||||
commands.put("fix", Fix::fix);
|
||||
}
|
||||
|
||||
commands.put("help", Help::help);
|
||||
commands.put("near", Near::near);
|
||||
commands.put("list", List::list);
|
||||
commands.put("delete", Delete::delete);
|
||||
commands.put("edit", Edit::edit);
|
||||
commands.put("view", View::view);
|
||||
commands.put("run", Run::run);
|
||||
commands.put("confirmdelete", Delete::confirmDelete);
|
||||
commands.put("reload", Reload::reload);
|
||||
commands.put("create", Create::create);
|
||||
commands.put("tp", Teleport::tp);
|
||||
commands.put("copy", Copy::copy);
|
||||
commands.put("select", Select::select);
|
||||
commands.put("purge", Purge::purge);
|
||||
commands.put("confirmpurge", Purge::confirmPurge);
|
||||
commands.put("fix", Fix::fix);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
if (sender instanceof Player) {
|
||||
|
||||
final Player p = (Player) sender;
|
||||
SudoSigns.users.computeIfAbsent(p.getUniqueId(), k -> new SudoUser(p));
|
||||
try {
|
||||
|
||||
BiConsumer<Player, String[]> command = commands.get(args[0].toLowerCase());
|
||||
|
||||
if(command != null) {
|
||||
|
||||
if (args.length > 1) {
|
||||
|
||||
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
|
||||
command.accept(p, newArgs);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
try {
|
||||
|
||||
command.accept(p, null);
|
||||
|
||||
}
|
||||
catch(CommandException error) {
|
||||
|
||||
invalidCommandError(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
invalidCommandError(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
|
||||
invalidCommandError(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private void invalidCommandError(Player p) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid command! &6Type &d/ss help &6for a list of valid commands.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if ((sender instanceof Player)) {
|
||||
final Player p = (Player) sender;
|
||||
SudoSigns.users.computeIfAbsent(p.getUniqueId(), k -> new SudoUser(p));
|
||||
try {
|
||||
BiConsumer<Player, String[]> command = commands.get(args[0].toLowerCase());
|
||||
if (args.length > 1) {
|
||||
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
command.accept(p, newArgs);
|
||||
} else {
|
||||
command.accept(p, null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid command!" + ChatColor.GRAY + " Type " + ChatColor.LIGHT_PURPLE + "/ss help " + ChatColor.GRAY + "for a list of commands.", null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,59 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Copy {
|
||||
/**
|
||||
* Copies one sign's data to another.
|
||||
* @param p The player running the command.
|
||||
* @param args 1 or 2 arguments: If 1, the name of the new sign. If 2, the name of the old sign in index 0 and name of new one in index 1.
|
||||
*/
|
||||
public static void copy(Player p, String[] args) {
|
||||
/**
|
||||
* Copies one sign's data to another.
|
||||
* @param p The player running the command.
|
||||
* @param args 1 or 2 arguments: If 1, the name of the new sign. If 2, the name of the old sign in index 0 and name of new one in index 1.
|
||||
*/
|
||||
public static void copy(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.COPY)) {
|
||||
String oldName = null;
|
||||
String newName = null;
|
||||
if (args == null || args.length < 1 || args.length > 2) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss copy [old-sign-name] <new-sign-name>" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
newName = args[0];
|
||||
} else {
|
||||
newName = args[1];
|
||||
oldName = args[0];
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.COPY)) {
|
||||
|
||||
String oldName = null;
|
||||
String newName = null;
|
||||
if (args == null || args.length < 1 || args.length > 2) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &6Correct syntax: &d/ss copy [old-sign-name] <new-sign-name>&6.");
|
||||
return;
|
||||
|
||||
}
|
||||
if (args.length == 1) {
|
||||
|
||||
newName = args[0];
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
newName = args[1];
|
||||
oldName = args[0];
|
||||
|
||||
}
|
||||
|
||||
if (Util.checkName(newName)) {
|
||||
|
||||
SudoSigns.users.get(p.getUniqueId()).setPassThru(newName);
|
||||
if (oldName == null) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please click the sign you'd like to copy from.");
|
||||
SudoSigns.users.get(p.getUniqueId()).setSelectToCopy(true);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
SudoSign oldSign = SudoSigns.signs.get(oldName);
|
||||
if (oldSign != null) {
|
||||
|
||||
if (! SudoSigns.signs.containsKey(newName)) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please click the sign you'd like to copy to.");
|
||||
SudoSign newSign = new SudoSign(newName);
|
||||
|
||||
newSign.copyFrom(oldSign);
|
||||
|
||||
SudoSigns.users.get(p.getUniqueId()).setCopy(true);
|
||||
SudoSigns.signs.put(newName, newSign);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &e%NAME% &calready exists!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &e%NAME% &cdoes not exist!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: The name of a SudoSign must only contain numbers and letters!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Util.checkName(newName)) {
|
||||
SudoSigns.users.get(p.getUniqueId()).setPassThru(newName);
|
||||
if (oldName == null) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Please click the sign you'd like to copy from!", null);
|
||||
SudoSigns.users.get(p.getUniqueId()).setSelectToCopy(true);
|
||||
} else {
|
||||
SudoSign oldSign = SudoSigns.signs.get(oldName);
|
||||
if (oldSign != null) {
|
||||
if (!SudoSigns.signs.containsKey(newName)) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Please click the sign you'd like to copy to!", null);
|
||||
SudoSign newSign = new SudoSign(newName);
|
||||
newSign.copyFrom(oldSign);
|
||||
SudoSigns.users.get(p.getUniqueId()).setCopy(true);
|
||||
SudoSigns.signs.put(newName, newSign);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% already exists!", newName);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "A sign with name %NAME% doesn't exist!", oldName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "The name of a SudoSign must only contain numbers and letters!", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,40 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Create {
|
||||
|
||||
/**
|
||||
* Creates a sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void create(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
|
||||
if (args == null) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &6Correct syntax: &d/ss create <name>&6.");
|
||||
return;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
String name = args[0];
|
||||
if (Util.checkName(name)) {
|
||||
|
||||
if (! SudoSigns.signs.containsKey(name)) {
|
||||
|
||||
SudoSigns.users.get(p.getUniqueId()).setCreate(true);
|
||||
SudoSigns.users.get(p.getUniqueId()).setPassThru(name);
|
||||
SudoSigns.signs.put(name, new SudoSign(name));
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please click on the sign you'd like to create.");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with name &e%NAME% &calready exists!", name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: The name of a SudoSign must only contain numbers and letters!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Creates a sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void create(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss create <name>" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
String name = args[0];
|
||||
if (Util.checkName(name)) {
|
||||
if (!SudoSigns.signs.containsKey(name)) {
|
||||
SudoSigns.users.get(p.getUniqueId()).setCreate(true);
|
||||
SudoSigns.users.get(p.getUniqueId()).setPassThru(name);
|
||||
SudoSigns.signs.put(name, new SudoSign(name));
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Please click the sign you'd like to create!", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% already exists!", name);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "The name of a SudoSign must only contain numbers and letters!", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,58 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Delete {
|
||||
/**
|
||||
* Deletes a sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 1 or 2 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void delete(Player p, String[] args) {
|
||||
/**
|
||||
* Deletes a sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 1 or 2 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void delete(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
String name;
|
||||
if (args != null) {
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss delete [name]" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Please click the sign you'd like to delete!", null);
|
||||
SudoSigns.users.get(p.getUniqueId()).setDelete(true);
|
||||
return;
|
||||
}
|
||||
name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
SudoSigns.signs.remove(name);
|
||||
SudoSigns.config.deleteSign(name);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Sign %NAME% successfully deleted!", name);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% doesn't exist!", name);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
|
||||
String name;
|
||||
if (args != null) {
|
||||
|
||||
if (args.length > 1) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &7Correct syntax: &d/ss delete [name]&7.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
Util.sudoSignsMessage(p, "&6Please click the sign you'd like to delete.");
|
||||
SudoSigns.users.get(p.getUniqueId()).setDelete(true);
|
||||
return;
|
||||
}
|
||||
|
||||
name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
|
||||
SudoSigns.signs.remove(name);
|
||||
SudoSigns.config.deleteSign(name);
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Sign &e%NAME% &6successfully deleted.", name);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &eNAME% &cdoes not exist!", name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms deletion of a sign (only run when [DELETE] is clicked in the selection message).
|
||||
* @param p The player running the command.
|
||||
* @param args 1 argument: The name of the sign.
|
||||
*/
|
||||
public static void confirmDelete(Player p, String[] args) {
|
||||
|
||||
// If the player has permission to delete signs, do this...
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
|
||||
// If the sign that was selected does not exist, do this...
|
||||
if (args.length != 1) {
|
||||
|
||||
// Cancel the deletion confirmation.
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (SudoSigns.signs.containsKey(args[0])) {
|
||||
|
||||
// Send a deletion confirmation menu with a clickable button.
|
||||
Util.selectMenuParser(p, "&c&l[CONFIRM DELETION]", ("&6Are you sure you want to delete sign &e" + args[0] + "&6?"), p.getName(), ("/ss delete " + args[0]), ("&cYes, delete the sign: &6" + args[0] + "&c!"));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &e%NAME% &cdoes not exist!", args[0]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Confirms deletion of a sign (only run when [DELETE] is clicked in the selection message).
|
||||
* @param p The player running the command.
|
||||
* @param args 1 argument: The name of the sign.
|
||||
*/
|
||||
public static void confirmDelete(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
if (args.length != 1) return;
|
||||
if (SudoSigns.signs.containsKey(args[0])) {
|
||||
String message = "[\"\",{\"text\":\"[SUDOSIGNS] \",\"color\":\"yellow\"},{\"text\":\"Are you sure you want to delete sign \",\"color\":\"gray\"},{\"text\":\"" + args[0] + "\",\"color\":\"gold\"},{\"text\":\"? \",\"color\":\"gray\"},{\"text\":\"[YES] \",\"bold\":true,\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss delete " + args[0] + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Yes, delete the sign!\",\"color\":\"green\"}]}}]";
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% doesn't exist!", args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,40 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Edit {
|
||||
|
||||
/**
|
||||
* Edits a sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void edit(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
|
||||
String name;
|
||||
if (args == null) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please click on the sign you'd like to edit.");
|
||||
|
||||
SudoSigns.users.get(p.getUniqueId()).setEdit(true);
|
||||
return;
|
||||
|
||||
}
|
||||
if (args.length > 1) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &aCorrect syntax: &d/ss edit [name]&a.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
|
||||
SignEditor editor = new SignEditor(p, SudoSigns.signs.get(name), SudoSigns.users.get(p.getUniqueId()));
|
||||
SudoSigns.users.get(p.getUniqueId()).setEditor(editor);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name %NAME% &cdoes not exist!", name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Edits a sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void edit(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
String name;
|
||||
if (args == null) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Please click the sign you'd like to edit!", null);
|
||||
SudoSigns.users.get(p.getUniqueId()).setEdit(true);
|
||||
return;
|
||||
}
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss edit [name]" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
SignEditor editor = new SignEditor(p, SudoSigns.signs.get(name), SudoSigns.users.get(p.getUniqueId()));
|
||||
SudoSigns.users.get(p.getUniqueId()).setEditor(editor);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% doesn't exist!", name);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +1,51 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Fix {
|
||||
/**
|
||||
* Attempt to fix an invalid entry by placing a sign in the config location.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign.
|
||||
*/
|
||||
public static void fix(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.FIX)) {
|
||||
|
||||
String name;
|
||||
if (args == null) {
|
||||
|
||||
int size = SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size();
|
||||
if (SudoSigns.config.getInvalidEntriesManager().fixInvalidEntry(null, true)) {
|
||||
|
||||
SudoSigns.config.loadSigns();
|
||||
if (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() == 0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aAll invalid entries have been successfully purged from the config.");
|
||||
|
||||
}
|
||||
else if (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() == size) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: No invalid entries were able to be automatically purged from the config!");
|
||||
|
||||
}
|
||||
else if (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() < size) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&e" + (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() - size) + "&a invalid entries were able to be automatically purged from the config. &e" + Integer.toString(SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size()) + "&c were unable to be automatically purged from the config!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (args.length > 2) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &6Correct syntax: &d/ss fix [name]&6.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
name = args[0];
|
||||
if (SudoSigns.config.getInvalidEntriesManager().fixInvalidEntry(name, false)) {
|
||||
|
||||
SudoSigns.config.loadSigns();
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aSign &e" + name + "&asuccessfully fixed!");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Sign &e" + name + "&c was unable to be fixed!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6WARNING: Nothing fixed! That entry is not invalid.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Attempt to fix an invalid entry by placing a sign in the config location.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign.
|
||||
*/
|
||||
public static void fix(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.FIX)) {
|
||||
String name;
|
||||
if (args == null) {
|
||||
int size = SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size();
|
||||
if (SudoSigns.config.getInvalidEntriesManager().fixInvalidEntry(null, true)) {
|
||||
SudoSigns.config.loadSigns();
|
||||
if (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() == 0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "All invalid entries successfully purged from the config!", null);
|
||||
} else if (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() == size) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "No invalid entries were able to be fixed automatically!", null);
|
||||
} else if (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() < size) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "" + ChatColor.GOLD + (SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size() - size) + " invalid entries were able to be fixed automatically!" + ChatColor.GOLD + Integer.toString(SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size()) + ChatColor.RED + " were unable to be fixed!", null);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (args.length > 2) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss fix [name]" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
name = args[0];
|
||||
if (SudoSigns.config.getInvalidEntriesManager().fixInvalidEntry(name, false)) {
|
||||
SudoSigns.config.loadSigns();
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "Sign " + ChatColor.GOLD + name + ChatColor.GREEN + " successfully fixed!", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Sign " + ChatColor.GOLD + name + ChatColor.RED + " was unable to be fixed!", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Nothing fixed! That entry is not invalid.", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +1,62 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Help {
|
||||
|
||||
/**
|
||||
* Sends the player a help message.
|
||||
* @param p The player running the command.
|
||||
* @param args Not required.
|
||||
*/
|
||||
public static void help(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.HELP)) {
|
||||
|
||||
Util.sudoSignsMessageNoPrefix(p, "&b======" + Util.chatPrefix + " &eHelp" + "&b======");
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d <>" + "&f - &6indicates a required argument.");
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d []" + "&f - &6indicates an optional argument.");
|
||||
|
||||
if (p.hasPermission(Permissions.HELP)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss help" + " &f- &6Displays this menu.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss list" + " &f- &6Lists all SudoSigns.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss near [radius]" + " &f- &6Lists SudoSigns within a specified radius (default 5 blocks).");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss view [name]" + " &f- &6Displays the details of a SudoSign.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss run [name]" + " &f- &6Runs a SudoSigns commands remotely.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss tp [name]" + " &f- &6Teleport to a SudoSign.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss create <name>" + " &f- &6Creates a SudoSign with the specified name.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss edit [name]" + " &f- &6Displays the editor for the specified SudoSign.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.COPY)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss copy [old-sign-name] <new-sign-name>" + " &f- &6Copies the specified SudoSign to a new sign.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss delete [name]" + " &f- &6Deletes the specified SudoSign.");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss reload" + " &f- &6Reloads the configuration file (signs.yml).");
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
Util.sudoSignsMessageNoPrefix(p, "&e[!]" + "&d /ss purge [name]" + " &f- &6Removes a specified invalid entry from the config (leave name blank to purge all invalid entries).");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sends the player a help message.
|
||||
* @param p The player running the command.
|
||||
* @param args Not required.
|
||||
*/
|
||||
public static void help(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.HELP)) {
|
||||
p.sendMessage(ChatColor.GRAY + "======" + ChatColor.YELLOW + " SudoSigns Help " + ChatColor.GRAY + "======");
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " <>" + ChatColor.GRAY + " indicates a required argument.");
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " []" + ChatColor.GRAY + " indicates an optional argument.");
|
||||
if (p.hasPermission(Permissions.HELP)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss help" + ChatColor.GRAY + " - Displays this menu.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss list" + ChatColor.GRAY + " - Lists all SudoSigns.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss near [radius]" + ChatColor.GRAY + " - Lists SudoSigns within a specified radius (default 5 blocks).");
|
||||
}
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss view [name]" + ChatColor.GRAY + " - Displays the details of a SudoSign.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss run [name]" + ChatColor.GRAY + " - Runs a SudoSigns commands remotely.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss tp [name]" + ChatColor.GRAY + " - Teleport to a SudoSign.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss create <name>" + ChatColor.GRAY + " - Creates a SudoSign with the specified name.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss edit [name]" + ChatColor.GRAY + " - Displays the editor for the specified SudoSign.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.COPY)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss copy [old-sign-name] <new-sign-name>" + ChatColor.GRAY + " - Copies the specified SudoSign to a new sign.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss delete [name]" + ChatColor.GRAY + " - Deletes the specified SudoSign.");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss reload" + ChatColor.GRAY + " - Reloads the configuration file (signs.yml).");
|
||||
}
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
p.sendMessage(ChatColor.YELLOW + "[!]" + ChatColor.LIGHT_PURPLE + " /ss purge [name]" + ChatColor.GRAY + " - Removes a specified invalid entry from the config (leave name blank to purge all invalid entries).");
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,35 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class List {
|
||||
|
||||
/**
|
||||
* Lists all signs.
|
||||
* @param p The player running the command.
|
||||
* @param args Not required
|
||||
*/
|
||||
public static void list(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
|
||||
if (SudoSigns.signs.size() == 0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: No SudoSigns were found!");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Listing all SudoSigns...");
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
|
||||
Util.sendSelectMenus(p, entry.getKey());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Lists all signs.
|
||||
* @param p The player running the command.
|
||||
* @param args Not required
|
||||
*/
|
||||
public static void list(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
if (SudoSigns.signs.size() == 0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "No SudoSigns were found!", null);
|
||||
return;
|
||||
}
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Listing all SudoSigns...", null);
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
String message = Util.getSelectString(p, entry.getKey());
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +1,64 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Near {
|
||||
|
||||
/**
|
||||
* Displays signs within a set radius.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments, with the only argument being the radius to search in (default is 5 blocks).
|
||||
*/
|
||||
public static void near(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
int r;
|
||||
String radius = null;
|
||||
if (args != null) {
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! " + "&6Correct syntax: " + "&d/ss near [radius]" + "&6.");
|
||||
return;
|
||||
} else if (args.length == 1) {
|
||||
radius = args[0];
|
||||
}
|
||||
}
|
||||
if (radius == null) {
|
||||
r = 5;
|
||||
} else {
|
||||
try {
|
||||
r = Integer.parseInt(radius);
|
||||
} catch (NumberFormatException e) {
|
||||
Util.sudoSignsMessage(p, "&cERROR: &e" + radius + " &cis not a valid number! &6Reverting to a radius of &e5&6.");
|
||||
r = 5;
|
||||
}
|
||||
}
|
||||
boolean found = false;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
Location signLoc = entry.getValue().getSign().getLocation();
|
||||
try {
|
||||
if (signLoc.distance(p.getLocation()) <= r) {
|
||||
if (!found)
|
||||
Util.sudoSignsMessage(p, "&6Displaying SudoSigns within a radius of &e%NAME% &6block(s):&e", Integer.toString(r));
|
||||
found = true;
|
||||
Util.sendSelectMenus(p, entry.getKey());
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
if (!found) {
|
||||
Util.sudoSignsMessage(p, "&6No SudoSigns found within a radius of &e%NAME% &6block(s).&e", Integer.toString(r));
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cYou do not have permission to do that!");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Displays signs within a set radius.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments, with the only argument being the radius to search in (default is 5 blocks).
|
||||
*/
|
||||
public static void near(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
int r;
|
||||
String radius = null;
|
||||
if (args != null) {
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss near [radius]" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
} else if (args.length == 1) {
|
||||
radius = args[0];
|
||||
}
|
||||
}
|
||||
if (radius == null) {
|
||||
r = 5;
|
||||
} else {
|
||||
try {
|
||||
r = Integer.parseInt(radius);
|
||||
} catch (NumberFormatException e) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, ChatColor.GOLD + radius + ChatColor.RED + " is not a valid number! Reverting to a radius of 5.", null);
|
||||
r = 5;
|
||||
}
|
||||
}
|
||||
boolean found = false;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
Location signLoc = entry.getValue().getSign().getLocation();
|
||||
try {
|
||||
if (signLoc.distance(p.getLocation()) <= r) {
|
||||
if (!found)
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Displaying SudoSigns within a radius of %NAME% block(s):", Integer.toString(r));
|
||||
found = true;
|
||||
String message = Util.getSelectString(p, entry.getKey());
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
if (!found) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "No SudoSigns found within a radius of %NAME% block(s).", Integer.toString(r));
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +1,68 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Purge {
|
||||
|
||||
/**
|
||||
* Purge an invalid sign's config entry (or all if name not provided).
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign.
|
||||
*/
|
||||
public static void purge(Player p, String[] args) {
|
||||
/**
|
||||
* Purge an invalid sign's config entry (or all if name not provided).
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign.
|
||||
*/
|
||||
public static void purge(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
String name = null;
|
||||
if (args == null) {
|
||||
purgeAll(p);
|
||||
return;
|
||||
}
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss purge [name]" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
if (args.length == 1) name = args[0];
|
||||
if (name != null) {
|
||||
if (SudoSigns.config.getInvalidEntriesManager().purgeInvalidEntry(args[0], false)) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "Sign " + ChatColor.GOLD + args[0] + ChatColor.GREEN + " successfully purged from the config!", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Nothing purged! That entry is not invalid.", null);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
|
||||
String name = null;
|
||||
if (args == null) {
|
||||
|
||||
purgeAll(p);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (args.length > 1) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! " + "&6Correct syntax: " + "&d/ss purge [name]" + "&6.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
|
||||
name = args[0];
|
||||
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
|
||||
if (SudoSigns.config.getInvalidEntriesManager().purgeInvalidEntry(args[0], false)) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aSign &e" + args[0] + "&a successfully purged from the config!");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&eWARNING: &6Nothing purged! That entry is not invalid.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void purgeAll(Player p) {
|
||||
|
||||
int beforeSize = SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size();
|
||||
if (beforeSize == 0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&eWARNING: &6No invalid entries found to remove from the config!");
|
||||
return;
|
||||
|
||||
}
|
||||
if (SudoSigns.config.getInvalidEntriesManager().purgeInvalidEntry(null, true)) {
|
||||
|
||||
int afterSize = SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size();
|
||||
if (afterSize == 0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aAll invalid entries have been successfully purged from the config!");
|
||||
|
||||
}
|
||||
else if (afterSize == beforeSize) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: No invalid entries were able to be removed automatically!");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&e" + (beforeSize - afterSize) + "&a invalid config entries were able to be removed automatically. &e" + afterSize + " &6were unable to be removed automatically.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public static void confirmPurge(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
|
||||
if (args.length != 1) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Util.selectMenuParser(p, "&a&l[YES]", ("&6Are you sure you want to purge sign &e" + args[0] + "&6?"), p.getName(), ("/ss purge " + args[0]), ("&aYes, delete the sign: &6" + args[0] + "&a!"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private static void purgeAll(Player p) {
|
||||
int beforeSize = SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size();
|
||||
if (beforeSize == 0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "No invalid entries found to remove from the config!", null);
|
||||
return;
|
||||
}
|
||||
if (SudoSigns.config.getInvalidEntriesManager().purgeInvalidEntry(null, true)) {
|
||||
int afterSize = SudoSigns.config.getInvalidEntriesManager().getInvalidEntries().size();
|
||||
if (afterSize == 0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "All invalid entries successfully purged from the config!", null);
|
||||
} else if (afterSize == beforeSize) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "No invalid entries were able to be removed automatically!", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "" + ChatColor.GOLD + (beforeSize - afterSize) + " invalid entries were able to be removed automatically!" + ChatColor.GOLD + afterSize + ChatColor.RED + " were unable to be removed!", null);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static void confirmPurge(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
if (args.length != 1) return;
|
||||
String message = "[\"\",{\"text\":\"[SUDOSIGNS] \",\"color\":\"yellow\"},{\"text\":\"Are you sure you want to purge sign \",\"color\":\"gray\"},{\"text\":\"" + args[0] + "\",\"color\":\"gold\"},{\"text\":\"? \",\"color\":\"gray\"},{\"text\":\"[YES] \",\"bold\":true,\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss purge " + args[0] + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Yes, delete the sign!\",\"color\":\"green\"}]}}]";
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +1,59 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class Reload {
|
||||
|
||||
/**
|
||||
* Reloads the config file (signs.yml)
|
||||
* @param p The player running the command.
|
||||
* @param args Not required
|
||||
*/
|
||||
public static void reload(Player p, String[] args) {
|
||||
/**
|
||||
* Reloads the config file (signs.yml)
|
||||
* @param p The player running the command.
|
||||
* @param args Not required
|
||||
*/
|
||||
public static void reload(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Reloading config...", null);
|
||||
SudoSigns.signs.clear();
|
||||
if (SudoSigns.config.loadCustomConfig()) {
|
||||
ArrayList<String> invalidSigns = SudoSigns.config.loadSigns();
|
||||
if (invalidSigns != null) {
|
||||
if (invalidSigns.size() == 0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "Config successfully reloaded! Found " + invalidSigns.size() + " invalid signs! ", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, "Config successfully reloaded!" + ChatColor.RED + " Found " + invalidSigns.size() + " invalid sign(s): ", null);
|
||||
for (String name : invalidSigns) {
|
||||
StringBuilder clickableMessage = new StringBuilder("[\"\",{\"text\":\"[SUDOSIGNS] \",\"color\":\"yellow\"},{\"text\":\"Sign: \",\"color\":\"red\"},{\"text\":\"" + name + " \",\"bold\":true,\"color\":\"gold\"}]");
|
||||
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
clickableMessage = new StringBuilder(clickableMessage.substring(0, clickableMessage.length() - 1));
|
||||
clickableMessage.append(",{\"text\":\"[FIX] \",\"bold\":true,\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss fix ").append(name).append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Fix ").append(name).append(" by placing a replica of the sign at the location\",\"color\":\"green\"}]}}]");
|
||||
}
|
||||
if (p.hasPermission(Permissions.FIX)) {
|
||||
clickableMessage = new StringBuilder(clickableMessage.substring(0, clickableMessage.length() - 1));
|
||||
clickableMessage.append(",{\"text\":\"[PURGE]\",\"bold\":true,\"color\":\"red\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss confirmpurge ").append(name).append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Remove ").append(name).append(" from the config file\",\"color\":\"red\"}]}}]");
|
||||
}
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(clickableMessage.toString()));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] There was an error with the SudoSigns config!");
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "There was an error with the SudoSigns config! Continuing to use old config...", null);
|
||||
} else {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] There was an error with the SudoSigns config!");
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "There was an error with the SudoSigns config! Please attempt to fix before the next server reload/restart.", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Reloading config...");
|
||||
SudoSigns.signs.clear();
|
||||
|
||||
if (SudoSigns.config.loadCustomConfig()) {
|
||||
|
||||
ArrayList<String> invalidSigns = SudoSigns.config.loadSigns();
|
||||
if (invalidSigns != null) {
|
||||
|
||||
if (invalidSigns.size() == 0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aConfig successfully reloaded! No invalid signs found.");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aConfig successfully reloaded! &cERROR: Found &e" + invalidSigns.size() + " &cinvalid signs!");
|
||||
for (String name : invalidSigns) {
|
||||
|
||||
// If the player has permission to purge a sign, do this...
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
|
||||
// Send a fix confirmation menu with a clickable button.
|
||||
Util.selectMenuParser(p, "&a&l[FIX]", ("&cSign: &e&l" + name), name, ("/ss fix " + name), ("&6Fix &e" + name + "&6by placing a replica of the sign at the location."));
|
||||
|
||||
}
|
||||
|
||||
// If the player has permission to fix a sign, do this...
|
||||
if (p.hasPermission(Permissions.FIX)) {
|
||||
|
||||
// Send a purge confirmation menu with a clickable button.
|
||||
Util.selectMenuParser(p, "&c&l[PURGE]", ("&cSign: &e&l" + name), name, ("/ss confirmpurge " + name), (("&cRemove &e" + name + "&6from the config file.")));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] There was an error with the SudoSigns config!");
|
||||
Util.sudoSignsMessage(p, "&cERROR: The latest update to the SudoSigns config was invalid! &6Continuing to use old config...");
|
||||
|
||||
}
|
||||
else {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] There was an error with the SudoSigns config!");
|
||||
Util.sudoSignsMessage(p, "&cERROR: The latest update to the SudoSigns config was invalid! &6Please attempt to fix it before the next server restart or plugin reload attempt.");
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +1,40 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Run {
|
||||
/**
|
||||
* Runs a sign remotely.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void run(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
|
||||
String name;
|
||||
if (args == null) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please click on the sign you would like to run.");
|
||||
SudoSigns.users.get(p.getUniqueId()).setRun(true);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (args.length > 1) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &6Correct syntax: &d/ss run [name]&6.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
|
||||
SudoSign sign = SudoSigns.signs.get(name);
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Executing &e" + sign.getMessages().size() + "&6 message(s) and &e" + (sign.getPlayerCommands().size() + sign.getConsoleCommands().size()) + "&6 command(s)...");
|
||||
SudoSigns.signs.get(name).executeCommands(p);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &e%NAME% &cdoes not exist!", name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Runs a sign remotely.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void run(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
String name;
|
||||
if (args == null) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Please click the sign you'd like to run!", null);
|
||||
SudoSigns.users.get(p.getUniqueId()).setRun(true);
|
||||
return;
|
||||
}
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss run [name]" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
SudoSign sign = SudoSigns.signs.get(name);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Executing " + ChatColor.LIGHT_PURPLE + sign.getMessages().size() + ChatColor.GRAY + " message(s) and " + ChatColor.LIGHT_PURPLE + (sign.getPlayerCommands().size() + sign.getConsoleCommands().size()) + ChatColor.GRAY + " command(s)...", null);
|
||||
SudoSigns.signs.get(name).executeCommands(p);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% doesn't exist!", name);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,28 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Select {
|
||||
|
||||
/**
|
||||
* Select a sign (display selection message in chat).
|
||||
* @param p The player running the command.
|
||||
* @param args 1 argument: The name of the sign.
|
||||
*/
|
||||
public static void select(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.SELECT)) {
|
||||
|
||||
if (args == null || args.length != 1) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! " + "&6Correct syntax: &d/ss select <name> &6.");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sendSelectMenus(p, args[0]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Select a sign (display selection message in chat).
|
||||
* @param p The player running the command.
|
||||
* @param args 1 argument: The name of the sign.
|
||||
*/
|
||||
public static void select(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.SELECT)) {
|
||||
if (args == null || args.length != 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss select <name>" + ChatColor.GRAY + ".", null);
|
||||
} else {
|
||||
String message = Util.getSelectString(p, args[0]);
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +1,127 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class SudoSignsTabCompleter implements TabCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] args) {
|
||||
if (commandSender instanceof Player) {
|
||||
Player p = (Player) commandSender;
|
||||
if (args.length == 1) {
|
||||
ArrayList<String> commands = new ArrayList<>();
|
||||
if (p.hasPermission(Permissions.HELP)) {
|
||||
commands.add("help");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
commands.add("reload");
|
||||
}
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
commands.add("create");
|
||||
}
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
commands.add("list");
|
||||
}
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
commands.add("near");
|
||||
}
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
commands.add("delete");
|
||||
}
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
commands.add("view");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
commands.add("run");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
commands.add("reload");
|
||||
}
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
commands.add("tp");
|
||||
}
|
||||
if (p.hasPermission(Permissions.COPY)) {
|
||||
commands.add("copy");
|
||||
}
|
||||
if (p.hasPermission(Permissions.SELECT)) {
|
||||
commands.add("select");
|
||||
}
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
commands.add("purge");
|
||||
}
|
||||
if (p.hasPermission(Permissions.FIX)) {
|
||||
commands.add("fix");
|
||||
}
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
commands.add("edit");
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
switch (args[0]) {
|
||||
case "create":
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
suggestions.add("<sign-name>");
|
||||
}
|
||||
return suggestions;
|
||||
case "delete":
|
||||
case "view":
|
||||
case "run":
|
||||
case "tp":
|
||||
case "copy":
|
||||
case "select":
|
||||
case "edit":
|
||||
if (p.hasPermission(Permissions.SELECT) || p.hasPermission(Permissions.VIEW)
|
||||
|| p.hasPermission(Permissions.RUN) || p.hasPermission(Permissions.TP)
|
||||
|| p.hasPermission(Permissions.COPY) || p.hasPermission(Permissions.SELECT)
|
||||
|| p.hasPermission(Permissions.EDIT)) {
|
||||
for (SudoSign s : SudoSigns.signs.values()) {
|
||||
suggestions.add(s.getName());
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
case "fix":
|
||||
case "purge":
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
suggestions.addAll(SudoSigns.invalidSigns);
|
||||
}
|
||||
return suggestions;
|
||||
case "near":
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
suggestions.add("2");
|
||||
suggestions.add("5");
|
||||
suggestions.add("10");
|
||||
suggestions.add("25");
|
||||
suggestions.add("50");
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String label, String[] args) {
|
||||
if (commandSender instanceof Player) {
|
||||
Player p = (Player) commandSender;
|
||||
if (args.length == 1) {
|
||||
ArrayList<String> commands = new ArrayList<>();
|
||||
if (p.hasPermission(Permissions.HELP)) {
|
||||
commands.add("help");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
commands.add("reload");
|
||||
}
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
commands.add("create");
|
||||
}
|
||||
if (p.hasPermission(Permissions.LIST)) {
|
||||
commands.add("list");
|
||||
}
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
commands.add("near");
|
||||
}
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
commands.add("delete");
|
||||
}
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
commands.add("view");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
commands.add("run");
|
||||
}
|
||||
if (p.hasPermission(Permissions.RELOAD)) {
|
||||
commands.add("reload");
|
||||
}
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
commands.add("tp");
|
||||
}
|
||||
if (p.hasPermission(Permissions.COPY)) {
|
||||
commands.add("copy");
|
||||
}
|
||||
if (p.hasPermission(Permissions.SELECT)) {
|
||||
commands.add("select");
|
||||
}
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
commands.add("purge");
|
||||
}
|
||||
if (p.hasPermission(Permissions.FIX)) {
|
||||
commands.add("fix");
|
||||
}
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
commands.add("edit");
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
switch (args[0]) {
|
||||
case "create":
|
||||
if (p.hasPermission(Permissions.CREATE)) {
|
||||
suggestions.add("<sign-name>");
|
||||
}
|
||||
return suggestions;
|
||||
case "delete":
|
||||
case "view":
|
||||
case "run":
|
||||
case "tp":
|
||||
case "copy":
|
||||
case "select":
|
||||
case "edit":
|
||||
if (p.hasPermission(Permissions.SELECT) || p.hasPermission(Permissions.VIEW)
|
||||
|| p.hasPermission(Permissions.RUN) || p.hasPermission(Permissions.TP)
|
||||
|| p.hasPermission(Permissions.COPY) || p.hasPermission(Permissions.SELECT)
|
||||
|| p.hasPermission(Permissions.EDIT)) {
|
||||
for (SudoSign s : SudoSigns.signs.values()) {
|
||||
suggestions.add(s.getName());
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
case "fix":
|
||||
case "purge":
|
||||
if (p.hasPermission(Permissions.PURGE)) {
|
||||
suggestions.addAll(SudoSigns.invalidSigns);
|
||||
}
|
||||
return suggestions;
|
||||
case "near":
|
||||
if (p.hasPermission(Permissions.NEAR)) {
|
||||
suggestions.add("2");
|
||||
suggestions.add("5");
|
||||
suggestions.add("10");
|
||||
suggestions.add("25");
|
||||
suggestions.add("50");
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
}
|
||||
if (args.length == 3) {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
switch (args[0]) {
|
||||
case "copy":
|
||||
suggestions.add("<new-sign-name>");
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.length == 3) {
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
switch (args[0]) {
|
||||
case "copy":
|
||||
suggestions.add("<new-sign-name>");
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +1,36 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Teleport {
|
||||
|
||||
/**
|
||||
* Teleports a player to the sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 1 argument: The name of the sign.
|
||||
*/
|
||||
public static void tp(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
|
||||
if (args == null || args.length != 1) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &6Correct syntax: &d/ss tp <name>&6.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
String name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
|
||||
Location newLoc = SudoSigns.signs.get(name).getSign().getLocation();
|
||||
newLoc.setX(newLoc.getX() + 0.5);
|
||||
newLoc.setZ(newLoc.getZ() + 0.5);
|
||||
|
||||
p.teleport(newLoc);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &e%NAME% &cdoes not exist!", name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Teleports a player to the sign.
|
||||
* @param p The player running the command.
|
||||
* @param args 1 argument: The name of the sign.
|
||||
*/
|
||||
public static void tp(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
if (args == null || args.length != 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss tp <name>" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
String name = args[0];
|
||||
if (SudoSigns.signs.containsKey(name)) {
|
||||
Location newLoc = SudoSigns.signs.get(name).getSign().getLocation();
|
||||
newLoc.setX(newLoc.getX() + 0.5);
|
||||
newLoc.setZ(newLoc.getZ() + 0.5);
|
||||
p.teleport(newLoc);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% doesn't exist!", name);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +1,60 @@
|
||||
package dev.mylesmor.sudosigns.commands;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class View {
|
||||
|
||||
/**
|
||||
* Views a sign's details, including location and number of permissions and commands assigned to it.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void view(Player p, String[] args) {
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
|
||||
String name = null;
|
||||
if (args == null) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please click on the sign you would like to view.");
|
||||
SudoSigns.users.get(p.getUniqueId()).setView(true);
|
||||
return;
|
||||
|
||||
}
|
||||
if (args.length > 1) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Invalid syntax! &6Correct syntax: &d/ss view [name]&6.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
name = args[0];
|
||||
SudoSign sign = SudoSigns.signs.get(name);
|
||||
if (sign != null) {
|
||||
|
||||
Location signLoc = sign.getSign().getLocation();
|
||||
String locString = "x=" + signLoc.getX() + " y=" + signLoc.getY() + " z=" + signLoc.getZ() + " ";
|
||||
Util.sudoSignsMessage(p, "&6Displaying details for sign &e%NAME%&6:", name);
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
|
||||
// Send a teleport confirmation menu with a clickable button.
|
||||
Util.selectMenuParser(p, "&d&l[TP]", ("&6Location: &e" + "&a" + locString), p.getName(), ("/ss tp " + name), ("&dTeleport to: &e" + name));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Location: &e" + locString);
|
||||
|
||||
}
|
||||
|
||||
if (sign.getPrice() == 1.0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&bPrice: " + sign.getPrice() + SudoSigns.econ.currencyNameSingular());
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&bPrice: " + sign.getPrice() + SudoSigns.econ.currencyNamePlural());
|
||||
|
||||
}
|
||||
|
||||
Util.sudoSignsMessage(p, "&bPrice: " + sign.getMessages().size());
|
||||
Util.sudoSignsMessage(p, "&6Messages: &e" + sign.getMessages().size());
|
||||
Util.sudoSignsMessage(p, "&6Permissions: &e" + sign.getPermissions().size());
|
||||
Util.sudoSignsMessage(p, "&6Player Commands: &e" + sign.getPlayerCommands().size());
|
||||
Util.sudoSignsMessage(p, "&6Console Commands: &e" + sign.getConsoleCommands().size());
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &e%NAME% &cdoes not exist!", name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Views a sign's details, including location and number of permissions and commands assigned to it.
|
||||
* @param p The player running the command.
|
||||
* @param args 0 or 1 arguments: The name of the sign (or null for click selection).
|
||||
*/
|
||||
public static void view(Player p, String[] args) {
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
String name = null;
|
||||
if (args == null) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Please click the sign you'd like to view!", null);
|
||||
SudoSigns.users.get(p.getUniqueId()).setView(true);
|
||||
return;
|
||||
}
|
||||
if (args.length > 1) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Invalid syntax! " + ChatColor.GRAY + "Correct syntax: " + ChatColor.LIGHT_PURPLE + "/ss view [name]" + ChatColor.GRAY + ".", null);
|
||||
return;
|
||||
}
|
||||
name = args[0];
|
||||
SudoSign sign = SudoSigns.signs.get(name);
|
||||
if (sign != null) {
|
||||
Location signLoc = sign.getSign().getLocation();
|
||||
String locString = "x=" + signLoc.getX() + " y=" + signLoc.getY() + " z=" + signLoc.getZ();
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Displaying details for sign %NAME%:", name);
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
String locMessage = "[\"\",{\"text\":\"[SUDOSIGNS] \",\"color\":\"yellow\"},{\"text\":\"Location: \",\"color\":\"gray\"},{\"text\":\"" + locString + " \",\"color\":\"light_purple\"},{\"text\":\"[TP]\",\"bold\":true,\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss tp " + name + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Teleport to " + name + "\",\"color\":\"aqua\"}]}},{\"text\":\"\",\"bold\":true,\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss delete NAME\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Yes, delete the sign!\",\"color\":\"green\"}]}}]";
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(locMessage));
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY,"Location: " + ChatColor.LIGHT_PURPLE + locString, null);
|
||||
}
|
||||
if (sign.getPrice() == 1.0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Price: " + ChatColor.LIGHT_PURPLE + SudoSigns.econ.currencyNameSingular() + sign.getPrice(), null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Price: " + ChatColor.LIGHT_PURPLE + SudoSigns.econ.currencyNamePlural() + sign.getPrice(), null);
|
||||
}
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Price: " + ChatColor.LIGHT_PURPLE + sign.getMessages().size(), null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Messages: " + ChatColor.LIGHT_PURPLE + sign.getMessages().size(), null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Permissions: " + ChatColor.LIGHT_PURPLE + sign.getPermissions().size(), null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY,"Player Commands: " + ChatColor.LIGHT_PURPLE + sign.getPlayerCommands().size(), null);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY,"Console Commands: " + ChatColor.LIGHT_PURPLE + sign.getConsoleCommands().size(), null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign with name %NAME% doesn't exist!", name);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to do this!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +1,87 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
|
||||
public class CommandConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
CommandConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
CommandConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void addCommandToConfig(SudoSign s, SignCommand cmd, PlayerInput type) {
|
||||
if (signConfig.isConfigurationSection("signs." + s.getName())) {
|
||||
HashMap<String, Double> map;
|
||||
switch (type) {
|
||||
case PLAYER_COMMAND:
|
||||
List<Map<?, ?>> pCmds = signConfig.getMapList("signs." + s.getName() + ".player-commands");
|
||||
map = new HashMap<>();
|
||||
map.put(cmd.getCommand(), cmd.getDelay());
|
||||
pCmds.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", pCmds);
|
||||
break;
|
||||
case CONSOLE_COMMAND:
|
||||
List<Map<?, ?>> cCmds = signConfig.getMapList("signs." + s.getName() + ".console-commands");
|
||||
map = new HashMap<>();
|
||||
map.put(cmd.getCommand(), cmd.getDelay());
|
||||
cCmds.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", cCmds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
public void addCommandToConfig(SudoSign s, SignCommand cmd, PlayerInput type) {
|
||||
if (signConfig.isConfigurationSection("signs." + s.getName())) {
|
||||
HashMap<String, Double> map;
|
||||
switch (type) {
|
||||
case PLAYER_COMMAND:
|
||||
List<Map<?, ?>> pCmds = signConfig.getMapList("signs." + s.getName() + ".player-commands");
|
||||
map = new HashMap<>();
|
||||
map.put(cmd.getCommand(), cmd.getDelay());
|
||||
pCmds.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", pCmds);
|
||||
break;
|
||||
case CONSOLE_COMMAND:
|
||||
List<Map<?, ?>> cCmds = signConfig.getMapList("signs." + s.getName() + ".console-commands");
|
||||
map = new HashMap<>();
|
||||
map.put(cmd.getCommand(), cmd.getDelay());
|
||||
cCmds.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", cCmds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deletes a command from a sign in the config.
|
||||
* @param s The SudoSign object to edit.
|
||||
* @param s The .
|
||||
* @param s The SudoSign object to edit.
|
||||
*/
|
||||
public void deleteCommandFromConfig(SudoSign s, SignCommand cmd, PlayerInput type, double oldDelay) {
|
||||
if (type.equals(PlayerInput.PLAYER_COMMAND)) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".player-commands");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> cmds : map.entrySet()) {
|
||||
if (cmds.getKey().equals(cmd.getCommand()) && (Double) cmds.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", mapList);
|
||||
} else if (type.equals(PlayerInput.CONSOLE_COMMAND)) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".console-commands");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> cmds : map.entrySet()) {
|
||||
if (cmds.getKey().equals(cmd.getCommand()) && (Double) cmds.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", mapList);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
/**
|
||||
* Deletes a command from a sign in the config.
|
||||
* @param s The SudoSign object to edit.
|
||||
* @param s The .
|
||||
* @param s The SudoSign object to edit.
|
||||
*/
|
||||
public void deleteCommandFromConfig(SudoSign s, SignCommand cmd, PlayerInput type, double oldDelay) {
|
||||
if (type.equals(PlayerInput.PLAYER_COMMAND)) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".player-commands");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> cmds : map.entrySet()) {
|
||||
if (cmds.getKey().equals(cmd.getCommand()) && (Double) cmds.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".player-commands", mapList);
|
||||
} else if (type.equals(PlayerInput.CONSOLE_COMMAND)) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".console-commands");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> cmds : map.entrySet()) {
|
||||
if (cmds.getKey().equals(cmd.getCommand()) && (Double) cmds.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".console-commands", mapList);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,19 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The class for managing the plugins config.
|
||||
@@ -26,301 +22,188 @@ import net.kyori.adventure.text.TextComponent;
|
||||
*/
|
||||
public class ConfigManager {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private File signConfigFile;
|
||||
private InvalidEntriesManager invalidEntriesManager;
|
||||
private SignConfig signConfigManager;
|
||||
private MessageConfig messageConfig;
|
||||
private CommandConfig commandConfig;
|
||||
private PermissionConfig permissionConfig;
|
||||
|
||||
|
||||
public ConfigManager() {
|
||||
|
||||
loadCustomConfig();
|
||||
loadModules();
|
||||
|
||||
}
|
||||
|
||||
public void loadModules() {
|
||||
|
||||
invalidEntriesManager = new InvalidEntriesManager(this, signConfig);
|
||||
signConfigManager = new SignConfig(this);
|
||||
signConfigManager.loadSigns();
|
||||
messageConfig = new MessageConfig(this);
|
||||
commandConfig = new CommandConfig(this);
|
||||
permissionConfig = new PermissionConfig(this);
|
||||
|
||||
}
|
||||
|
||||
public InvalidEntriesManager getInvalidEntriesManager() {
|
||||
|
||||
return invalidEntriesManager;
|
||||
|
||||
}
|
||||
|
||||
public FileConfiguration getSignConfig() {
|
||||
|
||||
return signConfig;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> loadSigns() {
|
||||
|
||||
return signConfigManager.loadSigns();
|
||||
|
||||
}
|
||||
|
||||
public void saveSign(SudoSign s, boolean singular, Player p) {
|
||||
|
||||
signConfigManager.saveToFile(s, singular, p);
|
||||
|
||||
}
|
||||
|
||||
public void deleteSign(String name) {
|
||||
|
||||
signConfigManager.deleteSign(name);
|
||||
|
||||
}
|
||||
|
||||
public void editSignText(String name, int lineNumber, TextComponent message) {
|
||||
|
||||
signConfigManager.editText(name, lineNumber, message);
|
||||
|
||||
}
|
||||
|
||||
public void addMessage(SudoSign s, SignMessage sm) {
|
||||
|
||||
messageConfig.addMessageToConfig(s, sm);
|
||||
|
||||
}
|
||||
|
||||
public void deleteMessage(SudoSign s, SignMessage sm, double delay) {
|
||||
|
||||
messageConfig.deleteMessageFromConfig(s, sm, delay);
|
||||
|
||||
}
|
||||
|
||||
public void addCommand(SudoSign s, SignCommand sm, PlayerInput type) {
|
||||
|
||||
commandConfig.addCommandToConfig(s, sm, type);
|
||||
|
||||
}
|
||||
|
||||
public void deleteCommand(SudoSign s, SignCommand sm, PlayerInput type, double oldDelay) {
|
||||
|
||||
commandConfig.deleteCommandFromConfig(s, sm, type, oldDelay);
|
||||
|
||||
}
|
||||
|
||||
public void setPrice(String name, double price) {
|
||||
|
||||
signConfigManager.setPrice(name, price);
|
||||
|
||||
}
|
||||
|
||||
public void addPermission(SudoSign s, String permission) {
|
||||
|
||||
permissionConfig.addPermissionToConfig(s, permission);
|
||||
|
||||
}
|
||||
|
||||
public void deletePermission(SudoSign s, String permission) {
|
||||
|
||||
permissionConfig.deletePermissionFromConfig(s, permission);
|
||||
|
||||
}
|
||||
|
||||
public boolean loadCustomConfig() {
|
||||
|
||||
if (! SudoSigns.sudoSignsPlugin.getDataFolder().exists()) {
|
||||
|
||||
SudoSigns.sudoSignsPlugin.getDataFolder().mkdir();
|
||||
|
||||
}
|
||||
|
||||
signConfigFile = new File(SudoSigns.sudoSignsPlugin.getDataFolder(), "signs.yml");
|
||||
if (! signConfigFile.exists()) {
|
||||
|
||||
try {
|
||||
|
||||
signConfigFile.createNewFile();
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to create config!");
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
signConfig = YamlConfiguration.loadConfiguration(signConfigFile);
|
||||
|
||||
if (signConfigManager != null) {
|
||||
|
||||
signConfigManager.setSignConfig(signConfig);
|
||||
|
||||
}
|
||||
|
||||
if (! signConfig.isConfigurationSection("signs")) {
|
||||
|
||||
signConfig.createSection("signs");
|
||||
|
||||
save();
|
||||
|
||||
}
|
||||
|
||||
if (invalidEntriesManager != null) {
|
||||
|
||||
invalidEntriesManager.setConfig(signConfig);
|
||||
|
||||
}
|
||||
|
||||
if (! signConfig.contains("version")) {
|
||||
|
||||
signConfig.createSection("version");
|
||||
signConfig.set("version", "1.2.1");
|
||||
|
||||
save();
|
||||
fixConfig();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to initialise signs.yml!");
|
||||
e.printStackTrace();
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void fixConfig() {
|
||||
|
||||
Set<String> signSection = signConfig.getConfigurationSection("signs").getKeys(false);
|
||||
String name = null;
|
||||
for (String key : signSection) {
|
||||
|
||||
signConfig.set("signs." + key + ".op-commands", null);
|
||||
signConfig.set("signs." + key + ".price", 0.0);
|
||||
|
||||
name = key;
|
||||
|
||||
List<String> pCommands = signConfig.getStringList("signs." + key + ".player-commands");
|
||||
List<String> cCommands = signConfig.getStringList("signs." + key + ".console-commands");
|
||||
List<String> messages = signConfig.getStringList("signs." + key + ".messages");
|
||||
|
||||
if (pCommands.size() == 0 && cCommands.size() == 0 && messages.size() == 0) {
|
||||
|
||||
save();
|
||||
continue;
|
||||
|
||||
}
|
||||
if (pCommands.size() != 0) {
|
||||
|
||||
try {
|
||||
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : pCommands) {
|
||||
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
signConfig.set("signs." + name + ".player-commands", mapList);
|
||||
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
|
||||
ignored.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
signConfig.set("signs." + key + ".op-commands", null);
|
||||
|
||||
if (cCommands.size() != 0) {
|
||||
try {
|
||||
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : cCommands) {
|
||||
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
signConfig.set("signs." + name + ".console-commands", mapList);
|
||||
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
|
||||
ignored.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (messages.size() != 0) {
|
||||
|
||||
try {
|
||||
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : messages) {
|
||||
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
|
||||
}
|
||||
|
||||
signConfig.set("signs." + name + ".messages", mapList);
|
||||
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
|
||||
ignored.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
save();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
try {
|
||||
|
||||
signConfig.save(signConfigFile);
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to save to signs.yml!");
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private FileConfiguration signConfig;
|
||||
private File signConfigFile;
|
||||
private InvalidEntriesManager invalidEntriesManager;
|
||||
private SignConfig signConfigManager;
|
||||
private MessageConfig messageConfig;
|
||||
private CommandConfig commandConfig;
|
||||
private PermissionConfig permissionConfig;
|
||||
|
||||
|
||||
public ConfigManager() {
|
||||
loadCustomConfig();
|
||||
loadModules();
|
||||
}
|
||||
|
||||
public void loadModules() {
|
||||
invalidEntriesManager = new InvalidEntriesManager(this, signConfig);
|
||||
signConfigManager = new SignConfig(this);
|
||||
signConfigManager.loadSigns();
|
||||
messageConfig = new MessageConfig(this);
|
||||
commandConfig = new CommandConfig(this);
|
||||
permissionConfig = new PermissionConfig(this);
|
||||
}
|
||||
|
||||
public InvalidEntriesManager getInvalidEntriesManager() {
|
||||
return invalidEntriesManager;
|
||||
}
|
||||
|
||||
public FileConfiguration getSignConfig() { return signConfig; }
|
||||
|
||||
public ArrayList<String> loadSigns() {
|
||||
return signConfigManager.loadSigns();
|
||||
}
|
||||
|
||||
public void saveSign(SudoSign s, boolean singular, Player p) {
|
||||
signConfigManager.saveToFile(s, singular, p);
|
||||
}
|
||||
|
||||
public void deleteSign(String name) {
|
||||
signConfigManager.deleteSign(name);
|
||||
}
|
||||
|
||||
public void editSignText(String name, int lineNumber, String message) {
|
||||
signConfigManager.editText(name, lineNumber, message);
|
||||
}
|
||||
|
||||
public void addMessage(SudoSign s, SignMessage sm) {
|
||||
messageConfig.addMessageToConfig(s, sm);
|
||||
}
|
||||
|
||||
public void deleteMessage(SudoSign s, SignMessage sm, double delay) {
|
||||
messageConfig.deleteMessageFromConfig(s, sm, delay);
|
||||
}
|
||||
|
||||
public void addCommand(SudoSign s, SignCommand sm, PlayerInput type) {
|
||||
commandConfig.addCommandToConfig(s, sm, type);
|
||||
}
|
||||
|
||||
public void deleteCommand(SudoSign s, SignCommand sm, PlayerInput type, double oldDelay) {
|
||||
commandConfig.deleteCommandFromConfig(s, sm, type, oldDelay);
|
||||
}
|
||||
|
||||
public void setPrice(String name, double price) {
|
||||
signConfigManager.setPrice(name, price);
|
||||
}
|
||||
|
||||
public void addPermission(SudoSign s, String permission) {
|
||||
permissionConfig.addPermissionToConfig(s, permission);
|
||||
}
|
||||
|
||||
public void deletePermission(SudoSign s, String permission) {
|
||||
permissionConfig.deletePermissionFromConfig(s, permission);
|
||||
}
|
||||
|
||||
private void createCustomConfig() {
|
||||
if (!SudoSigns.sudoSignsPlugin.getDataFolder().exists()) {
|
||||
SudoSigns.sudoSignsPlugin.getDataFolder().mkdir();
|
||||
}
|
||||
signConfigFile = new File(SudoSigns.sudoSignsPlugin.getDataFolder(), "signs.yml");
|
||||
if (!signConfigFile.exists()) {
|
||||
try {
|
||||
signConfigFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to create config!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean loadCustomConfig() {
|
||||
createCustomConfig();
|
||||
try {
|
||||
signConfig = YamlConfiguration.loadConfiguration(signConfigFile);
|
||||
if (signConfigManager != null) {
|
||||
signConfigManager.setSignConfig(signConfig);
|
||||
}
|
||||
if (!signConfig.isConfigurationSection("signs")) {
|
||||
signConfig.createSection("signs");
|
||||
save();
|
||||
}
|
||||
if (invalidEntriesManager != null) {
|
||||
invalidEntriesManager.setConfig(signConfig);
|
||||
}
|
||||
if (!signConfig.contains("version")) {
|
||||
signConfig.createSection("version");
|
||||
signConfig.set("version", "1.1.0");
|
||||
save();
|
||||
fixConfig();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to initialise signs.yml!");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void fixConfig() {
|
||||
Set<String> signSection = signConfig.getConfigurationSection("signs").getKeys(false);
|
||||
String name = null;
|
||||
for (String key : signSection) {
|
||||
signConfig.set("signs." + key + ".op-commands", null);
|
||||
signConfig.set("signs." + key + ".price", 0.0);
|
||||
name = key;
|
||||
List<String> pCommands = signConfig.getStringList("signs." + key + ".player-commands");
|
||||
List<String> cCommands = signConfig.getStringList("signs." + key + ".console-commands");
|
||||
List<String> messages = signConfig.getStringList("signs." + key + ".messages");
|
||||
if (pCommands.size() == 0 && cCommands.size() == 0 && messages.size() == 0) {
|
||||
save();
|
||||
continue;
|
||||
}
|
||||
if (pCommands.size() != 0) {
|
||||
try {
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : pCommands) {
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
}
|
||||
signConfig.set("signs." + name + ".player-commands", mapList);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
signConfig.set("signs." + key + ".op-commands", null);
|
||||
if (cCommands.size() != 0) {
|
||||
try {
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : cCommands) {
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
}
|
||||
signConfig.set("signs." + name + ".console-commands", mapList);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
if (messages.size() != 0) {
|
||||
try {
|
||||
ArrayList<HashMap<String, Double>> mapList = new ArrayList<>();
|
||||
HashMap<String, Double> map = new HashMap<>();
|
||||
for (String cmd : messages) {
|
||||
map.put(cmd, 0.0);
|
||||
mapList.add(map);
|
||||
map = new HashMap<>();
|
||||
}
|
||||
signConfig.set("signs." + name + ".messages", mapList);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
signConfig.save(signConfigFile);
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to save to signs.yml!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,164 +1,158 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InvalidEntriesManager {
|
||||
/**
|
||||
* The class for managing invalid sign entries in the config.
|
||||
* @author MylesMor
|
||||
* @author https://mylesmor.dev
|
||||
*/
|
||||
/**
|
||||
* The class for managing invalid sign entries in the config.
|
||||
* @author MylesMor
|
||||
* @author https://mylesmor.dev
|
||||
*/
|
||||
|
||||
ArrayList<String> invalidEntries = new ArrayList<>();
|
||||
ConfigManager configManager;
|
||||
FileConfiguration config;
|
||||
ArrayList<String> invalidEntries = new ArrayList<>();
|
||||
ConfigManager configManager;
|
||||
FileConfiguration config;
|
||||
|
||||
InvalidEntriesManager(ConfigManager configManager, FileConfiguration config) {
|
||||
this.configManager = configManager;
|
||||
this.config = config;
|
||||
}
|
||||
InvalidEntriesManager(ConfigManager configManager, FileConfiguration config) {
|
||||
this.configManager = configManager;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void setConfig(FileConfiguration config) {
|
||||
this.config = config;
|
||||
}
|
||||
public void setConfig(FileConfiguration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to a fix an invalid entry by placing a sign in the correct position.
|
||||
* @param s The sign's name.
|
||||
* @return True if sign successfully fixed, otherwise False.
|
||||
*/
|
||||
private boolean fixEntry(String s) {
|
||||
try {
|
||||
ConfigurationSection locSec = config.getConfigurationSection("signs." + s + ".location");
|
||||
String world = locSec.getString("world");
|
||||
double x = locSec.getDouble("x");
|
||||
double y = locSec.getDouble("y");
|
||||
double z = locSec.getDouble("z");
|
||||
String matString = config.getString("signs." + s + ".blocktype");
|
||||
if (SudoSigns.version.contains("1.13")) {
|
||||
matString = "SIGN";
|
||||
}
|
||||
Material material = Material.valueOf(matString);
|
||||
BlockFace blockFace = BlockFace.valueOf(locSec.getString("rotation"));
|
||||
World w = Bukkit.getServer().getWorld(world);
|
||||
if (w != null) {
|
||||
Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
w.getBlockAt(loc).setType(material);
|
||||
Block b = w.getBlockAt(loc);
|
||||
if (b.getBlockData() instanceof org.bukkit.block.data.type.Sign) {
|
||||
org.bukkit.block.data.type.Sign facing = (org.bukkit.block.data.type.Sign) b.getBlockData();
|
||||
facing.setRotation(blockFace);
|
||||
b.setBlockData(facing);
|
||||
} else if (b.getBlockData() instanceof org.bukkit.block.data.type.WallSign){
|
||||
org.bukkit.block.data.type.WallSign facing = (org.bukkit.block.data.type.WallSign) b.getBlockData();
|
||||
facing.setFacing(blockFace);
|
||||
b.setBlockData(facing);
|
||||
}
|
||||
Sign newSign = (Sign) b.getState();
|
||||
List<String> lines = getSignText(s);
|
||||
int i = 0;
|
||||
for (String line : lines) {
|
||||
newSign.line(i, Util.legacySerializerAnyCase(line));
|
||||
i++;
|
||||
}
|
||||
newSign.update();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Attempts to a fix an invalid entry by placing a sign in the correct position.
|
||||
* @param s The sign's name.
|
||||
* @return True if sign successfully fixed, otherwise False.
|
||||
*/
|
||||
private boolean fixEntry(String s) {
|
||||
try {
|
||||
ConfigurationSection locSec = config.getConfigurationSection("signs." + s + ".location");
|
||||
String world = locSec.getString("world");
|
||||
double x = locSec.getDouble("x");
|
||||
double y = locSec.getDouble("y");
|
||||
double z = locSec.getDouble("z");
|
||||
String matString = config.getString("signs." + s + ".blocktype");
|
||||
if (SudoSigns.version.contains("1.13")) {
|
||||
matString = "SIGN";
|
||||
}
|
||||
Material material = Material.valueOf(matString);
|
||||
BlockFace blockFace = BlockFace.valueOf(locSec.getString("rotation"));
|
||||
World w = Bukkit.getServer().getWorld(world);
|
||||
if (w != null) {
|
||||
Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
w.getBlockAt(loc).setType(material);
|
||||
Block b = w.getBlockAt(loc);
|
||||
if (b.getBlockData() instanceof org.bukkit.block.data.type.Sign) {
|
||||
org.bukkit.block.data.type.Sign facing = (org.bukkit.block.data.type.Sign) b.getBlockData();
|
||||
facing.setRotation(blockFace);
|
||||
b.setBlockData(facing);
|
||||
} else if (b.getBlockData() instanceof org.bukkit.block.data.type.WallSign){
|
||||
org.bukkit.block.data.type.WallSign facing = (org.bukkit.block.data.type.WallSign) b.getBlockData();
|
||||
facing.setFacing(blockFace);
|
||||
b.setBlockData(facing);
|
||||
}
|
||||
Sign newSign = (Sign) b.getState();
|
||||
List<String> lines = getSignText(s);
|
||||
int i = 0;
|
||||
for (String line : lines) {
|
||||
newSign.setLine(i, ChatColor.translateAlternateColorCodes('&', line));
|
||||
i++;
|
||||
}
|
||||
newSign.update();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ArrayList<String> getInvalidEntries() {
|
||||
return invalidEntries;
|
||||
}
|
||||
public ArrayList<String> getInvalidEntries() {
|
||||
return invalidEntries;
|
||||
}
|
||||
|
||||
public void setInvalidEntries(ArrayList<String> invalid) {
|
||||
invalidEntries = invalid;
|
||||
}
|
||||
public void setInvalidEntries(ArrayList<String> invalid) {
|
||||
invalidEntries = invalid;
|
||||
}
|
||||
|
||||
public void addInvalidEntry(String entry) {
|
||||
invalidEntries.add(entry);
|
||||
}
|
||||
public void addInvalidEntry(String entry) {
|
||||
invalidEntries.add(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the invalid sign's text from the config.
|
||||
* @param name Name of the sign.
|
||||
* @return The sign's message or null if not found.
|
||||
*/
|
||||
public List<String> getSignText(String name) {
|
||||
List<String> signSec = config.getStringList("signs." + name + ".text");
|
||||
for (String item : signSec) {
|
||||
item = Util.legacySerializerAnyCase(item).content();
|
||||
}
|
||||
if (signSec.size() != 0) {
|
||||
return signSec;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Retrieves the invalid sign's text from the config.
|
||||
* @param name Name of the sign.
|
||||
* @return The sign's message or null if not found.
|
||||
*/
|
||||
public List<String> getSignText(String name) {
|
||||
List<String> signSec = config.getStringList("signs." + name + ".text");
|
||||
for (String item : signSec) {
|
||||
item = ChatColor.translateAlternateColorCodes('&', item);
|
||||
}
|
||||
if (signSec.size() != 0) {
|
||||
return signSec;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a sign's entry in the config.
|
||||
* @param name Name of the sign.
|
||||
* @param all True if all invalid entries should be purged, or False for just one.
|
||||
* @return The sign's message or null if not found.
|
||||
*/
|
||||
public boolean purgeInvalidEntry(String name, boolean all) {
|
||||
if (all) {
|
||||
for (String s : invalidEntries) {
|
||||
Bukkit.getLogger().warning(Boolean.toString(config.isConfigurationSection("signs." + s)));
|
||||
config.set("signs." + s, null);
|
||||
}
|
||||
configManager.loadSigns();
|
||||
configManager.save();
|
||||
return true;
|
||||
} else {
|
||||
for (String s : invalidEntries) {
|
||||
if (name.equalsIgnoreCase(s)) {
|
||||
Bukkit.getLogger().warning(Boolean.toString(config.isConfigurationSection("signs." + s)));
|
||||
config.set("signs." + name, null);
|
||||
configManager.loadSigns();
|
||||
configManager.save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Removes a sign's entry in the config.
|
||||
* @param name Name of the sign.
|
||||
* @param all True if all invalid entries should be purged, or False for just one.
|
||||
* @return The sign's message or null if not found.
|
||||
*/
|
||||
public boolean purgeInvalidEntry(String name, boolean all) {
|
||||
if (all) {
|
||||
for (String s : invalidEntries) {
|
||||
Bukkit.getLogger().warning(Boolean.toString(config.isConfigurationSection("signs." + s)));
|
||||
config.set("signs." + s, null);
|
||||
}
|
||||
configManager.loadSigns();
|
||||
configManager.save();
|
||||
return true;
|
||||
} else {
|
||||
for (String s : invalidEntries) {
|
||||
if (name.equalsIgnoreCase(s)) {
|
||||
Bukkit.getLogger().warning(Boolean.toString(config.isConfigurationSection("signs." + s)));
|
||||
config.set("signs." + name, null);
|
||||
configManager.loadSigns();
|
||||
configManager.save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean fixInvalidEntry(String name, boolean all) {
|
||||
if (all) {
|
||||
for (String s : invalidEntries) {
|
||||
fixEntry(s);
|
||||
}
|
||||
configManager.save();
|
||||
return true;
|
||||
} else {
|
||||
for (String s : invalidEntries) {
|
||||
if (name.equals(s)) {
|
||||
if (fixEntry(s)) {
|
||||
configManager.save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public boolean fixInvalidEntry(String name, boolean all) {
|
||||
if (all) {
|
||||
for (String s : invalidEntries) {
|
||||
fixEntry(s);
|
||||
}
|
||||
configManager.save();
|
||||
return true;
|
||||
} else {
|
||||
for (String s : invalidEntries) {
|
||||
if (name.equals(s)) {
|
||||
if (fixEntry(s)) {
|
||||
configManager.save();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +1,50 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
|
||||
public class MessageConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
MessageConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
MessageConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void addMessageToConfig(SudoSign s, SignMessage sm) {
|
||||
HashMap<String, Double> map;
|
||||
List<Map<?, ?>> messages = signConfig.getMapList("signs." + s.getName() + ".messages");
|
||||
map = new HashMap<>();
|
||||
map.put(sm.getMessage(), sm.getDelay());
|
||||
messages.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".messages", messages);
|
||||
configManager.save();
|
||||
}
|
||||
public void addMessageToConfig(SudoSign s, SignMessage sm) {
|
||||
HashMap<String, Double> map;
|
||||
List<Map<?, ?>> messages = signConfig.getMapList("signs." + s.getName() + ".messages");
|
||||
map = new HashMap<>();
|
||||
map.put(sm.getMessage(), sm.getDelay());
|
||||
messages.add(map);
|
||||
signConfig.set("signs." + s.getName() + ".messages", messages);
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
public void deleteMessageFromConfig(SudoSign s, SignMessage sm, double oldDelay) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".messages");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> messages : map.entrySet()) {
|
||||
String key = (String) messages.getKey();
|
||||
if (key.equals(sm.getMessage()) && (Double) messages.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".messages", mapList);
|
||||
configManager.save();
|
||||
}
|
||||
public void deleteMessageFromConfig(SudoSign s, SignMessage sm, double oldDelay) {
|
||||
List<Map<?, ?>> mapList = signConfig.getMapList("signs." + s.getName() + ".messages");
|
||||
Map<?, ?> found = null;
|
||||
for (Map<?, ?> map : mapList) {
|
||||
for (Map.Entry<?, ?> messages : map.entrySet()) {
|
||||
String key = (String) messages.getKey();
|
||||
if (key.equals(sm.getMessage()) && (Double) messages.getValue() == oldDelay) {
|
||||
found = map;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
mapList.remove(found);
|
||||
}
|
||||
signConfig.set("signs." + s.getName() + ".messages", mapList);
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
|
||||
public class PermissionConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
PermissionConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
PermissionConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void addPermissionToConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.add(perm);
|
||||
signConfig.set(path, perms);
|
||||
configManager.save();
|
||||
}
|
||||
public void addPermissionToConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.add(perm);
|
||||
signConfig.set(path, perms);
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
public void deletePermissionFromConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.remove(perm);
|
||||
signConfig.set(path, perms);
|
||||
configManager.save();
|
||||
}
|
||||
public void deletePermissionFromConfig(SudoSign s, String perm) {
|
||||
String path = "signs." + s.getName() + ".permissions";
|
||||
List<String> perms = signConfig.getStringList(path);
|
||||
perms.remove(perm);
|
||||
signConfig.set(path, perms);
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -1,316 +1,200 @@
|
||||
package dev.mylesmor.sudosigns.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.Rotatable;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class SignConfig {
|
||||
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
SignConfig(ConfigManager configManager) {
|
||||
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
|
||||
}
|
||||
|
||||
public void setSignConfig(FileConfiguration signConfig) {
|
||||
|
||||
this.signConfig = signConfig;
|
||||
|
||||
}
|
||||
|
||||
// Loads the signs from the config.
|
||||
public ArrayList<String> loadSigns() {
|
||||
|
||||
Map<String, SudoSign> tempSigns = new HashMap<>();
|
||||
Set<String> signSection = signConfig.getConfigurationSection("signs").getKeys(false);
|
||||
|
||||
String name;
|
||||
ArrayList<String> invalidSigns = new ArrayList<>();
|
||||
|
||||
for (String key : signSection) {
|
||||
|
||||
name = key;
|
||||
|
||||
try {
|
||||
ConfigurationSection locSec = signConfig.getConfigurationSection("signs." + key + ".location");
|
||||
|
||||
String world = locSec.getString("world");
|
||||
double x = locSec.getDouble("x");
|
||||
double y = locSec.getDouble("y");
|
||||
double z = locSec.getDouble("z");
|
||||
World w = Bukkit.getServer().getWorld(world);
|
||||
|
||||
if (w != null) {
|
||||
|
||||
Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
if (loc.getBlock().getState() instanceof Sign || loc.getBlock().getState() instanceof WallSign) {
|
||||
|
||||
Sign sign = (Sign) loc.getBlock().getState();
|
||||
|
||||
SudoSign ss = new SudoSign(key);
|
||||
ss.setSign(sign);
|
||||
|
||||
List<Map<?, ?>> pCommands = signConfig.getMapList("signs." + key + ".player-commands");
|
||||
List<Map<?, ?>> cCommands = signConfig.getMapList("signs." + key + ".console-commands");
|
||||
List<String> permissions = signConfig.getStringList("signs." + key + ".permissions");
|
||||
List<Map<?, ?>> messages = signConfig.getMapList("signs." + key + ".messages");
|
||||
|
||||
try {
|
||||
|
||||
ss.setPrice((Double) signConfig.get("signs." + key + ".price"));
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
Bukkit.getLogger().info("[SUDOSIGNS] Invalid price for sign " + name + "! Defaulting to 0...");
|
||||
|
||||
ss.setPrice(0.0);
|
||||
|
||||
}
|
||||
|
||||
int number = 0;
|
||||
for (Map<?, ?> sc : pCommands) {
|
||||
|
||||
for (Map.Entry<?, ?> cmd : sc.entrySet()) {
|
||||
|
||||
ss.addPlayerCommand(new SignCommand(number++, (String) cmd.getKey(), (Double) cmd.getValue(), PlayerInput.PLAYER_COMMAND));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (Map<?, ?> sc : cCommands) {
|
||||
|
||||
for (Map.Entry<?, ?> cmd : sc.entrySet()) {
|
||||
|
||||
ss.addConsoleCommand(new SignCommand(number++, (String) cmd.getKey(), (Double) cmd.getValue(), PlayerInput.CONSOLE_COMMAND));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (String perm : permissions) {
|
||||
|
||||
ss.addPermission(perm);
|
||||
|
||||
}
|
||||
|
||||
number = 0;
|
||||
for (Map<?, ?> sc : messages) {
|
||||
|
||||
for (Map.Entry<?, ?> message : sc.entrySet()) {
|
||||
|
||||
ss.addMessage(new SignMessage(number++, (String) message.getKey(), (Double) message.getValue(), PlayerInput.MESSAGE));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tempSigns.put(name, ss);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The block at the provided location is not a sign. Skipping...");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The world name for this sign is invalid. Skipping...");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
configManager.getInvalidEntriesManager().setInvalidEntries(invalidSigns);
|
||||
|
||||
SudoSigns.signs = tempSigns;
|
||||
SudoSigns.invalidSigns = invalidSigns;
|
||||
|
||||
return invalidSigns;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a sign from the config.
|
||||
* @param name The name of the sign.
|
||||
*/
|
||||
public void deleteSign(String name) {
|
||||
|
||||
if (signConfig.isSet("signs." + name)) {
|
||||
|
||||
signConfig.set("signs." + name, null);
|
||||
|
||||
}
|
||||
|
||||
configManager.save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the SudoSigns to config.
|
||||
* @param s The SudoSign object.
|
||||
* @param singular True to save a singular sign, False to save all.
|
||||
* @param p The player who has edited the sign.
|
||||
*/
|
||||
public void saveToFile(SudoSign s, boolean singular, Player p) {
|
||||
|
||||
if (singular) {
|
||||
|
||||
saveSign(s, p);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
|
||||
saveSign(entry.getValue(), p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
configManager.save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a SudoSign in the config.
|
||||
* @param s The SudoSign object.
|
||||
* @param p The player who has edited the sign.
|
||||
*/
|
||||
public void saveSign(SudoSign s, Player p) {
|
||||
|
||||
String name = s.getName();
|
||||
try {
|
||||
|
||||
if (! signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
|
||||
signConfig.createSection("signs." + name + "");
|
||||
signConfig.createSection("signs." + name + ".text");
|
||||
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
|
||||
lines.addAll(s.getText());
|
||||
|
||||
signConfig.set("signs." + name + ".text", lines);
|
||||
signConfig.set("signs." + name + ".price", 0.0);
|
||||
|
||||
ConfigurationSection locSec = signConfig.createSection("signs." + name + ".location");
|
||||
|
||||
String world = s.getSign().getWorld().getName();
|
||||
double x = s.getSign().getLocation().getX();
|
||||
double y = s.getSign().getLocation().getY();
|
||||
double z = s.getSign().getLocation().getZ();
|
||||
|
||||
signConfig.set("signs." + name + ".blocktype", s.getSign().getType().toString());
|
||||
|
||||
locSec.set("world", world);
|
||||
locSec.set("x", x);
|
||||
locSec.set("y", y);
|
||||
locSec.set("z", z);
|
||||
|
||||
if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof Sign) {
|
||||
|
||||
Sign facing = (Sign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
|
||||
Rotatable data = (Rotatable) facing.getBlockData();
|
||||
BlockFace rotation = data.getRotation();
|
||||
|
||||
locSec.set("rotation", rotation);
|
||||
|
||||
}
|
||||
else if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof WallSign) {
|
||||
|
||||
WallSign facing = (WallSign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
|
||||
locSec.set("rotation", facing.getFacing().toString());
|
||||
|
||||
}
|
||||
|
||||
signConfig.createSection("signs." + name + ".permissions");
|
||||
signConfig.createSection("signs." + name + ".messages");
|
||||
signConfig.createSection("signs." + name + ".player-commands");
|
||||
signConfig.createSection("signs." + name + ".console-commands");
|
||||
|
||||
configManager.save();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
if (p != null) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: Failed to save sign %NAME% to the config!", name);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void editText(String name, int lineNumber, TextComponent newText) {
|
||||
|
||||
if (signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
|
||||
List<String> text = signConfig.getStringList("signs." + name + ".text");
|
||||
text.set(lineNumber - 1, newText.content());
|
||||
|
||||
signConfig.set("signs." + name + ".text", text);
|
||||
|
||||
}
|
||||
|
||||
configManager.save();
|
||||
|
||||
}
|
||||
|
||||
public void setPrice(String name, double price) {
|
||||
|
||||
if (signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
|
||||
signConfig.set("signs." + name + ".price", price);
|
||||
|
||||
}
|
||||
|
||||
configManager.save();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private FileConfiguration signConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
SignConfig(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
this.signConfig = configManager.getSignConfig();
|
||||
}
|
||||
|
||||
public void setSignConfig(FileConfiguration signConfig) {
|
||||
this.signConfig = signConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the signs from the config.
|
||||
* @return True if successful, false if not
|
||||
*/
|
||||
public ArrayList<String> loadSigns() {
|
||||
Map<String, SudoSign> tempSigns = new HashMap<>();
|
||||
Set<String> signSection = signConfig.getConfigurationSection("signs").getKeys(false);
|
||||
String name;
|
||||
ArrayList<String> invalidSigns = new ArrayList<>();
|
||||
for (String key : signSection) {
|
||||
name = key;
|
||||
try {
|
||||
ConfigurationSection locSec = signConfig.getConfigurationSection("signs." + key + ".location");
|
||||
String world = locSec.getString("world");
|
||||
double x = locSec.getDouble("x");
|
||||
double y = locSec.getDouble("y");
|
||||
double z = locSec.getDouble("z");
|
||||
World w = Bukkit.getServer().getWorld(world);
|
||||
if (w != null) {
|
||||
Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
|
||||
if (loc.getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) loc.getBlock().getState();
|
||||
SudoSign ss = new SudoSign(key);
|
||||
ss.setSign(sign);
|
||||
List<Map<?, ?>> pCommands = signConfig.getMapList("signs." + key + ".player-commands");
|
||||
List<Map<?, ?>> cCommands = signConfig.getMapList("signs." + key + ".console-commands");
|
||||
List<String> permissions = signConfig.getStringList("signs." + key + ".permissions");
|
||||
List<Map<?, ?>> messages = signConfig.getMapList("signs." + key + ".messages");
|
||||
try {
|
||||
ss.setPrice((Double) signConfig.get("signs." + key + ".price"));
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().info("Invalid price for sign " + name + "! Default to 0.");
|
||||
ss.setPrice(0.0);
|
||||
}
|
||||
int number = 0;
|
||||
for (Map<?, ?> sc : pCommands) {
|
||||
for (Map.Entry<?, ?> cmd : sc.entrySet()) {
|
||||
ss.addPlayerCommand(new SignCommand(number++, (String) cmd.getKey(), (Double) cmd.getValue(), PlayerInput.PLAYER_COMMAND));
|
||||
}
|
||||
}
|
||||
for (Map<?, ?> sc : cCommands) {
|
||||
for (Map.Entry<?, ?> cmd : sc.entrySet()) {
|
||||
ss.addConsoleCommand(new SignCommand(number++, (String) cmd.getKey(), (Double) cmd.getValue(), PlayerInput.CONSOLE_COMMAND));
|
||||
}
|
||||
}
|
||||
for (String perm : permissions) {
|
||||
ss.addPermission(perm);
|
||||
}
|
||||
number = 0;
|
||||
for (Map<?, ?> sc : messages) {
|
||||
for (Map.Entry<?, ?> message : sc.entrySet()) {
|
||||
ss.addMessage(new SignMessage(number++, (String) message.getKey(), (Double) message.getValue(), PlayerInput.MESSAGE));
|
||||
}
|
||||
}
|
||||
tempSigns.put(name, ss);
|
||||
} else {
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The block at the provided location is not a sign. Skipping...");
|
||||
}
|
||||
} else {
|
||||
invalidSigns.add(key);
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to load Sign " + key + "! The world name for this sign is invalid. Skipping...");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
configManager.getInvalidEntriesManager().setInvalidEntries(invalidSigns);
|
||||
SudoSigns.signs = tempSigns;
|
||||
SudoSigns.invalidSigns = invalidSigns;
|
||||
return invalidSigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a sign from the config.
|
||||
* @param name The name of the sign.
|
||||
*/
|
||||
public void deleteSign(String name) {
|
||||
if (signConfig.isSet("signs." + name)) {
|
||||
signConfig.set("signs." + name, null);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the SudoSigns to config.
|
||||
* @param s The SudoSign object.
|
||||
* @param singular True to save a singular sign, False to save all.
|
||||
* @param p The player who has edited the sign.
|
||||
*/
|
||||
public void saveToFile(SudoSign s, boolean singular, Player p) {
|
||||
if (singular) {
|
||||
saveSign(s, p);
|
||||
} else {
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
saveSign(entry.getValue(), p);
|
||||
}
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a SudoSign in the config.
|
||||
* @param s The SudoSign object.
|
||||
* @param p The player who has edited the sign.
|
||||
*/
|
||||
public void saveSign(SudoSign s, Player p) {
|
||||
String name = s.getName();
|
||||
try {
|
||||
if (!signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
signConfig.createSection("signs." + name + "");
|
||||
signConfig.createSection("signs." + name + ".text");
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
lines.addAll(s.getText());
|
||||
signConfig.set("signs." + name + ".text", lines);
|
||||
signConfig.set("signs." + name + ".price", 0.0);
|
||||
ConfigurationSection locSec = signConfig.createSection("signs." + name + ".location");
|
||||
String world = s.getSign().getWorld().getName();
|
||||
double x = s.getSign().getLocation().getX();
|
||||
double y = s.getSign().getLocation().getY();
|
||||
double z = s.getSign().getLocation().getZ();
|
||||
signConfig.set("signs." + name + ".blocktype", s.getSign().getType().toString());
|
||||
locSec.set("world", world);
|
||||
locSec.set("x", x);
|
||||
locSec.set("y", y);
|
||||
locSec.set("z", z);
|
||||
if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof org.bukkit.block.data.type.Sign) {
|
||||
org.bukkit.block.data.type.Sign facing = (org.bukkit.block.data.type.Sign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
locSec.set("rotation", facing.getRotation().toString());
|
||||
} else if (s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData() instanceof org.bukkit.block.data.type.WallSign) {
|
||||
org.bukkit.block.data.type.WallSign facing = (org.bukkit.block.data.type.WallSign) s.getSign().getWorld().getBlockAt(s.getSign().getLocation()).getBlockData();
|
||||
locSec.set("rotation", facing.getFacing().toString());
|
||||
}
|
||||
signConfig.createSection("signs." + name + ".permissions");
|
||||
signConfig.createSection("signs." + name + ".messages");
|
||||
signConfig.createSection("signs." + name + ".player-commands");
|
||||
signConfig.createSection("signs." + name + ".console-commands");
|
||||
configManager.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (p != null) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Failed to save sign %NAME% to the config!", name);
|
||||
}
|
||||
Bukkit.getLogger().warning("[SUDOSIGNS] Failed to save " + name + " to signs.yml!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void editText(String name, int lineNumber, String newText) {
|
||||
if (signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
List<String> text = signConfig.getStringList("signs." + name + ".text");
|
||||
Bukkit.getLogger().info(Integer.toString(text.size()));
|
||||
text.set(lineNumber-1, newText);
|
||||
signConfig.set("signs." + name + ".text", text);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
|
||||
public void setPrice(String name, double price) {
|
||||
if (signConfig.isConfigurationSection("signs." + name + "")) {
|
||||
signConfig.set("signs." + name + ".price", price);
|
||||
}
|
||||
configManager.save();
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,14 @@ package dev.mylesmor.sudosigns.data;
|
||||
* @author https://mylesmor.dev
|
||||
*/
|
||||
public enum PlayerInput {
|
||||
PLAYER_COMMAND,
|
||||
CONSOLE_COMMAND,
|
||||
RENAME,
|
||||
PERMISSION,
|
||||
MESSAGE,
|
||||
COMMAND_DELAY,
|
||||
MESSAGE_DELAY,
|
||||
EDIT_TEXT_NUMBER,
|
||||
EDIT_TEXT,
|
||||
SET_PRICE,
|
||||
}
|
||||
PLAYER_COMMAND,
|
||||
CONSOLE_COMMAND,
|
||||
RENAME,
|
||||
PERMISSION,
|
||||
MESSAGE,
|
||||
COMMAND_DELAY,
|
||||
MESSAGE_DELAY,
|
||||
EDIT_TEXT_NUMBER,
|
||||
EDIT_TEXT,
|
||||
SET_PRICE,
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.mylesmor.sudosigns.data;
|
||||
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
|
||||
/**
|
||||
* The SignCommand class for storing sign command data.
|
||||
* @author MylesMor
|
||||
@@ -7,34 +9,34 @@ package dev.mylesmor.sudosigns.data;
|
||||
*/
|
||||
public class SignCommand {
|
||||
|
||||
private String command;
|
||||
private PlayerInput type;
|
||||
private int number;
|
||||
private double delay;
|
||||
private String command;
|
||||
private PlayerInput type;
|
||||
private int number;
|
||||
private double delay;
|
||||
|
||||
public SignCommand(int number, String cmd, double delay, PlayerInput type) {
|
||||
this.number = number;
|
||||
command = cmd;
|
||||
this.type = type;
|
||||
this.delay = delay;
|
||||
}
|
||||
public SignCommand(int number, String cmd, double delay, PlayerInput type) {
|
||||
this.number = number;
|
||||
command = cmd;
|
||||
this.type = type;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public PlayerInput getType() {
|
||||
return type;
|
||||
}
|
||||
public PlayerInput getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getNumber() { return number; }
|
||||
public int getNumber() { return number; }
|
||||
|
||||
public double getDelay() {
|
||||
return delay;
|
||||
}
|
||||
public double getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
public void setDelay(double delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,33 +2,33 @@ package dev.mylesmor.sudosigns.data;
|
||||
|
||||
public class SignMessage {
|
||||
|
||||
private String message;
|
||||
private PlayerInput type;
|
||||
private int number;
|
||||
private double delay;
|
||||
private String message;
|
||||
private PlayerInput type;
|
||||
private int number;
|
||||
private double delay;
|
||||
|
||||
public SignMessage(int number, String message, double delay, PlayerInput type) {
|
||||
this.number = number;
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
this.delay = delay;
|
||||
}
|
||||
public SignMessage(int number, String message, double delay, PlayerInput type) {
|
||||
this.number = number;
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public PlayerInput getType() {
|
||||
return type;
|
||||
}
|
||||
public PlayerInput getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getNumber() { return number; }
|
||||
public int getNumber() { return number; }
|
||||
|
||||
public double getDelay() {
|
||||
return delay;
|
||||
}
|
||||
public double getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
}
|
||||
public void setDelay(double delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
package dev.mylesmor.sudosigns.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The class assigned to each created sign.
|
||||
@@ -24,399 +23,263 @@ import net.milkbowl.vault.economy.EconomyResponse;
|
||||
*/
|
||||
public class SudoSign {
|
||||
|
||||
private ArrayList<SignCommand> playerCommands = new ArrayList<>();
|
||||
private ArrayList<SignCommand> consoleCommands = new ArrayList<>();
|
||||
private ArrayList<String> permissions = new ArrayList<>();
|
||||
private ArrayList<SignMessage> messages = new ArrayList<>();
|
||||
private ArrayList<String> text = new ArrayList<>();
|
||||
private double price = 0;
|
||||
private String worldName;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private String name;
|
||||
|
||||
public SudoSign(String name) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
public void setSign(Sign sign) {
|
||||
|
||||
Location loc = sign.getLocation();
|
||||
|
||||
this.worldName = loc.getWorld().getName();
|
||||
this.x = loc.getX();
|
||||
this.y = loc.getY();
|
||||
this.z = loc.getZ();
|
||||
|
||||
}
|
||||
|
||||
public Sign getSign() {
|
||||
|
||||
if (worldName != null) {
|
||||
|
||||
Location loc = new Location(Bukkit.getWorld(worldName), x, y, z);
|
||||
|
||||
BlockState blockState = loc.getBlock().getState();
|
||||
if (blockState instanceof Sign || blockState instanceof WallSign) {
|
||||
|
||||
return (Sign) blockState;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Bukkit.getLogger().warning("Failed to locate sign " + name + "!");
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
}
|
||||
|
||||
public void addPlayerCommand(SignCommand sc) {
|
||||
|
||||
playerCommands.add(sc);
|
||||
|
||||
}
|
||||
|
||||
public List<String> getText() {
|
||||
|
||||
return text;
|
||||
|
||||
}
|
||||
|
||||
public void addLines() {
|
||||
|
||||
Sign sign = getSign();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
||||
String line = PlainTextComponentSerializer.plainText().serialize(sign.line(i));
|
||||
|
||||
text.add(line.replaceAll("§", "&"));
|
||||
sign.line(i, Util.legacySerializerAnyCase(line));
|
||||
|
||||
}
|
||||
|
||||
sign.update();
|
||||
|
||||
}
|
||||
|
||||
public void editLine(int lineNumber, TextComponent message) {
|
||||
|
||||
Sign sign = getSign();
|
||||
String line = PlainTextComponentSerializer.plainText().serialize(sign.line(lineNumber));
|
||||
|
||||
text.add(line.replaceAll("§", "&"));
|
||||
|
||||
sign.line(lineNumber, message);
|
||||
sign.update();
|
||||
|
||||
}
|
||||
|
||||
public void addConsoleCommand(SignCommand sc) {
|
||||
|
||||
consoleCommands.add(sc);
|
||||
|
||||
}
|
||||
|
||||
public void deleteConsoleCommand(SignCommand sc) {
|
||||
|
||||
consoleCommands.remove(sc);
|
||||
|
||||
}
|
||||
|
||||
public void deletePlayerCommand(SignCommand sc) {
|
||||
|
||||
playerCommands.remove(sc);
|
||||
|
||||
}
|
||||
|
||||
public void addPermission(String s) {
|
||||
|
||||
permissions.add(s);
|
||||
|
||||
}
|
||||
|
||||
public void removePermission(String s) {
|
||||
|
||||
permissions.remove(s);
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<String> getPermissions() {
|
||||
|
||||
return permissions;
|
||||
|
||||
}
|
||||
|
||||
public void addMessage(SignMessage s) {
|
||||
|
||||
messages.add(s);
|
||||
|
||||
}
|
||||
|
||||
public void removeMessage(SignMessage s) {
|
||||
|
||||
messages.remove(s);
|
||||
|
||||
}
|
||||
|
||||
public void copyFrom(SudoSign s) {
|
||||
|
||||
this.permissions = s.getPermissions();
|
||||
this.playerCommands = s.getPlayerCommands();
|
||||
this.consoleCommands = s.getConsoleCommands();
|
||||
this.messages = s.getMessages();
|
||||
this.price = s.getPrice();
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<SignMessage> getMessages() {
|
||||
|
||||
return messages;
|
||||
|
||||
}
|
||||
|
||||
public void setMessages(ArrayList<SignMessage> messages) {
|
||||
|
||||
this.messages = messages;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setPlayerCommands(ArrayList<SignCommand> playerCommands) {
|
||||
|
||||
this.playerCommands = playerCommands;
|
||||
|
||||
}
|
||||
|
||||
public void setConsoleCommands(ArrayList<SignCommand> consoleCommands) {
|
||||
|
||||
this.consoleCommands = consoleCommands;
|
||||
|
||||
}
|
||||
|
||||
public void setPermissions(ArrayList<String> permissions) {
|
||||
|
||||
this.permissions = permissions;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<SignCommand> getPlayerCommands() {
|
||||
|
||||
return playerCommands;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<SignCommand> getConsoleCommands() {
|
||||
|
||||
return consoleCommands;
|
||||
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
|
||||
this.price = price;
|
||||
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
|
||||
return price;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all of the commands attached to the sign, if the player has the required permissions.
|
||||
* @param p The player who is running the sign.
|
||||
*/
|
||||
public void executeCommands(Player p) {
|
||||
|
||||
boolean hasPermission = true;
|
||||
for (String perm : permissions) {
|
||||
|
||||
if (! p.hasPermission(perm)) {
|
||||
|
||||
hasPermission = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (hasPermission) {
|
||||
|
||||
if (SudoSigns.econ != null) {
|
||||
|
||||
EconomyResponse r = SudoSigns.econ.withdrawPlayer(p, price);
|
||||
if (! r.transactionSuccess()) {
|
||||
|
||||
if (price == 1.0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: You do not have a &b" + SudoSigns.econ.currencyNameSingular() + " &cto run this sign! &6The cost is: &b" + price + "&b" + SudoSigns.econ.currencyNameSingular() + "&6.");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: You do not have enough &b" + SudoSigns.econ.currencyNamePlural() + " &cto run this sign! &6The cost is: &b" + price + "&6.");
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
if (price == 1.0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&b" + price + "&b" + SudoSigns.econ.currencyNameSingular() + " &6has been withdrawn from your balance.");
|
||||
|
||||
}
|
||||
else if (price != 0.0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&b" + price + "&b" + SudoSigns.econ.currencyNamePlural() + " &6has been withdrawn from your balance.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
for (SignMessage sm : messages) {
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Util.sudoSignsMessage(p, (sm.getMessage().replaceAll("(?i)%PLAYER%", p.getName())));
|
||||
|
||||
}
|
||||
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sm.getDelay() / 50));
|
||||
|
||||
}
|
||||
for (SignCommand sc : playerCommands) {
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
p.performCommand(sc.getCommand());
|
||||
|
||||
}
|
||||
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sc.getDelay() / 50));
|
||||
|
||||
}
|
||||
for (SignCommand sc : consoleCommands) {
|
||||
|
||||
String cmd = sc.getCommand().replaceAll("(?i)%PLAYER%", p.getName());
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), cmd);
|
||||
|
||||
}
|
||||
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sc.getDelay() / 50));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsErrorMessage(p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getNextCommandNumber() {
|
||||
|
||||
int number = 0;
|
||||
for (SignCommand c: consoleCommands) {
|
||||
|
||||
number = Math.max(c.getNumber(), number);
|
||||
|
||||
}
|
||||
|
||||
for(SignCommand sc: playerCommands) {
|
||||
|
||||
number = Math.max(sc.getNumber(), number);
|
||||
|
||||
}
|
||||
|
||||
return number + 1;
|
||||
|
||||
}
|
||||
|
||||
public int getNextMessageNumber() {
|
||||
|
||||
int number = 0;
|
||||
for (SignMessage m : messages) {
|
||||
|
||||
number = Math.max(m.getNumber(), number);
|
||||
|
||||
}
|
||||
|
||||
return number + 1;
|
||||
|
||||
}
|
||||
|
||||
public SignMessage getSignMessageByNumber(int number) {
|
||||
|
||||
for (SignMessage sm: messages) {
|
||||
|
||||
if (sm.getNumber() == number) {
|
||||
|
||||
return sm;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public SignCommand getSignCommandByNumber(int number) {
|
||||
|
||||
for (SignCommand c: consoleCommands) {
|
||||
|
||||
if (c.getNumber() == number) {
|
||||
|
||||
return c;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(SignCommand sc: playerCommands) {
|
||||
|
||||
if (sc.getNumber() == number) {
|
||||
|
||||
return sc;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private ArrayList<SignCommand> playerCommands = new ArrayList<>();
|
||||
private ArrayList<SignCommand> consoleCommands = new ArrayList<>();
|
||||
private ArrayList<String> permissions = new ArrayList<>();
|
||||
private ArrayList<SignMessage> messages = new ArrayList<>();
|
||||
private ArrayList<String> text = new ArrayList<>();
|
||||
private double price = 0;
|
||||
private String worldName;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private String name;
|
||||
|
||||
public SudoSign(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setSign(Sign sign) {
|
||||
Location loc = sign.getLocation();
|
||||
this.worldName = loc.getWorld().getName();
|
||||
this.x = loc.getX();
|
||||
this.y = loc.getY();
|
||||
this.z = loc.getZ();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addPlayerCommand(SignCommand sc) {
|
||||
playerCommands.add(sc);
|
||||
}
|
||||
|
||||
public List<String> getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void addLines() {
|
||||
Sign sign = getSign();
|
||||
String[] lines = sign.getLines();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
String line = lines[i];
|
||||
text.add(line.replaceAll("§", "&"));
|
||||
line = ChatColor.translateAlternateColorCodes('&', line);
|
||||
sign.setLine(i, line);
|
||||
}
|
||||
sign.update();
|
||||
}
|
||||
|
||||
public void editLine(int lineNumber, String message) {
|
||||
Sign sign = getSign();
|
||||
String line = ChatColor.translateAlternateColorCodes('&', message);
|
||||
sign.setLine(lineNumber, line);
|
||||
sign.update();
|
||||
}
|
||||
|
||||
public void addConsoleCommand(SignCommand sc) {
|
||||
consoleCommands.add(sc);
|
||||
}
|
||||
|
||||
public void deleteConsoleCommand(SignCommand sc) {
|
||||
consoleCommands.remove(sc);
|
||||
}
|
||||
|
||||
public void deletePlayerCommand(SignCommand sc) {
|
||||
playerCommands.remove(sc);
|
||||
}
|
||||
|
||||
public void addPermission(String s) {
|
||||
permissions.add(s);
|
||||
}
|
||||
|
||||
public void removePermission(String s) {
|
||||
permissions.remove(s);
|
||||
}
|
||||
|
||||
public ArrayList<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void addMessage(SignMessage s) {
|
||||
messages.add(s);
|
||||
}
|
||||
|
||||
public void removeMessage(SignMessage s) {
|
||||
messages.remove(s);
|
||||
}
|
||||
|
||||
public void copyFrom(SudoSign s) {
|
||||
this.permissions = s.getPermissions();
|
||||
this.playerCommands = s.getPlayerCommands();
|
||||
this.consoleCommands = s.getConsoleCommands();
|
||||
this.messages = s.getMessages();
|
||||
this.price = s.getPrice();
|
||||
}
|
||||
|
||||
public ArrayList<SignMessage> getMessages() { return messages; }
|
||||
|
||||
public void setMessages(ArrayList<SignMessage> messages) { this.messages = messages; }
|
||||
|
||||
|
||||
public void setPlayerCommands(ArrayList<SignCommand> playerCommands) {
|
||||
this.playerCommands = playerCommands;
|
||||
}
|
||||
|
||||
public void setConsoleCommands(ArrayList<SignCommand> consoleCommands) {
|
||||
this.consoleCommands = consoleCommands;
|
||||
}
|
||||
|
||||
public void setPermissions(ArrayList<String> permissions) {
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public ArrayList<SignCommand> getPlayerCommands() {
|
||||
return playerCommands;
|
||||
}
|
||||
|
||||
public ArrayList<SignCommand> getConsoleCommands() {
|
||||
return consoleCommands;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes all of the commands attached to the sign, if the player has the required permissions.
|
||||
* @param p The player who is running the sign.
|
||||
*/
|
||||
public void executeCommands(Player p) {
|
||||
boolean hasPermission = true;
|
||||
for (String perm : permissions) {
|
||||
if (!p.hasPermission(perm)) {
|
||||
hasPermission = false;
|
||||
}
|
||||
}
|
||||
if (hasPermission) {
|
||||
if (SudoSigns.econ != null) {
|
||||
EconomyResponse r = SudoSigns.econ.withdrawPlayer(p, price);
|
||||
if (!r.transactionSuccess()) {
|
||||
if (price == 1.0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have enough money to run this sign! This sign costs " + ChatColor.GOLD + SudoSigns.econ.currencyNameSingular() + price + ChatColor.RED + ".", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have enough money to run this sign! This sign costs " + ChatColor.GOLD + SudoSigns.econ.currencyNamePlural() + price + ChatColor.RED + ".", null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (price == 1.0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, ChatColor.GOLD + SudoSigns.econ.currencyNameSingular() + price + ChatColor.GREEN + " has been withdrawn from your balance.", null);
|
||||
} else if (price != 0.0) {
|
||||
Util.sudoSignsMessage(p, ChatColor.GREEN, ChatColor.GOLD + SudoSigns.econ.currencyNamePlural() + price + ChatColor.GREEN + " has been withdrawn from your balance.", null);
|
||||
}
|
||||
}
|
||||
// Queue Sign messages
|
||||
for (SignMessage sm : messages) {
|
||||
String messageString = sm.getMessage().replaceAll("(?i)%PLAYER%", p.getName());
|
||||
if (SudoSigns.papi) {
|
||||
messageString = PlaceholderAPI.setPlaceholders(p, messageString);
|
||||
}
|
||||
String finalMessageString = messageString;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
p.sendMessage(ChatColor.translateAlternateColorCodes('&', finalMessageString));
|
||||
}
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sm.getDelay()/50));
|
||||
}
|
||||
// Queue Sign player commands
|
||||
for (SignCommand sc : playerCommands) {
|
||||
String commandString = sc.getCommand().replaceAll("(?i)%PLAYER%", p.getName());
|
||||
if (SudoSigns.papi) {
|
||||
commandString = PlaceholderAPI.setPlaceholders(p, commandString);
|
||||
}
|
||||
String finalCommandString = commandString;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
p.performCommand(finalCommandString);
|
||||
}
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sc.getDelay()/50));
|
||||
}
|
||||
// Queue Sign console commands
|
||||
for (SignCommand sc : consoleCommands) {
|
||||
String commandString = sc.getCommand().replaceAll("(?i)%PLAYER%", p.getName());
|
||||
if (SudoSigns.papi) {
|
||||
commandString = PlaceholderAPI.setPlaceholders(p, commandString);
|
||||
}
|
||||
String finalCommandString = commandString;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommandString);
|
||||
}
|
||||
}.runTaskLater(SudoSigns.sudoSignsPlugin, (long) (sc.getDelay()/50));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(ChatColor.RED + "You don't have permission to do this!");
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Sign getSign() {
|
||||
if (worldName != null) {
|
||||
Location loc = new Location(Bukkit.getWorld(worldName), x, y, z);
|
||||
if (loc.getBlock().getState() instanceof Sign) {
|
||||
return (Sign) loc.getBlock().getState();
|
||||
}
|
||||
}
|
||||
Bukkit.getLogger().warning("Failed to locate sign " + name + "!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getNextCommandNumber() {
|
||||
int number = 0;
|
||||
for (SignCommand c: consoleCommands) {
|
||||
number = Math.max(c.getNumber(), number);
|
||||
}
|
||||
for(SignCommand sc: playerCommands) {
|
||||
number = Math.max(sc.getNumber(), number);
|
||||
}
|
||||
return number+1;
|
||||
}
|
||||
|
||||
public int getNextMessageNumber() {
|
||||
int number = 0;
|
||||
for (SignMessage m : messages) {
|
||||
number = Math.max(m.getNumber(), number);
|
||||
}
|
||||
return number+1;
|
||||
}
|
||||
|
||||
public SignMessage getSignMessageByNumber(int number) {
|
||||
for (SignMessage sm: messages) {
|
||||
if (sm.getNumber() == number) {
|
||||
return sm;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SignCommand getSignCommandByNumber(int number) {
|
||||
for (SignCommand c: consoleCommands) {
|
||||
if (c.getNumber() == number) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
for(SignCommand sc: playerCommands) {
|
||||
if (sc.getNumber() == number) {
|
||||
return sc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package dev.mylesmor.sudosigns.data;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* SudoUser class to store all user variables.
|
||||
@@ -12,132 +11,124 @@ import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
public class SudoUser {
|
||||
|
||||
private Player p;
|
||||
private boolean edit = false;
|
||||
private boolean create = false;
|
||||
private boolean delete = false;
|
||||
private boolean selectToCopy = false;
|
||||
private boolean copy = false;
|
||||
private boolean run = false;
|
||||
private boolean view = false;
|
||||
private boolean textInput = false;
|
||||
private boolean editing = false;
|
||||
private SignEditor editor;
|
||||
private boolean edit = false;
|
||||
private boolean create = false;
|
||||
private boolean delete = false;
|
||||
private boolean selectToCopy = false;
|
||||
private boolean copy = false;
|
||||
private boolean run = false;
|
||||
private boolean view = false;
|
||||
private boolean textInput = false;
|
||||
private boolean editing = false;
|
||||
private SignEditor editor;
|
||||
|
||||
private PlayerInput inputType;
|
||||
private PlayerInput inputType;
|
||||
|
||||
public SudoUser(Player p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return p;
|
||||
}
|
||||
|
||||
public void setPlayer(Player p) {
|
||||
this.p = p;
|
||||
}
|
||||
public boolean isSelectToCopy() {
|
||||
return selectToCopy;
|
||||
}
|
||||
|
||||
public boolean isSelectToCopy() {
|
||||
return selectToCopy;
|
||||
}
|
||||
public void setSelectToCopy(boolean selectToCopy) {
|
||||
this.selectToCopy = selectToCopy;
|
||||
}
|
||||
|
||||
public void setSelectToCopy(boolean selectToCopy) {
|
||||
this.selectToCopy = selectToCopy;
|
||||
}
|
||||
public boolean isEdit() {
|
||||
return edit;
|
||||
}
|
||||
|
||||
public boolean isEdit() {
|
||||
return edit;
|
||||
}
|
||||
public SignEditor getEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
public SignEditor getEditor() {
|
||||
return editor;
|
||||
}
|
||||
public boolean isEditing() {
|
||||
return editing;
|
||||
}
|
||||
|
||||
public boolean isEditing() {
|
||||
return editing;
|
||||
}
|
||||
public void setEditor(SignEditor editor) {
|
||||
editing = true;
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
public void setEditor(SignEditor editor) {
|
||||
editing = true;
|
||||
this.editor = editor;
|
||||
}
|
||||
public void removeEditor() {
|
||||
editing = false;
|
||||
editor = null;
|
||||
}
|
||||
|
||||
public void removeEditor() {
|
||||
editing = false;
|
||||
editor = null;
|
||||
}
|
||||
public boolean isTextInput() {
|
||||
return textInput;
|
||||
}
|
||||
|
||||
public boolean isTextInput() {
|
||||
return textInput;
|
||||
}
|
||||
public PlayerInput getInputType() {
|
||||
return inputType;
|
||||
}
|
||||
|
||||
public PlayerInput getInputType() {
|
||||
return inputType;
|
||||
}
|
||||
public void addTextInput(PlayerInput type) {
|
||||
this.textInput = true;
|
||||
this.inputType = type;
|
||||
|
||||
public void addTextInput(PlayerInput type) {
|
||||
this.textInput = true;
|
||||
this.inputType = type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void removeTextInput() {
|
||||
this.textInput = false;
|
||||
this.inputType = null;
|
||||
}
|
||||
public void removeTextInput() {
|
||||
this.textInput = false;
|
||||
this.inputType = null;
|
||||
}
|
||||
|
||||
|
||||
private String passThru;
|
||||
private String passThru;
|
||||
|
||||
public String getPassThru() {
|
||||
return passThru;
|
||||
}
|
||||
public String getPassThru() {
|
||||
return passThru;
|
||||
}
|
||||
|
||||
public void setPassThru(String passThru) {
|
||||
this.passThru = passThru;
|
||||
}
|
||||
public void setPassThru(String passThru) {
|
||||
this.passThru = passThru;
|
||||
}
|
||||
|
||||
public boolean isView() {
|
||||
return view;
|
||||
}
|
||||
public boolean isView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public void setView(boolean view) {
|
||||
this.view = view;
|
||||
}
|
||||
public void setView(boolean view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public void setEdit(boolean edit) {
|
||||
this.edit = edit;
|
||||
}
|
||||
public void setEdit(boolean edit) {
|
||||
this.edit = edit;
|
||||
}
|
||||
|
||||
public boolean isCreate() {
|
||||
return create;
|
||||
}
|
||||
public boolean isCreate() {
|
||||
return create;
|
||||
}
|
||||
|
||||
public void setCreate(boolean create) {
|
||||
this.create = create;
|
||||
}
|
||||
public void setCreate(boolean create) {
|
||||
this.create = create;
|
||||
}
|
||||
|
||||
public boolean isDelete() {
|
||||
return delete;
|
||||
}
|
||||
public boolean isDelete() {
|
||||
return delete;
|
||||
}
|
||||
|
||||
public void setDelete(boolean delete) {
|
||||
this.delete = delete;
|
||||
}
|
||||
public void setDelete(boolean delete) {
|
||||
this.delete = delete;
|
||||
}
|
||||
|
||||
public boolean isCopy() {
|
||||
return copy;
|
||||
}
|
||||
public boolean isCopy() {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public void setCopy(boolean copy) {
|
||||
this.copy = copy;
|
||||
}
|
||||
public void setCopy(boolean copy) {
|
||||
this.copy = copy;
|
||||
}
|
||||
|
||||
public boolean isRun() {
|
||||
return run;
|
||||
}
|
||||
public boolean isRun() {
|
||||
return run;
|
||||
}
|
||||
|
||||
public void setRun(boolean run) {
|
||||
this.run = run;
|
||||
}
|
||||
}
|
||||
public void setRun(boolean run) {
|
||||
this.run = run;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
package dev.mylesmor.sudosigns.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
|
||||
/**
|
||||
@@ -23,290 +22,160 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
*/
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent e) {
|
||||
|
||||
Player p = e.getPlayer();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
|
||||
if (user.isTextInput() && user.isEditing()) {
|
||||
|
||||
if (user.getInputType() == PlayerInput.CONSOLE_COMMAND || user.getInputType() == PlayerInput.PLAYER_COMMAND) {
|
||||
|
||||
user.getEditor().getCommandsMenu().addCommand(e.getMessage().substring(1), user.getInputType());
|
||||
user.removeTextInput();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&eWARNING: &6Operation Cancelled!");
|
||||
user.removeTextInput();
|
||||
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncPlayerChat(AsyncChatEvent e) {
|
||||
|
||||
Player p = e.getPlayer();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
|
||||
if (user.isTextInput() && user.isEditing()) {
|
||||
|
||||
SignEditor editor = user.getEditor();
|
||||
|
||||
switch (user.getInputType()) {
|
||||
case PLAYER_COMMAND: case CONSOLE_COMMAND:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToCommands);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
user.removeTextInput();
|
||||
|
||||
handle(e, true, "No command found! Cancelling...", editor, user, null, editor::goToCommands);
|
||||
|
||||
break;
|
||||
case RENAME:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMain);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.renameSign(PlainTextComponentSerializer.plainText().serialize(e.message())), editor::goToMain);
|
||||
|
||||
break;
|
||||
case PERMISSION:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToPermissions);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.getPermMenu().addPermission(true, PlainTextComponentSerializer.plainText().serialize(e.message())), editor::goToPermissions);
|
||||
|
||||
break;
|
||||
case MESSAGE:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.getMessagesMenu().addMessage(PlainTextComponentSerializer.plainText().serialize(e.message())), editor::goToMessages);
|
||||
|
||||
break;
|
||||
case COMMAND_DELAY:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToCommands);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
double delay = 0;
|
||||
try {
|
||||
|
||||
delay = Double.parseDouble(PlainTextComponentSerializer.plainText().serialize(e.message()));
|
||||
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: Please enter a valid number.");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
double finalDelay = delay;
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.getCommandOptionsMenu().setDelay(finalDelay), editor::goToCommands);
|
||||
|
||||
break;
|
||||
case MESSAGE_DELAY:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
double messageDelay = 0;
|
||||
try {
|
||||
|
||||
messageDelay = Double.parseDouble(PlainTextComponentSerializer.plainText().serialize(e.message()));
|
||||
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: Please enter a valid number!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
double finalMessageDelay = messageDelay;
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.getMessageOptionsMenu().setDelay(finalMessageDelay), editor::goToMessages);
|
||||
|
||||
break;
|
||||
case EDIT_TEXT_NUMBER:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int lineNumber = 0;
|
||||
try {
|
||||
|
||||
lineNumber = Integer.parseInt(PlainTextComponentSerializer.plainText().serialize(e.message()));
|
||||
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: Please enter a valid number between 1-4!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
if (lineNumber < 1 || lineNumber > 4) {
|
||||
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: Please enter a valid number between 1-4!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
final int finalLineNumber = lineNumber;
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setLineNumber(finalLineNumber), null);
|
||||
|
||||
break;
|
||||
case EDIT_TEXT:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Regular expression contributed by lazerl0rd (MIT) at https://github.com/MylesMor/SudoSigns/pull/4
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).replaceAll("&([0-9]|[a-g]|[k-o]|r)", "").length() > 15) {
|
||||
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: The message can't be greater than 15 characters!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setText(Util.legacySerializerAnyCase(PlainTextComponentSerializer.plainText().serialize(e.message()))), editor::goToMain);
|
||||
|
||||
break;
|
||||
case SET_PRICE:
|
||||
if (PlainTextComponentSerializer.plainText().serialize(e.message()).equalsIgnoreCase("cancel")) {
|
||||
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
double price;
|
||||
try {
|
||||
|
||||
price = Double.parseDouble(PlainTextComponentSerializer.plainText().serialize(e.message()));
|
||||
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&eERROR: Please enter a valid number!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (price < 0) {
|
||||
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: Please enter &e0&c, or a positive number!");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
double finalPrice = price;
|
||||
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setPrice(finalPrice), editor::goToMain);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handle(AsyncChatEvent e, boolean cancel, String message, SignEditor editor, SudoUser user, Consumer<SignEditor> eventConsumer, Runnable finalAction) {
|
||||
|
||||
if (cancel) {
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
if (message != null) {
|
||||
|
||||
Util.sudoSignsMessage(e.getPlayer(), "&c" + message);
|
||||
|
||||
}
|
||||
|
||||
if (eventConsumer != null) {
|
||||
|
||||
Bukkit.getScheduler().runTask(SudoSigns.sudoSignsPlugin, () -> eventConsumer.accept(editor));
|
||||
|
||||
}
|
||||
|
||||
user.removeTextInput();
|
||||
|
||||
if (finalAction != null) {
|
||||
|
||||
Bukkit.getScheduler().runTask(SudoSigns.sudoSignsPlugin, finalAction);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
if (user.isTextInput() && user.isEditing()) {
|
||||
e.setCancelled(true);
|
||||
if (user.getInputType() == PlayerInput.CONSOLE_COMMAND || user.getInputType() == PlayerInput.PLAYER_COMMAND) {
|
||||
user.getEditor().getCommandsMenu().addCommand(e.getMessage().substring(1), user.getInputType());
|
||||
user.removeTextInput();
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Cancelled!", null);
|
||||
user.removeTextInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
if (user.isTextInput() && user.isEditing()) {
|
||||
SignEditor editor = user.getEditor();
|
||||
switch (user.getInputType()) {
|
||||
case PLAYER_COMMAND: case CONSOLE_COMMAND:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToCommands);
|
||||
return;
|
||||
}
|
||||
user.removeTextInput();
|
||||
handle(e, true, "No command found! Cancelling...", editor, user, null, editor::goToCommands);
|
||||
break;
|
||||
case RENAME:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMain);
|
||||
return;
|
||||
}
|
||||
handle(e, true, null, editor, user, edit -> editor.renameSign(ChatColor.stripColor(e.getMessage())), editor::goToMain);
|
||||
break;
|
||||
case PERMISSION:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToPermissions);
|
||||
return;
|
||||
}
|
||||
handle(e, true, null, editor, user, edit -> editor.getPermMenu().addPermission(true, ChatColor.stripColor(e.getMessage())), editor::goToPermissions);
|
||||
break;
|
||||
case MESSAGE:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
handle(e, true, null, editor, user, edit -> editor.getMessagesMenu().addMessage(ChatColor.stripColor(e.getMessage())), editor::goToMessages);
|
||||
break;
|
||||
case COMMAND_DELAY:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToCommands);
|
||||
return;
|
||||
}
|
||||
double delay = 0;
|
||||
try {
|
||||
delay = Double.parseDouble(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number!", "");
|
||||
return;
|
||||
}
|
||||
double finalDelay = delay;
|
||||
handle(e, true, null, editor, user, edit -> editor.getCommandOptionsMenu().setDelay(finalDelay), editor::goToCommands);
|
||||
break;
|
||||
case MESSAGE_DELAY:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
double messageDelay = 0;
|
||||
try {
|
||||
messageDelay = Double.parseDouble(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number!", "");
|
||||
return;
|
||||
}
|
||||
double finalMessageDelay = messageDelay;
|
||||
handle(e, true, null, editor, user, edit -> editor.getMessageOptionsMenu().setDelay(finalMessageDelay), editor::goToMessages);
|
||||
break;
|
||||
case EDIT_TEXT_NUMBER:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
int lineNumber = 0;
|
||||
try {
|
||||
lineNumber = Integer.parseInt(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number between 1-4!", "");
|
||||
return;
|
||||
}
|
||||
if (lineNumber < 1 || lineNumber > 4) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number between 1-4!", "");
|
||||
return;
|
||||
}
|
||||
final int finalLineNumber = lineNumber;
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setLineNumber(finalLineNumber), null);
|
||||
break;
|
||||
case EDIT_TEXT:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
if (e.getMessage().length() > 15) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "The message can't be greater than 15 characters!", "");
|
||||
return;
|
||||
}
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setText(e.getMessage()), editor::goToMain);
|
||||
break;
|
||||
case SET_PRICE:
|
||||
if (e.getMessage().equalsIgnoreCase("cancel")) {
|
||||
handle(e, true, "Cancelled!", editor, user, null, editor::goToMessages);
|
||||
return;
|
||||
}
|
||||
double price;
|
||||
try {
|
||||
price = Double.parseDouble(ChatColor.stripColor(e.getMessage()));
|
||||
} catch (NumberFormatException nfe) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter a valid number!", "");
|
||||
return;
|
||||
}
|
||||
if (price < 0) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Please enter 0 or a positive number!", "");
|
||||
return;
|
||||
}
|
||||
double finalPrice = price;
|
||||
handle(e, true, null, editor, user, edit -> editor.getMainMenu().setPrice(finalPrice), editor::goToMain);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(AsyncPlayerChatEvent e, boolean cancel, String message, SignEditor editor, SudoUser user, Consumer<SignEditor> eventConsumer, Runnable finalAction) {
|
||||
if (cancel) e.setCancelled(true);
|
||||
if (message != null) Util.sudoSignsMessage(e.getPlayer(), ChatColor.RED, message, null);
|
||||
if (eventConsumer != null) Bukkit.getScheduler().runTask(SudoSigns.sudoSignsPlugin, () -> eventConsumer.accept(editor));
|
||||
user.removeTextInput();
|
||||
if (finalAction != null) {
|
||||
Bukkit.getScheduler().runTask(SudoSigns.sudoSignsPlugin, finalAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package dev.mylesmor.sudosigns.listeners;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -11,13 +16,10 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,252 +29,244 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
*/
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
if (user.isEditing()) {
|
||||
if (Objects.equals(e.getClickedInventory(), e.getView().getTopInventory())) {
|
||||
SignEditor editor = user.getEditor();
|
||||
if (e.getCurrentItem() != null) {
|
||||
e.setCancelled(true);
|
||||
Material m = e.getCurrentItem().getType();
|
||||
String itemName = e.getCurrentItem().getDisplayName();
|
||||
switch (editor.getCurrentPage()) {
|
||||
case MAIN:
|
||||
checkForMainMenuClicks(editor, m);
|
||||
break;
|
||||
case COMMANDS:
|
||||
checkForCommandsClicks(p, editor, m, e.getCurrentItem());
|
||||
break;
|
||||
case PERMISSIONS:
|
||||
checkForPermissionsClicks(p, editor, m, itemName);
|
||||
break;
|
||||
case CHOOSE_COMMAND:
|
||||
chooseCommandType(editor, m, itemName);
|
||||
break;
|
||||
case CHOOSE_PERMISSION:
|
||||
choosePermissionType(editor, m);
|
||||
break;
|
||||
case MESSAGES:
|
||||
checkForMessagesClicks(p, editor, m, e.getCurrentItem());
|
||||
break;
|
||||
case COMMAND_OPTIONS:
|
||||
checkForCommandOptionClicks(p, editor, m, itemName);
|
||||
break;
|
||||
case MESSAGE_OPTIONS:
|
||||
checkForMessageOptionClicks(p, editor, m, itemName);
|
||||
break;
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
if (user.isEditing()) {
|
||||
if (Objects.equals(e.getClickedInventory(), e.getView().getTopInventory())) {
|
||||
SignEditor editor = user.getEditor();
|
||||
if (e.getCurrentItem() != null) {
|
||||
e.setCancelled(true);
|
||||
Material m = e.getCurrentItem().getType();
|
||||
String itemName = ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName());
|
||||
switch (editor.getCurrentPage()) {
|
||||
case MAIN:
|
||||
checkForMainMenuClicks(editor, m);
|
||||
break;
|
||||
case COMMANDS:
|
||||
checkForCommandsClicks(p, editor, m, e.getCurrentItem());
|
||||
break;
|
||||
case PERMISSIONS:
|
||||
checkForPermissionsClicks(p, editor, m, e.getCurrentItem());
|
||||
break;
|
||||
case CHOOSE_COMMAND:
|
||||
chooseCommandType(editor, m, itemName);
|
||||
break;
|
||||
case CHOOSE_PERMISSION:
|
||||
choosePermissionType(editor, m);
|
||||
break;
|
||||
case MESSAGES:
|
||||
checkForMessagesClicks(p, editor, m, e.getCurrentItem());
|
||||
break;
|
||||
case COMMAND_OPTIONS:
|
||||
checkForCommandOptionClicks(p, editor, m, itemName);
|
||||
break;
|
||||
case MESSAGE_OPTIONS:
|
||||
checkForMessageOptionClicks(p, editor, m, itemName);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void closeInventory(InventoryCloseEvent e) {
|
||||
Player p = (Player) e.getPlayer();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
// Checks whether the user has closed the GUI.
|
||||
if (user.isEditing()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SudoSigns.sudoSignsPlugin, () -> {
|
||||
InventoryView currentInv = p.getOpenInventory();
|
||||
if (PlainTextComponentSerializer.plainText().serialize(currentInv.title()).equalsIgnoreCase("CRAFTING") && ! user.isTextInput()) {
|
||||
user.getEditor().endEditor();
|
||||
user.removeEditor();
|
||||
}
|
||||
}, 5L);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void closeInventory(InventoryCloseEvent e) {
|
||||
Player p = (Player) e.getPlayer();
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
// Checks whether the user has closed the GUI.
|
||||
if (user.isEditing()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SudoSigns.sudoSignsPlugin, () -> {
|
||||
InventoryView currentInv = p.getOpenInventory();
|
||||
if (currentInv.getTitle().equalsIgnoreCase("CRAFTING") && !user.isTextInput()) {
|
||||
user.getEditor().endEditor();
|
||||
user.removeEditor();
|
||||
}
|
||||
}, 5L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the main menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
*/
|
||||
public void checkForMainMenuClicks(SignEditor editor, Material m) {
|
||||
if (m.equals(Material.OAK_SIGN)) {
|
||||
editor.goToMessages();
|
||||
return;
|
||||
}
|
||||
switch (m) {
|
||||
case NAME_TAG:
|
||||
editor.prepareRename();
|
||||
break;
|
||||
case WRITABLE_BOOK:
|
||||
editor.editSignNumber();
|
||||
break;
|
||||
case BARRIER:
|
||||
editor.goToPermissions();
|
||||
break;
|
||||
case COMMAND_BLOCK:
|
||||
editor.goToCommands();
|
||||
break;
|
||||
case BIRCH_SIGN:
|
||||
editor.goToMessages();
|
||||
break;
|
||||
case GOLD_NUGGET:
|
||||
editor.getMainMenu().prepareSetPrice();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks for GUI clicks in the main menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
*/
|
||||
public void checkForMainMenuClicks(SignEditor editor, Material m) {
|
||||
if (SudoSigns.version.contains("1.13")) {
|
||||
if (m.equals(Material.valueOf("SIGN"))) {
|
||||
editor.goToMessages();
|
||||
return;
|
||||
}
|
||||
}
|
||||
switch (m) {
|
||||
case NAME_TAG:
|
||||
editor.prepareRename();
|
||||
break;
|
||||
case WRITABLE_BOOK:
|
||||
editor.editSignNumber();
|
||||
break;
|
||||
case BARRIER:
|
||||
editor.goToPermissions();
|
||||
break;
|
||||
case COMMAND_BLOCK:
|
||||
editor.goToCommands();
|
||||
break;
|
||||
case BIRCH_SIGN:
|
||||
editor.goToMessages();
|
||||
break;
|
||||
case GOLD_NUGGET:
|
||||
editor.getMainMenu().prepareSetPrice();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Command Options menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param item The ItemStack of the clicked item.
|
||||
*/
|
||||
public void checkForCommandsClicks(Player p, SignEditor editor, Material m, ItemStack item) {
|
||||
switch (m) {
|
||||
case WRITABLE_BOOK:
|
||||
editor.getCommandsMenu().prepareCommand();
|
||||
break;
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
|
||||
editor.goToCommandOptionsMenu(item);
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks for GUI clicks in the Command Options menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param item The ItemStack of the clicked item.
|
||||
*/
|
||||
public void checkForCommandsClicks(Player p, SignEditor editor, Material m, ItemStack item) {
|
||||
switch (m) {
|
||||
case WRITABLE_BOOK:
|
||||
editor.getCommandsMenu().prepareCommand();
|
||||
break;
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
|
||||
editor.goToCommandOptionsMenu(item);
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Command Options menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param itemName The name of the item clicked.
|
||||
*/
|
||||
public void checkForCommandOptionClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case CLOCK:
|
||||
editor.getCommandOptionsMenu().addDelay();
|
||||
break;
|
||||
case BARRIER:
|
||||
if (p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
editor.getCommandOptionsMenu().deleteCommand();
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToCommands();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks for GUI clicks in the Command Options menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param itemName The name of the item clicked.
|
||||
*/
|
||||
public void checkForCommandOptionClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case CLOCK:
|
||||
editor.getCommandOptionsMenu().addDelay();
|
||||
break;
|
||||
case BARRIER:
|
||||
if (p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
editor.getCommandOptionsMenu().deleteCommand();
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToCommands();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Commands menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param itemName The name of the item clicked.
|
||||
*/
|
||||
public void checkForMessageOptionClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case CLOCK:
|
||||
editor.getMessageOptionsMenu().addDelay();
|
||||
break;
|
||||
case BARRIER:
|
||||
if (p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
editor.getMessageOptionsMenu().deleteMessage();
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMessages();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks for GUI clicks in the Commands menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param itemName The name of the item clicked.
|
||||
*/
|
||||
public void checkForMessageOptionClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case CLOCK:
|
||||
editor.getMessageOptionsMenu().addDelay();
|
||||
break;
|
||||
case BARRIER:
|
||||
if (p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
editor.getMessageOptionsMenu().deleteMessage();
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMessages();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Commands menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param item The ItemStack of the clicked item.
|
||||
*/
|
||||
public void checkForMessagesClicks(Player p, SignEditor editor, Material m, ItemStack item) {
|
||||
switch (m) {
|
||||
case WRITABLE_BOOK:
|
||||
editor.getMessagesMenu().prepareMessage();
|
||||
break;
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS)) {
|
||||
editor.goToMessageOptionsMenu(item);
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks for GUI clicks in the Commands menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param item The ItemStack of the clicked item.
|
||||
*/
|
||||
public void checkForMessagesClicks(Player p, SignEditor editor, Material m, ItemStack item) {
|
||||
switch (m) {
|
||||
case WRITABLE_BOOK:
|
||||
editor.getMessagesMenu().prepareMessage();
|
||||
break;
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS)) {
|
||||
editor.goToMessageOptionsMenu(item);
|
||||
}
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void choosePermissionType(SignEditor editor, Material m) {
|
||||
switch (m) {
|
||||
case PLAYER_HEAD:
|
||||
editor.getPermMenu().addPermission(true, null);
|
||||
break;
|
||||
case COMMAND_BLOCK:
|
||||
editor.getPermMenu().addPermission(false, null);
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToPermissions();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void choosePermissionType(SignEditor editor, Material m) {
|
||||
switch (m) {
|
||||
case PLAYER_HEAD:
|
||||
editor.getPermMenu().addPermission(true, null);
|
||||
break;
|
||||
case COMMAND_BLOCK:
|
||||
editor.getPermMenu().addPermission(false, null);
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToPermissions();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseCommandType(SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case PLAYER_HEAD:
|
||||
editor.getCommandsMenu().chooseCommandType(PlayerInput.PLAYER_COMMAND);
|
||||
break;
|
||||
case COMMAND_BLOCK:
|
||||
editor.getCommandsMenu().chooseCommandType(PlayerInput.CONSOLE_COMMAND);
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToCommands();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void chooseCommandType(SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case PLAYER_HEAD:
|
||||
editor.getCommandsMenu().chooseCommandType(PlayerInput.PLAYER_COMMAND);
|
||||
break;
|
||||
case COMMAND_BLOCK:
|
||||
editor.getCommandsMenu().chooseCommandType(PlayerInput.CONSOLE_COMMAND);
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToCommands();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Permissions menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param itemName The name of the item clicked.
|
||||
*/
|
||||
public void checkForPermissionsClicks(Player p, SignEditor editor, Material m, String itemName) {
|
||||
switch (m) {
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.DELETE_PERMISSION)) {
|
||||
editor.getPermMenu().deletePermission(itemName);
|
||||
}
|
||||
break;
|
||||
case WRITABLE_BOOK:
|
||||
editor.getPermMenu().preparePermission();
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks for GUI clicks in the Permissions menu.
|
||||
* @param editor The SignEditor class of the particular user.
|
||||
* @param m The material clicked on in the menu.
|
||||
* @param item The ItemStack of the item clicked.
|
||||
*/
|
||||
public void checkForPermissionsClicks(Player p, SignEditor editor, Material m, ItemStack item) {
|
||||
switch (m) {
|
||||
case BOOK:
|
||||
if (p.hasPermission(Permissions.DELETE_PERMISSION)) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "permission");
|
||||
if (itemMeta != null) {
|
||||
editor.getPermMenu().deletePermission(itemMeta.getPersistentDataContainer().get(key, PersistentDataType.STRING));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WRITABLE_BOOK:
|
||||
editor.getPermMenu().preparePermission();
|
||||
break;
|
||||
case ARROW:
|
||||
editor.goToMain();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
package dev.mylesmor.sudosigns.listeners;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
SudoSigns.users.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
SudoSigns.users.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package dev.mylesmor.sudosigns.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
@@ -12,322 +16,319 @@ import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.LeavesDecayEvent;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.menus.SignEditor;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class SignListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (e.getClickedBlock() != null) {
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
Block b = e.getClickedBlock();
|
||||
if (user.isCreate()) {
|
||||
e.setCancelled(true);
|
||||
create(p, user, b);
|
||||
} else if (user.isSelectToCopy()) {
|
||||
e.setCancelled(true);
|
||||
selectToCopy(p, user, b);
|
||||
} else if (user.isCopy()) {
|
||||
e.setCancelled(true);
|
||||
copy(p, user, b);
|
||||
} else if (user.isEdit()) {
|
||||
e.setCancelled(true);
|
||||
edit(p, user, b);
|
||||
} else if (user.isDelete()) {
|
||||
e.setCancelled(true);
|
||||
delete(p, user, b);
|
||||
} else if (user.isRun()) {
|
||||
e.setCancelled(true);
|
||||
runRemote(p, user, b);
|
||||
} else if (user.isView()) {
|
||||
e.setCancelled(true);
|
||||
view(p, user, b);
|
||||
} else {
|
||||
runSign(p, e);
|
||||
}
|
||||
} else {
|
||||
runSign(p, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (e.getClickedBlock() != null) {
|
||||
SudoUser user = SudoSigns.users.get(p.getUniqueId());
|
||||
if (user != null) {
|
||||
Block b = e.getClickedBlock();
|
||||
if (user.isCreate()) {
|
||||
e.setCancelled(true);
|
||||
create(p, user, b);
|
||||
} else if (user.isSelectToCopy()) {
|
||||
e.setCancelled(true);
|
||||
selectToCopy(p, user, b);
|
||||
} else if (user.isCopy()) {
|
||||
e.setCancelled(true);
|
||||
copy(p, user, b);
|
||||
} else if (user.isEdit()) {
|
||||
e.setCancelled(true);
|
||||
edit(p, user, b);
|
||||
} else if (user.isDelete()) {
|
||||
e.setCancelled(true);
|
||||
delete(p, user, b);
|
||||
} else if (user.isRun()) {
|
||||
e.setCancelled(true);
|
||||
runRemote(p, user, b);
|
||||
} else if (user.isView()) {
|
||||
e.setCancelled(true);
|
||||
view(p, user, b);
|
||||
} else {
|
||||
runSign(p, e);
|
||||
}
|
||||
} else {
|
||||
runSign(p, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void selectToCopy(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign || b.getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
user.setSelectToCopy(false);
|
||||
p.performCommand("ss copy " + name + " " + user.getPassThru());
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: Failed to copy: that is not a SudoSign!");
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign wasn't clicked! &6Cancelling...");
|
||||
}
|
||||
user.setSelectToCopy(false);
|
||||
}
|
||||
private void selectToCopy(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
user.setSelectToCopy(false);
|
||||
p.performCommand("ss copy " + name + " " + user.getPassThru());
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "Failed to copy: this is not a SudoSign!", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign wasn't clicked! Cancelling...", null);
|
||||
}
|
||||
user.setSelectToCopy(false);
|
||||
}
|
||||
|
||||
private void runSign(Player p, PlayerInteractEvent e) {
|
||||
if (Objects.requireNonNull(e.getClickedBlock()).getState() instanceof Sign || e.getClickedBlock().getState() instanceof WallSign) {
|
||||
if (p.hasPermission(Permissions.SELECT) && e.getAction() == Action.RIGHT_CLICK_BLOCK || ! p.hasPermission(Permissions.SELECT)) {
|
||||
Sign sign = (Sign) e.getClickedBlock().getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
SudoSigns.signs.get(name).executeCommands(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void runSign(Player p, PlayerInteractEvent e) {
|
||||
if (Objects.requireNonNull(e.getClickedBlock()).getState() instanceof Sign) {
|
||||
if (p.hasPermission(Permissions.SELECT) && e.getAction() == Action.RIGHT_CLICK_BLOCK || !p.hasPermission(Permissions.SELECT)) {
|
||||
Sign sign = (Sign) e.getClickedBlock().getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
SudoSigns.signs.get(name).executeCommands(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void create(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign || b.getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
user.setCreate(false);
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
Util.sudoSignsMessage(p, "&cERROR: That SudoSign already exists! &6Cancelling...");
|
||||
return;
|
||||
}
|
||||
SudoSigns.signs.get(user.getPassThru()).setSign(sign);
|
||||
SudoSigns.signs.get(user.getPassThru()).addLines();
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
SignEditor editor = new SignEditor(p, SudoSigns.signs.get(user.getPassThru()), user);
|
||||
user.setEditor(editor);
|
||||
}
|
||||
SudoSigns.config.saveSign(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
}
|
||||
else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign was not clicked! Cancelling...");
|
||||
user.setCreate(false);
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
}
|
||||
user.setCreate(false);
|
||||
}
|
||||
private void create(Player p, SudoUser user, Block b) {
|
||||
if (b.getBlockData() instanceof org.bukkit.block.data.type.Sign || b.getBlockData() instanceof org.bukkit.block.data.type.WallSign) {
|
||||
//if (b.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
user.setCreate(false);
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "This sign is already a SudoSign! Cancelling...", null);
|
||||
return;
|
||||
}
|
||||
SudoSigns.signs.get(user.getPassThru()).setSign(sign);
|
||||
SudoSigns.signs.get(user.getPassThru()).addLines();
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
SignEditor editor = new SignEditor(p, SudoSigns.signs.get(user.getPassThru()), user);
|
||||
user.setEditor(editor);
|
||||
}
|
||||
SudoSigns.config.saveSign(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign wasn't clicked! Cancelling...", null);
|
||||
user.setCreate(false);
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
}
|
||||
user.setCreate(false);
|
||||
}
|
||||
|
||||
private void copy(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign || b.getState() instanceof WallSign) {
|
||||
Sign newSign = (Sign) b.getState();
|
||||
String name = Util.findSign(newSign);
|
||||
if (name != null) {
|
||||
user.setCopy(false);
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
Util.sudoSignsMessage(p, "&cERROR: That sign is already a SudoSign! Cancelling...");
|
||||
return;
|
||||
}
|
||||
SudoSigns.signs.get(user.getPassThru()).setSign(newSign);
|
||||
SudoSigns.signs.get(user.getPassThru()).addLines();
|
||||
SudoSigns.config.saveSign(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
Util.sudoSignsMessage(p, "&aSign has been copied to sign &e%NAME% &asuccessfully!", user.getPassThru());
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign was not clicked! &6Cancelling...");
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
}
|
||||
user.setCopy(false);
|
||||
}
|
||||
private void copy(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign) {
|
||||
Sign newSign = (Sign) b.getState();
|
||||
String name = Util.findSign(newSign);
|
||||
if (name != null) {
|
||||
user.setCopy(false);
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "This sign is already a SudoSign! Cancelling...", null);
|
||||
return;
|
||||
}
|
||||
SudoSigns.signs.get(user.getPassThru()).setSign(newSign);
|
||||
SudoSigns.signs.get(user.getPassThru()).addLines();
|
||||
SudoSigns.config.saveSign(SudoSigns.signs.get(user.getPassThru()), true, p);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Sign has been copied to sign %NAME% successfully!", user.getPassThru());
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "A sign wasn't clicked! Cancelling...", null);
|
||||
SudoSigns.signs.remove(user.getPassThru());
|
||||
}
|
||||
user.setCopy(false);
|
||||
}
|
||||
|
||||
private void runRemote(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign || b.getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss run " +name);
|
||||
private void runRemote(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss run " +name);
|
||||
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: That is not a SudoSign! &6Use: &d/ss create <name> &6instead.");
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign was not clicked! Cancelling...");
|
||||
}
|
||||
user.setRun(false);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "This is not a SudoSign. Use " + ChatColor.GRAY + "/ss create <name>" + ChatColor.RED + " instead.", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED,"A sign wasn't clicked! Cancelling...", null);
|
||||
}
|
||||
user.setRun(false);
|
||||
}
|
||||
|
||||
private void edit(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign || b.getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss edit " + name);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: That is not a SudoSign! &6Use: &d/ss create <name> &6instead.");
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign was not clicked! Cancelling...");
|
||||
}
|
||||
user.setEdit(false);
|
||||
}
|
||||
private void edit(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss edit " + name);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "This is not a SudoSign. Use " + ChatColor.GRAY + "/ss create <name>" + ChatColor.RED + " instead.", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED,"A sign wasn't clicked! Cancelling...", null);
|
||||
}
|
||||
user.setEdit(false);
|
||||
}
|
||||
|
||||
private void delete(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign || b.getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss delete " + name);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: That is not a SudoSign!");
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign was not clicked! &6Cancelling...");
|
||||
}
|
||||
user.setDelete(false);
|
||||
}
|
||||
private void delete(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss delete " + name);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "This is not a SudoSign!", null);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "This is not a SudoSign!", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED,"A sign wasn't clicked! Cancelling...", null);
|
||||
}
|
||||
user.setDelete(false);
|
||||
}
|
||||
|
||||
private void view(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign || b.getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss view " + name);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: That is not a SudoSign! &6Use: &d/ss create <name> &6instead.");
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign was not clicked! &6Cancelling...");
|
||||
}
|
||||
user.setView(false);
|
||||
}
|
||||
private void view(Player p, SudoUser user, Block b) {
|
||||
if (b.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
String name = Util.findSign(sign);
|
||||
if (name != null) {
|
||||
p.performCommand("ss view " + name);
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "This is not a SudoSign. Use " + ChatColor.GRAY + "/ss create <name>" + ChatColor.RED + " instead.", null);
|
||||
}
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED,"A sign wasn't clicked! Cancelling...", null);
|
||||
}
|
||||
user.setView(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDestroy(BlockBreakEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (e.getBlock().getState() instanceof Sign || e.getBlock().getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) e.getBlock().getState();
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
if (p.hasPermission(Permissions.SELECT)) {
|
||||
Util.sendSelectMenus(p, entry.getKey());
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, "&cERROR: You do not have permission to destroy that sign!");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
Block br = e.getBlock().getRelative(face);
|
||||
BlockState bs = br.getState();
|
||||
if (bs instanceof Sign || bs instanceof WallSign) {
|
||||
Sign sign = (Sign) bs;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
if (br.getBlockData() instanceof Sign) {
|
||||
if (e.getBlock().equals(sign.getBlock().getRelative(BlockFace.DOWN))) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: You cannot destroy a block that is attached to a SudoSign!");
|
||||
return;
|
||||
}
|
||||
} else if (br.getBlockData() instanceof WallSign) {
|
||||
WallSign signData = (WallSign) sign.getBlock().getState().getBlockData();
|
||||
BlockFace attached = signData.getFacing().getOppositeFace();
|
||||
Block blockAttached = sign.getBlock().getRelative(attached);
|
||||
if (e.getBlock().equals(blockAttached)) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, "&cERROR: You cannot destroy a block that is attached to a SudoSign!");
|
||||
return;
|
||||
}
|
||||
@EventHandler
|
||||
public void onDestroy(BlockBreakEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
if (e.getBlock().getState() instanceof Sign) {
|
||||
Sign sign = (Sign) e.getBlock().getState();
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
if (p.hasPermission(Permissions.SELECT)) {
|
||||
String message = Util.getSelectString(p, entry.getKey());
|
||||
p.spigot().sendMessage(ComponentSerializer.parse(message));
|
||||
} else {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You don't have permission to destroy this sign!", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
Block br = e.getBlock().getRelative(face);
|
||||
BlockState bs = br.getState();
|
||||
if (bs instanceof Sign) {
|
||||
Sign sign = (Sign) bs;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
if (br.getBlockData() instanceof org.bukkit.block.data.type.Sign) {
|
||||
if (e.getBlock().equals(sign.getBlock().getRelative(BlockFace.DOWN))) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You can't destroy a block that's attached to a SudoSign!", null);
|
||||
return;
|
||||
}
|
||||
} else if (br.getBlockData() instanceof org.bukkit.block.data.type.WallSign) {
|
||||
WallSign signData = (WallSign) sign.getBlock().getState().getBlockData();
|
||||
BlockFace attached = signData.getFacing().getOppositeFace();
|
||||
Block blockAttached = sign.getBlock().getRelative(attached);
|
||||
if (e.getBlock().equals(blockAttached)) {
|
||||
e.setCancelled(true);
|
||||
Util.sudoSignsMessage(p, ChatColor.RED, "You can't destroy a block that's attached to a SudoSign!", null);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The following events all attempt to prevent a SudoSign being broken
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent e) {
|
||||
ArrayList<Block> blocksToRemove = new ArrayList<>();
|
||||
for (Block block : e.blockList()) {
|
||||
if (block.getState() instanceof Sign || block.getState() instanceof WallSign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
blocksToRemove.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = block.getRelative(face).getState();
|
||||
if (b instanceof Sign || b instanceof WallSign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
blocksToRemove.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Block b : blocksToRemove) {
|
||||
e.blockList().remove(b);
|
||||
}
|
||||
}
|
||||
// The following events all attempt to prevent a SudoSign being broken
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBurn(BlockBurnEvent e) {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = e.getBlock().getRelative(face).getState();
|
||||
if (b instanceof Sign || b instanceof WallSign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onEntityExplode(EntityExplodeEvent e) {
|
||||
ArrayList<Block> blocksToRemove = new ArrayList<>();
|
||||
for (Block block : e.blockList()) {
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign) block.getState();
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
blocksToRemove.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = block.getRelative(face).getState();
|
||||
if (b instanceof Sign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
blocksToRemove.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Block b : blocksToRemove) {
|
||||
e.blockList().remove(b);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockFade(BlockFadeEvent e) {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = e.getBlock().getRelative(face).getState();
|
||||
if (b instanceof Sign || b instanceof WallSign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onBlockBurn(BlockBurnEvent e) {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = e.getBlock().getRelative(face).getState();
|
||||
if (b instanceof Sign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeavesDecay(LeavesDecayEvent e) {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = e.getBlock().getRelative(face).getState();
|
||||
if (b instanceof Sign || b instanceof WallSign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@EventHandler
|
||||
public void onBlockFade(BlockFadeEvent e) {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = e.getBlock().getRelative(face).getState();
|
||||
if (b instanceof Sign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeavesDecay(LeavesDecayEvent e) {
|
||||
final BlockFace[] faces = {BlockFace.UP, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
for (BlockFace face : faces) {
|
||||
BlockState b = e.getBlock().getRelative(face).getState();
|
||||
if (b instanceof Sign) {
|
||||
Sign sign = (Sign) b;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().getSign().equals(sign)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,5 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
@@ -21,147 +7,116 @@ import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CommandOptionsMenu {
|
||||
|
||||
private Inventory menu;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private SignCommand sc;
|
||||
private Player p;
|
||||
private SignEditor editor;
|
||||
private Inventory menu;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private SignCommand sc;
|
||||
private Player p;
|
||||
private SignEditor editor;
|
||||
|
||||
CommandOptionsMenu(SudoUser su, Player p, SudoSign sign, ItemStack item, SignEditor editor) {
|
||||
CommandOptionsMenu(SudoUser su, Player p, SudoSign sign, ItemStack item, SignEditor editor) {
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
this.editor = editor;
|
||||
this.sc = findSignCommand(item);
|
||||
if (this.sc == null) {
|
||||
editor.goToCommands();
|
||||
return;
|
||||
}
|
||||
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
this.editor = editor;
|
||||
this.sc = findSignCommand(item);
|
||||
}
|
||||
|
||||
if (this.sc == null) {
|
||||
public void goToCommandOptionsMenu() {
|
||||
createCommandOptionsMenu();
|
||||
p.openInventory(menu);
|
||||
}
|
||||
|
||||
editor.goToCommands();
|
||||
private SignCommand findSignCommand(ItemStack item) {
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "command-number");
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
|
||||
return;
|
||||
if (container.has(key, PersistentDataType.INTEGER)) {
|
||||
int foundValue = container.get(key, PersistentDataType.INTEGER);
|
||||
return sign.getSignCommandByNumber(foundValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
private void createCommandOptionsMenu() {
|
||||
menu = Bukkit.createInventory(p, 45, "Command options: /" + sc.getCommand());
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
}
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
public void goToCommandOptionsMenu() {
|
||||
ItemStack clock = new ItemStack(Material.CLOCK);
|
||||
ItemMeta clockMeta = clock.getItemMeta();
|
||||
lore.add(ChatColor.YELLOW + "Change the delay after which the command executes");
|
||||
clockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Change Delay");
|
||||
clockMeta.setLore(lore);
|
||||
clock.setItemMeta(clockMeta);
|
||||
|
||||
createCommandOptionsMenu();
|
||||
p.openInventory(menu);
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.RED + "Delete Command");
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
}
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS) && p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
menu.setItem(20, clock);
|
||||
menu.setItem(24, barrier);
|
||||
} else {
|
||||
menu.setItem(22, clock);
|
||||
}
|
||||
menu.setItem(36, arrow);
|
||||
}
|
||||
|
||||
private SignCommand findSignCommand(ItemStack item) {
|
||||
public void addDelay() {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the delay in seconds. To cancel, type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.COMMAND_DELAY);
|
||||
}
|
||||
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "command-number");
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
public void setDelay(double delay) {
|
||||
double oldDelay = sc.getDelay();
|
||||
sc.setDelay(delay * 1000);
|
||||
SudoSigns.config.deleteCommand(sign, sc, sc.getType(), oldDelay);
|
||||
SudoSigns.config.addCommand(sign, sc, sc.getType());
|
||||
}
|
||||
|
||||
if (container.has(key, PersistentDataType.INTEGER)) {
|
||||
public void deleteCommand() {
|
||||
if (sc.getType() == PlayerInput.CONSOLE_COMMAND) {
|
||||
SudoSigns.config.deleteCommand(sign, sc, PlayerInput.CONSOLE_COMMAND, sc.getDelay());
|
||||
sign.deleteConsoleCommand(sc);
|
||||
} else if (sc.getType() == PlayerInput.PLAYER_COMMAND) {
|
||||
SudoSigns.config.deleteCommand(sign, sc, PlayerInput.PLAYER_COMMAND, sc.getDelay());
|
||||
sign.deletePlayerCommand(sc);
|
||||
}
|
||||
editor.goToCommands();
|
||||
}
|
||||
|
||||
int foundValue = container.get(key, PersistentDataType.INTEGER);
|
||||
|
||||
return sign.getSignCommandByNumber(foundValue);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private void createCommandOptionsMenu() {
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("Command options: /" + sc.getCommand());
|
||||
|
||||
menu = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
|
||||
arrowMeta.displayName(Util.legacySerializerAnyCase("&r&dBACK"));
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack clock = new ItemStack(Material.CLOCK);
|
||||
ItemMeta clockMeta = clock.getItemMeta();
|
||||
|
||||
lore.add("&eChange the delay after which the command executes");
|
||||
clockMeta.displayName(Util.legacySerializerAnyCase("&r&dChange Delay"));
|
||||
clockMeta.lore(Util.convertToTextComponents(lore));
|
||||
clock.setItemMeta(clockMeta);
|
||||
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
|
||||
barrierMeta.displayName(Util.legacySerializerAnyCase("&r&cDelete Command"));
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS) && p.hasPermission(Permissions.DELETE_COMMAND)) {
|
||||
|
||||
menu.setItem(20, clock);
|
||||
menu.setItem(24, barrier);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
menu.setItem(22, clock);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(36, arrow);
|
||||
|
||||
}
|
||||
|
||||
public void addDelay() {
|
||||
|
||||
p.closeInventory();
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please enter the delay in seconds. To cancel, type &cCANCEL&6.");
|
||||
|
||||
su.addTextInput(PlayerInput.COMMAND_DELAY);
|
||||
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
|
||||
double oldDelay = sc.getDelay();
|
||||
sc.setDelay(delay * 1000);
|
||||
|
||||
SudoSigns.config.deleteCommand(sign, sc, sc.getType(), oldDelay);
|
||||
SudoSigns.config.addCommand(sign, sc, sc.getType());
|
||||
|
||||
}
|
||||
|
||||
public void deleteCommand() {
|
||||
|
||||
if (sc.getType() == PlayerInput.CONSOLE_COMMAND) {
|
||||
|
||||
SudoSigns.config.deleteCommand(sign, sc, PlayerInput.CONSOLE_COMMAND, sc.getDelay());
|
||||
sign.deleteConsoleCommand(sc);
|
||||
|
||||
}
|
||||
else if (sc.getType() == PlayerInput.PLAYER_COMMAND) {
|
||||
|
||||
SudoSigns.config.deleteCommand(sign, sc, PlayerInput.PLAYER_COMMAND, sc.getDelay());
|
||||
sign.deletePlayerCommand(sc);
|
||||
|
||||
}
|
||||
|
||||
editor.goToCommands();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,261 +1,201 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.*;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandsMenu {
|
||||
|
||||
private Inventory menu;
|
||||
private Player p;
|
||||
private SudoSign sign;
|
||||
private SignEditor editor;
|
||||
private SudoUser su;
|
||||
|
||||
public CommandsMenu(SudoUser su, Player p, SudoSign sign, SignEditor editor) {
|
||||
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.editor = editor;
|
||||
this.p = p;
|
||||
|
||||
}
|
||||
|
||||
public void goToCommandsMenu() {
|
||||
|
||||
createCommandsMenu();
|
||||
|
||||
p.openInventory(menu);
|
||||
|
||||
}
|
||||
|
||||
private void createCommandsMenu() {
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("Commands: " + sign.getName());
|
||||
|
||||
menu = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
|
||||
}
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
|
||||
arrowMeta.displayName(Util.legacySerializerAnyCase("&r&dBACK"));
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.ADD_COMMAND)) {
|
||||
|
||||
ItemStack bookQuill = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bqMeta = bookQuill.getItemMeta();
|
||||
|
||||
bqMeta.displayName(Util.legacySerializerAnyCase("&r&2Add new command"));
|
||||
bookQuill.setItemMeta(bqMeta);
|
||||
|
||||
menu.setItem(40, bookQuill);
|
||||
|
||||
}
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
|
||||
cmdBlockMeta.displayName(Util.legacySerializerAnyCase("&r&5Console Commands"));
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemMeta headMeta = head.getItemMeta();
|
||||
|
||||
headMeta.displayName(Util.legacySerializerAnyCase("&r&d Player Commands"));
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "command-number");
|
||||
|
||||
ArrayList<SignCommand> orderedSignCommands = sign.getPlayerCommands();
|
||||
orderedSignCommands.sort(Comparator.comparing(SignCommand::getDelay));
|
||||
|
||||
// Populates spaces with commands.
|
||||
int i = 1;
|
||||
for (SignCommand sc : orderedSignCommands) {
|
||||
|
||||
if (i > 26) break;
|
||||
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
|
||||
lore.add("&6Player Command");
|
||||
bookMeta.displayName(Util.legacySerializerAnyCase("&r&6/" + sc.getCommand()));
|
||||
lore.add("&6Delay: &e" + (sc.getDelay() / 1000) + "s");
|
||||
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
|
||||
|
||||
lore.add("");
|
||||
lore.add("&2Click for options!");
|
||||
|
||||
}
|
||||
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sc.getNumber());
|
||||
bookMeta.lore(Util.convertToTextComponents(lore));
|
||||
|
||||
lore.clear();
|
||||
book.setItemMeta(bookMeta);
|
||||
|
||||
if (i == 9) i++;
|
||||
|
||||
menu.setItem(i, book);
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
orderedSignCommands = sign.getConsoleCommands();
|
||||
orderedSignCommands.sort(Comparator.comparing(SignCommand::getDelay));
|
||||
|
||||
i = 19;
|
||||
for (SignCommand sc : orderedSignCommands) {
|
||||
|
||||
if (i > 35) break;
|
||||
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
|
||||
lore.add("&6Console Command");
|
||||
bookMeta.displayName(Util.legacySerializerAnyCase("&r&6/" + sc.getCommand()));
|
||||
lore.add("&6Delay: &e" + (sc.getDelay() / 1000) + "s");
|
||||
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
|
||||
|
||||
lore.add("");
|
||||
lore.add("&2Click for options!");
|
||||
|
||||
}
|
||||
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sc.getNumber());
|
||||
bookMeta.lore(Util.convertToTextComponents(lore));
|
||||
|
||||
lore.clear();
|
||||
book.setItemMeta(bookMeta);
|
||||
|
||||
if (i == 27) i++;
|
||||
|
||||
menu.setItem(i, book);
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(0, head);
|
||||
menu.setItem(9, head);
|
||||
menu.setItem(18, cmdBlock);
|
||||
menu.setItem(27, cmdBlock);
|
||||
menu.setItem(36, arrow);
|
||||
|
||||
}
|
||||
|
||||
public void prepareCommand() {
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("Player or Console command?");
|
||||
|
||||
Inventory choiceInv = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
for (int i = 0; i < choiceInv.getSize(); i++) {
|
||||
|
||||
choiceInv.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
|
||||
}
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
|
||||
arrowMeta.displayName(Util.legacySerializerAnyCase("&r&dBACK"));
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemMeta headMeta = head.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add("&cThe player must have permission to run the command!");
|
||||
headMeta.displayName(Util.legacySerializerAnyCase("&r&dPlayer Command"));
|
||||
headMeta.lore(Util.convertToTextComponents(lore));
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
cmdBlockMeta.displayName(Util.legacySerializerAnyCase("&r&dConsole Command"));
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.CONSOLE_COMMAND)) {
|
||||
|
||||
choiceInv.setItem(21, head);
|
||||
choiceInv.setItem(23, cmdBlock);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
choiceInv.setItem(22, head);
|
||||
|
||||
}
|
||||
|
||||
choiceInv.setItem(36, arrow);
|
||||
|
||||
editor.setCurrentPage(GUIPage.CHOOSE_COMMAND);
|
||||
p.openInventory(choiceInv);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void chooseCommandType(PlayerInput type) {
|
||||
|
||||
p.closeInventory();
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please enter the full command in chat with the beginning &e/&6. The placeholder &e%PLAYER% &6will be replaced with the player who clicked the sign. To cancel, type &cCANCEL&6.");
|
||||
su.addTextInput(type);
|
||||
|
||||
}
|
||||
|
||||
public void addCommand(String cmd, PlayerInput type) {
|
||||
|
||||
SignCommand command = new SignCommand(sign.getNextCommandNumber(), cmd, 0, type);
|
||||
switch (type) {
|
||||
case CONSOLE_COMMAND:
|
||||
sign.addConsoleCommand(command);
|
||||
break;
|
||||
case PLAYER_COMMAND:
|
||||
sign.addPlayerCommand(command);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SudoSigns.config.addCommand(sign, command, type);
|
||||
|
||||
Util.sudoSignsMessage(p, "&aCommand added successfully!");
|
||||
editor.goToCommands();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private final GUIPage PAGE = GUIPage.COMMANDS;
|
||||
|
||||
private Inventory menu;
|
||||
private Player p;
|
||||
private SudoSign sign;
|
||||
private SignEditor editor;
|
||||
private SudoUser su;
|
||||
|
||||
public CommandsMenu(SudoUser su, Player p, SudoSign sign, SignEditor editor) {
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.editor = editor;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public void goToCommandsMenu() {
|
||||
createCommandsMenu();
|
||||
p.openInventory(menu);
|
||||
}
|
||||
|
||||
private void createCommandsMenu() {
|
||||
menu = Bukkit.createInventory(p, 45, "Commands: " + sign.getName());
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.ADD_COMMAND)) {
|
||||
ItemStack bookQuill = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bqMeta = bookQuill.getItemMeta();
|
||||
bqMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + "Add new command");
|
||||
bookQuill.setItemMeta(bqMeta);
|
||||
menu.setItem(40, bookQuill);
|
||||
}
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
cmdBlockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Console Commands");
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemMeta headMeta = head.getItemMeta();
|
||||
headMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Player Commands");
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "command-number");
|
||||
|
||||
ArrayList<SignCommand> orderedSignCommands = sign.getPlayerCommands();
|
||||
orderedSignCommands.sort(Comparator.comparing(SignCommand::getDelay));
|
||||
|
||||
// Populates spaces with commands.
|
||||
int i = 1;
|
||||
for (SignCommand sc : orderedSignCommands) {
|
||||
if (i > 26) break;
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Player Command");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
|
||||
lore.add("");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Delay: " + ChatColor.RED + (sc.getDelay() / 1000) + "s");
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GREEN + "Click for options!");
|
||||
}
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sc.getNumber());
|
||||
bookMeta.setLore(lore);
|
||||
lore.clear();
|
||||
book.setItemMeta(bookMeta);
|
||||
if (i == 9) i++;
|
||||
menu.setItem(i, book);
|
||||
i++;
|
||||
}
|
||||
|
||||
orderedSignCommands = sign.getConsoleCommands();
|
||||
orderedSignCommands.sort(Comparator.comparing(SignCommand::getDelay));
|
||||
|
||||
i = 19;
|
||||
for (SignCommand sc : orderedSignCommands) {
|
||||
if (i > 35) break;
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Console Command");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.RESET + ChatColor.GOLD + "/" + sc.getCommand());
|
||||
lore.add("");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Delay: " + ChatColor.RED + (sc.getDelay() / 1000) + "s");
|
||||
if (p.hasPermission(Permissions.COMMAND_OPTIONS)) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GREEN + "Click for options!");
|
||||
}
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sc.getNumber());
|
||||
bookMeta.setLore(lore);
|
||||
lore.clear();
|
||||
book.setItemMeta(bookMeta);
|
||||
if (i == 27) i++;
|
||||
menu.setItem(i, book);
|
||||
i++;
|
||||
}
|
||||
|
||||
menu.setItem(0, head);
|
||||
menu.setItem(9, head);
|
||||
menu.setItem(18, cmdBlock);
|
||||
menu.setItem(27, cmdBlock);
|
||||
|
||||
menu.setItem(36, arrow);
|
||||
}
|
||||
|
||||
public void prepareCommand() {
|
||||
Inventory choiceInv = Bukkit.createInventory(p, 45, "Player or Console command?");
|
||||
for (int i = 0; i < choiceInv.getSize(); i++) {
|
||||
choiceInv.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemMeta headMeta = head.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.RED + "The player must have permission to run the command!");
|
||||
headMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Player Command");
|
||||
headMeta.setLore(lore);
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
cmdBlockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Console Command");
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.CONSOLE_COMMAND)) {
|
||||
choiceInv.setItem(21, head);
|
||||
choiceInv.setItem(23, cmdBlock);
|
||||
} else {
|
||||
choiceInv.setItem(22, head);
|
||||
}
|
||||
choiceInv.setItem(36, arrow);
|
||||
|
||||
editor.setCurrentPage(GUIPage.CHOOSE_COMMAND);
|
||||
p.openInventory(choiceInv);
|
||||
}
|
||||
|
||||
|
||||
public void chooseCommandType(PlayerInput type) {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix);
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "Please enter the full command in chat beginning with " + ChatColor.GOLD + "/" + ChatColor.GRAY + ".");
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + ChatColor.GOLD + "%PLAYER%" + ChatColor.GRAY + " will be replaced with the player's name.");
|
||||
if (SudoSigns.papi) {
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "You can also use " + ChatColor.GOLD + "PlaceHolderAPI" + ChatColor.GRAY + " placeholders.");
|
||||
}
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "To cancel type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(type);
|
||||
}
|
||||
|
||||
public void addCommand(String cmd, PlayerInput type) {
|
||||
SignCommand command = new SignCommand(sign.getNextCommandNumber(), cmd, 0, type);
|
||||
switch (type) {
|
||||
case CONSOLE_COMMAND:
|
||||
sign.addConsoleCommand(command);
|
||||
break;
|
||||
case PLAYER_COMMAND:
|
||||
sign.addPlayerCommand(command);
|
||||
break;
|
||||
}
|
||||
SudoSigns.config.addCommand(sign, command, type);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Command added successfully!", null);
|
||||
editor.goToCommands();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,4 +9,4 @@ public enum GUIPage {
|
||||
MESSAGES,
|
||||
COMMAND_OPTIONS,
|
||||
MESSAGE_OPTIONS
|
||||
}
|
||||
}
|
||||
@@ -1,276 +1,194 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainMenu {
|
||||
|
||||
private Inventory menu;
|
||||
private SudoSign sign;
|
||||
private Player p;
|
||||
private int lineNumber = 0;
|
||||
|
||||
public MainMenu(Player p, SudoSign sign, SignEditor editor) {
|
||||
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
|
||||
}
|
||||
|
||||
public void goToMainMenu() {
|
||||
|
||||
createMainMenu();
|
||||
p.openInventory(menu);
|
||||
|
||||
}
|
||||
|
||||
private void createMainMenu() {
|
||||
|
||||
ArrayList<ItemStack> items = new ArrayList<>();
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("&r&2Editing: &e" + sign.getName());
|
||||
|
||||
menu = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(" ");
|
||||
menu.getItem(i).lore(Util.convertToTextComponents(lore));
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.RENAME)) {
|
||||
|
||||
ItemStack nametag = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta ntMeta = nametag.getItemMeta();
|
||||
|
||||
ntMeta.displayName(Util.legacySerializerAnyCase("&r&5Rename Sign"));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("&eChange the text that refers");
|
||||
lore.add("&eto this sign in the config");
|
||||
lore.add("&efile and in commands.");
|
||||
|
||||
ntMeta.lore(Util.convertToTextComponents(lore));
|
||||
nametag.setItemMeta(ntMeta);
|
||||
|
||||
items.add(nametag);
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.EDIT_TEXT)) {
|
||||
|
||||
ItemStack book = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
|
||||
bookMeta.displayName(Util.legacySerializerAnyCase("&r&5Edit Sign Text"));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("&eChange the text that displays");
|
||||
lore.add("&eon the sign itself. Colored");
|
||||
lore.add("&esigns require another plugin.");
|
||||
|
||||
bookMeta.lore(Util.convertToTextComponents(lore));
|
||||
book.setItemMeta(bookMeta);
|
||||
|
||||
items.add(book);
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW_PERMISSION)) {
|
||||
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
|
||||
barrierMeta.displayName(Util.legacySerializerAnyCase("&r&dPermissions"));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("&ePlayers must have all permissions");
|
||||
lore.add("&elisted in this section to be able");
|
||||
lore.add("&eto use the sign.");
|
||||
|
||||
barrierMeta.lore(Util.convertToTextComponents(lore));
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
items.add(barrier);
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW_COMMAND)) {
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("&eCommands listed here will be executed");
|
||||
lore.add("&ewhen a player uses the sign.");
|
||||
|
||||
cmdBlockMeta.lore(Util.convertToTextComponents(lore));
|
||||
cmdBlockMeta.displayName(Util.legacySerializerAnyCase("&r&5Commands"));
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
items.add(cmdBlock);
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW_MESSAGE)) {
|
||||
|
||||
ItemStack signBlock = new ItemStack(Material.OAK_SIGN);
|
||||
ItemMeta signMeta = signBlock.getItemMeta();
|
||||
|
||||
signMeta.displayName(Util.legacySerializerAnyCase("&r&5Messages"));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("&eMessages listed here will be shown");
|
||||
lore.add("&eto the player when they use the sign.");
|
||||
|
||||
signMeta.lore(Util.convertToTextComponents(lore));
|
||||
signBlock.setItemMeta(signMeta);
|
||||
|
||||
items.add(signBlock);
|
||||
|
||||
}
|
||||
|
||||
if (SudoSigns.econ != null) {
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW_PRICE)) {
|
||||
|
||||
if (SudoSigns.econ != null) {
|
||||
|
||||
ItemStack goldNugget = new ItemStack(Material.GOLD_NUGGET);
|
||||
ItemMeta goldNuggetItemMeta = goldNugget.getItemMeta();
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("&eThe cost to use this sign.");
|
||||
lore.add("&e");
|
||||
|
||||
if (sign.getPrice() == 1.0) {
|
||||
|
||||
lore.add("&7" + SudoSigns.econ.currencyNameSingular() + "&c" + sign.getPrice());
|
||||
|
||||
} else {
|
||||
|
||||
lore.add("&7" + SudoSigns.econ.currencyNamePlural() + "&c" + sign.getPrice());
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.SET_PRICE)) {
|
||||
|
||||
lore.add("&e");
|
||||
lore.add("&aClick to edit!");
|
||||
|
||||
}
|
||||
|
||||
goldNuggetItemMeta.lore(Util.convertToTextComponents(lore));
|
||||
goldNuggetItemMeta
|
||||
.displayName(Util.legacySerializerAnyCase("&r&dPrice"));
|
||||
goldNugget.setItemMeta(goldNuggetItemMeta);
|
||||
|
||||
items.add(goldNugget);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch (items.size()) {
|
||||
case 6:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
menu.setItem(31, items.get(4));
|
||||
menu.setItem(33, items.get(5));
|
||||
case 5:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
menu.setItem(31, items.get(4));
|
||||
case 4:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
break;
|
||||
case 3:
|
||||
menu.setItem(20, items.get(0));
|
||||
menu.setItem(22, items.get(1));
|
||||
menu.setItem(24, items.get(2));
|
||||
break;
|
||||
case 2:
|
||||
menu.setItem(21, items.get(0));
|
||||
menu.setItem(23, items.get(1));
|
||||
break;
|
||||
case 1:
|
||||
menu.setItem(22, items.get(0));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void prepareSetPrice() {
|
||||
|
||||
p.closeInventory();
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please enter the price to use the sign! Type &cCANCEL &6to cancel the operation.");
|
||||
SudoSigns.users.get(p.getUniqueId()).addTextInput(PlayerInput.SET_PRICE);
|
||||
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
|
||||
sign.setPrice(price);
|
||||
SudoSigns.config.setPrice(sign.getName(), price);
|
||||
|
||||
if (sign.getPrice() == 1.0) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6The price of &e" + sign.getName() + " &6has been set to: " + price + "&b"
|
||||
+ SudoSigns.econ.currencyNameSingular() + "&6.");
|
||||
|
||||
} else {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6The price of &e" + sign.getName() + " &6has been set to: " + price + "&b"
|
||||
+ SudoSigns.econ.currencyNamePlural() + "&6.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setLineNumber(int lineNumber) {
|
||||
|
||||
this.lineNumber = lineNumber;
|
||||
Util.sudoSignsMessage(p,
|
||||
"&6Please enter the new text (maximum 15 characters), using the &e& &6symbol for color codes. Type &cCANCEL &6to cancel the operation.");
|
||||
SudoSigns.users.get(p.getUniqueId()).addTextInput(PlayerInput.EDIT_TEXT);
|
||||
|
||||
}
|
||||
|
||||
public void setText(TextComponent message) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aLine &e" + lineNumber + " &ahas been set to: " + message);
|
||||
sign.editLine(lineNumber - 1, message);
|
||||
SudoSigns.config.editSignText(sign.getName(), lineNumber, message);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private final GUIPage PAGE = GUIPage.MAIN;
|
||||
|
||||
private Inventory menu;
|
||||
private SudoSign sign;
|
||||
private SignEditor editor;
|
||||
private Player p;
|
||||
private int lineNumber = 0;
|
||||
|
||||
public MainMenu(Player p, SudoSign sign, SignEditor editor) {
|
||||
this.sign = sign;
|
||||
this.editor = editor;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public void goToMainMenu() {
|
||||
createMainMenu();
|
||||
p.openInventory(menu);
|
||||
}
|
||||
|
||||
private void createMainMenu() {
|
||||
ArrayList<ItemStack> items = new ArrayList<>();
|
||||
menu = Bukkit.createInventory(p, 45, "Editing: " + sign.getName());
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
if (p.hasPermission(Permissions.RENAME)) {
|
||||
ItemStack nametag = new ItemStack(Material.NAME_TAG);
|
||||
ItemMeta ntMeta = nametag.getItemMeta();
|
||||
ntMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Rename Sign");
|
||||
nametag.setItemMeta(ntMeta);
|
||||
items.add(nametag);
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.EDIT_TEXT)) {
|
||||
ItemStack book = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
bookMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Edit Sign Text");
|
||||
book.setItemMeta(bookMeta);
|
||||
items.add(book);
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW_PERMISSION)) {
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Permissions");
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.YELLOW + "Players must have all permissions");
|
||||
lore.add(ChatColor.YELLOW + "listed in this section to be able");
|
||||
lore.add(ChatColor.YELLOW + "to use the sign.");
|
||||
barrierMeta.setLore(lore);
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
items.add(barrier);
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW_COMMAND)) {
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.YELLOW + "Commands listed here will be executed");
|
||||
lore.add(ChatColor.YELLOW + "when a player uses the sign.");
|
||||
cmdBlockMeta.setLore(lore);
|
||||
cmdBlockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Commands");
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
items.add(cmdBlock);
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW_MESSAGE)) {
|
||||
ItemStack signBlock;
|
||||
if (SudoSigns.version.contains("1.13")) {
|
||||
signBlock = new ItemStack(Material.valueOf("SIGN"));
|
||||
} else {
|
||||
signBlock = new ItemStack(Material.BIRCH_SIGN);
|
||||
}
|
||||
ItemMeta signMeta = signBlock.getItemMeta();
|
||||
signMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Messages");
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.YELLOW + "Messages listed here will be shown");
|
||||
lore.add(ChatColor.YELLOW + "to the player when they use the sign.");
|
||||
signMeta.setLore(lore);
|
||||
signBlock.setItemMeta(signMeta);
|
||||
items.add(signBlock);
|
||||
}
|
||||
|
||||
if (SudoSigns.econ != null) {
|
||||
if (p.hasPermission(Permissions.VIEW_PRICE)) {
|
||||
if (SudoSigns.econ != null) {
|
||||
ItemStack goldNugget = new ItemStack(Material.GOLD_NUGGET);
|
||||
ItemMeta goldNuggetItemMeta = goldNugget.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.YELLOW + "Set the price to use this sign.");
|
||||
lore.add(ChatColor.YELLOW + "");
|
||||
if (sign.getPrice() == 1.0) {
|
||||
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Price: " + ChatColor.GRAY + SudoSigns.econ.currencyNameSingular() + ChatColor.RED + sign.getPrice());
|
||||
} else {
|
||||
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Price: " + ChatColor.GRAY + SudoSigns.econ.currencyNamePlural() + ChatColor.RED + sign.getPrice());
|
||||
}
|
||||
if (p.hasPermission(Permissions.SET_PRICE)) {
|
||||
lore.add(ChatColor.YELLOW + "");
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GREEN + "Click to edit!");
|
||||
}
|
||||
goldNuggetItemMeta.setLore(lore);
|
||||
goldNuggetItemMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Price");
|
||||
goldNugget.setItemMeta(goldNuggetItemMeta);
|
||||
items.add(goldNugget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
switch (items.size()) {
|
||||
case 6:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
menu.setItem(31, items.get(4));
|
||||
menu.setItem(33, items.get(5));
|
||||
case 5:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
menu.setItem(31, items.get(4));
|
||||
case 4:
|
||||
menu.setItem(11, items.get(0));
|
||||
menu.setItem(13, items.get(1));
|
||||
menu.setItem(15, items.get(2));
|
||||
menu.setItem(29, items.get(3));
|
||||
break;
|
||||
case 3:
|
||||
menu.setItem(20, items.get(0));
|
||||
menu.setItem(22, items.get(1));
|
||||
menu.setItem(24, items.get(2));
|
||||
break;
|
||||
case 2:
|
||||
menu.setItem(21, items.get(0));
|
||||
menu.setItem(23, items.get(1));
|
||||
break;
|
||||
case 1:
|
||||
menu.setItem(22, items.get(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void prepareSetPrice() {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the price to use the sign! Type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + " to cancel.");
|
||||
SudoSigns.users.get(p.getUniqueId()).addTextInput(PlayerInput.SET_PRICE);
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
sign.setPrice(price);
|
||||
SudoSigns.config.setPrice(sign.getName(), price);
|
||||
if (sign.getPrice() == 1.0) {
|
||||
p.sendMessage(Util.prefix + ChatColor.GREEN + " The price of " + ChatColor.GRAY + sign.getName() + " has been set to: " + ChatColor.GOLD + SudoSigns.econ.currencyNameSingular() + price + ChatColor.GREEN + ".");
|
||||
} else {
|
||||
p.sendMessage(Util.prefix + ChatColor.GREEN + " The price of " + ChatColor.GRAY + sign.getName() + " has been set to: " + ChatColor.GOLD + SudoSigns.econ.currencyNamePlural() + price + ChatColor.GREEN + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public void setLineNumber(int lineNumber) {
|
||||
this.lineNumber = lineNumber;
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the new text (maximum 15 characters), using " + ChatColor.GOLD + "& " + ChatColor.GRAY + "for colour codes. Type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + " to cancel.");
|
||||
SudoSigns.users.get(p.getUniqueId()).addTextInput(PlayerInput.EDIT_TEXT);
|
||||
}
|
||||
|
||||
public void setText(String message) {
|
||||
p.sendMessage(Util.prefix + ChatColor.GREEN + " Line " + lineNumber + " has been set to: " + ChatColor.translateAlternateColorCodes('&', message));
|
||||
sign.editLine(lineNumber-1, message);
|
||||
SudoSigns.config.editSignText(sign.getName(), lineNumber, message);
|
||||
}
|
||||
}
|
||||
@@ -1,156 +1,112 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.*;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageOptionsMenu {
|
||||
|
||||
private Inventory menu;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private SignMessage sm;
|
||||
private Player p;
|
||||
private SignEditor editor;
|
||||
private Inventory menu;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private SignMessage sm;
|
||||
private Player p;
|
||||
private SignEditor editor;
|
||||
|
||||
MessageOptionsMenu(SudoUser su, Player p, SudoSign sign, ItemStack item, SignEditor editor) {
|
||||
MessageOptionsMenu(SudoUser su, Player p, SudoSign sign, ItemStack item, SignEditor editor) {
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
this.editor = editor;
|
||||
this.sm = findSignMessage(item);
|
||||
if (this.sm == null) {
|
||||
editor.goToMessages();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
this.editor = editor;
|
||||
this.sm = findSignMessage(item);
|
||||
public void goToMessageOptionsMenu() {
|
||||
createMessageOptionsMenu();
|
||||
p.openInventory(menu);
|
||||
}
|
||||
|
||||
if (this.sm == null) {
|
||||
private SignMessage findSignMessage(ItemStack item) {
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "message-number");
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
|
||||
editor.goToMessages();
|
||||
if (container.has(key, PersistentDataType.INTEGER)) {
|
||||
int foundValue = container.get(key, PersistentDataType.INTEGER);
|
||||
return sign.getSignMessageByNumber(foundValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return;
|
||||
private void createMessageOptionsMenu() {
|
||||
menu = Bukkit.createInventory(p, 45, "Message options");
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
}
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
}
|
||||
ItemStack clock = new ItemStack(Material.CLOCK);
|
||||
ItemMeta clockMeta = clock.getItemMeta();
|
||||
lore.add(ChatColor.YELLOW + "Change the delay after which the message is sent");
|
||||
clockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Change Delay");
|
||||
clockMeta.setLore(lore);
|
||||
clock.setItemMeta(clockMeta);
|
||||
|
||||
public void goToMessageOptionsMenu() {
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.RED + "Delete Message");
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
createMessageOptionsMenu();
|
||||
p.openInventory(menu);
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS) && p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
menu.setItem(20, clock);
|
||||
menu.setItem(24, barrier);
|
||||
} else {
|
||||
menu.setItem(22, clock);
|
||||
}
|
||||
menu.setItem(36, arrow);
|
||||
}
|
||||
|
||||
}
|
||||
public void addDelay() {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the delay in seconds. To cancel, type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.MESSAGE_DELAY);
|
||||
}
|
||||
|
||||
private SignMessage findSignMessage(ItemStack item) {
|
||||
public void setDelay(double delay) {
|
||||
double oldDelay = sm.getDelay();
|
||||
sm.setDelay(delay * 1000);
|
||||
SudoSigns.config.deleteMessage(sign, sm, oldDelay);
|
||||
SudoSigns.config.addMessage(sign, sm);
|
||||
}
|
||||
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "message-number");
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
public void deleteMessage() {
|
||||
sign.removeMessage(sm);
|
||||
SudoSigns.config.deleteMessage(sign, sm, sm.getDelay());
|
||||
// if (message.equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', m))) {
|
||||
editor.goToMessages();
|
||||
}
|
||||
|
||||
if (container.has(key, PersistentDataType.INTEGER)) {
|
||||
|
||||
int foundValue = container.get(key, PersistentDataType.INTEGER);
|
||||
|
||||
return sign.getSignMessageByNumber(foundValue);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private void createMessageOptionsMenu() {
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("&6Message options");
|
||||
|
||||
menu = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
|
||||
arrowMeta.displayName(Util.legacySerializerAnyCase("&r&dBACK"));
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack clock = new ItemStack(Material.CLOCK);
|
||||
ItemMeta clockMeta = clock.getItemMeta();
|
||||
|
||||
lore.add("&eChange the delay after which the message is sent");
|
||||
clockMeta.displayName(Util.legacySerializerAnyCase("&r&dChange Delay"));
|
||||
clockMeta.lore(Util.convertToTextComponents(lore));
|
||||
clock.setItemMeta(clockMeta);
|
||||
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
|
||||
barrierMeta.displayName(Util.legacySerializerAnyCase("&r&dDelete Message"));
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS) && p.hasPermission(Permissions.DELETE_MESSAGE)) {
|
||||
|
||||
menu.setItem(20, clock);
|
||||
menu.setItem(24, barrier);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
menu.setItem(22, clock);
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(36, arrow);
|
||||
|
||||
}
|
||||
|
||||
public void addDelay() {
|
||||
|
||||
p.closeInventory();
|
||||
Util.sudoSignsMessage(p, "&6Please enter the delay in seconds. To cancel, type &cCANCEL &6.");
|
||||
su.addTextInput(PlayerInput.MESSAGE_DELAY);
|
||||
|
||||
}
|
||||
|
||||
public void setDelay(double delay) {
|
||||
|
||||
double oldDelay = sm.getDelay();
|
||||
sm.setDelay(delay * 1000);
|
||||
|
||||
SudoSigns.config.deleteMessage(sign, sm, oldDelay);
|
||||
SudoSigns.config.addMessage(sign, sm);
|
||||
|
||||
}
|
||||
|
||||
public void deleteMessage() {
|
||||
|
||||
sign.removeMessage(sm);
|
||||
SudoSigns.config.deleteMessage(sign, sm, sm.getDelay());
|
||||
editor.goToMessages();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,161 +1,129 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.*;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignMessage;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MessagesMenu {
|
||||
|
||||
private Inventory menu;
|
||||
private Player p;
|
||||
private SudoSign sign;
|
||||
private SudoUser su;
|
||||
private final GUIPage PAGE = GUIPage.MESSAGES;
|
||||
|
||||
public MessagesMenu(SudoUser su, Player p, SudoSign sign, SignEditor editor) {
|
||||
private Inventory menu;
|
||||
private Player p;
|
||||
private SudoSign sign;
|
||||
private SignEditor editor;
|
||||
private SudoUser su;
|
||||
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.p = p;
|
||||
public MessagesMenu(SudoUser su, Player p, SudoSign sign, SignEditor editor) {
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.editor = editor;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
}
|
||||
public void goToMessagesMenu() {
|
||||
createMessagesMenu();
|
||||
p.openInventory(menu);
|
||||
}
|
||||
|
||||
public void goToMessagesMenu() {
|
||||
private void createMessagesMenu() {
|
||||
menu = Bukkit.createInventory(p, 45, "Messages: " + sign.getName());
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
createMessagesMenu();
|
||||
p.openInventory(menu);
|
||||
if (p.hasPermission(Permissions.ADD_MESSAGE)) {
|
||||
ItemStack bookQuill = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bqMeta = bookQuill.getItemMeta();
|
||||
bqMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + "Add new message");
|
||||
bookQuill.setItemMeta(bqMeta);
|
||||
menu.setItem(40, bookQuill);
|
||||
}
|
||||
|
||||
}
|
||||
ItemStack signItem = null;
|
||||
if (SudoSigns.version.contains("1.13")) {
|
||||
signItem = new ItemStack(Material.valueOf("SIGN"));
|
||||
} else {
|
||||
signItem = new ItemStack(Material.BIRCH_SIGN);
|
||||
} ItemMeta signMeta = signItem.getItemMeta();
|
||||
signMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Messages");
|
||||
signItem.setItemMeta(signMeta);
|
||||
|
||||
private void createMessagesMenu() {
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("&6Messages: " + sign.getName());
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "message-number");
|
||||
|
||||
menu = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
ArrayList<SignMessage> orderedSignMessages = sign.getMessages();
|
||||
orderedSignMessages.sort(Comparator.comparing(SignMessage::getDelay));
|
||||
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
int i = 1;
|
||||
for (SignMessage sm : orderedSignMessages) {
|
||||
if (i > 35) break;
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
lore.clear();
|
||||
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Message");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.RESET + ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', sm.getMessage()));
|
||||
lore.add("");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.GRAY + ChatColor.BOLD + "Delay: " + ChatColor.RED + (sm.getDelay() / 1000) + "s");
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS)) {
|
||||
lore.add("");
|
||||
lore.add(ChatColor.GREEN + "Click for options!");
|
||||
}
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sm.getNumber());
|
||||
bookMeta.setLore(lore);
|
||||
book.setItemMeta(bookMeta);
|
||||
if (i == 9 || i == 18 || i == 27) i++;
|
||||
menu.setItem(i, book);
|
||||
i++;
|
||||
}
|
||||
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
menu.setItem(0, signItem);
|
||||
menu.setItem(9, signItem);
|
||||
menu.setItem(18, signItem);
|
||||
menu.setItem(27, signItem);
|
||||
menu.setItem(36, arrow);
|
||||
}
|
||||
|
||||
}
|
||||
public void addMessage(String message) {
|
||||
SignMessage signMessage = new SignMessage(sign.getNextMessageNumber(), message, 0, PlayerInput.MESSAGE);
|
||||
SudoSigns.config.addMessage(sign, signMessage);
|
||||
sign.addMessage(signMessage);
|
||||
}
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
public void prepareMessage() {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix);
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "Please enter the message in chat.");
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "Use the " + ChatColor.GOLD + "& " + ChatColor.GRAY + "symbol for chat colour codes.");
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + ChatColor.GOLD + "%PLAYER%" + ChatColor.GRAY + " will be replaced with the player's name.");
|
||||
if (SudoSigns.papi) {
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "You can also use " + ChatColor.GOLD + "PlaceHolderAPI" + ChatColor.GRAY + " placeholders.");
|
||||
}
|
||||
p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "* " + ChatColor.GRAY + "To cancel type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.MESSAGE);
|
||||
}
|
||||
|
||||
arrowMeta.displayName(Util.legacySerializerAnyCase("&r&dBACK"));
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.ADD_MESSAGE)) {
|
||||
|
||||
ItemStack bookQuill = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bqMeta = bookQuill.getItemMeta();
|
||||
|
||||
bqMeta.displayName(Util.legacySerializerAnyCase("&r&2Add new message"));
|
||||
bookQuill.setItemMeta(bqMeta);
|
||||
|
||||
menu.setItem(40, bookQuill);
|
||||
|
||||
}
|
||||
|
||||
ItemStack signItem = null;
|
||||
if (SudoSigns.version.contains("1.13")) {
|
||||
|
||||
signItem = new ItemStack(Material.valueOf("SIGN"));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
signItem = new ItemStack(Material.BIRCH_SIGN);
|
||||
|
||||
}
|
||||
|
||||
ItemMeta signMeta = signItem.getItemMeta();
|
||||
|
||||
signMeta.displayName(Util.legacySerializerAnyCase("&r&dMessages"));
|
||||
signItem.setItemMeta(signMeta);
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "message-number");
|
||||
|
||||
ArrayList<SignMessage> orderedSignMessages = sign.getMessages();
|
||||
orderedSignMessages.sort(Comparator.comparing(SignMessage::getDelay));
|
||||
|
||||
int i = 1;
|
||||
for (SignMessage sm : orderedSignMessages) {
|
||||
|
||||
if (i > 35) break;
|
||||
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
|
||||
lore.clear();
|
||||
bookMeta.displayName(Util.legacySerializerAnyCase("&dMessage:"));
|
||||
lore.add("&r&f" + sm.getMessage());
|
||||
lore.add("");
|
||||
lore.add("");
|
||||
lore.add("&6Delay: &e" + (sm.getDelay() / 1000) + "s");
|
||||
|
||||
if (p.hasPermission(Permissions.MESSAGE_OPTIONS)) {
|
||||
|
||||
lore.add("");
|
||||
lore.add("&2Click for options!");
|
||||
|
||||
}
|
||||
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, sm.getNumber());
|
||||
bookMeta.lore(Util.convertToTextComponents(lore));
|
||||
book.setItemMeta(bookMeta);
|
||||
|
||||
if (i == 9 || i == 18 || i == 27) i++;
|
||||
menu.setItem(i, book);
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(0, signItem);
|
||||
menu.setItem(9, signItem);
|
||||
menu.setItem(18, signItem);
|
||||
menu.setItem(27, signItem);
|
||||
menu.setItem(36, arrow);
|
||||
|
||||
}
|
||||
|
||||
public void addMessage(String message) {
|
||||
|
||||
SignMessage signMessage = new SignMessage(sign.getNextMessageNumber(), message, 0, PlayerInput.MESSAGE);
|
||||
SudoSigns.config.addMessage(sign, signMessage);
|
||||
sign.addMessage(signMessage);
|
||||
|
||||
}
|
||||
|
||||
public void prepareMessage() {
|
||||
|
||||
p.closeInventory();
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please enter in chat the message which will be shown when the sign is clicked. Use the & symbol for chat color codes and the placeholder &e%PLAYER% &6for the player who clicked the sign. To cancel the operation, type &cCANCEL&6.");
|
||||
su.addTextInput(PlayerInput.MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,214 +1,156 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PermissionsMenu {
|
||||
|
||||
private final GUIPage PAGE = GUIPage.PERMISSIONS;
|
||||
|
||||
private Inventory menu;
|
||||
private Player p;
|
||||
private SudoSign sign;
|
||||
private SignEditor editor;
|
||||
private SudoUser su;
|
||||
|
||||
public PermissionsMenu(SudoUser su, Player p, SudoSign sign, SignEditor editor) {
|
||||
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.editor = editor;
|
||||
this.p = p;
|
||||
|
||||
}
|
||||
|
||||
public void goToPermissionsMenu() {
|
||||
|
||||
createPermissionsMenu();
|
||||
|
||||
p.openInventory(menu);
|
||||
editor.setCurrentPage(PAGE);
|
||||
|
||||
}
|
||||
|
||||
private void createPermissionsMenu() {
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("&6Default or Custom?");
|
||||
|
||||
menu = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
|
||||
}
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
|
||||
arrowMeta.displayName(Util.legacySerializerAnyCase("&r&dBACK"));
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
|
||||
barrierMeta.displayName(Util.legacySerializerAnyCase("&r&5Permissions"));
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.ADD_PERMISSION)) {
|
||||
|
||||
ItemStack bookQuill = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bqMeta = bookQuill.getItemMeta();
|
||||
|
||||
bqMeta.displayName(Util.legacySerializerAnyCase("&aAdd new permission"));
|
||||
bookQuill.setItemMeta(bqMeta);
|
||||
menu.setItem(40, bookQuill);
|
||||
|
||||
}
|
||||
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
lore.add("&cClick to delete!");
|
||||
|
||||
int i = 1;
|
||||
for (String perm : sign.getPermissions()) {
|
||||
|
||||
if (i > 35) break;
|
||||
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
bookMeta.displayName(Util.legacySerializerAnyCase("&r&6" + perm));
|
||||
if (p.hasPermission(Permissions.DELETE_PERMISSION)) {
|
||||
|
||||
lore.add("");
|
||||
bookMeta.lore(Util.convertToTextComponents(lore));
|
||||
|
||||
}
|
||||
|
||||
book.setItemMeta(bookMeta);
|
||||
|
||||
if (i == 9 || i == 18 || i == 27) i++;
|
||||
|
||||
menu.setItem(i, book);
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
menu.setItem(0, barrier);
|
||||
menu.setItem(9, barrier);
|
||||
menu.setItem(18, barrier);
|
||||
menu.setItem(27, barrier);
|
||||
menu.setItem(36, arrow);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void preparePermission() {
|
||||
|
||||
Inventory playersInventory = p.getInventory();
|
||||
InventoryHolder inventoryContainer = playersInventory.getHolder(false);
|
||||
TextComponent nameHandler = Util.legacySerializerAnyCase("&6Default or Custom?");
|
||||
Inventory choiceInv = Bukkit.createInventory(inventoryContainer, 45, nameHandler);
|
||||
|
||||
int inventorySize = choiceInv.getSize();
|
||||
ArrayList<String> lore = new ArrayList<String>(inventorySize);
|
||||
for (int i = 0; i < inventorySize; i++) {
|
||||
|
||||
lore.add("");
|
||||
|
||||
choiceInv.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
choiceInv.getItem(i).lore(Util.convertToTextComponents(lore));
|
||||
|
||||
}
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
|
||||
arrowMeta.displayName(Util.legacySerializerAnyCase("&r&dBACK"));
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemMeta headMeta = head.getItemMeta();
|
||||
List<String> loreString = new ArrayList<>();
|
||||
|
||||
loreString.add("&6sudosigns.sign." + sign.getName());
|
||||
headMeta.displayName(Util.legacySerializerAnyCase("&r&dDefault Permission"));
|
||||
headMeta.lore(Util.convertToTextComponents(loreString));
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
|
||||
cmdBlockMeta.displayName(Util.legacySerializerAnyCase("&r&5Custom Permission"));
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
choiceInv.setItem(21, head);
|
||||
choiceInv.setItem(23, cmdBlock);
|
||||
choiceInv.setItem(36, arrow);
|
||||
|
||||
editor.setCurrentPage(GUIPage.CHOOSE_PERMISSION);
|
||||
|
||||
p.openInventory(choiceInv);
|
||||
|
||||
}
|
||||
|
||||
public void addPermission(boolean provided, String perm) {
|
||||
|
||||
if (provided) {
|
||||
|
||||
if (perm == null) {
|
||||
|
||||
sign.addPermission("sudosigns.sign." + sign.getName());
|
||||
SudoSigns.config.addPermission(sign, "sudosigns.sign." + sign.getName());
|
||||
|
||||
goToPermissionsMenu();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
SudoSigns.config.addPermission(sign, perm);
|
||||
sign.addPermission(perm);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
p.closeInventory();
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please enter in chat the permission which the player must have to run this sign, or type &cCANCEL &6to cancel the operation.");
|
||||
su.addTextInput(PlayerInput.PERMISSION);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deletePermission(String perm) {
|
||||
|
||||
sign.removePermission(perm);
|
||||
SudoSigns.config.deletePermission(sign, perm);
|
||||
|
||||
goToPermissionsMenu();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private final GUIPage PAGE = GUIPage.PERMISSIONS;
|
||||
|
||||
private Inventory menu;
|
||||
private Player p;
|
||||
private SudoSign sign;
|
||||
private SignEditor editor;
|
||||
private SudoUser su;
|
||||
|
||||
public PermissionsMenu(SudoUser su, Player p, SudoSign sign, SignEditor editor) {
|
||||
this.su = su;
|
||||
this.sign = sign;
|
||||
this.editor = editor;
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public void goToPermissionsMenu() {
|
||||
createPermissionsMenu();
|
||||
p.openInventory(menu);
|
||||
editor.setCurrentPage(PAGE);
|
||||
}
|
||||
|
||||
private void createPermissionsMenu() {
|
||||
|
||||
menu = Bukkit.createInventory(p, 45, "Permissions: " + sign.getName());
|
||||
for (int i = 0; i < menu.getSize(); i++) {
|
||||
menu.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack barrier = new ItemStack(Material.BARRIER);
|
||||
ItemMeta barrierMeta = barrier.getItemMeta();
|
||||
barrierMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Permissions");
|
||||
barrier.setItemMeta(barrierMeta);
|
||||
|
||||
if (p.hasPermission(Permissions.ADD_PERMISSION)) {
|
||||
ItemStack bookQuill = new ItemStack(Material.WRITABLE_BOOK);
|
||||
ItemMeta bqMeta = bookQuill.getItemMeta();
|
||||
bqMeta.setDisplayName("" + ChatColor.RESET + ChatColor.GREEN + "Add new permission");
|
||||
bookQuill.setItemMeta(bqMeta);
|
||||
menu.setItem(40, bookQuill);
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
NamespacedKey key = new NamespacedKey(SudoSigns.sudoSignsPlugin, "permission");
|
||||
|
||||
int i = 1;
|
||||
for (String perm : sign.getPermissions()) {
|
||||
if (i > 35) break;
|
||||
ItemStack book = new ItemStack(Material.BOOK);
|
||||
ItemMeta bookMeta = book.getItemMeta();
|
||||
bookMeta.setDisplayName("" + ChatColor.LIGHT_PURPLE + ChatColor.BOLD + "Permission");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.RESET + ChatColor.GOLD + perm);
|
||||
if (p.hasPermission(Permissions.DELETE_PERMISSION)) {
|
||||
lore.add("");
|
||||
lore.add("");
|
||||
lore.add("" + ChatColor.RED + ChatColor.BOLD + "Click to delete!");
|
||||
}
|
||||
bookMeta.getPersistentDataContainer().set(key, PersistentDataType.STRING, perm);
|
||||
bookMeta.setLore(lore);
|
||||
book.setItemMeta(bookMeta);
|
||||
if (i == 9 || i == 18 || i == 27) i++;
|
||||
menu.setItem(i, book);
|
||||
i++;
|
||||
}
|
||||
|
||||
menu.setItem(0, barrier);
|
||||
menu.setItem(9, barrier);
|
||||
menu.setItem(18, barrier);
|
||||
menu.setItem(27, barrier);
|
||||
menu.setItem(36, arrow);
|
||||
}
|
||||
|
||||
|
||||
public void preparePermission() {
|
||||
Inventory choiceInv = Bukkit.createInventory(p, 45, "Default or Custom?");
|
||||
for (int i = 0; i < choiceInv.getSize(); i++) {
|
||||
choiceInv.setItem(i, new ItemStack(Material.GRAY_STAINED_GLASS_PANE));
|
||||
}
|
||||
ItemStack arrow = new ItemStack(Material.ARROW);
|
||||
ItemMeta arrowMeta = arrow.getItemMeta();
|
||||
arrowMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "BACK");
|
||||
arrow.setItemMeta(arrowMeta);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
ItemMeta headMeta = head.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.GOLD + "sudosigns.sign." + sign.getName());
|
||||
headMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Default Permission");
|
||||
headMeta.setLore(lore);
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
ItemStack cmdBlock = new ItemStack(Material.COMMAND_BLOCK);
|
||||
ItemMeta cmdBlockMeta = cmdBlock.getItemMeta();
|
||||
cmdBlockMeta.setDisplayName("" + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "Custom Permission");
|
||||
cmdBlock.setItemMeta(cmdBlockMeta);
|
||||
|
||||
choiceInv.setItem(21, head);
|
||||
choiceInv.setItem(23, cmdBlock);
|
||||
choiceInv.setItem(36, arrow);
|
||||
|
||||
editor.setCurrentPage(GUIPage.CHOOSE_PERMISSION);
|
||||
p.openInventory(choiceInv);
|
||||
}
|
||||
|
||||
public void addPermission(boolean provided, String perm) {
|
||||
if (provided) {
|
||||
if (perm == null) {
|
||||
sign.addPermission("sudosigns.sign." + sign.getName());
|
||||
SudoSigns.config.addPermission(sign, "sudosigns.sign." + sign.getName());
|
||||
goToPermissionsMenu();
|
||||
} else {
|
||||
SudoSigns.config.addPermission(sign, perm);
|
||||
sign.addPermission(perm);
|
||||
}
|
||||
} else {
|
||||
p.closeInventory();
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter in chat the permission which the player must have to run this sign or type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.PERMISSION);
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePermission(String perm) {
|
||||
sign.removePermission(perm);
|
||||
SudoSigns.config.deletePermission(sign, perm);
|
||||
goToPermissionsMenu();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,217 +1,153 @@
|
||||
package dev.mylesmor.sudosigns.menus;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.PlayerInput;
|
||||
import dev.mylesmor.sudosigns.data.SignCommand;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import dev.mylesmor.sudosigns.data.SudoUser;
|
||||
import dev.mylesmor.sudosigns.util.Permissions;
|
||||
import dev.mylesmor.sudosigns.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SignEditor {
|
||||
|
||||
private Player p;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private MainMenu mainMenu;
|
||||
private PermissionsMenu permMenu;
|
||||
private CommandsMenu commandsMenu;
|
||||
private CommandOptionsMenu commandOptionsMenu;
|
||||
private MessageOptionsMenu messageOptionsMenu;
|
||||
private MessagesMenu messagesMenu;
|
||||
private GUIPage currentPage;
|
||||
|
||||
public SignEditor(Player p, SudoSign s, SudoUser su) {
|
||||
|
||||
this.su = su;
|
||||
this.p = p;
|
||||
this.sign = s;
|
||||
|
||||
goToMain();
|
||||
|
||||
}
|
||||
|
||||
public GUIPage getCurrentPage() {
|
||||
|
||||
return currentPage;
|
||||
|
||||
}
|
||||
|
||||
public void setCurrentPage(GUIPage page) {
|
||||
|
||||
currentPage = page;
|
||||
|
||||
}
|
||||
|
||||
public void goToMain() {
|
||||
|
||||
if (mainMenu == null) {
|
||||
|
||||
mainMenu = new MainMenu(p, sign, this);
|
||||
|
||||
}
|
||||
|
||||
setCurrentPage(GUIPage.MAIN);
|
||||
mainMenu.goToMainMenu();
|
||||
|
||||
}
|
||||
|
||||
public void goToPermissions() {
|
||||
|
||||
if (permMenu == null) {
|
||||
|
||||
permMenu = new PermissionsMenu(su, p, sign, this);
|
||||
|
||||
}
|
||||
|
||||
setCurrentPage(GUIPage.PERMISSIONS);
|
||||
permMenu.goToPermissionsMenu();
|
||||
|
||||
}
|
||||
|
||||
public void goToCommands() {
|
||||
|
||||
if (commandsMenu == null) {
|
||||
|
||||
commandsMenu = new CommandsMenu(su, p, sign, this);
|
||||
|
||||
}
|
||||
|
||||
setCurrentPage(GUIPage.COMMANDS);
|
||||
commandsMenu.goToCommandsMenu();
|
||||
|
||||
}
|
||||
|
||||
public void goToMessages() {
|
||||
|
||||
if (messagesMenu == null) {
|
||||
|
||||
messagesMenu = new MessagesMenu(su, p, sign, this);
|
||||
|
||||
}
|
||||
|
||||
setCurrentPage(GUIPage.MESSAGES);
|
||||
messagesMenu.goToMessagesMenu();
|
||||
|
||||
}
|
||||
|
||||
public void goToCommandOptionsMenu(ItemStack item) {
|
||||
|
||||
commandOptionsMenu = new CommandOptionsMenu(su, p, sign, item, this);
|
||||
|
||||
setCurrentPage(GUIPage.COMMAND_OPTIONS);
|
||||
commandOptionsMenu.goToCommandOptionsMenu();
|
||||
|
||||
}
|
||||
|
||||
public void goToMessageOptionsMenu(ItemStack item) {
|
||||
|
||||
messageOptionsMenu = new MessageOptionsMenu(su, p, sign, item, this);
|
||||
|
||||
setCurrentPage(GUIPage.MESSAGE_OPTIONS);
|
||||
messageOptionsMenu.goToMessageOptionsMenu();
|
||||
|
||||
}
|
||||
|
||||
public MainMenu getMainMenu() {
|
||||
|
||||
return mainMenu;
|
||||
|
||||
}
|
||||
|
||||
public PermissionsMenu getPermMenu() {
|
||||
|
||||
return permMenu;
|
||||
|
||||
}
|
||||
|
||||
public CommandsMenu getCommandsMenu() {
|
||||
|
||||
return commandsMenu;
|
||||
|
||||
}
|
||||
|
||||
public CommandOptionsMenu getCommandOptionsMenu() {
|
||||
|
||||
return commandOptionsMenu;
|
||||
|
||||
}
|
||||
|
||||
public MessagesMenu getMessagesMenu() {
|
||||
|
||||
return messagesMenu;
|
||||
|
||||
}
|
||||
|
||||
public MessageOptionsMenu getMessageOptionsMenu() {
|
||||
|
||||
return messageOptionsMenu;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void endEditor() {
|
||||
|
||||
Util.sudoSignsMessage(p, "&aChanges saved to sign &e%NAME%&a.", sign.getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void editSignNumber() {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please enter the line you would like to edit (1-4) or type &cCANCEL&6!");
|
||||
su.addTextInput(PlayerInput.EDIT_TEXT_NUMBER);
|
||||
p.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
public void prepareRename() {
|
||||
|
||||
Util.sudoSignsMessage(p, "&6Please enter the new name for the sign in chat or type &cCANCEL&6!");
|
||||
su.addTextInput(PlayerInput.RENAME);
|
||||
p.closeInventory();
|
||||
|
||||
}
|
||||
|
||||
public void renameSign(String s) {
|
||||
|
||||
if (SudoSigns.signs.containsKey(s)) {
|
||||
|
||||
Util.sudoSignsMessage(p, "&cERROR: A sign with the name &e%NAME% &calready exists! &6Cancelling...", s);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
sign.setName(s);
|
||||
|
||||
Map.Entry<String, SudoSign> found = null;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
|
||||
if (entry.getValue().equals(sign)) {
|
||||
|
||||
found = entry;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (found != null) {
|
||||
|
||||
SudoSigns.signs.remove(found.getKey());
|
||||
SudoSigns.signs.put(s, sign);
|
||||
|
||||
Util.sudoSignsMessage(p, "&aSign successfully renamed to &e%NAME%&a.", s);
|
||||
|
||||
SudoSigns.config.saveSign(found.getValue(), true, p);
|
||||
SudoSigns.config.deleteSign(found.getKey());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private Player p;
|
||||
private SudoUser su;
|
||||
private SudoSign sign;
|
||||
private MainMenu mainMenu;
|
||||
private PermissionsMenu permMenu;
|
||||
private CommandsMenu commandsMenu;
|
||||
private CommandOptionsMenu commandOptionsMenu;
|
||||
private MessageOptionsMenu messageOptionsMenu;
|
||||
private MessagesMenu messagesMenu;
|
||||
private GUIPage currentPage;
|
||||
private boolean edited = false;
|
||||
|
||||
public SignEditor(Player p, SudoSign s, SudoUser su) {
|
||||
this.su = su;
|
||||
this.p = p;
|
||||
this.sign = s;
|
||||
goToMain();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GUIPage getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(GUIPage page) {
|
||||
currentPage = page;
|
||||
}
|
||||
|
||||
public void goToMain() {
|
||||
if (mainMenu == null) mainMenu = new MainMenu(p, sign, this);
|
||||
setCurrentPage(GUIPage.MAIN);
|
||||
mainMenu.goToMainMenu();
|
||||
}
|
||||
|
||||
public void goToPermissions() {
|
||||
if (permMenu == null) permMenu = new PermissionsMenu(su, p, sign, this);
|
||||
setCurrentPage(GUIPage.PERMISSIONS);
|
||||
permMenu.goToPermissionsMenu();
|
||||
}
|
||||
|
||||
public void goToCommands() {
|
||||
if (commandsMenu == null) commandsMenu = new CommandsMenu(su, p, sign, this);
|
||||
setCurrentPage(GUIPage.COMMANDS);
|
||||
commandsMenu.goToCommandsMenu();
|
||||
}
|
||||
|
||||
public void goToMessages() {
|
||||
if (messagesMenu == null) messagesMenu = new MessagesMenu(su, p, sign, this);
|
||||
setCurrentPage(GUIPage.MESSAGES);
|
||||
messagesMenu.goToMessagesMenu();
|
||||
}
|
||||
|
||||
public void goToCommandOptionsMenu(ItemStack item) {
|
||||
commandOptionsMenu = new CommandOptionsMenu(su, p, sign, item, this);
|
||||
setCurrentPage(GUIPage.COMMAND_OPTIONS);
|
||||
commandOptionsMenu.goToCommandOptionsMenu();
|
||||
}
|
||||
|
||||
public void goToMessageOptionsMenu(ItemStack item) {
|
||||
messageOptionsMenu = new MessageOptionsMenu(su, p, sign, item, this);
|
||||
setCurrentPage(GUIPage.MESSAGE_OPTIONS);
|
||||
messageOptionsMenu.goToMessageOptionsMenu();
|
||||
}
|
||||
|
||||
public MainMenu getMainMenu() {
|
||||
return mainMenu;
|
||||
}
|
||||
|
||||
public PermissionsMenu getPermMenu() {
|
||||
return permMenu;
|
||||
}
|
||||
|
||||
public CommandsMenu getCommandsMenu() {
|
||||
return commandsMenu;
|
||||
}
|
||||
|
||||
public CommandOptionsMenu getCommandOptionsMenu() {
|
||||
return commandOptionsMenu;
|
||||
}
|
||||
|
||||
public MessagesMenu getMessagesMenu() {
|
||||
return messagesMenu;
|
||||
}
|
||||
|
||||
public MessageOptionsMenu getMessageOptionsMenu() {
|
||||
return messageOptionsMenu;
|
||||
}
|
||||
|
||||
|
||||
public void endEditor() {
|
||||
//TODO: Find out whether they actually edited the sign
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Changes saved to sign %NAME%.", sign.getName());
|
||||
}
|
||||
|
||||
|
||||
public void editSignNumber() {
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the line you'd like to edit (1-4) or type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.EDIT_TEXT_NUMBER);
|
||||
p.closeInventory();
|
||||
}
|
||||
|
||||
public void prepareRename() {
|
||||
p.sendMessage(Util.prefix + ChatColor.GRAY + " Please enter the new name for the sign in chat or type " + ChatColor.RED + "CANCEL" + ChatColor.GRAY + ".");
|
||||
su.addTextInput(PlayerInput.RENAME);
|
||||
p.closeInventory();
|
||||
}
|
||||
|
||||
public void renameSign(String s) {
|
||||
if (SudoSigns.signs.containsKey(s)) {
|
||||
Util.sudoSignsMessage(p, ChatColor.RED,"A sign with name %NAME% already exists! Cancelling...", s);
|
||||
} else {
|
||||
sign.setName(s);
|
||||
Map.Entry<String, SudoSign> found = null;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
if (entry.getValue().equals(sign)) {
|
||||
found = entry;
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
SudoSigns.signs.remove(found.getKey());
|
||||
SudoSigns.signs.put(s, sign);
|
||||
Util.sudoSignsMessage(p, ChatColor.GRAY, "Sign successfully renamed to %NAME%.", s);
|
||||
SudoSigns.config.saveSign(found.getValue(), true, p);
|
||||
SudoSigns.config.deleteSign(found.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,35 +6,35 @@ package dev.mylesmor.sudosigns.util;
|
||||
* @author https://mylesmor.dev
|
||||
*/
|
||||
public final class Permissions {
|
||||
public static final String CREATE = "sudosigns.create";
|
||||
public static final String EDIT = "sudosigns.edit";
|
||||
public static final String DELETE = "sudosigns.delete";
|
||||
public static final String RUN = "sudosigns.run";
|
||||
public static final String TP = "sudosigns.tp";
|
||||
public static final String COPY = "sudosigns.copy";
|
||||
public static final String RELOAD = "sudosigns.reload";
|
||||
public static final String VIEW = "sudosigns.view";
|
||||
public static final String HELP = "sudosigns.help";
|
||||
public static final String SELECT = "sudosigns.select";
|
||||
public static final String NEAR = "sudosigns.near";
|
||||
public static final String LIST = "sudosigns.list";
|
||||
public static final String RENAME = "sudosigns.rename";
|
||||
public static final String PURGE = "sudosigns.purge";
|
||||
public static final String FIX = "sudosigns.fix";
|
||||
public static final String VIEW_COMMAND = "sudosigns.command.view";
|
||||
public static final String ADD_COMMAND = "sudosigns.command.add";
|
||||
public static final String DELETE_COMMAND = "sudosigns.command.delete";
|
||||
public static final String CONSOLE_COMMAND = "sudosigns.command.console";
|
||||
public static final String COMMAND_OPTIONS = "sudosigns.command.options";
|
||||
public static final String VIEW_PERMISSION = "sudosigns.permission.view";
|
||||
public static final String ADD_PERMISSION = "sudosigns.permission.add";
|
||||
public static final String DELETE_PERMISSION = "sudosigns.permission.delete";
|
||||
public static final String VIEW_MESSAGE = "sudosigns.message.view";
|
||||
public static final String ADD_MESSAGE = "sudosigns.message.add";
|
||||
public static final String DELETE_MESSAGE = "sudosigns.message.delete";
|
||||
public static final String MESSAGE_OPTIONS = "sudosigns.message.options";
|
||||
public static final String EDIT_TEXT = "sudosigns.text.edit";
|
||||
public static final String VIEW_PRICE = "sudosigns.price.view";
|
||||
public static final String SET_PRICE = "sudosigns.price.set";
|
||||
public static final String CREATE = "sudosigns.create";
|
||||
public static final String EDIT = "sudosigns.edit";
|
||||
public static final String DELETE = "sudosigns.delete";
|
||||
public static final String RUN = "sudosigns.run";
|
||||
public static final String TP = "sudosigns.tp";
|
||||
public static final String COPY = "sudosigns.copy";
|
||||
public static final String RELOAD = "sudosigns.reload";
|
||||
public static final String VIEW = "sudosigns.view";
|
||||
public static final String HELP = "sudosigns.help";
|
||||
public static final String SELECT = "sudosigns.select";
|
||||
public static final String NEAR = "sudosigns.near";
|
||||
public static final String LIST = "sudosigns.list";
|
||||
public static final String RENAME = "sudosigns.rename";
|
||||
public static final String PURGE = "sudosigns.purge";
|
||||
public static final String FIX = "sudosigns.fix";
|
||||
public static final String VIEW_COMMAND = "sudosigns.command.view";
|
||||
public static final String ADD_COMMAND = "sudosigns.command.add";
|
||||
public static final String DELETE_COMMAND = "sudosigns.command.delete";
|
||||
public static final String CONSOLE_COMMAND = "sudosigns.command.console";
|
||||
public static final String COMMAND_OPTIONS = "sudosigns.command.options";
|
||||
public static final String VIEW_PERMISSION = "sudosigns.permission.view";
|
||||
public static final String ADD_PERMISSION = "sudosigns.permission.add";
|
||||
public static final String DELETE_PERMISSION = "sudosigns.permission.delete";
|
||||
public static final String VIEW_MESSAGE = "sudosigns.message.view";
|
||||
public static final String ADD_MESSAGE = "sudosigns.message.add";
|
||||
public static final String DELETE_MESSAGE = "sudosigns.message.delete";
|
||||
public static final String MESSAGE_OPTIONS = "sudosigns.message.options";
|
||||
public static final String EDIT_TEXT = "sudosigns.text.edit";
|
||||
public static final String VIEW_PRICE = "sudosigns.price.view";
|
||||
public static final String SET_PRICE = "sudosigns.price.set";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dev.mylesmor.sudosigns.util;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
private JavaPlugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
public UpdateChecker(JavaPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
public void getVersion(final Consumer<String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
|
||||
if (scanner.hasNext()) {
|
||||
consumer.accept(scanner.next());
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
this.plugin.getLogger().info("Unable to look for updates: " + exception.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,236 +1,68 @@
|
||||
package dev.mylesmor.sudosigns.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.mylesmor.sudosigns.SudoSigns;
|
||||
import dev.mylesmor.sudosigns.data.SudoSign;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class Util {
|
||||
|
||||
// Create a colored chat prefix.
|
||||
public static String chatPrefix = "&8[&2SudoSigns&4-OG&8] ";
|
||||
|
||||
// Send the sign selection menu according to permissions.
|
||||
public static void sendSelectMenus(Player p, String name) {
|
||||
|
||||
selectMenuParser(p, chatPrefix, "&e-----", name, "", "&2True&4OG&a's Fork of &BSudoSigns&a.");
|
||||
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
|
||||
selectMenuParser(p, "&9&l[V]", "&9View Details", name, ("/ss view " + name), ("&9View &6" + name + "\'s &9details."));
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
|
||||
selectMenuParser(p, "&2&l[R]", "&2Run Commands", name, ("/ss run " + name), ("&2Run &6" + name + "\'s &2commands."));
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
|
||||
selectMenuParser(p, "&3&l[TP]", "&3Teleport To", name, ("/ss tp " + name), ("&3Teleport to &6" + name + "&3."));
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
|
||||
selectMenuParser(p, "&d&l[EDIT]", "&dEdit Details", name, ("/ss edit " + name), ("&dEdit &6" + name + "\'s &dcolor."));
|
||||
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
|
||||
selectMenuParser(p, "&c&l[DEL]", "&cDelete SudoSign", name, ("/ss confirmdelete " + name), ("&cDelete &6" + name + "&c."));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Sends customizable clickable message dialogues to the player.
|
||||
public static void selectMenuParser(Player p, String prefix, String prompt, String name, String command, String hoverMessage) {
|
||||
|
||||
// The clickable part of the confirmation message.
|
||||
TextComponent button = legacySerializerAnyCase(prefix);
|
||||
|
||||
// Add a hover dialogue to the clickable confirmation text.
|
||||
button.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, legacySerializerAnyCase(hoverMessage)));
|
||||
|
||||
// Make sure that a command is intended to be run.
|
||||
if(! command.equals("")) {
|
||||
// Create a click event on the delete confirmation chat text.
|
||||
button = button.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, (command)));
|
||||
}
|
||||
|
||||
// Send the prompt and clickable confirmation button to the player.
|
||||
sudoSignsPrompt(p, (prompt + " "), button);
|
||||
|
||||
}
|
||||
|
||||
public static TextComponent legacySerializerAnyCase(String subject) {
|
||||
|
||||
int count = 0;
|
||||
// Count the number of '&' characters to determine the size of the array
|
||||
for (char c : subject.toCharArray()) {
|
||||
|
||||
if (c == '&') {
|
||||
|
||||
count++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create an array to store the positions of '&' characters
|
||||
int[] positions = new int[count];
|
||||
int index = 0;
|
||||
// Find the positions of '&' characters and store in the array
|
||||
for (int i = 0; i < subject.length(); i++) {
|
||||
|
||||
if (subject.charAt(i) == '&') {
|
||||
|
||||
if (isUpperBukkitCode(subject.charAt(i + 1))) {
|
||||
|
||||
subject = replaceCharAtIndex(subject, (i + 1), Character.toLowerCase(subject.charAt(i + 1)));
|
||||
|
||||
}
|
||||
|
||||
positions[index++] = i;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(subject);
|
||||
|
||||
}
|
||||
|
||||
private static boolean isUpperBukkitCode(char input) {
|
||||
|
||||
char[] bukkitColorCodes = {'A', 'B', 'C', 'D', 'E', 'F', 'K', 'L', 'M', 'N', 'O', 'R'};
|
||||
boolean match = false;
|
||||
|
||||
// Loop through each character in the array.
|
||||
for (char c : bukkitColorCodes) {
|
||||
// Check if the current character in the array is equal to the input character.
|
||||
if (c == input) {
|
||||
|
||||
match = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return match;
|
||||
|
||||
}
|
||||
|
||||
private static String replaceCharAtIndex(String original, int index, char newChar) {
|
||||
|
||||
// Check if the index is valid
|
||||
if (index >= 0 && index < original.length()) {
|
||||
|
||||
// Create a new string with the replaced character
|
||||
return original.substring(0, index) + newChar + original.substring(index + 1);
|
||||
|
||||
}
|
||||
|
||||
// If the index is invalid, return the original string
|
||||
return original;
|
||||
|
||||
}
|
||||
|
||||
// Sends a formatted message to the player.
|
||||
public static void sudoSignsMessage(Player p, String message) {
|
||||
|
||||
p.sendMessage(legacySerializerAnyCase(chatPrefix + message));
|
||||
|
||||
}
|
||||
|
||||
// Sends a formatted message to the player (including name replacement).
|
||||
public static void sudoSignsMessage(Player p, String message, String name) {
|
||||
|
||||
if (message.contains("%NAME%")) {
|
||||
|
||||
message = message.replace("%NAME%", "&6" + name);
|
||||
|
||||
}
|
||||
|
||||
sudoSignsMessage(p, message);
|
||||
|
||||
}
|
||||
|
||||
// Sends a formatted message without a prefix to the player.
|
||||
public static void sudoSignsMessageNoPrefix(Player p, String message) {
|
||||
|
||||
p.sendMessage(legacySerializerAnyCase(message));
|
||||
|
||||
}
|
||||
|
||||
// Sends a standard error message to the player.
|
||||
public static void sudoSignsErrorMessage(Player p) {
|
||||
|
||||
sudoSignsMessage(p, "&c&lERROR: &cYou do not have permission to do that!");
|
||||
|
||||
}
|
||||
|
||||
// Sends a formatted prompt and clickable chat button to the player.
|
||||
public static void sudoSignsPrompt(Player player, String prompt, TextComponent button) {
|
||||
|
||||
player.sendMessage(legacySerializerAnyCase(prompt).append(button));
|
||||
|
||||
}
|
||||
|
||||
public static boolean checkName(String name) {
|
||||
|
||||
String regex = "^[A-z0-9]+$";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(name);
|
||||
|
||||
return matcher.matches();
|
||||
|
||||
}
|
||||
|
||||
public static String findSign(Sign s) {
|
||||
|
||||
String found = null;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
|
||||
Sign sign = entry.getValue().getSign();
|
||||
if (sign != null && sign.equals(s)) {
|
||||
|
||||
found = entry.getKey();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return found;
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<TextComponent> convertToTextComponents(List<String> stringList) {
|
||||
ArrayList<TextComponent> textComponents = new ArrayList<TextComponent>(18);
|
||||
|
||||
for (String str : stringList) {
|
||||
|
||||
TextComponent textComponent = legacySerializerAnyCase(str);
|
||||
textComponents.add(textComponent);
|
||||
|
||||
}
|
||||
|
||||
return textComponents;
|
||||
}
|
||||
|
||||
}
|
||||
public static final String prefix = ChatColor.YELLOW + "[SUDOSIGNS]";
|
||||
|
||||
public static String getSelectString(Player p, String name) {
|
||||
String message = "[\"\",{\"text\":\"[SUDOSIGNS] \",\"color\":\"yellow\"},{\"text\":\"Sign: \",\"color\":\"gray\"},{\"text\":\"" + name + " \",\"bold\":true,\"color\":\"gold\"}]";
|
||||
if (p.hasPermission(Permissions.VIEW)) {
|
||||
message = message.substring(0, message.length() - 1);
|
||||
message += ",{\"text\":\"[V] \",\"bold\":true,\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss view " + name + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"View " + name + "'s details\",\"color\":\"blue\"}]}}]";
|
||||
}
|
||||
if (p.hasPermission(Permissions.RUN)) {
|
||||
message = message.substring(0, message.length() - 1);
|
||||
message += ",{\"text\":\"[R] \",\"bold\":true,\"color\":\"green\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss run " + name + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Run " + name + "'s commands\",\"color\":\"green\"}]}}]";
|
||||
}
|
||||
if (p.hasPermission(Permissions.TP)) {
|
||||
message = message.substring(0, message.length() - 1);
|
||||
message += ",{\"text\":\"[TP] \",\"bold\":true,\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss tp " + name + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Teleport to " + name + "\",\"color\":\"aqua\"}]}}]";
|
||||
|
||||
}
|
||||
if (p.hasPermission(Permissions.EDIT)) {
|
||||
message = message.substring(0, message.length() - 1);
|
||||
message += ",{\"text\":\"[EDIT] \",\"bold\":true,\"color\":\"light_purple\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss edit " + name + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Edit "+ name +"\",\"color\":\"light_purple\"}]}}]";
|
||||
}
|
||||
|
||||
if (p.hasPermission(Permissions.DELETE)) {
|
||||
message = message.substring(0, message.length() - 1);
|
||||
message += ",{\"text\":\"[DEL]\",\"bold\":true,\"color\":\"red\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/ss confirmdelete " + name + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Delete " + name + "\",\"color\":\"red\"}]}}]";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public static void sudoSignsMessage(Player p, ChatColor color, String message, String name) {
|
||||
if (message.contains("%NAME%")) {
|
||||
message = message.replace("%NAME%", ChatColor.GOLD + name + color);
|
||||
}
|
||||
p.sendMessage(prefix + color + " " + message);
|
||||
}
|
||||
|
||||
public static boolean checkName(String name) {
|
||||
String regex = "^[A-z0-9]+$";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(name);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
public static String findSign(Sign s) {
|
||||
String found = null;
|
||||
for (Map.Entry<String, SudoSign> entry : SudoSigns.signs.entrySet()) {
|
||||
Sign sign = entry.getValue().getSign();
|
||||
if (sign != null && sign.equals(s)) {
|
||||
found = entry.getKey();
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
name: SudoSigns-OG
|
||||
version: '${version}'
|
||||
name: SudoSigns
|
||||
version: 1.1.1
|
||||
author: MylesMor
|
||||
main: dev.mylesmor.sudosigns.SudoSigns
|
||||
softdepend: [Multiverse-Core, Vault]
|
||||
api-version: '${apiVersion}'
|
||||
softdepend: [Multiverse-Core, Vault, PlaceholderAPI]
|
||||
api-version: 1.13
|
||||
commands:
|
||||
sudosigns:
|
||||
description: Opens the SudoSigns help menu.
|
||||
|
||||
Reference in new issue
Block a user