Search in sources :

Example 1 with Tameable

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

the class TameAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity entity = context.getTargetEntity();
    if (!(entity instanceof Tameable)) {
        return SpellResult.NO_TARGET;
    }
    Tameable tameable = (Tameable) entity;
    if (tameable.isTamed()) {
        return SpellResult.NO_TARGET;
    }
    tameable.setTamed(true);
    Player tamer = context.getMage().getPlayer();
    if (tamer != null) {
        tameable.setOwner(tamer);
    }
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) Tameable(org.bukkit.entity.Tameable)

Example 2 with Tameable

use of org.bukkit.entity.Tameable in project RedProtect by FabioZumbi12.

the class RPEntityListener method onInteractEvent.

@EventHandler
public void onInteractEvent(PlayerInteractEntityEvent e) {
    RedProtect.get().logger.debug("RPEntityListener - Is PlayerInteractEntityEvent");
    if (e.isCancelled()) {
        return;
    }
    Player p = e.getPlayer();
    if (p == null) {
        return;
    }
    Location l = e.getRightClicked().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    Entity et = e.getRightClicked();
    if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem)) {
        if (et instanceof Tameable) {
            Tameable tam = (Tameable) et;
            if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())) {
                return;
            }
        }
        e.setCancelled(true);
        RPLang.sendMessage(p, "entitylistener.region.cantinteract");
    }
}
Also used : Golem(org.bukkit.entity.Golem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Tameable(org.bukkit.entity.Tameable) Villager(org.bukkit.entity.Villager) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 3 with Tameable

use of org.bukkit.entity.Tameable in project Citizens2 by CitizensDev.

the class HorseEquipper method equip.

@Override
public void equip(Player equipper, NPC toEquip) {
    Tameable horse = (Tameable) toEquip.getEntity();
    NMS.openHorseScreen(horse, equipper);
}
Also used : Tameable(org.bukkit.entity.Tameable)

Example 4 with Tameable

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

the class SoliniaSpell method isValidEffectForEntity.

public static boolean isValidEffectForEntity(LivingEntity target, LivingEntity source, ISoliniaSpell soliniaSpell) throws CoreStateInitException {
    if (source == null) {
        System.out.println("Source was null for isValidEffectForEntity: " + soliniaSpell.getName() + " on target: " + target.getCustomName());
        return false;
    }
    if (target == null) {
        System.out.println("Target was null for isValidEffectForEntity: " + soliniaSpell.getName() + " from source: " + source.getCustomName());
        return false;
    }
    // Always allow self only spells if the target and source is the self
    if (source.getUniqueId().equals(target.getUniqueId()) && Utils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
        // just be sure to check the item its giving if its an item spell
        for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonHorse)) {
                if (source instanceof Player) {
                    if (source.getUniqueId().equals(target.getUniqueId())) {
                        if (StateManager.getInstance().getPlayerManager().getPlayerLastChangeChar(source.getUniqueId()) != null) {
                            source.sendMessage("You can only summon a mount once per server session. Please wait for the next 4 hourly restart");
                            return false;
                        }
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
                System.out.println("Validating SummonItem for source: " + source.getCustomName());
                int itemId = effect.getBase();
                try {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                    System.out.println("Validating SummonItem for source: " + source.getCustomName());
                    if (item == null) {
                        System.out.println("Validating SummonItem said item was null");
                        return false;
                    }
                    if (!item.isTemporary()) {
                        System.out.println("Validating SummonItem said item was not temporary");
                        return false;
                    }
                    if (!(target instanceof LivingEntity)) {
                        System.out.println("Validating SummonItem said target was not a living entity");
                        return false;
                    }
                } catch (CoreStateInitException e) {
                    return false;
                }
            }
        }
        // System.out.println("Detected a self only spell (" + soliniaSpell.getName() + "), returning as valid, always");
        return true;
    }
    if (!source.getUniqueId().equals(target.getUniqueId()))
        if (!source.hasLineOfSight(target))
            return false;
    // Try not to kill potentially friendly player tameables with hostile spells
    if (target instanceof Tameable && target instanceof Creature && !soliniaSpell.isBeneficial()) {
        Tameable t = (Tameable) target;
        Creature cr = (Creature) target;
        if (t.getOwner() != null) {
            if (cr.getTarget() == null)
                return false;
            if (!cr.getTarget().getUniqueId().equals(source.getUniqueId()))
                return false;
        }
    }
    for (SpellEffect effect : soliniaSpell.getBaseSpellEffects()) {
        // and the spell is a detrimental
        if (source instanceof Player && target instanceof Player && soliniaSpell.isDetrimental()) {
            ISoliniaPlayer solsourceplayer = SoliniaPlayerAdapter.Adapt((Player) source);
            if (solsourceplayer.getGroup() != null) {
                if (solsourceplayer.getGroup().getMembers().contains(target.getUniqueId())) {
                    return false;
                }
            }
        }
        // Return false if the target is in the same faction as the npc and not self
        if (!(source instanceof Player) && !(target instanceof Player) && soliniaSpell.isDetrimental() && !source.getUniqueId().equals(target.getUniqueId())) {
            if (source instanceof LivingEntity && target instanceof LivingEntity) {
                ISoliniaLivingEntity solsourceEntity = SoliniaLivingEntityAdapter.Adapt(source);
                ISoliniaLivingEntity soltargetEntity = SoliniaLivingEntityAdapter.Adapt(target);
                if (solsourceEntity.isNPC() && soltargetEntity.isNPC()) {
                    ISoliniaNPC sourceNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
                    ISoliniaNPC targetNpc = StateManager.getInstance().getConfigurationManager().getNPC(solsourceEntity.getNpcid());
                    if (sourceNpc.getFactionid() > 0 && targetNpc.getFactionid() > 0) {
                        if (sourceNpc.getFactionid() == targetNpc.getFactionid())
                            return false;
                    }
                }
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Revive)) {
            if (!(target instanceof Player)) {
                return false;
            }
            if (!(source instanceof Player))
                return false;
            Player sourcePlayer = (Player) source;
            if (!sourcePlayer.getInventory().getItemInOffHand().getType().equals(Material.NAME_TAG)) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (MC): " + sourcePlayer.getInventory().getItemInOffHand().getType().name());
                return false;
            }
            ItemStack item = sourcePlayer.getInventory().getItemInOffHand();
            if (item.getEnchantmentLevel(Enchantment.DURABILITY) != 1) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (EC)");
                return false;
            }
            if (!item.getItemMeta().getDisplayName().equals("Signaculum")) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (NC)");
                return false;
            }
            if (item.getItemMeta().getLore().size() < 5) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (LC)");
                return false;
            }
            String sigdataholder = item.getItemMeta().getLore().get(3);
            String[] sigdata = sigdataholder.split("\\|");
            if (sigdata.length != 2) {
                sourcePlayer.sendMessage("You are not holding a Signaculum in your offhand (SD)");
                return false;
            }
            String str_experience = sigdata[0];
            String str_stimetsamp = sigdata[1];
            int experience = Integer.parseInt(str_experience);
            Timestamp timestamp = Timestamp.valueOf(str_stimetsamp);
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp currenttimestamp = Timestamp.valueOf(datetime);
            long maxminutes = 60 * 7;
            if ((currenttimestamp.getTime() - timestamp.getTime()) >= maxminutes * 60 * 1000) {
                sourcePlayer.sendMessage("This Signaculum has lost its binding to the soul");
                return false;
            }
            String playeruuidb64 = item.getItemMeta().getLore().get(4);
            String uuid = Utils.uuidFromBase64(playeruuidb64);
            Player targetplayer = Bukkit.getPlayer(UUID.fromString(uuid));
            if (targetplayer == null || !targetplayer.isOnline()) {
                sourcePlayer.sendMessage("You cannot resurrect that player as they are offline");
                return false;
            }
        }
        // Validate spelleffecttype rules
        if (effect.getSpellEffectType().equals(SpellEffectType.CurrentHP) || effect.getSpellEffectType().equals(SpellEffectType.CurrentHPOnce)) {
            // Ignore this rule if the spell is self
            if (!Utils.getSpellTargetType(soliniaSpell.getTargettype()).equals(SpellTargetType.Self)) {
                // If the effect is negative standard nuke and on self, cancel out
                if (effect.getBase() < 0 && target.equals(source))
                    return false;
            }
            // cancel
            if (source instanceof Player) {
                if (!(target instanceof Player)) {
                    ISoliniaLivingEntity soltargetentity = SoliniaLivingEntityAdapter.Adapt(target);
                    if (!soltargetentity.isPet()) {
                        if (effect.getBase() > 0)
                            return false;
                    }
                }
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Illusion) || effect.getSpellEffectType().equals(SpellEffectType.IllusionaryTarget) || effect.getSpellEffectType().equals(SpellEffectType.IllusionCopy) || effect.getSpellEffectType().equals(SpellEffectType.IllusionOther) || effect.getSpellEffectType().equals(SpellEffectType.IllusionPersistence)) {
            // if target has spell effect of above already then we cant apply another
            for (SoliniaActiveSpell activeSpell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(target).getActiveSpells()) {
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.Illusion))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionaryTarget))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionCopy))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionOther))
                    return false;
                if (activeSpell.getSpell().getSpellEffectTypes().contains(SpellEffectType.IllusionPersistence))
                    return false;
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.SummonItem)) {
            System.out.println("Validating SummonItem for source: " + source.getCustomName());
            int itemId = effect.getBase();
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                System.out.println("Validating SummonItem for source: " + source.getCustomName());
                if (item == null) {
                    System.out.println("Validating SummonItem said item was null");
                    return false;
                }
                if (!item.isTemporary()) {
                    System.out.println("Validating SummonItem said item was not temporary");
                    return false;
                }
                if (!(target instanceof LivingEntity)) {
                    System.out.println("Validating SummonItem said target was not a living entity");
                    return false;
                }
            } catch (CoreStateInitException e) {
                return false;
            }
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.ResistAll) || effect.getSpellEffectType().equals(SpellEffectType.ResistCold) || effect.getSpellEffectType().equals(SpellEffectType.ResistFire) || effect.getSpellEffectType().equals(SpellEffectType.ResistMagic) || effect.getSpellEffectType().equals(SpellEffectType.ResistPoison) || effect.getSpellEffectType().equals(SpellEffectType.ResistDisease) || effect.getSpellEffectType().equals(SpellEffectType.ResistCorruption)) {
            // If the effect is negative standard resist debuffer and on self, cancel out
            if (effect.getBase() < 0 && target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Mez)) {
            // If the effect is a mez, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Stun)) {
            // If the effect is a stun, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Root)) {
            // If the effect is a root, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.Blind)) {
            // If the effect is a blindness, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.DamageShield) && !(target instanceof Player) && !SoliniaLivingEntityAdapter.Adapt(target).isPet()) {
            // If the effect is a mez, cancel out
            if (target.equals(source))
                return false;
        }
        if (effect.getSpellEffectType().equals(SpellEffectType.NecPet) || effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
            // If the effect is teleport and the target is not a player then fail
            if (!(target instanceof Player))
                return false;
            if (!(source instanceof Player))
                return false;
            // If the effect is a teleport and the target is not in a group or self then fail
            if (effect.getSpellEffectType().equals(SpellEffectType.Teleport) || effect.getSpellEffectType().equals(SpellEffectType.Teleport2) || effect.getSpellEffectType().equals(SpellEffectType.Translocate) || effect.getSpellEffectType().equals(SpellEffectType.TranslocatetoAnchor)) {
                // if target is not the player casting
                if (!target.getUniqueId().equals(source.getUniqueId())) {
                    ISoliniaPlayer solplayertarget = SoliniaPlayerAdapter.Adapt((Player) target);
                    if (solplayertarget == null)
                        return false;
                    if (solplayertarget.getGroup() == null)
                        return false;
                    if (!(solplayertarget.getGroup().getMembers().contains(source.getUniqueId())))
                        return false;
                }
            }
            if (effect.getSpellEffectType().equals(SpellEffectType.SummonPet) || effect.getSpellEffectType().equals(SpellEffectType.NecPet)) {
                try {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getPetNPCByName(soliniaSpell.getTeleportZone());
                    if (npc == null) {
                        return false;
                    }
                    if (npc.isPet() == false) {
                        System.out.print("NPC " + soliniaSpell.getTeleportZone() + " is not defined as a pet");
                        return false;
                    }
                } catch (CoreStateInitException e) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : LocalDateTime(java.time.LocalDateTime) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) Tameable(org.bukkit.entity.Tameable) Creature(org.bukkit.entity.Creature) Timestamp(java.sql.Timestamp) 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) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with Tameable

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

the class GriefPreventionPlusHook method canHurt.

@Override
public boolean canHurt(Player attacker, Entity defender) {
    try {
        if (!griefPrevention.claimsEnabledForWorld(defender.getWorld())) {
            return true;
        }
        DataStore dataStore = griefPrevention.getDataStore();
        if (!(defender instanceof Monster) && griefPrevention.config.claims_protectCreatures) {
            if (defender instanceof Tameable && !griefPrevention.config.pvp_enabledWorlds.contains(defender.getWorld().getUID())) {
                final Tameable tameable = (Tameable) defender;
                if (tameable.isTamed() && (tameable.getOwner() != null)) {
                    final UUID ownerID = tameable.getOwner().getUniqueId();
                    if (attacker.getUniqueId().equals(ownerID)) {
                        return false;
                    }
                    final PlayerData attackerData = dataStore.getPlayerData(attacker.getUniqueId());
                    if (attackerData.ignoreClaims) {
                        return true;
                    }
                }
            }
            PlayerData playerData = dataStore.getPlayerData(attacker.getUniqueId());
            Claim claim = dataStore.getClaimAt(defender.getLocation(), false, playerData.lastClaim);
            if (claim != null) {
                if (claim.canOpenContainers(attacker) != null) {
                    return false;
                }
            }
        }
    } catch (Throwable ignored) {
    }
    return true;
}
Also used : Tameable(org.bukkit.entity.Tameable) DataStore(net.kaikk.mc.gpp.DataStore) Monster(org.bukkit.entity.Monster) UUID(java.util.UUID) PlayerData(net.kaikk.mc.gpp.PlayerData) Claim(net.kaikk.mc.gpp.Claim)

Aggregations

Tameable (org.bukkit.entity.Tameable)13 LivingEntity (org.bukkit.entity.LivingEntity)9 Player (org.bukkit.entity.Player)7 Projectile (org.bukkit.entity.Projectile)4 Ageable (org.bukkit.entity.Ageable)3 EventHandler (org.bukkit.event.EventHandler)3 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)3 ItemStack (org.bukkit.inventory.ItemStack)3 PotionEffect (org.bukkit.potion.PotionEffect)3 Location (org.bukkit.Location)2 ArmorStand (org.bukkit.entity.ArmorStand)2 Entity (org.bukkit.entity.Entity)2 HumanEntity (org.bukkit.entity.HumanEntity)2 ItemFrame (org.bukkit.entity.ItemFrame)2 Monster (org.bukkit.entity.Monster)2 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)2 PlayerSection (org.cubeengine.module.log.action.block.player.ActionPlayerBlock.PlayerSection)2 Player (org.spongepowered.api.entity.player.Player)2 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)1 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1