Хостинг серверов Minecraft playvds.com
  1. Вы находитесь в русском сообществе Bukkit. Мы - администраторы серверов Minecraft, разрабатываем собственные плагины и переводим на русский язык плагины наших собратьев из других стран.
    Dismiss Notice

Помогите В разработке плагина

Discussion in 'Разработка плагинов для новичков' started by Fresh624, Jan 11, 2015.

  1. Reality_SC

    Reality_SC Старожил Пользователь

    Trophy Points:
    123
    Имя в Minecraft:
    Reality_SC
    Code:
       // Где-то внутри твоего главного класса плагина
        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;
                }
            }
        }
    В onDisable тоже лучше делать .clear(), так правильно.
     
  2. Хостинг MineCraft
    <

Share This Page