mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 06:59:24 +00:00
Initial Commit
This commit is contained in:
118
.gitignore
vendored
Normal file
118
.gitignore
vendored
Normal file
@@ -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
|
||||
110
build.gradle.kts
Normal file
110
build.gradle.kts
Normal file
@@ -0,0 +1,110 @@
|
||||
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.github.johnrengelman.shadow") version "7.1.1"
|
||||
id("io.papermc.paperweight.userdev") version "1.3.8"
|
||||
id("xyz.jpenilla.run-paper") version "1.0.6"
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
|
||||
}
|
||||
|
||||
group = "com.hibiscusmc"
|
||||
version = "Infdev"
|
||||
|
||||
bukkit {
|
||||
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
|
||||
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
||||
apiVersion = "1.19"
|
||||
authors = listOf("LoJoSho")
|
||||
depend = listOf("ProtocolLib")
|
||||
version = "${project.version}"
|
||||
|
||||
commands {
|
||||
register("cosmetic") {
|
||||
description = "Base command"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
maven("https://jitpack.io")
|
||||
maven("https://repo.dmulloy2.net/repository/public/")
|
||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||
maven("https://mvnrepository.com/artifact/com.zaxxer/HikariCP")
|
||||
maven("https://repo.citizensnpcs.co")
|
||||
//maven("https://mvn.lumine.io/repository/maven-public")
|
||||
maven {
|
||||
url = uri("https://mvn.lumine.io/repository/maven-public")
|
||||
metadataSources {
|
||||
artifact()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.19.2-R0.1-SNAPSHOT")
|
||||
compileOnly("com.mojang:authlib:1.5.25")
|
||||
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
|
||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0-SNAPSHOT")
|
||||
compileOnly("me.clip:placeholderapi:2.11.1")
|
||||
compileOnly("com.ticxo.modelengine:api:R3.0.0")
|
||||
implementation("net.kyori:adventure-api:4.11.0")
|
||||
implementation ("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
|
||||
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.release.set(17)
|
||||
}
|
||||
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
|
||||
processResources {
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
outputJar.set(layout.projectDirectory.file("run/plugins/HMCCosmeticsRemapped.jar"))
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate("dev.triumphteam.gui", "com.hisbiscus.hmccosmetics.gui")
|
||||
relocate("me.mattstudios.mf", "com.hisbiscus.hmccosmetics.mf")
|
||||
relocate("net.kyori.adventure", "com.hisbiscus.hmccosmetics.adventure")
|
||||
relocate("org.spongepowered.configurate", "com.hisbiscus.hmccosmetics.configurate")
|
||||
relocate("org.bstats", "com.hisbiscus.hmccosmetics.bstats")
|
||||
relocate("com.zaxxer.hikaricp", "com.hisbiscus.hmccosmetics.hikaricp")
|
||||
relocate("com.j256.ormlite", "com.hisbiscus.hmccosmetics.ormlite")
|
||||
archiveFileName.set("HMCCosmetics.jar")
|
||||
|
||||
dependencies {
|
||||
exclude(dependency("org.yaml:snakeyaml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17
|
||||
))
|
||||
}
|
||||
0
gradle.properties
Normal file
0
gradle.properties
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
234
gradlew
vendored
Normal file
234
gradlew
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright <20> 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 <20>$var<61>, <20>${var}<7D>, <20>${var:-default}<7D>, <20>${var+SET}<7D>,
|
||||
# <20>${var#prefix}<7D>, <20>${var%suffix}<7D>, and <20>$( cmd )<29>;
|
||||
# * compound commands having a testable exit status, especially <20>case<73>;
|
||||
# * various built-in commands including <20>command<6E>, <20>set<65>, and <20>ulimit<69>.
|
||||
#
|
||||
# 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" "$@"
|
||||
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
@@ -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
|
||||
8
settings.gradle.kts
Normal file
8
settings.gradle.kts
Normal file
@@ -0,0 +1,8 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "HMCCosmetics"
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.hibiscusmc.hmccosmetics;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
|
||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
|
||||
private static HMCCosmeticsPlugin instance;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
// File setup
|
||||
if (!getDataFolder().exists()) {
|
||||
saveDefaultConfig();
|
||||
saveResource("translations.yml", false);
|
||||
saveResource("messages.yml", false);
|
||||
saveResource("cosmetics/examplecosmetics.yml", false);
|
||||
saveResource("menus/examplemenu.yml", false);
|
||||
}
|
||||
|
||||
setup();
|
||||
|
||||
// Commands
|
||||
getServer().getPluginCommand("cosmetic").setExecutor(new CosmeticCommand());
|
||||
getServer().getPluginCommand("cosmetic").setTabCompleter(new CosmeticCommandTabComplete());
|
||||
|
||||
// Listener
|
||||
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
|
||||
|
||||
// Database
|
||||
new Database();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
public static HMCCosmeticsPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
getInstance().reloadConfig();
|
||||
|
||||
// Configuration setup
|
||||
final File file = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
||||
final YamlConfigurationLoader loader = YamlConfigurationLoader.
|
||||
builder().
|
||||
path(file.toPath()).
|
||||
defaultOptions(opts ->
|
||||
opts.serializers(build -> {
|
||||
build.register(Location.class, LocationSerializer.INSTANCE);
|
||||
build.register(ItemStack.class, ItemSerializer.INSTANCE);
|
||||
}))
|
||||
.build();
|
||||
try {
|
||||
Settings.load(loader.load().node(""));
|
||||
WardrobeSettings.load(loader.load().node("wardrobe"));
|
||||
} catch (ConfigurateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Cosmetics setup
|
||||
Cosmetics.setup();
|
||||
|
||||
// Menus setup
|
||||
Menus.setup();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.hibiscusmc.hmccosmetics.command;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CosmeticCommand implements CommandExecutor {
|
||||
|
||||
// cosmetics apply cosmetics playerName
|
||||
// 0 1 2
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
// Possble default menu here?
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
HMCCosmeticsPlugin.setup();
|
||||
sender.sendMessage("Reloaded.");
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("apply")) {
|
||||
Player player = null;
|
||||
Cosmetic cosmetic;
|
||||
|
||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||
|
||||
cosmetic = Cosmetics.getCosmetic(args[1]);
|
||||
|
||||
if (player == null || cosmetic == null) {
|
||||
sender.sendMessage("Something was null");
|
||||
return true;
|
||||
}
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
user.addPlayerCosmetic(cosmetic);
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("unapply")) {
|
||||
Player player = null;
|
||||
Cosmetic cosmetic;
|
||||
|
||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||
|
||||
cosmetic = Cosmetics.getCosmetic(args[1]);
|
||||
|
||||
if (player == null || cosmetic == null) {
|
||||
sender.sendMessage("Something was null");
|
||||
return true;
|
||||
}
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
CosmeticSlot slot = cosmetic.getSlot();
|
||||
user.removeCosmeticSlot(cosmetic);
|
||||
user.updateCosmetic(slot);
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("wardrobe")) {
|
||||
Player player = null;
|
||||
|
||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage("Player was null");
|
||||
return true;
|
||||
}
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
user.toggleWardrobe();
|
||||
return true;
|
||||
}
|
||||
// cosmetic menu exampleMenu playerName
|
||||
if (args[0].equalsIgnoreCase("menu")) {
|
||||
Menu menu = Menus.getMenu(args[1]);
|
||||
Player player = null;
|
||||
|
||||
if (sender instanceof Player) player = ((Player) sender).getPlayer();
|
||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||
|
||||
if (player == null || menu == null) {
|
||||
sender.sendMessage("Something was null");
|
||||
return true;
|
||||
}
|
||||
|
||||
menu.openMenu(CosmeticUsers.getUser(player));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.hibiscusmc.hmccosmetics.command;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.length == 1) {
|
||||
completions.add("apply");
|
||||
completions.add("wardrobe");
|
||||
completions.add("unapply");
|
||||
completions.add("menu");
|
||||
completions.add("reload");
|
||||
}
|
||||
|
||||
if (args.length >= 2) {
|
||||
if (args[0].equalsIgnoreCase("apply") || args[0].equalsIgnoreCase("unapply")) {
|
||||
completions.addAll(applyCommandComplete(args));
|
||||
} else if (args[0].equalsIgnoreCase("menu")) {
|
||||
completions.addAll(Menus.getMenuNames());
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(completions);
|
||||
return completions;
|
||||
}
|
||||
|
||||
private static List<String> applyCommandComplete(String[] args) {
|
||||
List<String> completitions = new ArrayList<>();
|
||||
|
||||
if (args.length == 2) {
|
||||
completitions.addAll(Cosmetics.keys());
|
||||
} else {
|
||||
if (args.length == 3) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
completitions.add(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return completitions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class Settings {
|
||||
|
||||
// General Settings
|
||||
private static final String DEFAULT_MENU = "default-menu";
|
||||
private static final String COSMETIC_SETTINGS_PATH = "cosmetic-settings";
|
||||
private static final String REQUIRE_EMPTY_HELMET_PATH = "require-empty-helmet";
|
||||
private static final String REQUIRE_EMPTY_OFF_HAND_PATH = "require-empty-off-hand";
|
||||
private static final String REQUIRE_EMPTY_CHEST_PLATE_PATH = "require-empty-chest-plate";
|
||||
private static final String REQUIRE_EMPTY_PANTS_PATH = "require-empty-pants";
|
||||
private static final String REQUIRE_EMPTY_BOOTS_PATH = "require-empty-boots";
|
||||
private static final String BALLOON_OFFSET = "balloon-offset";
|
||||
private static final String FIRST_PERSON_BACKPACK_MODE = "first-person-backpack-mode";
|
||||
|
||||
private static final transient String LOOK_DOWN_PITCH_PATH = "look-down-backpack-remove";
|
||||
private static final String VIEW_DISTANCE_PATH = "view-distance";
|
||||
private static final String PARTICLE_COUNT = "particle-count";
|
||||
|
||||
private static String defaultMenu;
|
||||
private static boolean requireEmptyHelmet;
|
||||
private static boolean requireEmptyOffHand;
|
||||
private static boolean requireEmptyChestPlate;
|
||||
private static boolean requireEmptyPants;
|
||||
private static boolean requireEmptyBoots;
|
||||
private static int lookDownPitch;
|
||||
private static int viewDistance;
|
||||
private static Vector balloonOffset;
|
||||
|
||||
public static void load(ConfigurationNode source) {
|
||||
|
||||
defaultMenu = source.node(DEFAULT_MENU).getString();
|
||||
|
||||
ConfigurationNode cosmeticSettings = source.node(COSMETIC_SETTINGS_PATH);
|
||||
|
||||
requireEmptyHelmet = cosmeticSettings.node(REQUIRE_EMPTY_HELMET_PATH).getBoolean();
|
||||
requireEmptyOffHand = cosmeticSettings.node(REQUIRE_EMPTY_OFF_HAND_PATH).getBoolean();
|
||||
requireEmptyChestPlate = cosmeticSettings.node(REQUIRE_EMPTY_CHEST_PLATE_PATH).getBoolean();
|
||||
requireEmptyPants = cosmeticSettings.node(REQUIRE_EMPTY_PANTS_PATH).getBoolean();
|
||||
requireEmptyBoots = cosmeticSettings.node(REQUIRE_EMPTY_BOOTS_PATH).getBoolean();
|
||||
|
||||
lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt();
|
||||
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt();
|
||||
|
||||
|
||||
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
|
||||
|
||||
if (balloonSection != null) {
|
||||
balloonOffset = loadVector(balloonSection);
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector loadVector(final ConfigurationNode config) {
|
||||
return new Vector(config.node("x").getDouble(), config.node("y").getDouble(), config.node("z").getDouble());
|
||||
}
|
||||
|
||||
public static boolean isRequireEmptyHelmet() {
|
||||
return requireEmptyHelmet;
|
||||
}
|
||||
|
||||
public static boolean isRequireEmptyOffHand() {
|
||||
return requireEmptyOffHand;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isRequireEmptyChestPlate() {
|
||||
return requireEmptyChestPlate;
|
||||
}
|
||||
|
||||
public static boolean isRequireEmptyPants() {
|
||||
return requireEmptyPants;
|
||||
}
|
||||
|
||||
public static boolean isRequireEmptyBoots() {
|
||||
return requireEmptyBoots;
|
||||
}
|
||||
|
||||
public static Vector getBalloonOffset() {
|
||||
return balloonOffset;
|
||||
}
|
||||
|
||||
public static int getLookDownPitch() {
|
||||
return lookDownPitch;
|
||||
}
|
||||
|
||||
public static int getViewDistance() {
|
||||
return viewDistance;
|
||||
}
|
||||
|
||||
public static String getDefaultMenu() {
|
||||
return defaultMenu;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||
import org.bukkit.Location;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
public class WardrobeSettings {
|
||||
|
||||
private static final String WARDROBE_PATH = "wardrobe";
|
||||
private static final String DISABLE_ON_DAMAGE_PATH = "disable-on-damage";
|
||||
private static final String DISPLAY_RADIUS_PATH = "display-radius";
|
||||
private static final String PORTABLE_PATH = "portable";
|
||||
private static final String ALWAYS_DISPLAY_PATH = "always-display";
|
||||
private static final String STATIC_RADIUS_PATH = "static-radius";
|
||||
private static final String ROTATION_SPEED_PATH = "rotation-speed";
|
||||
private static final String SPAWN_DELAY_PATH = "spawn-delay";
|
||||
private static final String DESPAWN_DELAY_PATH = "despawn-delay";
|
||||
private static final String APPLY_COSMETICS_ON_CLOSE = "apply-cosmetics-on-close";
|
||||
private static final String OPEN_SOUND = "open-sound";
|
||||
private static final String CLOSE_SOUND = "close-sound";
|
||||
private static final String STATIC_LOCATION_PATH = "wardrobe-location";
|
||||
private static final String VIEWER_LOCATION_PATH = "viewer-location";
|
||||
private static final String LEAVE_LOCATION_PATH = "leave-location";
|
||||
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
|
||||
private static final String RETURN_LAST_LOCATION = "return-last-location";
|
||||
|
||||
private static boolean disableOnDamage;
|
||||
private static int displayRadius;
|
||||
private static boolean portable;
|
||||
private static boolean alwaysDisplay;
|
||||
private static int staticRadius;
|
||||
private static int rotationSpeed;
|
||||
private static int spawnDelay;
|
||||
private static int despawnDelay;
|
||||
private static boolean applyCosmeticsOnClose;
|
||||
private static boolean equipPumpkin;
|
||||
private static boolean returnLastLocation;
|
||||
private static Location wardrobeLocation;
|
||||
private static Location viewerLocation;
|
||||
private static Location leaveLocation;
|
||||
|
||||
public static void load(ConfigurationNode source) {
|
||||
|
||||
disableOnDamage = source.node(DISABLE_ON_DAMAGE_PATH).getBoolean();
|
||||
displayRadius = source.node(DISPLAY_RADIUS_PATH).getInt();
|
||||
portable = source.node(PORTABLE_PATH).getBoolean();
|
||||
staticRadius = source.node(STATIC_RADIUS_PATH).getInt();
|
||||
alwaysDisplay = source.node(ALWAYS_DISPLAY_PATH).getBoolean();
|
||||
rotationSpeed = source.node(ROTATION_SPEED_PATH).getInt();
|
||||
spawnDelay = source.node(SPAWN_DELAY_PATH).getInt();
|
||||
despawnDelay = source.node(DESPAWN_DELAY_PATH).getInt();
|
||||
applyCosmeticsOnClose = source.node(APPLY_COSMETICS_ON_CLOSE).getBoolean();
|
||||
equipPumpkin = source.node(EQUIP_PUMPKIN_WARDROBE).getBoolean();
|
||||
returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean();
|
||||
try {
|
||||
wardrobeLocation = LocationSerializer.INSTANCE.deserialize(Location.class, source.node(STATIC_LOCATION_PATH));
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Wardrobe Location: " + wardrobeLocation);
|
||||
viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, source.node(VIEWER_LOCATION_PATH));
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Viewer Location: " + viewerLocation);
|
||||
leaveLocation = Utils.replaceIfNull(LocationSerializer.INSTANCE.deserialize(Location.class, source.node(LEAVE_LOCATION_PATH)), viewerLocation);
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getDisableOnDamage() {
|
||||
return disableOnDamage;
|
||||
}
|
||||
|
||||
public static int getDisplayRadius() {
|
||||
return displayRadius;
|
||||
}
|
||||
|
||||
public static boolean isPortable() {
|
||||
return portable;
|
||||
}
|
||||
|
||||
public static boolean isAlwaysDisplay() {
|
||||
return alwaysDisplay;
|
||||
}
|
||||
|
||||
public static int getStaticRadius() {
|
||||
return staticRadius;
|
||||
}
|
||||
|
||||
public static int getRotationSpeed() {
|
||||
return rotationSpeed;
|
||||
}
|
||||
|
||||
public static int getSpawnDelay() {
|
||||
return spawnDelay;
|
||||
}
|
||||
|
||||
public static int getDespawnDelay() {
|
||||
return despawnDelay;
|
||||
}
|
||||
|
||||
public static boolean isApplyCosmeticsOnClose() {
|
||||
return applyCosmeticsOnClose;
|
||||
}
|
||||
public static boolean isEquipPumpkin() {
|
||||
return equipPumpkin;
|
||||
}
|
||||
public static boolean isReturnLastLocation() {
|
||||
return returnLastLocation;
|
||||
}
|
||||
|
||||
public static Location getWardrobeLocation() {
|
||||
return wardrobeLocation.clone();
|
||||
}
|
||||
|
||||
public static Location getViewerLocation() {
|
||||
return viewerLocation;
|
||||
}
|
||||
|
||||
public static Location getLeaveLocation() {
|
||||
return leaveLocation;
|
||||
}
|
||||
|
||||
public static boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) {
|
||||
if (displayRadius == -1) return true;
|
||||
if (!wardrobeLocation.getWorld().equals(playerLocation.getWorld())) return false;
|
||||
return playerLocation.distanceSquared(wardrobeLocation) <= displayRadius * displayRadius;
|
||||
}
|
||||
|
||||
public static boolean inDistanceOfStatic(final Location location) {
|
||||
if (wardrobeLocation == null) return false;
|
||||
if (staticRadius == -1) return false;
|
||||
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
||||
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.hibiscusmc.hmccosmetics.config.serializer;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.builder.ColorBuilder;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.StringUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemSerializer implements TypeSerializer<ItemStack> {
|
||||
|
||||
public static final ItemSerializer INSTANCE = new ItemSerializer();
|
||||
private static final String MATERIAL = "material";
|
||||
private static final String AMOUNT = "amount";
|
||||
private static final String NAME = "name";
|
||||
private static final String UNBREAKABLE = "unbreakable";
|
||||
private static final String GLOWING = "glowing";
|
||||
private static final String LORE = "lore";
|
||||
private static final String MODEL_DATA = "model-data";
|
||||
private static final String ENCHANTS = "enchants";
|
||||
private static final String ITEM_FLAGS = "item-flags";
|
||||
private static final String TEXTURE = "texture";
|
||||
private static final String OWNER = "owner";
|
||||
private static final String COLOR = "color";
|
||||
private static final String RED = "red";
|
||||
private static final String GREEN = "green";
|
||||
private static final String BLUE = "blue";
|
||||
|
||||
private ItemSerializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack deserialize(final Type type, final ConfigurationNode source)
|
||||
throws SerializationException {
|
||||
final ConfigurationNode materialNode = source.node(MATERIAL);
|
||||
final ConfigurationNode amountNode = source.node(AMOUNT);
|
||||
final ConfigurationNode nameNode = source.node(NAME);
|
||||
final ConfigurationNode unbreakableNode = source.node(UNBREAKABLE);
|
||||
final ConfigurationNode glowingNode = source.node(GLOWING);
|
||||
final ConfigurationNode loreNode = source.node(LORE);
|
||||
final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
|
||||
final ConfigurationNode enchantsNode = source.node(ENCHANTS);
|
||||
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS);
|
||||
final ConfigurationNode textureNode = source.node(TEXTURE);
|
||||
final ConfigurationNode ownerNode = source.node(OWNER);
|
||||
final ConfigurationNode colorNode = source.node(COLOR);
|
||||
final ConfigurationNode redNode = colorNode.node(RED);
|
||||
final ConfigurationNode greenNode = colorNode.node(GREEN);
|
||||
final ConfigurationNode blueNode = colorNode.node(BLUE);
|
||||
|
||||
if (materialNode.virtual()) return null;
|
||||
|
||||
// Future hook integration
|
||||
String material = materialNode.getString();
|
||||
List<String> processedMaterial = Arrays.asList(material.split(":"));
|
||||
if (processedMaterial.get(0).equalsIgnoreCase("oraxen")) {
|
||||
// todo
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.getMaterial(materialNode.getString()));
|
||||
item.setAmount(amountNode.getInt(1));
|
||||
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (!nameNode.virtual()) itemMeta.setDisplayName(StringUtils.parseStringToString(Utils.replaceIfNull(nameNode.getString(), "")));
|
||||
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
|
||||
if (!glowingNode.virtual()) {
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
|
||||
}
|
||||
if (!loreNode.virtual()) itemMeta.setLore(Utils.replaceIfNull(loreNode.getList(String.class),
|
||||
new ArrayList<String>()).
|
||||
stream().map(StringUtils::parseStringToString).collect(Collectors.toList()));
|
||||
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
|
||||
|
||||
if (!enchantsNode.virtual()) {
|
||||
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
|
||||
if (Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())) == null) continue;
|
||||
itemMeta.addEnchant(Enchantment.getByKey(NamespacedKey.minecraft(enchantNode.key().toString())), enchantNode.getInt(1), true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!itemFlagsNode.virtual()) {
|
||||
for (ConfigurationNode flagNode : itemFlagsNode.childrenMap().values()) {
|
||||
if (ItemFlag.valueOf(flagNode.key().toString()) == null) continue;
|
||||
itemMeta.addItemFlags(ItemFlag.valueOf(flagNode.key().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (item.getType() == Material.PLAYER_HEAD) {
|
||||
SkullMeta skullMeta = (SkullMeta) itemMeta;
|
||||
if (!ownerNode.virtual()) {
|
||||
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(ownerNode.getString()));
|
||||
}
|
||||
|
||||
if (!textureNode.virtual()) {
|
||||
Bukkit.getUnsafe().modifyItemStack(item, "{SkullOwner:{Id:[I;0,0,0,0],Properties:{textures:[{Value:\""
|
||||
+ textureNode.getString() + "\"}]}}}");
|
||||
itemMeta = skullMeta;
|
||||
}
|
||||
}
|
||||
|
||||
if (!colorNode.virtual()) {
|
||||
if (ColorBuilder.canBeColored(item.getType())) {
|
||||
itemMeta = ColorBuilder.color(itemMeta, Color.fromRGB(redNode.getInt(0), greenNode.getInt(0), blueNode.getInt(0)));
|
||||
}
|
||||
}
|
||||
|
||||
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), source.key().toString());
|
||||
itemMeta.getPersistentDataContainer().set(key, PersistentDataType.STRING, source.key().toString());
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final ItemStack obj, final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.hibiscusmc.hmccosmetics.config.serializer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class LocationSerializer implements TypeSerializer<Location> {
|
||||
|
||||
public static final LocationSerializer INSTANCE = new LocationSerializer();
|
||||
|
||||
private static final String WORLD = "world";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String Z = "z";
|
||||
private static final String PITCH = "pitch";
|
||||
private static final String YAW = "yaw";
|
||||
|
||||
|
||||
private LocationSerializer() {}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Location deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
|
||||
final World world = Bukkit.getWorld(source.node(WORLD).getString());
|
||||
if (world == null) return null;
|
||||
return new Location(
|
||||
world,
|
||||
source.node(X).getDouble(),
|
||||
source.node(Y).getDouble(),
|
||||
source.node(Z).getDouble(),
|
||||
source.node(YAW).getFloat(),
|
||||
source.node(PITCH).getFloat()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final Location obj, final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class Cosmetic {
|
||||
|
||||
private String id;
|
||||
private String permission;
|
||||
private CosmeticSlot slot;
|
||||
|
||||
protected Cosmetic(String id, ConfigurationNode config) {
|
||||
this.id = id;
|
||||
//this.permission = config.node("permission").getString(null);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Slot: " + config.node("slot").getString());
|
||||
this.slot = CosmeticSlot.valueOf(config.node("slot").getString());
|
||||
|
||||
Cosmetics.addCosmetic(this);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
public String getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
public CosmeticSlot getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public void setSlot(CosmeticSlot slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public boolean requiresPermission() {
|
||||
if (permission == null) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void update(CosmeticUser user) {
|
||||
// overide
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
public enum CosmeticSlot {
|
||||
HELMET,
|
||||
CHESTPLATE,
|
||||
LEGGINGS,
|
||||
BOOTS,
|
||||
OFFHAND,
|
||||
BACKPACK,
|
||||
BALLOON
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
public class Cosmetics {
|
||||
|
||||
private static HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
|
||||
|
||||
public static void addCosmetic(Cosmetic cosmetic) {
|
||||
COSMETICS.put(cosmetic.getId(), cosmetic);
|
||||
}
|
||||
|
||||
public static void removeCosmetic(String id) {
|
||||
COSMETICS.remove(id);
|
||||
}
|
||||
|
||||
public static void removeCosmetic(Cosmetic cosmetic) {
|
||||
COSMETICS.remove(cosmetic);
|
||||
}
|
||||
|
||||
public static Cosmetic getCosmetic(String id) {
|
||||
return COSMETICS.get(id);
|
||||
}
|
||||
|
||||
public static Set<Cosmetic> values() {
|
||||
return COSMETICS.values();
|
||||
}
|
||||
|
||||
public static Set<String> keys() {
|
||||
return COSMETICS.keySet();
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
COSMETICS.clear();
|
||||
|
||||
File cosmeticFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder() + "/cosmetics");
|
||||
if (!cosmeticFolder.exists()) cosmeticFolder.mkdir();
|
||||
|
||||
File[] directoryListing = cosmeticFolder.listFiles();
|
||||
if (directoryListing == null) return;
|
||||
|
||||
for (File child : directoryListing) {
|
||||
if (child.toString().contains(".yml") || child.toString().contains(".yaml")) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Scanning " + child);
|
||||
// Loads file
|
||||
YamlConfigurationLoader loader = YamlConfigurationLoader.builder().path(child.toPath()).build();
|
||||
CommentedConfigurationNode root;
|
||||
try {
|
||||
root = loader.load();
|
||||
} catch (ConfigurateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
setupCosmetics(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupCosmetics(CommentedConfigurationNode config) {
|
||||
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
|
||||
String id = cosmeticConfig.key().toString();
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Attempting to add " + id);
|
||||
switch (CosmeticSlot.valueOf(cosmeticConfig.node("slot").getString())) {
|
||||
case BALLOON -> {
|
||||
new CosmeticBalloonType(id, cosmeticConfig);
|
||||
}
|
||||
case BACKPACK -> {
|
||||
new CosmeticBackpackType(id, cosmeticConfig);
|
||||
}
|
||||
default -> {
|
||||
new CosmeticArmorType(id, cosmeticConfig);
|
||||
}
|
||||
}
|
||||
//new Cosmetic(id, cosmeticConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
public class CosmeticArmorType extends Cosmetic {
|
||||
|
||||
private ItemStack itemStack;
|
||||
private EquipmentSlot equipSlot;
|
||||
|
||||
public CosmeticArmorType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
this.itemStack = generateItemStack(config.node("item"));
|
||||
this.equipSlot = InventoryUtils.getEquipmentSlot(getSlot());
|
||||
|
||||
//Cosmetics.addCosmetic(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(CosmeticUser user) {
|
||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||
PacketManager.equipmentSlotUpdate(player, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
||||
}
|
||||
|
||||
public ItemStack getCosmeticItem() {
|
||||
return this.itemStack;
|
||||
}
|
||||
|
||||
public EquipmentSlot getEquipSlot() {
|
||||
return this.equipSlot;
|
||||
}
|
||||
|
||||
private ItemStack generateItemStack(ConfigurationNode config) {
|
||||
try {
|
||||
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
||||
if (item == null) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().severe("Unable to create item for " + getId());
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
return item;
|
||||
} catch (SerializationException e) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().severe("Fatal error encountered for " + getId() + " regarding Serialization of item");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CosmeticBackpackType extends Cosmetic {
|
||||
|
||||
private ItemStack backpackItem;
|
||||
|
||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
this.backpackItem = generateItemStack(config.node("item"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(CosmeticUser user) {
|
||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||
List<Player> sendTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
Location loc = player.getLocation();
|
||||
|
||||
PacketManager.armorStandMetaPacket((Entity) user.getBackpackEntity(), sendTo);
|
||||
PacketManager.sendRotationPacket(user.getArmorstandId(), loc, false, sendTo);
|
||||
PacketManager.sendLookPacket(user.getArmorstandId(), loc, sendTo);
|
||||
|
||||
}
|
||||
|
||||
public ItemStack getBackpackItem() {
|
||||
return backpackItem;
|
||||
}
|
||||
|
||||
private ItemStack generateItemStack(ConfigurationNode config) {
|
||||
try {
|
||||
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
||||
if (item == null) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().severe("Unable to create item for " + getId());
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
return item;
|
||||
} catch (SerializationException e) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().severe("Fatal error encountered for " + getId() + " regarding Serialization of item");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class CosmeticBalloonType extends Cosmetic {
|
||||
public CosmeticBalloonType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.hibiscusmc.hmccosmetics.database;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.database.types.Data;
|
||||
import com.hibiscusmc.hmccosmetics.database.types.InternalData;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Database {
|
||||
|
||||
private static Data data;
|
||||
|
||||
private static InternalData INTERNAL_DATA = new InternalData();
|
||||
|
||||
public Database() {
|
||||
this.data = INTERNAL_DATA;
|
||||
// To be replaced when multiple systems exist
|
||||
}
|
||||
|
||||
public static void save(CosmeticUser user) {
|
||||
data.save(user);
|
||||
}
|
||||
|
||||
public static CosmeticUser get(UUID uniqueId) {
|
||||
return data.get(uniqueId);
|
||||
}
|
||||
|
||||
public static Data getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.hibiscusmc.hmccosmetics.database.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Data {
|
||||
|
||||
public void save(CosmeticUser user) {
|
||||
// Override
|
||||
}
|
||||
|
||||
public CosmeticUser get(UUID uniqueId) {
|
||||
// Override
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.hibiscusmc.hmccosmetics.database.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class InternalData extends Data {
|
||||
|
||||
@Override
|
||||
public void save(CosmeticUser user) {
|
||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
||||
NamespacedKey slotkey = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), cosmetic.getSlot().toString());
|
||||
player.getPersistentDataContainer().set(slotkey, PersistentDataType.STRING, cosmetic.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CosmeticUser get(UUID uniqueId) {
|
||||
Player player = Bukkit.getPlayer(uniqueId);
|
||||
CosmeticUser user = new CosmeticUser(uniqueId);
|
||||
for (CosmeticSlot slot : CosmeticSlot.values()) {
|
||||
NamespacedKey key = new NamespacedKey(HMCCosmeticsPlugin.getInstance(), slot.toString());
|
||||
if (!player.getPersistentDataContainer().has(key, PersistentDataType.STRING)) continue;
|
||||
user.addPlayerCosmetic(Cosmetics.getCosmetic(player.getPersistentDataContainer().get(key, PersistentDataType.STRING)));
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
|
||||
public class InvisibleArmorstand extends ArmorStand {
|
||||
|
||||
public InvisibleArmorstand(Level world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
public InvisibleArmorstand(Location loc) {
|
||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
}
|
||||
}
|
||||
106
src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java
Normal file
106
src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Menu {
|
||||
|
||||
private String id;
|
||||
private String title;
|
||||
private int rows;
|
||||
private ConfigurationNode config;
|
||||
|
||||
public Menu(String id, ConfigurationNode config) {
|
||||
this.id = id;
|
||||
this.config = config;
|
||||
|
||||
title = config.node("title").getString("chest");
|
||||
rows = config.node("rows").getInt(1);
|
||||
|
||||
Menus.addMenu(this);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public int getRows() {
|
||||
return this.getRows();
|
||||
}
|
||||
|
||||
public void openMenu(CosmeticUser user) {
|
||||
Player player = user.getPlayer();
|
||||
final Component component = Adventure.MINI_MESSAGE.deserialize(Placeholder.applyPapiPlaceholders(player, this.title));
|
||||
Gui gui = Gui.gui().
|
||||
title(component).
|
||||
rows(this.rows).
|
||||
create();
|
||||
|
||||
gui.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
|
||||
gui = getItems(user, gui);
|
||||
|
||||
gui.open(player);
|
||||
|
||||
}
|
||||
|
||||
private Gui getItems(CosmeticUser user, Gui gui) {
|
||||
Player player = user.getPlayer();
|
||||
|
||||
for (ConfigurationNode config : config.node("items").childrenMap().values()) {
|
||||
int slotNumber = Integer.valueOf(config.key().toString());
|
||||
|
||||
ItemStack item;
|
||||
|
||||
try {
|
||||
item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config.node("item"));
|
||||
//item = config.node("item").get(ItemStack.class);
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("something went wrong! " + item);
|
||||
continue;
|
||||
}
|
||||
|
||||
GuiItem guiItem = ItemBuilder.from(item).asGuiItem();
|
||||
guiItem.setAction(event -> {
|
||||
if (config.node("action").virtual()) return;
|
||||
String action = config.node("action").getString();
|
||||
List<String> processedAction = Arrays.asList(action.split(" "));
|
||||
if (processedAction.isEmpty()) return;
|
||||
if (processedAction.get(0).equalsIgnoreCase("equip")) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(processedAction.get(1));
|
||||
if (cosmetic == null) return;
|
||||
user.toggleCosmetic(cosmetic);
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
gui.updateItem(slotNumber, guiItem);
|
||||
}
|
||||
});
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Added " + slotNumber + " as " + guiItem + " in the menu");
|
||||
gui.setItem(slotNumber, guiItem);
|
||||
}
|
||||
return gui;
|
||||
}
|
||||
}
|
||||
65
src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java
Normal file
65
src/main/java/com/hibiscusmc/hmccosmetics/gui/Menus.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Menus {
|
||||
|
||||
private static HashMap<String, Menu> MENUS = new HashMap<>();
|
||||
|
||||
public static void addMenu(Menu menu) {
|
||||
MENUS.put(menu.getId(), menu);
|
||||
}
|
||||
|
||||
public static Menu getMenu(String id) {
|
||||
return MENUS.get(id);
|
||||
}
|
||||
|
||||
public static Collection<Menu> getMenu() {
|
||||
return MENUS.values();
|
||||
}
|
||||
|
||||
public static List<String> getMenuNames() {
|
||||
List<String> names = new ArrayList<>();
|
||||
|
||||
for (Menu menu : MENUS.values()) {
|
||||
names.add(menu.getId());
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
MENUS.clear();
|
||||
|
||||
File cosmeticFolder = new File(HMCCosmeticsPlugin.getInstance().getDataFolder() + "/menus");
|
||||
if (!cosmeticFolder.exists()) cosmeticFolder.mkdir();
|
||||
|
||||
File[] directoryListing = cosmeticFolder.listFiles();
|
||||
if (directoryListing == null) return;
|
||||
|
||||
for (File child : directoryListing) {
|
||||
if (child.toString().contains(".yml") || child.toString().contains(".yaml")) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Scanning " + child);
|
||||
// Loads file
|
||||
YamlConfigurationLoader loader = YamlConfigurationLoader.builder().path(child.toPath()).build();
|
||||
CommentedConfigurationNode root;
|
||||
try {
|
||||
root = loader.load();
|
||||
} catch (ConfigurateException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
new Menu(FilenameUtils.removeExtension(child.getName()), root);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerConnectionListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
|
||||
CosmeticUsers.addUser(user);
|
||||
user.updateCosmetic();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||
Database.save(user);
|
||||
CosmeticUsers.removeUser(user.getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerGameListener implements Listener {
|
||||
|
||||
public PlayerGameListener() {
|
||||
registerInventoryClickListener();
|
||||
registerMenuChangeListener();
|
||||
registerPlayerEquipmentListener();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerClick(@NotNull InventoryClickEvent event) {
|
||||
if (event.getClick() != ClickType.SHIFT_LEFT && event.getClick() != ClickType.SHIFT_RIGHT) return;
|
||||
//if (event.getSlotType() != InventoryType.SlotType.ARMOR) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getWhoClicked().getUniqueId());
|
||||
if (user == null) return;
|
||||
EquipmentSlot slot = getArmorSlot(event.getCurrentItem().getType());
|
||||
if (slot == null) return;
|
||||
CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot);
|
||||
if (cosmeticSlot == null) return;
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(cosmeticSlot);
|
||||
}, 1);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Event fired, updated cosmetic " + cosmeticSlot);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerShift(PlayerToggleSneakEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
|
||||
event.getPlayer().sendMessage("Shift");
|
||||
if (!event.isSneaking()) return;
|
||||
if (user == null) return;
|
||||
if (!user.isInWardrobe()) return;
|
||||
|
||||
user.leaveWardrobe();
|
||||
event.getPlayer().sendMessage("Left Wardrobe");
|
||||
}
|
||||
|
||||
private void registerInventoryClickListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
int invTypeClicked = event.getPacket().getIntegers().read(0);
|
||||
int slotClicked = event.getPacket().getIntegers().read(2);
|
||||
|
||||
// Must be a player inventory.
|
||||
if (invTypeClicked != 0) return;
|
||||
// -999 is when a player clicks outside their inventory. https://wiki.vg/Inventory#Player_Inventory
|
||||
if (slotClicked == -999) return;
|
||||
if (!(event.getPlayer() instanceof Player)) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
CosmeticSlot cosmeticSlot = InventoryUtils.NMSCosmeticSlot(slotClicked);
|
||||
if (cosmeticSlot == null) return;
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(cosmeticSlot);
|
||||
}, 1);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Packet fired, updated cosmetic " + cosmeticSlot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerMenuChangeListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.WINDOW_ITEMS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Menu Initial ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
if (!(event.getPlayer() instanceof Player)) return;
|
||||
|
||||
int windowID = event.getPacket().getIntegers().read(0);
|
||||
List<ItemStack> slotData = event.getPacket().getItemListModifier().read(0);
|
||||
if (windowID != 0) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
||||
if (!(cosmetic instanceof CosmeticArmorType)) continue;
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
}, 1);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Menu Fired, updated cosmetics " + cosmetic);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerPlayerEquipmentListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("equipment packet is activated");
|
||||
Player player = event.getPlayer(); // Player that's sent
|
||||
int entityID = event.getPacket().getIntegers().read(0);
|
||||
// User
|
||||
CosmeticUser user = CosmeticUsers.getUser(entityID);
|
||||
if (user == null) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("equipment packet is activated - user null");
|
||||
return;
|
||||
}
|
||||
|
||||
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
|
||||
|
||||
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(InventoryUtils.BukkitCosmeticSlot(equipmentSlot));
|
||||
if (cosmeticArmor == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), cosmeticArmor.getCosmeticItem());
|
||||
armor.add(pair);
|
||||
}
|
||||
|
||||
event.getPacket().getSlotStackPairLists().write(0, armor);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Nullable
|
||||
private EquipmentSlot getArmorSlot(final Material material) {
|
||||
for (final EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
final Set<Material> armorItems = ARMOR_ITEMS.get(slot);
|
||||
if (armorItems == null) continue;
|
||||
if (material == null) continue;
|
||||
if (armorItems.contains(material)) return slot;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final static Map<EquipmentSlot, Set<Material>> ARMOR_ITEMS = Map.of(
|
||||
EquipmentSlot.HEAD, EnumSet.of(
|
||||
Material.LEATHER_HELMET,
|
||||
Material.CHAINMAIL_HELMET,
|
||||
Material.IRON_HELMET,
|
||||
Material.GOLDEN_HELMET,
|
||||
Material.DIAMOND_HELMET,
|
||||
Material.NETHERITE_HELMET,
|
||||
Material.TURTLE_HELMET
|
||||
),
|
||||
EquipmentSlot.CHEST, EnumSet.of(
|
||||
Material.LEATHER_CHESTPLATE,
|
||||
Material.CHAINMAIL_CHESTPLATE,
|
||||
Material.IRON_CHESTPLATE,
|
||||
Material.GOLDEN_CHESTPLATE,
|
||||
Material.DIAMOND_CHESTPLATE,
|
||||
Material.NETHERITE_CHESTPLATE,
|
||||
Material.ELYTRA
|
||||
),
|
||||
EquipmentSlot.LEGS, EnumSet.of(
|
||||
Material.LEATHER_LEGGINGS,
|
||||
Material.CHAINMAIL_LEGGINGS,
|
||||
Material.IRON_LEGGINGS,
|
||||
Material.GOLDEN_LEGGINGS,
|
||||
Material.DIAMOND_LEGGINGS,
|
||||
Material.NETHERITE_LEGGINGS
|
||||
),
|
||||
EquipmentSlot.FEET, EnumSet.of(
|
||||
Material.LEATHER_BOOTS,
|
||||
Material.CHAINMAIL_BOOTS,
|
||||
Material.IRON_BOOTS,
|
||||
Material.GOLDEN_BOOTS,
|
||||
Material.DIAMOND_BOOTS,
|
||||
Material.NETHERITE_BOOTS
|
||||
)
|
||||
);
|
||||
}
|
||||
173
src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java
Normal file
173
src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java
Normal file
@@ -0,0 +1,173 @@
|
||||
package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.entities.InvisibleArmorstand;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CosmeticUser {
|
||||
|
||||
private UUID uniqueId;
|
||||
private HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
||||
private Wardrobe wardrobe;
|
||||
private InvisibleArmorstand invisibleArmorstand;
|
||||
|
||||
|
||||
public CosmeticUser(UUID uuid) {
|
||||
this.uniqueId = uuid;
|
||||
}
|
||||
|
||||
public UUID getUniqueId() {
|
||||
return this.uniqueId;
|
||||
}
|
||||
|
||||
public Cosmetic getCosmetic(CosmeticSlot slot) {
|
||||
return playerCosmetics.get(slot);
|
||||
}
|
||||
|
||||
public Collection<Cosmetic> getCosmetic() {
|
||||
return playerCosmetics.values();
|
||||
}
|
||||
|
||||
public int getArmorstandId() {
|
||||
return invisibleArmorstand.getId();
|
||||
}
|
||||
|
||||
public InvisibleArmorstand getBackpackEntity() {
|
||||
return this.invisibleArmorstand;
|
||||
}
|
||||
|
||||
public void addPlayerCosmetic(Cosmetic cosmetic) {
|
||||
playerCosmetics.put(cosmetic.getSlot(), cosmetic);
|
||||
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
|
||||
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
|
||||
spawnBackpack();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCosmeticSlot(CosmeticSlot slot) {
|
||||
if (slot == CosmeticSlot.BACKPACK) {
|
||||
despawnBackpack();
|
||||
}
|
||||
playerCosmetics.remove(slot);
|
||||
}
|
||||
|
||||
public void toggleCosmetic(Cosmetic cosmetic) {
|
||||
if (hasCosmetic(cosmetic)) {
|
||||
removeCosmeticSlot(cosmetic);
|
||||
return;
|
||||
}
|
||||
addPlayerCosmetic(cosmetic);
|
||||
}
|
||||
|
||||
public void removeCosmeticSlot(Cosmetic cosmetic) {
|
||||
removeCosmeticSlot(cosmetic.getSlot());
|
||||
}
|
||||
|
||||
public boolean hasCosmeticInSlot(CosmeticSlot slot) {
|
||||
return playerCosmetics.containsKey(slot);
|
||||
}
|
||||
|
||||
public void updateCosmetic(CosmeticSlot slot) {
|
||||
if (getCosmetic(slot) == null) {
|
||||
// TODO: Add something here
|
||||
return;
|
||||
}
|
||||
getCosmetic(slot).update(this);
|
||||
return;
|
||||
}
|
||||
|
||||
public void updateCosmetic() {
|
||||
for (Cosmetic cosmetic : playerCosmetics.values()) {
|
||||
updateCosmetic(cosmetic.getSlot());
|
||||
}
|
||||
}
|
||||
|
||||
public void enterWardrobe() {
|
||||
wardrobe = new Wardrobe(this);
|
||||
wardrobe.start();
|
||||
}
|
||||
|
||||
public Wardrobe getWardrobe() {
|
||||
return wardrobe;
|
||||
}
|
||||
|
||||
public void leaveWardrobe() {
|
||||
wardrobe.end();
|
||||
wardrobe = null;
|
||||
}
|
||||
|
||||
public boolean isInWardrobe() {
|
||||
if (wardrobe == null) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void toggleWardrobe() {
|
||||
if (isInWardrobe()) {
|
||||
leaveWardrobe();
|
||||
} else {
|
||||
enterWardrobe();
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnBackpack() {
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
|
||||
if (this.invisibleArmorstand != null) return;
|
||||
this.invisibleArmorstand = new InvisibleArmorstand(player.getLocation());
|
||||
((CraftWorld) player.getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
PacketManager.armorStandMetaPacket((Entity) invisibleArmorstand, sentTo);
|
||||
PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
|
||||
|
||||
player.addPassenger(invisibleArmorstand.getBukkitEntity());
|
||||
|
||||
}
|
||||
|
||||
public void despawnBackpack() {
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
if (invisibleArmorstand == null) return;
|
||||
invisibleArmorstand.remove(net.minecraft.world.entity.Entity.RemovalReason.DISCARDED);
|
||||
this.invisibleArmorstand = null;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(uniqueId);
|
||||
}
|
||||
|
||||
public boolean hasCosmetic(Cosmetic cosmetic) {
|
||||
if (!cosmetic.requiresPermission()) return true;
|
||||
if (getPlayer().hasPermission(cosmetic.getPermission())) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void hidePlayer() {
|
||||
Player player = getPlayer();
|
||||
if (player == null) return;
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.hidePlayer(HMCCosmeticsPlugin.getInstance(), player);
|
||||
player.hidePlayer(HMCCosmeticsPlugin.getInstance(), p);
|
||||
}
|
||||
}
|
||||
|
||||
public void showPlayer() {
|
||||
Player player = getPlayer();
|
||||
if (player == null) return;
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
p.showPlayer(HMCCosmeticsPlugin.getInstance(), player);
|
||||
player.showPlayer(HMCCosmeticsPlugin.getInstance(), p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CosmeticUsers {
|
||||
|
||||
private static HashBiMap<UUID, CosmeticUser> COSMETIC_USERS = HashBiMap.create();
|
||||
|
||||
public static void addUser(CosmeticUser user) {
|
||||
if (COSMETIC_USERS.containsKey(user.getUniqueId())) return; // do not add if already exists
|
||||
COSMETIC_USERS.put(user.getUniqueId(), user);
|
||||
}
|
||||
|
||||
public static void removeUser(UUID uuid) {
|
||||
COSMETIC_USERS.remove(uuid);
|
||||
}
|
||||
|
||||
public static void removeUser(CosmeticUser user) {
|
||||
COSMETIC_USERS.remove(user);
|
||||
}
|
||||
|
||||
public static CosmeticUser getUser(UUID uuid) {
|
||||
return COSMETIC_USERS.get(uuid);
|
||||
}
|
||||
|
||||
public static CosmeticUser getUser(Player player) {
|
||||
return COSMETIC_USERS.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static CosmeticUser getUser(int entityId) {
|
||||
Entity entity = ServerUtils.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
if (entity.getType().equals(EntityType.PLAYER)) return null;
|
||||
return COSMETIC_USERS.get(entity.getUniqueId());
|
||||
}
|
||||
}
|
||||
162
src/main/java/com/hibiscusmc/hmccosmetics/user/Wardrobe.java
Normal file
162
src/main/java/com/hibiscusmc/hmccosmetics/user/Wardrobe.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Wardrobe {
|
||||
|
||||
private int NPC_ID;
|
||||
private UUID WARDROBE_UUID;
|
||||
private int ARMORSTAND_ID;
|
||||
private GameMode originalGamemode;
|
||||
private CosmeticUser VIEWER;
|
||||
private Location viewingLocation;
|
||||
private Location npcLocation;
|
||||
private Location exitLocation;
|
||||
private Boolean active;
|
||||
|
||||
public Wardrobe(CosmeticUser user) {
|
||||
NPC_ID = Entity.nextEntityId();
|
||||
ARMORSTAND_ID = Entity.nextEntityId();
|
||||
WARDROBE_UUID = UUID.randomUUID();
|
||||
VIEWER = user;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Player player = VIEWER.getPlayer();
|
||||
player.sendMessage("start");
|
||||
player.sendMessage("NPC ID " + NPC_ID);
|
||||
player.sendMessage("armorstand id " + ARMORSTAND_ID);
|
||||
|
||||
if (!WardrobeSettings.inDistanceOfStatic(player.getLocation())) {
|
||||
player.sendMessage("You are to far away!");
|
||||
return;
|
||||
}
|
||||
|
||||
this.originalGamemode = player.getGameMode();
|
||||
if (WardrobeSettings.isReturnLastLocation()) {
|
||||
this.exitLocation = player.getLocation().clone();
|
||||
} else {
|
||||
this.exitLocation = WardrobeSettings.getLeaveLocation();
|
||||
}
|
||||
|
||||
VIEWER.hidePlayer();
|
||||
List<Player> viewer = List.of(player);
|
||||
// Armorstand
|
||||
PacketManager.sendEntitySpawnPacket(WardrobeSettings.getViewerLocation(), ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||
PacketManager.sendInvisibilityPacket(ARMORSTAND_ID, viewer);
|
||||
PacketManager.sendLookPacket(ARMORSTAND_ID, WardrobeSettings.getViewerLocation(), viewer);
|
||||
|
||||
// Player
|
||||
PacketManager.gamemodeChangePacket(player, 3);
|
||||
PacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
|
||||
|
||||
// NPC
|
||||
PacketManager.sendFakePlayerInfoPacket(player, NPC_ID, WARDROBE_UUID, viewer);
|
||||
|
||||
// NPC 2
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
PacketManager.sendFakePlayerSpawnPacket(WardrobeSettings.getWardrobeLocation(), WARDROBE_UUID, NPC_ID, viewer);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Spawned Fake Player on " + WardrobeSettings.getWardrobeLocation());
|
||||
}, 4);
|
||||
|
||||
|
||||
// Location
|
||||
PacketManager.sendLookPacket(NPC_ID, WardrobeSettings.getWardrobeLocation(), viewer);
|
||||
PacketManager.sendRotationPacket(NPC_ID, WardrobeSettings.getWardrobeLocation(), true, viewer);
|
||||
|
||||
this.active = true;
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
public void end() {
|
||||
this.active = false;
|
||||
|
||||
Player player = VIEWER.getPlayer();
|
||||
player.sendMessage("end");
|
||||
player.sendMessage("NPC ID " + NPC_ID);
|
||||
player.sendMessage("armorstand id " + ARMORSTAND_ID);
|
||||
|
||||
List<Player> viewer = List.of(player);
|
||||
|
||||
// NPC
|
||||
PacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success
|
||||
PacketManager.sendRemovePlayerPacket(player, player.getUniqueId(), viewer); // Success
|
||||
|
||||
// Player
|
||||
PacketManager.sendCameraPacket(player.getEntityId(), viewer);
|
||||
PacketManager.gamemodeChangePacket(player, ServerUtils.convertGamemode(this.originalGamemode)); // Success
|
||||
|
||||
// Armorstand
|
||||
PacketManager.sendEntityDestroyPacket(ARMORSTAND_ID, viewer); // Sucess
|
||||
|
||||
//PacketManager.sendEntityDestroyPacket(player.getEntityId(), viewer); // Success
|
||||
player.setGameMode(this.originalGamemode);
|
||||
VIEWER.showPlayer();
|
||||
|
||||
if (exitLocation == null) {
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
} else {
|
||||
player.teleport(exitLocation);
|
||||
}
|
||||
if (!player.isOnline()) return;
|
||||
VIEWER.updateCosmetic();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
final AtomicInteger data = new AtomicInteger();
|
||||
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (active == false) {
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Active is false");
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Update ");
|
||||
List<Player> viewer = List.of(VIEWER.getPlayer());
|
||||
|
||||
Location location = WardrobeSettings.getWardrobeLocation().clone();
|
||||
int yaw = data.get();
|
||||
location.setYaw(yaw);
|
||||
|
||||
PacketManager.sendLookPacket(NPC_ID, location, viewer);
|
||||
VIEWER.updateCosmetic();
|
||||
int rotationSpeed = 3;
|
||||
location.setYaw(getNextYaw(yaw - 30, rotationSpeed));
|
||||
PacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
|
||||
data.set(getNextYaw(yaw, rotationSpeed));
|
||||
}
|
||||
};
|
||||
|
||||
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 10, 0);
|
||||
}
|
||||
|
||||
private static int getNextYaw(final int current, final int rotationSpeed) {
|
||||
int nextYaw = current + rotationSpeed;
|
||||
if (nextYaw > 179) {
|
||||
nextYaw = (current + rotationSpeed) - 358;
|
||||
return nextYaw;
|
||||
}
|
||||
return nextYaw;
|
||||
}
|
||||
|
||||
public int getARMORSTAND_ID() {
|
||||
return ARMORSTAND_ID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class InventoryUtils {
|
||||
|
||||
/**
|
||||
* Converts from the Bukkit item slots to ProtocolLib item slots. Will produce a null if an improper bukkit item slot is sent through
|
||||
* @param slot The BUKKIT item slot to convert.
|
||||
* @return The ProtocolLib item slot that is returned
|
||||
*/
|
||||
public static EnumWrappers.ItemSlot itemBukkitSlot(final EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HEAD -> EnumWrappers.ItemSlot.HEAD;
|
||||
case CHEST -> EnumWrappers.ItemSlot.CHEST;
|
||||
case LEGS -> EnumWrappers.ItemSlot.LEGS;
|
||||
case FEET -> EnumWrappers.ItemSlot.FEET;
|
||||
case HAND -> EnumWrappers.ItemSlot.MAINHAND;
|
||||
case OFF_HAND -> EnumWrappers.ItemSlot.OFFHAND;
|
||||
};
|
||||
}
|
||||
|
||||
private static int getPacketArmorSlot(final EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HEAD -> 5;
|
||||
case CHEST -> 6;
|
||||
case LEGS -> 7;
|
||||
case FEET -> 8;
|
||||
case OFF_HAND -> 45;
|
||||
default -> -1;
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static EquipmentSlot getPacketArmorSlot(final int slot) {
|
||||
return switch (slot) {
|
||||
case 5 -> EquipmentSlot.HEAD;
|
||||
case 6 -> EquipmentSlot.CHEST;
|
||||
case 7 -> EquipmentSlot.LEGS;
|
||||
case 8 -> EquipmentSlot.FEET;
|
||||
case 45 -> EquipmentSlot.OFF_HAND;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case OFF_HAND -> CosmeticSlot.OFFHAND;
|
||||
case FEET -> CosmeticSlot.BOOTS;
|
||||
case LEGS -> CosmeticSlot.LEGGINGS;
|
||||
case CHEST -> CosmeticSlot.CHESTPLATE;
|
||||
case HEAD -> CosmeticSlot.HELMET;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
public static CosmeticSlot BukkitCosmeticSlot(int slot) {
|
||||
switch (slot) {
|
||||
case 39 -> {
|
||||
return CosmeticSlot.HELMET;
|
||||
}
|
||||
case 38 -> {
|
||||
return CosmeticSlot.CHESTPLATE;
|
||||
}
|
||||
case 37 -> {
|
||||
return CosmeticSlot.LEGGINGS;
|
||||
}
|
||||
case 36 -> {
|
||||
return CosmeticSlot.BOOTS;
|
||||
}
|
||||
case 40 -> {
|
||||
return CosmeticSlot.OFFHAND;
|
||||
}
|
||||
default -> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CosmeticSlot NMSCosmeticSlot(int slot) {
|
||||
switch (slot) {
|
||||
case 5 -> {
|
||||
return CosmeticSlot.HELMET;
|
||||
}
|
||||
case 6 -> {
|
||||
return CosmeticSlot.CHESTPLATE;
|
||||
}
|
||||
case 7 -> {
|
||||
return CosmeticSlot.LEGGINGS;
|
||||
}
|
||||
case 8 -> {
|
||||
return CosmeticSlot.BOOTS;
|
||||
}
|
||||
case 45 -> {
|
||||
return CosmeticSlot.OFFHAND;
|
||||
}
|
||||
default -> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static EquipmentSlot getEquipmentSlot(CosmeticSlot slot) {
|
||||
switch (slot) {
|
||||
case HELMET -> {
|
||||
return EquipmentSlot.HEAD;
|
||||
}
|
||||
case CHESTPLATE -> {
|
||||
return EquipmentSlot.CHEST;
|
||||
}
|
||||
case LEGGINGS -> {
|
||||
return EquipmentSlot.LEGS;
|
||||
}
|
||||
case BOOTS -> {
|
||||
return EquipmentSlot.FEET;
|
||||
}
|
||||
case OFFHAND -> {
|
||||
return EquipmentSlot.OFF_HAND;
|
||||
}
|
||||
default -> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerUtils {
|
||||
|
||||
public static WrappedSignedProperty getSkin(Player player) {
|
||||
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
||||
.get("textures").stream().findAny().orElse(null);
|
||||
|
||||
if (skinData == null) {
|
||||
return null;
|
||||
}
|
||||
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
||||
}
|
||||
|
||||
public static List<Player> getNearbyPlayers(Player player) {
|
||||
return getNearbyPlayers(player.getLocation());
|
||||
}
|
||||
|
||||
public static List<Player> getNearbyPlayers(Location location) {
|
||||
List<Player> players = new ArrayList<>();
|
||||
for (Entity entity : location.getWorld().getNearbyEntities(location, 32, 32, 32)) {
|
||||
if (entity instanceof Player) {
|
||||
players.add((Player) entity);
|
||||
}
|
||||
}
|
||||
return players;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class ServerUtils {
|
||||
|
||||
/**
|
||||
* Converts a bukkit gamemode into an integer for use in packets
|
||||
* @param gamemode Bukkit gamemode to convert.
|
||||
* @return int of the gamemode
|
||||
*/
|
||||
public static int convertGamemode(final GameMode gamemode) {
|
||||
return switch (gamemode) {
|
||||
case SURVIVAL -> 0;
|
||||
case CREATIVE -> 1;
|
||||
case ADVENTURE -> 2;
|
||||
case SPECTATOR -> 3;
|
||||
};
|
||||
}
|
||||
|
||||
public static Entity getEntity(int entityId) {
|
||||
return getNMSEntity(entityId).getBukkitEntity();
|
||||
}
|
||||
|
||||
public static net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.builder;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
|
||||
public class ColorBuilder {
|
||||
|
||||
public static boolean canBeColored(final Material material) {
|
||||
return canBeColored(new ItemStack(material));
|
||||
}
|
||||
|
||||
public static boolean canBeColored(final ItemStack itemStack) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
return (itemMeta instanceof LeatherArmorMeta ||
|
||||
itemMeta instanceof PotionMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color armor color
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public static ItemMeta color(ItemMeta itemMeta, final Color color) {
|
||||
if (itemMeta instanceof final PotionMeta meta) {
|
||||
meta.setColor(color);
|
||||
}
|
||||
if (itemMeta instanceof final LeatherArmorMeta meta) {
|
||||
meta.setColor(color);
|
||||
}
|
||||
return itemMeta;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.builder;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Placeholder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
protected Material material;
|
||||
protected int amount;
|
||||
protected ItemMeta itemMeta;
|
||||
|
||||
/**
|
||||
* @param material builder material
|
||||
*/
|
||||
|
||||
ItemBuilder(final Material material) {
|
||||
this.material = material;
|
||||
this.itemMeta = Bukkit.getItemFactory().getItemMeta(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemStack builder ItemStack
|
||||
*/
|
||||
|
||||
ItemBuilder(final ItemStack itemStack) {
|
||||
this.material = itemStack.getType();
|
||||
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
|
||||
: Bukkit.getItemFactory().getItemMeta(this.material);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param material builder material
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static ItemBuilder from(final Material material) {
|
||||
return new ItemBuilder(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemStack builder ItemStack
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static ItemBuilder from(final ItemStack itemStack) {
|
||||
return new ItemBuilder(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount ItemStack amount
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder amount(final int amount) {
|
||||
this.amount = Math.min(Math.max(1, amount), 64);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name ItemStack name
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder name(final String name) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
this.itemMeta.setDisplayName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets placeholders to the item's name
|
||||
*
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
public ItemBuilder namePlaceholders(final Map<String, String> placeholders) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
|
||||
final String name = Placeholder.
|
||||
applyPlaceholders(this.itemMeta.getDisplayName(), placeholders);
|
||||
this.itemMeta.setDisplayName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lore ItemStack lore
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder lore(final List<String> lore) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
this.itemMeta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets placeholders to the item's lore
|
||||
*
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
|
||||
public ItemBuilder lorePlaceholders(final Map<String, String> placeholders) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
final List<String> lore = new ArrayList<>();
|
||||
|
||||
final List<String> previousLore = this.itemMeta.getLore();
|
||||
|
||||
if (previousLore == null) {
|
||||
return this;
|
||||
}
|
||||
|
||||
for (final String line : previousLore) {
|
||||
lore.add(Placeholder.applyPlaceholders(
|
||||
line, placeholders
|
||||
));
|
||||
}
|
||||
|
||||
this.itemMeta.setLore(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder papiPlaceholders(final Player player) {
|
||||
this.lorePapiPlaceholders(player);
|
||||
this.namePapiPlaceholders(player);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void lorePapiPlaceholders(final Player player) {
|
||||
if (this.itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
final List<String> newLore = new ArrayList<>();
|
||||
|
||||
final List<String> lore = this.itemMeta.getLore();
|
||||
|
||||
if (lore == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final String line : this.itemMeta.getLore()) {
|
||||
newLore.add(Placeholder.applyPapiPlaceholders(player, line));
|
||||
}
|
||||
|
||||
this.itemMeta.setLore(newLore);
|
||||
}
|
||||
|
||||
private void namePapiPlaceholders(final Player player) {
|
||||
if (this.itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.itemMeta.setDisplayName(
|
||||
Placeholder.applyPapiPlaceholders(
|
||||
player,
|
||||
this.itemMeta.getDisplayName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unbreakable whether the ItemStack is unbreakable
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder unbreakable(final boolean unbreakable) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
this.itemMeta.setUnbreakable(unbreakable);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder glow(final boolean glow) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
if (glow) {
|
||||
this.itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
this.itemMeta.addEnchant(Enchantment.LUCK, 1, true);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enchantments enchants to be added to the ItemStack
|
||||
* @param ignoreLeveLRestrictions whether to ignore enchantment level restrictions
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder enchants(final Map<Enchantment, Integer> enchantments,
|
||||
boolean ignoreLeveLRestrictions) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
enchantments.forEach((enchantment, level) -> this.itemMeta.addEnchant(enchantment, level,
|
||||
ignoreLeveLRestrictions));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemFlags ItemStack ItemFlags
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder itemFlags(final Set<ItemFlag> itemFlags) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
this.itemMeta.addItemFlags(itemFlags.toArray(new ItemFlag[0]));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param modelData ItemStack modelData
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder modelData(final int modelData) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
this.itemMeta.setCustomModelData(modelData);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return built ItemStack
|
||||
*/
|
||||
|
||||
public ItemStack build() {
|
||||
final ItemStack itemStack = new ItemStack(this.material, Math.max(this.amount, 1));
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class Adventure {
|
||||
|
||||
public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
|
||||
.hexColors()
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build();
|
||||
|
||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().tags(
|
||||
StandardTags.defaults()
|
||||
).
|
||||
build();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class Keys {
|
||||
|
||||
static HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||
public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic");
|
||||
public static final NamespacedKey TOKEN_KEY = new NamespacedKey(plugin, "token-key");
|
||||
|
||||
public static void setKey(final ItemStack itemStack) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
itemMeta.getPersistentDataContainer().set(ITEM_KEY, PersistentDataType.BYTE, (byte) 1);
|
||||
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
public static <T, Z> void setKey(
|
||||
final ItemStack itemStack,
|
||||
final NamespacedKey key,
|
||||
final PersistentDataType<T, Z> type,
|
||||
final Z value) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
itemMeta.getPersistentDataContainer().set(key, type, value);
|
||||
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
public static boolean hasKey(final ItemStack itemStack) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (itemMeta == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return itemMeta.getPersistentDataContainer().has(ITEM_KEY, PersistentDataType.BYTE);
|
||||
}
|
||||
|
||||
public static <T, Z> boolean hasKey(final ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (itemMeta == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return itemMeta.getPersistentDataContainer().has(key, type);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T, Z> Z getValue(final ItemStack itemStack, final NamespacedKey key, final PersistentDataType<T, Z> type) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (itemMeta == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return itemMeta.getPersistentDataContainer().get(key, type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Placeholder {
|
||||
|
||||
public static final String PREFIX = "%prefix%";
|
||||
public static final String TYPE = "%type%";
|
||||
public static final String ITEM = "%item%";
|
||||
public static final String FILE = "%file%";
|
||||
|
||||
public static final String PLAYER = "%player%";
|
||||
public static final String ENABLED = "%enabled%";
|
||||
public static final String ALLOWED = "%allowed%";
|
||||
public static final String ID = "%id%";
|
||||
|
||||
/**
|
||||
* @param message message being translated
|
||||
* @param placeholders placeholders applied
|
||||
* @return message with placeholders applied
|
||||
*/
|
||||
|
||||
public static String applyPlaceholders(String message, final Map<String, String> placeholders) {
|
||||
for (final Map.Entry<String, String> entry : placeholders.entrySet()) {
|
||||
message = message.replace(entry.getKey(), Translation.translate(entry.getValue()));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public static String applyPapiPlaceholders(@Nullable final Player player,
|
||||
final String message) {
|
||||
/*
|
||||
if (HookManager.getInstance().isEnabled(PAPIHook.class)) {
|
||||
return HookManager.getInstance().getPapiHook().parse(player, message);
|
||||
}
|
||||
*/
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
* @param parsed message to be parsed
|
||||
* @return MiniMessage parsed string
|
||||
*/
|
||||
|
||||
public static Component parse(final String parsed) {
|
||||
return Adventure.MINI_MESSAGE.deserialize(parsed);
|
||||
}
|
||||
|
||||
public static String parseStringToString(final String parsed) {
|
||||
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
|
||||
}
|
||||
|
||||
public static String formatArmorItemType(String type) {
|
||||
type = type.toLowerCase();
|
||||
final String[] parts = type.split(" ");
|
||||
|
||||
final String firstPart = parts[0].substring(0, 1).toUpperCase() + parts[0].substring(1);
|
||||
|
||||
if (parts.length == 1) {
|
||||
return firstPart;
|
||||
}
|
||||
|
||||
return firstPart + parts[1].substring(0, 1).toUpperCase() + parts[1].substring(1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class Translation {
|
||||
|
||||
public static final String TRUE = "true";
|
||||
public static final String FALSE = "false";
|
||||
public static final String NONE = "none";
|
||||
private static final String FILE_NAME = "translations.yml";
|
||||
private static final String TRANSLATION_PATH = "translations";
|
||||
|
||||
private static Map<String, String> translations;
|
||||
|
||||
public static String translate(final String key) {
|
||||
return translations.getOrDefault(key, null);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
final File file = new File(HMCCosmeticsPlugin.getInstance().getDataFolder(), FILE_NAME);
|
||||
if (!file.exists()) {
|
||||
HMCCosmeticsPlugin.getInstance().saveResource(FILE_NAME, false);
|
||||
}
|
||||
|
||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
final ConfigurationSection section = config.getConfigurationSection(TRANSLATION_PATH);
|
||||
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final String key : section.getKeys(false)) {
|
||||
this.translations.put(key, section.getString(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
118
src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Utils.java
Normal file
118
src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Utils.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* @param original Object to be checked if null
|
||||
* @param replacement Object returned if original is null
|
||||
* @return original if not null, otherwise replacement
|
||||
*/
|
||||
|
||||
public static <T> T replaceIfNull(final @Nullable T original, final @NotNull T replacement) {
|
||||
return replaceIfNull(original, replacement, t -> {
|
||||
});
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> T replaceIf(final @Nullable T original, final T replacement, final @Nullable T... checks) {
|
||||
for (final T check : checks) {
|
||||
if (original == check) return replacement;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
public static <T> T replaceIf(final @Nullable T original, final T replacement, final Predicate<T> predicate) {
|
||||
if (predicate.test(original)) return replacement;
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param original Object to be checked if null
|
||||
* @param replacement Object returned if original is null
|
||||
* @param consumer accepts the original object, can be used for logging
|
||||
* @return original if not null, otherwise replacement
|
||||
*/
|
||||
|
||||
public static <T> T replaceIfNull(final @Nullable T original, final T replacement,
|
||||
final @NotNull Consumer<T> consumer) {
|
||||
if (original == null) {
|
||||
consumer.accept(replacement);
|
||||
return replacement;
|
||||
}
|
||||
consumer.accept(original);
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t object being checked
|
||||
* @param consumer accepted if t is not null
|
||||
* @param <T> type
|
||||
*/
|
||||
|
||||
public static <T> void doIfNotNull(final @Nullable T t, final @NotNull Consumer<T> consumer) {
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
consumer.accept(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t object being checked
|
||||
* @param function applied if t is not null
|
||||
* @param <T> type
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static <T> Optional<T> returnIfNotNull(final @Nullable T t,
|
||||
final @NotNull Function<T, T> function) {
|
||||
if (t == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(function.apply(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enumAsString Enum value as a string to be parsed
|
||||
* @param enumClass enum type enumAsString is to be converted to
|
||||
* @param defaultEnum default value to be returned
|
||||
* @return enumAsString as an enum, or default enum if it could not be parsed
|
||||
*/
|
||||
|
||||
public static <E extends Enum<E>> E stringToEnum(final @NotNull String enumAsString,
|
||||
final @NotNull Class<E> enumClass,
|
||||
E defaultEnum) {
|
||||
return stringToEnum(enumAsString, enumClass, defaultEnum, e -> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enumAsString Enum value as a string to be parsed
|
||||
* @param enumClass enum type enumAsString is to be converted to
|
||||
* @param defaultEnum default value to be returned
|
||||
* @param consumer accepts the returned enum, can be used for logging
|
||||
* @return enumAsString as an enum, or default enum if it could not be parsed
|
||||
*/
|
||||
|
||||
public static <E extends Enum<E>> E stringToEnum(final @NotNull String enumAsString,
|
||||
@NotNull final Class<E> enumClass,
|
||||
final E defaultEnum,
|
||||
final @NotNull Consumer<E> consumer) {
|
||||
try {
|
||||
final E value = Enum.valueOf(enumClass, enumAsString);
|
||||
consumer.accept(value);
|
||||
return value;
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
consumer.accept(defaultEnum);
|
||||
return defaultEnum;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.NetworkMarker;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BasePacket {
|
||||
|
||||
public static void sendPacket(Player player, Packet<?> packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.*;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetCameraPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketManager extends BasePacket {
|
||||
|
||||
public static void sendEntitySpawnPacket(
|
||||
final Location location,
|
||||
final int entityId,
|
||||
final EntityType entityType,
|
||||
final UUID uuid,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getUUIDs().write(0, uuid);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getEntityTypeModifier().write(0, entityType);
|
||||
packet.getDoubles().
|
||||
write(0, location.getX()).
|
||||
write(1, location.getY()).
|
||||
write(2, location.getZ());
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void gamemodeChangePacket(
|
||||
Player player,
|
||||
int gamemode
|
||||
) {
|
||||
sendPacket(player, new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gamemode));
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info("Gamemode Change sent to " + player + " to be " + gamemode);
|
||||
}
|
||||
|
||||
public static void ridingMountPacket(
|
||||
int mountId,
|
||||
int passengerId,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
packet.getIntegers().write(0, mountId);
|
||||
packet.getIntegerArrays().write(0, new int[]{passengerId});
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void equipmentSlotUpdate(
|
||||
Player player,
|
||||
CosmeticSlot cosmetic,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player.getUniqueId());
|
||||
equipmentSlotUpdate(user, cosmetic, sendTo);
|
||||
}
|
||||
public static void equipmentSlotUpdate(
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
EquipmentSlot nmsSlot = null;
|
||||
ItemStack nmsItem = null;
|
||||
|
||||
if (cosmeticSlot == CosmeticSlot.BACKPACK || cosmeticSlot == CosmeticSlot.BALLOON) return;
|
||||
|
||||
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) return;
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
|
||||
nmsItem = CraftItemStack.asNMSCopy(cosmeticArmor.getCosmeticItem());
|
||||
|
||||
if (nmsSlot == null || nmsItem == null) return;
|
||||
|
||||
Pair<EquipmentSlot, ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
Player player = user.getPlayer();
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(player.getEntityId(), pairs);
|
||||
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
org.bukkit.inventory.ItemStack item,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
EquipmentSlot nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
||||
ItemStack nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
|
||||
Pair<EquipmentSlot, ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void armorstandEquipmentUpdate(
|
||||
CosmeticUser user,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
CosmeticBackpackType cosmeticBackpack = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
EquipmentSlot nmsSlot = CraftEquipmentSlot.getNMS(org.bukkit.inventory.EquipmentSlot.HEAD);
|
||||
ItemStack nmsItem = CraftItemStack.asNMSCopy(cosmeticBackpack.getBackpackItem());
|
||||
|
||||
Pair<EquipmentSlot, ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(user.getArmorstandId(), pairs);
|
||||
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void armorStandMetaPacket(
|
||||
Entity entity,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entity.getEntityId());
|
||||
WrappedDataWatcher metadata = new WrappedDataWatcher();
|
||||
if (metadata == null) return;
|
||||
// 0x10 & 0x20
|
||||
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
||||
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
|
||||
packet.getWatchableCollectionModifier().write(0, metadata.getWatchableObjects());
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendInvisibilityPacket(
|
||||
int entityId,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entityId);
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
||||
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendLookPacket(
|
||||
int entityId,
|
||||
Location location,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendRotationPacket(
|
||||
int entityId,
|
||||
Location location,
|
||||
boolean onGround,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||
float yaw = location.getYaw() * ROTATION_FACTOR;
|
||||
float pitch = location.getPitch() * ROTATION_FACTOR;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getBytes().write(0, (byte) (location.getYaw() * ROTATION_FACTOR));
|
||||
packet.getBytes().write(1, (byte) (location.getPitch() * ROTATION_FACTOR));
|
||||
|
||||
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
|
||||
packet.getBooleans().write(0, onGround);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mostly to deal with backpacks, this deals with entities riding other entities.
|
||||
* @param mountId The entity that is the "mount", ex. a player
|
||||
* @param passengerId The entity that is riding the mount, ex. a armorstand for a backpack
|
||||
* @param sendTo Whom to send the packet to
|
||||
*/
|
||||
public static void sendRidingPacket(
|
||||
final int mountId,
|
||||
final int passengerId,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
packet.getIntegers().write(0, mountId);
|
||||
packet.getIntegerArrays().write(0, new int[]{passengerId});
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys an entity from a player
|
||||
* @param entityId The entity to delete for a player
|
||||
* @param sendTo The players the packet should be sent to
|
||||
*/
|
||||
public static void sendEntityDestroyPacket(final int entityId, List<Player> sendTo) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a camera packet
|
||||
* @param entityId The Entity ID that camera will go towards
|
||||
* @param sendTo The players that will be sent this packet
|
||||
*/
|
||||
public static void sendCameraPacket(final int entityId, List<Player> sendTo) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CAMERA);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
HMCCosmeticsPlugin.getInstance().getLogger().info(sendTo + " | " + entityId + " has had a camera packet on them!");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param location Location of the fake player.
|
||||
* @param uuid UUID of the fake player. Should be random.
|
||||
* @param entityId The entityID that the entity will take on.
|
||||
* @param sendTo Who should it send the packet to?
|
||||
*/
|
||||
public static void sendFakePlayerSpawnPacket(
|
||||
final Location location,
|
||||
final UUID uuid,
|
||||
final int entityId,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
|
||||
wrapper.setEntityID(entityId);
|
||||
wrapper.setPlayerUUID(uuid);
|
||||
wrapper.setPosition(location.toVector());
|
||||
wrapper.setPitch(location.getPitch());
|
||||
wrapper.setYaw(location.getYaw());
|
||||
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fake player entity.
|
||||
* @param skinnedPlayer The original player it bases itself off of.
|
||||
* @param uuid UUID of the fake entity.
|
||||
* @param sendTo Whom to send the packet to
|
||||
*/
|
||||
public static void sendFakePlayerInfoPacket(
|
||||
final Player skinnedPlayer,
|
||||
final int entityId,
|
||||
final UUID uuid,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
|
||||
info.setAction(EnumWrappers.PlayerInfoAction.ADD_PLAYER);
|
||||
|
||||
String name = "Mannequin-" + entityId;
|
||||
while (name.length() > 16) {
|
||||
name = name.substring(16);
|
||||
}
|
||||
|
||||
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
|
||||
WrappedSignedProperty skinData = PlayerUtils.getSkin(skinnedPlayer);
|
||||
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
|
||||
info.setData(List.of(new PlayerInfoData(wrappedGameProfile, 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
|
||||
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the overlay packet for entities.
|
||||
* @param playerId The entity the packet is about
|
||||
* @param sendTo Whom is sent the packet.
|
||||
*/
|
||||
public static void sendPlayerOverlayPacket(
|
||||
final int playerId,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
/*
|
||||
0x01 = Is on fire
|
||||
0x02 = Is courching
|
||||
0x04 = Unusued
|
||||
0x08 = Sprinting
|
||||
0x10 = Is swimming
|
||||
0x20 = Invisibile
|
||||
0x40 = Is Glowing
|
||||
0x80 = Is flying with an elytra
|
||||
https://wiki.vg/Entity_metadata#Entity
|
||||
*/
|
||||
final byte mask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x40;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, playerId);
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(17, WrappedDataWatcher.Registry.get(Byte.class)), mask);
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
|
||||
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a fake player from being seen by players.
|
||||
* @param player Which gameprofile to wrap for removing the player.
|
||||
* @param uuid What is the fake player UUID
|
||||
* @param sendTo Whom to send the packet to
|
||||
*/
|
||||
public static void sendRemovePlayerPacket(
|
||||
final Player player,
|
||||
final UUID uuid,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
|
||||
info.setAction(EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
String name = "Mannequin-" + player.getEntityId();
|
||||
while (name.length() > 16) {
|
||||
name = name.substring(16);
|
||||
}
|
||||
|
||||
info.setData(List.of(new PlayerInfoData(new WrappedGameProfile(uuid, player.getName()), 0, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(name))));
|
||||
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.google.common.base.Objects;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
// Courtesy of Packet Wrapper
|
||||
public class AbstractPacket {
|
||||
|
||||
// The packet we will be modifying
|
||||
protected PacketContainer handle;
|
||||
|
||||
/**
|
||||
* Constructs a new strongly typed wrapper for the given packet.
|
||||
*
|
||||
* @param handle - handle to the raw packet data.
|
||||
* @param type - the packet type.
|
||||
*/
|
||||
protected AbstractPacket(PacketContainer handle, PacketType type) {
|
||||
// Make sure we're given a valid packet
|
||||
if (handle == null)
|
||||
throw new IllegalArgumentException("Packet handle cannot be NULL.");
|
||||
if (!Objects.equal(handle.getType(), type))
|
||||
throw new IllegalArgumentException(handle.getHandle()
|
||||
+ " is not a packet of type " + type);
|
||||
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a handle to the raw packet data.
|
||||
*
|
||||
* @return Raw packet data.
|
||||
*/
|
||||
public PacketContainer getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current packet to the given receiver.
|
||||
*
|
||||
* @param receiver - the receiver.
|
||||
* @throws RuntimeException If the packet cannot be sent.
|
||||
*/
|
||||
public void sendPacket(Player receiver) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
|
||||
getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the current packet to all online players.
|
||||
*/
|
||||
public void broadcastPacket() {
|
||||
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate receiving the current packet from the given sender.
|
||||
*
|
||||
* @param sender - the sender.
|
||||
* @throws RuntimeException If the packet cannot be received.
|
||||
* @deprecated Misspelled. recieve to receive
|
||||
* @see #receivePacket(Player)
|
||||
*/
|
||||
@Deprecated
|
||||
public void recievePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot recieve packet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate receiving the current packet from the given sender.
|
||||
*
|
||||
* @param sender - the sender.
|
||||
* @throws RuntimeException if the packet cannot be received.
|
||||
*/
|
||||
public void receivePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
|
||||
getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot receive packet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
|
||||
public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
|
||||
public static final PacketType TYPE =
|
||||
PacketType.Play.Server.NAMED_ENTITY_SPAWN;
|
||||
|
||||
public WrapperPlayServerNamedEntitySpawn() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Entity ID.
|
||||
* <p>
|
||||
* Notes: entity's ID
|
||||
*
|
||||
* @return The current Entity ID
|
||||
*/
|
||||
public int getEntityID() {
|
||||
return handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Entity ID.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setEntityID(int value) {
|
||||
handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the entity of the painting that will be spawned.
|
||||
*
|
||||
* @param world - the current world of the entity.
|
||||
* @return The spawned entity.
|
||||
*/
|
||||
public Entity getEntity(World world) {
|
||||
return handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the entity of the painting that will be spawned.
|
||||
*
|
||||
* @param event - the packet event.
|
||||
* @return The spawned entity.
|
||||
*/
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Player UUID.
|
||||
* <p>
|
||||
* Notes: player's UUID
|
||||
*
|
||||
* @return The current Player UUID
|
||||
*/
|
||||
public UUID getPlayerUUID() {
|
||||
return handle.getUUIDs().read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Player UUID.
|
||||
*
|
||||
* @param value - new value.
|
||||
*/
|
||||
public void setPlayerUUID(UUID value) {
|
||||
handle.getUUIDs().write(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the position of the spawned entity as a vector.
|
||||
*
|
||||
* @return The position as a vector.
|
||||
*/
|
||||
public Vector getPosition() {
|
||||
return new Vector(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of the spawned entity using a vector.
|
||||
*
|
||||
* @param position - the new position.
|
||||
*/
|
||||
public void setPosition(Vector position) {
|
||||
setX(position.getX());
|
||||
setY(position.getY());
|
||||
setZ(position.getZ());
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return handle.getDoubles().read(0);
|
||||
}
|
||||
|
||||
public void setX(double value) {
|
||||
handle.getDoubles().write(0, value);
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return handle.getDoubles().read(1);
|
||||
}
|
||||
|
||||
public void setY(double value) {
|
||||
handle.getDoubles().write(1, value);
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return handle.getDoubles().read(2);
|
||||
}
|
||||
|
||||
public void setZ(double value) {
|
||||
handle.getDoubles().write(2, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the yaw of the spawned entity.
|
||||
*
|
||||
* @return The current Yaw
|
||||
*/
|
||||
public float getYaw() {
|
||||
return (handle.getBytes().read(0) * 360.F) / 256.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the yaw of the spawned entity.
|
||||
*
|
||||
* @param value - new yaw.
|
||||
*/
|
||||
public void setYaw(float value) {
|
||||
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the pitch of the spawned entity.
|
||||
*
|
||||
* @return The current pitch
|
||||
*/
|
||||
public float getPitch() {
|
||||
return (handle.getBytes().read(1) * 360.F) / 256.0F;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the pitch of the spawned entity.
|
||||
*
|
||||
* @param value - new pitch.
|
||||
*/
|
||||
public void setPitch(float value) {
|
||||
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
|
||||
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
|
||||
|
||||
public WrapperPlayServerPlayerInfo() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerPlayerInfo(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public PlayerInfoAction getAction() {
|
||||
return handle.getPlayerInfoAction().read(0);
|
||||
}
|
||||
|
||||
public void setAction(PlayerInfoAction value) {
|
||||
handle.getPlayerInfoAction().write(0, value);
|
||||
}
|
||||
|
||||
public List<PlayerInfoData> getData() {
|
||||
return handle.getPlayerInfoDataLists().read(0);
|
||||
}
|
||||
|
||||
public void setData(List<PlayerInfoData> value) {
|
||||
handle.getPlayerInfoDataLists().write(0, value);
|
||||
}
|
||||
}
|
||||
49
src/main/resources/config.yml
Normal file
49
src/main/resources/config.yml
Normal file
@@ -0,0 +1,49 @@
|
||||
default-menu: main
|
||||
cosmetic-settings:
|
||||
require-empty-helmet: false
|
||||
require-empty-off-hand: false
|
||||
require-empty-chest-plate: false
|
||||
require-empty-pants: false
|
||||
require-empty-boots: false
|
||||
|
||||
# view distance in blocks that other players will see the backpack cosmetic
|
||||
# setting this to lower than the server player view distance should fix the
|
||||
# bug where players see random backpacks
|
||||
view-distance: 32
|
||||
# how the balloon should be positioned relative to the player
|
||||
balloon-offset:
|
||||
x: 0.5
|
||||
y: 3
|
||||
z: 0.5
|
||||
wardrobe:
|
||||
# spawn static wardrobe if in this radius of wardrobe-location
|
||||
static-radius: 10
|
||||
# how much yaw should change per tick, set to 0 for none
|
||||
rotation-speed: 3
|
||||
# if cosmetics that the user have permissions for should be applied on close of wardrobe
|
||||
apply-cosmetics-on-close: true
|
||||
# Applies a pumpkin for an overlay of the player while in the wardrobe.
|
||||
equip-pumpkin: false
|
||||
# Rather than having a set exit location, this will send the player back to where they entered the wardrobe.
|
||||
return-last-location: false
|
||||
wardrobe-location:
|
||||
world: "World"
|
||||
x: 0
|
||||
y: 0
|
||||
z: 0
|
||||
yaw: 0
|
||||
pitch: 0
|
||||
viewer-location:
|
||||
world: "World"
|
||||
x: 5
|
||||
y: 0
|
||||
z: 5
|
||||
yaw: 0
|
||||
pitch: 0
|
||||
leave-location:
|
||||
world: "World"
|
||||
x: 5
|
||||
y: 5
|
||||
z: 5
|
||||
yaw: 0
|
||||
pitch: 0
|
||||
27
src/main/resources/cosmetics/examplecosmetics.yml
Normal file
27
src/main/resources/cosmetics/examplecosmetics.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
niftyhat:
|
||||
slot: HELMET
|
||||
item:
|
||||
material: DIAMOND_HELMET
|
||||
name: "<rainbow>Colorful Hat</rainbow>"
|
||||
lore:
|
||||
- "<gray>My awesome <rainbow>Colorful Hat</rainbow>!"
|
||||
amount: 1
|
||||
model-data: 2
|
||||
enchantments:
|
||||
UNBREAKING: 1
|
||||
niftychestplate:
|
||||
slot: CHESTPLATE
|
||||
item:
|
||||
material: DIAMOND_CHESTPLATE
|
||||
name: "<rainbow>Colorful Chestplate</rainbow>"
|
||||
lore:
|
||||
- "<gray>My awesome <rainbow>Colorful Chestplate</rainbow>!"
|
||||
amount: 1
|
||||
model-data: 2
|
||||
enchantments:
|
||||
UNBREAKING: 1
|
||||
colorfulbackpack:
|
||||
slot: BACKPACK
|
||||
item:
|
||||
material: PAPER
|
||||
model-data: 4
|
||||
8
src/main/resources/menus/examplemenu.yml
Normal file
8
src/main/resources/menus/examplemenu.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
title: "<white>"
|
||||
rows: 5
|
||||
items:
|
||||
1:
|
||||
item:
|
||||
material: LEATHER_HORSE_ARMOR
|
||||
amount: 1
|
||||
action: "equip niftyhat"
|
||||
63
src/main/resources/messages.yml
Normal file
63
src/main/resources/messages.yml
Normal file
@@ -0,0 +1,63 @@
|
||||
prefix: "<white>"
|
||||
no-permission: "%prefix% <red>No Permission!"
|
||||
no-cosmetic-permission: "%prefix% <red>You do not have permission for this cosmetic!"
|
||||
set-hat: "%prefix% <gradient:#6D9DC5:#45CDE9>Applied hat!"
|
||||
removed-hat: "%prefix% <gradient:#6D9DC5:#45CDE9>Removed hat!"
|
||||
set-balloon: "%prefix% <gradient:#6D9DC5:#45CDE9>Applied Balloon!"
|
||||
removed-balloon: "%prefix% <gradient:#6D9DC5:#45CDE9>Removed Balloon!"
|
||||
set-backpack: "%prefix% <gradient:#6D9DC5:#45CDE9>Applied backpack!"
|
||||
removed-backpack: "%prefix% <gradient:#6D9DC5:#45CDE9>Removed backpack!"
|
||||
set-off-hand: "%prefix% <gradient:#6D9DC5:#45CDE9>Applied offhand!"
|
||||
removed-off-hand: "%prefix% <gradient:#6D9DC5:#45CDE9>Removed offhand!"
|
||||
set-chest-plate: "%prefix% <gradient:#6D9DC5:#45CDE9>Applied chest plate!"
|
||||
removed-chest-plate: "%prefix% <gradient:#6D9DC5:#45CDE9>Removed chest plate!"
|
||||
set-off-pants: "%prefix% <gradient:#6D9DC5:#45CDE9>Applied pants!"
|
||||
removed-pants: "%prefix% <gradient:#6D9DC5:#45CDE9>Removed pants!"
|
||||
set-boots: "%prefix% <gradient:#6D9DC5:#45CDE9>Applied boots!"
|
||||
removed-boots: "%prefix% <gradient:#6D9DC5:#45CDE9>Removed boots!"
|
||||
set-dye-color: "%prefix% <gradient:#6D9DC5:#45CDE9>Set color of %item%!"
|
||||
must-be-player: "<red>You must be a player to do this!"
|
||||
reloaded: "%prefix% <gradient:#00ff87:#60efff>Config files reloaded!"
|
||||
invalid-type: "%prefix% <red>Invalid cosmetic type, please use <u>hat</u>, <u>backpack</u> or <u>off_hand</u>!"
|
||||
set-other-backpack: "%prefix% <gradient:#6D9DC5:#45CDE9>You have set the backpack of %player% to %type%"
|
||||
set-other-hat: "%prefix% <gradient:#6D9DC5:#45CDE9>You have set the hat of %player% to %type%"
|
||||
set-other-off-hand: "%prefix% <gradient:#6D9DC5:#45CDE9>You have set the off hand of %player% to %type%"
|
||||
set-other-chest-plate: "%prefix% <gradient:#6D9DC5:#45CDE9>You have set the chest plate of %player% to %type%"
|
||||
set-other-pants: "%prefix% <gradient:#6D9DC5:#45CDE9>You have set the pants of %player% to %type%"
|
||||
set-other-boots: "%prefix% <gradient:#6D9DC5:#45CDE9>You have set the boots of %player% to %type%"
|
||||
hid-cosmetics: "%prefix% <gradient:#6D9DC5:#45CDE9>You have hidden your cosmetics"
|
||||
shown-cosmetics: "%prefix% <gradient:#6D9DC5:#45CDE9>You have shown your cosmetics"
|
||||
opened-wardrobe:
|
||||
type: title
|
||||
message: "<black>"
|
||||
fade-in: 1
|
||||
duration: 1
|
||||
fade-out: 1
|
||||
closed-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9>Closed wardrobe!"
|
||||
wardrobe-already-open: "%prefix% <gradient:#6D9DC5:#45CDE9><red>The wardrobe is already open!"
|
||||
not-near-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9><red>You are not near the wardrobe!"
|
||||
cannot-use-portable-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9><red>You cannot use the portable wardrobe!"
|
||||
opened-other-wardrobe: "%prefix% <gradient:#6D9DC5:#45CDE9><red>Opening %player%'s wardrobe."
|
||||
gave-token: "%prefix% <gradient:#6D9DC5:#45CDE9><green>You gave %player% a %id% token"
|
||||
received-token: "%prefix% <gradient:#6D9DC5:#45CDE9><green>You were given a %id% token"
|
||||
traded-token: "%prefix% <gradient:#6D9DC5:#45CDE9><green>You have received the cosmetic: %id%"
|
||||
already-unlocked: "%prefix% <gradient:#6D9DC5:#45CDE9><green>You have already unlocked the cosmetic: %id%"
|
||||
help-command: "<#6D9DC5><st> </st> %prefix% <gradient:#40B7D6:#6D9DC5>HMCCosmetics - Help</gradient> %prefix% <#6D9DC5> <st> </st>
|
||||
|
||||
|
||||
<#5AE4B5>- <#40B7D6>/cosmetics - <#6D9DC5>Opens cosmetics GUI.
|
||||
|
||||
<#5AE4B5>- <#40B7D6>/cosmetics add <gray><USERNAME> <ID> (#HEX)</gray> - <#6D9DC5>Adds cosmetic to player.
|
||||
|
||||
<#5AE4B5>- <#40B7D6>/cosmetics remove <gray><USERNAME> \\<BACKPACK/HAT></gray> - <#6D9DC5>Removes cosmetic from a player.
|
||||
|
||||
<#5AE4B5>- <#40B7D6>/cosmetics dye <gray>\\<BACKPACK/HAT></gray> - <#6D9DC5>Opens dye menu for the specified cosmetic type.
|
||||
|
||||
<#5AE4B5>- <#40B7D6>/cosmetics token <gray>\\<ID> <USERNAME></gray> - <#6D9DC5>Gives player a cosmetic token.
|
||||
|
||||
<#5AE4B5>- <#40B7D6>/cosmetics menu <gray>\\<MENU></gray> - <#6D9DC5>Opens the specified menu.
|
||||
|
||||
<#5AE4B5>- <#40B7D6>/cosmetics help - <#6D9DC5>Opens this menu.
|
||||
|
||||
|
||||
<st> </st>"
|
||||
3
src/main/resources/translations.yml
Normal file
3
src/main/resources/translations.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
translations:
|
||||
true: "true"
|
||||
false: "false"
|
||||
Reference in New Issue
Block a user