Random formatting + java doc.

This commit is contained in:
asofold 2012-11-05 05:14:58 +01:00
parent d8d6c5ab60
commit 1a87a9d0da

View File

@ -8,6 +8,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -18,7 +19,7 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
/** /**
* The Class CheckUtils. * Random auxiliary gear, some might have general quality.
*/ */
public class CheckUtils { public class CheckUtils {
@ -37,7 +38,8 @@ public class CheckUtils {
} }
/** /**
* Check if a player looks at a target of a specific size, with a specific precision value (roughly). * Check if a player looks at a target of a specific size, with a specific
* precision value (roughly).
* *
* @param player * @param player
* the player * the player
@ -55,14 +57,13 @@ public class CheckUtils {
* the precision * the precision
* @return the double * @return the double
*/ */
public static double directionCheck(final Player player, final double targetX, final double targetY, public static double directionCheck(final Player player, final double targetX, final double targetY, final double targetZ, final double targetWidth, final double targetHeight, final double precision)
final double targetZ, final double targetWidth, final double targetHeight, final double precision) { {
// Get the eye location of the player. // Get the eye location of the player.
final Location eyes = player.getEyeLocation(); final Location eyes = player.getEyeLocation();
final double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) final double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));
+ Math.pow(eyes.getZ() - targetZ, 2));
// Get the view direction of the player. // Get the view direction of the player.
final Vector direction = eyes.getDirection(); final Vector direction = eyes.getDirection();
@ -81,15 +82,14 @@ public class CheckUtils {
off += Math.max(Math.abs(z - zPrediction) - (targetWidth / 2 + precision), 0.0D); off += Math.max(Math.abs(z - zPrediction) - (targetWidth / 2 + precision), 0.0D);
off += Math.max(Math.abs(y - yPrediction) - (targetHeight / 2 + precision), 0.0D); off += Math.max(Math.abs(y - yPrediction) - (targetHeight / 2 + precision), 0.0D);
if (off > 1) if (off > 1) off = Math.sqrt(off);
off = Math.sqrt(off);
return off; return off;
} }
/** /**
* Calculate the distance between two location, because for Bukkit distance is the distance squared and * Calculate the distance between two location, because for Bukkit distance
* distanceSquared is the distance non-squared. * is the distance squared and distanceSquared is the distance non-squared.
* *
* @param location1 * @param location1
* the location1 * the location1
@ -97,9 +97,9 @@ public class CheckUtils {
* the location2 * the location2
* @return the double * @return the double
*/ */
public static double distance(final Location location1, final Location location2) { public static double distance(final Location location1, final Location location2)
return Math.sqrt(Math.pow(location2.getX() - location1.getX(), 2) {
+ Math.pow(location2.getY() - location1.getY(), 2) + Math.pow(location2.getZ() - location1.getZ(), 2)); return Math.sqrt(Math.pow(location2.getX() - location1.getX(), 2) + Math.pow(location2.getY() - location1.getY(), 2) + Math.pow(location2.getZ() - location1.getZ(), 2));
} }
/** /**
@ -113,15 +113,16 @@ public class CheckUtils {
* the minimum value of the correlation coefficient * the minimum value of the correlation coefficient
* @return result true if the two Strings are similar, false otherwise * @return result true if the two Strings are similar, false otherwise
*/ */
public static boolean isSimilar(final String s, final String t, final float threshold) { public static boolean isSimilar(final String s, final String t, final float threshold)
{
return 1.0f - (float) levenshteinDistance(s, t) / Math.max(1.0, Math.max(s.length(), t.length())) > threshold; return 1.0f - (float) levenshteinDistance(s, t) / Math.max(1.0, Math.max(s.length(), t.length())) > threshold;
} }
/** /**
* Find the Levenshtein distance between two Strings. * Find the Levenshtein distance between two Strings.
* *
* This is the number of changes needed to change one String into another, where each change is a single character * This is the number of changes needed to change one String into another,
* modification (deletion, insertion or substitution). * where each change is a single character modification (deletion, insertion or substitution).
* *
* @param s * @param s
* the first String, must not be null * the first String, must not be null
@ -130,16 +131,13 @@ public class CheckUtils {
* @return result distance * @return result distance
*/ */
private static int levenshteinDistance(CharSequence s, CharSequence t) { private static int levenshteinDistance(CharSequence s, CharSequence t) {
if (s == null || t == null) if (s == null || t == null) throw new IllegalArgumentException("Strings must not be null");
throw new IllegalArgumentException("Strings must not be null");
int n = s.length(); int n = s.length();
int m = t.length(); int m = t.length();
if (n == 0) if (n == 0) return m;
return m; else if (m == 0) return n;
else if (m == 0)
return n;
if (n > m) { if (n > m) {
final CharSequence tmp = s; final CharSequence tmp = s;
@ -182,11 +180,13 @@ public class CheckUtils {
/** /**
* Join parts with link. * Join parts with link.
*
* @param input * @param input
* @param link * @param link
* @return * @return
*/ */
public static <O extends Object> String join(final Collection<O> input, final String link){ public static <O extends Object> String join(final Collection<O> input, final String link)
{
final StringBuilder builder = new StringBuilder(Math.max(300, input.size() * 10)); final StringBuilder builder = new StringBuilder(Math.max(300, input.size() * 10));
boolean first = true; boolean first = true;
for (final Object obj : input) { for (final Object obj : input) {
@ -199,11 +199,13 @@ public class CheckUtils {
/** /**
* Convenience method. * Convenience method.
*
* @param parts * @param parts
* @param link * @param link
* @return * @return
*/ */
public static <O extends Object> boolean scheduleOutputJoined(final List<O> parts, String link){ public static <O extends Object> boolean scheduleOutputJoined(final List<O> parts, String link)
{
return scheduleOutput(join(parts, link)); return scheduleOutput(join(parts, link));
} }
@ -307,6 +309,7 @@ public class CheckUtils {
/** /**
* Get the height from getLocation().getY() to head / above head.<br> * Get the height from getLocation().getY() to head / above head.<br>
* NOTE: Currently this is pretty much useless, it returns 1.0 most of the time. * NOTE: Currently this is pretty much useless, it returns 1.0 most of the time.
*
* @param entity * @param entity
* @return * @return
*/ */
@ -315,7 +318,6 @@ public class CheckUtils {
final double entityHeight = mcEntity.height; final double entityHeight = mcEntity.height;
if (entity instanceof LivingEntity) { if (entity instanceof LivingEntity) {
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
} } else return mcEntity.height;
else return mcEntity.height;
} }
} }