Search in sources :

Example 26 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class MagicController method clear.

protected void clear() {
    initialized = false;
    Collection<Mage> saveMages = new ArrayList<Mage>(mages.values());
    for (Mage mage : saveMages) {
        playerQuit(mage);
    }
    mages.clear();
    pendingConstruction.clear();
    spells.clear();
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) ArrayList(java.util.ArrayList)

Example 27 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class MagicController method undoRecent.

@Nullable
@Override
public UndoList undoRecent(Block target, int timeout) {
    for (Mage mage : mages.values()) {
        com.elmakers.mine.bukkit.api.block.UndoQueue queue = mage.getUndoQueue();
        UndoList undid = queue.undoRecent(target, timeout);
        if (undid != null) {
            return undid;
        }
    }
    return null;
}
Also used : UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Nullable(javax.annotation.Nullable)

Example 28 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class MagicController method clearCache.

public void clearCache() {
    schematics.clear();
    for (Mage mage : mages.values()) {
        if (mage instanceof com.elmakers.mine.bukkit.magic.Mage) {
            ((com.elmakers.mine.bukkit.magic.Mage) mage).clearCache();
        }
    }
    maps.clearCache();
    maps.resetAll();
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 29 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class SourceLocation method getLocation.

@Nullable
public Location getLocation(CastContext context) {
    Mage mage;
    Location eyeLocation;
    Location feetLocation;
    if (isSource) {
        mage = context.getMage();
        eyeLocation = context.getEyeLocation();
        feetLocation = context.getLocation();
    } else {
        Entity targetEntity = context.getTargetEntity();
        if (targetEntity == null) {
            mage = null;
            feetLocation = context.getTargetLocation();
            eyeLocation = context.getTargetLocation();
        } else {
            mage = context.getController().getRegisteredMage(targetEntity);
            feetLocation = targetEntity.getLocation();
            eyeLocation = targetEntity instanceof LivingEntity ? ((LivingEntity) targetEntity).getEyeLocation() : targetEntity.getLocation();
        }
    }
    if (mage == null && (locationType == LocationType.CAST || locationType == LocationType.WAND)) {
        locationType = LocationType.EYES;
    }
    Location location = null;
    switch(locationType) {
        case CAST:
            if (isSource) {
                location = context.getCastLocation();
            } else {
                location = mage.getCastLocation();
            }
            break;
        case EYES:
            location = eyeLocation;
            break;
        case FEET:
            location = feetLocation;
            break;
        case WAND:
            if (isSource) {
                location = context.getWandLocation();
            } else {
                location = mage.getWandLocation();
            }
            break;
        case BODY:
            if (eyeLocation != null && feetLocation != null) {
                location = eyeLocation.clone().add(feetLocation).multiply(0.5);
            }
            break;
        case HIT:
            location = context.getTargetLocation();
            break;
        case BLOCK:
            if (feetLocation != null) {
                location = feetLocation.getBlock().getLocation();
            }
            break;
    }
    if (location == null) {
        location = feetLocation;
    }
    Location targetLocation = isSource ? context.getTargetLocation() : context.getLocation();
    if (orientToTarget && targetLocation != null && location != null) {
        Vector direction = targetLocation.toVector().subtract(location.toVector()).normalize();
        if (MathUtils.isFinite(direction.getX()) && MathUtils.isFinite(direction.getY()) && MathUtils.isFinite(direction.getZ())) {
            location.setDirection(direction);
        }
    }
    return location;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) Nullable(javax.annotation.Nullable)

Example 30 with Mage

use of com.elmakers.mine.bukkit.api.magic.Mage in project MagicPlugin by elBukkit.

the class CastCommandExecutor method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
    String commandName = command.getName();
    if (commandName.equalsIgnoreCase("castp")) {
        if (!api.hasPermission(sender, "Magic.commands.castp")) {
            sendNoPermission(sender);
            return true;
        }
        if (args.length < 1) {
            if (sender != null)
                sender.sendMessage("Usage: /castp [player] [spell] <parameters>");
            return true;
        }
        String playerName = args[0];
        // Look for Entity-based Mages
        Mage mage = null;
        if (playerName.contains(",")) {
            String[] idPieces = StringUtils.split(playerName, ',');
            if (idPieces.length == 4 || idPieces.length == 2) {
                try {
                    String worldName = idPieces[0];
                    String entityId = idPieces[idPieces.length - 1];
                    World world = Bukkit.getWorld(worldName);
                    if (world == null) {
                        if (sender != null)
                            sender.sendMessage("Unknown world: " + worldName);
                        return false;
                    }
                    Entity entity = NMSUtils.getEntity(world, UUID.fromString(entityId));
                    if (entity == null) {
                        if (sender != null)
                            sender.sendMessage("Entity not found with id " + entityId + " in " + world.getName());
                        return false;
                    }
                    MageController controller = api.getController();
                    mage = controller.getMage(entity);
                    // If we have the mage, we no longer want to send anything to the console.
                    sender = null;
                } catch (Throwable ex) {
                    if (sender != null)
                        sender.sendMessage("Your spell failed (badly... check server logs)");
                    ex.printStackTrace();
                    return false;
                }
            }
        } else if (playerName.contains(":")) {
            // Look for custom id/name Mages
            String[] pieces = StringUtils.split(playerName, ':');
            String mageId = pieces[0];
            String mageName = (pieces.length > 0) ? pieces[1] : mageId;
            MageController controller = api.getController();
            mage = controller.getMage(mageId, mageName);
        }
        if (mage != null && !mage.isLoading()) {
            String[] castParameters = Arrays.copyOfRange(args, 1, args.length);
            if (castParameters.length < 1) {
                if (sender != null)
                    sender.sendMessage("Invalid command line, expecting more parameters");
                return false;
            }
            String spellName = castParameters[0];
            Spell spell = mage.getSpell(spellName);
            if (spell == null) {
                if (sender != null)
                    sender.sendMessage("Unknown spell " + spellName);
                return false;
            }
            String[] parameters = new String[castParameters.length - 1];
            for (int i = 1; i < castParameters.length; i++) {
                parameters[i - 1] = castParameters[i];
            }
            if (spell.cast(parameters)) {
                if (sender != null)
                    sender.sendMessage("Cast " + spell.getName() + " as " + mage.getName());
            } else {
                if (sender != null)
                    sender.sendMessage("Failed to cast " + spell.getName() + " as " + mage.getName());
            }
            return true;
        }
        Player player = DeprecatedUtils.getPlayer(playerName);
        if (player == null) {
            if (sender != null)
                sender.sendMessage("Can't find player " + playerName);
            return true;
        }
        if (!player.isOnline()) {
            if (sender != null)
                sender.sendMessage("Player " + playerName + " is not online");
            return true;
        }
        String[] args2 = Arrays.copyOfRange(args, 1, args.length);
        return processCastCommand(sender, player, args2);
    }
    if (commandName.equalsIgnoreCase("cast")) {
        if (!api.hasPermission(sender, "Magic.commands.cast")) {
            sendNoPermission(sender);
            return true;
        }
        Player player = null;
        if (sender instanceof Player) {
            player = (Player) sender;
        }
        return processCastCommand(sender, player, args);
    }
    return false;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) World(org.bukkit.World) Spell(com.elmakers.mine.bukkit.api.spell.Spell)

Aggregations

Mage (com.elmakers.mine.bukkit.api.magic.Mage)187 Player (org.bukkit.entity.Player)62 Entity (org.bukkit.entity.Entity)56 Wand (com.elmakers.mine.bukkit.api.wand.Wand)47 MageController (com.elmakers.mine.bukkit.api.magic.MageController)45 ItemStack (org.bukkit.inventory.ItemStack)38 Location (org.bukkit.Location)33 LivingEntity (org.bukkit.entity.LivingEntity)31 ArrayList (java.util.ArrayList)25 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)18 Inventory (org.bukkit.inventory.Inventory)16 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)15 Spell (com.elmakers.mine.bukkit.api.spell.Spell)14 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)14 Block (org.bukkit.block.Block)14 Target (com.elmakers.mine.bukkit.utility.Target)13 EventHandler (org.bukkit.event.EventHandler)13 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)10 Vector (org.bukkit.util.Vector)10