- Баллы
- 123
- Имя в Minecraft
- Reality_SC
Я написал, как знал. Ты знаешь лучший вариант - исправь мой (или напиши новый) и приведи сюда полный результат. По себе сужу - проще взять готовую рабочую процедуру или даже написать с нуля собственную, чем ковыряться-исправлять в чужих.
Java:
// Где-то внутри твоего главного класса плагина
private static class LocationEx
{
Location loc;
String caption;
int radiusSq;
LocationEx(Location l, String c, int r)
{
this.loc = l;
this.caption = c;
this.radiusSq = r * r;
}
boolean isInside(Location test)
{
return test.getWorld().equals(loc.getWorld()) && test.distanceSquared(loc) <= radiusSq;
}
}
private final Set<LocationEx> locations = new HashSet<>();
@Override
public void onEnable()
{
locations.clear();
FileConfiguration config = getConfig();
for(String point : config.getConfigurationSection("Points").getKeys(false))
locations.add(new LocationEx(
new Location(
getServer().getWorld(config.getString("Points." + point + ".world")),
config.getDouble("Points." + point + ".x"),
config.getDouble("Points." + point + ".y"),
config.getDouble("Points." + point + ".z")),
point,
config.getInt("Radius")));
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
final Player player = event.getPlayer();
final Location loc = player.getLocation();
for(LocationEx locEx : locations)
if(locEx.isInside(loc))
{
player.setHealth(10.0);
return;
}
}
}