├── .github └── workflows │ ├── deploy-development.yml │ └── deploy-master.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib ├── ProtocolSupport-Stripped-Api.jar └── README.md ├── settings.gradle.kts └── src └── main ├── java └── me │ └── tigerhix │ └── lib │ └── scoreboard │ ├── ScoreboardLib.java │ ├── common │ ├── EntryBuilder.java │ ├── Strings.java │ └── animate │ │ ├── AnimatableString.java │ │ ├── FrameAnimatedString.java │ │ ├── HighlightedString.java │ │ ├── ScrollableString.java │ │ └── StaticString.java │ ├── type │ ├── Entry.java │ ├── LegacySimpleScoreboard.java │ ├── Scoreboard.java │ ├── ScoreboardHandler.java │ └── SimpleScoreboard.java │ └── util │ └── ServerVersion.java └── resources └── plugin.yml /.github/workflows/deploy-development.yml: -------------------------------------------------------------------------------- 1 | name: Bump and Publish Development Branch 2 | 3 | on: 4 | push: 5 | branches: [ development ] 6 | workflow_dispatch: 7 | jobs: 8 | bump: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout Latest Commit 12 | uses: actions/checkout@v3 13 | - name: Grant execute permission for gradlew 14 | run: chmod +x gradlew 15 | - name: Bump Version 16 | id: bump 17 | uses: Plugily-Projects/version-bump-action@v8 18 | with: 19 | github-token: ${{ secrets.github_token }} 20 | auto-version-bump: true 21 | - name: Print Version 22 | run: "echo 'New Version: ${{steps.bump.outputs.version}}'" 23 | publish: 24 | needs: bump 25 | runs-on: ubuntu-latest 26 | steps: 27 | - name: Checkout Latest Commit 28 | uses: actions/checkout@v3 29 | with: 30 | ref: 'development' 31 | - name: Set up JDK 32 | uses: actions/setup-java@v3 33 | with: 34 | distribution: 'temurin' 35 | java-version: '17' 36 | java-package: jdk 37 | - name: Grant execute permission for gradlew 38 | run: chmod +x gradlew 39 | - name: Publish with Gradle 40 | run: ./gradlew build publishMavenPublicationToSnapshotsRepository 41 | env: 42 | MAVEN_USERNAME: ${{ secrets.SNAPSHOTSUSERNAME }} 43 | MAVEN_PASSWORD: ${{ secrets.SNAPSHOTSPASSWORD }} 44 | -------------------------------------------------------------------------------- /.github/workflows/deploy-master.yml: -------------------------------------------------------------------------------- 1 | name: Bump and Publish Master Branch 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - closed 7 | workflow_dispatch: 8 | jobs: 9 | bump: 10 | if: github.event.pull_request.merged 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout Latest Commit 14 | uses: actions/checkout@v3 15 | - name: Grant execute permission for gradlew 16 | run: chmod +x gradlew 17 | - name: Bump Version 18 | id: bump 19 | uses: Plugily-Projects/version-bump-action@v8 20 | with: 21 | github-token: ${{ secrets.github_token }} 22 | auto-version-bump: false 23 | auto-version-bump-release: true 24 | - name: Print Version 25 | run: "echo 'New Version: ${{steps.bump.outputs.version}}'" 26 | publish: 27 | needs: bump 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: Checkout Latest Commit 31 | uses: actions/checkout@v3 32 | with: 33 | ref: 'master' 34 | - name: Set up JDK 35 | uses: actions/setup-java@v3 36 | with: 37 | distribution: 'temurin' 38 | java-version: '17' 39 | java-package: jdk 40 | - name: Grant execute permission for gradlew 41 | run: chmod +x gradlew 42 | - name: Publish with Gradle 43 | run: ./gradlew build publishMavenPublicationToReleasesRepository 44 | env: 45 | MAVEN_USERNAME: ${{ secrets.RELEASESUSERNAME }} 46 | MAVEN_PASSWORD: ${{ secrets.RELEASESPASSWORD }} 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | output/ 3 | target/ 4 | ScoreboardLib.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | 167 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScoreboardLib [![Maven Repository](https://maven.plugily.xyz/api/badge/latest/releases/me/tigerhix/lib/scoreboard?color=40c14a&name=Maven&prefix=v)](https://maven.plugily.xyz/#/releases/me/tigerhix/lib/scoreboard) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Plugily-Projects_ScoreboardLib&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=Plugily-Projects_ScoreboardLib) [![Discord](https://img.shields.io/discord/345628548716822530.svg?color=7289DA&style=for-the-badge&logo=discord)](https://discord.plugily.xyz) [![Patreon]( https://img.shields.io/badge/Patreon-F96854?style=for-the-badge&logo=patreon&logoColor=white)](https://patreon.com/plugily) 2 | A flicker-free scoreboard library with support of text up to 122 chars for 1.14+ and 48 chars for 1.13- 3 | 4 | What is ScoreboardLib? 5 | -------------- 6 | ScoreboardLib is a flexiable library for adding pretty, animated scoreboards to your plugin without requiring you to figure out how to get rid of random flickers or limitations. This library is introduced to dealt with following problems in the original API and similar libraries: 7 | * Scoreboards cannot display text of more than 16 characters. 8 | * Scoreboards cannot display the same text more than once. 9 | * The scoreboard is flickering all the time. 10 | * Random disappearance of lines. 11 | 12 | Any screenshots? 13 | -------------- 14 | ![Preview](http://i.imgur.com/eJgctc9.gif) 15 | 16 | Other reasons to use ScoreboardLib? 17 | -------------- 18 | * Simple to use. You just have to decide the user interface, ScoreboardLib already got the backend handled. 19 | * Displays up to 48 characters instead of 16. 20 | * Easy to implement animated text with help of `ScrollableString` and `HighlightedString`. 21 | * Designed to be scalable and flexible. 22 | * Performant. ScoreboardLib doesn't create a scoreboard every time the content is updated. 23 | * Can be used as a standalone plugin, or be shaded into your project. 24 | 25 | How do I add it to my project? 26 | -------------- 27 | Simply add the following to your `pom.xml`. 28 | 29 | 30 | tiger-repo 31 | http://repo.tigerhix.me/content/repositories/snapshots/ 32 | 33 | 34 | 35 | me.tigerhix.lib 36 | scoreboard 37 | 1.0.1-SNAPSHOT 38 | 39 | 40 | Now you are able to create your own pretty scoreboards. 41 | 42 | How do I use it? 43 | -------------- 44 | First, you have to decide whether you use ScoreboardLib as a standalone plugin, or you just go shade it into your own plugin. For the latter case, you have to add following code to your onEnable(): 45 | 46 | ```java 47 | ScoreboardLib.setPluginInstance(this); 48 | ``` 49 | 50 | To let ScoreboardLib holds a reference to your plugin and hence able to schedule tasks, register events, etc. 51 | 52 | For the scoreboard itself, here is an usage example: 53 | 54 | ```java 55 | for (Player player: getServer().getOnlinePlayers()) { 56 | Scoreboard scoreboard = ScoreboardLib.createScoreboard(player) 57 | .setHandler(new ScoreboardHandler() { 58 | 59 | private final ScrollableString scroll = new ScrollableString(Strings.format("&aThis string is scrollable!"), 40, 0); 60 | private final HighlightedString highlighted = new HighlightedString("This string is highlighted!", "&6", "&e"); 61 | 62 | @Override 63 | public String getTitle(Player player) { 64 | return null; 65 | } 66 | 67 | @Override 68 | public List getEntries(Player player) { 69 | return new EntryBuilder() 70 | .next(" " + scroll.next()) 71 | .next(" " + highlighted.next()) 72 | .blank() 73 | .next(" &b&lCURRENT TIME MILLIS") 74 | .next(" " + System.currentTimeMillis()) 75 | .blank() 76 | .next(" &c&lCURRENT NANO TIME") 77 | .next(" " + System.nanoTime()) 78 | .blank() 79 | .next(" &7This line is equivalent to another line") 80 | .next(" &7This line is equivalent to another line") 81 | .blank() 82 | .build(); 83 | } 84 | 85 | }) 86 | .setUpdateInterval(2l); 87 | scoreboard.activate(); 88 | } 89 | ``` 90 | 91 | Which would display a scoreboard as shown in the above gif to all online players. 92 | 93 | To remove the scoreboard, use: 94 | 95 | ```java 96 | scoreboard.deactivate(); 97 | ``` 98 | 99 | That's really much of it. If you want to extend the functionalities somehow, simply create a new class that extends `SimpleScoreboard`, and start overriding methods, creating constructors, etc. 100 | 101 | License 102 | -------------- 103 | ScoreboardLib is licensed under the [GNU Lesser General Public License (Version 3)](https://github.com/TigerHix/ScoreboardLib/blob/master/LICENSE). 104 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("signing") 3 | `maven-publish` 4 | java 5 | } 6 | 7 | repositories { 8 | mavenLocal() 9 | maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") 10 | maven("https://oss.sonatype.org/content/repositories/snapshots") 11 | maven("https://oss.sonatype.org/content/repositories/central") 12 | maven(uri("https://repo.viaversion.com")) 13 | maven(uri("https://maven.plugily.xyz/releases")) 14 | maven(uri("https://maven.plugily.xyz/snapshots")) 15 | maven(uri("https://jitpack.io")) 16 | maven(uri("https://repo.maven.apache.org/maven2/")) 17 | } 18 | 19 | dependencies { 20 | implementation("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT") 21 | implementation("com.viaversion:viaversion-api:4.0.0") 22 | implementation("com.github.ProtocolSupport:ProtocolSupport:master") 23 | } 24 | 25 | 26 | group = "me.tigerhix.lib" 27 | version = "1.4.5" 28 | description = "scoreboard" 29 | java.sourceCompatibility = JavaVersion.VERSION_1_8 30 | 31 | 32 | tasks { 33 | processResources { 34 | filesMatching("**/plugin.yml") { 35 | expand(project.properties) 36 | } 37 | } 38 | 39 | javadoc { 40 | options.encoding = "UTF-8" 41 | } 42 | 43 | } 44 | 45 | publishing { 46 | repositories { 47 | maven { 48 | name = "Releases" 49 | url = uri("https://maven.plugily.xyz/releases") 50 | credentials { 51 | username = System.getenv("MAVEN_USERNAME") 52 | password = System.getenv("MAVEN_PASSWORD") 53 | } 54 | } 55 | maven { 56 | name = "Snapshots" 57 | url = uri("https://maven.plugily.xyz/snapshots") 58 | credentials { 59 | username = System.getenv("MAVEN_USERNAME") 60 | password = System.getenv("MAVEN_PASSWORD") 61 | } 62 | } 63 | } 64 | publications { 65 | create("mavenJava") { 66 | from(components["java"]) 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Plugily-Projects/ScoreboardLib/7cfd731b4827562f20ee6e8bafd73194c450519d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Use the maximum available, or set MAX_FD != -1 to use that value. 89 | MAX_FD=maximum 90 | 91 | warn () { 92 | echo "$*" 93 | } >&2 94 | 95 | die () { 96 | echo 97 | echo "$*" 98 | echo 99 | exit 1 100 | } >&2 101 | 102 | # OS specific support (must be 'true' or 'false'). 103 | cygwin=false 104 | msys=false 105 | darwin=false 106 | nonstop=false 107 | case "$( uname )" in #( 108 | CYGWIN* ) cygwin=true ;; #( 109 | Darwin* ) darwin=true ;; #( 110 | MSYS* | MINGW* ) msys=true ;; #( 111 | NONSTOP* ) nonstop=true ;; 112 | esac 113 | 114 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 115 | 116 | 117 | # Determine the Java command to use to start the JVM. 118 | if [ -n "$JAVA_HOME" ] ; then 119 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 120 | # IBM's JDK on AIX uses strange locations for the executables 121 | JAVACMD=$JAVA_HOME/jre/sh/java 122 | else 123 | JAVACMD=$JAVA_HOME/bin/java 124 | fi 125 | if [ ! -x "$JAVACMD" ] ; then 126 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 127 | 128 | Please set the JAVA_HOME variable in your environment to match the 129 | location of your Java installation." 130 | fi 131 | else 132 | JAVACMD=java 133 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 134 | 135 | Please set the JAVA_HOME variable in your environment to match the 136 | location of your Java installation." 137 | fi 138 | 139 | # Increase the maximum file descriptors if we can. 140 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 141 | case $MAX_FD in #( 142 | max*) 143 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 144 | # shellcheck disable=SC3045 145 | MAX_FD=$( ulimit -H -n ) || 146 | warn "Could not query maximum file descriptor limit" 147 | esac 148 | case $MAX_FD in #( 149 | '' | soft) :;; #( 150 | *) 151 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 152 | # shellcheck disable=SC3045 153 | ulimit -n "$MAX_FD" || 154 | warn "Could not set maximum file descriptor limit to $MAX_FD" 155 | esac 156 | fi 157 | 158 | # Collect all arguments for the java command, stacking in reverse order: 159 | # * args from the command line 160 | # * the main class name 161 | # * -classpath 162 | # * -D...appname settings 163 | # * --module-path (only if needed) 164 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 165 | 166 | # For Cygwin or MSYS, switch paths to Windows format before running java 167 | if "$cygwin" || "$msys" ; then 168 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 169 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 170 | 171 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 172 | 173 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 174 | for arg do 175 | if 176 | case $arg in #( 177 | -*) false ;; # don't mess with options #( 178 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 179 | [ -e "$t" ] ;; #( 180 | *) false ;; 181 | esac 182 | then 183 | arg=$( cygpath --path --ignore --mixed "$arg" ) 184 | fi 185 | # Roll the args list around exactly as many times as the number of 186 | # args, so each arg winds up back in the position where it started, but 187 | # possibly modified. 188 | # 189 | # NB: a `for` loop captures its iteration list before it begins, so 190 | # changing the positional parameters here affects neither the number of 191 | # iterations, nor the values presented in `arg`. 192 | shift # remove old arg 193 | set -- "$@" "$arg" # push replacement arg 194 | done 195 | fi 196 | 197 | 198 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 199 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 200 | 201 | # Collect all arguments for the java command; 202 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 203 | # shell script including quotes and variable substitutions, so put them in 204 | # double quotes to make sure that they get re-expanded; and 205 | # * put everything else in single quotes, so that it's not re-expanded. 206 | 207 | set -- \ 208 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 209 | -classpath "$CLASSPATH" \ 210 | org.gradle.wrapper.GradleWrapperMain \ 211 | "$@" 212 | 213 | # Stop when "xargs" is not available. 214 | if ! command -v xargs >/dev/null 2>&1 215 | then 216 | die "xargs is not available" 217 | fi 218 | 219 | # Use "xargs" to parse quoted args. 220 | # 221 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 222 | # 223 | # In Bash we could simply go: 224 | # 225 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 226 | # set -- "${ARGS[@]}" "$@" 227 | # 228 | # but POSIX shell has neither arrays nor command substitution, so instead we 229 | # post-process each arg (as a line of input to sed) to backslash-escape any 230 | # character that might be a shell metacharacter, then use eval to reverse 231 | # that process (while maintaining the separation between arguments), and wrap 232 | # the whole thing up as a single "set" statement. 233 | # 234 | # This will of course break if any of these variables contains a newline or 235 | # an unmatched quote. 236 | # 237 | 238 | eval "set -- $( 239 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 240 | xargs -n1 | 241 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 242 | tr '\n' ' ' 243 | )" '"$@"' 244 | 245 | exec "$JAVACMD" "$@" 246 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /lib/ProtocolSupport-Stripped-Api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Plugily-Projects/ScoreboardLib/7cfd731b4827562f20ee6e8bafd73194c450519d/lib/ProtocolSupport-Stripped-Api.jar -------------------------------------------------------------------------------- /lib/README.md: -------------------------------------------------------------------------------- 1 | _This lib folder contains external libs that are not provided by their author with Maven._ 2 | 3 | ProtocolSupport-Stripped-Api.jar ( https://github.com/ProtocolSupport/ProtocolSupport ) 4 | 5 | According to the **GNU General Public License v3.0, GNU Lesser General Public License v3.0 and GNU Affero General Public License v3.0** it is allowed to distribute the software. 6 | 7 | 8 | If you are the owner of one of these libraries feel free to contact us if you want removal of your lib ( https://discord.plugily.xyz or management@plugily.xyz ) . -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This project uses @Incubating APIs which are subject to change. 5 | */ 6 | 7 | rootProject.name = "scoreboard" 8 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/ScoreboardLib.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard; 2 | 3 | import com.viaversion.viaversion.api.Via; 4 | import com.viaversion.viaversion.api.ViaAPI; 5 | import me.tigerhix.lib.scoreboard.type.LegacySimpleScoreboard; 6 | import me.tigerhix.lib.scoreboard.type.Scoreboard; 7 | import me.tigerhix.lib.scoreboard.type.SimpleScoreboard; 8 | import me.tigerhix.lib.scoreboard.util.ServerVersion; 9 | import org.bukkit.Bukkit; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.plugin.Plugin; 12 | import org.bukkit.plugin.java.JavaPlugin; 13 | import protocolsupport.api.ProtocolSupportAPI; 14 | 15 | public final class ScoreboardLib extends JavaPlugin { 16 | 17 | private static Plugin instance; 18 | 19 | public static Plugin getPluginInstance() { 20 | return instance; 21 | } 22 | 23 | public static void setPluginInstance(Plugin instance) { 24 | if(ScoreboardLib.instance != null) return; 25 | ScoreboardLib.instance = instance; 26 | } 27 | 28 | public static Scoreboard createScoreboard(Player holder) { 29 | if(Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport")) { 30 | try { 31 | int version = ProtocolSupportAPI.getProtocolVersion(holder).getId(); 32 | if(version >= 401 && ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) { 33 | //only give player & server higher 1.12 the better scoreboard 34 | return new SimpleScoreboard(holder); 35 | } 36 | } catch(Exception ignored) { 37 | //Can't interact with protocol api 38 | } 39 | return new LegacySimpleScoreboard(holder); 40 | } 41 | if(Bukkit.getPluginManager().isPluginEnabled("ViaVersion")) { 42 | try { 43 | ViaAPI api = Via.getAPI(); // Get the API 44 | int version = api.getPlayerVersion(holder); // Get the protocol version 45 | if(version >= 401 && ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) { 46 | //only give player & server higher 1.12 the better scoreboard 47 | return new SimpleScoreboard(holder); 48 | } 49 | } catch(Exception ignored) { 50 | //Not using ViaVersion 4 or unable to get ViaVersion return LegacyBoard! 51 | } 52 | } else if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) { 53 | return new SimpleScoreboard(holder); 54 | } 55 | return new LegacySimpleScoreboard(holder); 56 | } 57 | 58 | @Override 59 | public void onEnable() { 60 | setPluginInstance(this); 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/common/EntryBuilder.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.common; 2 | 3 | import me.tigerhix.lib.scoreboard.type.Entry; 4 | import me.tigerhix.lib.scoreboard.util.ServerVersion; 5 | 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | 9 | /** 10 | * An utility to make pretty entries for the scoreboards, without calculating the positions by yourself. 11 | * 12 | * @author TigerHix 13 | */ 14 | public final class EntryBuilder { 15 | 16 | private final LinkedList entries = new LinkedList<>(); 17 | 18 | /** 19 | * Append a blank line. 20 | * 21 | * @return this 22 | */ 23 | public EntryBuilder blank() { 24 | return next(""); 25 | } 26 | 27 | /** 28 | * Append a new line with specified text. 29 | * 30 | * @param string text 31 | * @return this 32 | */ 33 | public EntryBuilder next(String string) { 34 | entries.add(new Entry(adapt(string), entries.size())); 35 | return this; 36 | } 37 | 38 | /** 39 | * Returns a map of entries. 40 | * 41 | * @return map 42 | */ 43 | public List build() { 44 | for (Entry entry : entries) { 45 | entry.setPosition(entries.size() - entry.getPosition()); 46 | } 47 | return entries; 48 | } 49 | 50 | private String adapt(String entry) { 51 | // Cut off the exceeded part if needed 52 | if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_14)) { 53 | if (entry.length() > 144) entry = entry.substring(0, 143); 54 | } else { 55 | if (entry.length() > 48) entry = entry.substring(0, 47); 56 | } 57 | return Strings.format(entry); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/common/Strings.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.common; 2 | 3 | import org.bukkit.ChatColor; 4 | 5 | public final class Strings { 6 | 7 | private Strings() { 8 | } 9 | 10 | public static String format(String string) { 11 | return ChatColor.translateAlternateColorCodes('&', string); 12 | } 13 | 14 | public static String repeat(String string, int count) { 15 | if (count == 0) { 16 | return ""; 17 | } 18 | 19 | if (count <= 1) { 20 | return string; 21 | } 22 | 23 | int len = string.length(); 24 | long longSize = (long) len * (long) count; 25 | int size = (int) longSize; 26 | 27 | if ((long) size != longSize) { 28 | throw new ArrayIndexOutOfBoundsException("Required array size too large: " + longSize); 29 | } 30 | 31 | char[] array = new char[size]; 32 | 33 | string.getChars(0, len, array, 0); 34 | 35 | int n; 36 | for (n = len; n < size - n; n <<= 1) { 37 | System.arraycopy(array, 0, array, n, n); 38 | } 39 | 40 | System.arraycopy(array, 0, array, n, size - n); 41 | return new String(array); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/common/animate/AnimatableString.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.common.animate; 2 | 3 | public interface AnimatableString { 4 | 5 | String current(); 6 | 7 | String next(); 8 | 9 | String previous(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/common/animate/FrameAnimatedString.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.common.animate; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | public class FrameAnimatedString implements AnimatableString { 8 | 9 | protected List frames = new ArrayList<>(); 10 | protected int currentFrame = -1; 11 | 12 | public FrameAnimatedString() { 13 | } 14 | 15 | public FrameAnimatedString(String... frames) { 16 | this.frames = Arrays.asList(frames); 17 | } 18 | 19 | public FrameAnimatedString(List frames) { 20 | this.frames = frames; 21 | } 22 | 23 | public void addFrame(String string) { 24 | frames.add(string); 25 | } 26 | 27 | public void setFrame(int frame, String string) { 28 | frames.set(frame, string); 29 | } 30 | 31 | public void removeFrame(String string) { 32 | frames.remove(string); 33 | } 34 | 35 | public int getCurrentFrame() { 36 | return currentFrame; 37 | } 38 | 39 | public void setCurrentFrame(int currentFrame) { 40 | this.currentFrame = currentFrame; 41 | } 42 | 43 | public int getTotalLength() { 44 | return frames.size(); 45 | } 46 | 47 | public String getString(int frame) { 48 | return frames.get(frame); 49 | } 50 | 51 | @Override 52 | public String current() { 53 | if (currentFrame == -1) return null; 54 | return frames.get(currentFrame); 55 | } 56 | 57 | @Override 58 | public String next() { 59 | currentFrame++; 60 | if (currentFrame == frames.size()) currentFrame = 0; 61 | return frames.get(currentFrame); 62 | } 63 | 64 | @Override 65 | public String previous() { 66 | currentFrame--; 67 | if (currentFrame == -1) currentFrame = frames.size() - 1; 68 | return frames.get(currentFrame); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/common/animate/HighlightedString.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.common.animate; 2 | 3 | public class HighlightedString extends FrameAnimatedString { 4 | 5 | protected String context; 6 | protected String normalFormat; 7 | protected String highlightFormat; 8 | protected String prefix = ""; 9 | protected String suffix = ""; 10 | 11 | public HighlightedString(String context, String normalFormat, String highlightFormat) { 12 | super(); 13 | this.context = context; 14 | this.normalFormat = normalFormat; 15 | this.highlightFormat = highlightFormat; 16 | generateFrames(); 17 | } 18 | 19 | public HighlightedString(String context, String normalFormat, String highlightFormat, String prefix, String suffix) { 20 | super(); 21 | this.context = context; 22 | this.normalFormat = normalFormat; 23 | this.highlightFormat = highlightFormat; 24 | this.prefix = prefix; 25 | this.suffix = suffix; 26 | generateFrames(); 27 | } 28 | 29 | protected void generateFrames() { 30 | int index = 0; 31 | while (index < context.length()) { 32 | if (context.charAt(index) != ' ') { 33 | String highlighted = normalFormat + context.substring(0, index) + highlightFormat + context.charAt(index) + normalFormat + context.substring(index + 1, context.length()); 34 | String whole = prefix + highlighted + suffix; 35 | addFrame(whole); 36 | } else { 37 | addFrame(prefix + normalFormat + context + suffix); 38 | } 39 | index++; 40 | } 41 | } 42 | 43 | public String getContext() { 44 | return context; 45 | } 46 | 47 | public String getNormalColor() { 48 | return normalFormat; 49 | } 50 | 51 | public String getHighlightColor() { 52 | return highlightFormat; 53 | } 54 | 55 | public String getPrefix() { 56 | return prefix; 57 | } 58 | 59 | public String getSuffix() { 60 | return suffix; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/common/animate/ScrollableString.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.common.animate; 2 | 3 | import org.bukkit.ChatColor; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | /** 9 | * An utility to scroll coloured strings. 10 | * 11 | * @author Chinwe 12 | */ 13 | public class ScrollableString extends FrameAnimatedString { 14 | 15 | private int position; 16 | private List list; 17 | private ChatColor color = ChatColor.RESET; 18 | 19 | public ScrollableString(String message, int width, int spaceBetween) { 20 | list = new ArrayList<>(); 21 | // String is too short for window? 22 | if (message.length() < width) { 23 | StringBuilder sb = new StringBuilder(message); 24 | while (sb.length() < width) 25 | sb.append(" "); 26 | message = sb.toString(); 27 | } 28 | // Allow for colours which add 2 to the width 29 | width -= 2; 30 | // Invalid width/space size 31 | if (width < 1) 32 | width = 1; 33 | if (spaceBetween < 0) 34 | spaceBetween = 0; 35 | // Add substrings 36 | for (int i = 0; i < message.length() - width; i++) 37 | list.add(message.substring(i, i + width)); 38 | // Add space between repeats 39 | StringBuilder space = new StringBuilder(); 40 | for (int i = 0; i < spaceBetween; ++i) { 41 | list.add(message.substring(message.length() - width + (i > width ? width : i), message.length()) + space); 42 | if (space.length() < width) 43 | space.append(" "); 44 | } 45 | // Wrap 46 | for (int i = 0; i < width - spaceBetween; ++i) 47 | list.add(message.substring(message.length() - width + spaceBetween + i, message.length()) + space + message.substring(0, i)); 48 | // Join up 49 | for (int i = 0; i < spaceBetween; i++) { 50 | if (i > space.length()) 51 | break; 52 | list.add(space.substring(0, space.length() - i) + message.substring(0, width - (spaceBetween > width ? width : spaceBetween) + i)); 53 | } 54 | } 55 | 56 | @Override 57 | public String next() { 58 | StringBuilder sb = getNext(); 59 | if (sb.charAt(sb.length() - 1) == ChatColor.COLOR_CHAR) { 60 | sb.setCharAt(sb.length() - 1, ' '); 61 | } 62 | if (sb.charAt(0) == ChatColor.COLOR_CHAR) { 63 | ChatColor c = ChatColor.getByChar(sb.charAt(1)); 64 | if (c != null) { 65 | color = c; 66 | sb = getNext(); 67 | if (sb.charAt(0) != ' ') 68 | sb.setCharAt(0, ' '); 69 | } 70 | } 71 | return color + sb.toString(); 72 | } 73 | 74 | private StringBuilder getNext() { 75 | return new StringBuilder(list.get(position++ % list.size())); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/common/animate/StaticString.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.common.animate; 2 | 3 | public class StaticString implements AnimatableString { 4 | 5 | private String string; 6 | 7 | public StaticString(String string) { 8 | this.string = string; 9 | } 10 | 11 | @Override 12 | public String current() { 13 | return string; 14 | } 15 | 16 | @Override 17 | public String previous() { 18 | return string; 19 | } 20 | 21 | @Override 22 | public String next() { 23 | return string; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/type/Entry.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.type; 2 | 3 | import me.tigerhix.lib.scoreboard.common.Strings; 4 | 5 | public class Entry { 6 | 7 | private String name; 8 | private int position; 9 | 10 | public Entry(String name, int position) { 11 | this.name = Strings.format(name); 12 | this.position = position; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | public int getPosition() { 24 | return position; 25 | } 26 | 27 | public void setPosition(int position) { 28 | this.position = position; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/type/LegacySimpleScoreboard.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.type; 2 | 3 | import com.google.common.collect.HashBasedTable; 4 | import com.google.common.collect.Table; 5 | import me.tigerhix.lib.scoreboard.common.Strings; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.Location; 9 | import org.bukkit.OfflinePlayer; 10 | import org.bukkit.entity.Player; 11 | import org.bukkit.scoreboard.DisplaySlot; 12 | import org.bukkit.scoreboard.Objective; 13 | import org.bukkit.scoreboard.Score; 14 | import org.bukkit.scoreboard.Team; 15 | 16 | import java.util.HashMap; 17 | import java.util.HashSet; 18 | import java.util.List; 19 | import java.util.Map; 20 | import java.util.Set; 21 | import java.util.UUID; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | @SuppressWarnings("deprecation") 25 | public class LegacySimpleScoreboard implements Scoreboard { 26 | 27 | private static final String TEAM_PREFIX = "Plugily_"; 28 | private static int TEAM_COUNTER = 0; 29 | 30 | private final org.bukkit.scoreboard.Scoreboard scoreboard; 31 | private final Objective objective; 32 | 33 | protected Player holder; 34 | 35 | private boolean activated; 36 | private ScoreboardHandler handler; 37 | private Map entryCache = new ConcurrentHashMap<>(); 38 | private Table playerCache = HashBasedTable.create(); 39 | private Table teamCache = HashBasedTable.create(); 40 | 41 | public LegacySimpleScoreboard(Player holder) { 42 | this.holder = holder; 43 | // Initiate the Bukkit scoreboard 44 | scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); 45 | scoreboard.registerNewObjective("plugily", "dummy").setDisplaySlot(DisplaySlot.SIDEBAR); 46 | objective = scoreboard.getObjective(DisplaySlot.SIDEBAR); 47 | } 48 | 49 | @Override 50 | public void activate() { 51 | if(activated) return; 52 | if(handler == null) throw new IllegalArgumentException("Scoreboard handler not set"); 53 | activated = true; 54 | // Set to the custom scoreboard 55 | holder.setScoreboard(scoreboard); 56 | } 57 | 58 | @Override 59 | public void deactivate() { 60 | if(!activated) return; 61 | activated = false; 62 | // Set to the main scoreboard 63 | if(holder.isOnline()) { 64 | synchronized(this) { 65 | holder.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); 66 | } 67 | } 68 | // Unregister teams that are created for this scoreboard 69 | for(Team team : teamCache.rowKeySet()) { 70 | team.unregister(); 71 | } 72 | } 73 | 74 | @Override 75 | public boolean isActivated() { 76 | return activated; 77 | } 78 | 79 | @Override 80 | public ScoreboardHandler getHandler() { 81 | return handler; 82 | } 83 | 84 | @Override 85 | public Scoreboard setHandler(ScoreboardHandler handler) { 86 | this.handler = handler; 87 | return this; 88 | } 89 | 90 | @Override 91 | public long getUpdateInterval() { 92 | throw new UnsupportedOperationException("Update interval is not supported anymore"); 93 | } 94 | 95 | @Override 96 | public LegacySimpleScoreboard setUpdateInterval(long updateInterval) { 97 | throw new UnsupportedOperationException("Update interval is not supported anymore"); 98 | } 99 | 100 | @Override 101 | public Player getHolder() { 102 | return holder; 103 | } 104 | 105 | @Override 106 | public void update() { 107 | if (!activated) { 108 | return; 109 | } 110 | 111 | if(!holder.isOnline()) { 112 | deactivate(); 113 | return; 114 | } 115 | 116 | // Title 117 | String handlerTitle = handler.getTitle(holder); 118 | String finalTitle = handlerTitle != null ? Strings.format(handlerTitle) : ChatColor.BOLD.toString(); 119 | 120 | if(!objective.getDisplayName().equals(finalTitle)) { 121 | objective.setDisplayName(finalTitle); 122 | } 123 | 124 | // Entries 125 | List passed = handler.getEntries(holder); 126 | if(passed == null) { 127 | return; 128 | } 129 | 130 | Map appeared = new HashMap<>(passed.size()); 131 | Set current = new HashSet<>(passed.size()); 132 | 133 | for(Entry entry : passed) { 134 | String key = entry.getName(); 135 | 136 | if(key.length() > 48) { 137 | key = key.substring(0, 48); 138 | } 139 | 140 | String appearance = key.length() > 16 ? key.substring(16) : key; 141 | 142 | int val = appeared.computeIfAbsent(appearance, k -> -1) + 1; 143 | appeared.put(appearance, val); 144 | 145 | FakePlayer faker = getFakePlayer(key, val); 146 | Score fakePlayerScore = objective.getScore(faker); 147 | int score = entry.getPosition(); 148 | 149 | // Set score 150 | for(String ks : scoreboard.getEntries()) { 151 | Score sc = objective.getScore(ks); 152 | 153 | if(score == sc.getScore() && !sc.getEntry().equals(fakePlayerScore.getEntry())) { 154 | scoreboard.resetScores(ks); 155 | break; 156 | } 157 | } 158 | 159 | fakePlayerScore.setScore(score); 160 | 161 | // Update references 162 | entryCache.put(faker, score); 163 | current.add(faker); 164 | } 165 | 166 | appeared.clear(); 167 | 168 | // Remove duplicated or non-existent entries 169 | for(FakePlayer fakePlayer : entryCache.keySet()) { 170 | if(!current.contains(fakePlayer)) { 171 | entryCache.remove(fakePlayer); 172 | scoreboard.resetScores(fakePlayer.toString()); 173 | } 174 | } 175 | } 176 | 177 | private FakePlayer getFakePlayer(String text, int offset) { 178 | Team team = null; 179 | String name; 180 | int length = text.length(); 181 | 182 | // If the text has a length less than 16, teams need not to be be created 183 | if(length <= 16) { 184 | name = text + Strings.repeat(" ", offset); 185 | } else { 186 | offset++; 187 | 188 | // Otherwise, iterate through the string and cut off prefix and suffix 189 | int index = 16 - offset; 190 | 191 | String prefix = text.substring(0, index); 192 | name = text.substring(index); 193 | 194 | if(name.length() > 16) { 195 | name = name.substring(0, 16); 196 | } 197 | 198 | String suffix = ""; 199 | if(length > 32) { 200 | suffix = text.substring(32 - offset); 201 | } 202 | 203 | // If teams already exist, use them 204 | for(Team other : teamCache.rowKeySet()) { 205 | if(other.getPrefix().equals(prefix) && suffix.equals(other.getSuffix())) { 206 | team = other; 207 | } 208 | } 209 | 210 | // Otherwise create them 211 | if(team == null) { 212 | team = scoreboard.registerNewTeam(TEAM_PREFIX + TEAM_COUNTER++); 213 | team.setPrefix(prefix); 214 | team.setSuffix(suffix); 215 | teamCache.put(team, prefix, suffix); 216 | } 217 | } 218 | 219 | FakePlayer fakePlayer = playerCache.get(name, offset); 220 | 221 | if(fakePlayer == null) { 222 | fakePlayer = new FakePlayer(name, team); 223 | playerCache.put(name, offset, fakePlayer); 224 | } else { 225 | if(team != null && fakePlayer.team != null) { 226 | fakePlayer.team.removePlayer(fakePlayer); 227 | } 228 | 229 | fakePlayer.team = team; 230 | } 231 | 232 | if(fakePlayer.team != null) { 233 | fakePlayer.team.addPlayer(fakePlayer); 234 | } 235 | 236 | return fakePlayer; 237 | } 238 | 239 | public Objective getObjective() { 240 | return objective; 241 | } 242 | 243 | public org.bukkit.scoreboard.Scoreboard getScoreboard() { 244 | return scoreboard; 245 | } 246 | 247 | private static class FakePlayer implements OfflinePlayer { 248 | 249 | private final UUID randomId = UUID.randomUUID(); 250 | 251 | private final String name; 252 | private Team team; 253 | 254 | FakePlayer(String name, Team team) { 255 | this.name = name; 256 | this.team = team; 257 | } 258 | 259 | @Override 260 | public boolean isOnline() { 261 | return true; 262 | } 263 | 264 | @Override 265 | public String getName() { 266 | return name; 267 | } 268 | 269 | @Override 270 | public UUID getUniqueId() { 271 | return randomId; 272 | } 273 | 274 | @Override 275 | public boolean isBanned() { 276 | return false; 277 | } 278 | 279 | @Override 280 | public boolean isWhitelisted() { 281 | return false; 282 | } 283 | 284 | @Override 285 | public void setWhitelisted(boolean whitelisted) { 286 | } 287 | 288 | @Override 289 | public Player getPlayer() { 290 | return null; 291 | } 292 | 293 | @Override 294 | public long getFirstPlayed() { 295 | return 0; 296 | } 297 | 298 | @Override 299 | public long getLastPlayed() { 300 | return 0; 301 | } 302 | 303 | @Override 304 | public boolean hasPlayedBefore() { 305 | return false; 306 | } 307 | 308 | @Override 309 | public Location getBedSpawnLocation() { 310 | return null; 311 | } 312 | 313 | @Override 314 | public Map serialize() { 315 | return null; 316 | } 317 | 318 | @Override 319 | public boolean isOp() { 320 | return false; 321 | } 322 | 323 | @Override 324 | public void setOp(boolean op) { 325 | } 326 | 327 | @Override 328 | public String toString() { 329 | return "FakePlayer{" + 330 | "name='" + name + '\'' + 331 | ", team=" + team 332 | + '}'; 333 | } 334 | 335 | } 336 | 337 | } -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/type/Scoreboard.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.type; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | /** 6 | * Represents an advanced scoreboard that can display up to 48 characters in a single entry. 7 | * 8 | * @author TigerHix 9 | */ 10 | public interface Scoreboard { 11 | 12 | /** 13 | * Activate the scoreboard. 14 | */ 15 | void activate(); 16 | 17 | /** 18 | * Deactivate the scoreboard. 19 | */ 20 | void deactivate(); 21 | 22 | /** 23 | * Updates the scoreboard lines. 24 | */ 25 | void update(); 26 | 27 | /** 28 | * Determine if the scoreboard has been already activated. 29 | * 30 | * @return activated 31 | */ 32 | boolean isActivated(); 33 | 34 | /** 35 | * Returns the handler for this scoreboard. 36 | * 37 | * @return handler 38 | */ 39 | ScoreboardHandler getHandler(); 40 | 41 | /** 42 | * Set the handler for this scoreboard. 43 | * 44 | * @param handler handler 45 | */ 46 | Scoreboard setHandler(ScoreboardHandler handler); 47 | 48 | /** 49 | * Returns the update interval (default = 10L). 50 | * 51 | * @deprecated not used anymore 52 | * @return update interval 53 | */ 54 | @Deprecated 55 | long getUpdateInterval(); 56 | 57 | /** 58 | * Set the update interval. 59 | * 60 | * @param updateInterval update interval 61 | * @deprecated not used anymore 62 | * @return this 63 | */ 64 | @Deprecated 65 | Scoreboard setUpdateInterval(long updateInterval); 66 | 67 | /** 68 | * Returns the holder of this scoreboard. 69 | * 70 | * @return holder 71 | */ 72 | Player getHolder(); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/type/ScoreboardHandler.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.type; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Represents the handler to determine the title and entries of a scoreboard. 9 | * 10 | * @author TigerHix 11 | */ 12 | public interface ScoreboardHandler { 13 | 14 | /** 15 | * Determines the title to display for this player. If null returned, title automatically becomes a blank line. 16 | * 17 | * @param player player 18 | * @return title 19 | */ 20 | String getTitle(Player player); 21 | 22 | /** 23 | * Determines the entries to display for this player. If null returned, the entries are not updated. 24 | * 25 | * @param player player 26 | * @return entries 27 | */ 28 | List getEntries(Player player); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.type; 2 | 3 | import me.tigerhix.lib.scoreboard.common.Strings; 4 | import org.bukkit.Bukkit; 5 | import org.bukkit.ChatColor; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.scoreboard.DisplaySlot; 8 | import org.bukkit.scoreboard.Objective; 9 | import org.bukkit.scoreboard.Team; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * @author Tigerpanzer_02 16 | *

17 | * Created at 28.12.2020 18 | */ 19 | public class SimpleScoreboard implements Scoreboard { 20 | 21 | private static final String TEAM_PREFIX = "Plugily_"; 22 | private final org.bukkit.scoreboard.Scoreboard scoreboard; 23 | private final Objective objective; 24 | protected Player holder; 25 | private boolean activated; 26 | private ScoreboardHandler handler; 27 | 28 | public SimpleScoreboard(Player holder) { 29 | this.holder = holder; 30 | // Initiate the Bukkit scoreboard 31 | scoreboard = Bukkit.getScoreboardManager().getNewScoreboard(); 32 | scoreboard.registerNewObjective("plugily", "dummy").setDisplaySlot(DisplaySlot.SIDEBAR); 33 | objective = scoreboard.getObjective(DisplaySlot.SIDEBAR); 34 | for(int i = 1; i <= 15; i++) { 35 | scoreboard.registerNewTeam(TEAM_PREFIX + i).addEntry(getEntry(i)); 36 | } 37 | } 38 | 39 | @Override 40 | public void activate() { 41 | if(activated) { 42 | return; 43 | } 44 | if(handler == null) { 45 | throw new IllegalArgumentException("Scoreboard handler not set"); 46 | } 47 | activated = true; 48 | // Set to the custom scoreboard 49 | holder.setScoreboard(scoreboard); 50 | } 51 | 52 | @Override 53 | public void deactivate() { 54 | if(!activated) { 55 | return; 56 | } 57 | activated = false; 58 | // Set to the main scoreboard 59 | if(holder.isOnline()) { 60 | synchronized(this) { 61 | holder.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); 62 | } 63 | } 64 | // Unregister teams that are created for this scoreboard 65 | for(Team team : scoreboard.getTeams()) { 66 | team.unregister(); 67 | } 68 | } 69 | 70 | @Override 71 | public boolean isActivated() { 72 | return activated; 73 | } 74 | 75 | @Override 76 | public ScoreboardHandler getHandler() { 77 | return handler; 78 | } 79 | 80 | @Override 81 | public Scoreboard setHandler(ScoreboardHandler handler) { 82 | this.handler = handler; 83 | return this; 84 | } 85 | 86 | @Override 87 | public long getUpdateInterval() { 88 | throw new UnsupportedOperationException("Update interval is not supported anymore"); 89 | } 90 | 91 | @Override 92 | public LegacySimpleScoreboard setUpdateInterval(long updateInterval) { 93 | throw new UnsupportedOperationException("Update interval is not supported anymore"); 94 | } 95 | 96 | @Override 97 | public Player getHolder() { 98 | return holder; 99 | } 100 | 101 | @Override 102 | public void update() { 103 | if (!activated) { 104 | return; 105 | } 106 | 107 | if(!holder.isOnline()) { 108 | deactivate(); 109 | return; 110 | } 111 | 112 | String handlerTitle = handler.getTitle(holder); 113 | String finalTitle = handlerTitle != null ? Strings.format(handlerTitle) : ChatColor.BOLD.toString(); 114 | 115 | if(!objective.getDisplayName().equals(finalTitle)) { 116 | objective.setDisplayName(finalTitle); 117 | } 118 | 119 | List passed = handler.getEntries(holder); 120 | 121 | if(passed == null) { 122 | return; 123 | } 124 | 125 | List current = new ArrayList<>(passed.size()); 126 | 127 | for(Entry entry : passed) { 128 | int score = entry.getPosition(); 129 | Team team = scoreboard.getTeam(TEAM_PREFIX + score); 130 | String temp = getEntry(score); 131 | 132 | if(!scoreboard.getEntries().contains(temp)) { 133 | objective.getScore(temp).setScore(score); 134 | } 135 | 136 | String key = Strings.format(entry.getName()); 137 | int length = key.length(); 138 | 139 | String prefix = length > 64 ? key.substring(0, 64) : key; 140 | String suffix = ChatColor.getLastColors(prefix) + (prefix.charAt(prefix.length() - 1) == '§' ? "§" : "") + limitKey(length, key); 141 | 142 | team.setPrefix(prefix); 143 | team.setSuffix(suffix.length() > 64 ? suffix.substring(0, 64) : suffix); 144 | 145 | current.add(score); 146 | } 147 | 148 | // Remove duplicated or non-existent entries 149 | for(int i = 1; i <= 15; i++) { 150 | if(!current.contains(i)) { 151 | String entry = getEntry(i); 152 | 153 | if(scoreboard.getEntries().contains(entry)) { 154 | scoreboard.resetScores(entry); 155 | } 156 | } 157 | } 158 | } 159 | 160 | public Objective getObjective() { 161 | return objective; 162 | } 163 | 164 | private final ChatColor[] values = ChatColor.values(); 165 | 166 | private String getEntry(int slot) { 167 | return values[slot].toString(); 168 | } 169 | 170 | public org.bukkit.scoreboard.Scoreboard getScoreboard() { 171 | return scoreboard; 172 | } 173 | 174 | private String limitKey(int length, String str) { 175 | if(length > 128) { 176 | return str.substring(0, 128); 177 | } 178 | 179 | return length > 64 ? str.substring(64) : ""; 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /src/main/java/me/tigerhix/lib/scoreboard/util/ServerVersion.java: -------------------------------------------------------------------------------- 1 | package me.tigerhix.lib.scoreboard.util; 2 | 3 | import org.bukkit.Bukkit; 4 | 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | public class ServerVersion { 9 | 10 | public Version getVersion() { 11 | return Version.getCurrent(); 12 | } 13 | 14 | public enum Version { 15 | v0_0_0(0, 0), 16 | v1_8_8(8, 4), 17 | v1_9(9, 4), 18 | v1_10(10, 2), 19 | v1_11(11, 0), 20 | v1_12(12, 0), 21 | v1_13(13, 1), 22 | v1_14(14, 0), 23 | v1_15(15, 0), 24 | v1_16(16, 0), 25 | v1_17(17, 0), 26 | v1_18(18, 0), 27 | v1_19(19, 0), 28 | v1_20(20, 0), 29 | v1_21(21, 0); 30 | 31 | 32 | private static Version current; 33 | private final int minor; 34 | private final int minPatch; 35 | 36 | Version(int minor, int minPatch) { 37 | this.minor = minor; 38 | this.minPatch = minPatch; 39 | } 40 | 41 | public int getMinor() { 42 | return minor; 43 | } 44 | 45 | public int getMinPatch() { 46 | return minPatch; 47 | } 48 | 49 | public static Version getCurrent() { 50 | if(current != null) { 51 | return current; 52 | } 53 | 54 | Matcher serverVersion = Pattern.compile("^(?\\d+)\\.(?\\d+)(?:\\.(?\\d+))?").matcher(Bukkit.getBukkitVersion()); 55 | if(serverVersion.find()) { 56 | int serverMinor = Integer.parseInt(serverVersion.group("minor")); 57 | String patch = serverVersion.group("patch"); 58 | int serverPatch = Integer.parseInt((patch == null || patch.isEmpty()) ? "0" : patch); 59 | 60 | for(Version value : values()) { 61 | if(value.getMinor() == serverMinor && serverPatch >= value.getMinPatch()) { 62 | current = value; 63 | break; 64 | } 65 | } 66 | } else { 67 | throw new IllegalStateException("Cannot parse server version: \"" + Bukkit.getBukkitVersion() + '"'); 68 | } 69 | 70 | if(current == null) { // Fallback 71 | current = Version.v0_0_0; 72 | } 73 | 74 | return current; 75 | } 76 | 77 | public boolean isLower(Version version) { 78 | return minor < version.getMinor(); 79 | } 80 | 81 | public boolean isHigher(Version version) { 82 | return minor > version.getMinor(); 83 | } 84 | 85 | public boolean isEqual(Version version) { 86 | return minor == version.getMinor(); 87 | } 88 | 89 | public boolean isEqualOrLower(Version version) { 90 | return minor <= version.getMinor(); 91 | } 92 | 93 | public boolean isEqualOrHigher(Version version) { 94 | return minor >= version.getMinor(); 95 | } 96 | 97 | public static boolean isCurrentEqualOrHigher(Version fixedVersion) { 98 | return getCurrent().getMinor() >= fixedVersion.getMinor(); 99 | } 100 | 101 | public static boolean isCurrentHigher(Version fixedVersion) { 102 | return getCurrent().getMinor() > fixedVersion.getMinor(); 103 | } 104 | 105 | public static boolean isCurrentLower(Version fixedVersion) { 106 | return getCurrent().getMinor() < fixedVersion.getMinor(); 107 | } 108 | 109 | public static boolean isCurrentEqualOrLower(Version fixedVersion) { 110 | return getCurrent().getMinor() <= fixedVersion.getMinor(); 111 | } 112 | 113 | public static boolean isCurrentEqual(Version fixedVersion) { 114 | return getCurrent().getMinor() == fixedVersion.getMinor(); 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: ScoreboardLib 2 | version: ${version} 3 | description: Utilizing scoreboards for a UI enhancement. 4 | authors: 5 | - TigerHix 6 | - Tigerpanzer_02 7 | - Plugily Projects 8 | main: me.tigerhix.lib.scoreboard.ScoreboardLib --------------------------------------------------------------------------------