Search in sources :

Example 1 with TargetingSpell

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;
    }
}
Also used : BrushSpell(com.elmakers.mine.bukkit.spell.BrushSpell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) TargetingSpell(com.elmakers.mine.bukkit.spell.TargetingSpell) BlockSpell(com.elmakers.mine.bukkit.spell.BlockSpell) UndoableSpell(com.elmakers.mine.bukkit.spell.UndoableSpell)

Example 2 with TargetingSpell

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));
                }
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) World(org.bukkit.World) TargetingSpell(com.elmakers.mine.bukkit.spell.TargetingSpell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) TargetingSpell(com.elmakers.mine.bukkit.spell.TargetingSpell) Location(org.bukkit.Location)

Aggregations

BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)2 TargetingSpell (com.elmakers.mine.bukkit.spell.TargetingSpell)2 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 BlockSpell (com.elmakers.mine.bukkit.spell.BlockSpell)1 BrushSpell (com.elmakers.mine.bukkit.spell.BrushSpell)1 UndoableSpell (com.elmakers.mine.bukkit.spell.UndoableSpell)1 Location (org.bukkit.Location)1 World (org.bukkit.World)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1