diff --git a/.gitignore b/.gitignore index f0db1b2..24f075a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,11 @@ build/ debug/ +# VS Code +# ------- + +.vscode/ + # IntelliJ # -------- diff --git a/build.gradle b/build.gradle index 799a674..eb24063 100644 --- a/build.gradle +++ b/build.gradle @@ -5,29 +5,28 @@ plugins { id 'java' // Generates the plugin.yml, allows easier access to common plugin libraries, and facilitates the test server tasks. - id 'kr.entree.spigradle' version '2.2.3' + id 'kr.entree.spigradle' version '2.4.2' // Allows us to shade libraries into the build plugin. id 'com.github.johnrengelman.shadow' version '5.2.0' } repositories { - jcenter() mavenCentral() + jitpack() - spigot() - paper() + spigotmc() + sonatype() + papermc() } dependencies { compileOnly spigot(project.property('mcVersion')) compileOnly paper(project.property('mcVersion')) - implementation 'com.google.guava:guava:28.2-jre' - - testImplementation platform('org.junit:junit-bom:5.7.0') - testImplementation 'org.junit.jupiter:junit-jupiter' - testImplementation mockBukkit() + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' + testImplementation 'com.github.seeseemelk:MockBukkit-v1.19:2.29.0' } test { @@ -46,14 +45,22 @@ task cleanAll { // Compilation variables / tasks // --------------------------------------------------------- -targetCompatibility = 1.8 -sourceCompatibility = 1.8 +compileJava { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +// Shading +// --------------------------------------------------------- tasks.build.dependsOn(shadowJar) +tasks.prepareSpigotPlugins.dependsOn(shadowJar) shadowJar { // This is required to prevent Spigradle from attempting to look for an incorrectly named file during debug. classifier = '' + + // relocate 'old.path.lib', "${project.property('group')}.lib" } // Plugin variables / tasks @@ -73,6 +80,8 @@ spigot { eula = true buildVersion = project.property('mcVersion') args = project.property('debugServerArgs').split(/(,\s*|\s+)/) - jvmArgs = project.property('debugServerJvmArgs').split(/(,\s*|\s+)/) + + // This caused issues with the debugPaper task + // jvmArgs = project.property('debugServerJvmArgs').split(/(,\s*|\s+)/) } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index aabcfdb..a43b5c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ -group = com.projectkorra +group = com.projectkorra.core name = ProjectKorra-Core authors = ProjectKorra version = 0.0.1 description = This is a placeholder plugin description. -mcVersion = 1.16.3 -apiVersion = 1.16 +mcVersion = 1.19.2 +apiVersion = 1.19 debugServerArgs = --nogui debugServerJvmArgs = \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..7454180 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 12d38de..84d1f85 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..1b6c787 100644 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -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 +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 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" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + 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 @@ -106,80 +140,95 @@ 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 +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# 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 +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "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 +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - 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\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - 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; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# 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" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/src/main/java/com/projectkorra/core/ProjectKorra.java b/src/main/java/com/projectkorra/core/ProjectKorra.java index 6115853..9783c2e 100644 --- a/src/main/java/com/projectkorra/core/ProjectKorra.java +++ b/src/main/java/com/projectkorra/core/ProjectKorra.java @@ -1,18 +1,49 @@ package com.projectkorra.core; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.logging.Level; + +import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPluginLoader; -import org.bukkit.plugin.PluginDescriptionFile; -import java.io.File; +import com.projectkorra.core.api.AbilityInfo; +import com.projectkorra.core.api.AbilityManager; +import com.projectkorra.core.api.PKListener; public class ProjectKorra extends JavaPlugin { + public static ProjectKorra plugin; + @Override - public void onEnable() {} + public void onEnable() { + plugin = this; + // get infos from classes + registerAbilities(); + // get their activations + + // validate activations + + // register listeners + + this.getServer().getPluginManager().registerEvents(new PKListener(), this); + + this.getServer().getScheduler().runTaskTimer(this, () -> { + System.out.println("TICK: " + System.currentTimeMillis()); + + AbilityManager.tick(); + // do other stuff; + }, 0, 1); + } @Override - public void onDisable() {} + public void onDisable() { + } public ProjectKorra() { super(); @@ -21,4 +52,49 @@ public ProjectKorra() { protected ProjectKorra(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { super(loader, description, dataFolder, file); } + + private void registerAbilities() { + if (!this.getDataFolder().exists()) { + this.getDataFolder().mkdir(); + } + + File abilFolder = new File(this.getDataFolder().getPath() + "\\abilities"); + if (!abilFolder.exists()) { + abilFolder.mkdir(); + } + + File[] files = abilFolder.listFiles(); + for (File f : files) { + try { + JarFile j = new JarFile(f); + Enumeration entries = j.entries(); + + while (entries.hasMoreElements()) { + JarEntry entry = entries.nextElement(); + if (!entry.getName().endsWith(".class") || entry.getName().contains("$")) { + continue; + } + + String className = entry.getName().replace('/', '.').substring(0, entry.getName().length() - 6); + + try { + Class clazz = Class.forName(className); + + if (clazz.getSuperclass() == AbilityInfo.class) { + Constructor c = clazz.getDeclaredConstructors()[0]; + c.newInstance(); + } + } catch (Exception e) { + ProjectKorra.plugin.getLogger().log(Level.SEVERE, + "Loading abilities from ability folder gone bad."); + e.printStackTrace(); + } + + } + j.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } } diff --git a/src/main/java/com/projectkorra/core/WaterManipulationInfo.java b/src/main/java/com/projectkorra/core/WaterManipulationInfo.java new file mode 100644 index 0000000..5e8f1f5 --- /dev/null +++ b/src/main/java/com/projectkorra/core/WaterManipulationInfo.java @@ -0,0 +1,31 @@ +package com.projectkorra.core; + +import com.projectkorra.core.api.AbilityInfo; +import com.projectkorra.core.api.AbilityInstance; +import com.projectkorra.core.api.ActionCriteria; +import com.projectkorra.core.api.ActivationCriteria; +import com.projectkorra.core.api.User; +import com.projectkorra.core.api.game.Input; + +public class WaterManipulationInfo extends AbilityInfo { + + public WaterManipulationInfo() { + super("Vahagn", "1.0", "WaterManipulation", true); + this.registerAction(new ActionCriteria( + (u, i) -> (u.apply(i, (e) -> ((WaterManipulationInstance) e).freeze()))) + .check(Input.SHIFT_DOWN)); + this.registerActivation(new ActivationCriteria()); + } + + @Override + public void load() { + // TODO Auto-generated method stub + + } + + @Override + public AbilityInstance createInstance(User user) { + return new WaterManipulationInstance(user, this, 15); + } + +} diff --git a/src/main/java/com/projectkorra/core/WaterManipulationInstance.java b/src/main/java/com/projectkorra/core/WaterManipulationInstance.java new file mode 100644 index 0000000..cffc1af --- /dev/null +++ b/src/main/java/com/projectkorra/core/WaterManipulationInstance.java @@ -0,0 +1,40 @@ +package com.projectkorra.core; + +import com.projectkorra.core.api.AbilityInfo; +import com.projectkorra.core.api.AbilityInstance; +import com.projectkorra.core.api.User; + +public class WaterManipulationInstance extends AbilityInstance { + + public WaterManipulationInstance(User user, AbilityInfo info, int priority) { + super(user, info, priority); + // TODO Auto-generated constructor stub + } + + @Override + public void onStart() { + // TODO Auto-generated method stub + + } + + @Override + public void progress() { + // TODO Auto-generated method stub + + } + + @Override + public void onRemove() { + // TODO Auto-generated method stub + + } + + public void freeze() { + } + + @Override + public void update() { + freeze(); + } + +} diff --git a/src/main/java/com/projectkorra/core/api/AbilityInfo.java b/src/main/java/com/projectkorra/core/api/AbilityInfo.java new file mode 100644 index 0000000..ff9f0f6 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/AbilityInfo.java @@ -0,0 +1,68 @@ +package com.projectkorra.core.api; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; + +import com.projectkorra.core.ProjectKorra; +import com.projectkorra.core.api.skills.Skill; + +public abstract class AbilityInfo { + public final List skills; + public final String author; + public final String version; + public final String name; + public final boolean bindable; + public final boolean needsMovement; + public final String configPath; + protected List>> actionCriterias; + protected List> activationCriterias; + public int priority = 1; + + public AbilityInfo(String author, String version, String name, boolean bindable, + Skill... skills) { + this(author, version, name, "DEFAULT", bindable, false, skills); + } + + public AbilityInfo(String author, String version, String name, boolean bindable, boolean needsMovement, + Skill... skills) { + this(author, version, name, "DEFAULT", bindable, needsMovement, skills); + } + + public AbilityInfo(String author, String version, String name, String configPath, boolean bindable, + boolean needsMovement, + Skill... skills) { + this.author = author; + this.version = version; + this.name = name; + this.bindable = bindable; + this.needsMovement = needsMovement; + this.skills = Collections.unmodifiableList(Arrays.asList(skills)); + this.configPath = configPath; + if (AbilityManager.infos.stream().filter(i -> i.name == this.name).toList().size() < 1) { + AbilityManager.infos.add(this); + this.load(); + } else { + // TODO: add appropriate method later + ProjectKorra.plugin.getLogger().log(Level.SEVERE, + this.name + "'s info is already registered! Please use *INSERT APPROPRIATE METHOD"); + } + } + + public void registerActivation(Sequence c1) { + activationCriterias.add(c1); + } + + public void registerAction(Sequence> c1) { + actionCriterias.add(c1); + } + + public abstract void load(); + + public abstract AbilityInstance createInstance(User user); + + public boolean needsMovement() { + return needsMovement; + } +} diff --git a/src/main/java/com/projectkorra/core/api/AbilityInstance.java b/src/main/java/com/projectkorra/core/api/AbilityInstance.java new file mode 100644 index 0000000..7ed6fc3 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/AbilityInstance.java @@ -0,0 +1,71 @@ +package com.projectkorra.core.api; + +public abstract class AbilityInstance { + private boolean started = false; + private boolean stopped = false; + private long startTime; + protected User user; + private int priority = 0; + + public final AbilityInfo info; + + public AbilityInstance(User user, AbilityInfo info, int priority) { + this.user = user; + this.info = info; + this.priority = priority; + this.user.getInstances().add(this); + } + + public final void start() { + if (!started) { + startTime = System.currentTimeMillis(); + started = true; + this.onStart(); + } + } + + public final void tick() { + if (started && !stopped) + this.progress(); + } + + public final void remove() { + if (!stopped) { + stopped = true; + this.onRemove(); + } + } + + public abstract void onStart(); + + public abstract void progress(); + + public abstract void onRemove(); + + public boolean started() { + return started; + } + + public boolean stopped() { + return stopped; + } + + public int getPriority() { + return priority; + } + + public long getStartTime() { + return startTime; + } + + public User getUser() { + return user; + } + + public AbilityInfo getInfo() { + return info; + } + + public abstract void update(); + +} diff --git a/src/main/java/com/projectkorra/core/api/AbilityManager.java b/src/main/java/com/projectkorra/core/api/AbilityManager.java new file mode 100644 index 0000000..284413b --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/AbilityManager.java @@ -0,0 +1,64 @@ +package com.projectkorra.core.api; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import com.projectkorra.core.api.game.Input; +import com.projectkorra.core.util.Pair; + +public class AbilityManager { + public static final Set infos = new HashSet<>(100); + + public static void tick() { + for (User user : UserManager.users) { + Iterator iter = user.getInstances().iterator(); + while (iter.hasNext()) { + AbilityInstance i = iter.next(); + if (i.stopped()) { + iter.remove(); + } else if (i.started()) { + i.tick(); + } else { + i.start(); + } + } + } + + for (User user : UserManager.users) { + for (Input t : Input.values) { + user.getInputs().put(t, new Pair<>(false, null)); + } + } + } + + public static void activateAbilities(User user) { + if (user == null) { + return; + } + for (Pair> e : user.getSequences(true)) { + if (!e.getKey().needsMovement()) { + if (e.getValue().test(user)) { + e.getValue().activate(user, e.getKey()); + } + } + } + } + + public static void activateMovement(User user) { + if (user == null) { + return; + } + for (Pair> e : user.getSequences(true)) { + if (e.getKey().needsMovement()) { + if (e.getValue().test(user)) { + e.getValue().activate(user, e.getKey()); + } + } + } + } + + public static void flagRemoval(User user, AbilityInstance ability, boolean cancel) { + + } +} diff --git a/src/main/java/com/projectkorra/core/api/ActionCriteria.java b/src/main/java/com/projectkorra/core/api/ActionCriteria.java new file mode 100644 index 0000000..262c32d --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/ActionCriteria.java @@ -0,0 +1,11 @@ +package com.projectkorra.core.api; + +import java.util.List; +import java.util.function.BiFunction; + +public class ActionCriteria extends Sequence> { + + public ActionCriteria(BiFunction> action) { + super(action); + } +} diff --git a/src/main/java/com/projectkorra/core/api/ActivationCriteria.java b/src/main/java/com/projectkorra/core/api/ActivationCriteria.java new file mode 100644 index 0000000..c39071e --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/ActivationCriteria.java @@ -0,0 +1,8 @@ +package com.projectkorra.core.api; + +public class ActivationCriteria extends Sequence { + + public ActivationCriteria() { + super((u, i) -> i.createInstance(u)); + } +} diff --git a/src/main/java/com/projectkorra/core/api/Criteria.java b/src/main/java/com/projectkorra/core/api/Criteria.java new file mode 100644 index 0000000..9177058 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/Criteria.java @@ -0,0 +1,47 @@ +package com.projectkorra.core.api; + +import java.util.function.Predicate; + +public class Criteria { + + Predicate condition; + Predicate excludes; + long timeTested; + boolean reset; + + public Criteria(Predicate condition) { + this(true, condition, b -> false); + } + + public Criteria(boolean reset, Predicate condition) { + this(reset, condition, b -> false); + } + + public Criteria(boolean reset, Predicate condition, Predicate excludes) { + this.reset = reset; + this.condition = condition; + this.excludes = excludes; + } + + public boolean test(User u) { + timeTested = System.currentTimeMillis(); + return condition.test(u); + } + + public long timeElapsed() { + return System.currentTimeMillis() - timeTested; + } + + public long timeTested() { + return timeTested; + } + + public boolean reset() { + return reset; + } + + public Predicate getExcludes() { + return excludes; + } + +} \ No newline at end of file diff --git a/src/main/java/com/projectkorra/core/api/PKListener.java b/src/main/java/com/projectkorra/core/api/PKListener.java new file mode 100644 index 0000000..9168770 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/PKListener.java @@ -0,0 +1,204 @@ +package com.projectkorra.core.api; + +import org.bukkit.Location; +import org.bukkit.Statistic; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerStatisticIncrementEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; +import org.bukkit.event.player.PlayerToggleFlightEvent; +import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.event.player.PlayerVelocityEvent; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.util.Vector; + +import com.projectkorra.core.api.game.Input; + +public class PKListener implements Listener { + + public long timeStart; + + @EventHandler + public void onPlayerLogin(PlayerLoginEvent event) { + UserManager.loadUser(event.getPlayer()); + } + + @EventHandler + public void onPlayerLogout(PlayerQuitEvent event) { + UserManager.saveUser(event.getPlayer()); + } + + @EventHandler + public void onPlayerSneak(PlayerToggleSneakEvent event) { + Player p = event.getPlayer(); + if (p != null) { + User user = UserManager.getUser(p); + user.does(!p.isSneaking() ? Input.SHIFT_DOWN : Input.SHIFT_UP, event); + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateAbilities(user); + } + } + + @EventHandler + public void onPlayerSprint(PlayerToggleSprintEvent event) { + Player p = event.getPlayer(); + if (p != null) { + User user = UserManager.getUser(p); + user.does(!p.isSprinting() ? Input.SPRINT_ON : Input.SPRINT_OFF, event); + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateAbilities(user); + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + Player p = event.getPlayer(); + if (p != null) { + User user = UserManager.getUser(p); + if (event.getHand() == EquipmentSlot.HAND) { + + switch (event.getAction()) { + case LEFT_CLICK_AIR: + user.does(Input.LEFT_CLICK, event); + break; + case LEFT_CLICK_BLOCK: + user.does(Input.LEFT_CLICK_BLOCK, event); + break; + case RIGHT_CLICK_AIR: + user.does(Input.RIGHT_CLICK_AIR, event); + break; + case RIGHT_CLICK_BLOCK: + user.does(Input.RIGHT_CLICK_BLOCK, event); + break; + default: + return; + } + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateAbilities(user); + } + } + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Player p = event.getPlayer(); + if (p != null) { + User user = UserManager.getUser(p); + + Location from = event.getFrom(); + Location to = event.getTo(); + + Vector direction = to.toVector().subtract(from.toVector()).clone().normalize(); + Vector forward = p.getLocation().getDirection().clone().setY(0).normalize(); + Vector left = p.getLocation().getPitch() % 90 == 0 ? forward.rotateAroundY(90) + : forward.clone().setY(0).normalize(); + Vector up = new Vector(0, 1, 0); + + double dL = direction.dot(left); + double dU = direction.dot(up); + double dF = direction.dot(forward); + + if (Math.abs(dL) > 0) { + user.does(dL > 0 ? Input.LEFT : Input.RIGHT, event); + } + if (Math.abs(dU) > 0) { + user.does(dU > 0 ? Input.UP : Input.DOWN, event); + } + if (Math.abs(dF) > 0) { + user.does(dF > 0 ? Input.FORWARD : Input.BACKWARD, event); + } + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateMovement(user); + } + } + + @EventHandler + public void onPlayerToggleFlight(PlayerToggleFlightEvent event) { + Player p = event.getPlayer(); + if (p != null) { + User user = UserManager.getUser(p); + user.does(!p.isFlying() ? Input.FLIGHT_ON : Input.FLIGHT_OFF, event); + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateAbilities(user); + } + } + + @EventHandler + public void onPlayerSlotChange(PlayerItemHeldEvent event) { + Player p = event.getPlayer(); + if (p != null) { + PlayerUser user = (PlayerUser) UserManager.getUser(p); + + user.setSlot(event.getNewSlot()); + + user.does(Input.SLOT_CHANGE, event); + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateAbilities(user); + } + } + + @EventHandler + public void onPlayerJump(PlayerStatisticIncrementEvent event) { + Player p = event.getPlayer(); + if (p != null) { + PlayerUser user = (PlayerUser) UserManager.getUser(p); + if (event.getStatistic() == Statistic.JUMP) { + user.does(Input.JUMP, event); + System.out.println("Listener: " + System.currentTimeMillis()); + AbilityManager.activateAbilities(user); + } + } + } + + @EventHandler + public void onPlayerVelocity(PlayerVelocityEvent event) { + Player p = event.getPlayer(); + if (p != null) { + PlayerUser user = (PlayerUser) UserManager.getUser(p); + if (!event.getVelocity().equals(new Vector())) { + System.out.println("Listener: " + System.currentTimeMillis()); + user.does(Input.KNOCK_BACK, event); + } + } + } + + @EventHandler + public void onPlayerSwapHandsC(PlayerSwapHandItemsEvent event) { + Player p = event.getPlayer(); + if (p != null) { + PlayerUser user = (PlayerUser) UserManager.getUser(p); + + user.does(Input.SWAP_HANDS, event); + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateAbilities(user); + } + } + + @EventHandler + public void onPlayerDrop(PlayerDropItemEvent event) { + Player p = event.getPlayer(); + if (p != null) { + PlayerUser user = (PlayerUser) UserManager.getUser(p); + + user.does(Input.THROW_ITEM, event); + System.out.println("Listener: " + System.currentTimeMillis()); + + AbilityManager.activateAbilities(user); + } + } +} diff --git a/src/main/java/com/projectkorra/core/api/PlayerUser.java b/src/main/java/com/projectkorra/core/api/PlayerUser.java new file mode 100644 index 0000000..722c9f9 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/PlayerUser.java @@ -0,0 +1,50 @@ +package com.projectkorra.core.api; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; + +import com.projectkorra.core.util.Pair; + +public class PlayerUser extends User { + private int slot; + + public PlayerUser(Player entity) { + super(entity); + } + + @Override + public AbilityInfo getCurrentBind() { + return null; + } + + public void setSlot(int i) { + this.slot = i; + } + + public int getSlot() { + return this.slot; + } + + @Override + protected final List>> getSequences(boolean current) { + if (current) { + List>> filtered = new ArrayList<>(); + for (Pair> e : activations) { + if (e.getKey() == this.getCurrentBind() || !e.getKey().bindable) { + filtered.add(e); + } + } + return filtered; + } else { + return activations; + } + } + + @Override + public List getBinds() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/main/java/com/projectkorra/core/api/Sequence.java b/src/main/java/com/projectkorra/core/api/Sequence.java new file mode 100644 index 0000000..8e451fe --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/Sequence.java @@ -0,0 +1,93 @@ +package com.projectkorra.core.api; + +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.Predicate; + +import com.projectkorra.core.api.game.Input; + +public abstract class Sequence { + + List conditions; + BiFunction action; + int step = 0; + + public Sequence(BiFunction action) { + this.action = action; + } + + public Sequence(Sequence seq) { + this.action = seq.action; + seq.conditions.forEach(i -> this.conditions.add(i.clone())); + } + + public Sequence check(Input... inputs) { + return check(30000, inputs); + } + + public Sequence check(long maxTime, Input... inputs) { + return check(maxTime, true, inputs); + } + + public Sequence check(long maxTime, boolean reset, Input... inputs) { + return check(0, maxTime, reset, inputs); + } + + public Sequence check(long t1, long t2, boolean reset, Input... inputs) { + return check(t1, t2, reset, asPredicate(inputs)); + } + + public Sequence check(long t1, long t2, boolean reset, Predicate predicate) { + this.conditions.add(new TimedCriteria(t1, t2, reset, predicate)); + return this; + } + + public boolean test(User u) { + + TimedCriteria curr = conditions.get(step); + + boolean valid = curr.test(u); + + if (valid) { + if (step > 0) { + TimedCriteria prev = conditions.get(step - 1); + long t1 = curr.getT1(); + long t2 = curr.getT2(); + long dT = curr.timeTested - prev.timeTested; + + if (dT > t2 || dT < t1) { + this.step = curr.reset ? 0 : this.step; + } else { + this.step++; + } + } else { + this.step++; + } + } else { + if (curr.reset) { + this.step = curr.getExcludes().test(u) ? this.step : 0; + } else { + this.step = curr.getExcludes().test(u) ? 0 : this.step; + } + } + + if (step == conditions.size()) { + this.step = 0; + return true; + } else { + return false; + } + } + + T activate(User user, AbilityInfo info) { + return this.action.apply(user, info); + } + + private Predicate asPredicate(Input[] inputs) { + Predicate predicate = b -> true; + for (Input input : inputs) { + predicate = predicate.and(b -> b.did(input)); + } + return predicate; + } +} diff --git a/src/main/java/com/projectkorra/core/api/TimedCriteria.java b/src/main/java/com/projectkorra/core/api/TimedCriteria.java new file mode 100644 index 0000000..8b56abf --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/TimedCriteria.java @@ -0,0 +1,35 @@ +package com.projectkorra.core.api; + +import java.util.function.Predicate; + +public class TimedCriteria extends Criteria { + + long t1; + long t2; + + public TimedCriteria(long t1, long t2, boolean reset, Predicate condition) { + super(reset, condition); + this.t1 = t1; + this.t2 = t2; + } + + /** + * @return the t1 + */ + public long getT1() { + return t1; + } + + /** + * @return the t2 + */ + public long getT2() { + return t2; + } + + @Override + public TimedCriteria clone() { + + return new TimedCriteria(t1, t2, reset, condition); + } +} \ No newline at end of file diff --git a/src/main/java/com/projectkorra/core/api/User.java b/src/main/java/com/projectkorra/core/api/User.java new file mode 100644 index 0000000..bc936f0 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/User.java @@ -0,0 +1,157 @@ +package com.projectkorra.core.api; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; + +import com.projectkorra.core.util.Pair; +import com.projectkorra.core.api.game.Input; + +public abstract class User { + + protected List>> activations = new ArrayList<>(20); + protected List instances = new ArrayList<>(); + protected Map cooldowns = new HashMap<>(20); + protected Entity entity; + + private Map> inputs = new HashMap<>(30); + private boolean toggledBindable = false; + private boolean toggledNonBindable = false; + + public AbilityInfo getInfo(Sequence a) { + for (Pair> e : activations) { + if (e.getValue() == a) { + + } + } + return null; + } + + public User(Entity entity) { + this.entity = entity; + for (Input t : Input.values) { + inputs.put(t, new Pair<>(false, null)); + } + } + + protected final void does(Input p, Event e) { + this.inputs.put(p, new Pair<>(true, e)); + } + + public final boolean did(Input p) { + return this.inputs.get(p).getKey(); + } + + public final boolean canBend(AbilityInfo info) { + return true; + } + + protected final void addCooldown(AbilityInfo info, long cooldown) { + Cooldown c = new Cooldown(cooldown); + c.addCooldown(); + cooldowns.put(info, c); + } + + public final boolean onCooldown(AbilityInfo info) { + Cooldown cooldown = cooldowns.get(info); + if (cooldown == null) { + return false; + } else if (System.currentTimeMillis() - cooldown.getCooldown() >= cooldown.getChecked()) { + return false; + } else { + return true; + } + } + + public Entity getEntity() { + return entity; + } + + protected final Map> getInputs() { + return inputs; + } + + protected final List getInstances() { + return instances; + } + + private final class Cooldown { + private long checked; + private long cooldown; + + public Cooldown(long cooldown) { + this.cooldown = cooldown; + } + + public void addCooldown() { + this.checked = System.currentTimeMillis(); + } + + public long getCooldown() { + return this.cooldown; + } + + public long getChecked() { + return this.checked; + } + } + + public final boolean toggledAll() { + return toggledBindable && toggledNonBindable; + } + + public final boolean toggledNonBindable() { + return !toggledBindable && toggledBindable; + } + + public final boolean toggledBindable() { + return toggledBindable && !toggledNonBindable; + } + + public final void toggleNonBindable(boolean on) { + this.toggledNonBindable = on; + } + + public final void toggleBindable(boolean on) { + this.toggledBindable = on; + + } + + public final void toggleAll(boolean on) { + toggleBindable(on); + toggleNonBindable(on); + } + + public final void toggleBindable() { + toggleBindable(!this.toggledBindable); + } + + public final void toggleNonBindable() { + toggleNonBindable(!this.toggledNonBindable); + } + + public final void toggleAll() { + toggleNonBindable(); + toggleBindable(); + } + + public abstract AbilityInfo getCurrentBind(); + + protected abstract List>> getSequences(boolean current); + + public abstract List getBinds(); + + public List getInstances(AbilityInfo info) { + return instances.stream().filter(i -> i.getInfo().equals(info)).toList(); + } + + public List apply(AbilityInfo info, Consumer action) { + return instances.stream().filter(i -> i.getInfo().equals(info)).peek(action).toList(); + } + +} diff --git a/src/main/java/com/projectkorra/core/api/UserManager.java b/src/main/java/com/projectkorra/core/api/UserManager.java new file mode 100644 index 0000000..801bf5b --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/UserManager.java @@ -0,0 +1,56 @@ +package com.projectkorra.core.api; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; + +import com.projectkorra.core.util.Pair; + +public class UserManager { + + protected static final List users = new ArrayList<>(20); + + public static User getUser(Player player) { + for (User u : users) { + if (u.getEntity() == player) { + return u; + } + } + return null; + } + + public static void loadUser(Player player) { + if (getUser(player) == null) { + // check if player is in database, if not create new object + User user = new PlayerUser(player); + + users.add(user); + + updateActivations(user); + } + } + + public static void saveUser(Player player) { + if (getUser(player) != null) { + // save information + } + } + + private static void updateActivations(User user) { + + List infos = AbilityManager.infos.stream().filter(i -> user.canBend(i)).toList(); + + for (AbilityInfo i : infos) { + for (Sequence e : i.activationCriterias) + user.getSequences(false).add(new Pair<>(i, e)); + for (Sequence> e : i.actionCriterias) + user.getSequences(false).add(new Pair<>(i, e)); + } + } + + public static void addCooldown(AbilityInstance abil, long cooldown) { + abil.getUser().addCooldown(abil.getInfo(), cooldown); + } + +} diff --git a/src/main/java/com/projectkorra/core/api/collision/CollisionManager.java b/src/main/java/com/projectkorra/core/api/collision/CollisionManager.java new file mode 100644 index 0000000..0ca9018 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/collision/CollisionManager.java @@ -0,0 +1,10 @@ +package com.projectkorra.core.api.collision; + +public class CollisionManager { + + public static void checkCollisions() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/com/projectkorra/core/api/game/AbilityUpdateEvent.java b/src/main/java/com/projectkorra/core/api/game/AbilityUpdateEvent.java new file mode 100644 index 0000000..313815a --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/game/AbilityUpdateEvent.java @@ -0,0 +1,28 @@ +package com.projectkorra.core.api.game; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; + +import com.projectkorra.core.api.AbilityInstance; +import com.projectkorra.core.api.AbilityManager; +import com.projectkorra.core.api.User; + +public class AbilityUpdateEvent extends BlockBreakEvent { + + private User user; + private AbilityInstance ability; + + public AbilityUpdateEvent(Block theBlock, User player, AbilityInstance ability) { + super(theBlock, player.getEntity() instanceof Player ? (Player) player.getEntity() : null); + this.user = player; + this.ability = ability; + } + + @Override + public void setCancelled(boolean cancel) { + super.setCancelled(cancel); + AbilityManager.flagRemoval(user, ability, cancel); + } + +} diff --git a/src/main/java/com/projectkorra/core/api/game/Input.java b/src/main/java/com/projectkorra/core/api/game/Input.java new file mode 100644 index 0000000..8e1058a --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/game/Input.java @@ -0,0 +1,78 @@ +package com.projectkorra.core.api.game; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class Input { + + public static final Map INPUTS = new HashMap<>(30); + public static Collection values = INPUTS.values(); + + public static final Input SHIFT_DOWN = new Input("SHIFT_DOWN"); + public static final Input SHIFT_UP = new Input("SHIFT_UP"); + public static final Input SPRINT_ON = new Input("SPRINT_ON"); + public static final Input SPRINT_OFF = new Input("SPRINT_OFF"); + + public static final Input LEFT_CLICK = new Input("LEFT_CLICK"); + public static final Input LEFT_CLICK_BLOCK = new Input("LEFT_CLICK_BLOCK"); + public static final Input RIGHT_CLICK_AIR = new Input("RIGHT_CLICK_AIR"); + public static final Input RIGHT_CLICK_BLOCK = new Input("RIGHT_CLICK_BLOCK"); + public static final Input RIGHT_CLICK_ENTITY = new Input("RIGHT_CLICK_ENTITY"); + public static final Input LEFT_CLICK_OFF_HAND = new Input("LEFT_CLICK_OFF_HAND"); + public static final Input LEFT_CLICK_BLOCK_OFF_HAND = new Input("LEFT_CLICK_BLOCK_OFF_HAND"); + public static final Input RIGHT_CLICK_AIR_OFF_HAND = new Input("RIGHT_CLICK_AIR_OFF_HAND"); + public static final Input RIGHT_CLICK_BLOCK_OFF_HAND = new Input("RIGHT_CLICK_BLOCK_OFF_HAND"); + + public static final Input LEFT = new Input("LEFT"); + public static final Input RIGHT = new Input("RIGHT"); + public static final Input FORWARD = new Input("FORWARD"); + public static final Input BACKWARD = new Input("BACKWARD"); + public static final Input UP = new Input("UP"); + public static final Input DOWN = new Input("DOWN"); + public static final Input FLIGHT_ON = new Input("FLIGHT_ON"); + public static final Input FLIGHT_OFF = new Input("FLIGHT_OFF"); + public static final Input JUMP = new Input("JUMP"); + public static final Input KNOCK_BACK = new Input("KNOCKBACK"); + + public static final Input SLOT_CHANGE = new Input("SLOT_CHANGE"); + public static final Input SWAP_HANDS = new Input("SWAP_HANDS"); + public static final Input THROW_ITEM = new Input("THROW_ITEM"); + + private String name; + + private Input(String name) { + this.name = name; + INPUTS.put(name, this); + } + + public static Input registerInput(String name) { + Input val = INPUTS.get(name); + + return val == null ? new Input(name) : val; + } + + public static Input getInput(String name) { + return INPUTS.get(name); + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + return (this == o) || ((o instanceof Input) && this.name.equals(((Input) o).name)); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public String toString() { + return this.name; + } + +} diff --git a/src/main/java/com/projectkorra/core/api/skills/Skill.java b/src/main/java/com/projectkorra/core/api/skills/Skill.java new file mode 100644 index 0000000..f196a55 --- /dev/null +++ b/src/main/java/com/projectkorra/core/api/skills/Skill.java @@ -0,0 +1,5 @@ +package com.projectkorra.core.api.skills; + +public abstract class Skill { + +} diff --git a/src/main/java/com/projectkorra/core/util/Pair.java b/src/main/java/com/projectkorra/core/util/Pair.java new file mode 100644 index 0000000..5b519eb --- /dev/null +++ b/src/main/java/com/projectkorra/core/util/Pair.java @@ -0,0 +1,35 @@ +package com.projectkorra.core.util; + +public class Pair { + + private T1 t1; + private T2 t2; + + public Pair(T1 t1, T2 t2) { + this.t1 = t1; + this.t2 = t2; + } + + public T1 getKey() { + return t1; + } + + public T2 getValue() { + return t2; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Pair)) { + return false; + } + Pair p = (Pair) o; + + return (t1.equals(p.t1) && t2.equals(p.t2)) || (t1.equals(p.t2) && t2.equals(p.t1)); + } + + @Override + public Pair clone() { + return new Pair<>(t1, t2); + } +} diff --git a/src/main/java/com/projectkorra/core/util/ParticleUtil.java b/src/main/java/com/projectkorra/core/util/ParticleUtil.java index da2dfa4..9045ad9 100644 --- a/src/main/java/com/projectkorra/core/util/ParticleUtil.java +++ b/src/main/java/com/projectkorra/core/util/ParticleUtil.java @@ -14,9 +14,9 @@ import org.bukkit.util.Vector; public class ParticleUtil { - + private static final Map DEFAULT_DATAS = new HashMap<>(); - + static { DEFAULT_DATAS.put(Particle.REDSTONE, new DustOptions(Color.RED, 0.8f)); DEFAULT_DATAS.put(Particle.BLOCK_CRACK, Material.BARRIER.createBlockData()); @@ -24,367 +24,437 @@ public class ParticleUtil { DEFAULT_DATAS.put(Particle.FALLING_DUST, Material.BARRIER.createBlockData()); DEFAULT_DATAS.put(Particle.ITEM_CRACK, new ItemStack(Material.BARRIER)); } - - private ParticleUtil() {} + + private ParticleUtil() { + } /** * Spawn a single particle at the given location + * * @param particle what particle to spawn - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawn(Particle particle, Location loc) { spawn(particle, loc, 1, 0, 0, 0, 0, null); } - + /** * Spawn a single particle at the given location with any additional data + * * @param particle what particle to spawn - * @param loc where to spawn the particle - * @param data additional data attached to the particle. See {@link Particle} for applicable data types + * @param loc where to spawn the particle + * @param data additional data attached to the particle. See + * {@link Particle} for applicable data types */ public static void spawn(Particle particle, Location loc, Object data) { spawn(particle, loc, 1, 0, 0, 0, 0, data); } - + /** * Spawn an amount of particles at the given location + * * @param particle what particle to spawn - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn */ public static void spawn(Particle particle, Location loc, int amount) { spawn(particle, loc, amount, 0, 0, 0, 0, null); } - + /** - * Spawn an amount of particles at the given location and with any additional data + * Spawn an amount of particles at the given location and with any additional + * data + * * @param particle what particle to spawn - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn - * @param extra additional number attached to the particle (usually speed in some way) + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn + * @param extra additional number attached to the particle (usually speed in + * some way) */ public static void spawn(Particle particle, Location loc, int amount, double extra) { spawn(particle, loc, amount, 0, 0, 0, extra, null); } - + /** - * Spawn an amount of particles at the given location and with any additional data + * Spawn an amount of particles at the given location and with any additional + * data + * * @param particle what particle to spawn - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn - * @param extra additional number attached to the particle (usually speed in some way) - * @param data additional data attached to the particle. See {@link Particle} for applicable data types + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn + * @param extra additional number attached to the particle (usually speed in + * some way) + * @param data additional data attached to the particle. See + * {@link Particle} for applicable data types */ public static void spawn(Particle particle, Location loc, int amount, double extra, Object data) { spawn(particle, loc, amount, 0, 0, 0, extra, data); } - + /** - * Spawn an amount of particles at the given location within the specified bounds and with any additional data + * Spawn an amount of particles at the given location within the specified + * bounds and with any additional data + * * @param particle what particle to spawn - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn - * @param offsets offset bounds for equal randomized spawning on each axis - * @param extra additional number attached to the particle (usually speed in some way) - * @param data additional data attached to the particle. See {@link Particle} for applicable data types + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn + * @param offsets offset bounds for equal randomized spawning on each axis + * @param extra additional number attached to the particle (usually speed in + * some way) + * @param data additional data attached to the particle. See + * {@link Particle} for applicable data types */ public static void spawn(Particle particle, Location loc, int amount, double offsets, double extra, Object data) { spawn(particle, loc, amount, offsets, offsets, offsets, extra, data); } - + /** - * Spawn an amount of particles at the given location within the specified bounds and with any additional data + * Spawn an amount of particles at the given location within the specified + * bounds and with any additional data + * * @param particle what particle to spawn - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn - * @param offsetX x-axis offset bounds for randomized spawning - * @param offsetY y-axis offset bounds for randomized spawning - * @param offsetZ z-axis offset bounds for randomized spawning - * @param extra additional number attached to the particle (usually speed in some way) - * @param data additional data attached to the particle. See {@link Particle} for applicable data types - */ - public static void spawn(Particle particle, Location loc, int amount, double offsetX, double offsetY, double offsetZ, double extra, Object data) { + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn + * @param offsetX x-axis offset bounds for randomized spawning + * @param offsetY y-axis offset bounds for randomized spawning + * @param offsetZ z-axis offset bounds for randomized spawning + * @param extra additional number attached to the particle (usually speed in + * some way) + * @param data additional data attached to the particle. See + * {@link Particle} for applicable data types + */ + public static void spawn(Particle particle, Location loc, int amount, double offsetX, double offsetY, + double offsetZ, double extra, Object data) { if (data == null && DEFAULT_DATAS.containsKey(particle)) { data = DEFAULT_DATAS.get(particle); } - + loc.getWorld().spawnParticle(particle, loc, amount, offsetX, offsetY, offsetZ, extra, data); } /** - * Spawn a single BLOCK_CRACK particle with the given BlockData at the given Location + * Spawn a single BLOCK_CRACK particle with the given BlockData at the given + * Location + * * @param block BlockData for the BLOCK_CRACK particle to show - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawnBlockCrack(BlockData block, Location loc) { spawnBlockCrack(block, loc, 1, 0, 0, 0); } - + /** - * Spawn an amount of the BLOCK_CRACK particle with the given BlockData at the given Location - * @param block BlockData for the BLOCK_CRACK particle to show - * @param loc where to spawn the particle + * Spawn an amount of the BLOCK_CRACK particle with the given BlockData at the + * given Location + * + * @param block BlockData for the BLOCK_CRACK particle to show + * @param loc where to spawn the particle * @param amount how many of the particle to spawn */ public static void spawnBlockCrack(BlockData block, Location loc, int amount) { spawnBlockCrack(block, loc, amount, 0, 0, 0); } - + /** - * Spawn an amount of the BLOCK_CRACK particle with the given BlockData at the given Location within the specified bounds - * @param block BlockData for the BLOCK_CRACK particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the BLOCK_CRACK particle with the given BlockData at the + * given Location within the specified bounds + * + * @param block BlockData for the BLOCK_CRACK particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnBlockCrack(BlockData block, Location loc, int amount, double offsets) { spawnBlockCrack(block, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of the BLOCK_CRACK particle with the given BlockData at the given Location within the specified bounds - * @param block BlockData for the BLOCK_CRACK particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the BLOCK_CRACK particle with the given BlockData at the + * given Location within the specified bounds + * + * @param block BlockData for the BLOCK_CRACK particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsetX x-axis offset bounds for randomized spawning * @param offsetY y-axis offset bounds for randomized spawning * @param offsetZ z-axis offset bounds for randomized spawning */ - public static void spawnBlockCrack(BlockData block, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + public static void spawnBlockCrack(BlockData block, Location loc, int amount, double offsetX, double offsetY, + double offsetZ) { if (block == null) { block = Material.BARRIER.createBlockData(); } - + spawn(Particle.BLOCK_CRACK, loc, amount, offsetX, offsetY, offsetZ, 0, block); } /** - * Spawn a single BLOCK_DUST particle with the given BlockData at the given Location + * Spawn a single BLOCK_DUST particle with the given BlockData at the given + * Location + * * @param block BlockData for the BLOCK_DUST particle to show - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawnBlockDust(BlockData block, Location loc) { spawnBlockDust(block, loc, 1, 0, 0, 0); } - + /** - * Spawn an amount of the BLOCK_DUST particle with the given BlockData at the given Location - * @param block BlockData for the BLOCK_DUST particle to show - * @param loc where to spawn the particle + * Spawn an amount of the BLOCK_DUST particle with the given BlockData at the + * given Location + * + * @param block BlockData for the BLOCK_DUST particle to show + * @param loc where to spawn the particle * @param amount how many of the particle to spawn */ public static void spawnBlockDust(BlockData block, Location loc, int amount) { spawnBlockDust(block, loc, amount, 0, 0, 0); } - + /** - * Spawn an amount of the BLOCK_DUST particle with the given BlockData at the given Location within the specified bounds - * @param block BlockData for the BLOCK_DUST particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the BLOCK_DUST particle with the given BlockData at the + * given Location within the specified bounds + * + * @param block BlockData for the BLOCK_DUST particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnBlockDust(BlockData block, Location loc, int amount, double offsets) { spawnBlockDust(block, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of the BLOCK_DUST particle with the given BlockData at the given Location within the specified bounds - * @param block BlockData for the BLOCK_DUST particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the BLOCK_DUST particle with the given BlockData at the + * given Location within the specified bounds + * + * @param block BlockData for the BLOCK_DUST particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsetX x-axis offset bounds for randomized spawning * @param offsetY y-axis offset bounds for randomized spawning * @param offsetZ z-axis offset bounds for randomized spawning */ - public static void spawnBlockDust(BlockData block, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + public static void spawnBlockDust(BlockData block, Location loc, int amount, double offsetX, double offsetY, + double offsetZ) { if (block == null) { block = Material.BARRIER.createBlockData(); } - + spawn(Particle.BLOCK_DUST, loc, amount, offsetX, offsetY, offsetZ, 0, block); } /** - * Spawn a single FALLING_DUST particle with the given BlockData at the given Location + * Spawn a single FALLING_DUST particle with the given BlockData at the given + * Location + * * @param block BlockData for the FALLING_DUST particle to show - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawnFallingDust(BlockData block, Location loc) { spawnFallingDust(block, loc, 1, 0, 0, 0); } - + /** - * Spawn an amount of the FALLING_DUST particle with the given BlockData at the given Location - * @param block BlockData for the FALLING_DUST particle to show - * @param loc where to spawn the particle + * Spawn an amount of the FALLING_DUST particle with the given BlockData at the + * given Location + * + * @param block BlockData for the FALLING_DUST particle to show + * @param loc where to spawn the particle * @param amount how many of the particle to spawn */ public static void spawnFallingDust(BlockData block, Location loc, int amount) { spawnFallingDust(block, loc, amount, 0, 0, 0); } - + /** - * Spawn an amount of the FALLING_DUST particle with the given BlockData at the given Location within the specified bounds - * @param block BlockData for the FALLING_DUST particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the FALLING_DUST particle with the given BlockData at the + * given Location within the specified bounds + * + * @param block BlockData for the FALLING_DUST particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnFallingDust(BlockData block, Location loc, int amount, double offsets) { spawnFallingDust(block, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of the FALLING_DUST particle with the given BlockData at the given Location within the specified bounds - * @param block BlockData for the FALLING_DUST particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the FALLING_DUST particle with the given BlockData at the + * given Location within the specified bounds + * + * @param block BlockData for the FALLING_DUST particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsetX x-axis offset bounds for randomized spawning * @param offsetY y-axis offset bounds for randomized spawning * @param offsetZ z-axis offset bounds for randomized spawning */ - public static void spawnFallingDust(BlockData block, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + public static void spawnFallingDust(BlockData block, Location loc, int amount, double offsetX, double offsetY, + double offsetZ) { if (block == null) { block = Material.BARRIER.createBlockData(); } - + spawn(Particle.FALLING_DUST, loc, amount, offsetX, offsetY, offsetZ, 0, block); } /** - * Spawn a single ITEM_CRACK particle with the given ItemStack at the given Location + * Spawn a single ITEM_CRACK particle with the given ItemStack at the given + * Location + * * @param item ItemStack for the ITEM_CRACK particle to show - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawnItemCrack(ItemStack item, Location loc) { spawnItemCrack(item, loc, 1, 0, 0, 0); } - + /** - * Spawn an amount of the ITEM_CRACK particle with the given ItemStack at the given Location - * @param item ItemStack for the ITEM_CRACK particle to show - * @param loc where to spawn the particle + * Spawn an amount of the ITEM_CRACK particle with the given ItemStack at the + * given Location + * + * @param item ItemStack for the ITEM_CRACK particle to show + * @param loc where to spawn the particle * @param amount how many of the particle to spawn */ public static void spawnItemCrack(ItemStack item, Location loc, int amount) { spawnItemCrack(item, loc, amount, 0, 0, 0); } - + /** - * Spawn an amount of the ITEM_CRACK particle with the given ItemStack at the given Location within the specified bounds - * @param item ItemStack for the ITEM_CRACK particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the ITEM_CRACK particle with the given ItemStack at the + * given Location within the specified bounds + * + * @param item ItemStack for the ITEM_CRACK particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnItemCrack(ItemStack item, Location loc, int amount, double offsets) { spawnItemCrack(item, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of the ITEM_CRACK particle with the given ItemStack at the given location within the specified bounds - * @param item ItemStack for the ITEM_CRACK particle to show - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of the ITEM_CRACK particle with the given ItemStack at the + * given location within the specified bounds + * + * @param item ItemStack for the ITEM_CRACK particle to show + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsetX x-axis offset bounds for randomized spawning * @param offsetY y-axis offset bounds for randomized spawning * @param offsetZ z-axis offset bounds for randomized spawning */ - public static void spawnItemCrack(ItemStack item, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + public static void spawnItemCrack(ItemStack item, Location loc, int amount, double offsetX, double offsetY, + double offsetZ) { if (item == null) { item = new ItemStack(Material.BARRIER); } - + spawn(Particle.ITEM_CRACK, loc, amount, offsetX, offsetY, offsetZ, 0, item); } /** * Spawn a single colored NOTE particle at the given Location + * * @param color which color the note should be - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawnColoredNote(NoteColor color, Location loc) { spawnColoredNote(color, loc, 1, 0, 0, 0); } - + /** * Spawn an amount of colored NOTE particles at the given Location - * @param color which color the note should be - * @param loc where to spawn the particle + * + * @param color which color the note should be + * @param loc where to spawn the particle * @param amount how many of the particle to spawn */ public static void spawnColoredNote(NoteColor color, Location loc, int amount) { spawnColoredNote(color, loc, amount, 0, 0, 0); } - + /** - * Spawn an amount of colored NOTE particles at the given Location within the specified bounds - * @param color which color the note should be - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of colored NOTE particles at the given Location within the + * specified bounds + * + * @param color which color the note should be + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnColoredNote(NoteColor color, Location loc, int amount, double offsets) { spawnColoredNote(color, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of colored NOTE particles at the given Location within the specified bounds - * @param color which color the note should be - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of colored NOTE particles at the given Location within the + * specified bounds + * + * @param color which color the note should be + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsetX x-axis offset bounds for randomized spawning * @param offsetY y-axis offset bounds for randomized spawning * @param offsetZ z-axis offset bounds for randomized spawning */ - public static void spawnColoredNote(NoteColor color, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + public static void spawnColoredNote(NoteColor color, Location loc, int amount, double offsetX, double offsetY, + double offsetZ) { World world = loc.getWorld(); double value = color.ordinal() / 24D; - + for (int i = 0; i < amount; i++) { double x = loc.getX() + offsetX * 2 * (Math.random() - 0.5); double y = loc.getY() + offsetY * 2 * (Math.random() - 0.5); double z = loc.getZ() + offsetZ * 2 * (Math.random() - 0.5); - + world.spawnParticle(Particle.NOTE, x, y, z, 0, value, 0, 0, 1); } } /** - * Spawn a single colored REDSTONE particle at the given Location and a size of 1 + * Spawn a single colored REDSTONE particle at the given Location and a size of + * 1 + * * @param color color of the particle - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawnColoredRedstone(Color color, Location loc) { spawnColoredRedstone(color, 1, loc, 1, 0, 0, 0); } - + /** * Spawn a single colored REDSTONE particle at the given Location + * * @param color color of the particle - * @param size size of the particle [0, ~4] (size seems to be capped around 4) - * @param loc where to spawn the particle + * @param size size of the particle [0, ~4] (size seems to be capped around 4) + * @param loc where to spawn the particle */ public static void spawnColoredRedstone(Color color, float size, Location loc) { spawnColoredRedstone(color, size, loc, 1, 0, 0, 0); } - + /** - * Spawn an amount of colored REDSTONE particles at the given Location and a size of 1 - * @param color color of the particle - * @param loc where to spawn the particle + * Spawn an amount of colored REDSTONE particles at the given Location and a + * size of 1 + * + * @param color color of the particle + * @param loc where to spawn the particle * @param amount how many of the particle to spawn */ public static void spawnColoredRedstone(Color color, Location loc, int amount) { spawnColoredRedstone(color, 1, loc, amount, 0, 0, 0); } - + /** * Spawn an amount of colored REDSTONE particles at the given Location - * @param color color of the particle - * @param size size of the particle [0, ~4] (size seems to be capped around 4) - * @param loc where to spawn the particle + * + * @param color color of the particle + * @param size size of the particle [0, ~4] (size seems to be capped around 4) + * @param loc where to spawn the particle * @param amount how many of the particle to spawn */ public static void spawnColoredRedstone(Color color, float size, Location loc, int amount) { @@ -392,186 +462,216 @@ public static void spawnColoredRedstone(Color color, float size, Location loc, i } /** - * Spawn an amount of colored REDSTONE particles at the given Location within the specified bounds and a size of 1 - * @param color color of the particle - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of colored REDSTONE particles at the given Location within + * the specified bounds and a size of 1 + * + * @param color color of the particle + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnColoredRedstone(Color color, Location loc, int amount, double offsets) { spawnColoredRedstone(color, 1, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of colored REDSTONE particles at the given Location within the specified bounds - * @param color color of the particle - * @param size size of the particle [0, ~4] (size seems to be capped around 4) - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of colored REDSTONE particles at the given Location within + * the specified bounds + * + * @param color color of the particle + * @param size size of the particle [0, ~4] (size seems to be capped around + * 4) + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnColoredRedstone(Color color, float size, Location loc, int amount, double offsets) { spawnColoredRedstone(color, size, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of colored REDSTONE particles at the given Location within the specified bounds - * @param color color of the particle - * @param size size of the particle [0, ~4] (size seems to be capped around 4) - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * Spawn an amount of colored REDSTONE particles at the given Location within + * the specified bounds + * + * @param color color of the particle + * @param size size of the particle [0, ~4] (size seems to be capped around + * 4) + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsetX x-axis offset bounds for randomized spawning * @param offsetY y-axis offset bounds for randomized spawning * @param offsetZ z-axis offset bounds for randomized spawning */ - public static void spawnColoredRedstone(Color color, float size, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + public static void spawnColoredRedstone(Color color, float size, Location loc, int amount, double offsetX, + double offsetY, double offsetZ) { if (color == null) { color = Color.RED; } - + size = Math.max(0, size); - + spawn(Particle.REDSTONE, loc, amount, offsetX, offsetY, offsetZ, 0, new DustOptions(color, size)); } /** * Spawn a single colored SPELL particle at the given Location - * @param color color of the particle + * + * @param color color of the particle * @param ambient if true, the particles will be considerably transparent - * @param loc where to spawn the particle + * @param loc where to spawn the particle */ public static void spawnColoredSpell(Color color, boolean ambient, Location loc) { spawnColoredSpell(color, ambient, loc, 1, 0, 0, 0); } - + /** * Spawn an amount of colored SPELL particles at the given Location - * @param color color of the particle + * + * @param color color of the particle * @param ambient if true, the particles will be considerably transparent - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn */ public static void spawnColoredSpell(Color color, boolean ambient, Location loc, int amount) { spawnColoredSpell(color, ambient, loc, amount, 0, 0, 0); } - + /** - * Spawn an amount of colored SPELL particles at the given Location within the specified bounds - * @param color color of the particle + * Spawn an amount of colored SPELL particles at the given Location within the + * specified bounds + * + * @param color color of the particle * @param ambient if true, the particles will be considerably transparent - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsets offset bounds for equal randomized spawning on each axis */ public static void spawnColoredSpell(Color color, boolean ambient, Location loc, int amount, double offsets) { spawnColoredSpell(color, ambient, loc, amount, offsets, offsets, offsets); } - + /** - * Spawn an amount of colored SPELL particles at the given Location within the specified bounds - * @param color color of the particle + * Spawn an amount of colored SPELL particles at the given Location within the + * specified bounds + * + * @param color color of the particle * @param ambient if true, the particles will be considerably transparent - * @param loc where to spawn the particle - * @param amount how many of the particle to spawn + * @param loc where to spawn the particle + * @param amount how many of the particle to spawn * @param offsetX x-axis offset bounds for randomized spawning * @param offsetY y-axis offset bounds for randomized spawning * @param offsetZ z-axis offset bounds for randomized spawning */ - public static void spawnColoredSpell(Color color, boolean ambient, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + public static void spawnColoredSpell(Color color, boolean ambient, Location loc, int amount, double offsetX, + double offsetY, double offsetZ) { if (color == null) { color = Color.WHITE; } - + Particle spell = ambient ? Particle.SPELL_MOB_AMBIENT : Particle.SPELL_MOB; World world = loc.getWorld(); double r = Math.max(1, Math.min(color.getRed(), 255)) / 255D; double g = Math.max(0, Math.min(color.getGreen(), 255)) / 255D; double b = Math.max(0, Math.min(color.getBlue(), 255)) / 255D; - + for (int i = 0; i < amount; i++) { double x = loc.getX() + offsetX * 2 * (Math.random() - 0.5); double y = loc.getY() + offsetY * 2 * (Math.random() - 0.5); double z = loc.getZ() + offsetZ * 2 * (Math.random() - 0.5); - + world.spawnParticle(spell, x, y, z, 0, r, g, b, 1); } } /** - * Spawns a single particle that moves from the given Location in the given direction using the magnitude of the direction vector as the speed - * @param particle a particle which can have direction applied to it + * Spawns a single particle that moves from the given Location in the given + * direction using the magnitude of the direction vector as the speed + * + * @param particle a particle which can have direction applied to it * @param direction which direction to move the particles - * @param loc where the particles spawn at + * @param loc where the particles spawn at */ public static void spawnWithDirection(DirectionalParticle particle, Vector direction, Location loc) { spawnWithDirection(particle, direction, direction.length(), loc, 1, 0, 0, 0); } - + /** - * Spawns a single particle that moves from the given Location in the given direction at the given speed - * @param particle a particle which can have direction applied to it + * Spawns a single particle that moves from the given Location in the given + * direction at the given speed + * + * @param particle a particle which can have direction applied to it * @param direction which direction to move the particles - * @param speed how fast to move the particle - * @param loc where the particles spawn at + * @param speed how fast to move the particle + * @param loc where the particles spawn at */ public static void spawnWithDirection(DirectionalParticle particle, Vector direction, double speed, Location loc) { spawnWithDirection(particle, direction, speed, loc, 1, 0, 0, 0); } - + /** - * Spawns an amount of particles that move from the given Location in the given direction at the given speed - * @param particle a particle which can have direction applied to it + * Spawns an amount of particles that move from the given Location in the given + * direction at the given speed + * + * @param particle a particle which can have direction applied to it * @param direction which direction to move the particles - * @param speed how fast to move the particle - * @param loc where the particles spawn at - * @param amount how many particles to spawn + * @param speed how fast to move the particle + * @param loc where the particles spawn at + * @param amount how many particles to spawn */ - public static void spawnWithDirection(DirectionalParticle particle, Vector direction, double speed, Location loc, int amount) { + public static void spawnWithDirection(DirectionalParticle particle, Vector direction, double speed, Location loc, + int amount) { spawnWithDirection(particle, direction, speed, loc, amount, 0, 0, 0); } - + /** - * Spawns an amount of particles that move from the given Location within the specified bounds in the given direction at the given speed - * @param particle a particle which can have direction applied to it + * Spawns an amount of particles that move from the given Location within the + * specified bounds in the given direction at the given speed + * + * @param particle a particle which can have direction applied to it * @param direction which direction to move the particles - * @param speed how fast to move the particle - * @param loc where the particles spawn at - * @param amount how many particles to spawn - * @param offsets offset bounds for equal randomized spawning on each axis + * @param speed how fast to move the particle + * @param loc where the particles spawn at + * @param amount how many particles to spawn + * @param offsets offset bounds for equal randomized spawning on each axis */ - public static void spawnWithDirection(DirectionalParticle particle, Vector direction, double speed, Location loc, int amount, double offsets) { + public static void spawnWithDirection(DirectionalParticle particle, Vector direction, double speed, Location loc, + int amount, double offsets) { spawnWithDirection(particle, direction, speed, loc, amount, offsets, offsets, offsets); } - + /** - * Spawns an amount of particles that move from the given Location within the specified bounds in the given direction at the given speed - * @param particle a particle which can have direction applied to it + * Spawns an amount of particles that move from the given Location within the + * specified bounds in the given direction at the given speed + * + * @param particle a particle which can have direction applied to it * @param direction which direction to move the particles - * @param speed how fast to move the particle - * @param loc where the particles spawn at - * @param amount how many particles to spawn - * @param offsetX x-axis offset bounds for randomized spawning - * @param offsetY y-axis offset bounds for randomized spawning - * @param offsetZ z-axis offset bounds for randomized spawning - */ - public static void spawnWithDirection(DirectionalParticle particle, Vector direction, double speed, Location loc, int amount, double offsetX, double offsetY, double offsetZ) { + * @param speed how fast to move the particle + * @param loc where the particles spawn at + * @param amount how many particles to spawn + * @param offsetX x-axis offset bounds for randomized spawning + * @param offsetY y-axis offset bounds for randomized spawning + * @param offsetZ z-axis offset bounds for randomized spawning + */ + public static void spawnWithDirection(DirectionalParticle particle, Vector direction, double speed, Location loc, + int amount, double offsetX, double offsetY, double offsetZ) { World world = loc.getWorld(); - + for (int i = 0; i < amount; i++) { double x = loc.getX() + offsetX * 2 * (Math.random() - 0.5); double y = loc.getY() + offsetY * 2 * (Math.random() - 0.5); double z = loc.getZ() + offsetZ * 2 * (Math.random() - 0.5); - - world.spawnParticle(particle.get(), x, y, z, 0, direction.getX(), direction.getY(), direction.getZ(), speed); + + world.spawnParticle(particle.get(), x, y, z, 0, direction.getX(), direction.getY(), direction.getZ(), + speed); } } - + public static enum NoteColor { - GREEN, - LIME, - YELLOW, - GOLD, - ORANGE, + GREEN, + LIME, + YELLOW, + GOLD, + ORANGE, RED_ORANGE, RED, CRIMSON, @@ -593,37 +693,38 @@ public static enum NoteColor { NEON_GREEN, GREEN_YELLOW; } - + public static enum DirectionalParticle { - EXPLOSION_NORMAL (Particle.EXPLOSION_NORMAL), - FIREWORKS_SPARK (Particle.FIREWORKS_SPARK), - WATER_BUBBLE (Particle.WATER_BUBBLE), - WATER_WAKE (Particle.WATER_WAKE), - CRIT (Particle.CRIT), - CRIT_MAGIC (Particle.CRIT_MAGIC), - SMOKE_NORMAL (Particle.SMOKE_NORMAL), - SMOKE_LARGE (Particle.SMOKE_LARGE), - PORTAL (Particle.PORTAL), - ENCHANTMENT_TABLE (Particle.ENCHANTMENT_TABLE), - FLAME (Particle.FLAME), - CLOUD (Particle.CLOUD), - DRAGON_BREATH (Particle.DRAGON_BREATH), - END_ROD (Particle.END_ROD), - DAMAGE_INDICATOR (Particle.DAMAGE_INDICATOR), - TOTEM (Particle.TOTEM), - SPIT (Particle.SPIT), - SQUID_INK (Particle.SQUID_INK), - BUBBLE_POP (Particle.BUBBLE_POP), - BUBBLE_COLUMN_UP (Particle.BUBBLE_COLUMN_UP), - NAUTILUS (Particle.NAUTILUS), - CAMPFIRE_COZY_SMOKE (Particle.CAMPFIRE_COSY_SMOKE), CAMPFIRE_COSY_SMOKE (Particle.CAMPFIRE_COSY_SMOKE), - CAMPFIRE_SIGNAL_SMOKE (Particle.CAMPFIRE_SIGNAL_SMOKE); - + EXPLOSION_NORMAL(Particle.EXPLOSION_NORMAL), + FIREWORKS_SPARK(Particle.FIREWORKS_SPARK), + WATER_BUBBLE(Particle.WATER_BUBBLE), + WATER_WAKE(Particle.WATER_WAKE), + CRIT(Particle.CRIT), + CRIT_MAGIC(Particle.CRIT_MAGIC), + SMOKE_NORMAL(Particle.SMOKE_NORMAL), + SMOKE_LARGE(Particle.SMOKE_LARGE), + PORTAL(Particle.PORTAL), + ENCHANTMENT_TABLE(Particle.ENCHANTMENT_TABLE), + FLAME(Particle.FLAME), + CLOUD(Particle.CLOUD), + DRAGON_BREATH(Particle.DRAGON_BREATH), + END_ROD(Particle.END_ROD), + DAMAGE_INDICATOR(Particle.DAMAGE_INDICATOR), + TOTEM(Particle.TOTEM), + SPIT(Particle.SPIT), + SQUID_INK(Particle.SQUID_INK), + BUBBLE_POP(Particle.BUBBLE_POP), + BUBBLE_COLUMN_UP(Particle.BUBBLE_COLUMN_UP), + NAUTILUS(Particle.NAUTILUS), + CAMPFIRE_COZY_SMOKE(Particle.CAMPFIRE_COSY_SMOKE), CAMPFIRE_COSY_SMOKE(Particle.CAMPFIRE_COSY_SMOKE), + CAMPFIRE_SIGNAL_SMOKE(Particle.CAMPFIRE_SIGNAL_SMOKE); + private Particle particle; + private DirectionalParticle(Particle particle) { this.particle = particle; } - + public Particle get() { return particle; } diff --git a/src/main/java/com/projectkorra/core/util/ThreadUtil.java b/src/main/java/com/projectkorra/core/util/ThreadUtil.java index 2928c5e..0a84720 100644 --- a/src/main/java/com/projectkorra/core/util/ThreadUtil.java +++ b/src/main/java/com/projectkorra/core/util/ThreadUtil.java @@ -1,8 +1,7 @@ package com.projectkorra.core.util; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; -import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; @@ -10,414 +9,651 @@ import com.projectkorra.core.ProjectKorra; /** -* A utility class to provide simple and uniform ways to schedule {@link java.lang.Runnable Runnables} and {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnables}. -*/ + * A utility class to provide simple and uniform ways to schedule + * {@link java.lang.Runnable Runnables} and + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnables}. + */ public class ThreadUtil { private static final ProjectKorra PLUGIN = JavaPlugin.getPlugin(ProjectKorra.class); - private ThreadUtil() {} + private ThreadUtil() { + } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run synchronously starting on next tick. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTask BukkitRunnable#runTask()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run synchronously starting on next tick. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTask BukkitRunnable#runTask()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ public static BukkitTask runTask(BukkitRunnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return runnable.runTask(PLUGIN); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run synchronously starting on next tick. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTask BukkitScheduler#runTask()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ + * Schedules the given {@link java.lang.Runnable Runnable} to run + * synchronously starting on next tick. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTask + * BukkitScheduler#runTask()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ public static BukkitTask runTask(Runnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return PLUGIN.getServer().getScheduler().runTask(PLUGIN, runnable); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run asynchronously starting on next tick. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskAsynchronously BukkitRunnable#runTaskAsynchronously()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runTaskAsynchronously(BukkitRunnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run asynchronously starting on next tick. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTaskAsynchronously + * BukkitRunnable#runTaskAsynchronously()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runTaskAsynchronously(BukkitRunnable runnable) + throws NullPointerException, IllegalStateException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return runnable.runTaskAsynchronously(PLUGIN); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run asynchronously starting on next tick. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskAsynchronously BukkitScheduler#runTaskAsynchronously()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runTaskAsynchronously(Runnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * asynchronously starting on next tick. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskAsynchronously + * BukkitScheduler#runTaskAsynchronously()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runTaskAsynchronously(Runnable runnable) + throws NullPointerException, IllegalStateException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return PLUGIN.getServer().getScheduler().runTaskAsynchronously(PLUGIN, runnable); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run synchronously after the given tick delay elapses. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskLater BukkitRunnable#runTaskLater()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runDelayedTask(BukkitRunnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run synchronously after the given tick delay + * elapses. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskLater + * BukkitRunnable#runTaskLater()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runDelayedTask(BukkitRunnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return runnable.runTaskLater(PLUGIN, delay); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run synchronously after the given tick delay elapses. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskLater BukkitScheduler#runTaskLater()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link java.lang.Runnable Runnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runDelayedTask(Runnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * synchronously after the given tick delay elapses. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskLater + * BukkitScheduler#runTaskLater()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given {@link java.lang.Runnable + * Runnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runDelayedTask(Runnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return PLUGIN.getServer().getScheduler().runTaskLater(PLUGIN, runnable, delay); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run asynchronously after the given tick delay elapses. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskLaterAsynchronously BukkitRunnable#runTaskLaterAsynchronously()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runDelayedTaskAsynchronously(BukkitRunnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run asynchronously after the given tick delay + * elapses. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTaskLaterAsynchronously + * BukkitRunnable#runTaskLaterAsynchronously()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runDelayedTaskAsynchronously(BukkitRunnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return runnable.runTaskLaterAsynchronously(PLUGIN, delay); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run asynchronously after the given tick delay elapses. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskLaterAsynchronously BukkitScheduler#runTaskLaterAsynchronously()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link java.lang.Runnable Runnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runDelayedTaskAsynchronously(Runnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * asynchronously after the given tick delay elapses. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskLaterAsynchronously + * BukkitScheduler#runTaskLaterAsynchronously()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given {@link java.lang.Runnable + * Runnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runDelayedTaskAsynchronously(Runnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return PLUGIN.getServer().getScheduler().runTaskLaterAsynchronously(PLUGIN, runnable, delay); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run synchronously every tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimer BukkitRunnable#runTaskTimer()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTask(BukkitRunnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run synchronously every tick until manually + * cancelled. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimer + * BukkitRunnable#runTaskTimer()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTask(BukkitRunnable runnable) + throws NullPointerException, IllegalStateException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return runRepeatingTask(runnable, 0L, 0L); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run synchronously every tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimer BukkitScheduler#runTaskTimer()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ + * Schedules the given {@link java.lang.Runnable Runnable} to run + * synchronously every tick until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimer + * BukkitScheduler#runTaskTimer()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ public static BukkitTask runRepeatingTask(Runnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return runRepeatingTask(runnable, 0L, 0L); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run synchronously after the given tick delay elapses and then again repeatedly each tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimer BukkitRunnable#runTaskTimer()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTask(BukkitRunnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run synchronously after the given tick delay + * elapses and then again repeatedly each tick until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimer + * BukkitRunnable#runTaskTimer()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTask(BukkitRunnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return runRepeatingTask(runnable, delay, 0L); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run synchronously after the given tick delay elapses and then again repeatedly each tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimer BukkitScheduler#runTaskTimer()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link java.lang.Runnable Runnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTask(Runnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * synchronously after the given tick delay elapses and then again + * repeatedly each tick until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimer + * BukkitScheduler#runTaskTimer()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given {@link java.lang.Runnable + * Runnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTask(Runnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return runRepeatingTask(runnable, delay, 0L); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run synchronously after the given tick delay elapses and then again repeatedly after the given period elapses until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimer BukkitRunnable#runTaskTimer()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * @param period The number of ticks the scheduler should wait before each subsequent execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative or if the given period is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTask(BukkitRunnable runnable, long delay, long period) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); - Validate.isTrue(period >= 0, "period cannot be negative"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run synchronously after the given tick delay + * elapses and then again repeatedly after the given period elapses until + * manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimer + * BukkitRunnable#runTaskTimer()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * @param period The number of ticks the scheduler should wait before + * each subsequent execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative or if the + * given period is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTask(BukkitRunnable runnable, long delay, long period) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); + Preconditions.checkArgument(period >= 0, "period cannot be negative"); return runnable.runTaskTimer(PLUGIN, delay, period); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run synchronously after the given tick delay elapses and then again repeatedly after the given period elapses until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimer BukkitScheduler#runTaskTimer()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link java.lang.Runnable Runnable}. - * @param period The number of ticks the scheduler should wait before each subsequent execution of the given {@link java.lang.Runnable Runnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative or if the given period is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTask(Runnable runnable, long delay, long period) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); - Validate.isTrue(period >= 0, "period cannot be negative"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * synchronously after the given tick delay elapses and then again + * repeatedly after the given period elapses until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimer + * BukkitScheduler#runTaskTimer()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given {@link java.lang.Runnable + * Runnable}. + * @param period The number of ticks the scheduler should wait before + * each subsequent execution of the given + * {@link java.lang.Runnable Runnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative or if the + * given period is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTask(Runnable runnable, long delay, long period) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); + Preconditions.checkArgument(period >= 0, "period cannot be negative"); return PLUGIN.getServer().getScheduler().runTaskTimer(PLUGIN, runnable, delay, period); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run asynchronously every tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimerAsynchronously BukkitRunnable#runTaskTimerAsynchronously​()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTaskAsynchronously(BukkitRunnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run asynchronously every tick until manually + * cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimerAsynchronously + * BukkitRunnable#runTaskTimerAsynchronously​()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTaskAsynchronously(BukkitRunnable runnable) + throws NullPointerException, IllegalStateException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return runRepeatingTaskAsynchronously(runnable, 0L, 0L); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run asynchronously every tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimerAsynchronously BukkitScheduler#runTaskTimerAsynchronously​()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTaskAsynchronously(Runnable runnable) throws NullPointerException, IllegalStateException { - Validate.notNull(runnable, "runnable cannot be null"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * asynchronously every tick until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimerAsynchronously + * BukkitScheduler#runTaskTimerAsynchronously​()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTaskAsynchronously(Runnable runnable) + throws NullPointerException, IllegalStateException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); return runRepeatingTaskAsynchronously(runnable, 0L, 0L); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run asynchronously after the given tick delay elapses and then again repeatedly each tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimerAsynchronously BukkitRunnable#runTaskTimerAsynchronously​()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTaskAsynchronously(BukkitRunnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run asynchronously after the given tick delay + * elapses and then again repeatedly each tick until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimerAsynchronously + * BukkitRunnable#runTaskTimerAsynchronously​()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTaskAsynchronously(BukkitRunnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return runRepeatingTaskAsynchronously(runnable, delay, 0L); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run asynchronously after the given tick delay elapses and then again repeatedly each tick until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimerAsynchronously BukkitScheduler#runTaskTimerAsynchronously​()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link java.lang.Runnable Runnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTaskAsynchronously(Runnable runnable, long delay) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * asynchronously after the given tick delay elapses and then again + * repeatedly each tick until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimerAsynchronously + * BukkitScheduler#runTaskTimerAsynchronously​()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given {@link java.lang.Runnable + * Runnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTaskAsynchronously(Runnable runnable, long delay) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); return runRepeatingTaskAsynchronously(runnable, delay, 0L); } /** - * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} to run asynchronously after the given tick delay elapses and then again repeatedly after the given period elapses until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimerAsynchronously BukkitRunnable#runTaskTimerAsynchronously​()}. - * - * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * @param period The number of ticks the scheduler should wait before each subsequent execution of the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} is null. - * @throws IllegalStateException if the given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative or if the given period is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTaskAsynchronously(BukkitRunnable runnable, long delay, long period) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); - Validate.isTrue(period >= 0, "period cannot be negative"); + * Schedules the given {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} to run asynchronously after the given tick delay + * elapses and then again repeatedly after the given period elapses until + * manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitRunnable#runTaskTimerAsynchronously + * BukkitRunnable#runTaskTimerAsynchronously​()}. + * + * @param runnable The {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * @param period The number of ticks the scheduler should wait before + * each subsequent execution of the given + * {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link org.bukkit.scheduler.BukkitRunnable BukkitRunnable} + * being executed by the scheduler. + * + * @throws NullPointerException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} is null. + * @throws IllegalStateException if the given + * {@link org.bukkit.scheduler.BukkitRunnable + * BukkitRunnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative or if the + * given period is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTaskAsynchronously(BukkitRunnable runnable, long delay, long period) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); + Preconditions.checkArgument(period >= 0, "period cannot be negative"); return runnable.runTaskTimerAsynchronously(PLUGIN, delay, period); } /** - * Schedules the given {@link java.lang.Runnable Runnable} to run asynchronously after the given tick delay elapses and then again repeatedly after the given period elapses until manually cancelled. Wraps {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimerAsynchronously BukkitScheduler#runTaskTimerAsynchronously​()}. - * - * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. - * @param delay The number of ticks the scheduler should wait before beginning execution of the given {@link java.lang.Runnable Runnable}. - * @param period The number of ticks the scheduler should wait before each subsequent execution of the given {@link java.lang.Runnable Runnable}. - * - * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the given {@link java.lang.Runnable Runnable} being executed by the scheduler. - * - * @throws NullPointerException if the given {@link java.lang.Runnable Runnable} is null. - * @throws IllegalStateException if the given {@link java.lang.Runnable Runnable} has already been scheduled. - * @throws IllegalArgumentException if the given delay is negative or if the given period is negative. - * - * @version 1.0.0 - * @since 0.0.1 - */ - public static BukkitTask runRepeatingTaskAsynchronously(Runnable runnable, long delay, long period) throws NullPointerException, IllegalStateException, IllegalArgumentException { - Validate.notNull(runnable, "runnable cannot be null"); - Validate.isTrue(delay >= 0, "delay cannot be negative"); - Validate.isTrue(period >= 0, "period cannot be negative"); + * Schedules the given {@link java.lang.Runnable Runnable} to run + * asynchronously after the given tick delay elapses and then again + * repeatedly after the given period elapses until manually cancelled. Wraps + * {@link org.bukkit.scheduler.BukkitScheduler#runTaskTimerAsynchronously + * BukkitScheduler#runTaskTimerAsynchronously​()}. + * + * @param runnable The {@link java.lang.Runnable Runnable} being scheduled. + * @param delay The number of ticks the scheduler should wait before + * beginning execution of the given {@link java.lang.Runnable + * Runnable}. + * @param period The number of ticks the scheduler should wait before + * each subsequent execution of the given + * {@link java.lang.Runnable Runnable}. + * + * @return A {@link org.bukkit.scheduler.BukkitTask BukkitTask} representing the + * given {@link java.lang.Runnable Runnable} being executed by the + * scheduler. + * + * @throws NullPointerException if the given {@link java.lang.Runnable + * Runnable} is null. + * @throws IllegalStateException if the given {@link java.lang.Runnable + * Runnable} has already been scheduled. + * @throws IllegalArgumentException if the given delay is negative or if the + * given period is negative. + * + * @version 1.0.0 + * @since 0.0.1 + */ + public static BukkitTask runRepeatingTaskAsynchronously(Runnable runnable, long delay, long period) + throws NullPointerException, IllegalStateException, IllegalArgumentException { + Preconditions.checkNotNull(runnable, "runnable cannot be null"); + Preconditions.checkArgument(delay >= 0, "delay cannot be negative"); + Preconditions.checkArgument(period >= 0, "period cannot be negative"); return PLUGIN.getServer().getScheduler().runTaskTimerAsynchronously(PLUGIN, runnable, delay, period); } } \ No newline at end of file diff --git a/src/main/java/com/projectkorra/core/util/VectorUtil.java b/src/main/java/com/projectkorra/core/util/VectorUtil.java index 0df68a2..81b957e 100644 --- a/src/main/java/com/projectkorra/core/util/VectorUtil.java +++ b/src/main/java/com/projectkorra/core/util/VectorUtil.java @@ -1,6 +1,7 @@ package com.projectkorra.core.util; -import org.apache.commons.lang.Validate; +import com.google.common.base.Preconditions; + import org.bukkit.Location; import org.bukkit.util.Vector; @@ -10,28 +11,32 @@ public class VectorUtil { - private VectorUtil() {} - + private VectorUtil() { + } + /** * Get a vector for the direction between two points + * * @param from start point - * @param to end point + * @param to end point * @return vector pointing from {@code ->} to */ public static Vector direction(Location from, Location to) { return new Vector(to.getX() - from.getX(), to.getY() - from.getY(), to.getZ() - from.getZ()); } - + /** * Returns an orthogonal vector from an axis - * @param axis vector to be orthogonal of - * @param length magnitude of orthogonal vector + * + * @param axis vector to be orthogonal of + * @param length magnitude of orthogonal vector * @param rotation counterclockwise rotation, 0 = righthand side of the axis * @return an orthogonal vector * @throws IllegalArgumentException when the axis vector is a zero vector */ public static Vector orthogonal(Vector axis, double length, Angle rotation) throws IllegalArgumentException { - Validate.isTrue(!axis.equals(UnitVector.ZERO.normal()), "Axis direction cannot be the zero vector!"); + Preconditions.checkArgument(!axis.equals(UnitVector.ZERO.normal()), + "Axis direction cannot be the zero vector!"); double yaw = Math.toRadians(getYaw(axis)); Vector other = new Vector(-Math.sin(yaw), axis.getY() - 1, Math.cos(yaw)); @@ -39,38 +44,41 @@ public static Vector orthogonal(Vector axis, double length, Angle rotation) thro return rotate(third.normalize().multiply(length), axis, rotation); } - + /** * Rotate a vector around an axis, this does mutate the rotator - * @param rotator vector to rotate - * @param axis axis to rotate around + * + * @param rotator vector to rotate + * @param axis axis to rotate around * @param rotation angle to rotate * @return rotated vector, not a new vector */ public static Vector rotate(Vector rotator, Vector axis, Angle rotation) { return rotator.rotateAroundAxis(axis, -rotation.getValue(AngleMode.RADIANS)); } - + /** * Gets the pitch of the given vector, -90 is up and 90 down + * * @param vector a vector * @return pitch of vector */ public static float getPitch(Vector vector) { double x = vector.getX(); double z = vector.getZ(); - + if (x == 0 && z == 0) { - return vector.getY() > 0 ? -90 : 90; + return vector.getY() > 0 ? -90 : 90; } - + double xz = Math.sqrt(x * x + z * z); return (float) Math.toDegrees(Math.atan(-vector.getY() / xz)); } - + /** * Gets the yaw of the given vector, a vector pointing straight * up or down will give a yaw of 0 + * * @param vector a vector * @return yaw of the vector */ diff --git a/src/main/java/com/projectkorra/core/util/math/Angle.java b/src/main/java/com/projectkorra/core/util/math/Angle.java index a05ce1d..a1ed0ce 100644 --- a/src/main/java/com/projectkorra/core/util/math/Angle.java +++ b/src/main/java/com/projectkorra/core/util/math/Angle.java @@ -25,16 +25,16 @@ public double getValue(AngleMode mode) { return value; } } - + public void set(AngleMode mode, double value) { this.mode = mode; this.value = value; } - + public void setValue(double value) { this.value = value; } - + public static Angle radians(double value) { return new Angle(AngleMode.RADIANS, value); } @@ -44,10 +44,11 @@ public static Angle degrees(double value) { } public static enum AngleMode { - DEGREES (180 / Math.PI), - RADIANS (Math.PI / 180); + DEGREES(180 / Math.PI), + RADIANS(Math.PI / 180); private double conversion; + private AngleMode(double conversion) { this.conversion = conversion; } diff --git a/src/main/java/com/projectkorra/core/util/math/UnitVector.java b/src/main/java/com/projectkorra/core/util/math/UnitVector.java index 8c10e7b..1ca48f8 100644 --- a/src/main/java/com/projectkorra/core/util/math/UnitVector.java +++ b/src/main/java/com/projectkorra/core/util/math/UnitVector.java @@ -4,32 +4,34 @@ public enum UnitVector { - ZERO (0, 0, 0), - POSITIVE_X (1, 0, 0), - POSITIVE_Y (0, 1, 0), - POSITIVE_Z (0, 0, 1), - NEGATIVE_X (-1, 0, 0), - NEGATIVE_Y (0, -1, 0), - NEGATIVE_Z (0, 0, -1); - + ZERO(0, 0, 0), + POSITIVE_X(1, 0, 0), + POSITIVE_Y(0, 1, 0), + POSITIVE_Z(0, 0, 1), + NEGATIVE_X(-1, 0, 0), + NEGATIVE_Y(0, -1, 0), + NEGATIVE_Z(0, 0, -1); + private double x, y, z; - + private UnitVector(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } - + /** * Gets the normal vector for this unit vector + * * @return normal vector */ public Vector normal() { return new Vector(x, y, z); } - + /** * Gets a vector of given magnitude for this unit vector + * * @param scale magnitude of the vector * @return scaled vector */ diff --git a/src/main/java/com/projectkorra/core/util/reflection/ReflectionUtil.java b/src/main/java/com/projectkorra/core/util/reflection/ReflectionUtil.java index ef443e0..055927c 100644 --- a/src/main/java/com/projectkorra/core/util/reflection/ReflectionUtil.java +++ b/src/main/java/com/projectkorra/core/util/reflection/ReflectionUtil.java @@ -1,5 +1,7 @@ package com.projectkorra.core.util.reflection; +import com.google.common.base.Preconditions; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -10,35 +12,44 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.lang.Validate; - import org.bukkit.Bukkit; /** - * A utility class to provide simple and uniform ways utilize java.lang.reflect Reflection. + * A utility class to provide simple and uniform ways utilize java.lang.reflect + * Reflection. */ public class ReflectionUtil { - /** Regex {@link java.util.regex.Pattern Pattern} used to match path variables in {@link getClass(final String classPath) getClass(final String classPath)} */ + /** + * Regex {@link java.util.regex.Pattern Pattern} used to match path variables in + * {@link getClass(final String classPath) getClass(final String classPath)} + */ private static Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}"); - private ReflectionUtil() {} + private ReflectionUtil() { + } // Classes /** - * Returns the {@link java.lang.Class Class} found at the given {@link java.lang.String String} path if it exists. + * Returns the {@link java.lang.Class Class} found at the given + * {@link java.lang.String String} path if it exists. * - * @param classPath The {@link java.lang.String String} path to the desired class. - * Supports the automatic expansion of certain path variables: - * {OBC} = org.bukkit.craftbukkit.[version] - * {NMS} = net.minecraft.server.[version] - * {VERSION} = [version] + * @param classPath The {@link java.lang.String String} path to the desired + * class. + * Supports the automatic expansion of certain path variables: + * {OBC} = org.bukkit.craftbukkit.[version] + * {NMS} = net.minecraft.server.[version] + * {VERSION} = [version] * - * Example: "{NMS}.Entity" = net.minecraft.server.[version].Entity + * Example: "{NMS}.Entity" = + * net.minecraft.server.[version].Entity * - * @return The class represented by the given {@link java.lang.String String} path. + * @return The class represented by the given {@link java.lang.String String} + * path. * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path does not correspond with a valid class or if an invalid path variable is used. + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path does not correspond with a valid class + * or if an invalid path variable is used. * * @version 1.0.0 * @since 0.0.1 @@ -48,33 +59,41 @@ public static Class getClass(final String classPath) throws IllegalArgumentEx } /** - * Returns the {@link java.lang.Class Class} found at the given {@link java.lang.String String} path if it exists. + * Returns the {@link java.lang.Class Class} found at the given + * {@link java.lang.String String} path if it exists. * - * @param canonicalName The exact {@link java.lang.String String} path of the desired class. + * @param canonicalName The exact {@link java.lang.String String} path of the + * desired class. * - * @return The class represented by the given {@link java.lang.String String} path. + * @return The class represented by the given {@link java.lang.String String} + * path. * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path does not correspond with a valid class. + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path does not correspond with a valid class. * * @version 1.0.0 * @since 0.0.1 */ private static Class getCanonicalClass(final String canonicalName) throws IllegalArgumentException { try { - return Class.forName(canonicalName); + return Class.forName(canonicalName); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(String.format("The class %s could not be found", canonicalName)); } } /** - * Converts the path variable aliases within the given {@link java.lang.String String} path to their actual counterparts. + * Converts the path variable aliases within the given {@link java.lang.String + * String} path to their actual counterparts. * - * @param path The {@link java.lang.String String} path containing path variable aliases to be expanded. + * @param path The {@link java.lang.String String} path containing path variable + * aliases to be expanded. * - * @return The new {@link java.lang.String String} path with all path variable aliases expanded to their actual counterparts. + * @return The new {@link java.lang.String String} path with all path variable + * aliases expanded to their actual counterparts. * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable. + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path contains an invalid path variable. * * @version 1.0.0 * @since 0.0.1 @@ -100,31 +119,40 @@ private static String expandPathVariables(final String path) throws IllegalArgum } /** - * Returns the {@link java.lang.Class Class} representing the type of the given {@link java.lang.Object Object}. + * Returns the {@link java.lang.Class Class} representing the type of the given + * {@link java.lang.Object Object}. * - * @param object The {@link java.lang.Object Object} whose type should be retrieved. + * @param object The {@link java.lang.Object Object} whose type should be + * retrieved. * - * @return The {@link java.lang.Class Class} representing the type of the given {@link java.lang.Object Object}. + * @return The {@link java.lang.Class Class} representing the type of the given + * {@link java.lang.Object Object}. * - * @throws NullPointerException if the given {@link java.lang.Object Object} is null. + * @throws NullPointerException if the given {@link java.lang.Object Object} is + * null. * * @version 1.0.0 * @since 0.0.1 */ private static Class getType(final Object object) throws NullPointerException { - Validate.notNull(object); + Preconditions.checkNotNull(object); return object.getClass(); } /** - * Returns a {@link java.lang.Class Class} array representing the types of the data stored within the given {@link java.lang.Object Object} array. + * Returns a {@link java.lang.Class Class} array representing the types of the + * data stored within the given {@link java.lang.Object Object} array. * - * @param objects The {@link java.lang.Object Object} array whose types should be retrieved. + * @param objects The {@link java.lang.Object Object} array whose types should + * be retrieved. * - * @return A {@link java.lang.Class Class} array representing the recursively accessed types of the data stored within the given {@link java.lang.Object Object}. + * @return A {@link java.lang.Class Class} array representing the recursively + * accessed types of the data stored within the given + * {@link java.lang.Object Object}. * - * @throws NullPointerException if any of the data within the given {@link java.lang.Object Object} array is null. + * @throws NullPointerException if any of the data within the given + * {@link java.lang.Object Object} array is null. * * @version 1.0.0 * @since 0.0.1 @@ -136,52 +164,82 @@ private static Class[] getType(final Object[] objects) throws NullPointerExce for (int i = 0; i < length; i++) { types[i] = getType(objects[i]); } - + return types; } // Constructors /** - * Returns the {@link java.lang.reflect.Constructor Constructor} in the class at the given {@link java.lang.String String} path if it exists. - * - * @param classPath The {@link java.lang.String String} path to the desired class. - * @param parameterTypes The {@link java.lang.Class Class} array representing the parameter types of the desired {@link java.lang.reflect.Constructor Constructor}. - * - * @return The {@link java.lang.reflect.Constructor Constructor} in the class at the given {@link java.lang.String String} path if it exists. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor Constructor} with the given parameter types does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Constructor Constructor} cannot be accessed due to insufficient permissions. + * Returns the {@link java.lang.reflect.Constructor Constructor} in the class at + * the given {@link java.lang.String String} path if it exists. + * + * @param classPath The {@link java.lang.String String} path to the desired + * class. + * @param parameterTypes The {@link java.lang.Class Class} array representing + * the parameter types of the desired + * {@link java.lang.reflect.Constructor Constructor}. + * + * @return The {@link java.lang.reflect.Constructor Constructor} in the class at + * the given {@link java.lang.String String} path if it exists. + * + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path contains an invalid path variable. + * @throws ClassNotFoundException if the given {@link java.lang.String String} + * path does not correspond with an existing + * class. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor + * Constructor} with the given parameter types + * does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Constructor + * Constructor} cannot be accessed due to + * insufficient permissions. * * @see #getClass(String) * * @version 1.0.0 * @since 0.0.1 */ - public static Constructor getConstructor(final String classPath, final Class... parameterTypes) throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, SecurityException { + public static Constructor getConstructor(final String classPath, final Class... parameterTypes) + throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, SecurityException { return getConstructor(getClass(classPath), parameterTypes); } /** - * Returns the {@link java.lang.reflect.Constructor Constructor} in the given {@link java.lang.Class Class} if it exists. - * - * @param The type corresponding the the {@link java.lang.Class Class} the returned {@link java.lang.reflect.Constructor Constructor} comes from. - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Constructor Constructor}. - * @param parameterTypes The {@link java.lang.Class Class} array representing the parameter types of the desired {@link java.lang.reflect.Constructor Constructor}. - * - * @return The {@link java.lang.reflect.Constructor Constructor} in the given {@link java.lang.Class Class} if it exists. - * - * @throws NullPointerException if the given {@link java.lang.Class Class} is null. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor Constructor} with the given parameter types does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Constructor Constructor} cannot be accessed due to insufficient permissions. + * Returns the {@link java.lang.reflect.Constructor Constructor} in the given + * {@link java.lang.Class Class} if it exists. + * + * @param The type corresponding the the {@link java.lang.Class + * Class} the returned + * {@link java.lang.reflect.Constructor Constructor} comes + * from. + * @param clazz The {@link java.lang.Class Class} containing the + * desired {@link java.lang.reflect.Constructor + * Constructor}. + * @param parameterTypes The {@link java.lang.Class Class} array representing + * the parameter types of the desired + * {@link java.lang.reflect.Constructor Constructor}. + * + * @return The {@link java.lang.reflect.Constructor Constructor} in the given + * {@link java.lang.Class Class} if it exists. + * + * @throws NullPointerException if the given {@link java.lang.Class Class} is + * null. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor + * Constructor} with the given parameter types + * does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Constructor + * Constructor} cannot be accessed due to + * insufficient permissions. * * @version 1.0.0 * @since 0.0.1 */ - public static Constructor getConstructor(final Class clazz, final Class... parameterTypes) throws NullPointerException, NoSuchMethodException, SecurityException { - Validate.notNull(clazz, "clazz cannot be null"); + public static Constructor getConstructor(final Class clazz, final Class... parameterTypes) + throws NullPointerException, NoSuchMethodException, SecurityException { + Preconditions.checkNotNull(clazz, "clazz cannot be null"); Constructor constructor = clazz.getDeclaredConstructor(parameterTypes); constructor.setAccessible(true); @@ -190,19 +248,39 @@ public static Constructor getConstructor(final Class clazz, final Clas } /** - * Creates and returns an instance of the class at the given {@link java.lang.String String} path if it exists. - * - * @param classPath The {@link java.lang.String String} path to the desired class to instantiate. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to construct the new instance. - * - * @return The new {@link java.lang.Object Object} instance of the class at the given {@link java.lang.String String} path if it exists. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable or invalid arguments are passed to the corresponding {@link java.lang.reflect.Constructor Constructor}. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor Constructor} with the given argument types does not exist. - * @throws InstantiationException if the {@link java.lang.Object Object} cannot be instantiated, most likely caused by the specified class being abstract. - * @throws IllegalAccessException if the corresponding {@link java.lang.reflect.Constructor Constructor} cannot be accessed. - * @throws InvocationTargetException if the found {@link java.lang.reflect.Constructor Constructor} throws an exception during instantiation. + * Creates and returns an instance of the class at the given + * {@link java.lang.String String} path if it exists. + * + * @param classPath The {@link java.lang.String String} path to the desired + * class to instantiate. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to construct the new instance. + * + * @return The new {@link java.lang.Object Object} instance of the class at the + * given {@link java.lang.String String} path if it exists. + * + * @throws IllegalArgumentException if the given {@link java.lang.String + * String} path contains an invalid path + * variable or invalid arguments are passed to + * the corresponding + * {@link java.lang.reflect.Constructor + * Constructor}. + * @throws ClassNotFoundException if the given {@link java.lang.String + * String} path does not correspond with an + * existing class. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor + * Constructor} with the given argument types + * does not exist. + * @throws InstantiationException if the {@link java.lang.Object Object} + * cannot be instantiated, most likely caused + * by the specified class being abstract. + * @throws IllegalAccessException if the corresponding + * {@link java.lang.reflect.Constructor + * Constructor} cannot be accessed. + * @throws InvocationTargetException if the found + * {@link java.lang.reflect.Constructor + * Constructor} throws an exception during + * instantiation. * * @see #getClass(String) * @see #getConstructor(String, Class...) @@ -210,56 +288,100 @@ public static Constructor getConstructor(final Class clazz, final Clas * @version 1.0.0 * @since 0.0.1 */ - public static Object instantiateObject(final String classPath, final Object... arguments) throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { + public static Object instantiateObject(final String classPath, final Object... arguments) + throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, + IllegalAccessException, InvocationTargetException { return instantiateObject(getClass(classPath), arguments); } /** - * Creates and returns an instance of the given class at the given {@link java.lang.Class Class} if a corresponding constructor it exists. - * - * @param The type corresponding the the {@link java.lang.Class Class} the invoked {@link java.lang.reflect.Constructor Constructor} comes from. - * @param clazz The {@link java.lang.Class Class} to instantiate. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to construct the new instance. - * - * @return The new T instance of the given {@link java.lang.Class Class} if a corresponding constructor it exists. - * - * @throws NullPointerException if the given {@link java.lang.Class Class} is null or if any of the specified arguments are null. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor Constructor} with the given argument types does not exist. - * @throws SecurityException if the corresponding {@link java.lang.reflect.Constructor Constructor} cannot be accessed due to insufficient permissions. - * @throws InstantiationException if the type T cannot be instantiated, most likely caused by the class being abstract. - * @throws IllegalAccessException if the corresponding {@link java.lang.reflect.Constructor Constructor} cannot be accessed. - * @throws IllegalArgumentException if invalid arguments are passed to the corresponding {@link java.lang.reflect.Constructor Constructor}. - * @throws InvocationTargetException if the found {@link java.lang.reflect.Constructor Constructor} throws an exception during instantiation. + * Creates and returns an instance of the given class at the given + * {@link java.lang.Class Class} if a corresponding constructor it exists. + * + * @param The type corresponding the the {@link java.lang.Class Class} + * the invoked {@link java.lang.reflect.Constructor + * Constructor} comes from. + * @param clazz The {@link java.lang.Class Class} to instantiate. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to construct the new instance. + * + * @return The new T instance of the given {@link java.lang.Class Class} if a + * corresponding constructor it exists. + * + * @throws NullPointerException if the given {@link java.lang.Class Class} + * is null or if any of the specified + * arguments are null. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Constructor + * Constructor} with the given argument types + * does not exist. + * @throws SecurityException if the corresponding + * {@link java.lang.reflect.Constructor + * Constructor} cannot be accessed due to + * insufficient permissions. + * @throws InstantiationException if the type T cannot be instantiated, most + * likely caused by the class being abstract. + * @throws IllegalAccessException if the corresponding + * {@link java.lang.reflect.Constructor + * Constructor} cannot be accessed. + * @throws IllegalArgumentException if invalid arguments are passed to the + * corresponding + * {@link java.lang.reflect.Constructor + * Constructor}. + * @throws InvocationTargetException if the found + * {@link java.lang.reflect.Constructor + * Constructor} throws an exception during + * instantiation. * * @see #getConstructor(Class, Class...) * * @version 1.0.0 * @since 0.0.1 */ - public static T instantiateObject(final Class clazz, final Object... arguments) throws NullPointerException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + public static T instantiateObject(final Class clazz, final Object... arguments) + throws NullPointerException, NoSuchMethodException, SecurityException, InstantiationException, + IllegalAccessException, IllegalArgumentException, InvocationTargetException { return getConstructor(clazz, getType(arguments)).newInstance(arguments); } /** - * Creates and returns an instance of the class corresponding to the given {@link java.lang.reflect.Constructor Constructor}. - * - * @param The type corresponding the the {@link java.lang.Class Class} the invoked {@link java.lang.reflect.Constructor Constructor} comes from. - * @param constructor The {@link java.lang.reflect.Constructor Constructor} being invoked. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to construct the new instance. - * - * @return The new T instance of the class corresponding to the given {@link java.lang.reflect.Constructor Constructor} - * - * @throws NullPointerException if the given {@link java.lang.reflect.Constructor Constructor} is null. - * @throws InstantiationException if the type T cannot be instantiated, most likely caused by the class being abstract. - * @throws IllegalAccessException if the given {@link java.lang.reflect.Constructor Constructor} cannot be accessed. - * @throws IllegalArgumentException if invalid arguments are passed to the corresponding {@link java.lang.reflect.Constructor Constructor}. - * @throws InvocationTargetException if the given {@link java.lang.reflect.Constructor Constructor} throws an exception during instantiation. + * Creates and returns an instance of the class corresponding to the given + * {@link java.lang.reflect.Constructor Constructor}. + * + * @param The type corresponding the the {@link java.lang.Class + * Class} the invoked {@link java.lang.reflect.Constructor + * Constructor} comes from. + * @param constructor The {@link java.lang.reflect.Constructor Constructor} + * being invoked. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to construct the new instance. + * + * @return The new T instance of the class corresponding to the given + * {@link java.lang.reflect.Constructor Constructor} + * + * @throws NullPointerException if the given + * {@link java.lang.reflect.Constructor + * Constructor} is null. + * @throws InstantiationException if the type T cannot be instantiated, most + * likely caused by the class being abstract. + * @throws IllegalAccessException if the given + * {@link java.lang.reflect.Constructor + * Constructor} cannot be accessed. + * @throws IllegalArgumentException if invalid arguments are passed to the + * corresponding + * {@link java.lang.reflect.Constructor + * Constructor}. + * @throws InvocationTargetException if the given + * {@link java.lang.reflect.Constructor + * Constructor} throws an exception during + * instantiation. * * @version 1.0.0 * @since 0.0.1 */ - public static T instantiateObject(final Constructor constructor, final Object... arguments) throws NullPointerException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Validate.notNull(constructor, "constructor cannot be null"); + public static T instantiateObject(final Constructor constructor, final Object... arguments) + throws NullPointerException, InstantiationException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + Preconditions.checkNotNull(constructor, "constructor cannot be null"); return constructor.newInstance(arguments); } @@ -267,46 +389,73 @@ public static T instantiateObject(final Constructor constructor, final Ob // Methods /** - * Returns the {@link java.lang.reflect.Method Method} in the class at the given {@link java.lang.String String} path if it exists. - * - * @param classPath The {@link java.lang.String String} path to the class conatining the desired {@link java.lang.reflect.Method Method}. - * @param methodName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Method Method}. - * @param parameterTypes The {@link java.lang.Class Class} array representing the parameter types of the desired {@link java.lang.reflect.Method Method}. - * - * @return The {@link java.lang.reflect.Method Method} in the class at the given {@link java.lang.String String} path if it exists. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} with the given parameter types does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Method Method} cannot be accessed due to insufficient permissions. + * Returns the {@link java.lang.reflect.Method Method} in the class at the given + * {@link java.lang.String String} path if it exists. + * + * @param classPath The {@link java.lang.String String} path to the class + * conatining the desired {@link java.lang.reflect.Method + * Method}. + * @param methodName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Method Method}. + * @param parameterTypes The {@link java.lang.Class Class} array representing + * the parameter types of the desired + * {@link java.lang.reflect.Method Method}. + * + * @return The {@link java.lang.reflect.Method Method} in the class at the given + * {@link java.lang.String String} path if it exists. + * + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path contains an invalid path variable. + * @throws ClassNotFoundException if the given {@link java.lang.String String} + * path does not correspond with an existing + * class. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} + * with the given parameter types does not + * exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed due to insufficient + * permissions. * * @see #getClass(String) * * @version 1.0.0 * @since 0.0.1 */ - public static Method getMethod(final String classPath, final String methodName, final Class... parameterTypes) throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, SecurityException { + public static Method getMethod(final String classPath, final String methodName, final Class... parameterTypes) + throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, SecurityException { return getMethod(getClass(classPath), methodName, parameterTypes); } /** - * Returns the {@link java.lang.reflect.Method Method} in the given {@link java.lang.Class Class} if it exists. - * - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Method Method}. - * @param methodName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Method Method}. - * @param parameterTypes The {@link java.lang.Class Class} array representing the parameter types of the desired {@link java.lang.reflect.Method Method}. - * - * @return The {@link java.lang.reflect.Method Method} in the class at the given {@link java.lang.String String} path if it exists. - * - * @throws NullPointerException if the given {@link java.lang.Class Class} is null. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} with the given parameter types does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Method Method} cannot be accessed due to insufficient permissions. + * Returns the {@link java.lang.reflect.Method Method} in the given + * {@link java.lang.Class Class} if it exists. + * + * @param clazz The {@link java.lang.Class Class} containing the + * desired {@link java.lang.reflect.Method Method}. + * @param methodName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Method Method}. + * @param parameterTypes The {@link java.lang.Class Class} array representing + * the parameter types of the desired + * {@link java.lang.reflect.Method Method}. + * + * @return The {@link java.lang.reflect.Method Method} in the class at the given + * {@link java.lang.String String} path if it exists. + * + * @throws NullPointerException if the given {@link java.lang.Class Class} is + * null. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} + * with the given parameter types does not exist. + * @throws SecurityException if the desired {@link java.lang.reflect.Method + * Method} cannot be accessed due to insufficient + * permissions. * * @version 1.0.0 * @since 0.0.1 */ - public static Method getMethod(final Class clazz, final String methodName, final Class... parameterTypes) throws NullPointerException, NoSuchMethodException, SecurityException { - Validate.notNull(clazz, "clazz cannot be null"); + public static Method getMethod(final Class clazz, final String methodName, final Class... parameterTypes) + throws NullPointerException, NoSuchMethodException, SecurityException { + Preconditions.checkNotNull(clazz, "clazz cannot be null"); // Checks all methods within the specified class. for (final Method method : clazz.getDeclaredMethods()) { @@ -321,26 +470,54 @@ public static Method getMethod(final Class clazz, final String methodName, fi return getMethod(clazz.getSuperclass(), methodName, parameterTypes); } - throw new NoSuchMethodException(String.format("The method %s could not be found with the specified parameter types", methodName)); + throw new NoSuchMethodException( + String.format("The method %s could not be found with the specified parameter types", methodName)); } /** - * Invokes the specified {@link java.lang.reflect.Method Method} for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance calling the desired {@link java.lang.reflect.Method Method}. - * @param classPath The {@link java.lang.String String} path to the class conatining the desired {@link java.lang.reflect.Method Method}. - * @param methodName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Method Method}. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to call the desired {@link java.lang.reflect.Method Method}. - * - * @return The {@link java.lang.Object Object} data returned by the desired {@link java.lang.reflect.Method Method} if it has a return value, otherwise null. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable or invalid arguments are passed to the corresponding {@link java.lang.reflect.Method Method}. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} with the given parameter types does not exist. - * @throws NullPointerException if the given {@link java.lang.reflect.Method Method} is null or if any of the specified arguments are null. - * @throws SecurityException if the desired {@link java.lang.reflect.Method Method} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Method Method} cannot be accessed. - * @throws InvocationTargetException if the desired {@link java.lang.reflect.Method Method} throws an exception during invocation. + * Invokes the specified {@link java.lang.reflect.Method Method} for the given + * instance. + * + * @param instance The {@link java.lang.Object Object} instance calling the + * desired {@link java.lang.reflect.Method Method}. + * @param classPath The {@link java.lang.String String} path to the class + * conatining the desired {@link java.lang.reflect.Method + * Method}. + * @param methodName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Method Method}. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to call the desired + * {@link java.lang.reflect.Method Method}. + * + * @return The {@link java.lang.Object Object} data returned by the desired + * {@link java.lang.reflect.Method Method} if it has a return value, + * otherwise null. + * + * @throws IllegalArgumentException if the given {@link java.lang.String + * String} path contains an invalid path + * variable or invalid arguments are passed to + * the corresponding + * {@link java.lang.reflect.Method Method}. + * @throws ClassNotFoundException if the given {@link java.lang.String + * String} path does not correspond with an + * existing class. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Method + * Method} with the given parameter types does + * not exist. + * @throws NullPointerException if the given + * {@link java.lang.reflect.Method Method} is + * null or if any of the specified arguments + * are null. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed due to insufficient + * permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed. + * @throws InvocationTargetException if the desired + * {@link java.lang.reflect.Method Method} + * throws an exception during invocation. * * @see #getClass(String) * @see #getType(Object[]) @@ -349,26 +526,52 @@ public static Method getMethod(final Class clazz, final String methodName, fi * @version 1.0.0 * @since 0.0.1 */ - public static Object invokeMethod(final Object instance, final String classPath, final String methodName, final Object... arguments) throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, NullPointerException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + public static Object invokeMethod(final Object instance, final String classPath, final String methodName, + final Object... arguments) + throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, NullPointerException, + SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { return invokeMethod(instance, getMethod(getClass(classPath), methodName, getType(arguments)), arguments); } /** - * Invokes the specified {@link java.lang.reflect.Method Method} for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance calling the desired {@link java.lang.reflect.Method Method}. - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Method Method}. - * @param methodName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Method Method}. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to call the desired {@link java.lang.reflect.Method Method}. - * - * @return The {@link java.lang.Object Object} data returned by the desired {@link java.lang.reflect.Method Method} if it has a return value, otherwise null. - * - * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} with the given parameter types does not exist. - * @throws NullPointerException if the given {@link java.lang.reflect.Method Method} is null, if the given {@link java.lang.Class Class} is null, or if any of the specified arguments are null. - * @throws SecurityException if the desired {@link java.lang.reflect.Method Method} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Method Method} cannot be accessed. - * @throws InvocationTargetException if the desired {@link java.lang.reflect.Method Method} throws an exception during invocation. - * @throws IllegalArgumentException if invalid arguments are passed to the corresponding {@link java.lang.reflect.Method Method}. + * Invokes the specified {@link java.lang.reflect.Method Method} for the given + * instance. + * + * @param instance The {@link java.lang.Object Object} instance calling the + * desired {@link java.lang.reflect.Method Method}. + * @param clazz The {@link java.lang.Class Class} containing the desired + * {@link java.lang.reflect.Method Method}. + * @param methodName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Method Method}. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to call the desired + * {@link java.lang.reflect.Method Method}. + * + * @return The {@link java.lang.Object Object} data returned by the desired + * {@link java.lang.reflect.Method Method} if it has a return value, + * otherwise null. + * + * @throws NoSuchMethodException if a {@link java.lang.reflect.Method + * Method} with the given parameter types does + * not exist. + * @throws NullPointerException if the given + * {@link java.lang.reflect.Method Method} is + * null, if the given {@link java.lang.Class + * Class} is null, or if any of the specified + * arguments are null. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed due to insufficient + * permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed. + * @throws InvocationTargetException if the desired + * {@link java.lang.reflect.Method Method} + * throws an exception during invocation. + * @throws IllegalArgumentException if invalid arguments are passed to the + * corresponding + * {@link java.lang.reflect.Method Method}. * * @see #getType(Object[]) * @see #getMethod(String, String, Class...) @@ -376,49 +579,95 @@ public static Object invokeMethod(final Object instance, final String classPath, * @version 1.0.0 * @since 0.0.1 */ - public static Object invokeMethod(final Object instance, final Class clazz, final String methodName, final Object... arguments) throws NoSuchMethodException, NullPointerException, IllegalAccessException, InvocationTargetException, IllegalArgumentException { + public static Object invokeMethod(final Object instance, final Class clazz, final String methodName, + final Object... arguments) throws NoSuchMethodException, NullPointerException, IllegalAccessException, + InvocationTargetException, IllegalArgumentException { return invokeMethod(instance, getMethod(clazz, methodName, getType(arguments)), arguments); } /** - * Invokes the specified {@link java.lang.reflect.Method Method} for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance calling the given {@link java.lang.reflect.Method Method}. - * @param method The {@link java.lang.reflect.Method Method} being invoked. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to call the given {@link java.lang.reflect.Method Method}. - * - * @return The {@link java.lang.Object Object} data returned by the desired {@link java.lang.reflect.Method Method} if it has a return value, otherwise null. - * - * @throws IllegalAccessException if the given {@link java.lang.reflect.Method Method} cannot be accessed. - * @throws InvocationTargetException if the given {@link java.lang.reflect.Method Method} throws an exception during invocation. - * @throws IllegalArgumentException if invalid arguments are passed to the corresponding {@link java.lang.reflect.Method Method}. + * Invokes the specified {@link java.lang.reflect.Method Method} for the given + * instance. + * + * @param instance The {@link java.lang.Object Object} instance calling the + * given {@link java.lang.reflect.Method Method}. + * @param method The {@link java.lang.reflect.Method Method} being invoked. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to call the given + * {@link java.lang.reflect.Method Method}. + * + * @return The {@link java.lang.Object Object} data returned by the desired + * {@link java.lang.reflect.Method Method} if it has a return value, + * otherwise null. + * + * @throws IllegalAccessException if the given + * {@link java.lang.reflect.Method Method} + * cannot be accessed. + * @throws InvocationTargetException if the given + * {@link java.lang.reflect.Method Method} + * throws an exception during invocation. + * @throws IllegalArgumentException if invalid arguments are passed to the + * corresponding + * {@link java.lang.reflect.Method Method}. * * @version 1.0.0 * @since 0.0.1 */ - public static Object invokeMethod(final Object instance, final Method method, final Object... arguments) throws IllegalAccessException, InvocationTargetException, IllegalArgumentException { + public static Object invokeMethod(final Object instance, final Method method, final Object... arguments) + throws IllegalAccessException, InvocationTargetException, IllegalArgumentException { return method.invoke(instance, arguments); } /** - * Invokes the specified {@link java.lang.reflect.Method Method} for the given instance. - * - * @param The type corresponding the the return type of the given {@link java.lang.reflect.Method Method}. - * @param instance The {@link java.lang.Object Object} instance calling the desired {@link java.lang.reflect.Method Method}. - * @param classPath The {@link java.lang.String String} path to the class conatining the desired {@link java.lang.reflect.Method Method}. - * @param methodName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Method Method}. - * @param returnType The {@link java.lang.Class Class} representing the return type of the given {@link java.lang.reflect.Method Method}. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to call the desired {@link java.lang.reflect.Method Method}. - * - * @return The T data returned by the desired {@link java.lang.reflect.Method Method} if it has a return value, otherwise null. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable, if invalid arguments are passed to the corresponding {@link java.lang.reflect.Method Method}, or if the given type T is not assignable to the actual return type of the given {@link java.lang.reflect.Method Method}. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} with the given parameter types does not exist. - * @throws NullPointerException if the given {@link java.lang.reflect.Method Method} is null or if any of the specified arguments are null. - * @throws SecurityException if the desired {@link java.lang.reflect.Method Method} cannot be accessed due to insufficient permissions. - * @throws InvocationTargetException if the desired {@link java.lang.reflect.Method Method} throws an exception during invocation. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Method Method} cannot be accessed. + * Invokes the specified {@link java.lang.reflect.Method Method} for the given + * instance. + * + * @param The type corresponding the the return type of the given + * {@link java.lang.reflect.Method Method}. + * @param instance The {@link java.lang.Object Object} instance calling the + * desired {@link java.lang.reflect.Method Method}. + * @param classPath The {@link java.lang.String String} path to the class + * conatining the desired {@link java.lang.reflect.Method + * Method}. + * @param methodName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Method Method}. + * @param returnType The {@link java.lang.Class Class} representing the return + * type of the given {@link java.lang.reflect.Method Method}. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to call the desired + * {@link java.lang.reflect.Method Method}. + * + * @return The T data returned by the desired {@link java.lang.reflect.Method + * Method} if it has a return value, otherwise null. + * + * @throws IllegalArgumentException if the given {@link java.lang.String + * String} path contains an invalid path + * variable, if invalid arguments are passed + * to the corresponding + * {@link java.lang.reflect.Method Method}, or + * if the given type T is not assignable to + * the actual return type of the given + * {@link java.lang.reflect.Method Method}. + * @throws ClassNotFoundException if the given {@link java.lang.String + * String} path does not correspond with an + * existing class. + * @throws NoSuchMethodException if a {@link java.lang.reflect.Method + * Method} with the given parameter types does + * not exist. + * @throws NullPointerException if the given + * {@link java.lang.reflect.Method Method} is + * null or if any of the specified arguments + * are null. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed due to insufficient + * permissions. + * @throws InvocationTargetException if the desired + * {@link java.lang.reflect.Method Method} + * throws an exception during invocation. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed. * * @see #getClass(String) * @see #getType(Object[]) @@ -427,28 +676,59 @@ public static Object invokeMethod(final Object instance, final Method method, fi * @version 1.0.0 * @since 0.0.1 */ - public static T invokeMethod(final Object instance, final String classPath, final String methodName, final Class returnType, final Object... arguments) throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, NullPointerException, SecurityException, InvocationTargetException, IllegalAccessException { - return invokeMethod(instance, getMethod(getClass(classPath), methodName, getType(arguments)), returnType, arguments); + public static T invokeMethod(final Object instance, final String classPath, final String methodName, + final Class returnType, final Object... arguments) + throws IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, NullPointerException, + SecurityException, InvocationTargetException, IllegalAccessException { + return invokeMethod(instance, getMethod(getClass(classPath), methodName, getType(arguments)), returnType, + arguments); } /** - * Invokes the specified {@link java.lang.reflect.Method Method} for the given instance. - * - * @param The type corresponding the the return type of the given {@link java.lang.reflect.Method Method}. - * @param instance The {@link java.lang.Object Object} instance calling the desired {@link java.lang.reflect.Method Method}. - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Method Method}. - * @param methodName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Method Method}. - * @param returnType The {@link java.lang.Class Class} representing the return type of the given {@link java.lang.reflect.Method Method}. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to call the desired {@link java.lang.reflect.Method Method}. - * - * @return The T data returned by the desired {@link java.lang.reflect.Method Method} if it has a return value, otherwise null. - * - * @throws NoSuchMethodException if a {@link java.lang.reflect.Method Method} with the given parameter types does not exist. - * @throws NullPointerException if the given {@link java.lang.reflect.Method Method} is null or if the given {@link java.lang.Class Class} is null or if any of the specified arguments are null. - * @throws SecurityException if the desired {@link java.lang.reflect.Method Method} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Method Method} cannot be accessed. - * @throws InvocationTargetException if the desired {@link java.lang.reflect.Method Method} throws an exception during invocation. - * @throws IllegalArgumentException if invalid arguments are passed to the corresponding {@link java.lang.reflect.Method Method} or if the given type T is not assignable to the actual return type of the corresponding {@link java.lang.reflect.Method Method}. + * Invokes the specified {@link java.lang.reflect.Method Method} for the given + * instance. + * + * @param The type corresponding the the return type of the given + * {@link java.lang.reflect.Method Method}. + * @param instance The {@link java.lang.Object Object} instance calling the + * desired {@link java.lang.reflect.Method Method}. + * @param clazz The {@link java.lang.Class Class} containing the desired + * {@link java.lang.reflect.Method Method}. + * @param methodName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Method Method}. + * @param returnType The {@link java.lang.Class Class} representing the return + * type of the given {@link java.lang.reflect.Method Method}. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to call the desired + * {@link java.lang.reflect.Method Method}. + * + * @return The T data returned by the desired {@link java.lang.reflect.Method + * Method} if it has a return value, otherwise null. + * + * @throws NoSuchMethodException if a {@link java.lang.reflect.Method + * Method} with the given parameter types does + * not exist. + * @throws NullPointerException if the given + * {@link java.lang.reflect.Method Method} is + * null or if the given {@link java.lang.Class + * Class} is null or if any of the specified + * arguments are null. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed due to insufficient + * permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Method Method} + * cannot be accessed. + * @throws InvocationTargetException if the desired + * {@link java.lang.reflect.Method Method} + * throws an exception during invocation. + * @throws IllegalArgumentException if invalid arguments are passed to the + * corresponding + * {@link java.lang.reflect.Method Method} or + * if the given type T is not assignable to + * the actual return type of the corresponding + * {@link java.lang.reflect.Method Method}. * * @see #getType(Object[]) * @see #getMethod(String, String, Class...) @@ -456,84 +736,129 @@ public static T invokeMethod(final Object instance, final String classPath, * @version 1.0.0 * @since 0.0.1 */ - public static T invokeMethod(final Object instance, final Class clazz, final String methodName, final Class returnType, final Object... arguments) throws NoSuchMethodException, NullPointerException, SecurityException, IllegalAccessException, InvocationTargetException, IllegalArgumentException { + public static T invokeMethod(final Object instance, final Class clazz, final String methodName, + final Class returnType, final Object... arguments) throws NoSuchMethodException, NullPointerException, + SecurityException, IllegalAccessException, InvocationTargetException, IllegalArgumentException { return invokeMethod(instance, getMethod(clazz, methodName, getType(arguments)), returnType, arguments); } /** - * Invokes the specified {@link java.lang.reflect.Method Method} for the given instance. - * - * @param The type corresponding the the return type of the given {@link java.lang.reflect.Method Method}. - * @param instance The {@link java.lang.Object Object} instance calling the given {@link java.lang.reflect.Method Method}. - * @param method The {@link java.lang.reflect.Method Method} being invoked. - * @param returnType The {@link java.lang.Class Class} representing the return type of the given {@link java.lang.reflect.Method Method}. - * @param arguments The {@link java.lang.Object Object} array containing the arguments needed to call the given {@link java.lang.reflect.Method Method}. - * - * @return The T data returned by the desired {@link java.lang.reflect.Method Method} if it has a return value, otherwise null. - * - * @throws NullPointerException if the given {@link java.lang.reflect.Method Method} is null. - * @throws IllegalAccessException if the given {@link java.lang.reflect.Method Method} cannot be accessed. - * @throws InvocationTargetException if the given {@link java.lang.reflect.Method Method} throws an exception during invocation. - * @throws IllegalArgumentException if invalid arguments are passed to the corresponding {@link java.lang.reflect.Method Method} or if the given type T is not assignable to the actual return type of the given {@link java.lang.reflect.Method Method}. + * Invokes the specified {@link java.lang.reflect.Method Method} for the given + * instance. + * + * @param The type corresponding the the return type of the given + * {@link java.lang.reflect.Method Method}. + * @param instance The {@link java.lang.Object Object} instance calling the + * given {@link java.lang.reflect.Method Method}. + * @param method The {@link java.lang.reflect.Method Method} being invoked. + * @param returnType The {@link java.lang.Class Class} representing the return + * type of the given {@link java.lang.reflect.Method Method}. + * @param arguments The {@link java.lang.Object Object} array containing the + * arguments needed to call the given + * {@link java.lang.reflect.Method Method}. + * + * @return The T data returned by the desired {@link java.lang.reflect.Method + * Method} if it has a return value, otherwise null. + * + * @throws NullPointerException if the given + * {@link java.lang.reflect.Method Method} is + * null. + * @throws IllegalAccessException if the given + * {@link java.lang.reflect.Method Method} + * cannot be accessed. + * @throws InvocationTargetException if the given + * {@link java.lang.reflect.Method Method} + * throws an exception during invocation. + * @throws IllegalArgumentException if invalid arguments are passed to the + * corresponding + * {@link java.lang.reflect.Method Method} or + * if the given type T is not assignable to + * the actual return type of the given + * {@link java.lang.reflect.Method Method}. * * @version 1.0.0 * @since 0.0.1 */ - public static T invokeMethod(final Object instance, final Method method, final Class returnType, final Object... arguments) throws NullPointerException, IllegalAccessException, InvocationTargetException, IllegalArgumentException { - Validate.notNull(method, "method cannot be null"); + public static T invokeMethod(final Object instance, final Method method, final Class returnType, + final Object... arguments) + throws NullPointerException, IllegalAccessException, InvocationTargetException, IllegalArgumentException { + Preconditions.checkNotNull(method, "method cannot be null"); if (returnType == null) { - return (T) method.invoke(instance, arguments); // null if void or Object, T will be Object if null is passed in but we still have to cast. + return (T) method.invoke(instance, arguments); // null if void or Object, T will be Object if null is passed + // in but we still have to cast. } else if (method.getReturnType().isAssignableFrom(returnType)) { Object obj = method.invoke(instance, arguments); return (obj == null) ? null : returnType.cast(obj); // null if void or T. } else { - throw new IllegalArgumentException(String.format("The type %s is not assignable from the return type of %s", returnType, method.getName())); + throw new IllegalArgumentException(String.format("The type %s is not assignable from the return type of %s", + returnType, method.getName())); } } // Fields /** - * Returns the {@link java.lang.reflect.Field Field} in the class at the given {@link java.lang.String String} path if it exists. - * - * @param classPath The {@link java.lang.String String} path to the class conatining the desired {@link java.lang.reflect.Field Field}. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. - * - * @return The {@link java.lang.reflect.Field Field} in the class at the given {@link java.lang.String String} path if it exists. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. + * Returns the {@link java.lang.reflect.Field Field} in the class at the given + * {@link java.lang.String String} path if it exists. + * + * @param classPath The {@link java.lang.String String} path to the class + * conatining the desired {@link java.lang.reflect.Field + * Field}. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. + * + * @return The {@link java.lang.reflect.Field Field} in the class at the given + * {@link java.lang.String String} path if it exists. + * + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path contains an invalid path variable. + * @throws ClassNotFoundException if the given {@link java.lang.String String} + * path does not correspond with an existing + * class. + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} + * with the given name does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed due to insufficient permissions. * * @see #getClass(String) * * @version 1.0.0 * @since 0.0.1 */ - public static Field getField(final String classPath, final String fieldName) throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, SecurityException { + public static Field getField(final String classPath, final String fieldName) + throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, SecurityException { return getField(getClass(classPath), fieldName); } /** - * Returns the {@link java.lang.reflect.Field Field} in the given {@link java.lang.Class Class} if it exists. + * Returns the {@link java.lang.reflect.Field Field} in the given + * {@link java.lang.Class Class} if it exists. * - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Field Field}. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. + * @param clazz The {@link java.lang.Class Class} containing the desired + * {@link java.lang.reflect.Field Field}. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. * - * @return The {@link java.lang.reflect.Field Field} in the class at the given {@link java.lang.String String} path if it exists. + * @return The {@link java.lang.reflect.Field Field} in the class at the given + * {@link java.lang.String String} path if it exists. * - * @throws NullPointerException if the given {@link java.lang.Class Class} is null. - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. + * @throws NullPointerException if the given {@link java.lang.Class Class} is + * null. + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with + * the given name does not exist. + * @throws SecurityException if the desired {@link java.lang.reflect.Field + * Field} cannot be accessed due to insufficient + * permissions. * * @version 1.0.0 * @since 0.0.1 */ - public static Field getField(final Class clazz, final String fieldName) throws NullPointerException, NoSuchFieldException, SecurityException { - Validate.notNull(clazz, "clazz cannot be null"); + public static Field getField(final Class clazz, final String fieldName) + throws NullPointerException, NoSuchFieldException, SecurityException { + Preconditions.checkNotNull(clazz, "clazz cannot be null"); // Checks all fields within the specified class. for (final Field field : clazz.getDeclaredFields()) { @@ -552,202 +877,335 @@ public static Field getField(final Class clazz, final String fieldName) throw } /** - * Returns the {@link java.lang.Object Object} value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance whose data is being retrieved. - * @param classPath The {@link java.lang.String String} path to the class conatining the desired {@link java.lang.reflect.Field Field} value. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. - * - * @return the {@link java.lang.Object Object} value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. + * Returns the {@link java.lang.Object Object} value of the + * {@link java.lang.reflect.Field Field} with the given {@link java.lang.String + * String} name for the given instance. + * + * @param instance The {@link java.lang.Object Object} instance whose data is + * being retrieved. + * @param classPath The {@link java.lang.String String} path to the class + * conatining the desired {@link java.lang.reflect.Field Field} + * value. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. + * + * @return the {@link java.lang.Object Object} value of the + * {@link java.lang.reflect.Field Field} with the given + * {@link java.lang.String String} name for the given instance. + * + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path contains an invalid path variable. + * @throws ClassNotFoundException if the given {@link java.lang.String String} + * path does not correspond with an existing + * class. + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} + * with the given name does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed due to insufficient permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed. * * @version 1.0.0 * @since 0.0.1 */ - public static Object getValue(final Object instance, final String classPath, final String fieldName) throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalAccessException { + public static Object getValue(final Object instance, final String classPath, final String fieldName) + throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, SecurityException, + IllegalAccessException { return getValue(instance, getField(getClass(classPath), fieldName), null); } /** - * Returns the {@link java.lang.Object Object} value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance whose data is being retrieved. - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Field Field} value. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. - * - * @return the {@link java.lang.Object Object} value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @throws NullPointerException if the given {@link java.lang.Class Class} is null. - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. + * Returns the {@link java.lang.Object Object} value of the + * {@link java.lang.reflect.Field Field} with the given {@link java.lang.String + * String} name for the given instance. + * + * @param instance The {@link java.lang.Object Object} instance whose data is + * being retrieved. + * @param clazz The {@link java.lang.Class Class} containing the desired + * {@link java.lang.reflect.Field Field} value. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. + * + * @return the {@link java.lang.Object Object} value of the + * {@link java.lang.reflect.Field Field} with the given + * {@link java.lang.String String} name for the given instance. + * + * @throws NullPointerException if the given {@link java.lang.Class Class} is + * null. + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} + * with the given name does not exist. + * @throws SecurityException if the desired {@link java.lang.reflect.Field + * Field} cannot be accessed due to insufficient + * permissions. + * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field + * Field} cannot be accessed. * * @version 1.0.0 * @since 0.0.1 */ - public static Object getValue(final Object instance, final Class clazz, final String fieldName) throws NullPointerException, NoSuchFieldException, SecurityException, IllegalAccessException { + public static Object getValue(final Object instance, final Class clazz, final String fieldName) + throws NullPointerException, NoSuchFieldException, SecurityException, IllegalAccessException { return getValue(instance, getField(clazz, fieldName), null); } /** - * Returns the {@link java.lang.Object Object} value of the {@link java.lang.reflect.Field Field} for the given instance. + * Returns the {@link java.lang.Object Object} value of the + * {@link java.lang.reflect.Field Field} for the given instance. * - * @param instance The {@link java.lang.Object Object} instance whose data is being retrieved. - * @param field The {@link java.lang.reflect.Field Field} containing the desired value. + * @param instance The {@link java.lang.Object Object} instance whose data is + * being retrieved. + * @param field The {@link java.lang.reflect.Field Field} containing the + * desired value. * - * @return the {@link java.lang.Object Object} value of the {@link java.lang.reflect.Field Field} for the given instance. + * @return the {@link java.lang.Object Object} value of the + * {@link java.lang.reflect.Field Field} for the given instance. * - * @throws NullPointerException if the given {@link java.lang.reflect.Field Field} is null. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. + * @throws NullPointerException if the given {@link java.lang.reflect.Field + * Field} is null. + * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field + * Field} cannot be accessed. * * @version 1.0.0 * @since 0.0.1 */ - public static Object getValue(final Object instance, final Field field) throws NullPointerException, IllegalAccessException { + public static Object getValue(final Object instance, final Field field) + throws NullPointerException, IllegalAccessException { return getValue(instance, field, null); } /** - * Returns the T value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @param The type corresponding the the type of the desired {@link java.lang.reflect.Field Field}. - * @param instance The {@link java.lang.Object Object} instance containing the desired {@link java.lang.reflect.Field Field} value. - * @param classPath The {@link java.lang.String String} path to the class conatining the desired {@link java.lang.reflect.Field Field} value. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. - * @param type The {@link java.lang.Class Class} representing the type of the desired {@link java.lang.reflect.Field Field} value. - * - * @return the T value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable or if the given type T is not assignable to the actual type of the desired {@link java.lang.reflect.Field Field}. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. + * Returns the T value of the {@link java.lang.reflect.Field Field} with the + * given {@link java.lang.String String} name for the given instance. + * + * @param The type corresponding the the type of the desired + * {@link java.lang.reflect.Field Field}. + * @param instance The {@link java.lang.Object Object} instance containing the + * desired {@link java.lang.reflect.Field Field} value. + * @param classPath The {@link java.lang.String String} path to the class + * conatining the desired {@link java.lang.reflect.Field Field} + * value. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. + * @param type The {@link java.lang.Class Class} representing the type of + * the desired {@link java.lang.reflect.Field Field} value. + * + * @return the T value of the {@link java.lang.reflect.Field Field} with the + * given {@link java.lang.String String} name for the given instance. + * + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path contains an invalid path variable or if + * the given type T is not assignable to the + * actual type of the desired + * {@link java.lang.reflect.Field Field}. + * @throws ClassNotFoundException if the given {@link java.lang.String String} + * path does not correspond with an existing + * class. + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} + * with the given name does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed due to insufficient permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed. * * @version 1.0.0 * @since 0.0.1 */ - public static T getValue(final Object instance, final String classPath, final String fieldName, final Class type) throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalAccessException { + public static T getValue(final Object instance, final String classPath, final String fieldName, + final Class type) throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, + SecurityException, IllegalAccessException { return getValue(instance, getField(getClass(classPath), fieldName), type); } /** - * Returns the T value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @param The type corresponding the the type of the desired {@link java.lang.reflect.Field Field}. - * @param instance The {@link java.lang.Object Object} instance containing the desired {@link java.lang.reflect.Field Field} value. - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Field Field} value. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. - * @param type The {@link java.lang.Class Class} representing the type of the desired {@link java.lang.reflect.Field Field} value. - * - * @return the T value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. - * @throws IllegalArgumentException if the given type T is not assignable to the actual type of the desired {@link java.lang.reflect.Field Field}. + * Returns the T value of the {@link java.lang.reflect.Field Field} with the + * given {@link java.lang.String String} name for the given instance. + * + * @param The type corresponding the the type of the desired + * {@link java.lang.reflect.Field Field}. + * @param instance The {@link java.lang.Object Object} instance containing the + * desired {@link java.lang.reflect.Field Field} value. + * @param clazz The {@link java.lang.Class Class} containing the desired + * {@link java.lang.reflect.Field Field} value. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. + * @param type The {@link java.lang.Class Class} representing the type of + * the desired {@link java.lang.reflect.Field Field} value. + * + * @return the T value of the {@link java.lang.reflect.Field Field} with the + * given {@link java.lang.String String} name for the given instance. + * + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} + * with the given name does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed due to insufficient permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed. + * @throws IllegalArgumentException if the given type T is not assignable to the + * actual type of the desired + * {@link java.lang.reflect.Field Field}. * * @version 1.0.0 * @since 0.0.1 */ - public static T getValue(final Object instance, final Class clazz, final String fieldName, final Class type) throws NoSuchFieldException, SecurityException, IllegalAccessException, IllegalArgumentException { + public static T getValue(final Object instance, final Class clazz, final String fieldName, + final Class type) + throws NoSuchFieldException, SecurityException, IllegalAccessException, IllegalArgumentException { return getValue(instance, getField(clazz, fieldName), type); } /** - * Returns the T value of the {@link java.lang.reflect.Field Field} for the given instance. - * - * @param The type corresponding the the type of the desired {@link java.lang.reflect.Field Field}. - * @param instance The {@link java.lang.Object Object} instance containing the desired {@link java.lang.reflect.Field Field} value. - * @param field The {@link java.lang.reflect.Field Field} containing the desired value. - * @param type The {@link java.lang.Class Class} representing the type of the desired {@link java.lang.reflect.Field Field} value. - * - * @return the T value of the {@link java.lang.reflect.Field Field} for the given instance. - * - * @throws NullPointerException if the given {@link java.lang.reflect.Field Field} is null. - * @throws IllegalArgumentException if the given type T is not assignable to the actual type of the given {@link java.lang.reflect.Field Field}. - * @throws IllegalAccessException if the given {@link java.lang.reflect.Field Field} cannot be accessed. + * Returns the T value of the {@link java.lang.reflect.Field Field} for the + * given instance. + * + * @param The type corresponding the the type of the desired + * {@link java.lang.reflect.Field Field}. + * @param instance The {@link java.lang.Object Object} instance containing the + * desired {@link java.lang.reflect.Field Field} value. + * @param field The {@link java.lang.reflect.Field Field} containing the + * desired value. + * @param type The {@link java.lang.Class Class} representing the type of + * the desired {@link java.lang.reflect.Field Field} value. + * + * @return the T value of the {@link java.lang.reflect.Field Field} for the + * given instance. + * + * @throws NullPointerException if the given {@link java.lang.reflect.Field + * Field} is null. + * @throws IllegalArgumentException if the given type T is not assignable to the + * actual type of the given + * {@link java.lang.reflect.Field Field}. + * @throws IllegalAccessException if the given {@link java.lang.reflect.Field + * Field} cannot be accessed. * * @version 1.0.0 * @since 0.0.1 */ - public static T getValue(final Object instance, final Field field, final Class type) throws NullPointerException, IllegalArgumentException, IllegalAccessException { - Validate.notNull(field, "field cannot be null"); + public static T getValue(final Object instance, final Field field, final Class type) + throws NullPointerException, IllegalArgumentException, IllegalAccessException { + Preconditions.checkNotNull(field, "field cannot be null"); if (type == null) { - return (T) field.get(instance); // null or Object, T will be Object if null is passed in but we still have to cast. + return (T) field.get(instance); // null or Object, T will be Object if null is passed in but we still have + // to cast. } else if (field.getType().isAssignableFrom(type)) { Object obj = field.get(instance); return (obj == null) ? null : type.cast(obj); // null or T. } else { - throw new IllegalArgumentException(String.format("The type %s is not assignable from the type of %s", type, field.getName())); + throw new IllegalArgumentException( + String.format("The type %s is not assignable from the type of %s", type, field.getName())); } } /** - * Sets the value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance containing the desired {@link java.lang.reflect.Field Field} to be modified. - * @param classPath The {@link java.lang.String String} path to the class conatining the desired {@link java.lang.reflect.Field Field} to be modified. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. - * @param value The new value of the desired {@link java.lang.reflect.Field Field}. - * - * @throws IllegalArgumentException if the given {@link java.lang.String String} path contains an invalid path variable or if the given value cannot be assigned to the desired {@link java.lang.reflect.Field Field}. - * @throws ClassNotFoundException if the given {@link java.lang.String String} path does not correspond with an existing class. - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. + * Sets the value of the {@link java.lang.reflect.Field Field} with the given + * {@link java.lang.String String} name for the given instance. + * + * @param instance The {@link java.lang.Object Object} instance containing the + * desired {@link java.lang.reflect.Field Field} to be + * modified. + * @param classPath The {@link java.lang.String String} path to the class + * conatining the desired {@link java.lang.reflect.Field Field} + * to be modified. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. + * @param value The new value of the desired {@link java.lang.reflect.Field + * Field}. + * + * @throws IllegalArgumentException if the given {@link java.lang.String String} + * path contains an invalid path variable or if + * the given value cannot be assigned to the + * desired {@link java.lang.reflect.Field + * Field}. + * @throws ClassNotFoundException if the given {@link java.lang.String String} + * path does not correspond with an existing + * class. + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} + * with the given name does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed due to insufficient permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed. * * @version 1.0.0 * @since 0.0.1 */ - public static void setValue(final Object instance, final String classPath, final String fieldName, final Object value) throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalAccessException { + public static void setValue(final Object instance, final String classPath, final String fieldName, + final Object value) throws IllegalArgumentException, ClassNotFoundException, NoSuchFieldException, + SecurityException, IllegalAccessException { getField(getClass(classPath), fieldName).set(instance, value); } /** - * Sets the value of the {@link java.lang.reflect.Field Field} with the given {@link java.lang.String String} name for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance containing the desired {@link java.lang.reflect.Field Field} to be modified. - * @param clazz The {@link java.lang.Class Class} containing the desired {@link java.lang.reflect.Field Field} to be modified. - * @param fieldName The {@link java.lang.String String} name of the desired {@link java.lang.reflect.Field Field}. - * @param value The new value of the desired {@link java.lang.reflect.Field Field}. - * - * @throws NullPointerException if the given {@link java.lang.Class Class} is null. - * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} with the given name does not exist. - * @throws SecurityException if the desired {@link java.lang.reflect.Field Field} cannot be accessed due to insufficient permissions. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. - * @throws IllegalArgumentException if the given value cannot be assigned to the desired {@link java.lang.reflect.Field Field}. + * Sets the value of the {@link java.lang.reflect.Field Field} with the given + * {@link java.lang.String String} name for the given instance. + * + * @param instance The {@link java.lang.Object Object} instance containing the + * desired {@link java.lang.reflect.Field Field} to be + * modified. + * @param clazz The {@link java.lang.Class Class} containing the desired + * {@link java.lang.reflect.Field Field} to be modified. + * @param fieldName The {@link java.lang.String String} name of the desired + * {@link java.lang.reflect.Field Field}. + * @param value The new value of the desired {@link java.lang.reflect.Field + * Field}. + * + * @throws NullPointerException if the given {@link java.lang.Class Class} + * is null. + * @throws NoSuchFieldException if a {@link java.lang.reflect.Field Field} + * with the given name does not exist. + * @throws SecurityException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed due to insufficient permissions. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed. + * @throws IllegalArgumentException if the given value cannot be assigned to the + * desired {@link java.lang.reflect.Field + * Field}. * * @version 1.0.0 * @since 0.0.1 */ - public static void setValue(final Object instance, final Class clazz, final String fieldName, final Object value) throws NullPointerException, NoSuchFieldException, SecurityException, IllegalAccessException, IllegalArgumentException { + public static void setValue(final Object instance, final Class clazz, final String fieldName, final Object value) + throws NullPointerException, NoSuchFieldException, SecurityException, IllegalAccessException, + IllegalArgumentException { getField(clazz, fieldName).set(instance, value); } /** - * Sets the value of the given {@link java.lang.reflect.Field Field} for the given instance. - * - * @param instance The {@link java.lang.Object Object} instance containing the given {@link java.lang.reflect.Field Field} to be modified. - * @param field The {@link java.lang.reflect.Field Field} to be modified. - * @param value The new value of the desired {@link java.lang.reflect.Field Field}. - * - * @throws NullPointerException if the given {@link java.lang.reflect.Field Field} is null. - * @throws IllegalAccessException if the desired {@link java.lang.reflect.Field Field} cannot be accessed. - * @throws IllegalArgumentException if the given value cannot be assigned to the desired {@link java.lang.reflect.Field Field}. + * Sets the value of the given {@link java.lang.reflect.Field Field} for the + * given instance. + * + * @param instance The {@link java.lang.Object Object} instance containing the + * given {@link java.lang.reflect.Field Field} to be modified. + * @param field The {@link java.lang.reflect.Field Field} to be modified. + * @param value The new value of the desired {@link java.lang.reflect.Field + * Field}. + * + * @throws NullPointerException if the given {@link java.lang.reflect.Field + * Field} is null. + * @throws IllegalAccessException if the desired + * {@link java.lang.reflect.Field Field} cannot + * be accessed. + * @throws IllegalArgumentException if the given value cannot be assigned to the + * desired {@link java.lang.reflect.Field + * Field}. * * @version 1.0.0 * @since 0.0.1 */ - public static void setValue(final Object instance, final Field field, final Object value) throws NullPointerException, IllegalAccessException, IllegalArgumentException { - Validate.notNull(field, "field cannot be null"); + public static void setValue(final Object instance, final Field field, final Object value) + throws NullPointerException, IllegalAccessException, IllegalArgumentException { + Preconditions.checkNotNull(field, "field cannot be null"); field.set(instance, value); } @@ -785,30 +1243,37 @@ public String getActual() { } /** - * Determines if the {@link java.util.String String} alias corresponds with an existing {@link PathVariable PathVariable}. + * Determines if the {@link java.util.String String} alias corresponds with an + * existing {@link PathVariable PathVariable}. * * @param alias The {@link java.util.String String} alias of potential variable. * - * @return true if the {@link java.util.String String} alias corresponds with an existing {@link PathVariable PathVariable}, false otherwise. + * @return true if the {@link java.util.String String} alias corresponds with an + * existing {@link PathVariable PathVariable}, false otherwise. * * @version 1.0.0 - * @since 0.0.1 + * @since 0.0.1 */ public static boolean isValidAlias(final String alias) { return VARIABLE_MAP.containsKey(alias.toUpperCase()); } /** - * Returns the {@link PathVariable PathVariable} with the matching {@link java.util.String String} alias if it exists. + * Returns the {@link PathVariable PathVariable} with the matching + * {@link java.util.String String} alias if it exists. * - * @param alias The {@link java.util.String String} alias of the desired variable. + * @param alias The {@link java.util.String String} alias of the desired + * variable. * - * @return The {@link PathVariable PathVariable} with the matching {@link java.util.String String} alias. + * @return The {@link PathVariable PathVariable} with the matching + * {@link java.util.String String} alias. * - * @throws IllegalArgumentException if the given {@link java.util.String String} alias does not correspond with a valid {@link PathVariable PathVariable}. + * @throws IllegalArgumentException if the given {@link java.util.String String} + * alias does not correspond with a valid + * {@link PathVariable PathVariable}. * * @version 1.0.0 - * @since 0.0.1 + * @since 0.0.1 */ public static PathVariable fromAlias(final String alias) throws IllegalArgumentException { if (!isValidAlias(alias)) { diff --git a/src/test/java/com/projectkorra/core/ProjectKorraTest.java b/src/test/java/com/projectkorra/core/ProjectKorraTest.java index 33a7464..a132c89 100644 --- a/src/test/java/com/projectkorra/core/ProjectKorraTest.java +++ b/src/test/java/com/projectkorra/core/ProjectKorraTest.java @@ -1,34 +1,5 @@ package com.projectkorra.core; -import be.seeseemelk.mockbukkit.MockBukkit; -import be.seeseemelk.mockbukkit.ServerMock; - -import org.bukkit.event.player.PlayerJoinEvent; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; - public class ProjectKorraTest { - private ServerMock server; - private ProjectKorra plugin; - - @BeforeEach - public void setUp() { - server = MockBukkit.mock(); - plugin = (ProjectKorra) MockBukkit.load(ProjectKorra.class); - } - - @Test - public void testPlayerCanJoin() { - // This is a test to ensure MockBukkit it set up correctly. In the future, we will utilize this to a greater extent. - server.addPlayer(); - server.getPluginManager().assertEventFired(PlayerJoinEvent.class); - } - @AfterEach - public void tearDown() { - MockBukkit.unmock(); - } }