commit d4b46996c1310051dbf84a679ea10f60e040744f Author: Paul Reilly Date: Wed Mar 8 00:42:58 2023 -0600 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Compiled class file +*.class + +# 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* +replay_pid* diff --git a/.gradle/7.3.3/checksums/checksums.lock b/.gradle/7.3.3/checksums/checksums.lock new file mode 100644 index 0000000..8d79106 Binary files /dev/null and b/.gradle/7.3.3/checksums/checksums.lock differ diff --git a/.gradle/7.3.3/checksums/md5-checksums.bin b/.gradle/7.3.3/checksums/md5-checksums.bin new file mode 100644 index 0000000..7818d21 Binary files /dev/null and b/.gradle/7.3.3/checksums/md5-checksums.bin differ diff --git a/.gradle/7.3.3/checksums/sha1-checksums.bin b/.gradle/7.3.3/checksums/sha1-checksums.bin new file mode 100644 index 0000000..a264584 Binary files /dev/null and b/.gradle/7.3.3/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000..f45842f Binary files /dev/null and b/.gradle/7.3.3/dependencies-accessors/dependencies-accessors.lock differ diff --git a/.gradle/7.3.3/dependencies-accessors/gc.properties b/.gradle/7.3.3/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin new file mode 100644 index 0000000..25ca89b Binary files /dev/null and b/.gradle/7.3.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock new file mode 100644 index 0000000..df0646d Binary files /dev/null and b/.gradle/7.3.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.3.3/fileChanges/last-build.bin b/.gradle/7.3.3/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/7.3.3/fileChanges/last-build.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin new file mode 100644 index 0000000..a051c68 Binary files /dev/null and b/.gradle/7.3.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock new file mode 100644 index 0000000..f13f76e Binary files /dev/null and b/.gradle/7.3.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.3/gc.properties b/.gradle/7.3.3/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..ba542d0 Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..d479b41 --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Tue Mar 07 20:50:28 CST 2023 +gradle.version=7.3.3 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..43baa5e Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe new file mode 100644 index 0000000..95806dd Binary files /dev/null and b/.gradle/file-system.probe differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..355f36e --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +TypeSelector \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml new file mode 100644 index 0000000..d8e9561 --- /dev/null +++ b/.idea/discord.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..6332aaf --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..7ae5ed7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,54 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..3fd2793 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..702fcdf --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/TypeSelector.main.iml b/.idea/modules/TypeSelector.main.iml new file mode 100644 index 0000000..f5de878 --- /dev/null +++ b/.idea/modules/TypeSelector.main.iml @@ -0,0 +1,13 @@ + + + + + + + PAPER + ADVENTURE + + + + + \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/0/a/0a12643b5926514dc78595dd0de298f57c214da6 b/.idea/sonarlint/issuestore/0/a/0a12643b5926514dc78595dd0de298f57c214da6 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/0/a/0a6146f64cde5935027cec3f5011843917c695cc b/.idea/sonarlint/issuestore/0/a/0a6146f64cde5935027cec3f5011843917c695cc new file mode 100644 index 0000000..ea35756 --- /dev/null +++ b/.idea/sonarlint/issuestore/0/a/0a6146f64cde5935027cec3f5011843917c695cc @@ -0,0 +1,17 @@ + +Q +java:S1066!"/Merge this if statement with the enclosing one.(80 +U +java:S1118":Add a private constructor to hide the implicit public one.( +t +java:S3776"RRefactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed.(80 +C +java:S1659"!Declare "col" on a separate line.(Ϥ80 +? +java:S1659""Declare "dCol" on a separate line.(80 +f +java:S3358*"DExtract this nested ternary operation into an independent statement.(80 +f +java:S3358*"DExtract this nested ternary operation into an independent statement.(80 +O +java:S1128"-Remove this unused import 'java.util.Arrays'.(80 \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/0/f/0f39357e2b7952a9117fcd9387b5a91735f600f5 b/.idea/sonarlint/issuestore/0/f/0f39357e2b7952a9117fcd9387b5a91735f600f5 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/1/1/114d1a559c312d068b50b6a948d509cbdc315e2b b/.idea/sonarlint/issuestore/1/1/114d1a559c312d068b50b6a948d509cbdc315e2b new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/1/2/12461258daee2839e766d082ea2e514d5578731c b/.idea/sonarlint/issuestore/1/2/12461258daee2839e766d082ea2e514d5578731c new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/1/7/172cbc3e89142dd502a2aa74ee25933e1e1dca0e b/.idea/sonarlint/issuestore/1/7/172cbc3e89142dd502a2aa74ee25933e1e1dca0e new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/3/0/30ddeaabb5082f9cf52c55066a39e20a1f7e4cde b/.idea/sonarlint/issuestore/3/0/30ddeaabb5082f9cf52c55066a39e20a1f7e4cde new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/3/f/3f45a40dab9ff1ac3dfeb0b1447c92d3fcca7e1d b/.idea/sonarlint/issuestore/3/f/3f45a40dab9ff1ac3dfeb0b1447c92d3fcca7e1d new file mode 100644 index 0000000..e9e06c1 --- /dev/null +++ b/.idea/sonarlint/issuestore/3/f/3f45a40dab9ff1ac3dfeb0b1447c92d3fcca7e1d @@ -0,0 +1,5 @@ + +c java:S116"NRename this field "INV" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +g java:S116"RRename this field "ACTIONS" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.( +I +java:S1611K"3Remove the parentheses around the "tuple" parameter(Ӗ \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/4/8/4853b7b764faca92eb34eb45c9c8ae8753e8c104 b/.idea/sonarlint/issuestore/4/8/4853b7b764faca92eb34eb45c9c8ae8753e8c104 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/5/1/5180bcd0407aa16dddc06876d760e9b3062791b1 b/.idea/sonarlint/issuestore/5/1/5180bcd0407aa16dddc06876d760e9b3062791b1 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/6/7/675f1b97b89a93527cff306e60abfb39c17a0c8d b/.idea/sonarlint/issuestore/6/7/675f1b97b89a93527cff306e60abfb39c17a0c8d new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/6/d/6d697c45549525f848d3b9bc2eb4094069cf0043 b/.idea/sonarlint/issuestore/6/d/6d697c45549525f848d3b9bc2eb4094069cf0043 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/9/9/999d23e2cf89fb28de6ae4c8b025a7d0a7c4820d b/.idea/sonarlint/issuestore/9/9/999d23e2cf89fb28de6ae4c8b025a7d0a7c4820d new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/a/5/a5bbb1ae03235febbc6078171e3310884077d032 b/.idea/sonarlint/issuestore/a/5/a5bbb1ae03235febbc6078171e3310884077d032 new file mode 100644 index 0000000..958bc98 --- /dev/null +++ b/.idea/sonarlint/issuestore/a/5/a5bbb1ae03235febbc6078171e3310884077d032 @@ -0,0 +1,7 @@ + +J +java:S2386"4Move "invByUUID" to a class and lower its visibility( +P +java:S2386":Move "openInventories" to a class and lower its visibility( +E +java:S1611-"/Remove the parentheses around the "p" parameter(ӑ \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/a/c/ac5a95c559f2fc71d19c20cce19c09d1c5a8e233 b/.idea/sonarlint/issuestore/a/c/ac5a95c559f2fc71d19c20cce19c09d1c5a8e233 new file mode 100644 index 0000000..39d3a2e --- /dev/null +++ b/.idea/sonarlint/issuestore/a/c/ac5a95c559f2fc71d19c20cce19c09d1c5a8e233 @@ -0,0 +1,9 @@ + +] +java:S2094"BRemove this empty class, write its code or make it an "interface".(̈ +6 +java:S2326"A is not used in the class.(̈ +6 +java:S2326"B is not used in the class.(̈ +6 +java:S2326"C is not used in the class.(̈ \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/b/3/b3eafc205cf9dae5d1a7b77b5dbb74e37277308b b/.idea/sonarlint/issuestore/b/3/b3eafc205cf9dae5d1a7b77b5dbb74e37277308b new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/b/6/b6a6baf26fa767cc0299e356d0466810eb110166 b/.idea/sonarlint/issuestore/b/6/b6a6baf26fa767cc0299e356d0466810eb110166 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/c/0/c073e6b63a4ab557c6e151977d8a00190061ea34 b/.idea/sonarlint/issuestore/c/0/c073e6b63a4ab557c6e151977d8a00190061ea34 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/c/1/c17017a8e659f282bdd6ebfdaf9293f034645a9c b/.idea/sonarlint/issuestore/c/1/c17017a8e659f282bdd6ebfdaf9293f034645a9c new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/e/9/e9f15dd068513a64c53a24b0daa25119adfcc9ec b/.idea/sonarlint/issuestore/e/9/e9f15dd068513a64c53a24b0daa25119adfcc9ec new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/f/7/f7a91356545d95e994ebce6af582f1824b8ba782 b/.idea/sonarlint/issuestore/f/7/f7a91356545d95e994ebce6af582f1824b8ba782 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/f/b/fb9f8bc5d1d91117468f0312d09333f5af318753 b/.idea/sonarlint/issuestore/f/b/fb9f8bc5d1d91117468f0312d09333f5af318753 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000..d77fa44 --- /dev/null +++ b/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,45 @@ + +j +:src/main/java/io/github/simplexdevelopment/util/Tuple.java,a\c\ac5a95c559f2fc71d19c20cce19c09d1c5a8e233 +i +9src/main/java/io/github/simplexdevelopment/util/Pair.java,5\1\5180bcd0407aa16dddc06876d760e9b3062791b1 +m +=src/main/java/io/github/simplexdevelopment/api/GUIAction.java,3\0\30ddeaabb5082f9cf52c55066a39e20a1f7e4cde +l +src/main/java/io/github/simplexdevelopment/mob/ParrotType.java,c\1\c17017a8e659f282bdd6ebfdaf9293f034645a9c +m +=src/main/java/io/github/simplexdevelopment/mob/SheepType.java,f\7\f7a91356545d95e994ebce6af582f1824b8ba782 +n +>src/main/java/io/github/simplexdevelopment/mob/RabbitType.java,b\6\b6a6baf26fa767cc0299e356d0466810eb110166 +m +=src/main/java/io/github/simplexdevelopment/mob/PandaType.java,6\d\6d697c45549525f848d3b9bc2eb4094069cf0043 +t +Dsrc/main/java/io/github/simplexdevelopment/mob/TropicalFishType.java,f\b\fb9f8bc5d1d91117468f0312d09333f5af318753 +p +@src/main/java/io/github/simplexdevelopment/mob/VillagerType.java,0\f\0f39357e2b7952a9117fcd9387b5a91735f600f5 +x +Hsrc/main/java/io/github/simplexdevelopment/util/DisplayableSlotEnum.java,b\3\b3eafc205cf9dae5d1a7b77b5dbb74e37277308b +o +?src/main/java/io/github/simplexdevelopment/inv/AbstractGUI.java,3\f\3f45a40dab9ff1ac3dfeb0b1447c92d3fcca7e1d +m +=src/main/java/io/github/simplexdevelopment/api/GUIWindow.java,a\5\a5bbb1ae03235febbc6078171e3310884077d032 +l + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..b3bb358 --- /dev/null +++ b/build.gradle @@ -0,0 +1,47 @@ +plugins { + id 'java' +} + +group = 'io.github.simplexdevelopment' +version = '1.0' + +repositories { + mavenCentral() + maven { + name = 'papermc-repo' + url = 'https://repo.papermc.io/repository/maven-public/' + } + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/content/groups/public/' + } +} + +dependencies { + compileOnly 'io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT' +} + +def targetJavaVersion = 17 +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } +} + +tasks.withType(JavaCompile).configureEach { + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + options.release = targetJavaVersion + } +} + +processResources { + def props = [version: version] + inputs.properties props + filteringCharset 'UTF-8' + filesMatching('plugin.yml') { + expand props + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2e6e589 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..c53aefa --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/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/master/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 + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +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 + which java >/dev/null 2>&1 || 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 + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + 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 + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# 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" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..8435cac --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'TypeSelector' diff --git a/src/main/java/io/github/simplexdevelopment/TypeListener.java b/src/main/java/io/github/simplexdevelopment/TypeListener.java new file mode 100644 index 0000000..fc4b011 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/TypeListener.java @@ -0,0 +1,118 @@ +package io.github.simplexdevelopment; + +import io.github.simplexdevelopment.api.GUIAction; +import io.github.simplexdevelopment.api.GUIWindow; +import io.github.simplexdevelopment.mob.*; +import org.bukkit.entity.*; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.UUID; + +public class TypeListener implements Listener { + @EventHandler + public void interact(@NotNull PlayerInteractEntityEvent e) { + if (!e.getPlayer().hasPermission("selector.menu")) { + return; + } + // + final Entity ent = e.getRightClicked(); + final EntityType type = ent.getType(); + final Player p = e.getPlayer(); + // + if (p.isSneaking()) { + switch (type) { + case AXOLOTL -> { + Axolotl axolotl = (Axolotl) ent; + // + new AxolotlType(axolotl, p).openMenu(); + } + case CAT -> { + Cat cat = (Cat) ent; + // + new CatType(cat, p).openMenu(); + } + case FOX -> { + Fox fox = (Fox) ent; + // + new FoxType(fox, p); + } + case FROG -> { + Frog frog = (Frog) ent; + // + new FrogType(frog, p).openMenu(); + } + case HORSE -> { + Horse horse = (Horse) ent; + // + new HorseType(horse, p).openMenu(); + } + case LLAMA -> { + Llama llama = (Llama) ent; + // + new LlamaType(llama, p).openMenu(); + } + case PANDA -> { + Panda panda = (Panda) ent; + // + new PandaType(panda, p).openMenu(); + } + case PARROT -> { + Parrot parrot = (Parrot) ent; + // + new ParrotType(parrot, p).openMenu(); + } + case RABBIT -> { + Rabbit rabbit = (Rabbit) ent; + // + new RabbitType(rabbit, p).openMenu(); + } + case SHEEP -> { + Sheep sheep = (Sheep) ent; + // + new SheepType(sheep, p).openMenu(); + } + case TROPICAL_FISH -> { + TropicalFish fish = (TropicalFish) ent; + // + new TropicalFishType(fish, p).openMenu(); + } + case VILLAGER -> { + Villager villager = (Villager) ent; + // + new VillagerType(villager, p).openMenu(); + } + default -> { + // We don't need anything here, because we don't want to do anything if it doesn't have a variant. + } + } + } + } + + @EventHandler + public void onClick(@NotNull InventoryClickEvent e) { + if (!(e.getWhoClicked() instanceof Player player)) { return; } + // + UUID pUUID = player.getUniqueId(); + UUID invUUID = GUIWindow.getOpenInvs().get(pUUID); + if (invUUID != null) { + e.setCancelled(true); + GUIWindow menu = GUIWindow.getInvByUUID().get(invUUID); + GUIAction action = menu.getActions().get(e.getSlot()); + if (action != null) { + action.onClick(player); + } + } + } + + @EventHandler + public void onClose(@NotNull InventoryCloseEvent e) { + Player player = (Player) e.getPlayer(); + UUID pUUID = player.getUniqueId(); + GUIWindow.getOpenInvs().remove(pUUID); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/TypeSelector.java b/src/main/java/io/github/simplexdevelopment/TypeSelector.java new file mode 100644 index 0000000..8e873b2 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/TypeSelector.java @@ -0,0 +1,17 @@ +package io.github.simplexdevelopment; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +public final class TypeSelector extends JavaPlugin { + @Override + public void onEnable() { + this.getServer().getPluginManager().registerEvents(new TypeListener(), this); + Bukkit.getLogger().info("TypeSelector has been enabled!"); + } + + @Override + public void onDisable() { + Bukkit.getLogger().info("TypeSelector has been disabled!"); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/api/GUIAction.java b/src/main/java/io/github/simplexdevelopment/api/GUIAction.java new file mode 100644 index 0000000..512f1d3 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/api/GUIAction.java @@ -0,0 +1,8 @@ +package io.github.simplexdevelopment.api; + +import org.bukkit.entity.Player; + +@FunctionalInterface +public interface GUIAction { + void onClick(Player player); +} diff --git a/src/main/java/io/github/simplexdevelopment/api/GUIWindow.java b/src/main/java/io/github/simplexdevelopment/api/GUIWindow.java new file mode 100644 index 0000000..f7f25f3 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/api/GUIWindow.java @@ -0,0 +1,76 @@ +package io.github.simplexdevelopment.api; + +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public interface GUIWindow extends InventoryHolder, Listener { + Map invByUUID = new HashMap<>(); + Map openInventories = new HashMap<>(); + + static Map getInvByUUID() { + return invByUUID; + } + + static Map getOpenInvs() { + return openInventories; + } + + void openMenu(); + + UUID getUUID(); + + Map getActions(); + + void setItem(int slot, @NotNull ItemStack itemStack, @Nullable GUIAction action); + + void clear(); + + void open(@NotNull Player p); + + default void delete() { + Bukkit.getOnlinePlayers().forEach((p) -> { + UUID u = openInventories.get(p.getUniqueId()); + if (u.equals(getUUID())) { + p.closeInventory(); + } + }); + invByUUID.remove(getUUID()); + } + + default void setItem(int slot, @NotNull ItemStack itemStack) { + setItem(slot, itemStack, null); + } + + default ItemStack newItem(@NotNull Material mat, String name) { + return newItem(mat, name, ""); + } + + default ItemStack newItem(@NotNull Material mat, String name, String... lore) { + ItemStack item = new ItemStack(mat); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.displayName(Component.text(name)); + ArrayList lores = new ArrayList<>(); + for (String s : lore) { + lores.add(Component.text(s)); + } + meta.lore(lores); + item.setItemMeta(meta); + } + return item; + } +} diff --git a/src/main/java/io/github/simplexdevelopment/inv/AbstractGUI.java b/src/main/java/io/github/simplexdevelopment/inv/AbstractGUI.java new file mode 100644 index 0000000..e5ea6b3 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/inv/AbstractGUI.java @@ -0,0 +1,89 @@ +package io.github.simplexdevelopment.inv; + +import io.github.simplexdevelopment.api.GUIAction; +import io.github.simplexdevelopment.api.GUIWindow; +import io.github.simplexdevelopment.util.DisplayableSlotEnum; +import io.github.simplexdevelopment.util.Tuple; +import io.github.simplexdevelopment.util.Utility; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +import java.util.*; +import java.util.stream.Collectors; + +public abstract class AbstractGUI implements GUIWindow { + private final Inventory INV; + private final Map ACTIONS; + private final UUID uuid; + private final int[] slots = Utility.range(0, 44); + private final Map slotMap = DisplayableSlotEnum.getSlotMaterialMap(); + private final Set> tupleList = new HashSet<>(); + + protected AbstractGUI(String name) { + this.uuid = UUID.randomUUID(); + this.INV = Bukkit.createInventory(null, 45, Component.text(name)); + this.ACTIONS = new HashMap<>(); + GUIWindow.getInvByUUID().put(getUUID(), this); + } + + @Override + public Map getActions() { + return ACTIONS; + } + + @Override + public UUID getUUID() { + return uuid; + } + + @Override + public Inventory getInventory() { + return INV; + } + + @Override + public void setItem(int slot, @NotNull ItemStack itemStack, GUIAction action) { + INV.setItem(slot, itemStack); + if (action != null) { + ACTIONS.put(slot, action); + } + } + + @Override + public void clear() { + INV.clear(); + } + + @Override + public void open(@NotNull Player p) { + p.openInventory(INV); + openInventories.put(p.getUniqueId(), getUUID()); + } + + public void createInjection(int slot, String name, GUIAction action) { + tupleList.add(new Tuple<>(slot, name, action)); + } + + public void dynamicSlotAssignment(Set> integerGUIActionTupleList) { + Set availableSlots = Arrays.stream(slots).boxed().collect(Collectors.toSet()); + int[] slotMapSelector = {0}; + integerGUIActionTupleList.forEach((tuple) -> { + int slot = tuple.getA(); + GUIAction action = tuple.getC(); + if (availableSlots.contains(slot)) { + setItem(slot, newItem(slotMap.get(slotMapSelector[0]), tuple.getB()), action); + availableSlots.remove(slot); + slotMapSelector[0]++; + } + }); + } + + public Set> getTupleList() { + return tupleList; + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/AxolotlType.java b/src/main/java/io/github/simplexdevelopment/mob/AxolotlType.java new file mode 100644 index 0000000..3882dbc --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/AxolotlType.java @@ -0,0 +1,31 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Axolotl; +import org.bukkit.entity.Player; + +public class AxolotlType extends AbstractGUI { + private final Axolotl axolotl; + private final Player player; + + public AxolotlType(Axolotl axolotl, Player player) { + super("Axolotl Type"); + this.axolotl = axolotl; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Axolotl.Variant.values(), variant -> { + this.createInjection(x[0], variant.name(), action -> { + axolotl.setVariant(variant); + action.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/CatType.java b/src/main/java/io/github/simplexdevelopment/mob/CatType.java new file mode 100644 index 0000000..5ffa6d3 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/CatType.java @@ -0,0 +1,31 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Cat; +import org.bukkit.entity.Player; + +public class CatType extends AbstractGUI { + private final Cat cat; + private final Player player; + + public CatType(Cat cat, Player player) { + super("Cat Type"); + this.cat = cat; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Cat.Type.values(), type -> { + this.createInjection(x[0], type.name(), p -> { + cat.setCatType(type); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/FoxType.java b/src/main/java/io/github/simplexdevelopment/mob/FoxType.java new file mode 100644 index 0000000..a7715d1 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/FoxType.java @@ -0,0 +1,31 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Fox; +import org.bukkit.entity.Player; + +public class FoxType extends AbstractGUI { + private final Fox fox; + private final Player player; + + public FoxType(Fox fox, Player player) { + super("Fox Variant"); + this.fox = fox; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Fox.Type.values(), type -> { + this.createInjection(x[0], type.name(), s -> { + fox.setFoxType(type); + s.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/FrogType.java b/src/main/java/io/github/simplexdevelopment/mob/FrogType.java new file mode 100644 index 0000000..7da9516 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/FrogType.java @@ -0,0 +1,31 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Frog; +import org.bukkit.entity.Player; + +public class FrogType extends AbstractGUI { + private final Frog frog; + private final Player player; + + public FrogType(Frog frog, Player player) { + super("Frog Type"); + this.frog = frog; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Frog.Variant.values(), type -> { + this.createInjection(x[0], type.name(), p -> { + frog.setVariant(type); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/HorseType.java b/src/main/java/io/github/simplexdevelopment/mob/HorseType.java new file mode 100644 index 0000000..cc79755 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/HorseType.java @@ -0,0 +1,59 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Horse; +import org.bukkit.entity.Player; + +public class HorseType extends AbstractGUI { + private final Horse horse; + private final Player player; + private final HorseStyle horseStyle; + + public HorseType(Horse horse, Player player) { + super("Horse Type"); + this.horse = horse; + this.player = player; + this.horseStyle = new HorseStyle(horse, player); + } + + @Override + public void openMenu() { + int[] x = {0}; + Utility.forEach(Horse.Color.values(), color -> { + this.createInjection(x[0], color.name(), p -> { + horse.setColor(color); + horseStyle.openMenu(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + + } + + private final class HorseStyle extends AbstractGUI { + private final Horse horse; + private final Player player; + + public HorseStyle(Horse horse, Player player) { + super("Horse Style"); + this.horse = horse; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Horse.Style.values(), style -> { + this.createInjection(x[0], style.name(), p -> { + horse.setStyle(style); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/LlamaType.java b/src/main/java/io/github/simplexdevelopment/mob/LlamaType.java new file mode 100644 index 0000000..431a62b --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/LlamaType.java @@ -0,0 +1,31 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Llama; +import org.bukkit.entity.Player; + +public class LlamaType extends AbstractGUI { + private final Llama llama; + private final Player player; + + public LlamaType(Llama llama, Player player) { + super("Llama Type"); + this.llama = llama; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Llama.Color.values(), color -> { + this.createInjection(x[0], color.name(), p-> { + llama.setColor(color); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/PandaType.java b/src/main/java/io/github/simplexdevelopment/mob/PandaType.java new file mode 100644 index 0000000..3f5f5a2 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/PandaType.java @@ -0,0 +1,57 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Panda; +import org.bukkit.entity.Player; + +public class PandaType extends AbstractGUI { + private final Panda panda; + private final Player player; + private final PandaDiminutive diminutive; + + public PandaType(Panda panda, Player player) { + super("Panda"); + this.panda = panda; + this.player = player; + this.diminutive = new PandaDiminutive(panda, player); + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Panda.Gene.values(), gene -> { + this.createInjection(x[0], gene.name(), p -> { + panda.setMainGene(gene); + diminutive.openMenu(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + private static final class PandaDiminutive extends AbstractGUI { + private final Panda panda; + private final Player player; + + public PandaDiminutive(Panda panda, Player player) { + super("Panda Diminutive"); + this.panda = panda; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Panda.Gene.values(), gene -> { + this.createInjection(x[0], gene.name(), p -> { + panda.setHiddenGene(gene); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/ParrotType.java b/src/main/java/io/github/simplexdevelopment/mob/ParrotType.java new file mode 100644 index 0000000..eebcded --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/ParrotType.java @@ -0,0 +1,31 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Parrot; +import org.bukkit.entity.Player; + +public class ParrotType extends AbstractGUI { + private final Parrot parrot; + private final Player player; + + public ParrotType(Parrot parrot, Player player) { + super("Parrot Type"); + this.parrot = parrot; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Parrot.Variant.values(), variant -> { + this.createInjection(x[0], variant.name(), action -> { + parrot.setVariant(variant); + action.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/RabbitType.java b/src/main/java/io/github/simplexdevelopment/mob/RabbitType.java new file mode 100644 index 0000000..7d3125f --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/RabbitType.java @@ -0,0 +1,31 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.entity.Player; +import org.bukkit.entity.Rabbit; + +public class RabbitType extends AbstractGUI { + private final Rabbit rabbit; + private final Player player; + + public RabbitType(Rabbit rabbit, Player player) { + super("Rabbit Type"); + this.rabbit = rabbit; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Rabbit.Type.values(), type -> { + this.createInjection(x[0], type.name(), p -> { + rabbit.setRabbitType(type); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/SheepType.java b/src/main/java/io/github/simplexdevelopment/mob/SheepType.java new file mode 100644 index 0000000..49caf6c --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/SheepType.java @@ -0,0 +1,32 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.DyeColor; +import org.bukkit.entity.Player; +import org.bukkit.entity.Sheep; + +public class SheepType extends AbstractGUI { + private final Sheep sheep; + private final Player player; + + public SheepType(Sheep sheep, Player player) { + super("Rabbit Type"); + this.sheep = sheep; + this.player = player; + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(DyeColor.values(), color -> { + this.createInjection(x[0], color.name(), p -> { + sheep.setColor(color); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/TropicalFishType.java b/src/main/java/io/github/simplexdevelopment/mob/TropicalFishType.java new file mode 100644 index 0000000..022fd8f --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/TropicalFishType.java @@ -0,0 +1,84 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.DyeColor; +import org.bukkit.entity.Player; +import org.bukkit.entity.TropicalFish; + +public class TropicalFishType extends AbstractGUI { + private final TropicalFish fish; + private final Player player; + private final FishBodyColor bodyColor; + private final FishPatternColor patternColor; + + public TropicalFishType(TropicalFish fish, Player player) { + super("Tropical Fish"); + this.fish = fish; + this.player = player; + this.bodyColor = new FishBodyColor(fish, player); + this.patternColor = new FishPatternColor(fish, player); + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(TropicalFish.Pattern.values(), pattern -> { + this.createInjection(x[0], pattern.name(), p -> { + fish.setPattern(pattern); + bodyColor.openMenu(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + + private final class FishBodyColor extends AbstractGUI { + private final TropicalFish fish; + private final Player player; + + public FishBodyColor(TropicalFish fish, Player player) { + super("Body Color"); + this.fish = fish; + this.player = player; + } + + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(DyeColor.values(), dyeColor -> { + this.createInjection(x[0], dyeColor.name(), p -> { + fish.setBodyColor(dyeColor); + patternColor.openMenu(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + } + + private final class FishPatternColor extends AbstractGUI { + private final TropicalFish fish; + private final Player player; + + public FishPatternColor(TropicalFish fish, Player player) { + super("Body Color"); + this.fish = fish; + this.player = player; + } + + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(DyeColor.values(), dyeColor -> { + this.createInjection(x[0], dyeColor.name(), p -> { + fish.setPatternColor(dyeColor); + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + } +} diff --git a/src/main/java/io/github/simplexdevelopment/mob/VillagerType.java b/src/main/java/io/github/simplexdevelopment/mob/VillagerType.java new file mode 100644 index 0000000..f672dd4 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/mob/VillagerType.java @@ -0,0 +1,59 @@ +package io.github.simplexdevelopment.mob; + +import io.github.simplexdevelopment.inv.AbstractGUI; +import io.github.simplexdevelopment.util.Utility; +import org.bukkit.DyeColor; +import org.bukkit.entity.Player; +import org.bukkit.entity.Villager; + +public class VillagerType extends AbstractGUI { + private final Villager villager; + private final Player player; + private final VillagerProfession villagerProfession; + + public VillagerType(Villager villager, Player player) { + super("Rabbit Type"); + this.villager = villager; + this.player = player; + this.villagerProfession = new VillagerProfession(villager, player); + } + + @Override + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Villager.Type.values(), type -> { + this.createInjection(x[0], type.name(), p -> { + villager.setVillagerType(type); + villagerProfession.openMenu(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + + private final class VillagerProfession extends AbstractGUI { + private final Villager villager; + private final Player player; + + public VillagerProfession(Villager villager, Player player) { + super("Body Color"); + this.villager = villager; + this.player = player; + } + + public void openMenu() { + int[] x = {Utility.getNextEmptySlot(22)}; + Utility.forEach(Villager.Profession.values(), profession -> { + this.createInjection(x[0], profession.name(), p -> { + villager.setProfession(profession); + villager.setVillagerExperience(1); // This prevents loss of profession. + p.closeInventory(); + }); + x[0] = Utility.getNextEmptySlot(x[0]); + }); + this.dynamicSlotAssignment(this.getTupleList()); + this.open(player); + } + } +} \ No newline at end of file diff --git a/src/main/java/io/github/simplexdevelopment/util/Context.java b/src/main/java/io/github/simplexdevelopment/util/Context.java new file mode 100644 index 0000000..54c4275 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/util/Context.java @@ -0,0 +1,21 @@ +package io.github.simplexdevelopment.util; + +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public class Context { + private final S state; + + protected Context(S state) { + this.state = state; + } + + public S getState() { + return state; + } + + @Contract(value = "_ -> new", pure = true) + public static @NotNull Context of(S state) { + return new Context<>(state); + } +} diff --git a/src/main/java/io/github/simplexdevelopment/util/DisplayableSlotEnum.java b/src/main/java/io/github/simplexdevelopment/util/DisplayableSlotEnum.java new file mode 100644 index 0000000..73123de --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/util/DisplayableSlotEnum.java @@ -0,0 +1,84 @@ +package io.github.simplexdevelopment.util; + +import org.bukkit.Material; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; + +public enum DisplayableSlotEnum { + ZERO(0, Material.WHITE_DYE), + ONE(1, Material.LIGHT_GRAY_DYE), + TWO(2, Material.GRAY_DYE), + THREE(3, Material.BLACK_DYE), + FOUR(4, Material.RED_DYE), + FIVE(5, Material.ORANGE_DYE), + SIX(6, Material.YELLOW_DYE), + SEVEN(7, Material.GREEN_DYE), + EIGHT(8, Material.LIME_DYE), + NINE(9, Material.CYAN_DYE), + TEN(10, Material.LIGHT_BLUE_DYE), + ELEVEN(11, Material.BLUE_DYE), + TWELVE(12, Material.PURPLE_DYE), + THIRTEEN(13, Material.MAGENTA_DYE), + FOURTEEN(14, Material.PINK_DYE), + FIFTEEN(15, Material.BROWN_DYE), + SIXTEEN(16, Material.WHITE_WOOL), + SEVENTEEN(17, Material.LIGHT_GRAY_WOOL), + EIGHTEEN(18, Material.GRAY_WOOL), + NINETEEN(19, Material.BLACK_WOOL), + TWENTY(20, Material.RED_WOOL), + TWENTY_ONE(21, Material.ORANGE_WOOL), + TWENTY_TWO(22, Material.YELLOW_WOOL), + TWENTY_THREE(23, Material.GREEN_WOOL), + TWENTY_FOUR(24, Material.LIME_WOOL), + TWENTY_FIVE(25, Material.CYAN_WOOL), + TWENTY_SIX(26, Material.LIGHT_BLUE_WOOL), + TWENTY_SEVEN(27, Material.BLUE_WOOL), + TWENTY_EIGHT(28, Material.PURPLE_WOOL), + TWENTY_NINE(29, Material.MAGENTA_WOOL), + THIRTY(30, Material.PINK_WOOL), + THIRTY_ONE(31, Material.BROWN_WOOL), + THIRTY_TWO(32, Material.WHITE_STAINED_GLASS), + THIRTY_THREE(33, Material.LIGHT_GRAY_STAINED_GLASS), + THIRTY_FOUR(34, Material.GRAY_STAINED_GLASS), + THIRTY_FIVE(35, Material.BLACK_STAINED_GLASS), + THIRTY_SIX(36, Material.RED_STAINED_GLASS), + THIRTY_SEVEN(37, Material.ORANGE_STAINED_GLASS), + THIRTY_EIGHT(38, Material.YELLOW_STAINED_GLASS), + THIRTY_NINE(39, Material.GREEN_STAINED_GLASS), + FORTY(40, Material.LIME_STAINED_GLASS), + FORTY_ONE(41, Material.CYAN_STAINED_GLASS), + FORTY_TWO(42, Material.LIGHT_BLUE_STAINED_GLASS), + FORTY_THREE(43, Material.BLUE_STAINED_GLASS), + FORTY_FOUR(44, Material.PURPLE_STAINED_GLASS); + + + private final int slot; + private final Material material; + + @Contract(pure = true) + DisplayableSlotEnum(int slot, Material material) { + this.slot = slot; + this.material = material; + } + + @Contract(pure = true) + public int getSlot() { + return slot; + } + + @Contract(pure = true) + public Material getMaterial() { + return material; + } + + public static @NotNull Map getSlotMaterialMap() { + Map slotMaterialMap = new HashMap<>(); + for (DisplayableSlotEnum displayableSlotEnum : values()) { + slotMaterialMap.put(displayableSlotEnum.getSlot(), displayableSlotEnum.getMaterial()); + } + return slotMaterialMap; + } +} diff --git a/src/main/java/io/github/simplexdevelopment/util/Pair.java b/src/main/java/io/github/simplexdevelopment/util/Pair.java new file mode 100644 index 0000000..d55175d --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/util/Pair.java @@ -0,0 +1,19 @@ +package io.github.simplexdevelopment.util; + +public class Pair { + private final X x; + private final Y y; + + public Pair(X x, Y y) { + this.x = x; + this.y = y; + } + + public X getX() { + return x; + } + + public Y getY() { + return y; + } +} diff --git a/src/main/java/io/github/simplexdevelopment/util/Tuple.java b/src/main/java/io/github/simplexdevelopment/util/Tuple.java new file mode 100644 index 0000000..fecb20d --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/util/Tuple.java @@ -0,0 +1,25 @@ +package io.github.simplexdevelopment.util; + +public class Tuple { + private final A a; + private final B b; + private final C c; + + public Tuple(A a, B b, C c) { + this.a = a; + this.b = b; + this.c = c; + } + + public A getA() { + return a; + } + + public B getB() { + return b; + } + + public C getC() { + return c; + } +} diff --git a/src/main/java/io/github/simplexdevelopment/util/Utility.java b/src/main/java/io/github/simplexdevelopment/util/Utility.java new file mode 100644 index 0000000..b7c6b17 --- /dev/null +++ b/src/main/java/io/github/simplexdevelopment/util/Utility.java @@ -0,0 +1,52 @@ +package io.github.simplexdevelopment.util; + +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.function.Consumer; + +public class Utility { + public static int[] range(int start, int end) { + int[] range = new int[end - start]; + for (int i = 0; i < range.length; i++) { + range[i] = start + i; + } + return range; + } + + public static void forEach(T @NotNull [] array, Consumer consumer) { + for (T t : array) { + consumer.accept(t); + } + } + + public static int getNextEmptySlot(int x) { + int[][] grid = new int[5][9]; // initialize the grid + + int row = 0, col = 0; + int dRow = 0, dCol = 1; + int[] dr = {0, 1, 0, -1}; + int[] dc = {1, 0, -1, 0}; + + for (int i = 0; i < 5 * 9; i++) { + if (grid[row][col] == 0) { + if (i == x) { + return row * 9 + col; + } + } + row += dRow; + col += dCol; + if (row < 0 || row >= 5 || col < 0 || col >= 9 || grid[row][col] != 0) { + row -= dRow; + col -= dCol; + int dir = (dRow == 0) ? (dCol == 1 ? 1 : 3) : (dRow == 1 ? 2 : 0); + dRow = dr[dir]; + dCol = dc[dir]; + row += dRow; + col += dCol; + } + } + + return -1; // no empty slot found + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..8db92e1 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +name: TypeSelector +version: '${version}' +main: io.github.simplexdevelopment.typeselector.TypeSelector +api-version: 1.19 +authors: [ SimplexDevelopment ] +description: A mob type selector for Paper servers.