GoTo Objective now properly uses blocks as a calculation for range

This commit is contained in:
ASangarin 2020-12-04 20:02:45 +01:00
parent 363b09f3d4
commit 5379bfbf0b

View File

@ -16,14 +16,14 @@ import net.mmogroup.mmolib.api.MMOLineConfig;
public class GoToObjective extends Objective {
private final Location loc;
private final int rangeSquared;
private final double range;
public GoToObjective(ConfigurationSection section, MMOLineConfig config) {
super(section);
config.validate("range", "world", "x", "y", "z");
rangeSquared = config.getInt("range") ^ 2;
range = config.getDouble("range");
World world = Bukkit.getWorld(config.getString("world"));
Validate.notNull(world, "Could not find world " + config.getString("world"));
@ -46,9 +46,10 @@ public class GoToObjective extends Objective {
return;
Player player = event.getPlayer();
if (getPlayer().isOnline() && player.equals(getPlayer().getPlayer()))
if (player.getWorld().equals(loc.getWorld()) && player.getLocation().distanceSquared(loc) < rangeSquared)
if (getPlayer().isOnline() && player.equals(getPlayer().getPlayer())) {
if (player.getWorld().equals(loc.getWorld()) && ((player.getLocation().distance(loc) - 0.5d) < range))
getQuestProgress().completeObjective();
}
}
@Override