AFKGuard allows you to detect even the most tricky AFK machines and cheats, by being fully configurable and accessible!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

package com.entryrise.afkguard.utils;
import java.io.File;
import org.apache.commons.lang.RandomStringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.WorldBorder;
import org.bukkit.configuration.file.YamlConfiguration;
import com.entryrise.afkguard.Main;
public class Others {
public static boolean isInsideBorder(Location loc) {
WorldBorder border = loc.getWorld().getWorldBorder();
double radius = border.getSize() / 2;
Location location = loc, center = border.getCenter();
return center.distanceSquared(location) < (radius * radius);
}
public static YamlConfiguration getConfig(File f, int version) {
YamlConfiguration fc = new YamlConfiguration();
if (!f.exists()) {
f.getParentFile().mkdirs();
Main.p.saveResource(f.getName(), false);
}
try {
fc.load(f);
if (fc.contains("version")) {
if (fc.getInt("version") != version) {
Bukkit.getLogger().info(Main.PREFIX + "Updating " + f.getName() + " file!");
f.renameTo(getOldFile(f));
Main.p.saveResource(f.getName(), false);
fc.load(f);
}
} else {
Bukkit.getLogger().info(Main.PREFIX + "Updating " + f.getName() + " file!");
f.renameTo(getOldFile(f));
Main.p.saveResource(f.getName(), false);
fc.load(f);
}
} catch (Exception e) {
e.printStackTrace();
}
return fc;
}
private static File getOldFile(File f) {
return new File(f.getParentFile(), f.getName() + "." + RandomStringUtils.randomAlphanumeric(3) + ".old");
}
public static String serializeLocation(Location loc) {
if (loc.getWorld() == null) {
System.out.println("world doesn't exist man!");
}
return loc.getWorld().getName() + ";" + loc.getX() + ";" + loc.getY() + ";" + loc.getZ() + ";" + loc.getYaw() + ";"
+ loc.getPitch();
}
public static Location deserializeLocation(String loc) {
String[] rawloc = loc.split(";");
return new Location(Bukkit.getWorld(rawloc[0]), Double.valueOf(rawloc[1]), Double.valueOf(rawloc[2]),
Double.valueOf(rawloc[3]), Float.valueOf(rawloc[4]), Float.valueOf(rawloc[5]));
}
}