From 7cd20ecd5f72739884cbecf2dbfcdaedb9f76ce0 Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Fri, 24 Jun 2022 00:46:46 +0800 Subject: [PATCH] 1.1 --- .gitignore | 118 +++++++++ build.gradle | 76 ++++++ gradle.properties | 0 gradlew | 234 ++++++++++++++++++ gradlew.bat | 89 +++++++ settings.gradle | 1 + .../customnameplates/ConfigManager.java | 2 + .../customnameplates/CustomNameplates.java | 1 + .../customnameplates/font/FontWidthThin.java | 78 ++++++ .../customnameplates/hook/HookManager.java | 57 +++++ .../customnameplates/hook/PapiPlate.java | 36 +++ .../nameplates/NameplateConfig.java | 6 +- .../nameplates/NameplateUtil.java | 16 +- .../resource/ResourceManager.java | 10 +- src/main/resources/config.yml | 3 + 15 files changed, 720 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java create mode 100644 src/main/java/net/momirealms/customnameplates/hook/HookManager.java create mode 100644 src/main/java/net/momirealms/customnameplates/hook/PapiPlate.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c37caf --- /dev/null +++ b/.gitignore @@ -0,0 +1,118 @@ +# User-specific stuff +.idea/ + +*.iml +*.ipr +*.iws + +# IntelliJ +out/ +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Cache of project +.gradletasknamecache + +**/build/ + +# Common working directory +run/ + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..de105fb --- /dev/null +++ b/build.gradle @@ -0,0 +1,76 @@ +plugins { + id 'java' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +group = 'net.momirealms' +version = '1.1' + +repositories { + mavenCentral() + maven { + name = 'papermc-repo' + url = 'https://papermc.io/repo/repository/maven-public/' + } + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/content/groups/public/' + } + maven { + name = "sonatype-oss-snapshots1" + url = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + } + maven { + name = "dmulloy2-repo" + url = "https://repo.dmulloy2.net/repository/public/" + } + maven { + name = "clip-repo" + url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' + } +} + +dependencies { + compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT' + compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "4.8.0" + compileOnly 'me.clip:placeholderapi:2.11.1' + implementation('com.zaxxer:HikariCP:5.0.1') + implementation('net.kyori:adventure-api:4.11.0') + implementation('net.kyori:adventure-platform-bukkit:4.1.1') + implementation('net.kyori:adventure-text-minimessage:4.11.0') + implementation("net.kyori:adventure-text-serializer-gson:4.11.0") + implementation group: 'commons-io', name: 'commons-io', version: '2.11.0' +} + +def targetJavaVersion = 16 +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } +} + +tasks.withType(JavaCompile).configureEach { + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + options.release = targetJavaVersion + } +} + +processResources { + def props = [version: version] + inputs.properties props + filteringCharset 'UTF-8' + filesMatching('plugin.yml') { + expand props + } +} + +shadowJar { + relocate 'net.kyori', 'net.momirealms.customnameplates.libs.kyori' +} + +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..3da45c1 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright ? 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions ?$var?, ?${var}?, ?${var:-default}?, ?${var+SET}?, +# ?${var#prefix}?, ?${var%suffix}?, and ?$( cmd )?; +# * compound commands having a testable exit status, especially ?case?; +# * various built-in commands including ?command?, ?set?, and ?ulimit?. +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..6529a22 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'CustomNameplates' diff --git a/src/main/java/net/momirealms/customnameplates/ConfigManager.java b/src/main/java/net/momirealms/customnameplates/ConfigManager.java index eb7012c..98c6231 100644 --- a/src/main/java/net/momirealms/customnameplates/ConfigManager.java +++ b/src/main/java/net/momirealms/customnameplates/ConfigManager.java @@ -35,6 +35,7 @@ public class ConfigManager { public static boolean show_after; public static String lang; public static Long preview; + public static boolean thin_font; public static void ReloadConfig(){ CustomNameplates.instance.saveDefaultConfig(); @@ -55,6 +56,7 @@ public class ConfigManager { show_after = config.getBoolean("config.show-after-load-resourcepack"); key = Key.key(fontName); preview = config.getLong("config.preview-duration"); + thin_font = config.getBoolean("config.use-thin-font",false); } } //消息文件 diff --git a/src/main/java/net/momirealms/customnameplates/CustomNameplates.java b/src/main/java/net/momirealms/customnameplates/CustomNameplates.java index 206ad8d..7d84f25 100644 --- a/src/main/java/net/momirealms/customnameplates/CustomNameplates.java +++ b/src/main/java/net/momirealms/customnameplates/CustomNameplates.java @@ -6,6 +6,7 @@ import net.momirealms.customnameplates.commands.Execute; import net.momirealms.customnameplates.commands.TabComplete; import net.momirealms.customnameplates.data.DataManager; import net.momirealms.customnameplates.data.SqlHandler; +import net.momirealms.customnameplates.hook.HookManager; import net.momirealms.customnameplates.listener.PlayerListener; import net.momirealms.customnameplates.listener.PacketsListener; import net.momirealms.customnameplates.resource.ResourceManager; diff --git a/src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java b/src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java new file mode 100644 index 0000000..fdba100 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/font/FontWidthThin.java @@ -0,0 +1,78 @@ +package net.momirealms.customnameplates.font; + +public enum FontWidthThin { + + A('A', 3), a('a', 3), B('B', 3), b('b', 3), + C('C', 3), c('c', 3), D('D', 3), d('d', 3), + E('E', 3), e('e', 3), F('F', 3), f('f', 2), + G('G', 3), g('g', 3), H('H', 3), h('h', 3), + I('I', 2), i('i', 2), J('J', 3), j('j', 2), + K('K', 3), k('k', 3), L('L', 3), l('l', 2), + M('M', 3), m('m', 3), N('N', 3), n('n', 3), + O('O', 3), o('o', 3), P('P', 3), p('p', 3), + Q('Q', 3), q('q', 3), R('R', 3), r('r', 3), + S('S', 3), s('s', 3), T('T', 3), t('t', 2), + U('U', 3), u('u', 3), V('V', 3), v('v', 3), + W('W', 3), w('w', 3), X('X', 3), x('x', 3), + Y('Y', 3), y('y', 3), Z('Z', 3), z('z', 3), + NUM_1('1', 2), NUM_2('2', 3), NUM_3('3', 3), NUM_4('4', 3), + NUM_5('5', 3), NUM_6('6', 3), NUM_7('7', 3), NUM_8('8', 3), + NUM_9('9', 3), NUM_0('0', 3), EXCLAMATION_POINT('!', 1), AT_SYMBOL('@', 3), + NUM_SIGN('#', 3), DOLLAR_SIGN('$', 3), PERCENT('%', 3), UP_ARROW('^', 3), + AMPERSAND('&', 3), ASTERISK('*', 3), LEFT_PARENTHESIS('(', 2), + RIGHT_PARENTHESIS(')', 2), MINUS('-', 3), UNDERSCORE('_', 3), PLUS_SIGN('+', 3), + EQUALS_SIGN('=', 3), LEFT_CURL_BRACE('{', 1), RIGHT_CURL_BRACE('}', 1), + LEFT_BRACKET('[', 2), RIGHT_BRACKET(']', 2), COLON(':', 1), SEMI_COLON(';', 1), + DOUBLE_QUOTE('\"', 2), SINGLE_QUOTE('\'', 1), LEFT_ARROW('<', 2), + RIGHT_ARROW('>', 2), QUESTION_MARK('?', 3), SLASH('/', 3), + BACK_SLASH('\\', 3), LINE('|', 1), TILDE('~', 3), TICK('`', 1), + PERIOD('.', 1), COMMA(',', 1), SPACE(' ', 3), + IN_BETWEEN(' ', 1), DEFAULT('默', 8); + + private final char character; + private final int length; + + FontWidthThin(char character, int length) { + this.character = character; + this.length = length; + } + + public char getCharacter() { + return this.character; + } + + public int getLength() { + return this.length; + } + + public int getBoldLength() { + if (this == FontWidthThin.SPACE) { + return this.getLength(); + } + return this.getLength() + 1; + } + + /* + 获取每个字符的像素宽度 + */ + public static FontWidthThin getInfo(char c) { + for (FontWidthThin minecraftFontWidth : values()) { + if (minecraftFontWidth.getCharacter() == c) { + return minecraftFontWidth; + } + } + return FontWidthThin.DEFAULT; + } + + /* + 计算一个字符串的总宽度 + */ + public static int getTotalWidth(String s) { + int length = s.length(); + int n = 0; + for (int i = 0; i < length; i++) { + n += getInfo(s.charAt(i)).getLength(); + } + return n + FontWidthThin.IN_BETWEEN.getLength() * (length - 1); //总长还需加上字符间距 + } +} diff --git a/src/main/java/net/momirealms/customnameplates/hook/HookManager.java b/src/main/java/net/momirealms/customnameplates/hook/HookManager.java new file mode 100644 index 0000000..be6ee90 --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/hook/HookManager.java @@ -0,0 +1,57 @@ +package net.momirealms.customnameplates.hook; + +import me.clip.placeholderapi.PlaceholderAPI; +import net.momirealms.customnameplates.AdventureManager; +import net.momirealms.customnameplates.ConfigManager; +import net.momirealms.customnameplates.CustomNameplates; +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +public class HookManager { + + private boolean placeholderAPI; + private boolean itemsAdder; + + public boolean hasPlaceholderAPI() { + return this.placeholderAPI; + } + public boolean hasItemsAdder() { + return this.itemsAdder; + } + + public HookManager(CustomNameplates plugin) { + this.initializePlaceholderAPI(); + this.initializeItemsAdder(); + } + + //Papi Hook检测 + private void initializePlaceholderAPI() { + if(!ConfigManager.MainConfig.placeholderAPI){ + this.placeholderAPI = false; + return; + } + if(CustomNameplates.instance.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null){ + this.placeholderAPI = true; + AdventureManager.consoleMessage("[CustomNameplates] " + "PlaceholderAPI Hooked!"); + } + } + //ItemsAdder Hook检测 + private void initializeItemsAdder() { + if (!ConfigManager.MainConfig.itemsAdder) { + this.itemsAdder = false; + } + if(CustomNameplates.instance.getServer().getPluginManager().getPlugin("ItemsAdder") != null){ + this.itemsAdder = true; + AdventureManager.consoleMessage("[CustomNameplates] " + "ItemsAdder Hooked!"); + } + } + /* + 解析prefix与suffix + */ + public String parsePlaceholders(Player player, String papi) { + String s = StringUtils.replace(StringUtils.replace(papi, "%player_name%", player.getName()), "%player_displayname%", player.getDisplayName()); + s = PlaceholderAPI.setPlaceholders(player, s); + return ChatColor.translateAlternateColorCodes('&', s); + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customnameplates/hook/PapiPlate.java b/src/main/java/net/momirealms/customnameplates/hook/PapiPlate.java new file mode 100644 index 0000000..7ed210a --- /dev/null +++ b/src/main/java/net/momirealms/customnameplates/hook/PapiPlate.java @@ -0,0 +1,36 @@ +package net.momirealms.customnameplates.hook; + +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import net.momirealms.customnameplates.CustomNameplates; +import org.bukkit.OfflinePlayer; +import org.jetbrains.annotations.NotNull; + +public class PapiPlate extends PlaceholderExpansion{ + + private CustomNameplates plugin; + + public PapiPlate(CustomNameplates plugin) { + this.plugin = plugin; + } + + @Override + public @NotNull String getIdentifier() { + return "nameplates"; + } + + @Override + public @NotNull String getAuthor() { + return "XiaoMoMi"; + } + + @Override + public @NotNull String getVersion() { + return "1.0"; + } + + @Override + public String onRequest(OfflinePlayer player, String params) { + + return null; + } +} diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java index 84ba292..2b41276 100644 --- a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java +++ b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateConfig.java @@ -2,12 +2,12 @@ package net.momirealms.customnameplates.nameplates; import org.bukkit.ChatColor; -public record NameplateConfig(ChatColor color, int height, String name) { +public record NameplateConfig(ChatColor color, int height, String name, int yoffset) { public static NameplateConfig EMPTY; static { - EMPTY = new NameplateConfig(ChatColor.WHITE, 16, "none"); + EMPTY = new NameplateConfig(ChatColor.WHITE, 16, "none", 12); } //获取Team颜色 @@ -24,4 +24,6 @@ public record NameplateConfig(ChatColor color, int height, String name) { public String getName() { return this.name; } + + public int getyoffset() {return this.yoffset; } } diff --git a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java index 29d9d0a..610c7ba 100644 --- a/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java +++ b/src/main/java/net/momirealms/customnameplates/nameplates/NameplateUtil.java @@ -1,8 +1,10 @@ package net.momirealms.customnameplates.nameplates; +import net.momirealms.customnameplates.ConfigManager; import net.momirealms.customnameplates.font.FontCache; import net.momirealms.customnameplates.font.FontNegative; import net.momirealms.customnameplates.font.FontWidth; +import net.momirealms.customnameplates.font.FontWidthThin; import org.bukkit.ChatColor; public class NameplateUtil { @@ -18,7 +20,12 @@ public class NameplateUtil { 当然这个玩家名是带上前缀与后缀的 */ public String makeCustomNameplate(String prefix, String name, String suffix) { - int totalWidth = FontWidth.getTotalWidth(ChatColor.stripColor(prefix + name + suffix)); + int totalWidth; + if (ConfigManager.MainConfig.thin_font){ + totalWidth = FontWidthThin.getTotalWidth(ChatColor.stripColor(prefix + name + suffix)); + }else { + totalWidth = FontWidth.getTotalWidth(ChatColor.stripColor(prefix + name + suffix)); + } boolean isEven = totalWidth % 2 == 0; //奇偶判断 char left = this.fontcache.getChar().getLeft(); char middle = this.fontcache.getChar().getMiddle(); @@ -44,7 +51,12 @@ public class NameplateUtil { 保证铭牌总是位于玩家头顶中央的位置 */ public String getSuffixLength(String name) { - final int totalWidth = FontWidth.getTotalWidth(ChatColor.stripColor(name)); + int totalWidth; + if (ConfigManager.MainConfig.thin_font){ + totalWidth = FontWidthThin.getTotalWidth(ChatColor.stripColor(name)); + }else { + totalWidth = FontWidth.getTotalWidth(ChatColor.stripColor(name)); + } return FontNegative.getShortestNegChars(totalWidth + totalWidth % 2 + 1); } diff --git a/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java b/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java index f107317..a9763eb 100644 --- a/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java +++ b/src/main/java/net/momirealms/customnameplates/resource/ResourceManager.java @@ -23,7 +23,7 @@ import java.util.*; public class ResourceManager { public final HashMap caches; - private CustomNameplates plugin; + private final CustomNameplates plugin; public ResourceManager(CustomNameplates plugin) { this.caches = new HashMap<>(); @@ -78,7 +78,7 @@ public class ResourceManager { caches.put(pngName, new FontCache(pngName, fontChar, config)); jsonObject_2.add("type", new JsonPrimitive("bitmap")); jsonObject_2.add("file", new JsonPrimitive(ConfigManager.MainConfig.namespace + ":" + ConfigManager.MainConfig.folder_path.replaceAll("\\\\","/") + png.getName().toLowerCase())); - jsonObject_2.add("ascent", new JsonPrimitive(12)); + jsonObject_2.add("ascent", new JsonPrimitive(config.getyoffset())); jsonObject_2.add("height", new JsonPrimitive(config.getHeight())); JsonArray jsonArray_2 = new JsonArray(); jsonArray_2.add(native2ascii(fontChar.getLeft()) + native2ascii(fontChar.getMiddle()) + native2ascii(fontChar.getRight())); @@ -170,6 +170,9 @@ public class ResourceManager { if (!config.contains("size")){ config.set("size", 16); } + if (!config.contains("yoffset")){ + config.set("yoffset", 12); + } ChatColor color = ChatColor.WHITE; try { color = ChatColor.valueOf(Objects.requireNonNull(config.getString("color")).toUpperCase()); @@ -178,9 +181,10 @@ public class ResourceManager { AdventureManager.consoleMessage("[CustomNameplates] Invalid Color of " + nameplate + ""); } int size = config.getInt("size"); + int yoffset = config.getInt("yoffset"); String name = config.getString("name"); config.save(file); - return new NameplateConfig(color, size, name); + return new NameplateConfig(color, size, name, yoffset); } catch (Exception e) { return NameplateConfig.EMPTY; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7bda0df..4664ef1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -37,6 +37,9 @@ config: prefix: '' suffix: '' + # Thin-font support + use-thin-font: false + # Should the plugin hook into other plugins integrations: # When enabled, the plugin will be able to parse prefix and suffix