/*
* This file is part of RPG Items.
*
* RPG Items is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RPG Items is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RPG Items. If not, see <http://www.gnu.org/licenses/>.
*/
package think.rpgitems.power;
import gnu.trove.map.hash.TObjectIntHashMap;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import think.rpgitems.item.RPGItem;
public abstract class Power {
public static HashMap<String, Class<? extends Power>> powers = new HashMap<String, Class<? extends Power>>();
public static TObjectIntHashMap<String> powerUsage = new TObjectIntHashMap<String>();
public RPGItem item;
public Power() {
}
public abstract void init(ConfigurationSection s);
public abstract void save(ConfigurationSection s);
public abstract String getName();
public abstract String displayText(String locale);
public static Entity[] getNearbyEntities(Location l, double radius) {
int iRadius = (int) radius;
int chunkRadius = iRadius < 16 ? 1 : (iRadius - (iRadius % 16)) / 16;
HashSet<Entity> radiusEntities = new HashSet<Entity>();
for (int chX = 0 - chunkRadius; chX <= chunkRadius; chX++) {
for (int chZ = 0 - chunkRadius; chZ <= chunkRadius; chZ++) {
int x = (int) l.getX(), y = (int) l.getY(), z = (int) l.getZ();
for (Entity e : new Location(l.getWorld(), x + (chX * 16), y, z + (chZ * 16)).getChunk().getEntities()) {
if (e.getLocation().distance(l) <= radius && e.getLocation().getBlock() != l.getBlock())
radiusEntities.add(e);
}
}
}
return radiusEntities.toArray(new Entity[radiusEntities.size()]);
}
}