mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-30 20:37:52 +01:00
Random formatting + java doc.
This commit is contained in:
parent
d8d6c5ab60
commit
1a87a9d0da
@ -8,6 +8,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@ -18,7 +19,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* The Class CheckUtils.
|
||||
* Random auxiliary gear, some might have general quality.
|
||||
*/
|
||||
public class CheckUtils {
|
||||
|
||||
@ -28,7 +29,7 @@ public class CheckUtils {
|
||||
/** Decimal format for "#.###" */
|
||||
public static final DecimalFormat fdec3 = new DecimalFormat();
|
||||
|
||||
static{
|
||||
static {
|
||||
DecimalFormatSymbols sym = fdec3.getDecimalFormatSymbols();
|
||||
sym.setDecimalSeparator('.');
|
||||
fdec3.setDecimalFormatSymbols(sym);
|
||||
@ -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
|
||||
* the player
|
||||
@ -55,14 +57,13 @@ public class CheckUtils {
|
||||
* the precision
|
||||
* @return the double
|
||||
*/
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
|
||||
// Get the eye location of the player.
|
||||
final Location eyes = player.getEyeLocation();
|
||||
|
||||
final double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2)
|
||||
+ Math.pow(eyes.getZ() - targetZ, 2));
|
||||
final double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));
|
||||
|
||||
// Get the view direction of the player.
|
||||
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(y - yPrediction) - (targetHeight / 2 + precision), 0.0D);
|
||||
|
||||
if (off > 1)
|
||||
off = Math.sqrt(off);
|
||||
if (off > 1) off = Math.sqrt(off);
|
||||
|
||||
return off;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the distance between two location, because for Bukkit distance is the distance squared and
|
||||
* distanceSquared is the distance non-squared.
|
||||
* Calculate the distance between two location, because for Bukkit distance
|
||||
* is the distance squared and distanceSquared is the distance non-squared.
|
||||
*
|
||||
* @param location1
|
||||
* the location1
|
||||
@ -97,9 +97,9 @@ public class CheckUtils {
|
||||
* the location2
|
||||
* @return the double
|
||||
*/
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,15 +113,16 @@ public class CheckUtils {
|
||||
* the minimum value of the correlation coefficient
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* modification (deletion, insertion or substitution).
|
||||
* This is the number of changes needed to change one String into another,
|
||||
* where each change is a single character modification (deletion, insertion or substitution).
|
||||
*
|
||||
* @param s
|
||||
* the first String, must not be null
|
||||
@ -130,16 +131,13 @@ public class CheckUtils {
|
||||
* @return result distance
|
||||
*/
|
||||
private static int levenshteinDistance(CharSequence s, CharSequence t) {
|
||||
if (s == null || t == null)
|
||||
throw new IllegalArgumentException("Strings must not be null");
|
||||
if (s == null || t == null) throw new IllegalArgumentException("Strings must not be null");
|
||||
|
||||
int n = s.length();
|
||||
int m = t.length();
|
||||
|
||||
if (n == 0)
|
||||
return m;
|
||||
else if (m == 0)
|
||||
return n;
|
||||
if (n == 0) return m;
|
||||
else if (m == 0) return n;
|
||||
|
||||
if (n > m) {
|
||||
final CharSequence tmp = s;
|
||||
@ -182,14 +180,16 @@ public class CheckUtils {
|
||||
|
||||
/**
|
||||
* Join parts with link.
|
||||
*
|
||||
* @param input
|
||||
* @param link
|
||||
* @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));
|
||||
boolean first = true;
|
||||
for (final Object obj : input){
|
||||
for (final Object obj : input) {
|
||||
if (!first) builder.append(link);
|
||||
builder.append(obj.toString());
|
||||
first = false;
|
||||
@ -199,11 +199,13 @@ public class CheckUtils {
|
||||
|
||||
/**
|
||||
* Convenience method.
|
||||
*
|
||||
* @param parts
|
||||
* @param link
|
||||
* @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));
|
||||
}
|
||||
|
||||
@ -307,15 +309,15 @@ public class CheckUtils {
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
public static double getHeight(final Entity entity) {
|
||||
final net.minecraft.server.Entity mcEntity = ((CraftEntity)entity).getHandle();
|
||||
final net.minecraft.server.Entity mcEntity = ((CraftEntity) entity).getHandle();
|
||||
final double entityHeight = mcEntity.height;
|
||||
if (entity instanceof LivingEntity){
|
||||
if (entity instanceof LivingEntity) {
|
||||
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
|
||||
}
|
||||
else return mcEntity.height;
|
||||
} else return mcEntity.height;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user