Search in sources :

Example 11 with Tameable

use of org.bukkit.entity.Tameable in project Jobs by GamingMesh.

the class JobsPaymentListener method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
    // Entity that died must be living
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    LivingEntity lVictim = (LivingEntity) event.getEntity();
    // mob spawner, no payment or experience
    if (lVictim.hasMetadata(mobSpawnerMetadata)) {
        lVictim.removeMetadata(mobSpawnerMetadata, plugin);
        return;
    }
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
        org.bukkit.entity.Player pDamager = null;
        if (e.getDamager() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) e.getDamager();
        } else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) ((Projectile) e.getDamager()).getShooter();
        } else if (e.getDamager() instanceof Tameable) {
            Tameable t = (Tameable) e.getDamager();
            if (t.isTamed() && t.getOwner() instanceof org.bukkit.entity.Player) {
                pDamager = (org.bukkit.entity.Player) t.getOwner();
            }
        }
        if (pDamager != null) {
            // check if in creative
            if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
                return;
            if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
                return;
            // restricted area multiplier
            double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(pDamager);
            // pay
            JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
            Jobs.action(jDamager, new EntityActionInfo(lVictim.getType(), ActionType.KILL), multiplier);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Tameable(org.bukkit.entity.Tameable) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Player(org.bukkit.entity.Player) EntityActionInfo(com.gamingmesh.jobs.actions.EntityActionInfo) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 12 with Tameable

use of org.bukkit.entity.Tameable in project solinia3-core by mixxit.

the class CommandSolNPCInfo method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage("This is a player only command");
        return true;
    }
    // sender.sendMessage("Fetching information about NPC targetted");
    Player player = (Player) sender;
    try {
        ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
        LivingEntity targetmob = solPlayer.getEntityTarget();
        if (targetmob == null) {
            player.sendMessage("You need to target an NPC for info about it");
            return true;
        }
        ISoliniaLivingEntity solLivingEntity = SoliniaLivingEntityAdapter.Adapt(targetmob);
        String mobtag = "";
        String npcidtag = "";
        player.sendMessage("EQUIPMENT");
        for (ISoliniaItem solItem : solLivingEntity.getEquippedSoliniaItems()) {
            player.sendMessage("SolItemId: " + solItem.getId() + " " + solItem.getDisplayname());
        }
        if (solLivingEntity.getBukkitLivingEntity().hasMetadata("Faction")) {
            String metadata = "";
            for (MetadataValue val : solLivingEntity.getBukkitLivingEntity().getMetadata("Faction")) {
                metadata = val.asString();
            }
            player.sendMessage("Faction: " + metadata);
        }
        player.sendMessage("Active Effects");
        try {
            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(solLivingEntity.getBukkitLivingEntity()).getActiveSpells()) {
                player.sendMessage(spell.getSpell().getName());
                for (ActiveSpellEffect effect : spell.getActiveSpellEffects()) {
                    player.sendMessage(" - " + effect.getSpellEffectType().name() + " " + effect.getRemainingValue());
                }
            }
        } catch (CoreStateInitException e) {
        // 
        }
        solLivingEntity.sendHateList(player);
        solLivingEntity.sendStats(player);
        for (MetadataValue val : targetmob.getMetadata("mobname")) mobtag = "mobname tag: " + ChatColor.GOLD + val.asString() + ChatColor.RESET;
        for (MetadataValue val : targetmob.getMetadata("npcid")) npcidtag = "npcid tag: " + ChatColor.GOLD + val.asString() + ChatColor.RESET;
        // player.sendMessage("GUID: " + targetmob.getUniqueId() + " IsNPC: " + solLivingEntity.isNPC() + " npcid: " + npcid);
        player.sendMessage(mobtag + " " + npcidtag);
        if (solLivingEntity.getBukkitLivingEntity() instanceof Creature) {
            String parent = "Owner: " + ChatColor.GOLD + solLivingEntity.getActiveMob().getOwner() + ChatColor.RESET;
            String owner = "Parent: " + ChatColor.GOLD + solLivingEntity.getActiveMob().getParent() + ChatColor.RESET;
            String tame = "";
            if (solLivingEntity.getBukkitLivingEntity() instanceof Tameable)
                tame = "TameOwner: " + ChatColor.GOLD + ((Tameable) (solLivingEntity.getBukkitLivingEntity())).getOwner() + ChatColor.RESET;
            player.sendMessage(parent + " " + owner + " " + tame);
        }
        String canSee = "";
        if (player.isOp())
            canSee = "Can i see you: " + ChatColor.GOLD + solLivingEntity.checkLosFN(SoliniaLivingEntityAdapter.Adapt(player));
        String attackTarget = "Minecraft attack target: " + ChatColor.GOLD + (solLivingEntity.getAttackTarget() == null ? "None" : solLivingEntity.getAttackTarget().getName()) + ChatColor.RESET + " " + canSee;
        if (solLivingEntity.getSpawnPoint() == null) {
            player.sendMessage("spawnpoint: " + ChatColor.GOLD + "null");
        } else {
            player.sendMessage("spawnpoint: " + ChatColor.GOLD + solLivingEntity.getSpawnPoint().getWorld().getName() + "," + solLivingEntity.getSpawnPoint().getX() + "," + solLivingEntity.getSpawnPoint().getY() + "," + solLivingEntity.getSpawnPoint().getZ());
        }
        if (player.isOp() && solLivingEntity.isNPC()) {
            ISoliniaNPC npc = solLivingEntity.getNPC();
            double hp = solLivingEntity.getStatMaxHP(75);
            if (npc.isHeroic()) {
                hp += (NPCUtils.getHeroicHPMultiplier() * npc.getLevel());
            }
            if (npc.isBoss()) {
                hp += (NPCUtils.getBossHPMultiplier(npc.isHeroic()) * npc.getLevel());
            }
            if (npc.isRaidheroic()) {
                hp += (NPCUtils.getRaidHeroicHPMultiplier() * npc.getLevel());
            }
            if (npc.isRaidboss()) {
                hp += (NPCUtils.getRaidBossHPMultiplier() * npc.getLevel());
            }
            if (npc.getForcedMaxHp() > 0)
                hp = npc.getForcedMaxHp();
            double damage = npc.getMaxDamage();
            player.sendMessage("Debug calc hp: " + hp + " " + "Debug calc dmg: " + npc.getMaxDamage());
        }
        player.sendMessage(attackTarget);
        if (player.isOp())
            player.sendMessage("isCollidable: " + targetmob.isCollidable());
    } catch (CoreStateInitException e) {
        player.sendMessage("SoliniaNPCInfo: " + "Could not fetch information");
    }
    return true;
}
Also used : MetadataValue(org.bukkit.metadata.MetadataValue) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) Creature(org.bukkit.entity.Creature) Tameable(org.bukkit.entity.Tameable) ActiveSpellEffect(com.solinia.solinia.Models.ActiveSpellEffect) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell)

Example 13 with Tameable

use of org.bukkit.entity.Tameable in project Essentials by EssentialsX.

the class Commandremove method removeHandler.

private void removeHandler(final CommandSource sender, final List<String> types, final List<String> customTypes, final World world, int radius) {
    int removed = 0;
    if (radius > 0) {
        radius *= radius;
    }
    final ArrayList<ToRemove> removeTypes = new ArrayList<>();
    final ArrayList<Mob> customRemoveTypes = new ArrayList<>();
    for (final String s : types) {
        removeTypes.add(ToRemove.valueOf(s));
    }
    boolean warnUser = false;
    for (final String s : customTypes) {
        final Mob mobType = Mob.fromName(s);
        if (mobType == null) {
            warnUser = true;
        } else {
            customRemoveTypes.add(mobType);
        }
    }
    if (warnUser) {
        sender.sendMessage(tl("invalidMob"));
    }
    for (final Chunk chunk : world.getLoadedChunks()) {
        for (final Entity e : chunk.getEntities()) {
            if (radius > 0) {
                if (sender.getPlayer().getLocation().distanceSquared(e.getLocation()) > radius) {
                    continue;
                }
            }
            if (e instanceof HumanEntity) {
                continue;
            }
            for (final ToRemove toRemove : removeTypes) {
                // We should skip any animals tamed by players unless we are specifially targetting them.
                if (e instanceof Tameable && ((Tameable) e).isTamed() && (((Tameable) e).getOwner() instanceof Player || ((Tameable) e).getOwner() instanceof OfflinePlayer) && !removeTypes.contains(ToRemove.TAMED)) {
                    continue;
                }
                // We should skip any NAMED animals unless we are specifially targetting them.
                if (e instanceof LivingEntity && e.getCustomName() != null && !removeTypes.contains(ToRemove.NAMED)) {
                    continue;
                }
                switch(toRemove) {
                    case TAMED:
                        if (e instanceof Tameable && ((Tameable) e).isTamed()) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case NAMED:
                        if (e instanceof LivingEntity && e.getCustomName() != null) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case DROPS:
                        if (e instanceof Item) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ARROWS:
                        if (e instanceof Projectile) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case BOATS:
                        if (e instanceof Boat) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case MINECARTS:
                        if (e instanceof Minecart) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case XP:
                        if (e instanceof ExperienceOrb) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case PAINTINGS:
                        if (e instanceof Painting) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ITEMFRAMES:
                        if (e instanceof ItemFrame) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ENDERCRYSTALS:
                        if (e instanceof EnderCrystal) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case AMBIENT:
                        if (e instanceof Flying) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case HOSTILE:
                    case MONSTERS:
                        if (e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case PASSIVE:
                    case ANIMALS:
                        if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Ambient) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case MOBS:
                        if (e instanceof Animals || e instanceof NPC || e instanceof Snowman || e instanceof WaterMob || e instanceof Monster || e instanceof ComplexLivingEntity || e instanceof Flying || e instanceof Slime || e instanceof Ambient) {
                            e.remove();
                            removed++;
                        }
                        break;
                    case ENTITIES:
                    case ALL:
                        e.remove();
                        removed++;
                        break;
                    case CUSTOM:
                        for (final Mob type : customRemoveTypes) {
                            if (e.getType() == type.getType()) {
                                e.remove();
                                removed++;
                            }
                        }
                        break;
                }
            }
        }
    }
    sender.sendMessage(tl("removed", removed));
}
Also used : NPC(org.bukkit.entity.NPC) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ArrayList(java.util.ArrayList) Minecart(org.bukkit.entity.Minecart) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) ItemFrame(org.bukkit.entity.ItemFrame) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Item(org.bukkit.entity.Item) Monster(org.bukkit.entity.Monster) HumanEntity(org.bukkit.entity.HumanEntity) OfflinePlayer(org.bukkit.OfflinePlayer) WaterMob(org.bukkit.entity.WaterMob) Mob(com.earth2me.essentials.Mob) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) Tameable(org.bukkit.entity.Tameable) ExperienceOrb(org.bukkit.entity.ExperienceOrb) EnderCrystal(org.bukkit.entity.EnderCrystal) Chunk(org.bukkit.Chunk) Slime(org.bukkit.entity.Slime) Projectile(org.bukkit.entity.Projectile) Painting(org.bukkit.entity.Painting) WaterMob(org.bukkit.entity.WaterMob) Flying(org.bukkit.entity.Flying) Animals(org.bukkit.entity.Animals) Ambient(org.bukkit.entity.Ambient) Snowman(org.bukkit.entity.Snowman) Boat(org.bukkit.entity.Boat)

Example 14 with Tameable

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

the class CompatibilityUtilsBase method getOwnerId.

@Override
public UUID getOwnerId(Entity entity) {
    String ownerIdString = platform.getEnityMetadataUtils().getString(entity, MagicMetaKeys.OWNER);
    if (ownerIdString != null && !ownerIdString.isEmpty()) {
        try {
            return UUID.fromString(ownerIdString);
        } catch (Exception ex) {
            platform.getLogger().warning("Error parsing owner id from: " + ownerIdString);
        }
    }
    if (entity instanceof Tameable) {
        Tameable tamed = (Tameable) entity;
        AnimalTamer tamer = tamed.getOwner();
        return tamer == null ? null : tamer.getUniqueId();
    }
    return null;
}
Also used : Tameable(org.bukkit.entity.Tameable) AnimalTamer(org.bukkit.entity.AnimalTamer) FileNotFoundException(java.io.FileNotFoundException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException)

Example 15 with Tameable

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

the class CompatibilityUtilsBase method tame.

@Override
public boolean tame(Entity entity, Player tamer) {
    if (!(entity instanceof Tameable)) {
        return false;
    }
    Tameable tameable = (Tameable) entity;
    if (tameable.isTamed()) {
        return false;
    }
    tameable.setTamed(true);
    if (tamer != null) {
        tameable.setOwner(tamer);
    }
    return true;
}
Also used : Tameable(org.bukkit.entity.Tameable)

Aggregations

Tameable (org.bukkit.entity.Tameable)20 LivingEntity (org.bukkit.entity.LivingEntity)14 Player (org.bukkit.entity.Player)10 Projectile (org.bukkit.entity.Projectile)7 Entity (org.bukkit.entity.Entity)6 Ageable (org.bukkit.entity.Ageable)4 PotionEffect (org.bukkit.potion.PotionEffect)4 Location (org.bukkit.Location)3 Animals (org.bukkit.entity.Animals)3 ArmorStand (org.bukkit.entity.ArmorStand)3 Creature (org.bukkit.entity.Creature)3 ExperienceOrb (org.bukkit.entity.ExperienceOrb)3 HumanEntity (org.bukkit.entity.HumanEntity)3 ItemFrame (org.bukkit.entity.ItemFrame)3 Monster (org.bukkit.entity.Monster)3 EventHandler (org.bukkit.event.EventHandler)3 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)3 Vector (org.bukkit.util.Vector)3 EffectPlayer (com.elmakers.mine.bukkit.api.effect.EffectPlayer)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2