Search in sources :

Example 6 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project modules-extra by CubeEngine.

the class ListenerHanging method onItemRemove.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onItemRemove(EntityDamageByEntityEvent event) {
    Entity frame = event.getEntity();
    if (frame instanceof ItemFrame) {
        Entity causer;
        if (event.getDamager() instanceof Projectile) {
            ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
            if (shooter instanceof Entity) {
                causer = (Entity) shooter;
            } else {
                // TODO other ProjectileSources
                return;
            }
        } else {
            causer = event.getDamager();
        }
        if (causer instanceof Player) {
            ItemFrameItemRemove action = this.newAction(ItemFrameItemRemove.class, frame.getWorld());
            if (action != null) {
                action.setLocation(frame.getLocation());
                action.setHanging(frame);
                action.setPlayer((Player) causer);
                action.item = ((ItemFrame) frame).getItem();
                this.logAction(action);
            }
        } else {
        // TODO
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) ItemFrame(org.bukkit.entity.ItemFrame) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 7 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project askyblock by tastybento.

the class IslandGuard1_9 method EndCrystalDamage.

/**
 * Handle end crystal damage by visitors
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void EndCrystalDamage(EntityDamageByEntityEvent e) {
    if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    if (!(e.getEntity() instanceof EnderCrystal)) {
        return;
    }
    Player p = null;
    if (e.getDamager() instanceof Player) {
        p = (Player) e.getDamager();
    } else if (e.getDamager() instanceof Projectile) {
        // Get the shooter
        Projectile projectile = (Projectile) e.getDamager();
        ProjectileSource shooter = projectile.getShooter();
        if (shooter instanceof Player) {
            p = (Player) shooter;
        }
    }
    if (p != null) {
        if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        // Check if on island
        if (plugin.getGrid().playerIsOnIsland(p)) {
            return;
        }
        // Check island
        Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        if (island != null && island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) EnderCrystal(org.bukkit.entity.EnderCrystal) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Island(com.wasteofplastic.askyblock.Island) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 8 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project AuthMeReloaded by AuthMe.

the class EntityListener method onProjectileLaunch.

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    final Projectile projectile = event.getEntity();
    ProjectileSource shooter = projectile.getShooter();
    if (shooter instanceof Player && listenerService.shouldCancelEvent((Player) shooter)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 9 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.

the class AreaEffectCloudStore method save.

@Override
public void save(GlowAreaEffectCloud entity, CompoundTag tag) {
    super.save(entity, tag);
    tag.putInt("Age", entity.getTicksLived());
    Color color = entity.getColor();
    if (color != null) {
        tag.putInt(COLOR, color.asRGB());
    }
    tag.putInt(DURATION, entity.getDuration());
    tag.putInt(REAPPLICATION_DELAY, entity.getReapplicationDelay());
    tag.putInt(WAIT_TIME, entity.getWaitTime());
    ProjectileSource source = entity.getSource();
    if (source instanceof Entity) {
        UUID uuid = ((Entity) source).getUniqueId();
        tag.putLong(OWNER_UUID_LEAST, uuid.getLeastSignificantBits());
        tag.putLong(OWNER_UUID_MOST, uuid.getMostSignificantBits());
    }
    tag.putInt(DURATION_ON_USE, entity.getDurationOnUse());
    tag.putFloat(RADIUS, entity.getRadius());
    tag.putFloat(RADIUS_ON_USE, entity.getRadiusOnUse());
    tag.putFloat(RADIUS_PER_TICK, entity.getRadiusPerTick());
    Particle particle = entity.getParticle();
    if (particle != null) {
        tag.putString(PARTICLE, particle.toString());
    }
    PotionData potion = entity.getBasePotionData();
    if (potion != null) {
        tag.putString(POTION, GlowMetaPotion.dataToString(potion));
    }
    tag.putCompoundList(EFFECTS, entity.getCustomEffects().stream().map(GlowMetaPotion::toNbt).collect(Collectors.toList()));
// TODO: Are ParticleParam1 and ParticleParam2 unused?
}
Also used : Particle(org.bukkit.Particle) Entity(org.bukkit.entity.Entity) PotionData(org.bukkit.potion.PotionData) GlowMetaPotion(net.glowstone.inventory.GlowMetaPotion) Color(org.bukkit.Color) ProjectileSource(org.bukkit.projectiles.ProjectileSource) UUID(java.util.UUID)

Example 10 with ProjectileSource

use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.

the class GlowFishingHook method setShooter.

@Override
public void setShooter(ProjectileSource shooter) {
    ProjectileSource oldShooter = getShooter();
    if (oldShooter == shooter) {
        return;
    }
    // Shooter is immutable client-side (a situation peculiar to fishing hooks), so if it
    // changes then all clients who can see this fishing hook must be told that this hook has
    // despawned and a new one has spawned.
    super.setShooter(shooter);
    World world = location.getWorld();
    if (world instanceof GlowWorld) {
        List<Message> respawnMessages = new LinkedList<>();
        DestroyEntitiesMessage destroyOldCopy = new DestroyEntitiesMessage(Collections.singletonList(getObjectId()));
        respawnMessages.add(destroyOldCopy);
        respawnMessages.addAll(createSpawnMessage(getShooterId()));
        ((GlowWorld) world).getRawPlayers().stream().filter(player -> !Objects.equal(player, shooter)).filter(player -> player.canSeeEntity(this)).forEach(player -> player.getSession().sendAll(respawnMessages.toArray(EMPTY_MESSAGE_ARRAY)));
        if (shooter instanceof GlowPlayer) {
            GlowSession session = ((GlowPlayer) shooter).getSession();
            session.send(destroyOldCopy);
            session.sendAll(createSpawnMessage(getEntityId()).toArray(EMPTY_MESSAGE_ARRAY));
        }
    }
}
Also used : DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) Setter(lombok.Setter) Getter(lombok.Getter) BoundingBox(org.bukkit.util.BoundingBox) Enchantment(org.bukkit.enchantments.Enchantment) Message(com.flowpowered.network.Message) GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) InventoryUtil(net.glowstone.util.InventoryUtil) EntityNetworkUtil(net.glowstone.entity.EntityNetworkUtil) Block(org.bukkit.block.Block) GlowProjectile(net.glowstone.entity.projectile.GlowProjectile) Location(org.bukkit.Location) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) World(org.bukkit.World) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GlowSession(net.glowstone.net.GlowSession) Objects(com.google.common.base.Objects) GlowWorld(net.glowstone.GlowWorld) LinkedList(java.util.LinkedList) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Material(org.bukkit.Material) Position(net.glowstone.util.Position) Entity(org.bukkit.entity.Entity) GlowBiomeClimate(net.glowstone.constants.GlowBiomeClimate) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) EventFactory(net.glowstone.EventFactory) RewardItem(net.glowstone.entity.FishingRewardManager.RewardItem) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) List(java.util.List) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) FishHook(org.bukkit.entity.FishHook) RewardCategory(net.glowstone.entity.FishingRewardManager.RewardCategory) SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) CAUGHT_FISH(org.bukkit.event.player.PlayerFishEvent.State.CAUGHT_FISH) GlowSession(net.glowstone.net.GlowSession) Message(com.flowpowered.network.Message) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) GlowWorld(net.glowstone.GlowWorld) ProjectileSource(org.bukkit.projectiles.ProjectileSource) World(org.bukkit.World) GlowWorld(net.glowstone.GlowWorld) LinkedList(java.util.LinkedList)

Aggregations

ProjectileSource (org.bukkit.projectiles.ProjectileSource)44 EventHandler (org.bukkit.event.EventHandler)24 LivingEntity (org.bukkit.entity.LivingEntity)21 Projectile (org.bukkit.entity.Projectile)21 Entity (org.bukkit.entity.Entity)20 Player (org.bukkit.entity.Player)17 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)5 UUID (java.util.UUID)4 Entity (org.spongepowered.api.entity.Entity)4 Player (org.spongepowered.api.entity.player.Player)4 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)3 EntityTag (com.denizenscript.denizen.objects.EntityTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 EnumAbilities (com.jacob_vejvoda.infernal_mobs.ability.EnumAbilities)2 Mob (com.jacob_vejvoda.infernal_mobs.persist.Mob)2 List (java.util.List)2 Random (java.util.Random)2 GlowPlayer (net.glowstone.entity.GlowPlayer)2 Location (org.bukkit.Location)2