├── .github
├── FUNDING.yml
├── pull_request_template.md
└── workflows
│ ├── publish.yml
│ └── tests.yml
├── .gitignore
├── .vscode
└── settings.json
├── README.md
├── pom.xml
├── run.sh
└── src
├── commands
├── compile.sh
├── download.sh
└── extract.sh
├── test.sh
└── util
├── args.sh
├── helpers.sh
├── menu.sh
└── print_utils.sh
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: Jacxk
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
14 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | Thank you for creating a pull request before you create the pull request make sure you've done the following:
2 | - [ ] Is the latest version R1 | R2 | R3? To check use this [page](https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-1-16/).
3 | - [ ] Have you updated the [versions README](https://github.com/Jacxk/all-spigot-nms/tree/master/spigot_versions) with the correct version?
4 | - [ ] Does it compile correctly with no errors?
5 |
6 | *Make sure that if there's more than one version, ex. 1.19, 1.19.1, etc. you use the latest for each of the R1 | R2 | R3.*\
7 | *This can be deleted if you will.*
8 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish package to GitHub Packages
2 | on:
3 | release:
4 | types: [created]
5 | workflow_dispatch:
6 | jobs:
7 | publish:
8 | runs-on: ubuntu-latest
9 | permissions:
10 | contents: read
11 | packages: write
12 | steps:
13 | - name: Checkout repository
14 | uses: actions/checkout@v2
15 |
16 | - name: Set up JDK
17 | uses: actions/setup-java@v4
18 | with:
19 | java-version: '11'
20 | distribution: 'temurin'
21 |
22 | - name: Generate needed files
23 | run: |
24 | bash run.sh -axk
25 |
26 | - name: Build with Maven
27 | run: mvn clean package
28 |
29 | - name: Publish package
30 | run: mvn --batch-mode deploy
31 | env:
32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 |
--------------------------------------------------------------------------------
/.github/workflows/tests.yml:
--------------------------------------------------------------------------------
1 | name: Build Test
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 | workflow_dispatch:
9 |
10 | jobs:
11 | linux:
12 | name: Linux Test
13 | runs-on: ubuntu-latest
14 |
15 | steps:
16 | - name: Checkout repository
17 | uses: actions/checkout@v4
18 |
19 | - name: Build Jar File and test for Linux
20 | run: |
21 | bash run.sh -t
22 | windows:
23 | name: Windows Test
24 | runs-on: windows-latest
25 |
26 | steps:
27 | - name: Checkout repository
28 | uses: actions/checkout@v4
29 |
30 | - name: Build Jar File and test for Windows
31 | run: |
32 | bash run.sh -t
33 | mac:
34 | name: Mac Test
35 | runs-on: macos-latest
36 |
37 | steps:
38 | - name: Checkout repository
39 | uses: actions/checkout@v4
40 |
41 | - name: Build Jar File and test for MacOS
42 | run: |
43 | bash run.sh -t
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # IDE
2 | .idea/
3 | *.iml
4 | .DS_STORE
5 |
6 | # Jar files
7 | *.jar
8 |
9 | # Compiler
10 | target/
11 | extracted_files/
12 | spigot_versions/
13 | out/
14 |
15 | # Extras
16 | .config
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "java.configuration.updateBuildConfiguration": "automatic"
3 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # All Spigot NMS
2 | This is a tool I created to create a single jar file that contains all of spigot NMS
3 | versions, for easy import while creating a plugin that needs to support multiple versions of the Minecraft server libraries.
4 |
5 | > ## Important
6 | > Since version `1.17.1` Spigot changed the layout and obfucation mapping method, so this tool only compiles from version *1.8* to *1.17*.
7 | > If you need support for version `1.18` and above please check out [tekanaka](https://github.com/zlataovce/takenaka).\
8 | > *I will try to find a way to include everything but nothing is promised.*
9 |
10 | ## Usage
11 | NOTE: This tool uses the `jar` command.
12 | It uses the `JAVA_HOME` or `$PATH` environmental variable to find the command.
13 | If you dont have that variable set, go to your JDK folder and copy the path then on your terminal run:
14 |
15 |
16 |
17 | #### Set JDK to `$PATH`
18 | ```shell
19 | echo 'export PATH="{JDK_PATH}/bin:$PATH"' >> ~/.zshrc
20 | ```
21 | *`~/.zshrc` is your shell profile file*
22 |
23 | #### Set JDK to `$JAVA_HOME`
24 | ```shell
25 | set JAVA_HOME="{JDK_PATH}"
26 | ```
27 |
28 |
29 |
30 | ### Compilation:
31 |
32 | * Download or clone this repository:
33 | ```
34 | git clone https://github.com/Jacxk/all-spigot-nms
35 | ```
36 |
37 | * To compile the Jar file is as easy as runing the [run.sh](run.sh) script and select one of options.
38 |
39 |
40 | Options:
41 |
42 | *If no flags are found while executing the script an interactive menu will appear. Available flags are: `-d | -e | -c | -a`*
43 |
44 | * Download `-d` - Downloads all the spigot jar files.
45 | * Extract `-e` - Extracts all the needed files from the downloaded files for compilation.
46 | * Compile `-c` - Compiles the Jar file from the extracted files.
47 | * All the above `-a` - Does all the above sequentially.
48 | * Exit - Closes everything and exits of course.
49 |
50 | *Use the arrows and enter key to navigate through the menu.*
51 |
52 | ***Extra Flags:***
53 | * `-t` - Tests that the tool works as expected and everything is included on the out jar file.
54 | * `-k` - Removes title printout
55 | * `-x` - Disables verbose out put. Only important info will be displayed.
56 |
57 |
58 | #
59 |
60 |
61 | 
62 |
63 | # Importing
64 | ### Maven:
65 | ```xml
66 |
67 | local.spigot.nms
68 | AllSpigotNMS
69 | LATEST
70 | system
71 | ${project.basedir}/PATH TO FILE HERE
72 |
73 | ```
74 | ### Gradle:
75 | ```groovy
76 | dependencies {
77 | implementation(files("/path/to/file.jar"))
78 | }
79 | ```
80 | You can now install it using the [github package](https://github.com/Jacxk?tab=packages&repo_name=all-spigot-nms)
81 | #
82 |
83 | *I'm not distributing anything, please don't sue me Mojang.*
84 |
85 | #### Spigot NMS and Minecraft Versions:
86 | * 1.8 and 1.9 Look at [this page](https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-legacy/)
87 | * 1.10 up Look at [this page](https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-1-10-1-15/)
88 | * 1.16 and up Look at [this page](https://www.spigotmc.org/wiki/spigot-nms-and-minecraft-versions-1-16/)
89 |
90 |
91 |
92 | NMS Versions with its latest minecraft version.
93 |
94 | *Each version as a link to its download.*
95 |
96 | | Version | R1 | R2 | R3 |
97 | |---------|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
98 | | 1.8 | [1.8](https://cdn.getbukkit.org/spigot/spigot-1.8-R0.1-SNAPSHOT-latest.jar) | [1.8.3](https://cdn.getbukkit.org/spigot/spigot-1.8.3-R0.1-SNAPSHOT-latest.jar) | [1.8.8](https://cdn.getbukkit.org/spigot/spigot-1.8.8-R0.1-SNAPSHOT-latest.jar) |
99 | | 1.9 | [1.9.2](https://cdn.getbukkit.org/spigot/spigot-1.9.2-R0.1-SNAPSHOT-latest.jar) | [1.9.4](https://cdn.getbukkit.org/spigot/spigot-1.9.4-R0.1-SNAPSHOT-latest.jar) | |
100 | | 1.10 | [1.10.2](https://cdn.getbukkit.org/spigot/spigot-1.10.2-R0.1-SNAPSHOT-latest.jar) | | |
101 | | 1.11 | [1.11.2](https://cdn.getbukkit.org/spigot/spigot-1.11.2.jar) | | |
102 | | 1.12 | [1.12](https://cdn.getbukkit.org/spigot/spigot-1.12.2.jar) | | |
103 | | 1.13 | [1.13](https://cdn.getbukkit.org/spigot/spigot-1.13.jar) | [1.13.2](https://cdn.getbukkit.org/spigot/spigot-1.13.2.jar) | |
104 | | 1.14 | [1.14.4](https://cdn.getbukkit.org/spigot/spigot-1.14.4.jar) | | |
105 | | 1.15 | [1.15.2](https://cdn.getbukkit.org/spigot/spigot-1.15.2.jar) | | |
106 | | 1.16 | [1.16.1](https://cdn.getbukkit.org/spigot/spigot-1.16.1.jar) | [1.16.3](https://cdn.getbukkit.org/spigot/spigot-1.16.3.jar) | [1.16.5](https://cdn.getbukkit.org/spigot/spigot-1.16.5.jar) |
107 | | 1.17 | [1.17.1](https://download.getbukkit.org/spigot/spigot-1.17.1.jar) | | |
108 | | 1.18 | [1.18.1](https://download.getbukkit.org/spigot/spigot-1.18.1.jar) | [1.18.2](https://download.getbukkit.org/spigot/spigot-1.18.2.jar) | |
109 | | 1.19 | [1.19.2](https://download.getbukkit.org/spigot/spigot-1.19.2.jar) | [1.19.3](https://download.getbukkit.org/spigot/spigot-1.19.3.jar) | [1.19.4](https://download.getbukkit.org/spigot/spigot-1.19.4.jar) |
110 | | 1.20 | [1.20.1](https://download.getbukkit.org/spigot/spigot-1.20.1.jar) | [1.20.2](https://download.getbukkit.org/spigot/spigot-1.20.2.jar) | [1.20.4](https://download.getbukkit.org/spigot/spigot-1.20.4.jar) |
111 |
112 |
113 | #
114 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.Jacxk
7 | all-spigot-nms
8 | 1.6.0
9 | jar
10 |
11 | All Spigot NMS
12 | A jar file containing all Spigot's NMS versions
13 | https://github.com/Jacxk/all-spigot-nms
14 |
15 |
16 |
17 | github
18 | GitHub Jacxk Apache Maven Packages
19 | https://maven.pkg.github.com/Jacxk/all-spigot-nms
20 |
21 |
22 |
23 |
24 |
25 |
26 | extracted_files
27 |
28 |
29 |
30 |
31 | maven-deploy-plugin
32 | 2.8.1
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/run.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Import all the util files
4 | source src/util/args.sh
5 | source src/util/helpers.sh
6 | source src/util/menu.sh
7 | source src/util/print_utils.sh
8 |
9 | # Import commands
10 | source src/commands/download.sh
11 | source src/commands/compile.sh
12 | source src/commands/extract.sh
13 |
14 | # Run the command specified by the choice made on the menu
15 | run_command() {
16 | case $1 in
17 | [0])
18 | download spigot_versions
19 | ;;
20 | [1])
21 | extract spigot_versions extracted_files
22 | ;;
23 | [2])
24 | compile extracted_files;;
25 | esac
26 |
27 | if [ $? -ne 0 ]; then
28 | echo 🔴 Something went wrong while performing the selected action!
29 | fi
30 |
31 | # Delete all output and re-render the menu
32 | if [ $2 == 1 ] && [ $is_interactive == 1 ]; then
33 | choice=89
34 | moveCursorUp
35 | delete_lines 21
36 | moveCursorDown
37 | execute
38 | fi
39 | }
40 |
41 | execute() {
42 | if [ $display_title = 1 ]; then
43 | print_title
44 | fi
45 | check_os
46 | echo
47 |
48 | flag=false
49 | # If no flag added to the command, create an interactive menu
50 | if [[ "$choice" == 89 ]]; then
51 |
52 | echo "What do would you like to do today? (Use arrow keys to move, and Enter to select)"
53 | echo
54 |
55 | # Set mode as interactive
56 | is_interactive=1
57 | # Options to display on menu
58 | local options=(
59 | "Download"
60 | "Extract"
61 | "Compile"
62 | "All the above"
63 | "Exit"
64 | )
65 | select_option "${options[@]}"
66 | choice=$?
67 |
68 | delete_lines 9
69 | else
70 | flag=true
71 | fi
72 |
73 | if [ $choice = 3 ]; then
74 | echo Performing all actions...
75 | # Run through all commands if the choice is "All the above"
76 | for i in {0..2}; do
77 | run_command $i 0
78 | if [ $? -ne 0 ]; then
79 | break
80 | fi
81 | done
82 | elif [ $choice = 4 ]; then
83 | # Exit the program
84 |
85 | delete_lines 20
86 | unset ASNMSCMD
87 |
88 | echo Bye Bye...
89 | exit 0
90 | elif [ $choice = 77 ]; then
91 | # Run tests
92 | source src/test.sh
93 | else
94 | # Run the correct command according to the choice
95 | run_command $choice 1
96 | fi
97 |
98 | unset ASNMSCMD
99 |
100 | RETURN_CODE=$?
101 | if [ $RETURN_CODE -ne 0 ]; then
102 | echo "🔴 Something went wrong while executing: '${options[$choice]}'"
103 | exit $RETURN_CODE
104 | fi
105 |
106 | }
107 |
108 | mkdir -p spigot_versions
109 | mkdir -p extracted_files
110 |
111 | execute
--------------------------------------------------------------------------------
/src/commands/compile.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Run this to compile the jar using the extracted files.
4 |
5 | # Command to be used depending on OS
6 | cmd="$(printenv ASNMSCMD)"
7 |
8 | # If cmd is empty default to jar
9 | if [ -z "$cmd" ]; then
10 | cmd=jar
11 | fi
12 |
13 | compile() {
14 | local output_folder='out'
15 | local output_file=all-spigot-nms.jar
16 | local input_folder=$1
17 | local output="$output_folder/$output_file"
18 |
19 | if [ ! "$(ls -A $input_folder)" ]; then
20 | echo "The folder: $input_folder/ does not exist or is empty."
21 | return 3
22 | fi
23 |
24 | mkdir -p $output_folder
25 | echo Creating $output_file
26 |
27 | # Remove file if it exists
28 | rm -f -- $output
29 | # Bundle all the files in a jar file
30 | "$cmd" -cf $output -C "$input_folder" .
31 |
32 | RETURN_CODE=$?
33 | if [ $RETURN_CODE -ne 0 ]; then
34 | return 3
35 | fi
36 |
37 | delete_lines 1
38 | echo ✅ File created at: $output
39 | }
40 |
--------------------------------------------------------------------------------
/src/commands/download.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Run this to download all the available jars.
4 |
5 | # All the NMS versions available
6 | legacy_versions=(
7 | "spigot-1.8-R0.1-SNAPSHOT-latest"
8 | "spigot-1.8.3-R0.1-SNAPSHOT-latest"
9 | "spigot-1.8.8-R0.1-SNAPSHOT-latest"
10 | "spigot-1.9.2-R0.1-SNAPSHOT-latest"
11 | "spigot-1.9.4-R0.1-SNAPSHOT-latest"
12 | "spigot-1.10.2-R0.1-SNAPSHOT-latest"
13 | "spigot-1.11.2"
14 | "spigot-1.12.2"
15 | "spigot-1.13"
16 | "spigot-1.13.2"
17 | "spigot-1.14.4"
18 | "spigot-1.15.2"
19 | "spigot-1.16.1"
20 | "spigot-1.16.3"
21 | "spigot-1.16.5"
22 | )
23 |
24 | new_versions=(
25 | "spigot-1.17.1"
26 | )
27 |
28 | legacy_url="https://cdn.getbukkit.org/spigot"
29 | new_url="https://download.getbukkit.org/spigot"
30 |
31 | function _download_jars {
32 | local version=$1
33 | local url=$2
34 | local output=$3
35 |
36 | saveCursorPosition
37 | echo_verbose " ⭕️ $version"
38 |
39 | curl_command() {
40 | curl --fail "$url/$version".jar --output "$output/$version".jar --progress-bar
41 | }
42 |
43 | if [ $verbose -eq 0 ]; then
44 | curl_command() {
45 | curl -s "$url/$version".jar --output "$output/$version".jar > /dev/null
46 | }
47 | fi
48 |
49 | # Download the jar file to the output folder.
50 | # Also saves the cursor and replaces the printed string for less clutter
51 | if curl_command; then
52 | moveCursorToSavedPosition
53 | echo_verbose " 🟢 $version"
54 | deleteLine
55 | else
56 | # If the download fails stop the execution
57 | return 1
58 | fi
59 | }
60 |
61 | function download {
62 | check_internet_connection
63 |
64 | local output_folder=$1
65 | echo Downloading all available jar files
66 |
67 | # Download all legacy versions from cdn.getbukkit.org on dir spigot_versions
68 | for version in "${legacy_versions[@]}"; do
69 | _download_jars $version $legacy_url $output_folder
70 |
71 | RETURN_CODE=$?
72 | if [ $RETURN_CODE -ne 0 ]; then
73 | return $RETURN_CODE
74 | fi
75 | done
76 |
77 | # Download all versions from download.getbukkit.org on dir spigot_versions
78 | for version in "${new_versions[@]}"; do
79 | _download_jars $version $new_url $output_folder
80 |
81 | RETURN_CODE=$?
82 | if [ $RETURN_CODE -ne 0 ]; then
83 | return $RETURN_CODE
84 | fi
85 | done
86 |
87 | delete_lines 24
88 | echo ✅ Successfully downloaded all available versions! Files located at: $output_folder
89 | }
90 |
--------------------------------------------------------------------------------
/src/commands/extract.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Run this to ONLY extract the jars.
4 |
5 | # Command to be used depending on OS
6 | cmd="$(printenv ASNMSCMD)"
7 |
8 | # If cmd is empty default to jar
9 | if [ -z "$cmd" ]; then
10 | cmd=jar
11 | fi
12 |
13 | extract() {
14 | local current_dir=$(pwd)
15 | local input_folder=$1
16 | local output_folder=$2
17 |
18 | if [ ! "$(ls -A $input_folder)" ]; then
19 | echo "The folder: $input_folder/ does not exist or is empty."
20 | return 3
21 | fi
22 |
23 | cd $output_folder
24 | echo "Extracting all the spigot.jar files, please wait..."
25 |
26 | # Extract all files that match in holder
27 | for filename in ../$input_folder/spigot-1.*.jar; do
28 | saveCursorPosition
29 | echo_verbose " ⭕️ $(basename ${filename})"
30 |
31 | # Loop through the needed folder and extract them.
32 | for dir in net/minecraft/server org/bukkit/craftbukkit com/mojang; do
33 | "$cmd" -xf "$filename" "$dir"
34 |
35 | if [ $? -ne 0 ]; then
36 | return 2
37 | fi
38 | done
39 |
40 | moveCursorToSavedPosition
41 | echo_verbose " 🟢 $(basename ${filename})"
42 | done
43 |
44 | delete_lines 24
45 | echo "✅ Extraction completed! Files located at: $output_folder/"
46 | cd $current_dir
47 | }
48 |
--------------------------------------------------------------------------------
/src/test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Test if the file was created an contains all the NMS files
4 |
5 | echo Starting test...
6 | bash run.sh -axk
7 |
8 | # List containing all files
9 | legacy_list=(
10 | v1_8_R1 v1_8_R2 v1_8_R3 v1_9_R1 v1_9_R2 v1_10_R1
11 | v1_11_R1 v1_12_R1 v1_13_R1 v1_13_R2 v1_14_R1
12 | v1_15_R1 v1_16_R1 v1_16_R2 v1_16_R3
13 | )
14 | # List containing only certain files
15 | extra_list=(v1_17_R1)
16 |
17 | jar_file="out/all-spigot-nms.jar"
18 | missing_folders=0
19 |
20 | function join_by {
21 | local d=${1-} f=${2-}
22 | if shift 2; then
23 | printf %s "$f" "${@/#/$d}"
24 | fi
25 | }
26 |
27 | function check_for_folder {
28 | local folder=$1
29 | local list=(${@:2})
30 |
31 | contents=$(jar -tf "$jar_file")
32 |
33 | # Check each version in the list
34 | for version in "${list[@]}"; do
35 | if ! grep -q "$folder/$version" <<< "$contents"; then
36 | echo "'$folder/$version' is missing"
37 | missing_folders=1
38 | else
39 | echo_verbose "'$folder/$version' was found"
40 | fi
41 | done
42 | }
43 |
44 | if [ -f "$jar_file" ]; then
45 |
46 | net_minecraft_folder="net/minecraft/server"
47 | org_bukkit_folder="org/bukkit/craftbukkit"
48 |
49 | concated_list=("${legacy_list[@]}" "${extra_list[@]}")
50 |
51 | check_for_folder $org_bukkit_folder ${concated_list[@]}
52 | check_for_folder $net_minecraft_folder ${legacy_list[@]}
53 |
54 | else
55 | echo ❌ Test failded... could not find $jar_file
56 | exit 1
57 | fi
58 |
59 | if [ $missing_folders -eq 1 ]; then
60 | echo ❌ Tests failed due to contents missing. Check above to see which.
61 | exit 1
62 | fi
63 |
64 | echo ✅ Test completed. No issues where found.
--------------------------------------------------------------------------------
/src/util/args.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | choice=89
4 | is_interactive=0
5 | display_title=1
6 | verbose=1
7 |
8 | while getopts ":adecxtk" OPTION; do
9 | case $OPTION in
10 | d)
11 | choice=0;;
12 | e)
13 | choice=1;;
14 | c)
15 | choice=2;;
16 | a)
17 | choice=3;;
18 | x)
19 | verbose=0
20 | echo Verbose is off.
21 | ;;
22 | t)
23 | choice=77;;
24 | k)
25 | display_title=0;;
26 | *)
27 | choice=89;;
28 | esac
29 |
30 | done
31 |
--------------------------------------------------------------------------------
/src/util/helpers.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | print_title() {
4 | echo "
5 | +-------------------------------------------------------------------------+
6 | | _ _ _____ _ _ _ _ __ __ _____ |
7 | | /\ | | | / ____| (_) | | | \ | | \/ |/ ____| |
8 | | / \ | | | | (___ _ __ _ __ _ ___ | |_ | \| | \ / | (___ |
9 | | / /\ \ | | | \___ \| '_ \| |/ _\` |/ _ \| __| | . \` | |\/| |\___ \ |
10 | | / ____ \| | | ____) | |_) | | (_| | (_) | |_ | |\ | | | |____) | |
11 | | /_/ \_\_|_| |_____/| .__/|_|\__, |\___/ \__| |_| \_|_| |_|_____/ |
12 | | | | __/ | |
13 | | |_| |___/ |
14 | | |
15 | | Created by: Jacxk |
16 | | Github: https://github.com/Jacxk/all-spigot-nms |
17 | | |
18 | | Report any issues on Github. |
19 | | |
20 | +-------------------------------------------------------------------------+
21 | "
22 | }
23 |
24 | # Check which OS is the command running on
25 | check_os() {
26 | OS=$(uname)
27 | echo Detected OS: $OS.
28 |
29 | # Check if the user is running inside a shell terminal
30 | if [ $? -ne 0 ]; then
31 | echo It looks like you\'re running the script outside a shell
32 | exit 1
33 | fi
34 |
35 | export_cmd() {
36 | # Check the current OS to set the correct path to `jar`
37 | if [[ $OS == Linux* ]] || [[ $OS == Darwin* ]]; then
38 | export ASNMSCMD="$java_home\bin\jar"
39 | else
40 | export ASNMSCMD="$java_home\bin\jar.exe"
41 | fi
42 | }
43 |
44 | # Check if the jar command is available
45 | if ! jar --version > /dev/null; then
46 | java_home="$(printenv JAVA_HOME)"
47 |
48 | # Check if the $JAVA_HOME variable is set
49 | if [ -z "$java_home" ]; then
50 | # If not set, check the $PATH and see if it's added
51 | if [[ $PATH == *'jdk/bin'* ]]; then
52 | echo Could not find the JDK on \$JAVA_HOME or in \$PATH
53 | exit 1
54 | fi
55 |
56 | export_cmd
57 | fi
58 | fi
59 | # Use `jar` if the JDK is in $PATH
60 | export ASNMSCMD=jar
61 |
62 | echo "Using '$ASNMSCMD' for compilation"
63 | }
64 |
65 | check_internet_connection() {
66 | curl -sI https://example.com/ > /dev/null
67 | if [[ $? -ne 0 ]]; then
68 | echo There\'s no internet connection to download the Jar files
69 | exit 1
70 | fi
71 | }
72 |
73 | delete_lines() {
74 | if [ $verbose -eq 1 ]; then
75 | local range="$1"
76 | for ((i = 1; i <= range; i++)); do
77 | moveCursorUp
78 | deleteLine
79 | done
80 | fi
81 | }
82 |
83 | echo_verbose() {
84 | if [ $verbose -eq 1 ]; then
85 | echo $@
86 | fi
87 | }
--------------------------------------------------------------------------------
/src/util/menu.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | # Thanks to https://unix.stackexchange.com/a/415155
4 |
5 | # Renders a text based list of options that can be selected by the
6 | # user using up, down and enter keys and returns the chosen option.
7 | #
8 | # Arguments : list of options, maximum of 256
9 | # "opt1" "opt2" ...
10 | # Return value: selected index (0 for opt1, 1 for opt2 ...)
11 | select_option() {
12 |
13 | # little helpers for terminal print control and key input
14 | ESC=$(printf "\033")
15 | cursor_blink_on() { printf "$ESC[?25h"; }
16 | cursor_blink_off() { printf "$ESC[?25l"; }
17 | cursor_to() { printf "$ESC[$1;${2:-1}H"; }
18 | print_option() { printf " $1 "; }
19 | print_selected() { printf " $ESC[7m $1 $ESC[27m"; }
20 | get_cursor_row() {
21 | IFS=';' read -sdR -p $'\E[6n' ROW COL
22 | echo ${ROW#*[}
23 | }
24 | key_input() {
25 | read -s -n3 key 2>/dev/null >&2
26 | if [[ $key == $ESC[A ]]; then echo up; fi
27 | if [[ $key == $ESC[B ]]; then echo down; fi
28 | if [[ $key == "" ]]; then echo enter; fi
29 | }
30 |
31 | # initially print empty new lines (scroll down if at bottom of screen)
32 | for opt; do printf "\n"; done
33 |
34 | # determine current screen position for overwriting the options
35 | local lastrow=$(get_cursor_row)
36 | local startrow=$(($lastrow - $#))
37 |
38 | # ensure cursor and input echoing back on upon a ctrl+c during read -s
39 | trap "cursor_blink_on; stty echo; printf '\n'; exit" 2
40 | cursor_blink_off
41 |
42 | local selected=0
43 | while true; do
44 | # print options by overwriting the last lines
45 | local idx=0
46 | for opt; do
47 | cursor_to $(($startrow + $idx))
48 | if [ $idx -eq $selected ]; then
49 | print_selected "$opt"
50 | else
51 | print_option "$opt"
52 | fi
53 | ((idx++))
54 | done
55 |
56 | # user key control
57 | case $(key_input) in
58 | enter) break ;;
59 | up)
60 | ((selected--))
61 | if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi
62 | ;;
63 | down)
64 | ((selected++))
65 | if [ $selected -ge $# ]; then selected=0; fi
66 | ;;
67 | esac
68 | done
69 |
70 | # cursor position back to normal
71 | cursor_to $lastrow
72 | printf "\n"
73 | cursor_blink_on
74 |
75 | return $selected
76 | }
77 |
--------------------------------------------------------------------------------
/src/util/print_utils.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ## +-----------------------------------+-----------------------------------+
4 | ## | |
5 | ## | Copyright (c) 2019-2024, Andres Gongora . |
6 | ## | |
7 | ## | This program is free software: you can redistribute it and/or modify |
8 | ## | it under the terms of the GNU General Public License as published by |
9 | ## | the Free Software Foundation, either version 3 of the License, or |
10 | ## | (at your option) any later version. |
11 | ## | |
12 | ## | This program is distributed in the hope that it will be useful, |
13 | ## | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | ## | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | ## | GNU General Public License for more details. |
16 | ## | |
17 | ## | You should have received a copy of the GNU General Public License |
18 | ## | along with this program. If not, see . |
19 | ## | |
20 | ## +-----------------------------------------------------------------------+
21 |
22 |
23 | ##
24 | ## DESCRIPTION
25 | ## ===========
26 | ##
27 | ## Helper functions to print on different places of the screen
28 |
29 | ##==================================================================================================
30 | ## TERMINAL CURSOR
31 | ##==================================================================================================
32 |
33 | enableTerminalLineWrap()
34 | {
35 | printf '\e[?7h'
36 | }
37 |
38 |
39 | disableTerminalLineWrap()
40 | {
41 | printf '\e[?7l'
42 | }
43 |
44 |
45 | saveCursorPosition()
46 | {
47 | printf "\e[s"
48 | }
49 |
50 |
51 | moveCursorToSavedPosition()
52 | {
53 | printf "\e[u"
54 | }
55 |
56 |
57 | moveCursorToRowCol()
58 | {
59 | local row=$1
60 | local col=$2
61 | printf "\e[${row};${col}H"
62 | }
63 |
64 |
65 | moveCursorHome()
66 | {
67 | printf "\e[;H"
68 | }
69 |
70 |
71 | moveCursorUp()
72 | {
73 | local inc=$1
74 | if [ -z "$inc" ]; then
75 | printf "\e[1A"
76 | elif [ $inc -gt 0 ]; then
77 | printf "\e[${inc}A"
78 | fi
79 | }
80 |
81 |
82 | moveCursorDown()
83 | {
84 | local inc=$1
85 | if [ -z "$inc" ]; then
86 | printf "\e[1B"
87 | elif [ $inc -gt 0 ]; then
88 | printf "\e[${inc}B"
89 | fi
90 | }
91 |
92 |
93 | moveCursorRight()
94 | {
95 | local inc=$1
96 | if [ -z "$inc" ]; then
97 | printf "\e[1C"
98 | elif [ $inc -gt 0 ]; then
99 | printf "\e[${inc}D"
100 | fi
101 | }
102 |
103 |
104 | moveCursorLeft()
105 | {
106 | local inc=$1
107 | if [ -z "$inc" ]; then
108 | printf "\e[1D"
109 | elif [ $inc -gt 0 ]; then
110 | printf "\e[${inc}C"
111 | fi
112 | }
113 |
114 | deleteLine()
115 | {
116 | printf "\33[2K\r"
117 | }
118 |
119 | ##==================================================================================================
120 | ## FUNCTIONS
121 | ##==================================================================================================
122 |
123 | ##------------------------------------------------------------------------------
124 | ##
125 | getTerminalNumRows()
126 | {
127 | tput lines
128 | }
129 |
130 |
131 |
132 | ##------------------------------------------------------------------------------
133 | ##
134 | getTerminalNumCols()
135 | {
136 | tput cols
137 | }
138 |
139 |
140 |
141 | ##------------------------------------------------------------------------------
142 | ##
143 | getTextNumRows()
144 | {
145 | ## COUNT ROWS
146 | local rows=$(echo -e "$1" | wc -l )
147 | echo "$rows"
148 | }
149 |
150 |
151 |
152 | ##------------------------------------------------------------------------------
153 | ##
154 | getTextNumCols()
155 | {
156 | ## COUNT COLUMNS - Remove color sequences before counting
157 | ## 's/\x1b\[[0-9;]*m//g' to remove formatting sequences (\e=\033=\x1b)
158 | local columns=$(echo -e "$1" | sed 's/\x1b\[[0-9;]*m//g' | wc -L )
159 | echo "$columns"
160 | }
161 |
162 |
163 | ##------------------------------------------------------------------------------
164 | ##
165 | getTextShape()
166 | {
167 | echo "$(getTextNumRows) $(getTextNumCols)"
168 | }
169 |
170 |
171 |
172 | ##------------------------------------------------------------------------------
173 | ##
174 | printWithOffset()
175 | {
176 | local row=$1
177 | local col=$2
178 | local text=${@:3}
179 |
180 |
181 | ## MOVE CURSOR TO TARGET ROW
182 | moveCursorDown "$row"
183 |
184 |
185 | ## EDIT TEXT TO PRINT IN CORRECT COLUMN
186 | ## If spacer is 1 column or more
187 | ## - Add spacer at the start of the text
188 | ## - Add spacer after each line break
189 | ## Otherwise, do not alter the text
190 | if [ $col -gt 0 ]; then
191 | col_spacer="\\\\e[${col}C"
192 | local text=$(echo "$text" |\
193 | sed "s/^/$col_spacer/g;s/\\\\n/\\\\n$col_spacer/g")
194 | fi
195 |
196 |
197 | ## PRINT TEXT WITHOUT LINE WRAP
198 | disableTerminalLineWrap
199 | echo -e "${text}"
200 | enableTerminalLineWrap
201 | }
202 |
203 |
204 |
205 | ##------------------------------------------------------------------------------
206 | ##
207 | printTwoElementsSideBySide()
208 | {
209 | ## GET ELEMENTS TO PRINT
210 | local element_1=$1
211 | local element_2=$2
212 | local print_cols_max=$3
213 |
214 |
215 | ## GET PRINTABLE AREA SIZE
216 | ## If print_cols_max specified, then keep the smaller between it and
217 | ## the current terminal width
218 | local term_cols=$(getTerminalNumCols)
219 | if [ ! -z "$print_cols_max" ]; then
220 | local term_cols=$(( ( $term_cols > $print_cols_max ) ?\
221 | $print_cols_max : $term_cols ))
222 | fi
223 |
224 |
225 | ## GET ELEMENT SHAPES
226 | local e_1_cols=$(getTextNumCols "$element_1")
227 | local e_1_rows=$(getTextNumRows "$element_1")
228 | local e_2_cols=$(getTextNumCols "$element_2")
229 | local e_2_rows=$(getTextNumRows "$element_2")
230 |
231 |
232 | ## COMPUTE OPTIMAL HORIZONTAL PADDING
233 | local free_cols=$(( $term_cols - $e_1_cols - $e_2_cols ))
234 | if [ $free_cols -lt 1 ]; then
235 | local free_cols=0
236 | fi
237 |
238 | if [ $e_1_cols -gt 0 ] && [ $e_2_cols -gt 0 ]; then
239 | local h_pad=$(( $free_cols/3 ))
240 | local e_1_h_pad=$h_pad
241 | local e_2_h_pad=$(( $e_1_cols + 2*$h_pad ))
242 | elif [ $e_1_cols -gt 0 ]; then
243 | local h_pad=$(( $free_cols/2 ))
244 | local e_1_h_pad=$h_pad
245 | local e_2_h_pad=0
246 | elif [ $e_2_cols -gt 0 ]; then
247 | local h_pad=$(( $free_cols/2 ))
248 | local e_1_h_pad=0
249 | local e_2_h_pad=$h_pad
250 | else
251 | local e_1_h_pad=0
252 | local e_2_h_pad=0
253 | fi
254 |
255 |
256 | ## COMPUTE OPTIMAL VERTICAL PADDING
257 | local e_1_v_pad=$(( ( $e_1_rows > $e_2_rows ) ?\
258 | 0 : (( ($e_2_rows - $e_1_rows)/2 )) ))
259 | local e_2_v_pad=$(( ( $e_2_rows > $e_1_rows ) ?\
260 | 0 : (( ($e_1_rows - $e_2_rows)/2 )) ))
261 | local max_rows=$(( ( $e_1_rows > $e_2_rows ) ? $e_1_rows : $e_2_rows ))
262 |
263 |
264 | ## CLEAN PRINTING AREA
265 | for i in `seq $max_rows`; do printf "\n"; done
266 | moveCursorUp $max_rows
267 |
268 |
269 | saveCursorPosition
270 | printWithOffset $e_1_v_pad $e_1_h_pad "$element_1"
271 | moveCursorToSavedPosition
272 | printWithOffset $e_2_v_pad $e_2_h_pad "$element_2"
273 | moveCursorToSavedPosition
274 |
275 |
276 | ## LEAVE CURSOR AT "SAFE" POSITION
277 | moveCursorDown $(( $max_rows ))
278 | }
279 |
--------------------------------------------------------------------------------