Search in sources :

Example 16 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MyPet by xXKeyleXx.

the class Lightning method strikeLightning.

public void strikeLightning(Location loc) {
    Player owner = myPet.getOwner().getPlayer();
    isStriking = true;
    loc.getWorld().strikeLightningEffect(loc);
    for (Entity entity : myPet.getEntity().get().getNearbyEntities(1.5, 1.5, 1.5)) {
        if (entity instanceof LivingEntity && entity != owner) {
            ((LivingEntity) entity).damage(damage, myPet.getEntity().get());
        }
    }
    isStriking = false;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player)

Example 17 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class BaseSpell method canCast.

@Override
public boolean canCast(Location location) {
    if (bypassAll)
        return true;
    if (!hasCastPermission(mage.getCommandSender()))
        return false;
    Entity entity = mage.getEntity();
    if (disguiseRestricted && entity != null && entity instanceof Player && controller.isDisguised(entity))
        return false;
    if (glideRestricted && entity != null && entity instanceof LivingEntity && ((LivingEntity) entity).isGliding())
        return false;
    if (glideExclusive && entity != null && entity instanceof LivingEntity && !((LivingEntity) entity).isGliding())
        return false;
    if (location == null)
        return true;
    Boolean regionPermission = bypassRegionPermission ? null : controller.getRegionCastPermission(mage.getPlayer(), this, location);
    if (regionPermission != null && regionPermission == true)
        return true;
    Boolean personalPermission = bypassRegionPermission ? null : controller.getPersonalCastPermission(mage.getPlayer(), this, location);
    if (personalPermission != null && personalPermission == true)
        return true;
    if (regionPermission != null && regionPermission == false)
        return false;
    if (requiresBuildPermission() && !hasBuildPermission(location.getBlock()))
        return false;
    if (requiresBreakPermission() && !hasBreakPermission(location.getBlock()))
        return false;
    if (worldBorderRestricted) {
        WorldBorder border = location.getWorld().getWorldBorder();
        double borderSize = border.getSize() / 2 - border.getWarningDistance();
        Location offset = location.clone().subtract(border.getCenter());
        if (offset.getX() < -borderSize || offset.getX() > borderSize || offset.getZ() < -borderSize || offset.getZ() > borderSize)
            return false;
    }
    return !pvpRestricted || bypassPvpRestriction || mage.isPVPAllowed(location);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) EffectPlayer(com.elmakers.mine.bukkit.effect.EffectPlayer) WorldBorder(org.bukkit.WorldBorder) Location(org.bukkit.Location)

Example 18 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class BaseSpell method processResult.

protected void processResult(SpellResult result, ConfigurationSection parameters) {
    mage.onCast(this, result);
    // Show messaging
    String resultName = result.name().toLowerCase();
    if (!mage.isQuiet()) {
        if (result.isSuccess()) {
            String message = null;
            if (result != SpellResult.CAST) {
                message = getMessage("cast");
            }
            if (result.isAlternate() && result != SpellResult.ALTERNATE) {
                message = getMessage("alternate", message);
            }
            message = getMessage(resultName, message);
            if (!currentCast.getTargetedEntities().isEmpty()) {
                message = getMessage("cast_target", message);
            }
            LivingEntity sourceEntity = mage.getLivingEntity();
            Entity targetEntity = getTargetEntity();
            if (targetEntity == sourceEntity) {
                message = getMessage("cast_self", message);
            } else if (targetEntity instanceof Player) {
                message = getMessage("cast_player", message);
            } else if (targetEntity instanceof LivingEntity) {
                message = getMessage("cast_livingentity", message);
            } else if (targetEntity != null) {
                message = getMessage("cast_entity", message);
            }
            castMessage(message);
        } else // Special cases where messaging is handled elsewhere
        if (result != SpellResult.INSUFFICIENT_RESOURCES && result != SpellResult.COOLDOWN) {
            String message = null;
            if (result.isFailure() && result != SpellResult.FAIL) {
                message = getMessage("fail");
            }
            if (result.isFailure()) {
                sendMessage(getMessage(resultName, message));
            } else {
                castMessage(getMessage(resultName, message));
            }
        }
    }
    // Play effects
    playEffects(resultName);
    // Check for finalization
    if (currentCast != null) {
        // Legacy spells never update the final context result.
        if (isLegacy())
            currentCast.addResult(result);
        // Batched spells will call finish() on completion
        if (!isBatched())
            currentCast.finish();
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) EffectPlayer(com.elmakers.mine.bukkit.effect.EffectPlayer)

Example 19 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class BaseSpell method cast.

@Override
public boolean cast(ConfigurationSection extraParameters, Location defaultLocation) {
    if (mage.isPlayer() && mage.getPlayer().getGameMode() == GameMode.SPECTATOR) {
        if (mage.getDebugLevel() > 0 && extraParameters != null) {
            mage.sendDebugMessage("Cannot cast in spectator mode.");
        }
        return false;
    }
    if (toggle != ToggleType.NONE && isActive()) {
        mage.sendDebugMessage(ChatColor.DARK_BLUE + "Deactivating " + ChatColor.GOLD + getName());
        deactivate(true, true);
        processResult(SpellResult.DEACTIVATE, parameters);
        return true;
    }
    if (mage.getDebugLevel() > 5 && extraParameters != null) {
        Collection<String> keys = extraParameters.getKeys(false);
        if (keys.size() > 0) {
            mage.sendDebugMessage(ChatColor.BLUE + "Cast " + ChatColor.GOLD + getName() + " " + ChatColor.GREEN + ConfigurationUtils.getParameters(extraParameters));
        }
    }
    this.reset();
    Location location = mage.getLocation();
    if (location != null) {
        Set<String> overrides = controller.getSpellOverrides(mage, location);
        if (overrides != null && !overrides.isEmpty()) {
            if (extraParameters == null) {
                extraParameters = new MemoryConfiguration();
            }
            for (String entry : overrides) {
                String[] pieces = StringUtils.split(entry, ' ');
                if (pieces.length < 2)
                    continue;
                String fullKey = pieces[0];
                String[] key = StringUtils.split(fullKey, '.');
                if (key.length == 0)
                    continue;
                if (key.length == 2 && !key[0].equals("default") && !key[0].equals(spellKey.getBaseKey()) && !key[0].equals(spellKey.getKey())) {
                    continue;
                }
                fullKey = key.length == 2 ? key[1] : key[0];
                ConfigurationUtils.set(extraParameters, fullKey, pieces[1]);
            }
        }
    }
    if (this.currentCast == null) {
        this.currentCast = new CastContext();
        this.currentCast.setSpell(this);
    }
    this.location = defaultLocation;
    workingParameters = new SpellParameters(this);
    ConfigurationUtils.addConfigurations(workingParameters, this.parameters);
    ConfigurationUtils.addConfigurations(workingParameters, extraParameters);
    processParameters(workingParameters);
    // Check to see if this is allowed to be cast by a command block
    if (!commandBlockAllowed) {
        CommandSender sender = mage.getCommandSender();
        if (sender != null && sender instanceof BlockCommandSender) {
            Block block = mage.getLocation().getBlock();
            if (block.getType() == Material.COMMAND) {
                block.setType(Material.AIR);
            }
            return false;
        }
    }
    // Allow other plugins to cancel this cast
    PreCastEvent preCast = new PreCastEvent(mage, this);
    Bukkit.getPluginManager().callEvent(preCast);
    if (preCast.isCancelled()) {
        processResult(SpellResult.CANCELLED, workingParameters);
        sendCastMessage(SpellResult.CANCELLED, " (no cast)");
        return false;
    }
    // Don't allow casting if the player is confused or weakened
    bypassConfusion = workingParameters.getBoolean("bypass_confusion", bypassConfusion);
    bypassWeakness = workingParameters.getBoolean("bypass_weakness", bypassWeakness);
    LivingEntity livingEntity = mage.getLivingEntity();
    if (livingEntity != null && !mage.isSuperPowered()) {
        if (!bypassConfusion && livingEntity.hasPotionEffect(PotionEffectType.CONFUSION)) {
            processResult(SpellResult.CURSED, workingParameters);
            sendCastMessage(SpellResult.CURSED, " (no cast)");
            return false;
        }
        // Don't allow casting if the player is weakened
        if (!bypassWeakness && livingEntity.hasPotionEffect(PotionEffectType.WEAKNESS)) {
            processResult(SpellResult.CURSED, workingParameters);
            sendCastMessage(SpellResult.CURSED, " (no cast)");
            return false;
        }
    }
    // Don't perform permission check until after processing parameters, in case of overrides
    if (!canCast(getLocation())) {
        processResult(SpellResult.INSUFFICIENT_PERMISSION, workingParameters);
        sendCastMessage(SpellResult.INSUFFICIENT_PERMISSION, " (no cast)");
        if (mage.getDebugLevel() > 1) {
            CommandSender messageTarget = mage.getDebugger();
            if (messageTarget == null) {
                messageTarget = mage.getCommandSender();
            }
            if (messageTarget != null) {
                mage.debugPermissions(messageTarget, this);
            }
        }
        return false;
    }
    this.preCast();
    // PVP override settings
    bypassPvpRestriction = workingParameters.getBoolean("bypass_pvp", false);
    bypassPvpRestriction = workingParameters.getBoolean("bp", bypassPvpRestriction);
    bypassPermissions = workingParameters.getBoolean("bypass_permissions", bypassPermissions);
    bypassFriendlyFire = workingParameters.getBoolean("bypass_friendly_fire", false);
    onlyFriendlyFire = workingParameters.getBoolean("only_friendly", false);
    // Check cooldowns
    cooldown = workingParameters.getInt("cooldown", cooldown);
    cooldown = workingParameters.getInt("cool", cooldown);
    mageCooldown = workingParameters.getInt("cooldown_mage", mageCooldown);
    // Color override
    color = ConfigurationUtils.getColor(workingParameters, "color", color);
    particle = workingParameters.getString("particle", null);
    double cooldownRemaining = getRemainingCooldown() / 1000.0;
    String timeDescription = "";
    if (cooldownRemaining > 0) {
        if (cooldownRemaining > 60 * 60) {
            long hours = (long) Math.ceil(cooldownRemaining / (60 * 60));
            if (hours == 1) {
                timeDescription = controller.getMessages().get("cooldown.wait_hour");
            } else {
                timeDescription = controller.getMessages().get("cooldown.wait_hours").replace("$hours", Long.toString(hours));
            }
        } else if (cooldownRemaining > 60) {
            long minutes = (long) Math.ceil(cooldownRemaining / 60);
            if (minutes == 1) {
                timeDescription = controller.getMessages().get("cooldown.wait_minute");
            } else {
                timeDescription = controller.getMessages().get("cooldown.wait_minutes").replace("$minutes", Long.toString(minutes));
            }
        } else if (cooldownRemaining >= 1) {
            long seconds = (long) Math.ceil(cooldownRemaining);
            if (seconds == 1) {
                timeDescription = controller.getMessages().get("cooldown.wait_second");
            } else {
                timeDescription = controller.getMessages().get("cooldown.wait_seconds").replace("$seconds", Long.toString(seconds));
            }
        } else {
            timeDescription = controller.getMessages().get("cooldown.wait_moment");
            if (timeDescription.contains("$seconds")) {
                timeDescription = timeDescription.replace("$seconds", SECONDS_FORMATTER.format(cooldownRemaining));
            }
        }
        castMessage(getMessage("cooldown").replace("$time", timeDescription));
        processResult(SpellResult.COOLDOWN, workingParameters);
        sendCastMessage(SpellResult.COOLDOWN, " (no cast)");
        return false;
    }
    CastingCost required = getRequiredCost();
    if (required != null) {
        String baseMessage = getMessage("insufficient_resources");
        String costDescription = required.getDescription(controller.getMessages(), mage);
        // Send loud messages when items are required.
        if (required.isItem()) {
            sendMessage(baseMessage.replace("$cost", costDescription));
        } else {
            castMessage(baseMessage.replace("$cost", costDescription));
        }
        processResult(SpellResult.INSUFFICIENT_RESOURCES, workingParameters);
        sendCastMessage(SpellResult.INSUFFICIENT_RESOURCES, " (no cast)");
        return false;
    }
    if (requiredHealth > 0) {
        LivingEntity li = mage.getLivingEntity();
        double healthPercentage = li == null ? 0 : 100 * li.getHealth() / li.getMaxHealth();
        if (healthPercentage < requiredHealth) {
            processResult(SpellResult.INSUFFICIENT_RESOURCES, workingParameters);
            sendCastMessage(SpellResult.INSUFFICIENT_RESOURCES, " (no cast)");
            return false;
        }
    }
    if (controller.isSpellProgressionEnabled()) {
        long progressLevel = getProgressLevel();
        for (Entry<String, EquationTransform> entry : progressLevelEquations.entrySet()) {
            workingParameters.set(entry.getKey(), entry.getValue().get(progressLevel));
        }
    }
    // Check for cancel-on-cast-other spells, after we have determined that this spell can really be cast.
    if (!passive) {
        for (Iterator<Batch> iterator = mage.getPendingBatches().iterator(); iterator.hasNext(); ) {
            Batch batch = iterator.next();
            if (!(batch instanceof SpellBatch))
                continue;
            SpellBatch spellBatch = (SpellBatch) batch;
            Spell spell = spellBatch.getSpell();
            if (spell.cancelOnCastOther()) {
                spell.cancel();
                batch.finish();
                iterator.remove();
            }
        }
    }
    return finalizeCast(workingParameters);
}
Also used : EquationTransform(de.slikey.effectlib.math.EquationTransform) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) SpellParameters(com.elmakers.mine.bukkit.magic.SpellParameters) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) PreCastEvent(com.elmakers.mine.bukkit.api.event.PreCastEvent) Spell(com.elmakers.mine.bukkit.api.spell.Spell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) PrerequisiteSpell(com.elmakers.mine.bukkit.api.spell.PrerequisiteSpell) LivingEntity(org.bukkit.entity.LivingEntity) CastingCost(com.elmakers.mine.bukkit.api.spell.CastingCost) CastContext(com.elmakers.mine.bukkit.action.CastContext) Batch(com.elmakers.mine.bukkit.api.batch.Batch) SpellBatch(com.elmakers.mine.bukkit.api.batch.SpellBatch) Block(org.bukkit.block.Block) CommandSender(org.bukkit.command.CommandSender) BlockCommandSender(org.bukkit.command.BlockCommandSender) Location(org.bukkit.Location) BlockCommandSender(org.bukkit.command.BlockCommandSender)

Example 20 with LivingEntity

use of org.bukkit.entity.LivingEntity in project MagicPlugin by elBukkit.

the class MagicCommandExecutor method showEntityInfo.

private void showEntityInfo(CommandSender sender, Entity entity, String label, NumberFormat formatter) {
    BoundingBox hitbox = HitboxUtils.getHitbox(entity);
    Vector size = hitbox.size();
    String message = ChatColor.BLACK + label + ": " + ChatColor.AQUA + formatter.format(size.getX()) + ChatColor.DARK_GRAY + "x" + ChatColor.AQUA + formatter.format(size.getY()) + ChatColor.DARK_GRAY + "x" + ChatColor.AQUA + formatter.format(size.getZ());
    if (entity instanceof LivingEntity) {
        LivingEntity li = (LivingEntity) entity;
        message += ChatColor.DARK_GRAY + ", " + ChatColor.GREEN + ((int) li.getMaxHealth()) + "hp";
    }
    sender.sendMessage(message);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) BoundingBox(com.elmakers.mine.bukkit.utility.BoundingBox) BlockVector(org.bukkit.util.BlockVector) Vector(org.bukkit.util.Vector)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)324 Entity (org.bukkit.entity.Entity)170 Player (org.bukkit.entity.Player)123 Location (org.bukkit.Location)72 EventHandler (org.bukkit.event.EventHandler)64 Vector (org.bukkit.util.Vector)60 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)41 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)37 PotionEffect (org.bukkit.potion.PotionEffect)34 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)30 Block (org.bukkit.block.Block)24 Mage (com.elmakers.mine.bukkit.api.magic.Mage)22 Projectile (org.bukkit.entity.Projectile)20 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)18 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)17 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)16 Target (com.elmakers.mine.bukkit.utility.Target)15 World (org.bukkit.World)14 Creature (org.bukkit.entity.Creature)14