Search in sources :

Example 1 with MageController

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

the class WandCommandExecutor method onWandDelete.

public boolean onWandDelete(CommandSender sender, String wandKey) {
    MageController controller = api.getController();
    WandTemplate existing = controller.getWandTemplate(wandKey);
    if (existing == null) {
        sender.sendMessage(ChatColor.RED + "Unknown wand: " + wandKey);
        return true;
    }
    boolean hasPermission = true;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.hasPermission("Magic.wand.overwrite")) {
            if (player.hasPermission("Magic.wand.overwrite_own")) {
                String creatorId = existing.getCreatorId();
                hasPermission = creatorId != null && creatorId.equalsIgnoreCase(player.getUniqueId().toString());
            } else {
                hasPermission = false;
            }
        }
    }
    if (!hasPermission) {
        sender.sendMessage(ChatColor.RED + "You don't have permission to delete " + wandKey);
        return true;
    }
    File wandFolder = new File(controller.getConfigFolder(), "wands");
    File wandFile = new File(wandFolder, wandKey + ".yml");
    if (!wandFile.exists()) {
        sender.sendMessage(ChatColor.RED + "File doesn't exist: " + wandFile.getName());
        return true;
    }
    wandFile.delete();
    controller.unloadWandTemplate(wandKey);
    sender.sendMessage("Deleted wand " + wandKey);
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) WandTemplate(com.elmakers.mine.bukkit.api.wand.WandTemplate) File(java.io.File)

Example 2 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController 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)

Example 3 with MageController

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

the class EffSpawn method execute.

@Override
protected void execute(Event event) {
    Number count = null;
    if (amount != null) {
        count = amount.getSingle(event);
    }
    ;
    if (count == null) {
        count = 1;
    }
    MageController controller = MagicPlugin.getAPI().getController();
    final String[] keys = mobKeys.getArray(event);
    for (final Location location : locations.getArray(event)) {
        for (final String mobKey : keys) {
            for (int i = 0; i < count.doubleValue(); i++) {
                controller.spawnMob(mobKey, location);
            }
        }
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Location(org.bukkit.Location)

Example 4 with MageController

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

the class ProjectileAction method start.

@Override
public SpellResult start(CastContext context) {
    MageController controller = context.getController();
    Mage mage = context.getMage();
    // Modify with wand power
    // Turned some of this off for now
    // int count = this.count * mage.getRadiusMultiplier();
    // int speed = this.speed * damageMultiplier;
    int size = (int) (mage.getRadiusMultiplier() * this.size);
    double damageMultiplier = mage.getDamageMultiplier("projectile");
    double damage = damageMultiplier * this.damage;
    float radiusMultiplier = mage.getRadiusMultiplier();
    float spread = this.spread;
    if (radiusMultiplier > 1) {
        spread = spread / radiusMultiplier;
    }
    Random random = context.getRandom();
    Class<?> projectileType = NMSUtils.getBukkitClass("net.minecraft.server.Entity" + projectileTypeName);
    if (!CompatibilityUtils.isValidProjectileClass(projectileType)) {
        controller.getLogger().warning("Bad projectile class: " + projectileTypeName);
        return SpellResult.FAIL;
    }
    // Prepare parameters
    Location location = sourceLocation.getLocation(context);
    Vector direction = location.getDirection();
    if (startDistance > 0) {
        location = location.clone().add(direction.clone().multiply(startDistance));
    }
    // Spawn projectiles
    LivingEntity shootingEntity = context.getLivingEntity();
    ProjectileSource source = null;
    if (shootingEntity != null) {
        source = shootingEntity;
    }
    for (int i = 0; i < count; i++) {
        try {
            // Spawn a new projectile
            Projectile projectile = CompatibilityUtils.spawnProjectile(projectileType, location, direction, source, speed, spread, i > 0 ? spread : 0, random);
            if (projectile == null) {
                return SpellResult.FAIL;
            }
            if (shootingEntity != null) {
                projectile.setShooter(shootingEntity);
            }
            if (projectile instanceof Fireball) {
                Fireball fireball = (Fireball) projectile;
                fireball.setIsIncendiary(useFire);
                fireball.setYield(size);
            }
            if (projectile instanceof Arrow) {
                Arrow arrow = (Arrow) projectile;
                if (useFire) {
                    arrow.setFireTicks(300);
                }
                if (damage > 0) {
                    CompatibilityUtils.setDamage(projectile, damage);
                }
                if (tickIncrease > 0) {
                    CompatibilityUtils.decreaseLifespan(projectile, tickIncrease);
                }
                if (pickupStatus != null && !pickupStatus.isEmpty()) {
                    CompatibilityUtils.setPickupStatus(arrow, pickupStatus);
                }
            }
            if (!breakBlocks) {
                projectile.setMetadata("cancel_explosion", new FixedMetadataValue(controller.getPlugin(), true));
            }
            track(context, projectile);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return checkTracking(context);
}
Also used : Arrow(org.bukkit.entity.Arrow) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Projectile(org.bukkit.entity.Projectile) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Fireball(org.bukkit.entity.Fireball) Random(java.util.Random) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) SourceLocation(com.elmakers.mine.bukkit.magic.SourceLocation)

Example 5 with MageController

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

the class RecallAction method getWaypoint.

@Nullable
protected Waypoint getWaypoint(Player player, RecallType type, int index, ConfigurationSection parameters, CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    switch(type) {
        case MARKER:
            Location location = ConfigurationUtils.getLocation(mage.getData(), markerKey);
            return new Waypoint(type, location, context.getMessage("title_marker"), context.getMessage("cast_marker"), context.getMessage("no_target_marker"), context.getMessage("description_marker", ""), getIcon(context, parameters, "icon_marker"), true);
        case DEATH:
            Waypoint death = new Waypoint(type, mage.getLastDeathLocation(), "Last Death", context.getMessage("cast_death"), context.getMessage("no_target_death"), context.getMessage("description_death", ""), getIcon(context, parameters, "icon_death"), true);
            death.safe = false;
            return death;
        case SPAWN:
            return new Waypoint(type, context.getWorld().getSpawnLocation(), context.getMessage("title_spawn"), context.getMessage("cast_spawn"), context.getMessage("no_target_spawn"), context.getMessage("description_spawn", ""), getIcon(context, parameters, "icon_spawn"), false);
        case TOWN:
            return new Waypoint(type, controller.getTownLocation(player), context.getMessage("title_town"), context.getMessage("cast_town"), context.getMessage("no_target_town"), context.getMessage("description_town", ""), getIcon(context, parameters, "icon_town"), false);
        case HOME:
            Location bedLocation = player == null ? null : player.getBedSpawnLocation();
            if (bedLocation != null) {
                bedLocation.setX(bedLocation.getX() + 0.5);
                bedLocation.setZ(bedLocation.getZ() + 0.5);
            }
            return new Waypoint(type, bedLocation, context.getMessage("title_home"), context.getMessage("cast_home"), context.getMessage("no_target_home"), context.getMessage("description_home", ""), getIcon(context, parameters, "icon_home"), false);
        case WAND:
            List<LostWand> lostWands = mage.getLostWands();
            if (lostWands == null || index < 0 || index >= lostWands.size())
                return null;
            return new Waypoint(type, lostWands.get(index).getLocation(), context.getMessage("title_wand"), context.getMessage("cast_wand"), context.getMessage("no_target_wand"), context.getMessage("description_wand", ""), getIcon(context, parameters, "icon_wand"), true);
        default:
            return null;
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Location(org.bukkit.Location) Nullable(javax.annotation.Nullable)

Aggregations

MageController (com.elmakers.mine.bukkit.api.magic.MageController)76 Mage (com.elmakers.mine.bukkit.api.magic.Mage)45 Entity (org.bukkit.entity.Entity)27 Player (org.bukkit.entity.Player)26 Location (org.bukkit.Location)16 ItemStack (org.bukkit.inventory.ItemStack)16 Wand (com.elmakers.mine.bukkit.api.wand.Wand)14 Block (org.bukkit.block.Block)11 LivingEntity (org.bukkit.entity.LivingEntity)11 ArrayList (java.util.ArrayList)10 Inventory (org.bukkit.inventory.Inventory)9 ItemMeta (org.bukkit.inventory.meta.ItemMeta)8 Spell (com.elmakers.mine.bukkit.api.spell.Spell)5 MagicController (com.elmakers.mine.bukkit.magic.MagicController)5 Nullable (javax.annotation.Nullable)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 ItemData (com.elmakers.mine.bukkit.api.item.ItemData)4 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)4 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)4 File (java.io.File)4