Search in sources :

Example 26 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (this.passenger == null || !(this.passenger instanceof EntityPlayer)) {
            hasRider = false;
            // climb height -> halfslab
            this.S = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (this.passenger != null) {
            if (this.passenger instanceof EntityPlayer) {
                if (getOwner().equals(this.passenger)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.S = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    this.passenger.mount(null);
                }
            } else {
                this.passenger.mount(null);
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), "BARRIER", 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), "VILLAGER_HAPPY", 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Example 27 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.P = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                if (e instanceof EntityPlayer && getOwner().equals(e)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.P = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    e.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), "BARRIER", 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), "VILLAGER_HAPPY", 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Example 28 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.P = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                if (e instanceof EntityPlayer && getOwner().equals(e)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.P = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    e.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), "BARRIER", 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), "VILLAGER_HAPPY", 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_9_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Example 29 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.P = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                if (e instanceof EntityPlayer && getOwner().equals(e)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.P = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    e.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), "BARRIER", 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), "VILLAGER_HAPPY", 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Example 30 with PotionEffect

use of org.bukkit.potion.PotionEffect in project MyPet by xXKeyleXx.

the class Beacon method schedule.

public void schedule() {
    if (myPet.getStatus() == MyPet.PetState.Here && isActive() && active && selectedBuffs.size() != 0 && --beaconTimer <= 0) {
        beaconTimer = 2;
        double range = this.range;
        if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.HungerSystem.AFFECT_BEACON_RANGE) {
            range *= (Math.log10(myPet.getSaturation()) / 2);
        }
        if (range < 0.7) {
            return;
        }
        range = range * range;
        if (selectedBuffs.size() > selectableBuffs) {
            int usableBuff = 0;
            for (int buff : selectedBuffs) {
                if (buffLevel.get(buff) > 0) {
                    usableBuff = buff;
                }
            }
            selectedBuffs.clear();
            if (usableBuff != 0) {
                selectedBuffs.add(usableBuff);
            }
        }
        if (selectedBuffs.size() == 0) {
            return;
        }
        MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 1, 0), "SPELL_WITCH", 0.2F, 0.2F, 0.2F, 0.1F, 5, 20);
        List<Player> members = null;
        if (Configuration.Skilltree.Skill.Beacon.PARTY_SUPPORT && receiver == BeaconReceiver.Party) {
            members = MyPetApi.getHookHelper().getPartyMembers(getMyPet().getOwner().getPlayer());
        }
        int duration = this.duration * 20;
        List<PotionEffect> potionEffects = new ArrayList<>();
        for (int buff : selectedBuffs) {
            int amplification = buffLevel.get(buff) - 1;
            PotionEffect effect = new PotionEffect(PotionEffectType.getById(buff), duration, amplification, true, true);
            potionEffects.add(effect);
        }
        Location myPetLocation = this.myPet.getLocation().get();
        targetLoop: for (Player player : myPetLocation.getWorld().getPlayers()) {
            if (MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), myPetLocation) > range) {
                continue;
            }
            switch(receiver) {
                case Owner:
                    if (!myPet.getOwner().equals(player)) {
                        continue targetLoop;
                    } else {
                        for (PotionEffect effect : potionEffects) {
                            player.addPotionEffect(effect, true);
                        }
                        MyPetApi.getPlatformHelper().playParticleEffect(player.getLocation().add(0, 1, 0), "SPELL_INSTANT", 0.2F, 0.2F, 0.2F, 0.1F, 5, 20);
                        break targetLoop;
                    }
                case Everyone:
                    for (PotionEffect effect : potionEffects) {
                        player.addPotionEffect(effect, true);
                    }
                    MyPetApi.getPlatformHelper().playParticleEffect(player.getLocation().add(0, 1, 0), "SPELL_INSTANT", 0.2F, 0.2F, 0.2F, 0.1F, 5, 20);
                    break;
                case Party:
                    if (Configuration.Skilltree.Skill.Beacon.PARTY_SUPPORT && members != null) {
                        if (members.contains(player)) {
                            for (PotionEffect effect : potionEffects) {
                                player.addPotionEffect(effect, true);
                            }
                            MyPetApi.getPlatformHelper().playParticleEffect(player.getLocation().add(0, 1, 0), "SPELL_INSTANT", 0.2F, 0.2F, 0.2F, 0.1F, 5, 20);
                        }
                        break;
                    } else {
                        receiver = BeaconReceiver.Owner;
                        break targetLoop;
                    }
            }
        }
        if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.Skilltree.Skill.Beacon.HUNGER_DECREASE_TIME > 0 && hungerDecreaseTimer-- < 0) {
            myPet.decreaseSaturation(1);
            hungerDecreaseTimer = Configuration.Skilltree.Skill.Beacon.HUNGER_DECREASE_TIME;
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PotionEffect(org.bukkit.potion.PotionEffect) Location(org.bukkit.Location)

Aggregations

PotionEffect (org.bukkit.potion.PotionEffect)224 Player (org.bukkit.entity.Player)61 PotionEffectType (org.bukkit.potion.PotionEffectType)39 Location (org.bukkit.Location)37 LivingEntity (org.bukkit.entity.LivingEntity)37 EventHandler (org.bukkit.event.EventHandler)36 ItemStack (org.bukkit.inventory.ItemStack)34 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)23 PotionMeta (org.bukkit.inventory.meta.PotionMeta)18 Vector (org.bukkit.util.Vector)16 Random (java.util.Random)14 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)9 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)9 Material (org.bukkit.Material)7 Enchantment (org.bukkit.enchantments.Enchantment)7 Projectile (org.bukkit.entity.Projectile)7 PotionData (org.bukkit.potion.PotionData)7