mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-22 19:11:23 +00:00
Compare commits
60 Commits
1.9.10
...
11d6a5bf91
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11d6a5bf91 | ||
|
|
df4fadb1f0 | ||
|
|
c5deb0f7fd | ||
|
|
27427c9ee6 | ||
|
|
7cd5e8f0d0 | ||
|
|
6a13c7fef7 | ||
|
|
a785e331b3 | ||
|
|
16462d8d81 | ||
|
|
d06cad1c5f | ||
|
|
7360e4ac2f | ||
|
|
4513804c40 | ||
|
|
1d56d77bdb | ||
|
|
906b13f91e | ||
|
|
c801ce18ec | ||
|
|
75692f0a05 | ||
|
|
018b7fee9b | ||
|
|
3a2b18907e | ||
|
|
6217015862 | ||
|
|
46db1af915 | ||
|
|
772acf4332 | ||
|
|
1cd38294cc | ||
|
|
9e01726b84 | ||
|
|
1176b57886 | ||
|
|
5c54182301 | ||
|
|
47846df0e4 | ||
|
|
b666323c4a | ||
|
|
b484b772cb | ||
|
|
d56eda6512 | ||
|
|
c7a784920d | ||
|
|
e029c1af3b | ||
|
|
a0282e67c1 | ||
|
|
bb33f4031a | ||
|
|
91331965f1 | ||
|
|
7e9a62a8f1 | ||
|
|
bf4e2af631 | ||
|
|
870b086a94 | ||
|
|
58042980eb | ||
|
|
1157a4312f | ||
|
|
5c4b212390 | ||
|
|
e321e9066c | ||
|
|
a0b64e0499 | ||
|
|
6204a3e22b | ||
|
|
9e9482067d | ||
|
|
58a74a0cdd | ||
|
|
9755ac2035 | ||
|
|
06232f1dc4 | ||
|
|
a21fbf7a95 | ||
|
|
96dd3ccd89 | ||
|
|
fb1901085c | ||
|
|
e537286785 | ||
|
|
6a994e4a82 | ||
|
|
8a4da8ad56 | ||
|
|
25e5a13095 | ||
|
|
72a5de5ee8 | ||
|
|
43b811db4e | ||
|
|
bd4ab50dc7 | ||
|
|
3087e3adcb | ||
|
|
588f413484 | ||
|
|
7beaa151c1 | ||
|
|
b5040a4636 |
0
.deepsource.toml
Normal file → Executable file
0
.deepsource.toml
Normal file → Executable file
0
.github/FUNDING.yml
vendored
Normal file → Executable file
0
.github/FUNDING.yml
vendored
Normal file → Executable file
2
.github/dependabot.yml
vendored
Normal file → Executable file
2
.github/dependabot.yml
vendored
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: maven
|
||||
- package-ecosystem: gradle
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
|
||||
24
.github/workflows/build.yml
vendored
Executable file
24
.github/workflows/build.yml
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
name: Build with Gradle
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 25
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 25
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v6
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
0
.github/workflows/hangar.yml
vendored
Normal file → Executable file
0
.github/workflows/hangar.yml
vendored
Normal file → Executable file
25
.github/workflows/maven.yml
vendored
25
.github/workflows/maven.yml
vendored
@@ -1,25 +0,0 @@
|
||||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Build with Maven
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 21
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
0
.github/workflows/modrinth.yml
vendored
Normal file → Executable file
0
.github/workflows/modrinth.yml
vendored
Normal file → Executable file
17
.gitignore
vendored
Normal file → Executable file
17
.gitignore
vendored
Normal file → Executable file
@@ -18,7 +18,6 @@ out/
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
@@ -95,19 +94,9 @@ $RECYCLE.BIN/
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
target/
|
||||
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.flattened-pom.xml
|
||||
# Gradle
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
8
README.md
Normal file → Executable file
8
README.md
Normal file → Executable file
@@ -17,15 +17,21 @@ Here is everything it tracks:
|
||||
* Crops mined (hoes).
|
||||
* Player/mob kills (swords, axes, tridents, bows/crossbows, mace).
|
||||
* Ownership of items when crafted, looted (from chests/vaults/barrels), traded, spawned via creative, and caught from fishing.
|
||||
* Armor damage taken.
|
||||
* Armor damage taken (shields too).
|
||||
* Damage done with weapons.
|
||||
* Fish caught.
|
||||
* Sheep sheared.
|
||||
* Arrows shot (bows/crossbows).
|
||||
* Flight time with elytras.
|
||||
* Critical strikes for melee weapons.
|
||||
* Times trident thrown.
|
||||
* Logs stripped.
|
||||
|
||||
The best part is, this data is stored on the item itself.
|
||||
|
||||
This plugin also has compatibility for:
|
||||
* [RoseStacker](https://modrinth.com/plugin/rosestacker)
|
||||
|
||||
If item lore is ever incorrect/missing, you can run `/toolstats reset`. This command fixes the lore on whatever item you are holding.
|
||||
|
||||

|
||||
|
||||
46
build.gradle.kts
Normal file
46
build.gradle.kts
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.rosewooddev.io/repository/public/")
|
||||
mavenCentral()
|
||||
maven("https://jitpack.io")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:26.1.1.build.+")
|
||||
compileOnly("dev.rosewood:rosestacker:1.5.39")
|
||||
compileOnly("com.github.hyperdefined:hyperlib:1.0.14:all")
|
||||
}
|
||||
|
||||
group = "lol.hyper"
|
||||
version = "2.0.3"
|
||||
description = "ToolStats"
|
||||
java.sourceCompatibility = JavaVersion.VERSION_25
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.withType<Javadoc> {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
val pluginVersion = version.toString()
|
||||
|
||||
tasks.processResources {
|
||||
filteringCharset = "UTF-8"
|
||||
|
||||
val props = mapOf("version" to pluginVersion)
|
||||
inputs.properties(props)
|
||||
|
||||
filesMatching("paper-plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
}
|
||||
5
gradle.properties
Normal file
5
gradle.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
# This file was generated by the Gradle 'init' task.
|
||||
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
|
||||
|
||||
org.gradle.configuration-cache=true
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
248
gradlew
vendored
Executable file
248
gradlew
vendored
Executable file
@@ -0,0 +1,248 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 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.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/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
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
# 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
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
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
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
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" )
|
||||
|
||||
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
|
||||
|
||||
|
||||
# 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"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# 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" "$@"
|
||||
93
gradlew.bat
vendored
Normal file
93
gradlew.bat
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
@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
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@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=.
|
||||
@rem This is normally unused
|
||||
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% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 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!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
118
pom.xml
118
pom.xml
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ This file is part of ToolStats.
|
||||
~
|
||||
~ ToolStats is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ ToolStats is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.9.10</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ToolStats</name>
|
||||
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>auto-clean</id>
|
||||
<phase>initialize</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>lol.hyper.hyperlib</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.hyperlib</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.10-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.hyperdefined</groupId>
|
||||
<artifactId>hyperlib</artifactId>
|
||||
<version>1.0.9</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
5
settings.gradle.kts
Normal file
5
settings.gradle.kts
Normal file
@@ -0,0 +1,5 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
|
||||
rootProject.name = "toolstats"
|
||||
@@ -23,107 +23,24 @@ import lol.hyper.hyperlib.releases.HyperUpdater;
|
||||
import lol.hyper.hyperlib.utils.TextUtils;
|
||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||
import lol.hyper.toolstats.events.*;
|
||||
import lol.hyper.toolstats.support.rosestacker.RoseStacker;
|
||||
import lol.hyper.toolstats.tools.*;
|
||||
import lol.hyper.toolstats.tools.config.ConfigTools;
|
||||
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public final class ToolStats extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* Stores who created an item.
|
||||
*/
|
||||
public final NamespacedKey itemOwner = new NamespacedKey(this, "owner");
|
||||
/**
|
||||
* Stores when the item was created.
|
||||
*/
|
||||
public final NamespacedKey timeCreated = new NamespacedKey(this, "time-created");
|
||||
/**
|
||||
* Stores how many player kills.
|
||||
*/
|
||||
public final NamespacedKey playerKills = new NamespacedKey(this, "player-kills");
|
||||
/**
|
||||
* Stores how many mob kills.
|
||||
*/
|
||||
public final NamespacedKey mobKills = new NamespacedKey(this, "mob-kills");
|
||||
/**
|
||||
* Stores how many blocks were mined.
|
||||
*/
|
||||
public final NamespacedKey blocksMined = new NamespacedKey(this, "generic-mined");
|
||||
/**
|
||||
* Stores how many crops were harvested.
|
||||
*/
|
||||
public final NamespacedKey cropsHarvested = new NamespacedKey(this, "crops-mined");
|
||||
/**
|
||||
* Stores how many fish were caught.
|
||||
*/
|
||||
public final NamespacedKey fishCaught = new NamespacedKey(this, "fish-caught");
|
||||
/**
|
||||
* Stores how many sheep were sheared.
|
||||
*/
|
||||
public final NamespacedKey sheepSheared = new NamespacedKey(this, "sheared");
|
||||
/**
|
||||
* Stores how much damage an armor piece has taken.
|
||||
*/
|
||||
public final NamespacedKey armorDamage = new NamespacedKey(this, "damage-taken");
|
||||
/**
|
||||
* Stores how much damage a weapon has done.
|
||||
*/
|
||||
public final NamespacedKey damageDone = new NamespacedKey(this, "damage-done");
|
||||
/**
|
||||
* Key for tracking new elytras that spawn.
|
||||
*/
|
||||
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
||||
/**
|
||||
* Key for item has.
|
||||
*/
|
||||
public final NamespacedKey hash = new NamespacedKey(this, "hash");
|
||||
/**
|
||||
* Key for arrows shot.
|
||||
*/
|
||||
public final NamespacedKey arrowsShot = new NamespacedKey(this, "arrows-shot");
|
||||
/**
|
||||
* Key for arrows shot.
|
||||
*/
|
||||
public final NamespacedKey droppedBy = new NamespacedKey(this, "dropped-by");
|
||||
/**
|
||||
* Key for tracking flight time.
|
||||
*/
|
||||
public final NamespacedKey flightTime = new NamespacedKey(this, "flightTime");
|
||||
/**
|
||||
* Key for token type. This is for the token itself.
|
||||
*/
|
||||
public final NamespacedKey tokenType = new NamespacedKey(this, "token-type");
|
||||
/**
|
||||
* Key for applied token. This is what goes onto the tool/armor to record the type.
|
||||
*/
|
||||
public final NamespacedKey tokenApplied = new NamespacedKey(this, "token-applied");
|
||||
/**
|
||||
* Stores how an item was created.
|
||||
* 0 = crafted.
|
||||
* 1 = dropped.
|
||||
* 2 = looted.
|
||||
* 3 = traded.
|
||||
* 4 = founded (for elytras).
|
||||
* 5 = fished.
|
||||
* 6 = spawned in (creative).
|
||||
*/
|
||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||
|
||||
public final int CONFIG_VERSION = 13;
|
||||
public final int CONFIG_VERSION = 17;
|
||||
public final ComponentLogger logger = this.getComponentLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
public boolean tokens = false;
|
||||
public final Set<NamespacedKey> tokenKeys = new HashSet<>();
|
||||
|
||||
public BlockBreak blockBreak;
|
||||
public ChunkPopulate chunkPopulate;
|
||||
@@ -154,6 +71,11 @@ public final class ToolStats extends JavaPlugin {
|
||||
public BlockDispenseEvent blockDispenseEvent;
|
||||
public HyperLib hyperLib;
|
||||
public TextUtils textUtils;
|
||||
public ProjectileShoot projectileShoot;
|
||||
public ToolStatsKeys toolStatsKeys;
|
||||
public InventoryClose inventoryClose;
|
||||
public PlayerDrop playerDrop;
|
||||
public RoseStacker roseStacker = null;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -172,6 +94,8 @@ public final class ToolStats extends JavaPlugin {
|
||||
|
||||
loadConfig();
|
||||
configTools = new ConfigTools(this);
|
||||
toolStatsKeys = new ToolStatsKeys(this);
|
||||
toolStatsKeys.make();
|
||||
tokenData = new TokenData(this);
|
||||
tokenData.setup();
|
||||
for (ShapedRecipe recipe : tokenData.getRecipes()) {
|
||||
@@ -203,17 +127,13 @@ public final class ToolStats extends JavaPlugin {
|
||||
anvilEvent = new AnvilEvent(this);
|
||||
prepareCraft = new PrepareCraft(this);
|
||||
blockDispenseEvent = new BlockDispenseEvent(this);
|
||||
|
||||
// save which stat can be used by a reset token
|
||||
tokenKeys.add(blocksMined);
|
||||
tokenKeys.add(playerKills);
|
||||
tokenKeys.add(mobKills);
|
||||
tokenKeys.add(cropsHarvested);
|
||||
tokenKeys.add(sheepSheared);
|
||||
tokenKeys.add(fishCaught);
|
||||
tokenKeys.add(flightTime);
|
||||
tokenKeys.add(arrowsShot);
|
||||
tokenKeys.add(armorDamage);
|
||||
projectileShoot = new ProjectileShoot(this);
|
||||
inventoryClose = new InventoryClose(this);
|
||||
playerDrop = new PlayerDrop(this);
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("RoseStacker")) {
|
||||
logger.info("RoseStacker has been detected, adding support!");
|
||||
roseStacker = new RoseStacker(this);
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blockBreak, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
||||
@@ -234,8 +154,11 @@ public final class ToolStats extends JavaPlugin {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(anvilEvent, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(prepareCraft, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blockDispenseEvent, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(projectileShoot, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(inventoryClose, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerDrop, this);
|
||||
|
||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||
registerCommand("toolstats", commandToolStats);
|
||||
|
||||
HyperUpdater updater = new HyperUpdater(hyperLib);
|
||||
updater.setGitHub("hyperdefined", "ToolStats");
|
||||
|
||||
37
src/main/java/lol/hyper/toolstats/ToolStatsLoader.java
Normal file
37
src/main/java/lol/hyper/toolstats/ToolStatsLoader.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats;
|
||||
|
||||
import io.papermc.paper.plugin.loader.PluginClasspathBuilder;
|
||||
import io.papermc.paper.plugin.loader.PluginLoader;
|
||||
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
|
||||
public class ToolStatsLoader implements PluginLoader {
|
||||
@Override
|
||||
public void classloader(PluginClasspathBuilder classpathBuilder) {
|
||||
MavenLibraryResolver resolver = new MavenLibraryResolver();
|
||||
|
||||
resolver.addRepository(new RemoteRepository.Builder("jitpack", "default", "https://jitpack.io").build());
|
||||
resolver.addDependency(new Dependency(new DefaultArtifact("com.github.hyperdefined:hyperlib:jar:all:1.0.14"), null));
|
||||
|
||||
classpathBuilder.addLibrary(resolver);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
171
src/main/java/lol/hyper/toolstats/events/AnvilEvent.java
Normal file → Executable file
171
src/main/java/lol/hyper/toolstats/events/AnvilEvent.java
Normal file → Executable file
@@ -39,7 +39,7 @@ public class AnvilEvent implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onAnvilEvent(PrepareAnvilEvent event) {
|
||||
// only listen if the token system is enabled
|
||||
if (!toolStats.config.getBoolean("tokens.enabled")) {
|
||||
@@ -65,12 +65,12 @@ public class AnvilEvent implements Listener {
|
||||
PersistentDataContainer secondSlotContainer = secondSlot.getItemMeta().getPersistentDataContainer();
|
||||
|
||||
// make sure the 2nd item is one of ours
|
||||
if (!secondSlotContainer.has(toolStats.tokenType, PersistentDataType.STRING)) {
|
||||
if (!secondSlotContainer.has(toolStats.toolStatsKeys.getTokenType(), PersistentDataType.STRING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the type from the token
|
||||
String tokenType = secondSlotContainer.get(toolStats.tokenType, PersistentDataType.STRING);
|
||||
String tokenType = secondSlotContainer.get(toolStats.toolStatsKeys.getTokenType(), PersistentDataType.STRING);
|
||||
if (tokenType == null) {
|
||||
return;
|
||||
}
|
||||
@@ -127,6 +127,22 @@ public class AnvilEvent implements Listener {
|
||||
addToken(event, tokenType, "damage-done", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("wither-kills")) {
|
||||
addToken(event, tokenType, "wither-kills", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("enderdragon-kills")) {
|
||||
addToken(event, tokenType, "enderdragon-kills", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("critical-strikes")) {
|
||||
addToken(event, tokenType, "critical-strikes", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("logs-stripped")) {
|
||||
addToken(event, tokenType, "logs-stripped", clone);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -151,6 +167,22 @@ public class AnvilEvent implements Listener {
|
||||
addToken(event, tokenType, "damage-done", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("wither-kills")) {
|
||||
addToken(event, tokenType, "wither-kills", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("enderdragon-kills")) {
|
||||
addToken(event, tokenType, "enderdragon-kills", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("critical-strikes")) {
|
||||
addToken(event, tokenType, "critical-strikes", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("trident-throws")) {
|
||||
addToken(event, tokenType, "trident-throws", clone);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (firstSlotMaterial == Material.BOW || firstSlotMaterial == Material.CROSSBOW) {
|
||||
@@ -170,6 +202,14 @@ public class AnvilEvent implements Listener {
|
||||
addToken(event, tokenType, "damage-done", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("wither-kills")) {
|
||||
addToken(event, tokenType, "wither-kills", clone);
|
||||
return;
|
||||
}
|
||||
if (tokenType.equalsIgnoreCase("enderdragon-kills")) {
|
||||
addToken(event, tokenType, "enderdragon-kills", clone);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (firstSlotMaterial == Material.FISHING_ROD) {
|
||||
@@ -291,6 +331,51 @@ public class AnvilEvent implements Listener {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "wither-kills": {
|
||||
if (toolStats.config.getBoolean("enabled.bosses-killed.wither")) {
|
||||
newItem.setItemMeta(toolStats.itemLore.updateBossesKilled(newItem, 0, "wither"));
|
||||
} else {
|
||||
event.setResult(null);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "enderdragon-kills": {
|
||||
if (toolStats.config.getBoolean("enabled.bosses-killed.enderdragon")) {
|
||||
newItem.setItemMeta(toolStats.itemLore.updateBossesKilled(newItem, 0, "enderdragon"));
|
||||
} else {
|
||||
event.setResult(null);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "critical-strikes": {
|
||||
if (toolStats.config.getBoolean("enabled.critical-strikes")) {
|
||||
newItem.setItemMeta(toolStats.itemLore.updateCriticalStrikes(newItem, 0));
|
||||
} else {
|
||||
event.setResult(null);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "trident-throws": {
|
||||
if (toolStats.config.getBoolean("enabled.trident-throws")) {
|
||||
newItem.setItemMeta(toolStats.itemLore.updateTridentThrows(newItem, 0));
|
||||
} else {
|
||||
event.setResult(null);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "logs-stripped": {
|
||||
if (toolStats.config.getBoolean("enabled.logs-stripped")) {
|
||||
newItem.setItemMeta(toolStats.itemLore.updateLogsStripped(newItem, 0));
|
||||
} else {
|
||||
event.setResult(null);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
event.setResult(newItem);
|
||||
event.getView().setRepairCost(toolStats.itemChecker.getCost(targetToken));
|
||||
@@ -312,86 +397,126 @@ public class AnvilEvent implements Listener {
|
||||
ItemMeta meta = finalItem.getItemMeta();
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.toolStatsKeys.getPlayerKills())) {
|
||||
Integer playerKills = container.get(toolStats.toolStatsKeys.getPlayerKills(), PersistentDataType.INTEGER);
|
||||
if (playerKills == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updatePlayerKills(finalItem, -playerKills);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.toolStatsKeys.getMobKills())) {
|
||||
Integer mobKills = container.get(toolStats.toolStatsKeys.getMobKills(), PersistentDataType.INTEGER);
|
||||
if (mobKills == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateMobKills(finalItem, -mobKills);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.toolStatsKeys.getBlocksMined())) {
|
||||
Integer blocksMined = container.get(toolStats.toolStatsKeys.getBlocksMined(), PersistentDataType.INTEGER);
|
||||
if (blocksMined == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateBlocksMined(finalItem, -blocksMined);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.toolStatsKeys.getCropsHarvested())) {
|
||||
Integer cropsHarvested = container.get(toolStats.toolStatsKeys.getCropsHarvested(), PersistentDataType.INTEGER);
|
||||
if (cropsHarvested == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateCropsMined(finalItem, -cropsHarvested);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.toolStatsKeys.getFishCaught())) {
|
||||
Integer fishCaught = container.get(toolStats.toolStatsKeys.getFishCaught(), PersistentDataType.INTEGER);
|
||||
if (fishCaught == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateFishCaught(finalItem, -fishCaught);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.toolStatsKeys.getSheepSheared())) {
|
||||
Integer sheepSheared = container.get(toolStats.toolStatsKeys.getSheepSheared(), PersistentDataType.INTEGER);
|
||||
if (sheepSheared == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateSheepSheared(finalItem, -sheepSheared);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (container.has(toolStats.toolStatsKeys.getArmorDamage())) {
|
||||
Double armorDamage = container.get(toolStats.toolStatsKeys.getArmorDamage(), PersistentDataType.DOUBLE);
|
||||
if (armorDamage == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateArmorDamage(finalItem, -armorDamage, true);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
Double damageDone = container.get(toolStats.damageDone, PersistentDataType.DOUBLE);
|
||||
if (container.has(toolStats.toolStatsKeys.getDamageDone())) {
|
||||
Double damageDone = container.get(toolStats.toolStatsKeys.getDamageDone(), PersistentDataType.DOUBLE);
|
||||
if (damageDone == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateArmorDamage(finalItem, -damageDone, true);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.arrowsShot)) {
|
||||
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.toolStatsKeys.getArrowsShot())) {
|
||||
Integer arrowsShot = container.get(toolStats.toolStatsKeys.getArrowsShot(), PersistentDataType.INTEGER);
|
||||
if (arrowsShot == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateArrowsShot(finalItem, -arrowsShot);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
if (container.has(toolStats.toolStatsKeys.getFlightTime())) {
|
||||
Long flightTime = container.get(toolStats.toolStatsKeys.getFlightTime(), PersistentDataType.LONG);
|
||||
if (flightTime == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateFlightTime(finalItem, -flightTime);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getWitherKills())) {
|
||||
Integer witherKills = container.get(toolStats.toolStatsKeys.getWitherKills(), PersistentDataType.INTEGER);
|
||||
if (witherKills == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateBossesKilled(finalItem, -witherKills, "wither");
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getEnderDragonKills())) {
|
||||
Integer enderDragonKills = container.get(toolStats.toolStatsKeys.getEnderDragonKills(), PersistentDataType.INTEGER);
|
||||
if (enderDragonKills == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateBossesKilled(finalItem, -enderDragonKills, "enderdragon");
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getCriticalStrikes())) {
|
||||
Integer criticalStrikes = container.get(toolStats.toolStatsKeys.getCriticalStrikes(), PersistentDataType.INTEGER);
|
||||
if (criticalStrikes == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateCriticalStrikes(finalItem, -criticalStrikes);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getTridentThrows())) {
|
||||
Integer tridentThrows = container.get(toolStats.toolStatsKeys.getTridentThrows(), PersistentDataType.INTEGER);
|
||||
if (tridentThrows == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateTridentThrows(finalItem, -tridentThrows);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getLogsStripped())) {
|
||||
Integer logsStripped = container.get(toolStats.toolStatsKeys.getLogsStripped(), PersistentDataType.INTEGER);
|
||||
if (logsStripped == null) {
|
||||
return;
|
||||
}
|
||||
meta = toolStats.itemLore.updateLogsStripped(finalItem, -logsStripped);
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
event.setResult(finalItem);
|
||||
event.getView().setRepairCost(toolStats.itemChecker.getCost("reset"));
|
||||
}
|
||||
|
||||
58
src/main/java/lol/hyper/toolstats/events/BlockBreak.java
Normal file → Executable file
58
src/main/java/lol/hyper/toolstats/events/BlockBreak.java
Normal file → Executable file
@@ -18,36 +18,39 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BlockBreak implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
public final List<Block> brokenContainers = new ArrayList<>();
|
||||
|
||||
public BlockBreak(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
@@ -55,9 +58,9 @@ public class BlockBreak implements Listener {
|
||||
ItemStack heldItem = inventory.getItemInMainHand();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (block.getType() == Material.CHEST) {
|
||||
toolStats.playerInteract.openedChests.put(block, player);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> toolStats.playerInteract.openedChests.remove(block), 20);
|
||||
if (block.getType() == Material.CHEST || block.getType() == Material.BARREL) {
|
||||
brokenContainers.add(block);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> brokenContainers.remove(block), 20);
|
||||
}
|
||||
|
||||
// only check certain items
|
||||
@@ -96,4 +99,41 @@ public class BlockBreak implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onBreak(BlockDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location eventLocation = event.getBlock().getLocation();
|
||||
Chunk eventChunk = eventLocation.getChunk();
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, eventLocation.getWorld(), eventChunk.getX(), eventChunk.getZ(), scheduledTask -> {
|
||||
boolean validLootDrops = false;
|
||||
for (Location droppedLootLocation : toolStats.generateLoot.droppedLootLocations) {
|
||||
if (eventLocation.getWorld() == droppedLootLocation.getWorld()) {
|
||||
double distance = droppedLootLocation.distance(eventLocation);
|
||||
if (distance <= 1.0) {
|
||||
validLootDrops = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (validLootDrops) {
|
||||
toolStats.generateLoot.droppedLootLocations.remove(eventLocation);
|
||||
for (Item droppedItemEntity : event.getItems()) {
|
||||
ItemStack droppedItem = droppedItemEntity.getItemStack();
|
||||
if (!toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack newItem = toolStats.inventoryClose.addLootedOrigin(droppedItem, player);
|
||||
if (newItem != null) {
|
||||
droppedItemEntity.setItemStack(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
41
src/main/java/lol/hyper/toolstats/events/BlockDispenseEvent.java
Normal file → Executable file
41
src/main/java/lol/hyper/toolstats/events/BlockDispenseEvent.java
Normal file → Executable file
@@ -45,14 +45,16 @@ public class BlockDispenseEvent implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onDispense(BlockDispenseLootEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
@@ -99,7 +101,7 @@ public class BlockDispenseEvent implements Listener {
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG) || container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -111,11 +113,34 @@ public class BlockDispenseEvent implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
// by request
|
||||
if (newItem.getType() == Material.ELYTRA) {
|
||||
if (!toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 4, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 4);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 4, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 4);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
}
|
||||
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 2, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 2);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -123,8 +148,8 @@ public class BlockDispenseEvent implements Listener {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 2, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 2);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -132,7 +157,7 @@ public class BlockDispenseEvent implements Listener {
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
newItem.setItemMeta(meta);
|
||||
|
||||
9
src/main/java/lol/hyper/toolstats/events/ChunkPopulate.java
Normal file → Executable file
9
src/main/java/lol/hyper/toolstats/events/ChunkPopulate.java
Normal file → Executable file
@@ -44,16 +44,19 @@ public class ChunkPopulate implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPopulate(ChunkPopulateEvent event) {
|
||||
if (event.getChunk().getWorld().getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
World world = event.getChunk().getWorld();
|
||||
if (!toolStats.configTools.checkWorld(world.getName())) {
|
||||
return;
|
||||
}
|
||||
// this is delayed because entities are not loaded instantly
|
||||
// we just check 1 second later
|
||||
Chunk chunk = event.getChunk();
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, world, chunk.getX(), chunk.getZ(), scheduledTask -> {
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, world, chunk.getX(), chunk.getZ(), _ -> {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
// if there is a new item frame
|
||||
if (!(entity instanceof ItemFrame itemFrame)) {
|
||||
@@ -68,7 +71,7 @@ public class ChunkPopulate implements Listener {
|
||||
}
|
||||
// add the new tag so we know it's new
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
||||
container.set(toolStats.toolStatsKeys.getElytraKey(), PersistentDataType.INTEGER, 1);
|
||||
elytraCopy.setItemMeta(meta);
|
||||
itemFrame.setItem(elytraCopy);
|
||||
}
|
||||
|
||||
18
src/main/java/lol/hyper/toolstats/events/CraftItem.java
Normal file → Executable file
18
src/main/java/lol/hyper/toolstats/events/CraftItem.java
Normal file → Executable file
@@ -44,12 +44,12 @@ public class CraftItem implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onCraft(CraftItemEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class CraftItem implements Listener {
|
||||
|
||||
// if the item already has the tag
|
||||
// this is to prevent duplicate tags
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG) || container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -145,8 +145,8 @@ public class CraftItem implements Listener {
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 0, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 0);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -154,8 +154,8 @@ public class CraftItem implements Listener {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 0, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 0);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class CraftItem implements Listener {
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
}
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
|
||||
20
src/main/java/lol/hyper/toolstats/events/CreativeEvent.java
Normal file → Executable file
20
src/main/java/lol/hyper/toolstats/events/CreativeEvent.java
Normal file → Executable file
@@ -23,6 +23,7 @@ import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -42,9 +43,12 @@ public class CreativeEvent implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onCreativeEvent(InventoryCreativeEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
// make sure they are in creative mode
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
return;
|
||||
@@ -61,7 +65,7 @@ public class CreativeEvent implements Listener {
|
||||
// if the item already has an origin set, don't add it again
|
||||
// this is needed since you can spam click an item and the event will fire again
|
||||
PersistentDataContainer container = spawnedItemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +101,7 @@ public class CreativeEvent implements Listener {
|
||||
|
||||
// if the item already has the tag
|
||||
// this is to prevent duplicate tags
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG) || container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -112,8 +116,8 @@ public class CreativeEvent implements Listener {
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 6, newSpawnedItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 6);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -121,8 +125,8 @@ public class CreativeEvent implements Listener {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 6, newSpawnedItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 6);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -130,7 +134,7 @@ public class CreativeEvent implements Listener {
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newSpawnedItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
newSpawnedItem.setItemMeta(meta);
|
||||
|
||||
237
src/main/java/lol/hyper/toolstats/events/EntityDamage.java
Normal file → Executable file
237
src/main/java/lol/hyper/toolstats/events/EntityDamage.java
Normal file → Executable file
@@ -29,6 +29,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
@@ -45,13 +46,13 @@ public class EntityDamage implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDamage(EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
if (!toolStats.configTools.checkWorld(mobBeingAttacked.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,10 +67,27 @@ public class EntityDamage implements Listener {
|
||||
boolean playerBeingAttacked = mobBeingAttacked instanceof Player;
|
||||
double finalDamage = event.getFinalDamage();
|
||||
boolean modDied = mobBeingAttacked.getHealth() - finalDamage <= 0;
|
||||
EntityType mobAttackedType = event.getEntityType();
|
||||
boolean critical = event.isCritical();
|
||||
|
||||
if (playerBeingAttacked) {
|
||||
Player player = (Player) event.getEntity();
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
if (player.isBlocking()) {
|
||||
double blockedDamage = -event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING);
|
||||
updateShieldDamage(player.getInventory(), blockedDamage);
|
||||
}
|
||||
}
|
||||
|
||||
// player attacks something
|
||||
if (playerAttacking) {
|
||||
PlayerInventory playerAttackingInventory = ((Player) damager).getInventory();
|
||||
Player player = (Player) damager;
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory playerAttackingInventory = player.getInventory();
|
||||
// make sure the item the player used is an item we want
|
||||
if (!toolStats.itemChecker.isMeleeWeapon(playerAttackingInventory.getItemInMainHand().getType())) {
|
||||
return;
|
||||
@@ -78,14 +96,25 @@ public class EntityDamage implements Listener {
|
||||
// update their weapon's damage
|
||||
updateWeaponDamage(playerAttackingInventory, event.getFinalDamage());
|
||||
|
||||
// if the player crit
|
||||
if (critical) {
|
||||
updateCriticalStrikes(playerAttackingInventory);
|
||||
}
|
||||
|
||||
// the mob the player attacked died
|
||||
if (modDied) {
|
||||
// player killed another player
|
||||
if (playerBeingAttacked) {
|
||||
updateWeaponKills(playerAttackingInventory, "player");
|
||||
updateWeaponKills(playerAttackingInventory, "player", null);
|
||||
} else {
|
||||
// player kills a regular mob
|
||||
updateWeaponKills(playerAttackingInventory, "mob");
|
||||
updateWeaponKills(playerAttackingInventory, "mob", mobBeingAttacked);
|
||||
if (mobAttackedType == EntityType.WITHER) {
|
||||
updateBossesKilled(playerAttackingInventory, "wither", mobBeingAttacked);
|
||||
}
|
||||
if (mobAttackedType == EntityType.ENDER_DRAGON) {
|
||||
updateBossesKilled(playerAttackingInventory, "enderdragon", mobBeingAttacked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +125,10 @@ public class EntityDamage implements Listener {
|
||||
// something was hit by a trident
|
||||
if (damager instanceof Trident trident) {
|
||||
ProjectileSource source = trident.getShooter();
|
||||
if (source instanceof Player) {
|
||||
if (source instanceof Player player) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
// update the trident's tracked damage
|
||||
updateTridentDamage(trident, finalDamage);
|
||||
|
||||
@@ -104,10 +136,16 @@ public class EntityDamage implements Listener {
|
||||
if (modDied) {
|
||||
// if the trident killed a player, update the kills
|
||||
if (playerBeingAttacked) {
|
||||
updateTridentKills(trident, "player");
|
||||
updateTridentKills(trident, "player", null);
|
||||
} else {
|
||||
// the trident killed a mob, update the kills
|
||||
updateTridentKills(trident, "mob");
|
||||
updateTridentKills(trident, "mob", mobBeingAttacked);
|
||||
if (mobAttackedType == EntityType.WITHER) {
|
||||
updateBossesKilled(player.getInventory(), "wither", mobBeingAttacked);
|
||||
}
|
||||
if (mobAttackedType == EntityType.ENDER_DRAGON) {
|
||||
updateBossesKilled(player.getInventory(), "enderdragon", mobBeingAttacked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +160,9 @@ public class EntityDamage implements Listener {
|
||||
|
||||
// a player shot the arrow
|
||||
if (source instanceof Player shootingPlayer) {
|
||||
if (shootingPlayer.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
// update the player's bow damage
|
||||
updateBowDamage(shootingPlayer.getInventory(), finalDamage);
|
||||
|
||||
@@ -129,10 +170,16 @@ public class EntityDamage implements Listener {
|
||||
if (modDied) {
|
||||
if (playerBeingAttacked) {
|
||||
// player killed another player with an arrow
|
||||
updateBowKills(shootingPlayer.getInventory(), "player");
|
||||
updateBowKills(shootingPlayer.getInventory(), "player", null);
|
||||
} else {
|
||||
// player killed mob with an arrow
|
||||
updateBowKills(shootingPlayer.getInventory(), "mob");
|
||||
updateBowKills(shootingPlayer.getInventory(), "mob", mobBeingAttacked);
|
||||
if (mobAttackedType == EntityType.WITHER) {
|
||||
updateBossesKilledByBow(shootingPlayer.getInventory(), "wither", mobBeingAttacked);
|
||||
}
|
||||
if (mobAttackedType == EntityType.ENDER_DRAGON) {
|
||||
updateBossesKilledByBow(shootingPlayer.getInventory(), "enderdragon", mobBeingAttacked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +235,6 @@ public class EntityDamage implements Listener {
|
||||
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||
ItemMeta newBowDamage = toolStats.itemLore.updateWeaponDamage(heldBow, damage, false);
|
||||
//toolStats.logger.info(newBowDamage.toString());
|
||||
|
||||
// player is shooting another player
|
||||
if (newBowDamage != null) {
|
||||
@@ -202,7 +248,7 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBowKills(PlayerInventory playerInventory, String type) {
|
||||
private void updateBowKills(PlayerInventory playerInventory, String type, LivingEntity entity) {
|
||||
ItemStack heldBow = toolStats.itemChecker.getBow(playerInventory);
|
||||
if (heldBow == null) {
|
||||
return;
|
||||
@@ -213,6 +259,21 @@ public class EntityDamage implements Listener {
|
||||
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
// player is shooting a mob
|
||||
if (toolStats.roseStacker != null) {
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemMeta newBow = toolStats.itemLore.updateMobKills(heldBow, count);
|
||||
if (newBow != null) {
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||
} else if (isMain) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newBow);
|
||||
} else if (isOffHand) {
|
||||
playerInventory.getItemInOffHand().setItemMeta(newBow);
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
ItemMeta newBow = toolStats.itemLore.updateMobKills(heldBow, 1);
|
||||
if (newBow != null) {
|
||||
if (isMain && isOffHand) {
|
||||
@@ -239,18 +300,33 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTridentKills(Trident trident, String type) {
|
||||
private void updateTridentKills(Trident trident, String type, LivingEntity entity) {
|
||||
ItemStack newTrident = trident.getItemStack();
|
||||
ItemMeta newKills;
|
||||
if (type.equalsIgnoreCase("player")) {
|
||||
newKills = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||
} else {
|
||||
newKills = toolStats.itemLore.updateMobKills(trident.getItemStack(), 1);
|
||||
}
|
||||
if (newKills != null) {
|
||||
newTrident.setItemMeta(newKills);
|
||||
ItemMeta newTridentMeta = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
|
||||
if (newTridentMeta != null) {
|
||||
newTrident.setItemMeta(newTridentMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
if (toolStats.roseStacker != null) {
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemMeta newTridentMeta = toolStats.itemLore.updateMobKills(newTrident, count);
|
||||
if (newTridentMeta != null) {
|
||||
newTrident.setItemMeta(newTridentMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
ItemMeta newTridentMeta = toolStats.itemLore.updateMobKills(trident.getItemStack(), 1);
|
||||
if (newTridentMeta != null) {
|
||||
newTrident.setItemMeta(newTridentMeta);
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTridentDamage(Trident trident, double damage) {
|
||||
@@ -270,17 +346,128 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWeaponKills(PlayerInventory playerInventory, String type) {
|
||||
private void updateWeaponKills(PlayerInventory playerInventory, String type, LivingEntity entity) {
|
||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||
ItemMeta newHeldWeaponMeta = null;
|
||||
if (type.equalsIgnoreCase("player")) {
|
||||
newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updatePlayerKills(heldWeapon, 1);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (type.equalsIgnoreCase("mob")) {
|
||||
newHeldWeaponMeta = toolStats.itemLore.updateMobKills(heldWeapon, 1);
|
||||
if (toolStats.roseStacker != null) {
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemStack currentHeldWeapon = playerInventory.getItemInMainHand();
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateMobKills(currentHeldWeapon, count);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
currentHeldWeapon.setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateMobKills(heldWeapon, 1);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBossesKilled(PlayerInventory playerInventory, String boss, LivingEntity entity) {
|
||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||
int count = 1;
|
||||
if (toolStats.roseStacker != null) {
|
||||
//count = toolStats.roseStacker.countMobs(entity);
|
||||
}
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldWeapon, count, boss);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBossesKilledByBow(PlayerInventory playerInventory, String boss, LivingEntity entity) {
|
||||
ItemStack heldBow = toolStats.itemChecker.getBow(playerInventory);
|
||||
if (heldBow == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.BOW || playerInventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.BOW || playerInventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||
|
||||
if (toolStats.roseStacker != null) {
|
||||
toolStats.roseStacker.countMobs(entity, count -> {
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldBow, count, boss);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
} else if (isMain) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
} else if (isOffHand) {
|
||||
playerInventory.getItemInOffHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateBossesKilled(heldBow, 1, boss);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
} else if (isMain) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
} else if (isOffHand) {
|
||||
playerInventory.getItemInOffHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCriticalStrikes(PlayerInventory playerInventory) {
|
||||
ItemStack heldWeapon = playerInventory.getItemInMainHand();
|
||||
ItemMeta newHeldWeaponMeta = toolStats.itemLore.updateCriticalStrikes(heldWeapon, 1);
|
||||
if (newHeldWeaponMeta != null) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newHeldWeaponMeta);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateShieldDamage(PlayerInventory playerInventory, double damage) {
|
||||
boolean isMain = playerInventory.getItemInMainHand().getType() == Material.SHIELD;
|
||||
boolean isOffHand = playerInventory.getItemInOffHand().getType() == Material.SHIELD;
|
||||
|
||||
ItemStack heldShield;
|
||||
if (isMain && isOffHand) {
|
||||
heldShield = playerInventory.getItemInMainHand();
|
||||
int shieldDamage = (heldShield.getItemMeta() instanceof Damageable d) ? d.getDamage() : 0;
|
||||
|
||||
ItemMeta newShieldMeta = toolStats.itemLore.updateArmorDamage(heldShield, damage, false);
|
||||
if (newShieldMeta != null) {
|
||||
if (newShieldMeta instanceof Damageable dNew) {
|
||||
dNew.setDamage(shieldDamage);
|
||||
}
|
||||
playerInventory.getItemInMainHand().setItemMeta(newShieldMeta);
|
||||
}
|
||||
} else if (isMain) {
|
||||
heldShield = playerInventory.getItemInMainHand();
|
||||
int shieldDamage = (heldShield.getItemMeta() instanceof Damageable d) ? d.getDamage() : 0;
|
||||
|
||||
ItemMeta newShieldMeta = toolStats.itemLore.updateArmorDamage(heldShield, damage, false);
|
||||
if (newShieldMeta != null) {
|
||||
if (newShieldMeta instanceof Damageable dNew) {
|
||||
dNew.setDamage(shieldDamage);
|
||||
}
|
||||
playerInventory.getItemInMainHand().setItemMeta(newShieldMeta);
|
||||
}
|
||||
} else if (isOffHand) {
|
||||
heldShield = playerInventory.getItemInOffHand();
|
||||
int shieldDamage = (heldShield.getItemMeta() instanceof Damageable d) ? d.getDamage() : 0;
|
||||
|
||||
ItemMeta newShieldMeta = toolStats.itemLore.updateArmorDamage(heldShield, damage, false);
|
||||
if (newShieldMeta != null) {
|
||||
if (newShieldMeta instanceof Damageable dNew) {
|
||||
dNew.setDamage(shieldDamage);
|
||||
}
|
||||
playerInventory.getItemInOffHand().setItemMeta(newShieldMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
src/main/java/lol/hyper/toolstats/events/EntityDeath.java
Normal file → Executable file
15
src/main/java/lol/hyper/toolstats/events/EntityDeath.java
Normal file → Executable file
@@ -43,12 +43,15 @@ public class EntityDeath implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
LivingEntity livingEntity = event.getEntity();
|
||||
if (livingEntity instanceof Player) {
|
||||
return;
|
||||
}
|
||||
if (!toolStats.configTools.checkWorld(livingEntity.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
UUID livingEntityUUID = event.getEntity().getUniqueId();
|
||||
// if it's a mob we are tracking that matters
|
||||
if (toolStats.mobKill.trackedMobs.contains(livingEntityUUID)) {
|
||||
@@ -57,7 +60,7 @@ public class EntityDeath implements Listener {
|
||||
ItemMeta droppedItemMeta = droppedItem.getItemMeta();
|
||||
if (droppedItemMeta != null) {
|
||||
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER)) {
|
||||
continue; // ignore any items that have our tags
|
||||
}
|
||||
|
||||
@@ -109,15 +112,15 @@ public class EntityDeath implements Listener {
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 1, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 1);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
container.set(toolStats.droppedBy, PersistentDataType.STRING, mobName);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 1);
|
||||
container.set(toolStats.toolStatsKeys.getDroppedBy(), PersistentDataType.STRING, mobName);
|
||||
Component droppedBy = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||
lore.add(droppedBy);
|
||||
}
|
||||
|
||||
142
src/main/java/lol/hyper/toolstats/events/GenerateLoot.java
Normal file → Executable file
142
src/main/java/lol/hyper/toolstats/events/GenerateLoot.java
Normal file → Executable file
@@ -17,52 +17,55 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.entity.minecart.StorageMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.LootGenerateEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GenerateLoot implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
public final Map<Inventory, Location> generatedInventory = new HashMap<>();
|
||||
public final List<Location> droppedLootLocations = new ArrayList<>();
|
||||
|
||||
public GenerateLoot(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onGenerateLoot(LootGenerateEvent event) {
|
||||
InventoryHolder inventoryHolder = event.getInventoryHolder();
|
||||
if (inventoryHolder == null) {
|
||||
return;
|
||||
}
|
||||
Location lootLocation = event.getLootContext().getLocation();
|
||||
|
||||
if (inventoryHolder instanceof Chest) {
|
||||
if (!toolStats.configTools.checkWorld(lootLocation.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Chunk lootChunk = lootLocation.getChunk();
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, lootLocation.getWorld(), lootChunk.getX(), lootChunk.getZ(), scheduledTask -> {
|
||||
if (inventoryHolder instanceof Container) {
|
||||
Block openedChest = null;
|
||||
Location chestLocation = null;
|
||||
// look at the current list of opened chest and get the distance
|
||||
// between the LootContext location and chest location
|
||||
// if the distance is less than 1, it's the same chest
|
||||
for (Block chest : toolStats.playerInteract.openedChests.keySet()) {
|
||||
Location chestLocation = chest.getLocation();
|
||||
for (Block chest : toolStats.playerInteract.openedChests) {
|
||||
chestLocation = chest.getLocation();
|
||||
if (chest.getWorld() == lootLocation.getWorld()) {
|
||||
double distance = lootLocation.distance(chestLocation);
|
||||
if (distance <= 1.0) {
|
||||
@@ -70,102 +73,27 @@ public class GenerateLoot implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
// ignore if the chest is not in the same location
|
||||
if (openedChest == null) {
|
||||
return;
|
||||
for (Block brokenChest : toolStats.blockBreak.brokenContainers) {
|
||||
Location brokenChestLocation = brokenChest.getLocation();
|
||||
if (brokenChestLocation.getWorld() == lootLocation.getWorld()) {
|
||||
double distance = lootLocation.distance(brokenChestLocation);
|
||||
if (distance <= 1.0) {
|
||||
droppedLootLocations.add(brokenChestLocation);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask2 -> droppedLootLocations.remove(brokenChestLocation), 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ignore if the chest is not in the same location
|
||||
if (openedChest != null) {
|
||||
generatedInventory.put(inventoryHolder.getInventory(), chestLocation);
|
||||
}
|
||||
|
||||
Player player = toolStats.playerInteract.openedChests.get(openedChest);
|
||||
setLoot(event.getLoot(), player);
|
||||
}
|
||||
if (inventoryHolder instanceof StorageMinecart mineCart) {
|
||||
if (toolStats.playerInteract.openedMineCarts.containsKey(mineCart)) {
|
||||
Player player = toolStats.playerInteract.openedMineCarts.get(mineCart);
|
||||
setLoot(event.getLoot(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds lore to newly generated items.
|
||||
*
|
||||
* @param itemStack The item to add lore to.
|
||||
* @param owner The player that found the item.
|
||||
* @return The item with the lore.
|
||||
*/
|
||||
private ItemStack addLootedOrigin(ItemStack itemStack, Player owner) {
|
||||
ItemStack newItem = itemStack.clone();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate;
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// get the current lore the item
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 2, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 2, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tags to the generated loot.
|
||||
*
|
||||
* @param loot The loot from the event.
|
||||
* @param player The player triggering the event.
|
||||
*/
|
||||
private void setLoot(List<ItemStack> loot, Player player) {
|
||||
for (int i = 0; i < loot.size(); i++) {
|
||||
ItemStack itemStack = loot.get(i);
|
||||
// ignore air
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
if (toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
ItemStack newItem = addLootedOrigin(itemStack, player);
|
||||
if (newItem != null) {
|
||||
loot.set(i, newItem);
|
||||
}
|
||||
if (toolStats.playerInteract.openedMineCarts.contains(mineCart)) {
|
||||
Inventory mineCartInventory = mineCart.getInventory();
|
||||
generatedInventory.put(mineCartInventory, mineCart.getLocation());
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
196
src/main/java/lol/hyper/toolstats/events/InventoryClose.java
Executable file
196
src/main/java/lol/hyper/toolstats/events/InventoryClose.java
Executable file
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Container;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.minecart.StorageMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class InventoryClose implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public InventoryClose(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
if (toolStats.generateLoot.generatedInventory.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
Inventory closedInventory = event.getInventory();
|
||||
InventoryHolder holder = closedInventory.getHolder();
|
||||
if (toolStats.generateLoot.generatedInventory.containsKey(closedInventory)) {
|
||||
Location chestLocation = toolStats.generateLoot.generatedInventory.get(closedInventory);
|
||||
toolStats.generateLoot.generatedInventory.remove(closedInventory);
|
||||
|
||||
player.getScheduler().runDelayed(toolStats, scheduledTask -> {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
for (int i = 0; i < playerInventory.getContents().length; i++) {
|
||||
ItemStack item = playerInventory.getItem(i);
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!toolStats.itemChecker.isValidItem(item.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack newItem = addLootedOrigin(item, player);
|
||||
if (newItem != null) {
|
||||
playerInventory.setItem(i, newItem);
|
||||
}
|
||||
}
|
||||
}, null, 1);
|
||||
|
||||
if (holder instanceof StorageMinecart mineCart) {
|
||||
mineCart.getScheduler().runDelayed(toolStats, scheduledTask -> {
|
||||
Inventory chestInventory = mineCart.getInventory();
|
||||
for (int i = 0; i < chestInventory.getContents().length; i++) {
|
||||
ItemStack item = chestInventory.getItem(i);
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!toolStats.itemChecker.isValidItem(item.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack newItem = addLootedOrigin(item, player);
|
||||
if (newItem != null) {
|
||||
chestInventory.setItem(i, newItem);
|
||||
}
|
||||
}
|
||||
}, null, 1);
|
||||
}
|
||||
|
||||
if (holder instanceof Container) {
|
||||
Chunk chestChunk = chestLocation.getChunk();
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, chestLocation.getWorld(), chestChunk.getX(), chestChunk.getZ(), scheduledTask -> {
|
||||
BlockState blockState = chestLocation.getWorld().getBlockAt(chestLocation).getState();
|
||||
if (blockState instanceof InventoryHolder chest) {
|
||||
Inventory chestInventory = chest.getInventory();
|
||||
for (int i = 0; i < chestInventory.getContents().length; i++) {
|
||||
ItemStack item = chestInventory.getItem(i);
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!toolStats.itemChecker.isValidItem(item.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack newItem = addLootedOrigin(item, player);
|
||||
if (newItem != null) {
|
||||
chestInventory.setItem(i, newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds lore to newly generated items.
|
||||
*
|
||||
* @param itemStack The item to add lore to.
|
||||
* @param owner The player that found the item.
|
||||
* @return The item with the lore.
|
||||
*/
|
||||
public ItemStack addLootedOrigin(ItemStack itemStack, Player owner) {
|
||||
ItemStack newItem = itemStack.clone();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate;
|
||||
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||
timeCreated = finalDate.getTime();
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER) || container.has(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG) || container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// get the current lore the item
|
||||
List<Component> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 2, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 2);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 2, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 2);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,14 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.hyperlib.datatypes.UUIDDataType;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
@@ -40,19 +42,20 @@ public class InventoryOpen implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onOpen(InventoryOpenEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
// only check these
|
||||
if (inventory.getType() != InventoryType.CHEST || inventory.getType() != InventoryType.BARREL || inventory.getType() != InventoryType.SHULKER_BOX || inventory.getType() != InventoryType.ENDER_CHEST) {
|
||||
InventoryHolder holder = inventory.getHolder();
|
||||
boolean isBlockInventory = holder instanceof BlockInventoryHolder || holder instanceof DoubleChest;
|
||||
if (!(inventory.getHolder() instanceof BlockInventoryHolder)) {
|
||||
// ignore not real inventories
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
for (ItemStack itemStack : inventory) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
@@ -69,13 +72,13 @@ public class InventoryOpen implements Listener {
|
||||
|
||||
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||
// if the token system is on and the item doesn't have stat keys
|
||||
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.tokenType)) {
|
||||
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.toolStatsKeys.getTokenType())) {
|
||||
// add the tokens
|
||||
String newTokens = toolStats.itemChecker.addTokensToExisting(itemStack);
|
||||
if (newTokens == null) {
|
||||
return;
|
||||
}
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, newTokens);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
@@ -83,29 +86,29 @@ public class InventoryOpen implements Listener {
|
||||
// generate a hash if the item doesn't have one (and enabled)
|
||||
// if hashes are disabled and the item has one, remove it.
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||
if (!container.has(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING)) {
|
||||
UUID owner = null;
|
||||
// get the current owner if there is one.
|
||||
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||
owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||
if (container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
owner = container.get(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType());
|
||||
}
|
||||
// if there is no owner, use the player holding it
|
||||
if (owner == null) {
|
||||
owner = player.getUniqueId();
|
||||
}
|
||||
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
Long timestamp = container.get(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG);
|
||||
if (timestamp == null) {
|
||||
// if there is no time created, use now
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
} else {
|
||||
// if hashes are disabled but the item has one, remove it.
|
||||
if (container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||
container.remove(toolStats.hash);
|
||||
if (container.has(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING)) {
|
||||
container.remove(toolStats.toolStatsKeys.getHash());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
|
||||
28
src/main/java/lol/hyper/toolstats/events/PickupItem.java
Normal file → Executable file
28
src/main/java/lol/hyper/toolstats/events/PickupItem.java
Normal file → Executable file
@@ -47,13 +47,13 @@ public class PickupItem implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPickup(EntityPickupItemEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player player) {
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class PickupItem implements Listener {
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (itemStack.getType() == Material.ELYTRA) {
|
||||
// the elytra has the new key, set the lore to it
|
||||
if (container.has(toolStats.newElytra, PersistentDataType.INTEGER)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getElytraKey(), PersistentDataType.INTEGER)) {
|
||||
ItemStack newElytra = addElytraOrigin(itemStack, (Player) event.getEntity());
|
||||
if (newElytra != null) {
|
||||
item.setItemStack(newElytra);
|
||||
@@ -105,7 +105,7 @@ public class PickupItem implements Listener {
|
||||
// only make the hash if it's enabled
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(finalItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
// get the current lore the item
|
||||
@@ -116,23 +116,23 @@ public class PickupItem implements Listener {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
container.remove(toolStats.newElytra);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 4);
|
||||
container.remove(toolStats.toolStatsKeys.getElytraKey());
|
||||
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 4, finalItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 4);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 4, finalItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 4);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
|
||||
65
src/main/java/lol/hyper/toolstats/events/PlayerDrop.java
Executable file
65
src/main/java/lol/hyper/toolstats/events/PlayerDrop.java
Executable file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PlayerDrop implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public PlayerDrop(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDrop(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (toolStats.generateLoot.generatedInventory.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.getScheduler().runDelayed(toolStats, scheduledTask -> {
|
||||
Inventory opened = player.getOpenInventory().getTopInventory();
|
||||
if (toolStats.generateLoot.generatedInventory.containsKey(opened)) {
|
||||
Item droppedItemEntity = event.getItemDrop();
|
||||
ItemStack droppedItem = droppedItemEntity.getItemStack();
|
||||
|
||||
if (!toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack newItem = toolStats.inventoryClose.addLootedOrigin(droppedItem, player);
|
||||
if (newItem != null) {
|
||||
droppedItemEntity.setItemStack(newItem);
|
||||
}
|
||||
}
|
||||
}, null, 1);
|
||||
}
|
||||
}
|
||||
20
src/main/java/lol/hyper/toolstats/events/PlayerFish.java
Normal file → Executable file
20
src/main/java/lol/hyper/toolstats/events/PlayerFish.java
Normal file → Executable file
@@ -46,17 +46,17 @@ public class PlayerFish implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onFish(PlayerFishEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
// only listen to when a player catches a fish
|
||||
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class PlayerFish implements Listener {
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG) || container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -132,8 +132,8 @@ public class PlayerFish implements Listener {
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 5, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 5);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -141,8 +141,8 @@ public class PlayerFish implements Listener {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 5, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 5);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class PlayerFish implements Listener {
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
newItem.setItemMeta(meta);
|
||||
|
||||
60
src/main/java/lol/hyper/toolstats/events/PlayerInteract.java
Normal file → Executable file
60
src/main/java/lol/hyper/toolstats/events/PlayerInteract.java
Normal file → Executable file
@@ -31,23 +31,30 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class PlayerInteract implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public final Map<Block, Player> openedChests = new HashMap<>();
|
||||
public final Map<StorageMinecart, Player> openedMineCarts = new HashMap<>();
|
||||
public final List<Block> openedChests = new ArrayList<>();
|
||||
public final List<StorageMinecart> openedMineCarts = new ArrayList<>();
|
||||
public final List<Inventory> chestInventories = new ArrayList<>();
|
||||
public final List<Inventory> mineCartChestInventories = new ArrayList<>();
|
||||
|
||||
public PlayerInteract(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
@@ -59,18 +66,47 @@ public class PlayerInteract implements Listener {
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a chest
|
||||
BlockState state = block.getState();
|
||||
if (state instanceof InventoryHolder) {
|
||||
openedChests.put(block, player);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
||||
if (state instanceof InventoryHolder holder) {
|
||||
Inventory holderInventory = holder.getInventory();
|
||||
openedChests.add(block);
|
||||
chestInventories.add(holderInventory);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, _ -> openedChests.remove(block), 20);
|
||||
}
|
||||
// player right-clicked a log
|
||||
String blockType = block.getType().toString().toLowerCase(Locale.ROOT);
|
||||
if (blockType.endsWith("_log") && !blockType.contains("stripped")) {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack axe = toolStats.itemChecker.getAxe(playerInventory);
|
||||
|
||||
// not holding an axe
|
||||
if (axe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta newAxe = toolStats.itemLore.updateLogsStripped(axe, 1);
|
||||
if (newAxe != null) {
|
||||
boolean isMain = playerInventory.getItemInMainHand().getType().toString().endsWith("_AXE");
|
||||
boolean isOffHand = playerInventory.getItemInOffHand().getType().toString().endsWith("_AXE");
|
||||
if (isMain && isOffHand) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newAxe);
|
||||
} else if (isMain) {
|
||||
playerInventory.getItemInMainHand().setItemMeta(newAxe);
|
||||
} else if (isOffHand) {
|
||||
playerInventory.getItemInOffHand().setItemMeta(newAxe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInteract(PlayerInteractEntityEvent event) {
|
||||
Entity clicked = event.getRightClicked();
|
||||
Player player = event.getPlayer();
|
||||
@@ -80,8 +116,10 @@ public class PlayerInteract implements Listener {
|
||||
// store when a player opens a minecart
|
||||
if (clicked.getType() == EntityType.CHEST_MINECART) {
|
||||
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
||||
openedMineCarts.put(storageMinecart, player);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedMineCarts.remove(storageMinecart), 20);
|
||||
Inventory mineCartInventory = storageMinecart.getInventory();
|
||||
mineCartChestInventories.add(mineCartInventory);
|
||||
openedMineCarts.add(storageMinecart);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, _ -> openedMineCarts.remove(storageMinecart), 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
21
src/main/java/lol/hyper/toolstats/events/PlayerJoin.java
Normal file → Executable file
21
src/main/java/lol/hyper/toolstats/events/PlayerJoin.java
Normal file → Executable file
@@ -42,6 +42,9 @@ public class PlayerJoin implements Listener {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = player.getInventory();
|
||||
for (ItemStack itemStack : inventory) {
|
||||
@@ -60,42 +63,42 @@ public class PlayerJoin implements Listener {
|
||||
|
||||
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||
// if the token system is on and the item doesn't have stat keys
|
||||
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.tokenType)) {
|
||||
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.toolStatsKeys.getTokenType())) {
|
||||
// add the tokens
|
||||
String newTokens = toolStats.itemChecker.addTokensToExisting(itemStack);
|
||||
if (newTokens == null) {
|
||||
return;
|
||||
}
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, newTokens);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
|
||||
// generate a hash if the item doesn't have one
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||
if (!container.has(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING)) {
|
||||
UUID owner = null;
|
||||
// get the current owner if there is one.
|
||||
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||
owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||
if (container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
owner = container.get(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType());
|
||||
}
|
||||
// if there is no owner, use the player holding it
|
||||
if (owner == null) {
|
||||
owner = player.getUniqueId();
|
||||
}
|
||||
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
Long timestamp = container.get(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG);
|
||||
if (timestamp == null) {
|
||||
// if there is no time created, use now
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
} else {
|
||||
// if hashes are disabled but the item has one, remove it.
|
||||
if (container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||
container.remove(toolStats.hash);
|
||||
if (container.has(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING)) {
|
||||
container.remove(toolStats.toolStatsKeys.getHash());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
|
||||
5
src/main/java/lol/hyper/toolstats/events/PlayerMove.java
Normal file → Executable file
5
src/main/java/lol/hyper/toolstats/events/PlayerMove.java
Normal file → Executable file
@@ -39,9 +39,12 @@ public class PlayerMove implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
// player starts to fly
|
||||
if (player.isGliding()) {
|
||||
// if they are flying, and we don't have them tracked, add them
|
||||
|
||||
2
src/main/java/lol/hyper/toolstats/events/PrepareCraft.java
Normal file → Executable file
2
src/main/java/lol/hyper/toolstats/events/PrepareCraft.java
Normal file → Executable file
@@ -48,7 +48,7 @@ public class PrepareCraft implements Listener {
|
||||
}
|
||||
// if the paper item has our PDC, cancel it
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.tokenType)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getTokenType())) {
|
||||
event.getInventory().setResult(null);
|
||||
}
|
||||
}
|
||||
|
||||
58
src/main/java/lol/hyper/toolstats/events/ProjectileShoot.java
Executable file
58
src/main/java/lol/hyper/toolstats/events/ProjectileShoot.java
Executable file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class ProjectileShoot implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public ProjectileShoot(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onProjectileLaunch(PlayerLaunchProjectileEvent event) {
|
||||
if (!(event.getProjectile() instanceof Trident tridentEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!toolStats.configTools.checkWorld(tridentEntity.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
tridentEntity.getScheduler().runDelayed(toolStats, scheduledTask -> {
|
||||
ItemStack tridentStack = tridentEntity.getItemStack();
|
||||
ItemMeta newTridentMeta = toolStats.itemLore.updateTridentThrows(tridentStack, 1);
|
||||
if (newTridentMeta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
tridentStack.setItemMeta(newTridentMeta);
|
||||
tridentEntity.setItemStack(tridentStack);
|
||||
}, null, 1);
|
||||
}
|
||||
}
|
||||
10
src/main/java/lol/hyper/toolstats/events/SheepShear.java
Normal file → Executable file
10
src/main/java/lol/hyper/toolstats/events/SheepShear.java
Normal file → Executable file
@@ -39,12 +39,15 @@ public class SheepShear implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onShear(PlayerInteractEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
@@ -59,6 +62,11 @@ public class SheepShear implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure they are not a baby
|
||||
if (!sheep.isAdult()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the sheep is not sheared
|
||||
if (sheep.isSheared()) {
|
||||
return;
|
||||
|
||||
5
src/main/java/lol/hyper/toolstats/events/ShootBow.java
Normal file → Executable file
5
src/main/java/lol/hyper/toolstats/events/ShootBow.java
Normal file → Executable file
@@ -38,7 +38,7 @@ public class ShootBow implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onShoot(EntityShootBowEvent event) {
|
||||
Entity shooter = event.getEntity();
|
||||
// only listen for players
|
||||
@@ -46,6 +46,9 @@ public class ShootBow implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE && !toolStats.config.getBoolean("allow-creative")) {
|
||||
return;
|
||||
}
|
||||
|
||||
19
src/main/java/lol/hyper/toolstats/events/VillagerTrade.java
Normal file → Executable file
19
src/main/java/lol/hyper/toolstats/events/VillagerTrade.java
Normal file → Executable file
@@ -47,15 +47,18 @@ public class VillagerTrade implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onTrade(InventoryClickEvent event) {
|
||||
if (event.isCancelled() || event.getCurrentItem() == null) {
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
if (!toolStats.configTools.checkWorld(player.getWorld().getName())) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
@@ -134,7 +137,7 @@ public class VillagerTrade implements Listener {
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG) || container.has(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -150,8 +153,8 @@ public class VillagerTrade implements Listener {
|
||||
// if creation date is enabled, add it
|
||||
Component creationDate = toolStats.itemLore.formatCreationTime(timeCreated, 3, newItem);
|
||||
if (creationDate != null) {
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
container.set(toolStats.toolStatsKeys.getTimeCreated(), PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 3);
|
||||
lore.add(creationDate);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -159,8 +162,8 @@ public class VillagerTrade implements Listener {
|
||||
// if ownership is enabled, add it
|
||||
Component itemOwner = toolStats.itemLore.formatOwner(owner.getName(), 3, newItem);
|
||||
if (itemOwner != null) {
|
||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
container.set(toolStats.toolStatsKeys.getItemOwner(), new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.toolStatsKeys.getOriginType(), PersistentDataType.INTEGER, 3);
|
||||
lore.add(itemOwner);
|
||||
meta.lore(lore);
|
||||
}
|
||||
@@ -168,7 +171,7 @@ public class VillagerTrade implements Listener {
|
||||
// if hash is enabled, add it
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.toolStatsKeys.getHash(), PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
newItem.setItemMeta(meta);
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.support.rosestacker;
|
||||
|
||||
import dev.rosewood.rosestacker.api.RoseStackerAPI;
|
||||
import dev.rosewood.rosestacker.stack.StackedEntity;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class RoseStacker {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final RoseStackerAPI rsAPI;
|
||||
|
||||
public RoseStacker(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
this.rsAPI = RoseStackerAPI.getInstance();
|
||||
}
|
||||
|
||||
public void countMobs(LivingEntity entity, Consumer<Integer> callback) {
|
||||
if (!rsAPI.isEntityStacked(entity)) {
|
||||
// if the entity is not stacked, ignore
|
||||
callback.accept(1);
|
||||
return;
|
||||
}
|
||||
StackedEntity stackedEntity = rsAPI.getStackedEntity(entity);
|
||||
if (stackedEntity == null) {
|
||||
callback.accept(1);
|
||||
return;
|
||||
}
|
||||
|
||||
int before = stackedEntity.getStackSize();
|
||||
boolean killAll = stackedEntity.getStackSettings().shouldKillEntireStackOnDeath();
|
||||
// if we kill the entire stack, add the entire stack to the count
|
||||
if (killAll) {
|
||||
callback.accept(before);
|
||||
return;
|
||||
}
|
||||
|
||||
Location stackedLocation = stackedEntity.getLocation();
|
||||
Chunk stackedChunk = stackedEntity.getLocation().getChunk();
|
||||
// check the stack size after a tick to see the difference
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, stackedLocation.getWorld(), stackedChunk.getX(), stackedChunk.getZ(), _ -> {
|
||||
int after = stackedEntity.getStackSize();
|
||||
int difference = before - after;
|
||||
// if the diff goes negative, we killed more than the stack
|
||||
// we killed the entire stack, so return the size
|
||||
if (difference <= 0) {
|
||||
difference = before;
|
||||
}
|
||||
|
||||
toolStats.logger.info("before: {}", before);
|
||||
toolStats.logger.info("after: {}", after);
|
||||
toolStats.logger.info("difference: {}", difference);
|
||||
|
||||
callback.accept(difference);
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
0
src/main/java/lol/hyper/toolstats/tools/HashMaker.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/HashMaker.java
Normal file → Executable file
81
src/main/java/lol/hyper/toolstats/tools/ItemChecker.java
Normal file → Executable file
81
src/main/java/lol/hyper/toolstats/tools/ItemChecker.java
Normal file → Executable file
@@ -52,7 +52,7 @@ public class ItemChecker {
|
||||
mineItems.add(material);
|
||||
}
|
||||
|
||||
if (lowerCase.contains("_sword") || lowerCase.contains("_axe")) {
|
||||
if (lowerCase.contains("_sword") || lowerCase.contains("_axe") || lowerCase.contains("_spear")) {
|
||||
meleeItems.add(material);
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ public class ItemChecker {
|
||||
validItems.add(Material.CROSSBOW);
|
||||
validItems.add(Material.FISHING_ROD);
|
||||
validItems.add(Material.ELYTRA);
|
||||
validItems.add(Material.SHIELD);
|
||||
|
||||
// combine the lists
|
||||
validItems.addAll(armorItems);
|
||||
@@ -142,12 +143,12 @@ public class ItemChecker {
|
||||
*/
|
||||
public boolean checkTokens(PersistentDataContainer container, String targetToken) {
|
||||
// make sure the item has tokens
|
||||
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
|
||||
if (!container.has(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the tokens for this item
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
String tokens = container.get(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -168,12 +169,12 @@ public class ItemChecker {
|
||||
return new String[0];
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
|
||||
if (!container.has(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING)) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
// get the tokens for this item
|
||||
String tokensRaw = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
String tokensRaw = container.get(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING);
|
||||
if (tokensRaw == null) {
|
||||
return new String[0];
|
||||
}
|
||||
@@ -197,12 +198,12 @@ public class ItemChecker {
|
||||
String[] tokens = getTokens(item);
|
||||
// there are no tokens
|
||||
if (tokens.length == 0) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, token);
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, token);
|
||||
} else {
|
||||
// other tokens exist, so add
|
||||
String[] newTokens = Arrays.copyOf(tokens, tokens.length + 1);
|
||||
newTokens[tokens.length] = token;
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
@@ -305,6 +306,35 @@ public class ItemChecker {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player's axe.
|
||||
*
|
||||
* @param inventory Their inventory.
|
||||
* @return Their axe, either main or offhand.
|
||||
*/
|
||||
public @Nullable ItemStack getAxe(PlayerInventory inventory) {
|
||||
ItemStack main = inventory.getItemInMainHand();
|
||||
ItemStack offHand = inventory.getItemInOffHand();
|
||||
|
||||
boolean isMain = main.getType().toString().endsWith("_AXE");
|
||||
boolean isOffHand = offHand.getType().toString().endsWith("_AXE");
|
||||
|
||||
// if the player is holding an axe in their main hand, use that one
|
||||
// if the axe is in their offhand instead, use that one after checking main hand
|
||||
// Minecraft prioritizes main hand if the player holds in both hands
|
||||
if (isMain && isOffHand) {
|
||||
return main;
|
||||
}
|
||||
if (isMain) {
|
||||
return main;
|
||||
}
|
||||
if (isOffHand) {
|
||||
return offHand;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the keys of the item and returns the tokens we should add.
|
||||
* If the server swaps token systems this should allow compatability.
|
||||
@@ -320,36 +350,51 @@ public class ItemChecker {
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
ArrayList<String> tokens = new ArrayList<>();
|
||||
if (container.has(toolStats.playerKills)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getPlayerKills())) {
|
||||
tokens.add("player-kills");
|
||||
}
|
||||
if (container.has(toolStats.mobKills)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getMobKills())) {
|
||||
tokens.add("mob-kills");
|
||||
}
|
||||
if (container.has(toolStats.blocksMined)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getBlocksMined())) {
|
||||
tokens.add("blocks-mined");
|
||||
}
|
||||
if (container.has(toolStats.cropsHarvested)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getCropsHarvested())) {
|
||||
tokens.add("crops-mined");
|
||||
}
|
||||
if (container.has(toolStats.fishCaught)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getFishCaught())) {
|
||||
tokens.add("fish-caught");
|
||||
}
|
||||
if (container.has(toolStats.sheepSheared)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getSheepSheared())) {
|
||||
tokens.add("sheep-sheared");
|
||||
}
|
||||
if (container.has(toolStats.armorDamage)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getArmorDamage())) {
|
||||
tokens.add("damage-taken");
|
||||
}
|
||||
if (container.has(toolStats.arrowsShot)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getArrowsShot())) {
|
||||
tokens.add("arrows-shot");
|
||||
}
|
||||
if (container.has(toolStats.flightTime)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getFlightTime())) {
|
||||
tokens.add("flight-time");
|
||||
}
|
||||
if (container.has(toolStats.damageDone)) {
|
||||
if (container.has(toolStats.toolStatsKeys.getDamageDone())) {
|
||||
tokens.add("damage-done");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getWitherKills())) {
|
||||
tokens.add("wither-kills");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getEnderDragonKills())) {
|
||||
tokens.add("enderdragon-kills");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getCriticalStrikes())) {
|
||||
tokens.add("critical-strikes");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getTridentThrows())) {
|
||||
tokens.add("trident-throws");
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getLogsStripped())) {
|
||||
tokens.add("logs-stripped");
|
||||
}
|
||||
if (tokens.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -386,6 +431,6 @@ public class ItemChecker {
|
||||
public boolean keyCheck(PersistentDataContainer container) {
|
||||
return container.getKeys().stream()
|
||||
.map(NamespacedKey::getKey)
|
||||
.anyMatch(key -> toolStats.tokenKeys.stream().anyMatch(tokenKey -> tokenKey.getKey().equalsIgnoreCase(key)));
|
||||
.anyMatch(key -> toolStats.toolStatsKeys.getTokenKeys().stream().anyMatch(tokenKey -> tokenKey.getKey().equalsIgnoreCase(key)));
|
||||
}
|
||||
}
|
||||
|
||||
806
src/main/java/lol/hyper/toolstats/tools/ItemLore.java
Normal file → Executable file
806
src/main/java/lol/hyper/toolstats/tools/ItemLore.java
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
0
src/main/java/lol/hyper/toolstats/tools/NumberFormat.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/NumberFormat.java
Normal file → Executable file
42
src/main/java/lol/hyper/toolstats/tools/TokenData.java
Normal file → Executable file
42
src/main/java/lol/hyper/toolstats/tools/TokenData.java
Normal file → Executable file
@@ -125,6 +125,41 @@ public class TokenData {
|
||||
removeRecipe.setIngredient('P', Material.PAPER);
|
||||
recipes.add(removeRecipe);
|
||||
|
||||
NamespacedKey witherKillsKey = new NamespacedKey(toolStats, "wither-kills-token");
|
||||
ShapedRecipe witherKillsRecipe = new ShapedRecipe(witherKillsKey, createToken("wither-kills"));
|
||||
witherKillsRecipe.shape(" P ", "PWP", " P ");
|
||||
witherKillsRecipe.setIngredient('P', Material.PAPER);
|
||||
witherKillsRecipe.setIngredient('W', Material.WITHER_ROSE);
|
||||
recipes.add(witherKillsRecipe);
|
||||
|
||||
NamespacedKey enderDragonKillsKey = new NamespacedKey(toolStats, "enderdragon-kills-token");
|
||||
ShapedRecipe enderDragonKillsRecipe = new ShapedRecipe(enderDragonKillsKey, createToken("enderdragon-kills"));
|
||||
enderDragonKillsRecipe.shape(" P ", "PEP", " P ");
|
||||
enderDragonKillsRecipe.setIngredient('P', Material.PAPER);
|
||||
enderDragonKillsRecipe.setIngredient('E', Material.ENDER_PEARL);
|
||||
recipes.add(enderDragonKillsRecipe);
|
||||
|
||||
NamespacedKey criticalStrikesKey = new NamespacedKey(toolStats, "critical-strikes-token");
|
||||
ShapedRecipe criticalStrikesRecipe = new ShapedRecipe(criticalStrikesKey, createToken("critical-strikes"));
|
||||
criticalStrikesRecipe.shape(" P ", "PSP", " P ");
|
||||
criticalStrikesRecipe.setIngredient('P', Material.PAPER);
|
||||
criticalStrikesRecipe.setIngredient('S', Material.GOLDEN_SWORD);
|
||||
recipes.add(criticalStrikesRecipe);
|
||||
|
||||
NamespacedKey tridentThrowsKey = new NamespacedKey(toolStats, "trident-throws-token");
|
||||
ShapedRecipe tridentThrowsRecipe = new ShapedRecipe(tridentThrowsKey, createToken("trident-throws"));
|
||||
tridentThrowsRecipe.shape(" P ", "PSP", " P ");
|
||||
tridentThrowsRecipe.setIngredient('P', Material.PAPER);
|
||||
tridentThrowsRecipe.setIngredient('S', Material.PRISMARINE_SHARD);
|
||||
recipes.add(tridentThrowsRecipe);
|
||||
|
||||
NamespacedKey logsStrippedKey = new NamespacedKey(toolStats, "logs-stripped-token");
|
||||
ShapedRecipe logsStrippedRecipe = new ShapedRecipe(logsStrippedKey, createToken("logs-stripped"));
|
||||
logsStrippedRecipe.shape(" P ", "PSP", " P ");
|
||||
logsStrippedRecipe.setIngredient('P', Material.PAPER);
|
||||
logsStrippedRecipe.setIngredient('S', Material.WOODEN_AXE);
|
||||
recipes.add(logsStrippedRecipe);
|
||||
|
||||
tokenTypes.add("crops-mined");
|
||||
tokenTypes.add("blocks-mined");
|
||||
tokenTypes.add("damage-taken");
|
||||
@@ -137,6 +172,11 @@ public class TokenData {
|
||||
tokenTypes.add("fish-caught");
|
||||
tokenTypes.add("reset");
|
||||
tokenTypes.add("remove");
|
||||
tokenTypes.add("wither-kills");
|
||||
tokenTypes.add("enderdragon-kills");
|
||||
tokenTypes.add("critical-strikes");
|
||||
tokenTypes.add("trident-throws");
|
||||
tokenTypes.add("logs-stripped");
|
||||
}
|
||||
|
||||
public Set<ShapedRecipe> getRecipes() {
|
||||
@@ -177,7 +217,7 @@ public class TokenData {
|
||||
tokenMeta.lore(lore);
|
||||
|
||||
// set the PDC
|
||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, tokenType);
|
||||
tokenData.set(toolStats.toolStatsKeys.getTokenType(), PersistentDataType.STRING, tokenType);
|
||||
token.setItemMeta(tokenMeta);
|
||||
|
||||
// set the custom model data
|
||||
|
||||
189
src/main/java/lol/hyper/toolstats/tools/ToolStatsKeys.java
Executable file
189
src/main/java/lol/hyper/toolstats/tools/ToolStatsKeys.java
Executable file
@@ -0,0 +1,189 @@
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ToolStatsKeys {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final Set<NamespacedKey> tokenKeys = new HashSet<>();
|
||||
|
||||
public ToolStatsKeys(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
private NamespacedKey itemOwner;
|
||||
private NamespacedKey timeCreated;
|
||||
private NamespacedKey playerKills;
|
||||
private NamespacedKey mobKills;
|
||||
private NamespacedKey blocksMined;
|
||||
private NamespacedKey cropsHarvested;
|
||||
private NamespacedKey fishCaught;
|
||||
private NamespacedKey sheepSheared;
|
||||
private NamespacedKey armorDamage;
|
||||
private NamespacedKey damageDone;
|
||||
private NamespacedKey newElytra;
|
||||
private NamespacedKey hash;
|
||||
private NamespacedKey arrowsShot;
|
||||
private NamespacedKey droppedBy;
|
||||
private NamespacedKey flightTime;
|
||||
private NamespacedKey tokenType;
|
||||
private NamespacedKey tokenApplied;
|
||||
private NamespacedKey witherKills;
|
||||
private NamespacedKey enderDragonKills;
|
||||
private NamespacedKey criticalStrikes;
|
||||
private NamespacedKey tridentThrows;
|
||||
private NamespacedKey originType;
|
||||
private NamespacedKey logsStripped;
|
||||
|
||||
public void make() {
|
||||
itemOwner = new NamespacedKey(toolStats, "owner");
|
||||
timeCreated = new NamespacedKey(toolStats, "time-created");
|
||||
playerKills = new NamespacedKey(toolStats, "player-kills");
|
||||
mobKills = new NamespacedKey(toolStats, "mob-kills");
|
||||
blocksMined = new NamespacedKey(toolStats, "generic-mined");
|
||||
cropsHarvested = new NamespacedKey(toolStats, "crops-mined");
|
||||
fishCaught = new NamespacedKey(toolStats, "fish-caught");
|
||||
sheepSheared = new NamespacedKey(toolStats, "sheared");
|
||||
armorDamage = new NamespacedKey(toolStats, "damage-taken");
|
||||
damageDone = new NamespacedKey(toolStats, "damage-done");
|
||||
newElytra = new NamespacedKey(toolStats, "new");
|
||||
hash = new NamespacedKey(toolStats, "hash");
|
||||
arrowsShot = new NamespacedKey(toolStats, "arrows-shot");
|
||||
droppedBy = new NamespacedKey(toolStats, "dropped-by");
|
||||
flightTime = new NamespacedKey(toolStats, "flightTime");
|
||||
tokenType = new NamespacedKey(toolStats, "token-type");
|
||||
tokenApplied = new NamespacedKey(toolStats, "token-applied");
|
||||
witherKills = new NamespacedKey(toolStats, "wither-kills");
|
||||
enderDragonKills = new NamespacedKey(toolStats, "enderdragon-kills");
|
||||
criticalStrikes = new NamespacedKey(toolStats, "critical-strikes");
|
||||
tridentThrows = new NamespacedKey(toolStats, "trident-throws");
|
||||
originType = new NamespacedKey(toolStats, "origin");
|
||||
logsStripped = new NamespacedKey(toolStats, "logs-stripped");
|
||||
|
||||
// save which stat can be used by a reset token
|
||||
tokenKeys.add(blocksMined);
|
||||
tokenKeys.add(playerKills);
|
||||
tokenKeys.add(mobKills);
|
||||
tokenKeys.add(cropsHarvested);
|
||||
tokenKeys.add(sheepSheared);
|
||||
tokenKeys.add(fishCaught);
|
||||
tokenKeys.add(flightTime);
|
||||
tokenKeys.add(arrowsShot);
|
||||
tokenKeys.add(armorDamage);
|
||||
tokenKeys.add(witherKills);
|
||||
tokenKeys.add(enderDragonKills);
|
||||
tokenKeys.add(criticalStrikes);
|
||||
tokenKeys.add(tridentThrows);
|
||||
tokenKeys.add(logsStripped);
|
||||
}
|
||||
|
||||
public NamespacedKey getItemOwner() {
|
||||
return itemOwner;
|
||||
}
|
||||
|
||||
public NamespacedKey getTimeCreated() {
|
||||
return timeCreated;
|
||||
}
|
||||
|
||||
public NamespacedKey getPlayerKills() {
|
||||
return playerKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getMobKills() {
|
||||
return mobKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getBlocksMined() {
|
||||
return blocksMined;
|
||||
}
|
||||
|
||||
public NamespacedKey getCropsHarvested() {
|
||||
return cropsHarvested;
|
||||
}
|
||||
|
||||
public NamespacedKey getFishCaught() {
|
||||
return fishCaught;
|
||||
}
|
||||
|
||||
public NamespacedKey getSheepSheared() {
|
||||
return sheepSheared;
|
||||
}
|
||||
|
||||
public NamespacedKey getArmorDamage() {
|
||||
return armorDamage;
|
||||
}
|
||||
|
||||
public NamespacedKey getDamageDone() {
|
||||
return damageDone;
|
||||
}
|
||||
|
||||
public NamespacedKey getElytraKey() {
|
||||
return newElytra;
|
||||
}
|
||||
|
||||
public NamespacedKey getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public NamespacedKey getArrowsShot() {
|
||||
return arrowsShot;
|
||||
}
|
||||
|
||||
public NamespacedKey getDroppedBy() {
|
||||
return droppedBy;
|
||||
}
|
||||
|
||||
public NamespacedKey getFlightTime() {
|
||||
return flightTime;
|
||||
}
|
||||
|
||||
public NamespacedKey getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
public NamespacedKey getTokenApplied() {
|
||||
return tokenApplied;
|
||||
}
|
||||
|
||||
public NamespacedKey getWitherKills() {
|
||||
return witherKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getEnderDragonKills() {
|
||||
return enderDragonKills;
|
||||
}
|
||||
|
||||
public NamespacedKey getCriticalStrikes() {
|
||||
return criticalStrikes;
|
||||
}
|
||||
|
||||
public NamespacedKey getTridentThrows() {
|
||||
return tridentThrows;
|
||||
}
|
||||
|
||||
public NamespacedKey getLogsStripped() {
|
||||
return logsStripped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores how an item was created.
|
||||
* 0 = crafted.
|
||||
* 1 = dropped.
|
||||
* 2 = looted.
|
||||
* 3 = traded.
|
||||
* 4 = founded (for elytras).
|
||||
* 5 = fished.
|
||||
* 6 = spawned in (creative).
|
||||
*/
|
||||
public NamespacedKey getOriginType() {
|
||||
return originType;
|
||||
}
|
||||
|
||||
public Set<NamespacedKey> getTokenKeys() {
|
||||
return tokenKeys;
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class ConfigTools {
|
||||
String itemName = material.toString().toLowerCase();
|
||||
String itemType = null;
|
||||
// hardcode these
|
||||
if (material == Material.BOW || material == Material.CROSSBOW || material == Material.SHEARS || material == Material.TRIDENT || material == Material.FISHING_ROD) {
|
||||
if (material == Material.BOW || material == Material.CROSSBOW || material == Material.SHEARS || material == Material.TRIDENT || material == Material.FISHING_ROD || material == Material.SHIELD) {
|
||||
switch (material) {
|
||||
case CROSSBOW:
|
||||
case BOW: {
|
||||
@@ -72,6 +72,10 @@ public class ConfigTools {
|
||||
itemType = "fishing-rod";
|
||||
break;
|
||||
}
|
||||
case SHIELD: {
|
||||
itemType = "shield";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
||||
@@ -87,12 +91,55 @@ public class ConfigTools {
|
||||
case "trident" -> toolStats.config.getBoolean("enabled." + configName + ".trident");
|
||||
case "fishing-rod" -> toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||
case "mace" -> toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||
case "spear" -> toolStats.config.getBoolean("enabled." + configName + ".spear");
|
||||
case "shield" -> toolStats.config.getBoolean("enabled." + configName + ".shield");
|
||||
case "helmet", "chestplate", "leggings", "boots" ->
|
||||
toolStats.config.getBoolean("enabled." + configName + ".armor");
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the status of a world from the config.
|
||||
*
|
||||
* @param worldName The world to check.
|
||||
* @return True if we can work in this world, false if not.
|
||||
*/
|
||||
public boolean checkWorld(String worldName) {
|
||||
boolean enabled = toolStats.config.getBoolean("world-limit.enabled");
|
||||
// if the system is disabled, all worlds are allowed
|
||||
if (!enabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String mode = toolStats.config.getString("world-limit.mode");
|
||||
if (mode == null) {
|
||||
toolStats.logger.info("world-limit.mode is not set, not allowing any worlds by default.");
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> worlds = toolStats.config.getStringList("world-limit.worlds");
|
||||
// if no worlds are defined, deny them
|
||||
if (worlds.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode.equalsIgnoreCase("blacklist")) {
|
||||
// this world is on list and mode = blacklisted
|
||||
// don't allow this world, allow others not on list
|
||||
return !worlds.contains(worldName);
|
||||
}
|
||||
|
||||
if (mode.equalsIgnoreCase("whitelist")) {
|
||||
// this world is on list and mode = whitelisted
|
||||
// allow it. if the world is not on list, don't allow it
|
||||
return worlds.contains(worldName);
|
||||
}
|
||||
|
||||
toolStats.logger.warn("Unknown worlds.mode '{}', denying by default.", mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string to be ready for lore usage.
|
||||
*
|
||||
|
||||
4
src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java
Normal file → Executable file
4
src/main/java/lol/hyper/toolstats/tools/config/ConfigUpdater.java
Normal file → Executable file
@@ -40,6 +40,10 @@ public class ConfigUpdater {
|
||||
case 10 -> new Version11(toolStats).update(); // 10 to 11
|
||||
case 11 -> new Version12(toolStats).update(); // 11 to 12
|
||||
case 12 -> new Version13(toolStats).update(); // 12 to 13
|
||||
case 13 -> new Version14(toolStats).update(); // 13 to 14
|
||||
case 14 -> new Version15(toolStats).update(); // 14 to 15
|
||||
case 15 -> new Version16(toolStats).update(); // 15 to 16
|
||||
case 16 -> new Version17(toolStats).update(); // 16 to 17
|
||||
}
|
||||
}
|
||||
}
|
||||
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version10.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version10.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version11.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version11.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version12.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version12.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version13.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version13.java
Normal file → Executable file
88
src/main/java/lol/hyper/toolstats/tools/config/versions/Version14.java
Executable file
88
src/main/java/lol/hyper/toolstats/tools/config/versions/Version14.java
Executable file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Version14 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 13 to 14.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version14(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the config update.
|
||||
*/
|
||||
public void update() {
|
||||
// save the old config first
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-13.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config-13.yml!", exception);
|
||||
}
|
||||
|
||||
toolStats.logger.info("Updating config.yml to version 14.");
|
||||
toolStats.config.set("config-version", 14);
|
||||
|
||||
// add spear to sections to be a toggle
|
||||
toolStats.config.set("enabled.crafted-by.spear", true);
|
||||
toolStats.logger.info("Adding enabled.crafted-by.spear");
|
||||
|
||||
toolStats.config.set("enabled.crafted-on.spear", true);
|
||||
toolStats.logger.info("Adding enabled.crafted-on.spear");
|
||||
|
||||
toolStats.config.set("enabled.looted-by.spear", true);
|
||||
toolStats.logger.info("Adding enabled.looted-by.spear");
|
||||
|
||||
toolStats.config.set("enabled.looted-on.spear", true);
|
||||
toolStats.logger.info("Adding enabled.looted-on.spear");
|
||||
|
||||
toolStats.config.set("enabled.damage-done.spear", true);
|
||||
toolStats.logger.info("Adding enabled.damage-done.spear");
|
||||
|
||||
toolStats.config.set("enabled.player-kills.spear", true);
|
||||
toolStats.logger.info("Adding enabled.player-kills.spear");
|
||||
|
||||
toolStats.config.set("enabled.mob-kills.spear", true);
|
||||
toolStats.logger.info("Adding enabled.mob-kills.spear");
|
||||
|
||||
toolStats.config.set("enabled.spawned-in-by.spear", true);
|
||||
toolStats.logger.info("Adding enabled.spawned-in-by.spear");
|
||||
|
||||
toolStats.config.set("enabled.spawned-in-on.spear", true);
|
||||
toolStats.logger.info("Adding enabled.spawned-in-on.spear");
|
||||
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 14. A copy of version 13 has been saved as config-13.yml");
|
||||
}
|
||||
}
|
||||
146
src/main/java/lol/hyper/toolstats/tools/config/versions/Version15.java
Executable file
146
src/main/java/lol/hyper/toolstats/tools/config/versions/Version15.java
Executable file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Version15 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 14 to 15.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version15(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the config update.
|
||||
*/
|
||||
public void update() {
|
||||
// save the old config first
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-14.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config-14.yml!", exception);
|
||||
}
|
||||
|
||||
toolStats.logger.info("Updating config.yml to version 15.");
|
||||
toolStats.config.set("config-version", 15);
|
||||
|
||||
// wither kills token
|
||||
toolStats.logger.info("Adding new token to config: wither-kills");
|
||||
toolStats.config.set("tokens.data.wither-kills.title", "&7ToolStats: &8Wither Kills Token");
|
||||
toolStats.config.set("tokens.data.wither-kills.lore", List.of(
|
||||
"&8Combine with a melee or ranged weapon in an anvil to track wither kills.",
|
||||
"&8Uses &7{levels} &8level."
|
||||
));
|
||||
toolStats.config.set("tokens.data.wither-kills.levels", 1);
|
||||
toolStats.config.set("tokens.data.wither-kills.material", "PAPER");
|
||||
|
||||
toolStats.config.set("tokens.data.wither-kills.custom-model-data.enabled", false);
|
||||
toolStats.config.set("tokens.data.wither-kills.custom-model-data.type", "float");
|
||||
toolStats.config.set("tokens.data.wither-kills.custom-model-data.value", 1001);
|
||||
|
||||
// ender dragon kills token
|
||||
toolStats.logger.info("Adding new token to config: enderdragon-kills");
|
||||
toolStats.config.set("tokens.data.enderdragon-kills.title", "&7ToolStats: &8Ender Dragon Kills Token");
|
||||
toolStats.config.set("tokens.data.enderdragon-kills.lore", List.of(
|
||||
"&8Combine with a melee or ranged weapon in an anvil to track Ender Dragon kills.",
|
||||
"&8Uses &7{levels} &8level."
|
||||
));
|
||||
toolStats.config.set("tokens.data.enderdragon-kills.levels", 1);
|
||||
toolStats.config.set("tokens.data.enderdragon-kills.material", "PAPER");
|
||||
|
||||
toolStats.config.set("tokens.data.enderdragon-kills.custom-model-data.enabled", false);
|
||||
toolStats.config.set("tokens.data.enderdragon-kills.custom-model-data.type", "float");
|
||||
toolStats.config.set("tokens.data.enderdragon-kills.custom-model-data.value", 1001);
|
||||
|
||||
// critical strikes token
|
||||
toolStats.logger.info("Adding new token to config: critical-strikes");
|
||||
toolStats.config.set("tokens.data.critical-strikes.title", "&7ToolStats: &8Critical Strikes Token");
|
||||
toolStats.config.set("tokens.data.critical-strikes.lore", List.of(
|
||||
"&8Combine with a melee or ranged weapon in an anvil to track critical strikes.",
|
||||
"&8Uses &7{levels} &8level."
|
||||
));
|
||||
toolStats.config.set("tokens.data.critical-strikes.levels", 1);
|
||||
toolStats.config.set("tokens.data.critical-strikes.material", "PAPER");
|
||||
|
||||
toolStats.config.set("tokens.data.critical-strikes.custom-model-data.enabled", false);
|
||||
toolStats.config.set("tokens.data.critical-strikes.custom-model-data.type", "float");
|
||||
toolStats.config.set("tokens.data.critical-strikes.custom-model-data.value", 1001);
|
||||
|
||||
// trident throws token
|
||||
toolStats.logger.info("Adding new token to config: trident-throws");
|
||||
toolStats.config.set("tokens.data.trident-throws.title", "&7ToolStats: &8Trident Throws Token");
|
||||
toolStats.config.set("tokens.data.trident-throws.lore", List.of(
|
||||
"&8Combine with a trident in an anvil to track times thrown.",
|
||||
"&8Uses &7{levels} &8level."
|
||||
));
|
||||
toolStats.config.set("tokens.data.trident-throws.levels", 1);
|
||||
toolStats.config.set("tokens.data.trident-throws.material", "PAPER");
|
||||
|
||||
toolStats.config.set("tokens.data.trident-throws.custom-model-data.enabled", false);
|
||||
toolStats.config.set("tokens.data.trident-throws.custom-model-data.type", "float");
|
||||
toolStats.config.set("tokens.data.trident-throws.custom-model-data.value", 1001);
|
||||
|
||||
// bosses-killed stuff
|
||||
toolStats.logger.info("Adding enabled.bosses-killed.wither");
|
||||
toolStats.config.set("enabled.bosses-killed.wither", true);
|
||||
toolStats.logger.info("Adding enabled.bosses-killed.enderdragon");
|
||||
toolStats.config.set("enabled.bosses-killed.enderdragon", true);
|
||||
|
||||
// critical strikes
|
||||
toolStats.config.set("enabled.critical-strikes", true);
|
||||
toolStats.logger.info("Adding enabled.critical-strikes");
|
||||
|
||||
//trident throws
|
||||
toolStats.config.set("enabled.trident-throws", true);
|
||||
toolStats.logger.info("Adding enabled.trident-throws");
|
||||
|
||||
// default for new stats
|
||||
toolStats.logger.info("Adding new default messages");
|
||||
toolStats.config.set("messages.bosses-killed.wither", "&7Withers killed: &8{kills}");
|
||||
toolStats.config.set("messages.bosses-killed.enderdragon", "&7Ender Dragons killed: &8{kills}");
|
||||
toolStats.config.set("messages.critical-strikes", "&7Critical strikes: &8{strikes}");
|
||||
toolStats.config.set("messages.trident-throws", "&7Times thrown: &8{times}");
|
||||
|
||||
// blacklist feature
|
||||
toolStats.logger.info("Adding new world-limit feature, which is disabled by default");
|
||||
List<String> worlds = Arrays.asList("world_1", "world_2");
|
||||
toolStats.config.set("world-limit.enabled", false);
|
||||
toolStats.config.set("world-limit.mode", "blacklist");
|
||||
toolStats.config.set("world-limit.worlds", worlds);
|
||||
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 15. A copy of version 14 has been saved as config-14.yml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Version16 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 15 to 16.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version16(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the config update.
|
||||
*/
|
||||
public void update() {
|
||||
// save the old config first
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-15.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config-15.yml!", exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
toolStats.logger.info("Updating config.yml to version 16.");
|
||||
toolStats.config.set("config-version", 16);
|
||||
|
||||
toolStats.logger.info("Adding enabled.crafted-on.shield to config.yml.");
|
||||
toolStats.config.set("enabled.crafted-on.shield", true);
|
||||
toolStats.logger.info("Adding enabled.crafted-by.shield to config.yml.");
|
||||
toolStats.config.set("enabled.crafted-by.shield", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.traded-on.shield to config.yml.");
|
||||
toolStats.config.set("enabled.traded-on.shield", true);
|
||||
toolStats.logger.info("Adding enabled.traded-by.shield to config.yml.");
|
||||
toolStats.config.set("enabled.traded-by.shield", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.looted-on.shield to config.yml.");
|
||||
toolStats.config.set("enabled.looted-on.shield", true);
|
||||
toolStats.logger.info("Adding enabled.looted-by.shield to config.yml.");
|
||||
toolStats.config.set("enabled.looted-by.shield", true);
|
||||
|
||||
// save the config and reload it
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 16. A copy of version 6 has been saved as config-15.yml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class Version17 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 16 to 17.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version17(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the config update.
|
||||
*/
|
||||
public void update() {
|
||||
// save the old config first
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-16.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config-16.yml!", exception);
|
||||
}
|
||||
|
||||
toolStats.logger.info("Updating config.yml to version 17.");
|
||||
toolStats.config.set("config-version", 17);
|
||||
|
||||
toolStats.logger.info("Adding new token to config: logs-stripped");
|
||||
toolStats.config.set("tokens.data.logs-stripped.title", "&7ToolStats: &8Logs Stripped Token");
|
||||
toolStats.config.set("tokens.data.logs-stripped.lore", List.of(
|
||||
"&8Combine with an axe in an anvil to track logs stripped.",
|
||||
"&8Uses &7{levels} &8level."
|
||||
));
|
||||
toolStats.config.set("tokens.data.logs-stripped.levels", 1);
|
||||
toolStats.config.set("tokens.data.logs-stripped.material", "PAPER");
|
||||
|
||||
toolStats.config.set("tokens.data.logs-stripped.custom-model-data.enabled", false);
|
||||
toolStats.config.set("tokens.data.logs-stripped.custom-model-data.type", "float");
|
||||
toolStats.config.set("tokens.data.logs-stripped.custom-model-data.value", 1001);
|
||||
|
||||
toolStats.logger.info("Adding enabled.logs-stripped");
|
||||
toolStats.config.set("enabled.logs-stripped", true);
|
||||
|
||||
toolStats.logger.info("Adding messages.logs-stripped");
|
||||
toolStats.config.set("messages.logs-stripped", "&7Logs stripped: &8{logs}");
|
||||
|
||||
|
||||
// save the config and reload it
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.error("Unable to save config.yml!", exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 17. A copy of version 16 has been saved as config-16.yml");
|
||||
}
|
||||
}
|
||||
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version6.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version6.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version7.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version7.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version8.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version8.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version9.java
Normal file → Executable file
0
src/main/java/lol/hyper/toolstats/tools/config/versions/Version9.java
Normal file → Executable file
93
src/main/resources/config.yml
Normal file → Executable file
93
src/main/resources/config.yml
Normal file → Executable file
@@ -136,6 +136,61 @@ tokens:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
wither-kills:
|
||||
title: "&7ToolStats: &8Wither Kills Token"
|
||||
lore:
|
||||
- "&8Combine with a melee or ranged weapon in an anvil to track wither kills."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
enderdragon-kills:
|
||||
title: "&7ToolStats: &8Ender Dragon Kills Token"
|
||||
lore:
|
||||
- "&8Combine with a melee or ranged weapon in an anvil to track Ender Dragon kills."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
critical-strikes:
|
||||
title: "&7ToolStats: &8Critical Strikes Token"
|
||||
lore:
|
||||
- "&8Combine with a melee or ranged weapon in an anvil to track critical strikes."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
trident-throws:
|
||||
title: "&7ToolStats: &8Trident Throws Token"
|
||||
lore:
|
||||
- "&8Combine with a trident in an anvil to track times thrown."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
logs-stripped:
|
||||
title: "&7ToolStats: &8Logs Stripped Token"
|
||||
lore:
|
||||
- "&8Combine with an axe in an anvil to track logs stripped."
|
||||
- "&8Uses &7{levels} &8level."
|
||||
levels: 1
|
||||
material: PAPER
|
||||
custom-model-data:
|
||||
enabled: false
|
||||
type: float
|
||||
value: 1001
|
||||
|
||||
enabled:
|
||||
# Will show "Crafted by <player>"
|
||||
@@ -150,6 +205,8 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
shield: true
|
||||
# Will show "Crafted on <date>"
|
||||
crafted-on:
|
||||
pickaxe: true
|
||||
@@ -162,6 +219,8 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
shield: true
|
||||
# Will show "Fished by <player>"
|
||||
fished-by:
|
||||
pickaxe: true
|
||||
@@ -195,6 +254,8 @@ enabled:
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
shield: true
|
||||
# Will show "Found on <date>"
|
||||
looted-on:
|
||||
pickaxe: true
|
||||
@@ -206,6 +267,8 @@ enabled:
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
shield: true
|
||||
# Will show "Traded by <player>"
|
||||
traded-by:
|
||||
pickaxe: true
|
||||
@@ -217,6 +280,7 @@ enabled:
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
shield: true
|
||||
# Will show "Traded on <date>"
|
||||
traded-on:
|
||||
pickaxe: true
|
||||
@@ -228,24 +292,28 @@ enabled:
|
||||
bow: true
|
||||
armor: true
|
||||
fishing-rod: true
|
||||
shield: true
|
||||
damage-done:
|
||||
sword: true
|
||||
axe: true
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
spear: true
|
||||
player-kills:
|
||||
sword: true
|
||||
axe: true
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
spear: true
|
||||
mob-kills:
|
||||
sword: true
|
||||
axe: true
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
spear: true
|
||||
blocks-mined:
|
||||
pickaxe: true
|
||||
shovel: true
|
||||
@@ -264,6 +332,7 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
# Will show "Spawned in on <date>"
|
||||
spawned-in-on:
|
||||
pickaxe: true
|
||||
@@ -276,6 +345,10 @@ enabled:
|
||||
armor: true
|
||||
mace: true
|
||||
fishing-rod: true
|
||||
spear: true
|
||||
bosses-killed:
|
||||
wither: true
|
||||
enderdragon: true
|
||||
fish-caught: true
|
||||
sheep-sheared: true
|
||||
armor-damage: true
|
||||
@@ -285,6 +358,9 @@ enabled:
|
||||
arrows-shot: true
|
||||
flight-time: true
|
||||
crops-harvested: true
|
||||
critical-strikes: true
|
||||
trident-throws: true
|
||||
logs-stripped: true
|
||||
|
||||
messages:
|
||||
crafted:
|
||||
@@ -308,6 +384,9 @@ messages:
|
||||
spawned-in:
|
||||
spawned-by: "&7Spawned in by: &8{player}"
|
||||
spawned-on: "&7Spawned on: &8{date}"
|
||||
bosses-killed:
|
||||
wither: "&7Withers killed: &8{kills}"
|
||||
enderdragon: "&7Ender Dragons killed: &8{kills}"
|
||||
blocks-mined: "&7Blocks mined: &8{blocks}"
|
||||
crops-harvested: "&7Crops harvested: &8{crops}"
|
||||
sheep-sheared: "&7Sheep sheared: &8{sheep}"
|
||||
@@ -317,6 +396,9 @@ messages:
|
||||
arrows-shot: "&7Arrows shot: &8{arrows}"
|
||||
flight-time: "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s"
|
||||
damage-done: "&7Damage done: &8{damage}"
|
||||
critical-strikes: "&7Critical strikes: &8{strikes}"
|
||||
trident-throws: "&7Times thrown: &8{times}"
|
||||
logs-stripped: "&7Logs stripped: &8{logs}"
|
||||
# Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
|
||||
mobs:
|
||||
ZOMBIE: "Zombie"
|
||||
@@ -346,4 +428,13 @@ normalize-time-creation: false
|
||||
# Allows stats and origins to be tracked if the player is in creative mode.
|
||||
allow-creative: false
|
||||
|
||||
config-version: 13
|
||||
# Allows you to change what worlds ToolStats works in.
|
||||
# Mode is blacklist or whitelist.
|
||||
world-limit:
|
||||
enabled: false
|
||||
mode: "blacklist"
|
||||
worlds:
|
||||
- world_1
|
||||
- world_2
|
||||
|
||||
config-version: 17
|
||||
@@ -1,34 +1,26 @@
|
||||
name: ToolStats
|
||||
version: '${project.version}'
|
||||
version: ${version}
|
||||
main: lol.hyper.toolstats.ToolStats
|
||||
api-version: 1.21
|
||||
api-version: '26.1.1'
|
||||
folia-supported: true
|
||||
author: hyperdefined
|
||||
description: Track various tool stats!
|
||||
website: https://github.com/hyperdefined/ToolStats
|
||||
folia-supported: true
|
||||
commands:
|
||||
toolstats:
|
||||
usage: /toolstats
|
||||
permission: toolstats.command
|
||||
|
||||
loader: lol.hyper.toolstats.ToolStatsLoader
|
||||
|
||||
permissions:
|
||||
toolstats.command:
|
||||
description: Allows the usage of /toolstats.
|
||||
default: true
|
||||
children:
|
||||
toolstats.reset: true
|
||||
toolstats.reset.confirm: true
|
||||
toolstats.purge: true
|
||||
toolstats.purge.confirm: true
|
||||
toolstats.reload:
|
||||
description: Allows the usage of /toolstats reload.
|
||||
default: op
|
||||
toolstats.reset:
|
||||
description: Allows the usage of /toolstats reset.
|
||||
default: true
|
||||
toolstats.reset.confirm:
|
||||
description: Allows the usage of /toolstats reset confirm.
|
||||
default: true
|
||||
toolstats.purge:
|
||||
description: Allows the usage of /toolstats purge.
|
||||
default: true
|
||||
toolstats.purge.confirm:
|
||||
description: Allows the usage of /toolstats purge confirm.
|
||||
default: true
|
||||
toolstats.givetokens:
|
||||
description: Allows the usage of /toolstats givetoken.
|
||||
default: op
|
||||
@@ -38,3 +30,9 @@ permissions:
|
||||
toolstats.remove:
|
||||
description: Allows the usage of /toolstats remove.
|
||||
default: op
|
||||
|
||||
dependencies:
|
||||
server:
|
||||
RoseStacker:
|
||||
load: BEFORE
|
||||
required: false
|
||||
Reference in New Issue
Block a user