use of com.elmakers.mine.bukkit.spell.TargetingSpell in project MagicPlugin by elBukkit.
the class CastContext method setSpell.
public void setSpell(Spell spell) {
this.spell = spell;
if (spell instanceof BaseSpell) {
this.baseSpell = (BaseSpell) spell;
}
if (spell instanceof MageSpell) {
MageSpell mageSpell = (MageSpell) spell;
this.mage = mageSpell.getMage();
this.wand = mage.getActiveWand();
this.mageClass = (this.wand == null ? this.mage.getActiveClass() : this.wand.getMageClass());
}
if (spell instanceof UndoableSpell) {
this.undoSpell = (UndoableSpell) spell;
undoList = this.undoSpell.getUndoList();
}
if (spell instanceof TargetingSpell) {
this.targetingSpell = (TargetingSpell) spell;
}
if (spell instanceof BlockSpell) {
this.blockSpell = (BlockSpell) spell;
}
if (spell instanceof BrushSpell) {
this.brushSpell = (BrushSpell) spell;
}
}
use of com.elmakers.mine.bukkit.spell.TargetingSpell in project MagicPlugin by elBukkit.
the class AllEntitiesAction method addEntities.
@Override
public void addEntities(CastContext context, List<WeakReference<Entity>> entities) {
Spell spell = context.getSpell();
Entity sourceEntity = context.getMage().getEntity();
Location sourceLocation = context.getLocation();
if (sourceLocation == null && !targetAllWorlds) {
return;
}
Class<?> targetType = Player.class;
if (spell instanceof TargetingSpell) {
targetType = ((TargetingSpell) spell).getTargetEntityType();
}
if (targetType == Player.class) {
Collection<? extends Player> players = context.getPlugin().getServer().getOnlinePlayers();
for (Player player : players) {
if ((context.getTargetsCaster() || player != sourceEntity) && (targetAllWorlds || (sourceLocation != null && sourceLocation.getWorld().equals(player.getWorld()))) && spell.canTarget(player)) {
entities.add(new WeakReference<Entity>(player));
}
}
} else {
List<World> worlds;
if (targetAllWorlds) {
worlds = Bukkit.getWorlds();
} else {
worlds = new ArrayList<>();
worlds.add(sourceLocation.getWorld());
}
for (World world : worlds) {
List<Entity> candidates = world.getEntities();
for (Entity entity : candidates) {
if (spell.canTarget(entity) && (context.getTargetsCaster() || entity != sourceEntity)) {
entities.add(new WeakReference<>(entity));
}
}
}
}
}
Aggregations