├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── settings.gradle └── src └── main ├── java └── de │ └── littleprogrammer │ └── guiapi │ ├── GuiApi.java │ ├── commands │ └── SpawnCommand.java │ ├── components │ ├── Button.java │ ├── Component.java │ └── Text.java │ ├── customeEvents │ ├── HoverButtonEvent.java │ └── UnHoverButtonEvent.java │ ├── enums │ └── ServerVersion.java │ ├── guis │ ├── Gui.java │ ├── PagedGui.java │ └── SimpleGui.java │ ├── listeners │ ├── GuiEvents.java │ └── MoveListener.java │ └── utils │ ├── Calculations.java │ └── TeleportInterpolator.java └── resources └── plugin.yml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/ 3 | 4 | *.iml 5 | *.ipr 6 | *.iws 7 | 8 | # IntelliJ 9 | out/ 10 | # mpeltonen/sbt-idea plugin 11 | .idea_modules/ 12 | 13 | # JIRA plugin 14 | atlassian-ide-plugin.xml 15 | 16 | # Compiled class file 17 | *.class 18 | 19 | # Log file 20 | *.log 21 | 22 | # BlueJ files 23 | *.ctxt 24 | 25 | # Package Files # 26 | *.jar 27 | *.war 28 | *.nar 29 | *.ear 30 | *.zip 31 | *.tar.gz 32 | *.rar 33 | 34 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 35 | hs_err_pid* 36 | 37 | *~ 38 | 39 | # temporary files which can be created if a process still has a handle open of a deleted file 40 | .fuse_hidden* 41 | 42 | # KDE directory preferences 43 | .directory 44 | 45 | # Linux trash folder which might appear on any partition or disk 46 | .Trash-* 47 | 48 | # .nfs files are created when an open file is removed but is still being accessed 49 | .nfs* 50 | 51 | # General 52 | .DS_Store 53 | .AppleDouble 54 | .LSOverride 55 | 56 | # Icon must end with two \r 57 | Icon 58 | 59 | # Thumbnails 60 | ._* 61 | 62 | # Files that might appear in the root of a volume 63 | .DocumentRevisions-V100 64 | .fseventsd 65 | .Spotlight-V100 66 | .TemporaryItems 67 | .Trashes 68 | .VolumeIcon.icns 69 | .com.apple.timemachine.donotpresent 70 | 71 | # Directories potentially created on remote AFP share 72 | .AppleDB 73 | .AppleDesktop 74 | Network Trash Folder 75 | Temporary Items 76 | .apdisk 77 | 78 | # Windows thumbnail cache files 79 | Thumbs.db 80 | Thumbs.db:encryptable 81 | ehthumbs.db 82 | ehthumbs_vista.db 83 | 84 | # Dump file 85 | *.stackdump 86 | 87 | # Folder config file 88 | [Dd]esktop.ini 89 | 90 | # Recycle Bin used on file shares 91 | $RECYCLE.BIN/ 92 | 93 | # Windows Installer files 94 | *.cab 95 | *.msi 96 | *.msix 97 | *.msm 98 | *.msp 99 | 100 | # Windows shortcuts 101 | *.lnk 102 | 103 | build/ 104 | .gradle 105 | 106 | # Ignore Gradle GUI config 107 | gradle-app.setting 108 | 109 | # Cache of project 110 | .gradletasknamecache 111 | 112 | **/build/ 113 | 114 | # Common working directory 115 | run/ 116 | 117 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 118 | !gradle-wrapper.jar 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://jitpack.io/v/LitleProgrammer/3d-gui-api.svg)](https://jitpack.io/#LitleProgrammer/3d-gui-api) 2 | --- 3 | 4 | # 3D Gui API 5 | I made this API, because I wanted to step up the 2d GUI theme of minecraft. 6 | This API enables plugin developers to easily build 3D guis into their plugins. At the moment it only features a simple GUI with up to 3 buttons and some text. 7 | 8 | 9 | 10 | https://github.com/LitleProgrammer/3d-gui-api/assets/87831625/9307bb33-2c8a-4377-9c42-c3facd5ea5b2 11 | 12 | 13 | 14 | https://github.com/LitleProgrammer/3d-gui-api/assets/87831625/02595d41-8308-46b3-adaf-adcb03785abb 15 | 16 | 17 | 18 | 19 | --- 20 | 21 | ### Features 22 | * Creating a 3D GUI that follows the player arround the world and is always in front of the player 23 | * Click action on button click 24 | * Changable text or image on hover 25 | * Custom event on hover and unHover 26 | 27 | 28 | --- 29 | For any questions take a look at the wiki or ask me directly on my disord server: https://discord.gg/YjmAFKTUHK 30 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'maven-publish' 4 | } 5 | 6 | group = 'de.littleprogrammer' 7 | version = '0.0.1' 8 | 9 | repositories { 10 | mavenCentral() 11 | maven { 12 | name = "spigotmc-repo" 13 | url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" 14 | } 15 | maven { 16 | name = "sonatype" 17 | url = "https://oss.sonatype.org/content/groups/public/" 18 | } 19 | } 20 | 21 | dependencies { 22 | compileOnly "org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT" 23 | } 24 | 25 | def targetJavaVersion = 17 26 | java { 27 | def javaVersion = JavaVersion.toVersion(targetJavaVersion) 28 | sourceCompatibility = javaVersion 29 | targetCompatibility = javaVersion 30 | if (JavaVersion.current() < javaVersion) { 31 | toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) 32 | } 33 | } 34 | 35 | publishing { 36 | publications { 37 | maven(MavenPublication) { 38 | from components.java 39 | } 40 | } 41 | } 42 | 43 | wrapper { 44 | gradleVersion = "7.3.3" 45 | distributionType = Wrapper.DistributionType.ALL 46 | } 47 | 48 | tasks.withType(JavaCompile).configureEach { 49 | options.encoding = 'UTF-8' 50 | 51 | if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { 52 | options.release.set(targetJavaVersion) 53 | } 54 | } 55 | 56 | processResources { 57 | def props = [version: version] 58 | inputs.properties props 59 | filteringCharset 'UTF-8' 60 | filesMatching('plugin.yml') { 61 | expand props 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LitleProgrammer/3d-gui-api/ff36b11cd8ee52398f702220da4d14c359aec339/gradle.properties -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LitleProgrammer/3d-gui-api/ff36b11cd8ee52398f702220da4d14c359aec339/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk17 3 | before_install: 4 | - sdk install java 17.0.1-open 5 | - sdk use java 17.0.1-open 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'guiapi' 2 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/GuiApi.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi; 2 | 3 | import de.littleprogrammer.guiapi.commands.SpawnCommand; 4 | import de.littleprogrammer.guiapi.enums.ServerVersion; 5 | import de.littleprogrammer.guiapi.guis.Gui; 6 | import de.littleprogrammer.guiapi.guis.SimpleGui; 7 | import de.littleprogrammer.guiapi.listeners.GuiEvents; 8 | import de.littleprogrammer.guiapi.listeners.MoveListener; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.Listener; 11 | import org.bukkit.plugin.java.JavaPlugin; 12 | import org.bukkit.scheduler.BukkitScheduler; 13 | 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | import java.util.UUID; 17 | 18 | public final class GuiApi /*extends JavaPlugin*/ { 19 | 20 | private JavaPlugin plugin; 21 | private static GuiApi instance; 22 | private ServerVersion version; 23 | private final Listener listener = new GuiEvents(); 24 | private final Listener moveListener = new MoveListener(); 25 | private Map guis = new HashMap<>(); 26 | 27 | public GuiApi(JavaPlugin plugin) { 28 | this.plugin = plugin; 29 | instance = this; 30 | } 31 | 32 | /*@Override 33 | public void onEnable() { 34 | // Plugin startup logic 35 | this.plugin = this; 36 | instance = this; 37 | 38 | init(); 39 | } 40 | 41 | @Override 42 | public void onDisable() { 43 | // Plugin shutdown logic 44 | }*/ 45 | 46 | public void init() { 47 | //This method checks the server version, to determine weather it should use the new 1.20.2 teleport interpolation or my own teleport interpolation 48 | String secIndicator = plugin.getServer().getBukkitVersion().split("\\.")[1]; 49 | String preTrdIndicator = plugin.getServer().getBukkitVersion().split("\\.")[2]; 50 | String trdIndicator = preTrdIndicator.split("-")[0]; 51 | 52 | //If version is like 1.21 it threw an error 53 | try { 54 | Integer.parseInt(secIndicator); 55 | } catch (NumberFormatException e) { 56 | secIndicator = secIndicator.split("-")[0]; 57 | } 58 | 59 | //If version is like 1.21 there is no .0 in the input string, but it needs to be for the following method 60 | try { 61 | Integer.parseInt(preTrdIndicator); 62 | } catch (NumberFormatException e) { 63 | trdIndicator = "0"; 64 | } 65 | 66 | //1.20.x 67 | if (Integer.parseInt(secIndicator) == 20) { 68 | //1.20.2 69 | if (Integer.parseInt(trdIndicator) >= 2) { 70 | version = ServerVersion.POST_1_20_2; 71 | } else { 72 | version = ServerVersion.PRE_1_20_2; 73 | } 74 | } else { 75 | if (Integer.parseInt(secIndicator) > 20) { 76 | version = ServerVersion.POST_1_20_2; 77 | } else { 78 | version = ServerVersion.PRE_1_20_2; 79 | } 80 | } 81 | 82 | //register the two listeners needed 83 | getPlugin().getServer().getPluginManager().registerEvents(this.listener, this.plugin); 84 | getPlugin().getServer().getPluginManager().registerEvents(this.moveListener, this.plugin); 85 | 86 | //this.getPlugin().getCommand("spawnGui").setExecutor(new SpawnCommand()); 87 | } 88 | 89 | public JavaPlugin getPlugin() {return this.plugin;} 90 | public static GuiApi getInstance() {return instance;} 91 | public ServerVersion getVersion() { 92 | return version; 93 | } 94 | public static BukkitScheduler getScheduler() { 95 | return GuiApi.getInstance().getPlugin().getServer().getScheduler(); 96 | } 97 | 98 | public Gui getGUI(UUID uuid) { 99 | return guis.get(uuid); 100 | } 101 | 102 | public Gui getGUI(Player player) { 103 | return guis.get(player.getUniqueId()); 104 | } 105 | 106 | public Map getGuis() { 107 | return guis; 108 | } 109 | 110 | public Listener getListener() { 111 | return listener; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/commands/SpawnCommand.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.commands; 2 | 3 | import de.littleprogrammer.guiapi.guis.PagedGui; 4 | import de.littleprogrammer.guiapi.guis.SimpleGui; 5 | import de.littleprogrammer.guiapi.components.Button; 6 | import de.littleprogrammer.guiapi.components.Text; 7 | import net.md_5.bungee.api.ChatColor; 8 | import org.bukkit.command.Command; 9 | import org.bukkit.command.CommandExecutor; 10 | import org.bukkit.command.CommandSender; 11 | import org.bukkit.entity.Player; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class SpawnCommand implements CommandExecutor { 17 | @Override 18 | public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { 19 | /*Button button = new Button("\uE001", "\uE002", 1) 20 | .setSize(2) 21 | .onClick(event -> { 22 | event.getPlayer().sendMessage("You clicked a button1"); 23 | }) 24 | .onHover(event -> { 25 | event.getPlayer().sendMessage("You hovered over a button"); 26 | }) 27 | .onUnHover(event -> { 28 | event.getPlayer().sendMessage("You unhovered a button"); 29 | }); 30 | 31 | Button button2 = new Button("\uE001", "\uE002", 2).onClick(event -> { 32 | event.getPlayer().sendMessage("You clicked a button2"); 33 | }); 34 | 35 | Button button3 = new Button("\uE001", "\uE002", 3).onClick(event -> { 36 | event.getPlayer().sendMessage("You clicked a button3"); 37 | }); 38 | 39 | Text text = new Text("Here you can put\n some text. This is just for\n testing purposes.\n As you can see, \nit's working quite nicely and \nlook at this cool hovering effect.", 0) 40 | .setSize(1.4f); 41 | 42 | SimpleGui gui = new SimpleGui("Some title") 43 | .addContent(text) 44 | .addButton(button) 45 | .addButton(button2) 46 | .addButton(button3); 47 | gui.open((Player) commandSender);*/ 48 | 49 | List stringList = new ArrayList<>(); 50 | stringList.add(ChatColor.GOLD.toString() + ChatColor.BOLD + "Some Heading\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 51 | stringList.add(ChatColor.GREEN.toString() + ChatColor.BOLD + "Another Heading\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 52 | stringList.add(ChatColor.RED.toString() + ChatColor.BOLD + "3rd Heading\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 53 | stringList.add(ChatColor.BLUE.toString() + ChatColor.BOLD + "Happy Happy\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 54 | stringList.add(ChatColor.YELLOW.toString() + ChatColor.BOLD + "Yellow?!\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 55 | stringList.add(ChatColor.DARK_PURPLE.toString() + ChatColor.BOLD + "6th Content\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 56 | stringList.add(ChatColor.AQUA.toString() + ChatColor.BOLD + "How many are there?\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 57 | stringList.add(ChatColor.GRAY.toString() + ChatColor.BOLD + "Still same text\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 58 | stringList.add(ChatColor.DARK_AQUA.toString() + ChatColor.BOLD + "You can stop now\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 59 | stringList.add(ChatColor.LIGHT_PURPLE.toString() + ChatColor.BOLD + "Stop...\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 60 | stringList.add(ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Stooooppp!!!\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 61 | stringList.add(ChatColor.DARK_GREEN.toString() + ChatColor.BOLD + "The end.\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam"); 62 | 63 | Button button2 = new Button("close", "CLOSE", 1).onClick(event -> { 64 | event.getPlayer().sendMessage("You clicked the close button!"); 65 | }); 66 | 67 | PagedGui pagedGui = new PagedGui("Title", 0).addButton(button2); 68 | pagedGui.setSpacing(30); 69 | pagedGui.setContentSpacing(50); 70 | pagedGui.addContent(stringList); 71 | pagedGui.open((Player) commandSender); 72 | pagedGui.setLeftButtonText("left", "lll").setRightButtonText("right", "rrr"); 73 | 74 | return false; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/components/Button.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.components; 2 | 3 | import de.littleprogrammer.guiapi.GuiApi; 4 | import de.littleprogrammer.guiapi.guis.Gui; 5 | import de.littleprogrammer.guiapi.guis.SimpleGui; 6 | import de.littleprogrammer.guiapi.customeEvents.HoverButtonEvent; 7 | import de.littleprogrammer.guiapi.customeEvents.UnHoverButtonEvent; 8 | import de.littleprogrammer.guiapi.utils.Calculations; 9 | import org.bukkit.Location; 10 | import org.bukkit.entity.*; 11 | import org.bukkit.event.player.PlayerInteractEntityEvent; 12 | import org.bukkit.util.Transformation; 13 | import org.joml.Vector3f; 14 | 15 | import javax.annotation.Nonnull; 16 | import java.util.UUID; 17 | import java.util.function.Consumer; 18 | 19 | public class Button implements Component { 20 | 21 | private String texture; 22 | private String hoverTexture; 23 | private UUID uuid; 24 | private TextDisplay textDisplay; 25 | private Location location; 26 | private Consumer clickAction; 27 | private Consumer hoverAction; 28 | private Consumer unHoverAction; 29 | private int slot; 30 | private float size = 2; 31 | private Gui gui; 32 | private boolean hover = false; 33 | 34 | public Button(String texture, String hoverTexture, int slot) { 35 | this.texture = texture; 36 | this.hoverTexture = hoverTexture; 37 | this.slot = slot; 38 | 39 | uuid = UUID.randomUUID(); 40 | } 41 | 42 | public void spawn() { 43 | textDisplay = (TextDisplay) gui.getCenterLocation().getWorld().spawnEntity(Calculations.calculateComponentLocation(gui, this, gui.getButtonAmount(), 30), EntityType.TEXT_DISPLAY); 44 | textDisplay.setCustomName(uuid.toString()); 45 | textDisplay.setCustomNameVisible(false); 46 | textDisplay.setText(texture); 47 | textDisplay.setGlowing(true); 48 | textDisplay.setBillboard(Display.Billboard.CENTER); 49 | textDisplay.setDisplayWidth(30); 50 | textDisplay.setDisplayHeight(30); 51 | textDisplay.setVisibleByDefault(false); 52 | textDisplay.setDefaultBackground(false); 53 | Transformation transformation = textDisplay.getTransformation(); 54 | transformation.getScale().set(new Vector3f(size, size, size)); 55 | textDisplay.setTransformation(transformation); 56 | } 57 | 58 | public void show(Player player) { 59 | player.showEntity(GuiApi.getInstance().getPlugin(), textDisplay); 60 | } 61 | 62 | public void hide(Player player) { 63 | player.hideEntity(GuiApi.getInstance().getPlugin(), textDisplay); 64 | } 65 | 66 | public void remove() { 67 | textDisplay.remove(); 68 | } 69 | 70 | @Nonnull 71 | public Consumer getClickAction() { 72 | if (clickAction != null) { 73 | return clickAction; 74 | } else { 75 | return (event -> {}); 76 | } 77 | } 78 | 79 | @Nonnull 80 | public Button onClick(Consumer clickAction) { 81 | this.clickAction = clickAction; 82 | return this; 83 | } 84 | 85 | public Consumer getHoverAction() { 86 | if (hoverAction != null) { 87 | return hoverAction; 88 | } else { 89 | return (event -> {}); 90 | } 91 | } 92 | 93 | public Button onHover(Consumer hoverAction) { 94 | this.hoverAction = hoverAction; 95 | return this; 96 | } 97 | 98 | public Consumer getUnHoverAction() { 99 | if (unHoverAction != null) { 100 | return unHoverAction; 101 | } else { 102 | return (event -> {}); 103 | } 104 | } 105 | 106 | public Button onUnHover(Consumer unHoverAction) { 107 | this.unHoverAction = unHoverAction; 108 | return this; 109 | } 110 | 111 | public Entity getEntity() { 112 | return textDisplay; 113 | } 114 | 115 | public TextDisplay getDisplay() { 116 | return textDisplay; 117 | } 118 | 119 | public UUID getUniqueId() { 120 | return uuid; 121 | } 122 | 123 | public Gui getGui() { 124 | return gui; 125 | } 126 | 127 | public String getText() { 128 | return texture; 129 | } 130 | 131 | public String getHoverText() { 132 | return hoverTexture; 133 | } 134 | 135 | public int getSlot() { 136 | return slot; 137 | } 138 | 139 | public void setSlot(int slot) { 140 | this.slot = slot; 141 | } 142 | 143 | public void setGui(Gui gui) { 144 | this.gui = gui; 145 | } 146 | 147 | public Button setSize(float size) { 148 | this.size = size; 149 | return this; 150 | } 151 | 152 | public void setHover(boolean hover) { 153 | this.hover = hover; 154 | } 155 | 156 | public boolean isHover() { 157 | return hover; 158 | } 159 | 160 | public void setTexture(String texture) { 161 | this.texture = texture; 162 | } 163 | 164 | public void setHoverTexture(String hoverTexture) { 165 | this.hoverTexture = hoverTexture; 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/components/Component.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.components; 2 | 3 | import org.bukkit.entity.Display; 4 | import org.bukkit.entity.Entity; 5 | import org.bukkit.entity.Player; 6 | 7 | import java.util.UUID; 8 | 9 | public interface Component { 10 | 11 | public Entity getEntity(); 12 | public Display getDisplay(); 13 | public UUID getUniqueId(); 14 | public void show(Player player); 15 | public void hide(Player player); 16 | public void remove(); 17 | public void spawn(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/components/Text.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.components; 2 | 3 | import de.littleprogrammer.guiapi.GuiApi; 4 | import de.littleprogrammer.guiapi.guis.Gui; 5 | import de.littleprogrammer.guiapi.guis.SimpleGui; 6 | import org.bukkit.entity.*; 7 | import org.bukkit.util.Transformation; 8 | import org.joml.Vector3f; 9 | 10 | import java.util.UUID; 11 | 12 | public class Text implements Component { 13 | 14 | private String text; 15 | private UUID uuid; 16 | private float size = 2; 17 | private TextDisplay textDisplay; 18 | private Gui gui; 19 | private int slot; 20 | 21 | public Text(String text) { 22 | this.text = text; 23 | uuid = UUID.randomUUID(); 24 | } 25 | 26 | public Text(String text, int slot) { 27 | this.text = text; 28 | this.slot = slot < 0 || slot > 3 ? 1 : slot; 29 | uuid = UUID.randomUUID(); 30 | } 31 | 32 | @Override 33 | public void spawn() { 34 | textDisplay = (TextDisplay) gui.getCenterLocation().getWorld().spawnEntity(gui.getCenterLocation(), EntityType.TEXT_DISPLAY); 35 | textDisplay.setCustomName(uuid.toString()); 36 | textDisplay.setCustomNameVisible(false); 37 | textDisplay.setText(text); 38 | textDisplay.setGlowing(true); 39 | textDisplay.setBillboard(Display.Billboard.CENTER); 40 | textDisplay.setDisplayWidth(30); 41 | textDisplay.setDisplayHeight(30); 42 | textDisplay.setVisibleByDefault(false); 43 | textDisplay.setDefaultBackground(false); 44 | Transformation transformation = textDisplay.getTransformation(); 45 | transformation.getScale().set(new Vector3f(size, size, size)); 46 | textDisplay.setTransformation(transformation); 47 | } 48 | 49 | @Override 50 | public Entity getEntity() { 51 | return textDisplay; 52 | } 53 | 54 | @Override 55 | public Display getDisplay() { 56 | return textDisplay; 57 | } 58 | 59 | @Override 60 | public UUID getUniqueId() { 61 | return uuid; 62 | } 63 | 64 | public Gui getGui() { 65 | return gui; 66 | } 67 | 68 | public float getSize() { 69 | return size; 70 | } 71 | 72 | public void setGui(Gui gui) { 73 | this.gui = gui; 74 | } 75 | 76 | public Text setSize(float size) { 77 | this.size = size; 78 | return this; 79 | } 80 | 81 | @Override 82 | public void show(Player player) { 83 | player.showEntity(GuiApi.getInstance().getPlugin(), textDisplay); 84 | } 85 | 86 | @Override 87 | public void hide(Player player) { 88 | player.hideEntity(GuiApi.getInstance().getPlugin(), textDisplay); 89 | } 90 | 91 | @Override 92 | public void remove() { 93 | textDisplay.remove(); 94 | } 95 | 96 | public int getSlot() { 97 | return slot; 98 | } 99 | 100 | public void setSlot(int slot) { 101 | this.slot = slot; 102 | } 103 | 104 | public void updateText(String newText) { 105 | textDisplay.setText(newText); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/customeEvents/HoverButtonEvent.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.customeEvents; 2 | 3 | import de.littleprogrammer.guiapi.guis.Gui; 4 | import de.littleprogrammer.guiapi.guis.SimpleGui; 5 | import de.littleprogrammer.guiapi.components.Button; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.Event; 8 | import org.bukkit.event.HandlerList; 9 | 10 | public class HoverButtonEvent extends Event { 11 | private static final HandlerList HANDLERS = new HandlerList(); 12 | 13 | private final Gui gui; 14 | private final Player player; 15 | private final Button button; 16 | private final String hoverText; 17 | private final String text; 18 | 19 | public HoverButtonEvent(Gui gui, Player player, Button button, String hoverText, String text) { 20 | this.gui = gui; 21 | this.player = player; 22 | this.button = button; 23 | this.hoverText = hoverText; 24 | this.text = text; 25 | 26 | button.getDisplay().setText(hoverText); 27 | } 28 | 29 | @Override 30 | public HandlerList getHandlers() { 31 | return HANDLERS; 32 | } 33 | 34 | public static HandlerList getHandlerList() { 35 | return HANDLERS; 36 | } 37 | 38 | public Gui getGui() { 39 | return gui; 40 | } 41 | 42 | public Player getPlayer() { 43 | return player; 44 | } 45 | 46 | public Button getButton() { 47 | return button; 48 | } 49 | 50 | public String getHoverText() { 51 | return hoverText; 52 | } 53 | 54 | public String getText() { 55 | return text; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/customeEvents/UnHoverButtonEvent.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.customeEvents; 2 | 3 | import de.littleprogrammer.guiapi.guis.Gui; 4 | import de.littleprogrammer.guiapi.guis.SimpleGui; 5 | import de.littleprogrammer.guiapi.components.Button; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.Event; 8 | import org.bukkit.event.HandlerList; 9 | 10 | public class UnHoverButtonEvent extends Event { 11 | private static final HandlerList HANDLERS = new HandlerList(); 12 | 13 | private final Gui gui; 14 | private final Player player; 15 | private final Button button; 16 | private final String hoverText; 17 | private final String text; 18 | 19 | public UnHoverButtonEvent(Gui gui, Player player, Button button, String hoverText, String text) { 20 | this.gui = gui; 21 | this.player = player; 22 | this.button = button; 23 | this.hoverText = hoverText; 24 | this.text = text; 25 | 26 | button.getDisplay().setText(text); 27 | } 28 | 29 | @Override 30 | public HandlerList getHandlers() { 31 | return HANDLERS; 32 | } 33 | 34 | public static HandlerList getHandlerList() { 35 | return HANDLERS; 36 | } 37 | 38 | public Gui getGui() { 39 | return gui; 40 | } 41 | 42 | public Player getPlayer() { 43 | return player; 44 | } 45 | 46 | public Button getButton() { 47 | return button; 48 | } 49 | 50 | public String getHoverText() { 51 | return hoverText; 52 | } 53 | 54 | public String getText() { 55 | return text; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/enums/ServerVersion.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.enums; 2 | 3 | public enum ServerVersion { 4 | PRE_1_20_2, 5 | POST_1_20_2; 6 | ServerVersion() { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/guis/Gui.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.guis; 2 | 3 | import de.littleprogrammer.guiapi.components.Button; 4 | import de.littleprogrammer.guiapi.components.Component; 5 | import org.bukkit.Location; 6 | import org.bukkit.entity.Player; 7 | 8 | import java.util.*; 9 | 10 | public abstract class Gui { 11 | public UUID uuid; 12 | public Player player; 13 | public Location centerLocation; 14 | public boolean open; 15 | public Map components; 16 | public Map buttons; 17 | public int spacing; 18 | 19 | public Gui(UUID uuid, boolean open) { 20 | this.uuid = uuid; 21 | this.open = open; 22 | 23 | this.components = new HashMap<>(); 24 | this.buttons = new HashMap<>(); 25 | } 26 | 27 | public abstract void open(Player player); 28 | public abstract void close(); 29 | public abstract void updatePosition(Location location); 30 | 31 | public void setUuid(UUID uuid) { 32 | this.uuid = uuid; 33 | } 34 | 35 | public void setPlayer(Player player) { 36 | this.player = player; 37 | } 38 | 39 | public void setCenterLocation(Location centerLocation) { 40 | this.centerLocation = centerLocation; 41 | } 42 | 43 | public void setOpen(boolean open) { 44 | this.open = open; 45 | } 46 | 47 | public boolean isOpen() { 48 | return open; 49 | } 50 | 51 | public Component getComponent(UUID uuid) { 52 | return components.get(uuid); 53 | } 54 | 55 | public Location getCenterLocation() { 56 | return centerLocation; 57 | } 58 | 59 | public Player getPlayer() { 60 | return player; 61 | } 62 | 63 | public List getComponents() { 64 | return new ArrayList<>(components.values()); 65 | } 66 | 67 | public void setSpacing(int spacing) { 68 | this.spacing = spacing; 69 | } 70 | 71 | public int getSpacing() { 72 | return spacing; 73 | } 74 | 75 | public int getButtonAmount() { 76 | return buttons.size(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/guis/PagedGui.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.guis; 2 | 3 | import de.littleprogrammer.guiapi.GuiApi; 4 | import de.littleprogrammer.guiapi.components.Button; 5 | import de.littleprogrammer.guiapi.components.Component; 6 | import de.littleprogrammer.guiapi.components.Text; 7 | import de.littleprogrammer.guiapi.enums.ServerVersion; 8 | import de.littleprogrammer.guiapi.utils.Calculations; 9 | import de.littleprogrammer.guiapi.utils.TeleportInterpolator; 10 | import org.bukkit.Location; 11 | import org.bukkit.entity.Player; 12 | 13 | import java.util.*; 14 | 15 | public class PagedGui extends Gui { 16 | 17 | private int page; 18 | private String title; 19 | private List contents; 20 | private List texts; 21 | private Button leftButton; 22 | private Button middleButton; 23 | private Button rightButton; 24 | private float contentSize = 1.3f; 25 | private int contentSpacing = 60; 26 | 27 | public PagedGui(String title, int page) { 28 | super(UUID.randomUUID(), false); 29 | 30 | this.page = page; 31 | this.contents = new ArrayList<>(); 32 | this.texts = new ArrayList<>(); 33 | this.title = title; 34 | 35 | setSpacing(60); 36 | } 37 | 38 | @Override 39 | public void open(Player player) { 40 | if (this.player != null && this.player.getUniqueId().equals(player.getUniqueId())) { 41 | //close GUI and open for the new player 42 | close(); 43 | } 44 | this.player = player; 45 | GuiApi.getInstance().getGuis().put(player.getUniqueId(), this); 46 | centerLocation = new Location(player.getWorld(), 0, 0, 0); 47 | 48 | for (int i = 0; i < 3; i++) { 49 | if (contents.size() > i) { 50 | Text text = new Text(contents.get(i + page), i + 1).setSize(contentSize); 51 | text.setGui(this); 52 | texts.add(text); 53 | components.put(text.getUniqueId(), text); 54 | } 55 | } 56 | 57 | leftButton = new Button("<", "<<", 1).onClick(event -> { 58 | if (GuiApi.getInstance().getGuis().get(player.getUniqueId()) instanceof PagedGui) { 59 | PagedGui gui = (PagedGui) GuiApi.getInstance().getGuis().get(player.getUniqueId()); 60 | if (gui.getPage() > 0) { 61 | gui.changePage(gui.getPage() - 1); 62 | } 63 | } 64 | }); 65 | leftButton.setGui(this); 66 | buttons.put(leftButton.getUniqueId(), leftButton); 67 | 68 | rightButton = new Button(">", ">>", 3).onClick(event -> { 69 | if (GuiApi.getInstance().getGuis().get(player.getUniqueId()) instanceof PagedGui) { 70 | PagedGui gui = (PagedGui) GuiApi.getInstance().getGuis().get(player.getUniqueId()); 71 | System.out.println("Page " + gui.getPage() + " texts size " + contents.size() + " bool " + (gui.getPage() < contents.size() - 3)); 72 | if (gui.getPage() < contents.size() - 3) { 73 | gui.changePage(gui.getPage() + 1); 74 | } 75 | } 76 | }); 77 | rightButton.setGui(this); 78 | buttons.put(rightButton.getUniqueId(), rightButton); 79 | 80 | components.put(leftButton.getUniqueId(), leftButton); 81 | components.put(rightButton.getUniqueId(), rightButton); 82 | 83 | for (Component component : components.values()) { 84 | component.spawn(); 85 | component.show(player); 86 | } 87 | 88 | open = true; 89 | } 90 | 91 | @Override 92 | public void close() { 93 | GuiApi.getInstance().getGuis().remove(player.getUniqueId()); 94 | 95 | for (Component component : components.values()) { 96 | component.hide(player); 97 | component.remove(); 98 | } 99 | open = false; 100 | } 101 | 102 | @Override 103 | public void updatePosition(Location playerLoc) { 104 | if (player != null) { 105 | centerLocation = Calculations.calculateInventoryCenter(playerLoc); 106 | 107 | if (GuiApi.getInstance().getVersion().equals(ServerVersion.PRE_1_20_2)) { 108 | for (Text text : texts) { 109 | Location newComponentLocation = Calculations.calculateComponentLocation(this, text, 3, contentSpacing); 110 | 111 | TeleportInterpolator teleportInterpolator = new TeleportInterpolator(text.getEntity(), newComponentLocation, 5, 1); 112 | teleportInterpolator.startInterpolation(); 113 | } 114 | 115 | for (Button button : buttons.values()) { 116 | Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 3, spacing); 117 | 118 | TeleportInterpolator teleportInterpolator = new TeleportInterpolator(button.getEntity(), newComponentLocation, 5, 1); 119 | teleportInterpolator.startInterpolation(); 120 | } 121 | } else { 122 | for (Text text : texts) { 123 | Location newComponentLocation = Calculations.calculateComponentLocation(this, text, 3, contentSpacing); 124 | 125 | text.getDisplay().setTeleportDuration(5); 126 | text.getDisplay().teleport(newComponentLocation); 127 | } 128 | 129 | for (Button button : buttons.values()) { 130 | Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 3, spacing); 131 | 132 | button.getDisplay().setTeleportDuration(5); 133 | button.getDisplay().teleport(newComponentLocation); 134 | } 135 | } 136 | } 137 | } 138 | 139 | private void changePage(int newPage) { 140 | for (int i = 0; i < 3; i++) { 141 | texts.get(i).updateText(contents.get(i + newPage)); 142 | } 143 | this.page = newPage; 144 | } 145 | 146 | public PagedGui addButton(Button button) { 147 | if (middleButton == null) { 148 | button.setSlot(2); 149 | components.put(button.getUniqueId(), button); 150 | buttons.put(button.getUniqueId(), button); 151 | middleButton = button; 152 | button.setGui(this); 153 | } 154 | return this; 155 | } 156 | 157 | public void setContents(List contents) { 158 | this.contents = contents; 159 | } 160 | 161 | public void addContent(List contents) { 162 | if (contents != null) { 163 | this.contents.addAll(contents); 164 | } 165 | } 166 | 167 | public void addContent(String content) { 168 | this.contents.add(content); 169 | } 170 | 171 | public List getContents() { 172 | return contents; 173 | } 174 | 175 | public String getTitle() { 176 | return title; 177 | } 178 | 179 | public int getPage() { 180 | return page; 181 | } 182 | 183 | public void setContentSize(float contentSize) { 184 | this.contentSize = contentSize; 185 | } 186 | 187 | public void setContentSpacing(int contentSpacing) { 188 | this.contentSpacing = contentSpacing; 189 | } 190 | 191 | public PagedGui setLeftButtonText(String text, String hoverText) { 192 | leftButton.setTexture(text); 193 | leftButton.setHoverTexture(hoverText); 194 | return this; 195 | } 196 | 197 | public PagedGui setRightButtonText(String text, String hoverText) { 198 | rightButton.setTexture(text); 199 | rightButton.setHoverTexture(hoverText); 200 | return this; 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/guis/SimpleGui.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.guis; 2 | 3 | import de.littleprogrammer.guiapi.GuiApi; 4 | import de.littleprogrammer.guiapi.components.Button; 5 | import de.littleprogrammer.guiapi.components.Component; 6 | import de.littleprogrammer.guiapi.components.Text; 7 | import de.littleprogrammer.guiapi.enums.ServerVersion; 8 | import de.littleprogrammer.guiapi.utils.Calculations; 9 | import de.littleprogrammer.guiapi.utils.TeleportInterpolator; 10 | import org.bukkit.Location; 11 | import org.bukkit.entity.Player; 12 | 13 | import java.util.*; 14 | 15 | public class SimpleGui extends Gui { 16 | 17 | private final String title; 18 | private Component content; 19 | 20 | public SimpleGui(String title) { 21 | super(UUID.randomUUID(), false); 22 | 23 | this.title = title; 24 | this.components = new HashMap<>(); 25 | setSpacing(30); 26 | } 27 | 28 | @Override 29 | public void updatePosition(Location playerLoc) { 30 | if (player != null) { 31 | centerLocation = Calculations.calculateInventoryCenter(playerLoc); 32 | 33 | if (GuiApi.getInstance().getVersion().equals(ServerVersion.PRE_1_20_2)) { 34 | for (Component component : components.values()) { 35 | Location newComponentLocation = Calculations.calculateComponentLocation(this, component, buttons.size(), spacing); 36 | 37 | TeleportInterpolator teleportInterpolator = new TeleportInterpolator(component.getEntity(), newComponentLocation, 5, 1); 38 | teleportInterpolator.startInterpolation(); 39 | } 40 | } else { 41 | for (Component component : components.values()) { 42 | Location newComponentLocation = Calculations.calculateComponentLocation(this, component, buttons.size(), spacing); 43 | 44 | component.getDisplay().setTeleportDuration(5); 45 | component.getDisplay().teleport(newComponentLocation); 46 | } 47 | } 48 | } 49 | } 50 | 51 | @Override 52 | public void close() { 53 | //close GUI 54 | GuiApi.getInstance().getGuis().remove(player.getUniqueId()); 55 | 56 | for (Component component : components.values()) { 57 | component.hide(player); 58 | component.remove(); 59 | } 60 | open = false; 61 | } 62 | 63 | @Override 64 | public void open(Player player) { 65 | if (this.player != null && this.player.getUniqueId().equals(player.getUniqueId())) { 66 | //close GUI and open for the new player 67 | close(); 68 | } 69 | this.player = player; 70 | GuiApi.getInstance().getGuis().put(player.getUniqueId(), this); 71 | centerLocation = new Location(player.getWorld(), 0, 0, 0); 72 | 73 | for (Component component : components.values()) { 74 | component.spawn(); 75 | component.show(player); 76 | } 77 | open = true; 78 | } 79 | 80 | 81 | public SimpleGui addButton(Button button) { 82 | if (buttons.size() < 3) { 83 | components.put(button.getUniqueId(), button); 84 | buttons.put(button.getUniqueId(), button); 85 | button.setGui(this); 86 | } 87 | return this; 88 | } 89 | 90 | public SimpleGui addContent(Text content) { 91 | if (this.content != null) { 92 | components.remove(this.content.getUniqueId()); 93 | this.content.remove(); 94 | } 95 | this.content = content; 96 | components.put(content.getUniqueId(), content); 97 | content.setGui(this); 98 | return this; 99 | } 100 | 101 | public String getTitle() { 102 | return title; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/listeners/GuiEvents.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.listeners; 2 | 3 | import de.littleprogrammer.guiapi.GuiApi; 4 | import de.littleprogrammer.guiapi.guis.Gui; 5 | import de.littleprogrammer.guiapi.components.Button; 6 | import de.littleprogrammer.guiapi.components.Component; 7 | import de.littleprogrammer.guiapi.utils.Calculations; 8 | import org.bukkit.entity.Display; 9 | import org.bukkit.entity.Entity; 10 | import org.bukkit.event.EventHandler; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.player.PlayerInteractEntityEvent; 13 | import org.bukkit.event.player.PlayerInteractEvent; 14 | 15 | import java.util.UUID; 16 | 17 | public class GuiEvents implements Listener { 18 | 19 | @EventHandler 20 | public void onPlayerInteractEvent(PlayerInteractEvent event) { 21 | final Gui gui = GuiApi.getInstance().getGUI(event.getPlayer()); 22 | 23 | if (gui == null) return; 24 | 25 | Entity awaitenEntity = null; 26 | for (Entity entity : event.getPlayer().getNearbyEntities(7, 7, 7)) { 27 | if (entity instanceof Display && entity.getCustomName() != null) { 28 | if (Calculations.playerLookingAtEntity(event.getPlayer(), entity)) { 29 | awaitenEntity = entity; 30 | break; 31 | } 32 | } 33 | } 34 | 35 | if (awaitenEntity == null) { return; } 36 | 37 | UUID uuid = UUID.fromString(awaitenEntity.getCustomName()); 38 | Component component = gui.getComponent(uuid); 39 | if (!(component instanceof Button)) return; 40 | 41 | Button button = (Button) component; 42 | button.getClickAction().accept(new PlayerInteractEntityEvent(event.getPlayer(), button.getEntity())); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/listeners/MoveListener.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.listeners; 2 | 3 | import de.littleprogrammer.guiapi.GuiApi; 4 | import de.littleprogrammer.guiapi.guis.Gui; 5 | import de.littleprogrammer.guiapi.components.Button; 6 | import de.littleprogrammer.guiapi.components.Component; 7 | import de.littleprogrammer.guiapi.customeEvents.HoverButtonEvent; 8 | import de.littleprogrammer.guiapi.customeEvents.UnHoverButtonEvent; 9 | import de.littleprogrammer.guiapi.utils.Calculations; 10 | import org.bukkit.entity.Display; 11 | import org.bukkit.entity.Entity; 12 | import org.bukkit.event.EventHandler; 13 | import org.bukkit.event.Listener; 14 | import org.bukkit.event.player.PlayerMoveEvent; 15 | 16 | import java.util.UUID; 17 | 18 | public class MoveListener implements Listener { 19 | 20 | @EventHandler 21 | public void onPlayerMove(PlayerMoveEvent event) { 22 | if (GuiApi.getInstance().getGuis().containsKey(event.getPlayer().getUniqueId())) { 23 | Gui gui = GuiApi.getInstance().getGuis().get(event.getPlayer().getUniqueId()); 24 | 25 | if (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getY() != event.getTo().getY() || event.getFrom().getZ() != event.getTo().getZ()) { 26 | //Location is different 27 | gui.updatePosition(event.getPlayer().getEyeLocation()); 28 | } else if (!Calculations.isInRange(event.getPlayer().getEyeLocation(), gui.getCenterLocation(), gui.getSpacing() + 15)) { 29 | gui.updatePosition(event.getPlayer().getEyeLocation()); 30 | } 31 | 32 | Entity hoveredEntity = null; 33 | for (Entity entity : event.getPlayer().getNearbyEntities(8, 8, 8)) { 34 | if (entity instanceof Display && entity.getCustomName() != null) { 35 | if (Calculations.isInRange(event.getPlayer().getEyeLocation(), entity.getLocation(), 7)) { 36 | hoveredEntity = entity; 37 | break; 38 | } 39 | } 40 | } 41 | 42 | if (hoveredEntity != null) { 43 | if (gui.getComponent(UUID.fromString(hoveredEntity.getCustomName())) instanceof Button) { 44 | Button button = (Button) gui.getComponent(UUID.fromString(hoveredEntity.getCustomName())); 45 | button.getHoverAction().accept(new HoverButtonEvent(gui, event.getPlayer(), button, button.getHoverText(), button.getText())); 46 | button.setHover(true); 47 | } 48 | } else { 49 | for (Component component : gui.getComponents()) { 50 | if (component instanceof Button) { 51 | Button button = (Button) component; 52 | if (button.isHover()) { 53 | button.getUnHoverAction().accept(new UnHoverButtonEvent(gui, event.getPlayer(), button, button.getHoverText(), button.getText())); 54 | button.setHover(false); 55 | } 56 | } 57 | } 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/utils/Calculations.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.utils; 2 | 3 | import de.littleprogrammer.guiapi.components.Text; 4 | import de.littleprogrammer.guiapi.guis.Gui; 5 | import de.littleprogrammer.guiapi.guis.SimpleGui; 6 | import de.littleprogrammer.guiapi.components.Button; 7 | import de.littleprogrammer.guiapi.components.Component; 8 | import org.bukkit.Location; 9 | import org.bukkit.entity.Entity; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.util.Vector; 12 | 13 | public class Calculations { 14 | 15 | public static Location calculateInventoryCenter(Location midLocation) { 16 | double distance = 4; // 4 blocks away 17 | double yawRadians = Math.toRadians(midLocation.getYaw()); 18 | double pitchRadians = Math.toRadians(midLocation.getPitch()); 19 | double x = midLocation.getX() - distance * Math.sin(yawRadians); 20 | double y = midLocation.getY() - 1; 21 | double z = midLocation.getZ() + distance * Math.cos(yawRadians); // Negative here to match player rotation direction 22 | 23 | return new Location(midLocation.getWorld(), x, y, z, midLocation.getYaw(), 0); 24 | } 25 | 26 | public static Location calculateComponentLocation(Gui gui, Component component, int buttonAmount, int spacing) { 27 | Location centerLoc = gui.getCenterLocation(); 28 | if (component instanceof Button) { 29 | Button button = (Button) component; 30 | 31 | Location[] locations = calculateTrianglePoints(gui.getPlayer().getLocation(), centerLoc, spacing); 32 | //Is button in row 33 | switch (buttonAmount) { 34 | case 1: 35 | return centerLoc.clone().subtract(0, 0, 0); 36 | case 2: 37 | if (button.getSlot() == 1) { 38 | return locations[0]; 39 | } else if (button.getSlot() == 2) { 40 | return locations[1]; 41 | } 42 | break; 43 | case 3: 44 | if (button.getSlot() == 1) { 45 | return locations[0]; 46 | } else if (button.getSlot() == 2) { 47 | return centerLoc.clone().subtract(0, 0, 0); 48 | } else if (button.getSlot() == 3) { 49 | return locations[1]; 50 | } 51 | break; 52 | } 53 | } else if (component instanceof Text) { 54 | Text text = (Text) component; 55 | 56 | Location[] locations = calculateTrianglePoints(gui.getPlayer().getLocation(), centerLoc, spacing); 57 | //Is button in row 58 | switch (buttonAmount) { 59 | case 1: 60 | return centerLoc.clone().add(0, 1.5, 0); 61 | case 2: 62 | if (text.getSlot() == 1) { 63 | return locations[0].clone().add(0, 1.5, 0); 64 | } else if (text.getSlot() == 2) { 65 | return locations[1].add(0, 1.5, 0); 66 | } 67 | break; 68 | case 3: 69 | if (text.getSlot() == 1) { 70 | return locations[0].add(0, 1.5, 0); 71 | } else if (text.getSlot() == 2) { 72 | return centerLoc.clone().add(0, 1.5, 0); 73 | } else if (text.getSlot() == 3) { 74 | return locations[1].add(0, 1.5, 0); 75 | } 76 | break; 77 | } 78 | } else { 79 | //Is content 80 | return centerLoc.clone().add(0, 1.5, 0); 81 | } 82 | return null; 83 | } 84 | 85 | 86 | /** 87 | * @param playerLocation the location of the player (the point in the middle) 88 | * @param centerLocation the location on the circle to get the correct height 89 | */ 90 | private static Location[] calculateTrianglePoints(Location playerLocation, Location centerLocation, int spacing) { 91 | double radius = playerLocation.distance(centerLocation); 92 | 93 | Vector vector1 = playerLocation.getDirection().setY(0).normalize().multiply(radius).rotateAroundY(Math.toRadians(spacing)); 94 | Vector vector2 = playerLocation.getDirection().setY(0).normalize().multiply(radius).rotateAroundY(Math.toRadians(spacing * -1)); 95 | 96 | Location loc1 = playerLocation.clone().add(vector1); 97 | loc1.setY(centerLocation.getY()); 98 | 99 | Location loc2 = playerLocation.clone().add(vector2); 100 | loc2.setY(centerLocation.getY()); 101 | 102 | return new Location[]{loc1, loc2}; 103 | } 104 | 105 | public static boolean playerLookingAtEntity(Player player, Entity entity) { 106 | Vector playerDirection = player.getLocation().getDirection().normalize(); 107 | 108 | Location entityLocation = entity.getLocation(); 109 | Location playerEyeLocation = player.getEyeLocation(); 110 | 111 | Vector playerToEntity = entityLocation.toVector().subtract(playerEyeLocation.toVector()).normalize(); 112 | double dotProduct = playerDirection.dot(playerToEntity); 113 | 114 | //System.out.println("Checking entity" + entity + " " + entity.getCustomName() + " dot: " + dotProduct); 115 | 116 | return dotProduct > 0.97; 117 | } 118 | 119 | public static boolean isInRange(Location playerEyeLocation, Location centerLocation, double rangeInDegrees) { 120 | Vector playerEyeVector = playerEyeLocation.getDirection().setY(0).normalize(); 121 | Vector playerToCenter = centerLocation.toVector().subtract(playerEyeLocation.toVector()).setY(0).normalize(); 122 | 123 | double dotProduct = playerToCenter.dot(playerEyeVector); 124 | double angle = Math.toDegrees(Math.acos(dotProduct)); 125 | 126 | return angle <= rangeInDegrees; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/de/littleprogrammer/guiapi/utils/TeleportInterpolator.java: -------------------------------------------------------------------------------- 1 | package de.littleprogrammer.guiapi.utils; 2 | 3 | import de.littleprogrammer.guiapi.GuiApi; 4 | import org.bukkit.Location; 5 | import org.bukkit.entity.Entity; 6 | 7 | public class TeleportInterpolator { 8 | 9 | private Entity entity; 10 | private Location targetLocation; 11 | private int steps; 12 | private int delay; 13 | 14 | public TeleportInterpolator(Entity entity, Location targetLocation, int steps, int delay) { 15 | this.entity = entity; 16 | this.targetLocation = targetLocation; 17 | this.steps = steps; 18 | this.delay = delay; 19 | } 20 | 21 | public void startInterpolation() { 22 | Location currentLocation = entity.getLocation(); 23 | 24 | double dx = (targetLocation.getX() - currentLocation.getX()) / steps; 25 | double dy = (targetLocation.getY() - currentLocation.getY()) / steps; 26 | double dz = (targetLocation.getZ() - currentLocation.getZ()) / steps; 27 | 28 | for (int i = 1; i <= steps; i++) { 29 | double newX = currentLocation.getX() + dx * i; 30 | double newY = currentLocation.getY() + dy * i; 31 | double newZ = currentLocation.getZ() + dz * i; 32 | 33 | Location intermediateLocation = new Location(targetLocation.getWorld(), newX, newY, newZ); 34 | 35 | // Teleport the entity to the intermediate location after a delay 36 | teleportWithDelay(intermediateLocation, i * delay); 37 | } 38 | } 39 | 40 | private void teleportWithDelay(Location location, int delayTicks) { 41 | GuiApi.getScheduler().runTaskLater(GuiApi.getInstance().getPlugin(), () -> { 42 | entity.teleport(location); 43 | }, delayTicks); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: 3dGuiApi 2 | version: '${version}' 3 | main: de.littleprogrammer.guiapi.GuiApi 4 | api-version: '1.19' 5 | authors: [LittleProgrammer] 6 | description: An API to make 3D Gui's in minecraft 7 | commands: 8 | #spawnGui: --------------------------------------------------------------------------------