Initial commit
This commit is contained in:
commit
ada4c7789d
118
.gitignore
vendored
Normal file
118
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
.gradle
|
||||
build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
**/build/
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
49
build.gradle.kts
Normal file
49
build.gradle.kts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
id("com.github.johnrengelman.shadow") version "7.1.0"
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
group = "com.alttd"
|
||||
version = "1.0-SNAPSHOT"
|
||||
description = "Altitude's Transfer Items plugin"
|
||||
|
||||
apply<JavaLibraryPlugin>()
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
withType<JavaCompile> {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
|
||||
withType<Javadoc> {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
dependsOn(getByName("relocateJars") as ConfigureShadowRelocation)
|
||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
minimize()
|
||||
configurations = listOf(project.configurations.shadow.get())
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
create<ConfigureShadowRelocation>("relocateJars") {
|
||||
target = shadowJar.get()
|
||||
prefix = "${project.name}.lib"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.alttd:Galaxy-API:1.19-R0.1-SNAPSHOT")
|
||||
}
|
||||
0
gradle.properties
Normal file
0
gradle.properties
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
185
gradlew
vendored
Normal file
185
gradlew
vendored
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 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
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
89
gradlew.bat
vendored
Normal file
89
gradlew.bat
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
18
settings.gradle.kts
Normal file
18
settings.gradle.kts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
rootProject.name = "PlayerUtils"
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven("https://dev.alttd.com/snapshots") // Altitude - Galaxy
|
||||
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
||||
maven("'https://jitpack.io'") // Vault
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
30
src/main/java/com/alttd/playerutils/PlayerUtils.java
Normal file
30
src/main/java/com/alttd/playerutils/PlayerUtils.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package com.alttd.playerutils;
|
||||
|
||||
import com.alttd.playerutils.commands.PlayerUtilsCommand;
|
||||
import com.alttd.playerutils.event_listeners.XpBottleEvent;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class PlayerUtils extends JavaPlugin {
|
||||
|
||||
private Logger logger;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.logger = new Logger(getLogger());
|
||||
registerCommands();
|
||||
registerEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
new PlayerUtilsCommand(this, logger);
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
getServer().getPluginManager().registerEvents(new XpBottleEvent(this, logger), this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
package com.alttd.playerutils.commands;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.Glow;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.XPCheque;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import org.bukkit.command.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayerUtilsCommand implements CommandExecutor, TabExecutor {
|
||||
private final List<SubCommand> subCommands;
|
||||
|
||||
public PlayerUtilsCommand(PlayerUtils playerUtils, Logger logger) {
|
||||
PluginCommand command = playerUtils.getCommand("playerutils");
|
||||
if (command == null) {
|
||||
subCommands = null;
|
||||
logger.severe("Unable to find transfer command.");
|
||||
return;
|
||||
}
|
||||
command.setExecutor(this);
|
||||
command.setTabCompleter(this);
|
||||
command.setAliases(List.of("pu"));
|
||||
|
||||
subCommands = Arrays.asList(
|
||||
new Glow(),
|
||||
new XPCheque(playerUtils)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
commandSender.sendMiniMessage(Messages.HELP.HELP_MESSAGE_WRAPPER.replaceAll("<commands>", subCommands.stream()
|
||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getHelpMessage)
|
||||
.collect(Collectors.joining("\n"))), null);
|
||||
return true;
|
||||
}
|
||||
|
||||
SubCommand subCommand = getSubCommand(args[0]);
|
||||
if (subCommand == null)
|
||||
return false;
|
||||
|
||||
if (!commandSender.hasPermission(subCommand.getPermission())) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.NO_PERMISSION, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean executedCorrectly = subCommand.onCommand(commandSender, args);
|
||||
if (!executedCorrectly) {
|
||||
commandSender.sendMiniMessage(subCommand.getHelpMessage(), null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String cmd, @NotNull String[] args) {
|
||||
List<String> res = new ArrayList<>();
|
||||
|
||||
if (args.length <= 1) {
|
||||
res.addAll(subCommands.stream()
|
||||
.filter(subCommand -> commandSender.hasPermission(subCommand.getPermission()))
|
||||
.map(SubCommand::getName)
|
||||
.filter(name -> args.length == 0 || name.startsWith(args[0]))
|
||||
.toList()
|
||||
);
|
||||
} else {
|
||||
SubCommand subCommand = getSubCommand(args[0]);
|
||||
if (subCommand != null && commandSender.hasPermission(subCommand.getPermission()))
|
||||
res.addAll(subCommand.getTabComplete(commandSender, args).stream()
|
||||
.filter(str -> str.toLowerCase().startsWith(args[args.length - 1].toLowerCase()))
|
||||
.toList());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
|
||||
private SubCommand getSubCommand(String cmdName) {
|
||||
return subCommands.stream()
|
||||
.filter(subCommand -> subCommand.getName().equals(cmdName))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
22
src/main/java/com/alttd/playerutils/commands/SubCommand.java
Normal file
22
src/main/java/com/alttd/playerutils/commands/SubCommand.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package com.alttd.playerutils.commands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SubCommand {
|
||||
|
||||
public SubCommand() {}
|
||||
|
||||
public abstract boolean onCommand(CommandSender commandSender, String[] args);
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public String getPermission() {
|
||||
return "playerutils." + getName();
|
||||
}
|
||||
|
||||
public abstract List<String> getTabComplete(CommandSender commandSender, String[] args);
|
||||
|
||||
public abstract String getHelpMessage();
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package com.alttd.playerutils.commands.playerutils_subcommands;
|
||||
|
||||
import com.alttd.playerutils.commands.SubCommand;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Glow extends SubCommand {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.PLAYER_ONLY, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("off")) {
|
||||
commandSender.sendMiniMessage(Messages.GLOW.GLOW_OFF, null);
|
||||
player.setGlowing(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<DyeColor> any = Arrays.stream(DyeColor.values()).filter(chatColor -> chatColor.name().equalsIgnoreCase(args[1])).findAny();
|
||||
if (any.isEmpty()) {
|
||||
commandSender.sendMiniMessage(getHelpMessage(), null);
|
||||
return true;
|
||||
}
|
||||
|
||||
DyeColor dyeColor = any.get();
|
||||
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
|
||||
Team team = board.getTeam("Glow " + dyeColor.name());
|
||||
|
||||
if (team == null) {
|
||||
team = board.registerNewTeam("Glow " + dyeColor.name());
|
||||
}
|
||||
|
||||
if (!team.hasEntry(player.getName())) {
|
||||
team.addEntry(player.getName());
|
||||
}
|
||||
|
||||
NamedTextColor namedTextColor = NamedTextColor.nearestTo(TextColor.color(dyeColor.getColor().asRGB()));
|
||||
team.color(namedTextColor);
|
||||
|
||||
player.setGlowing(true);
|
||||
commandSender.sendMiniMessage(Messages.GLOW.GLOW_ON, Placeholder.parsed("color", dyeColor.name()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "glow";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
if (args.length == 2) {
|
||||
return Arrays.stream(DyeColor.values()).map(Enum::name).collect(Collectors.toList());
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Messages.HELP.GLOW;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
package com.alttd.playerutils.commands.playerutils_subcommands;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.commands.SubCommand;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class XPCheque extends SubCommand {
|
||||
|
||||
private final PlayerUtils playerUtils;
|
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public XPCheque(PlayerUtils playerUtils) {
|
||||
this.playerUtils = playerUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.PLAYER_ONLY, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 2)
|
||||
return false;
|
||||
|
||||
int xpValue;
|
||||
try {
|
||||
xpValue = Integer.parseInt(args[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int totalExperience = player.getTotalExperience();
|
||||
if (totalExperience < xpValue) {
|
||||
commandSender.sendMiniMessage(Messages.XP_CHEQUE.NOT_ENOUGH_XP, Placeholder.parsed("xp", String.valueOf(totalExperience)));
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
if (!heldItem.getType().equals(Material.GLASS_BOTTLE)) {
|
||||
commandSender.sendMiniMessage(Messages.XP_CHEQUE.NOT_HOLDING_BOTTLE, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<ItemStack> optionalItemStack = getExpBottleItem(player, xpValue);
|
||||
if (optionalItemStack.isEmpty())
|
||||
return true;
|
||||
|
||||
ItemStack xpBottle = optionalItemStack.get();
|
||||
|
||||
decreaseExperience(player, xpValue);
|
||||
|
||||
if (heldItem.getAmount() == 1) {
|
||||
player.getInventory().setItemInMainHand(xpBottle);
|
||||
player.updateInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
heldItem.setAmount(heldItem.getAmount() - 1);
|
||||
player.getInventory().addItem(xpBottle).values()
|
||||
.forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
|
||||
player.updateInventory();
|
||||
return true;
|
||||
}
|
||||
|
||||
private Optional<ItemStack> getExpBottleItem(Player player, int xpValue) {
|
||||
ItemStack expBottle = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
||||
ItemMeta itemMeta = expBottle.getItemMeta();
|
||||
PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer();
|
||||
NamespacedKey customXp = NamespacedKey.fromString("custom_xp", playerUtils);
|
||||
|
||||
if (customXp == null) {
|
||||
player.sendMiniMessage(Messages.XP_CHEQUE.FAILED_STORAGE, null);
|
||||
return Optional.empty();
|
||||
}
|
||||
persistentDataContainer.set(customXp, PersistentDataType.INTEGER, xpValue);
|
||||
itemMeta.displayName(miniMessage.deserialize(Messages.XP_CHEQUE.DISPLAY_NAME, Placeholder.parsed("xp", String.valueOf(xpValue))));
|
||||
itemMeta.lore(Messages.XP_CHEQUE.LORE.stream()
|
||||
.map(str -> miniMessage.deserialize(str, Placeholder.component("name", player.displayName())))
|
||||
.collect(Collectors.toList()));
|
||||
expBottle.setItemMeta(itemMeta);
|
||||
return Optional.of(expBottle);
|
||||
}
|
||||
|
||||
public void decreaseExperience(Player player, int xpToRemove) {
|
||||
// int oldLevel = player.getLevel();
|
||||
// float oldExp = player.getExp();
|
||||
// int newTotalExp = Math.max(player.getTotalExperience() - xpToRemove, 0);
|
||||
//
|
||||
// player.setTotalExperience(newTotalExp);
|
||||
//
|
||||
// int newLevel = player.getLevel();
|
||||
// float newExp = player.getExp();
|
||||
// float progressDiff = newExp - oldExp;
|
||||
//
|
||||
// if (newLevel < oldLevel) {
|
||||
// progressDiff += 1;
|
||||
// player.sendExperienceChange(-progressDiff, newLevel - oldLevel);
|
||||
// } else
|
||||
// player.sendExperienceChange(progressDiff, newLevel - oldLevel);
|
||||
|
||||
int totalExp = player.getTotalExperience();
|
||||
int newTotalExp = Math.max(totalExp - xpToRemove, 0);
|
||||
|
||||
int level = 0;
|
||||
while (true) {
|
||||
int expToNextLevel = getExpToNext(level);
|
||||
if (newTotalExp < expToNextLevel)
|
||||
break;
|
||||
newTotalExp -= expToNextLevel;
|
||||
level++;
|
||||
}
|
||||
|
||||
float progress = (float) newTotalExp / getExpToNext(level);
|
||||
|
||||
player.setTotalExperience(totalExp - xpToRemove);
|
||||
player.setLevel(level);
|
||||
player.setExp(progress);
|
||||
}
|
||||
|
||||
public int getExpToNext(int level) {
|
||||
if (level <= 15) {
|
||||
return 2 * level + 7;
|
||||
} else if (level <= 30) {
|
||||
return 5 * level - 38;
|
||||
} else {
|
||||
return 9 * level - 158;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "xpcheque";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Messages.HELP.XP_CHEQUE;
|
||||
}
|
||||
}
|
||||
153
src/main/java/com/alttd/playerutils/config/AbstractConfig.java
Normal file
153
src/main/java/com/alttd/playerutils/config/AbstractConfig.java
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings({"unused", "SameParameterValue"})
|
||||
abstract class AbstractConfig {
|
||||
File file;
|
||||
YamlConfiguration yaml;
|
||||
private static Logger logger = null;
|
||||
|
||||
AbstractConfig(PlayerUtils playerUtils, String filename, Logger logger) {
|
||||
AbstractConfig.logger = logger;
|
||||
init(new File(playerUtils.getDataFolder(), filename), filename);
|
||||
}
|
||||
|
||||
AbstractConfig(File file, String filename, Logger logger) {
|
||||
AbstractConfig.logger = logger;
|
||||
init(new File(file.getPath() + File.separator + filename), filename);
|
||||
}
|
||||
|
||||
private void init(File file, String filename) {
|
||||
this.file = file;
|
||||
this.yaml = new YamlConfiguration();
|
||||
try {
|
||||
yaml.load(file);
|
||||
} catch (IOException ignore) {
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
if (logger != null)
|
||||
logger.severe(String.format("Could not load %s, please correct your syntax errors", filename));
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
yaml.options().copyDefaults(true);
|
||||
}
|
||||
|
||||
void readConfig(Class<?> clazz, Object instance) {
|
||||
for (Class<?> declaredClass : clazz.getDeclaredClasses()) {
|
||||
for (Method method : declaredClass.getDeclaredMethods()) {
|
||||
if (Modifier.isPrivate(method.getModifiers())) {
|
||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex.getCause());
|
||||
} catch (Exception ex) {
|
||||
if (logger != null)
|
||||
logger.severe("Error invoking %.", method.toString());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
private void save() {
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException ex) {
|
||||
if (logger != null)
|
||||
logger.severe("Could not save %.", file.toString());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void set(String prefix, String path, Object val) {
|
||||
path = prefix + path;
|
||||
yaml.addDefault(path, val);
|
||||
yaml.set(path, val);
|
||||
save();
|
||||
}
|
||||
|
||||
String getString(String prefix, String path, String def) {
|
||||
path = prefix + path;
|
||||
yaml.addDefault(path, def);
|
||||
return yaml.getString(path, yaml.getString(path));
|
||||
}
|
||||
|
||||
boolean getBoolean(String prefix, String path, boolean def) {
|
||||
path = prefix + path;
|
||||
yaml.addDefault(path, def);
|
||||
return yaml.getBoolean(path, yaml.getBoolean(path));
|
||||
}
|
||||
|
||||
int getInt(String prefix, String path, int def) {
|
||||
path = prefix + path;
|
||||
yaml.addDefault(path, def);
|
||||
return yaml.getInt(path, yaml.getInt(path));
|
||||
}
|
||||
|
||||
double getDouble(String prefix, String path, double def) {
|
||||
path = prefix + path;
|
||||
yaml.addDefault(path, def);
|
||||
return yaml.getDouble(path, yaml.getDouble(path));
|
||||
}
|
||||
|
||||
<T> List<String> getList(String prefix, String path, T def) {
|
||||
path = prefix + path;
|
||||
yaml.addDefault(path, def);
|
||||
List<?> list = yaml.getList(path, yaml.getList(path));
|
||||
return list == null ? null : list.stream().map(Object::toString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<String> getStringList(String prefix, String path, List<String> def) {
|
||||
path = prefix + path;
|
||||
yaml.addDefault(path, def);
|
||||
return yaml.getStringList(path);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
<T> Map<String, T> getMap(String prefix, @NonNull String path, final @Nullable Map<String, T> def) {
|
||||
path = prefix + path;
|
||||
final ImmutableMap.Builder<String, T> builder = ImmutableMap.builder();
|
||||
if (def != null && yaml.getConfigurationSection(path) == null) {
|
||||
yaml.addDefault(path, def.isEmpty() ? new HashMap<>() : def);
|
||||
return def;
|
||||
}
|
||||
final ConfigurationSection section = yaml.getConfigurationSection(path);
|
||||
if (section != null) {
|
||||
for (String key : section.getKeys(false)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final T val = (T) section.get(key);
|
||||
if (val != null) {
|
||||
builder.put(key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
ConfigurationSection getConfigurationSection(String path) {
|
||||
return yaml.getConfigurationSection(path);
|
||||
}
|
||||
}
|
||||
33
src/main/java/com/alttd/playerutils/config/Config.java
Normal file
33
src/main/java/com/alttd/playerutils/config/Config.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
|
||||
public class Config extends AbstractConfig{
|
||||
|
||||
static Config config;
|
||||
private Logger logger;
|
||||
|
||||
Config(PlayerUtils playerUtils, Logger logger) {
|
||||
super(playerUtils, "config.yml", logger);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public static void reload(PlayerUtils playerUtils, Logger logger) {
|
||||
logger.info("Reloading config");
|
||||
config = new Config(playerUtils, logger);
|
||||
config.readConfig(Config.class, null);
|
||||
}
|
||||
|
||||
public static class SETTINGS {
|
||||
private static final String prefix = "settings.";
|
||||
public static boolean DEBUG = false;
|
||||
public static boolean WARNINGS = true;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
DEBUG = config.getBoolean(prefix, "debug", DEBUG);
|
||||
WARNINGS = config.getBoolean(prefix, "warnings", WARNINGS);
|
||||
}
|
||||
}
|
||||
}
|
||||
83
src/main/java/com/alttd/playerutils/config/Messages.java
Normal file
83
src/main/java/com/alttd/playerutils/config/Messages.java
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Messages extends AbstractConfig {
|
||||
static Messages config;
|
||||
private final Logger logger;
|
||||
|
||||
Messages(PlayerUtils playerUtils, Logger logger) {
|
||||
super(playerUtils, "config.yml", logger);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public static void reload(PlayerUtils playerUtils, Logger logger) {
|
||||
config = new Messages(playerUtils, logger);
|
||||
config.readConfig(Messages.class, null);
|
||||
}
|
||||
|
||||
public static class HELP {
|
||||
private static final String prefix = "help.";
|
||||
|
||||
public static String HELP_MESSAGE_WRAPPER = "<gold>PlayerUtils help:\n<commands></gold>";
|
||||
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/pu help</gold></green>";
|
||||
public static String GLOW = "<green>Glow in a specified color: <gold>/pu glow <color></gold></green>";
|
||||
public static String XP_CHEQUE = "<green>Create an xp cheque: <gold>/pu xpcheque <amount></gold></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
HELP_MESSAGE_WRAPPER = config.getString(prefix, "help-wrapper", HELP_MESSAGE_WRAPPER);
|
||||
HELP_MESSAGE = config.getString(prefix, "help", HELP_MESSAGE);
|
||||
GLOW = config.getString(prefix, "glow", GLOW);
|
||||
XP_CHEQUE = config.getString(prefix, "xp-cheque", XP_CHEQUE);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GENERIC {
|
||||
private static final String prefix = "generic.";
|
||||
|
||||
public static String NO_PERMISSION = "<red>You don't have permission for this command</red>";
|
||||
public static String PLAYER_ONLY = "<red>This command can only be executed as a player</red>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
NO_PERMISSION = config.getString(prefix, "no-permission", NO_PERMISSION);
|
||||
PLAYER_ONLY = config.getString(prefix, "player-only", PLAYER_ONLY);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GLOW {
|
||||
private static final String prefix = "pu-command.glow";
|
||||
|
||||
public static String GLOW_OFF = "<green>Glow turned off</green>";
|
||||
public static String GLOW_ON = "<green>Glow turned on, you are now glowing <color></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
GLOW_OFF = config.getString(prefix, "glow-off",GLOW_OFF);
|
||||
GLOW_ON = config.getString(prefix, "glow-on",GLOW_ON);
|
||||
}
|
||||
}
|
||||
|
||||
public static class XP_CHEQUE {
|
||||
private static final String prefix = "pu-command.xp-cheque.";
|
||||
|
||||
public static String FAILED_STORAGE = "<red>Unable to create custom item for xp cheque</red>";
|
||||
public static String NOT_ENOUGH_XP = "<red>Not enough xp, you have <xp></red>";
|
||||
public static String NOT_HOLDING_BOTTLE = "<red>You need to hold an empty glass bottle while executing this command</red>";
|
||||
public static String DISPLAY_NAME = "<yellow>Xp bottle containing <xp> xp</yellow>";
|
||||
public static List<String> LORE = List.of("Issued by <name>", "Throw to retrieve xp");
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
FAILED_STORAGE = config.getString(prefix, "failed-storage", FAILED_STORAGE);
|
||||
NOT_ENOUGH_XP = config.getString(prefix, "not-enough-xp", NOT_ENOUGH_XP);
|
||||
NOT_HOLDING_BOTTLE = config.getString(prefix, "not-holding-bottle", NOT_HOLDING_BOTTLE);
|
||||
DISPLAY_NAME = config.getString(prefix, "display-name", DISPLAY_NAME);
|
||||
LORE = config.getStringList(prefix, "lore", LORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.ExpBottleEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class XpBottleEvent implements Listener {
|
||||
|
||||
private final PlayerUtils playerUtils;
|
||||
private final Logger logger;
|
||||
|
||||
public XpBottleEvent(PlayerUtils playerUtils, Logger logger) {
|
||||
this.playerUtils = playerUtils;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExpBottle(ExpBottleEvent event) {
|
||||
ItemStack item = event.getEntity().getItem();
|
||||
PersistentDataContainer persistentDataContainer = item.getItemMeta().getPersistentDataContainer();
|
||||
NamespacedKey customXp = NamespacedKey.fromString("custom_xp", playerUtils);
|
||||
if (customXp == null) {
|
||||
logger.warning("Unable to retrieve name spaced key.");
|
||||
return;
|
||||
}
|
||||
Integer integer = persistentDataContainer.get(customXp, PersistentDataType.INTEGER);
|
||||
if (integer == null) {
|
||||
return;
|
||||
}
|
||||
event.setExperience(integer);
|
||||
}
|
||||
|
||||
}
|
||||
42
src/main/java/com/alttd/playerutils/util/Logger.java
Normal file
42
src/main/java/com/alttd/playerutils/util/Logger.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package com.alttd.playerutils.util;
|
||||
|
||||
import com.alttd.playerutils.config.Config;
|
||||
|
||||
public class Logger {
|
||||
|
||||
private final java.util.logging.Logger logger;
|
||||
static private final String RESET = "\u001B[0m";
|
||||
static private final String GREEN = "\u001B[32m";
|
||||
static private final String TEAL = "\u001B[36m";
|
||||
|
||||
public Logger(java.util.logging.Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void debug(String debug, String... variables) {
|
||||
if (!Config.SETTINGS.DEBUG)
|
||||
return;
|
||||
logger.info(TEAL + replace(debug, variables) + RESET);
|
||||
}
|
||||
|
||||
public void info(String info, String... variables) {
|
||||
logger.info(GREEN + replace(info, variables) + RESET);
|
||||
}
|
||||
|
||||
public void warning(String warning, String... variables) {
|
||||
if (!Config.SETTINGS.WARNINGS)
|
||||
return;
|
||||
logger.warning(replace(warning, variables));
|
||||
}
|
||||
|
||||
public void severe(String severe, String... variables) {
|
||||
logger.severe(replace(severe, variables));
|
||||
}
|
||||
|
||||
private String replace(String text, String... variables) {
|
||||
for (String variable : variables) {
|
||||
text = text.replaceFirst("%", variable);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
11
src/main/resources/plugin.yml
Normal file
11
src/main/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
name: PlayerUtils
|
||||
version: '${version}'
|
||||
main: com.alttd.playerutils.PlayerUtils
|
||||
api-version: '1.20'
|
||||
commands:
|
||||
playerutils:
|
||||
description: Base command for player utils
|
||||
permission: playerutils.use
|
||||
usage: /playerutils
|
||||
aliases:
|
||||
- pu
|
||||
Loading…
Reference in New Issue
Block a user