Initial commit
This commit is contained in:
commit
816af4d421
42
.gitignore
vendored
Normal file
42
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Plugin
|
||||||
|
.idea
|
||||||
|
testserver
|
||||||
|
run
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Maven
|
||||||
|
target/
|
||||||
|
|
||||||
|
# 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*
|
||||||
|
.gradle
|
||||||
|
|
||||||
|
# My Files
|
||||||
|
build.bat
|
||||||
50
build.gradle.kts
Normal file
50
build.gradle.kts
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
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")
|
||||||
|
compileOnly("dev.sergiferry:playernpc:2023.4")
|
||||||
|
}
|
||||||
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
|
||||||
17
settings.gradle.kts
Normal file
17
settings.gradle.kts
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
rootProject.name = "FishingEvent"
|
||||||
|
|
||||||
|
dependencyResolutionManagement {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
||||||
|
maven("https://repo.ranull.com/maven/external/")
|
||||||
|
}
|
||||||
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/main/java/com/alttd/fishingevent/FishingEvent.java
Normal file
45
src/main/java/com/alttd/fishingevent/FishingEvent.java
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.alttd.fishingevent;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.commands.FishCommand;
|
||||||
|
import com.alttd.fishingevent.config.Config;
|
||||||
|
import com.alttd.fishingevent.config.Fishes;
|
||||||
|
import com.alttd.fishingevent.config.Messages;
|
||||||
|
import com.alttd.fishingevent.fish_generator.WaterFishGenerator;
|
||||||
|
import com.alttd.fishingevent.listeners.CatchFish;
|
||||||
|
import com.alttd.fishingevent.points.PointsManagement;
|
||||||
|
import com.alttd.fishingevent.util.Logger;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public final class FishingEvent extends JavaPlugin {
|
||||||
|
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
this.logger = new Logger(getLogger());
|
||||||
|
registerEvents(getServer().getPluginManager());
|
||||||
|
//add a way to stop and start the fishing event and a way to stop all fishing (so 3 modes normal, active, disabled)
|
||||||
|
reloadFishConfigs();
|
||||||
|
registerCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEvents(@NotNull PluginManager pluginManager) {
|
||||||
|
pluginManager.registerEvents(new CatchFish(logger, new WaterFishGenerator(Fishes.WATER_FISH.RARITY_FISH_MAP, logger), PointsManagement.getInstance()), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerCommands() {
|
||||||
|
new FishCommand(this, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadFishConfigs() {
|
||||||
|
Config.reload(this, logger);
|
||||||
|
Fishes.reload(this, logger);
|
||||||
|
Messages.reload(this, logger);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.alttd.fishingevent.commands;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
|
import com.alttd.fishingevent.config.Messages;
|
||||||
|
import com.alttd.fishingevent.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 FishCommand implements CommandExecutor, TabExecutor {
|
||||||
|
private final List<SubCommand> subCommands;
|
||||||
|
|
||||||
|
public FishCommand(FishingEvent fishingEvent, Logger logger) {
|
||||||
|
|
||||||
|
PluginCommand command = fishingEvent.getCommand("fish");
|
||||||
|
if (command == null) {
|
||||||
|
subCommands = null;
|
||||||
|
logger.severe("Unable to find transfer command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
command.setExecutor(this);
|
||||||
|
command.setTabCompleter(this);
|
||||||
|
|
||||||
|
subCommands = Arrays.asList(
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return subCommand.onCommand(commandSender, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.alttd.fishingevent.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 "fish." + getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract List<String> getTabComplete(CommandSender commandSender, String[] args);
|
||||||
|
|
||||||
|
public abstract String getHelpMessage();
|
||||||
|
}
|
||||||
153
src/main/java/com/alttd/fishingevent/config/AbstractConfig.java
Normal file
153
src/main/java/com/alttd/fishingevent/config/AbstractConfig.java
Normal file
|
|
@ -0,0 +1,153 @@
|
||||||
|
package com.alttd.fishingevent.config;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
|
import com.alttd.fishingevent.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(FishingEvent fishingEvent, String filename, Logger logger) {
|
||||||
|
AbstractConfig.logger = logger;
|
||||||
|
init(new File(fishingEvent.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/main/java/com/alttd/fishingevent/config/Config.java
Normal file
49
src/main/java/com/alttd/fishingevent/config/Config.java
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.alttd.fishingevent.config;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import com.alttd.fishingevent.util.Logger;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Config extends AbstractConfig{
|
||||||
|
|
||||||
|
static Config config;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
Config(FishingEvent fishingEvent, Logger logger) {
|
||||||
|
super(fishingEvent, "config.yml", logger);
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload(FishingEvent fishingEvent, Logger logger) {
|
||||||
|
logger.debug("Reloading config [config.yml]");
|
||||||
|
config = new Config(fishingEvent, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RARITY_MULTIPLIERS {
|
||||||
|
private static final String prefix = "rarity-multipliers.";
|
||||||
|
public static HashMap<Rarity, Float> multiplierMap = new HashMap<>();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
multiplierMap.clear();
|
||||||
|
for (Rarity rarity : Rarity.values()) {
|
||||||
|
multiplierMap.put(rarity, (float) config.getDouble(prefix, rarity.configName(), 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
144
src/main/java/com/alttd/fishingevent/config/Fishes.java
Normal file
144
src/main/java/com/alttd/fishingevent/config/Fishes.java
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
package com.alttd.fishingevent.config;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
|
import com.alttd.fishingevent.fish.Fish;
|
||||||
|
import com.alttd.fishingevent.fish.LavaFish;
|
||||||
|
import com.alttd.fishingevent.fish.WaterFish;
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import com.alttd.fishingevent.util.FishConfigHelper;
|
||||||
|
import com.alttd.fishingevent.util.Logger;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class Fishes extends AbstractConfig {
|
||||||
|
|
||||||
|
static Fishes config;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
Fishes(FishingEvent fishingEvent, Logger logger) {
|
||||||
|
super(fishingEvent, "fishes.yml", logger);
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload(FishingEvent fishingEvent, Logger logger) {
|
||||||
|
logger.debug("Reloading config [fishes.yml]");
|
||||||
|
config = new Fishes(fishingEvent, logger);
|
||||||
|
config.readConfig(Fishes.class, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FORMAT {
|
||||||
|
private static final String prefix = "format.";
|
||||||
|
|
||||||
|
public static String DISPLAY_NAME = "<gold><fish_name></gold>";
|
||||||
|
public static List<String> LORE = List.of(
|
||||||
|
"<gray>Length: <gold><length></gold>cm</gray>",
|
||||||
|
"<gray>Caught by: <player></gray>"
|
||||||
|
);
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
DISPLAY_NAME = config.getString(prefix, "display-name", DISPLAY_NAME);
|
||||||
|
LORE = config.getStringList(prefix, "lore", LORE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LAVA_FISH {
|
||||||
|
|
||||||
|
public static List<Fish> FISH = new ArrayList<>();
|
||||||
|
public static HashMap<Rarity, List<Fish>> RARITY_FISH_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
FISH.clear();
|
||||||
|
ConfigurationSection configurationSection = config.getConfigurationSection("lava-fish");
|
||||||
|
if (configurationSection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String key : configurationSection.getKeys(false)) {
|
||||||
|
ConfigurationSection fishSection = configurationSection.getConfigurationSection(key);
|
||||||
|
if (fishSection == null) {
|
||||||
|
config.logger.warning("Invalid lava fish section: " + configurationSection.getCurrentPath() + "." + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
loadLavaFish(fishSection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadLavaFish(ConfigurationSection fishSection) {
|
||||||
|
Optional<Rarity> rarity = FishConfigHelper.getRarity(config.logger, fishSection);
|
||||||
|
if (rarity.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Optional<ItemStack> optionalItemStack = FishConfigHelper.loadFishItem(config.logger, fishSection);
|
||||||
|
if (optionalItemStack.isEmpty()) {
|
||||||
|
config.logger.warning("Invalid lava fish item for " + fishSection.getCurrentPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FISH.add(new LavaFish(
|
||||||
|
(float) fishSection.getDouble("min-length", 0),
|
||||||
|
(float) fishSection.getDouble("max-length", 0),
|
||||||
|
fishSection.getString("fish-name", "default name"),
|
||||||
|
rarity.get(),
|
||||||
|
optionalItemStack.get(),
|
||||||
|
null) //TODO implement particles or make them hardcoded
|
||||||
|
);
|
||||||
|
for (Fish fish : FISH) {
|
||||||
|
RARITY_FISH_MAP.computeIfAbsent(fish.getRarity(), list -> new ArrayList<>()).add(fish);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class WATER_FISH {
|
||||||
|
|
||||||
|
public static List<Fish> FISH = new ArrayList<>();
|
||||||
|
public static HashMap<Rarity, List<Fish>> RARITY_FISH_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
FISH.clear();
|
||||||
|
RARITY_FISH_MAP.clear();
|
||||||
|
ConfigurationSection configurationSection = config.getConfigurationSection("water-fish");
|
||||||
|
if (configurationSection == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String key : configurationSection.getKeys(false)) {
|
||||||
|
ConfigurationSection fishSection = configurationSection.getConfigurationSection(key);
|
||||||
|
if (fishSection == null) {
|
||||||
|
config.logger.warning("Invalid water fish section: " + configurationSection.getCurrentPath() + "." + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
loadWaterFish(fishSection);
|
||||||
|
}
|
||||||
|
for (Fish fish : FISH) {
|
||||||
|
config.logger.debug("Adding fish [%] with rarity [%]", fish.normalFishName(), fish.getRarity().toString());
|
||||||
|
RARITY_FISH_MAP.computeIfAbsent(fish.getRarity(), list -> new ArrayList<>()).add(fish);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadWaterFish(ConfigurationSection fishSection) {
|
||||||
|
Optional<Rarity> rarity = FishConfigHelper.getRarity(config.logger, fishSection);
|
||||||
|
if (rarity.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Optional<ItemStack> optionalItemStack = FishConfigHelper.loadFishItem(config.logger, fishSection);
|
||||||
|
if (optionalItemStack.isEmpty()) {
|
||||||
|
config.logger.warning("Invalid water fish item for " + fishSection.getCurrentPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FISH.add(new WaterFish(
|
||||||
|
(float) fishSection.getDouble("min-length", 0),
|
||||||
|
(float) fishSection.getDouble("max-length", 0),
|
||||||
|
fishSection.getString("fish-name", "default name"),
|
||||||
|
rarity.get(),
|
||||||
|
optionalItemStack.get())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
63
src/main/java/com/alttd/fishingevent/config/Messages.java
Normal file
63
src/main/java/com/alttd/fishingevent/config/Messages.java
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.alttd.fishingevent.config;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
|
import com.alttd.fishingevent.util.Logger;
|
||||||
|
|
||||||
|
public class Messages extends AbstractConfig {
|
||||||
|
static Messages config;
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
Messages(FishingEvent fishingEvent, Logger logger) {
|
||||||
|
super(fishingEvent, "messages.yml", logger);
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reload(FishingEvent fishingEvent, Logger logger) {
|
||||||
|
logger.debug("Reloading config [messages.yml]");
|
||||||
|
config = new Messages(fishingEvent, logger);
|
||||||
|
config.readConfig(Messages.class, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HELP {
|
||||||
|
private static final String prefix = "help.";
|
||||||
|
|
||||||
|
public static String HELP_MESSAGE_WRAPPER = "<gold>Fishing help:\n<commands></gold>";
|
||||||
|
public static String HELP_MESSAGE = "<green>Show this menu: <gold>/fishing help</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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 GUI {
|
||||||
|
private static final String prefix = "gui.";
|
||||||
|
public static String TITLE = "Fishing Event turn in";
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
TITLE = config.getString(prefix, "title", TITLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FISHING_COMMAND {
|
||||||
|
private static final String prefix = "fishing-command.";
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void load() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
70
src/main/java/com/alttd/fishingevent/fish/Fish.java
Normal file
70
src/main/java/com/alttd/fishingevent/fish/Fish.java
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.alttd.fishingevent.fish;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.config.Config;
|
||||||
|
import com.alttd.fishingevent.config.Fishes;
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public abstract class Fish {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an the fish item for a specific player
|
||||||
|
* @param player Player to get the item for
|
||||||
|
* @return ItemStack for that fish item if one exists
|
||||||
|
*/
|
||||||
|
protected abstract ItemStack getFishItem(Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gives back a different result each call, it generates a length based on the min and max length values for a fish
|
||||||
|
* @return a random length for this fish
|
||||||
|
*/
|
||||||
|
public abstract float getLength();
|
||||||
|
|
||||||
|
public abstract Component fishName();
|
||||||
|
|
||||||
|
public abstract String normalFishName();
|
||||||
|
|
||||||
|
protected List<Component> fishLore(TagResolver tagResolver) {
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
return Fishes.FORMAT.LORE.stream()
|
||||||
|
.map(entry -> miniMessage.deserialize(entry, tagResolver))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Rarity getRarity();
|
||||||
|
|
||||||
|
public ItemStack createItem(Player player, double length) {
|
||||||
|
ItemStack fishItem = getFishItem(player);
|
||||||
|
ItemMeta itemMeta = fishItem.getItemMeta();
|
||||||
|
TagResolver resolver = TagResolver.resolver(
|
||||||
|
Placeholder.component("player", player.name()),
|
||||||
|
Placeholder.parsed("length", String.format("%.2f", length)),
|
||||||
|
Placeholder.parsed("rarity", getRarity().displayName())
|
||||||
|
);
|
||||||
|
|
||||||
|
itemMeta.lore(fishLore(resolver));
|
||||||
|
itemMeta.displayName(fishName());
|
||||||
|
|
||||||
|
fishItem.setItemMeta(itemMeta);
|
||||||
|
return fishItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gives back the amount of points for this type of fish with the specified length
|
||||||
|
* @param length The length to calculate points for
|
||||||
|
* @return points based on the length and rarity of this fish
|
||||||
|
*/
|
||||||
|
public int getPoints(float length) {
|
||||||
|
return Math.round(Config.RARITY_MULTIPLIERS.multiplierMap.get(getRarity()) * length);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
61
src/main/java/com/alttd/fishingevent/fish/LavaFish.java
Normal file
61
src/main/java/com/alttd/fishingevent/fish/LavaFish.java
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.alttd.fishingevent.fish;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class LavaFish extends Fish {
|
||||||
|
|
||||||
|
public LavaFish(float minLength, float maxLength, String fishName, Rarity rarity, ItemStack itemStack, ArrayList<Set<Particle>> particles) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getFishItem(Player player) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getLength() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Component fishName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String normalFishName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Rarity getRarity() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spawnParticles(Location location) {
|
||||||
|
//TODO run async function in here
|
||||||
|
//TODO color particles based on rarity?
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean validRod(ItemStack fishingRod) {
|
||||||
|
//TODO check data to see if its a lava rod
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant getSpawnTime(ItemStack fishingRod) {
|
||||||
|
//TODO calc based on rod enchant level and check if the rod is valid maybe?
|
||||||
|
return Instant.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
52
src/main/java/com/alttd/fishingevent/fish/WaterFish.java
Normal file
52
src/main/java/com/alttd/fishingevent/fish/WaterFish.java
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.alttd.fishingevent.fish;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.config.Fishes;
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class WaterFish extends Fish {
|
||||||
|
|
||||||
|
private final float minLength;
|
||||||
|
private final float maxLength;
|
||||||
|
private final String fishName;
|
||||||
|
private final Rarity rarity;
|
||||||
|
private final ItemStack itemStack;
|
||||||
|
|
||||||
|
public WaterFish(float minLength, float maxLength, String fishName, Rarity rarity, ItemStack itemStack) {
|
||||||
|
this.minLength = minLength;
|
||||||
|
this.maxLength = maxLength;
|
||||||
|
this.fishName = fishName;
|
||||||
|
this.rarity = rarity;
|
||||||
|
this.itemStack = itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getFishItem(Player player) {
|
||||||
|
return itemStack.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getLength() {
|
||||||
|
return new Random().nextFloat(minLength, maxLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public net.kyori.adventure.text.@NotNull Component fishName() {
|
||||||
|
return MiniMessage.miniMessage().deserialize(Fishes.FORMAT.DISPLAY_NAME, Placeholder.parsed("fish_name", fishName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String normalFishName() {
|
||||||
|
return fishName;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Rarity getRarity() {
|
||||||
|
return rarity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.alttd.fishingevent.fish_generator;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.fish.Fish;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface FishGenerator {
|
||||||
|
|
||||||
|
Optional<Fish> getFish(ItemStack fishingRod);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.alttd.fishingevent.fish_generator;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.fish.Fish;
|
||||||
|
import com.alttd.fishingevent.objects.CustomRandom;
|
||||||
|
import com.alttd.fishingevent.objects.RandomListItem;
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import com.alttd.fishingevent.util.Logger;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class WaterFishGenerator implements FishGenerator {
|
||||||
|
|
||||||
|
private final HashMap<Rarity, List<Fish>> possibleFishMap;
|
||||||
|
private final RandomListItem<Fish> randomListItem = new RandomListItem<>();
|
||||||
|
private final Logger logger;
|
||||||
|
|
||||||
|
public WaterFishGenerator(HashMap<Rarity, List<Fish>> possibleFishMap, Logger logger) {
|
||||||
|
this.possibleFishMap = possibleFishMap;
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Fish> getFish(ItemStack fishingRod) {
|
||||||
|
if (!fishingRod.getType().equals(Material.FISHING_ROD))
|
||||||
|
return Optional.empty();
|
||||||
|
int luckLevel = fishingRod.getEnchantmentLevel(Enchantment.LUCK);
|
||||||
|
int rarityValue = CustomRandom.generateNumber(0, Rarity.values().length - 1, luckLevel + 1);
|
||||||
|
Rarity rarity = Rarity.values()[rarityValue];
|
||||||
|
List<Fish> fish = possibleFishMap.get(rarity);
|
||||||
|
if (fish == null) {
|
||||||
|
logger.warning("Empty fish map for rarity [%]", rarity.toString());
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return randomListItem.getRandomObject(fish);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
package com.alttd.fishingevent.listeners;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.fish.Fish;
|
||||||
|
import com.alttd.fishingevent.fish_generator.FishGenerator;
|
||||||
|
import com.alttd.fishingevent.points.PointsManagement;
|
||||||
|
import com.alttd.fishingevent.util.Logger;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
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.PlayerFishEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class CatchFish implements Listener {
|
||||||
|
|
||||||
|
private final Logger logger;
|
||||||
|
private final FishGenerator waterFishGenerator;
|
||||||
|
private final PointsManagement pointsManagement;
|
||||||
|
|
||||||
|
public CatchFish(Logger logger, FishGenerator waterFishGenerator, PointsManagement pointsManagement) {
|
||||||
|
this.logger = logger;
|
||||||
|
this.waterFishGenerator = waterFishGenerator;
|
||||||
|
this.pointsManagement = pointsManagement;
|
||||||
|
logger.debug("Registered PlayerFishEvent listener");
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerFish(PlayerFishEvent event) {
|
||||||
|
if (event.getState().equals(PlayerFishEvent.State.FISHING)) {
|
||||||
|
//if fishing rod in lava continue else return
|
||||||
|
// logger.debug("% might have caught a lava fish", event.getPlayer().getName());
|
||||||
|
// handleLavaFishCaught(event);
|
||||||
|
} else if (event.getState().equals(PlayerFishEvent.State.CAUGHT_FISH)) {
|
||||||
|
if (event.getCaught() == null) {
|
||||||
|
logger.debug("% caught a water fish but it was null", event.getPlayer().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.debug("% caught a water fish", event.getPlayer().getName());
|
||||||
|
handleFishCaught(event);
|
||||||
|
} else if (event.getState().equals(PlayerFishEvent.State.IN_GROUND)) {
|
||||||
|
logger.debug("% reeled in fishing rod that was in the ground", event.getPlayer().getName());
|
||||||
|
handleLavaFishCaught(event);
|
||||||
|
} else {
|
||||||
|
logger.debug("Registered different fish state [%]", event.getState().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleLavaFish(PlayerFishEvent event) {
|
||||||
|
Location location = event.getHook().getLocation();
|
||||||
|
Block block = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ());
|
||||||
|
if (!block.isLiquid())
|
||||||
|
return;
|
||||||
|
//TODO get fish and start timer for it
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleLavaFishCaught(PlayerFishEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleFishCaught(PlayerFishEvent event) {
|
||||||
|
Entity caught = event.getCaught();
|
||||||
|
if (!(caught instanceof Item item)) {
|
||||||
|
logger.debug("% did not catch an item", event.getPlayer().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ItemStack activeItem = player.getInventory().getItemInMainHand();
|
||||||
|
if (!activeItem.getType().equals(Material.FISHING_ROD))
|
||||||
|
activeItem = player.getInventory().getItemInOffHand();
|
||||||
|
Optional<Fish> optionalFish = waterFishGenerator.getFish(activeItem);
|
||||||
|
if (optionalFish.isEmpty()) {
|
||||||
|
logger.warning("Unable to get water fish for %", event.getPlayer().getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Fish fish = optionalFish.get();
|
||||||
|
|
||||||
|
float length = fish.getLength();
|
||||||
|
item.setItemStack(fish.createItem(player, length));
|
||||||
|
int addedPoints = pointsManagement.caughtFish(player.getUniqueId(), fish.getRarity(), length);
|
||||||
|
logger.debug("[%] caught a [%] with length [%] and rarity [%] for [%] points",
|
||||||
|
player.getName(), fish.normalFishName(), String.format("%.2f", length),
|
||||||
|
fish.getRarity().displayName(), String.valueOf(addedPoints));
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/main/java/com/alttd/fishingevent/npc/NPC.java
Normal file
4
src/main/java/com/alttd/fishingevent/npc/NPC.java
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.alttd.fishingevent.npc;
|
||||||
|
|
||||||
|
public interface NPC {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.alttd.fishingevent.objects;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class CustomRandom {
|
||||||
|
private static final Random random = new Random();
|
||||||
|
|
||||||
|
public static int generateNumber(int min, int max, int attempts) {
|
||||||
|
int highestValue = 0;
|
||||||
|
for (int i = 0; i < attempts; i++) {
|
||||||
|
max = Math.max(max, random.nextInt(min, max + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return highestValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.alttd.fishingevent.objects;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class RandomListItem<T> {
|
||||||
|
|
||||||
|
private final Random random = new Random();
|
||||||
|
|
||||||
|
public Optional<T> getRandomObject(List<T> items) {
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
int randomIndex = random.nextInt(items.size());
|
||||||
|
return Optional.of(items.get(randomIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
23
src/main/java/com/alttd/fishingevent/objects/Rarity.java
Normal file
23
src/main/java/com/alttd/fishingevent/objects/Rarity.java
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.alttd.fishingevent.objects;
|
||||||
|
|
||||||
|
public enum Rarity {
|
||||||
|
NORMAL("Normal"),
|
||||||
|
LEGENDARY("Legendary")
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String displayName;
|
||||||
|
private final String configName;
|
||||||
|
|
||||||
|
public String displayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String configName() {
|
||||||
|
return configName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rarity(String displayName) {
|
||||||
|
configName = this.name().toLowerCase().replaceAll(" ", "-");
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.alttd.fishingevent.objects;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.ParticleBuilder;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class SpawnParticles extends BukkitRunnable {
|
||||||
|
|
||||||
|
private final List<Set<ParticleBuilder>> particles;
|
||||||
|
private final Player player;
|
||||||
|
private final Duration delay;
|
||||||
|
|
||||||
|
public SpawnParticles(List<Set<ParticleBuilder>> particles, Player player, Duration delay) {
|
||||||
|
this.particles = particles;
|
||||||
|
this.player = player;
|
||||||
|
this.delay = delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Set<ParticleBuilder> particleBuilders : particles) {
|
||||||
|
for (ParticleBuilder particle : particleBuilders) {
|
||||||
|
particle.receivers(player).spawn();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.wait(delay.toMillis());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
src/main/java/com/alttd/fishingevent/points/LoadTask.java
Normal file
34
src/main/java/com/alttd/fishingevent/points/LoadTask.java
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.alttd.fishingevent.points;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
|
import it.unimi.dsi.fastutil.io.BinIO;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class LoadTask implements Runnable {
|
||||||
|
|
||||||
|
private final PointsManagement pointsManagement;
|
||||||
|
private final FishingEvent fishingEvent;
|
||||||
|
|
||||||
|
public LoadTask(PointsManagement pointsManagement, FishingEvent fishingEvent) {
|
||||||
|
this.pointsManagement = pointsManagement;
|
||||||
|
this.fishingEvent = fishingEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
File file = new File(fishingEvent.getDataFolder(), "map.bin");
|
||||||
|
Object2IntOpenHashMap<UUID> loadedMap;
|
||||||
|
try {
|
||||||
|
//noinspection unchecked
|
||||||
|
loadedMap = (Object2IntOpenHashMap<UUID>) BinIO.loadObject(file);
|
||||||
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pointsManagement.setMap(loadedMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.alttd.fishingevent.points;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.config.Config;
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PointsManagement {
|
||||||
|
|
||||||
|
private static PointsManagement instance = null;
|
||||||
|
private final Object2IntOpenHashMap<UUID> pointsMap = new Object2IntOpenHashMap<>();
|
||||||
|
|
||||||
|
private PointsManagement() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PointsManagement getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new PointsManagement();
|
||||||
|
instance.pointsMap.defaultReturnValue(0);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized int caughtFish(UUID uuid, Rarity rarity, float length) {
|
||||||
|
int pointsToAdd = (int) (Config.RARITY_MULTIPLIERS.multiplierMap.get(rarity) * length);
|
||||||
|
pointsMap.addTo(uuid, pointsToAdd);
|
||||||
|
return pointsToAdd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized int getPoints(UUID uuid) {
|
||||||
|
return pointsMap.getInt(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void clear() {
|
||||||
|
pointsMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized int removePoints(UUID uuid, int points) throws IllegalArgumentException {
|
||||||
|
int availablePoints = pointsMap.getInt(uuid);
|
||||||
|
if (availablePoints < points) {
|
||||||
|
throw new IllegalArgumentException("Player only has " + availablePoints + " available points, can't remove " + points);
|
||||||
|
}
|
||||||
|
int newPoints = availablePoints - points;
|
||||||
|
return pointsMap.put(uuid, newPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object2IntOpenHashMap<UUID> getPointsMap() {
|
||||||
|
return pointsMap.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected synchronized void setMap(Object2IntOpenHashMap<UUID> populatedMap) {
|
||||||
|
pointsMap.clear();
|
||||||
|
pointsMap.putAll(populatedMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/main/java/com/alttd/fishingevent/points/SaveTask.java
Normal file
29
src/main/java/com/alttd/fishingevent/points/SaveTask.java
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.alttd.fishingevent.points;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.FishingEvent;
|
||||||
|
import it.unimi.dsi.fastutil.io.BinIO;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class SaveTask implements Runnable {
|
||||||
|
|
||||||
|
private final PointsManagement pointsManagement;
|
||||||
|
private final FishingEvent fishingEvent;
|
||||||
|
|
||||||
|
public SaveTask(PointsManagement pointsManagement, FishingEvent fishingEvent) {
|
||||||
|
this.pointsManagement = pointsManagement;
|
||||||
|
this.fishingEvent = fishingEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
File file = new File(fishingEvent.getDataFolder(), "map.bin");
|
||||||
|
try {
|
||||||
|
BinIO.storeObject(pointsManagement.getPointsMap(), file);
|
||||||
|
System.out.println("Object2IntOpenHashMap saved to map.bin");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.alttd.fishingevent.util;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.objects.Rarity;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.bukkit.profile.PlayerProfile;
|
||||||
|
import org.bukkit.profile.PlayerTextures;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class FishConfigHelper {
|
||||||
|
public static Optional<Rarity> getRarity(Logger logger, ConfigurationSection fishSection) {
|
||||||
|
Rarity rarity;
|
||||||
|
try {
|
||||||
|
rarity = Rarity.valueOf(fishSection.getString("rarity", "REPLACE").toUpperCase());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.warning("Invalid rarity for " + fishSection.getCurrentPath());
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(rarity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static Optional<ItemStack> loadFishItem(Logger logger, ConfigurationSection fishSection) {
|
||||||
|
ConfigurationSection fishItemSection = fishSection.getConfigurationSection("item");
|
||||||
|
if (fishItemSection == null) {
|
||||||
|
logger.warning("Invalid fish item section: " + fishSection.getCurrentPath() + ".item");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
|
||||||
|
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
|
||||||
|
|
||||||
|
PlayerProfile playerProfile = Bukkit.getOfflinePlayer(UUID.fromString(fishItemSection.getString("uuid", UUID.randomUUID().toString()))).getPlayerProfile();
|
||||||
|
PlayerTextures playerTextures = playerProfile.getTextures();
|
||||||
|
try {
|
||||||
|
playerTextures.setSkin(new URL("http://textures.minecraft.net/texture/" + fishItemSection.getString("url-texture")));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
playerProfile.setTextures(playerTextures);
|
||||||
|
skullMeta.setOwnerProfile(playerProfile);
|
||||||
|
skull.setItemMeta(skullMeta);
|
||||||
|
return Optional.of(skull);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
src/main/java/com/alttd/fishingevent/util/Logger.java
Normal file
42
src/main/java/com/alttd/fishingevent/util/Logger.java
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.alttd.fishingevent.util;
|
||||||
|
|
||||||
|
import com.alttd.fishingevent.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/main/resources/plugin.yml
Normal file
9
src/main/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
name: FishingEvent
|
||||||
|
version: '${version}'
|
||||||
|
main: com.alttd.fishingevent.FishingEvent
|
||||||
|
api-version: 1.20
|
||||||
|
commands:
|
||||||
|
fish:
|
||||||
|
description: Base command for FishingEvent
|
||||||
|
permission: fish.use
|
||||||
|
usage: /fish
|
||||||
Loading…
Reference in New Issue
Block a user