Search in sources :

Example 31 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project MyPet by xXKeyleXx.

the class Sprint method finish.

@Override
public void finish() {
    nav.getParameters().removeSpeedModifier("Sprint");
    new BukkitRunnable() {

        public void run() {
            petEntity.setSprinting(false);
        }
    }.runTaskLater(MyPetApi.getPlugin(), 25L);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 32 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project MyPet by xXKeyleXx.

the class EntityMyPig method handlePlayerInteraction.

public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
    if (enumhand == EnumHand.OFF_HAND) {
        if (itemStack != null) {
            if (itemStack.getItem() == Items.LEAD) {
                ((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
                entityhuman.a(EnumHand.OFF_HAND, ItemStack.a);
                new BukkitRunnable() {

                    public void run() {
                        if (entityhuman instanceof EntityPlayer) {
                            entityhuman.a(EnumHand.OFF_HAND, itemStack);
                            Player p = (Player) entityhuman.getBukkitEntity();
                            if (!p.isOnline()) {
                                p.saveData();
                            }
                        }
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 5);
            }
        }
        return true;
    }
    if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
        if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isSkillActive(Ride.class) && canMove()) {
                if (itemStack != null && itemStack.getItem() == Items.LEAD) {
                    ((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
                    entityhuman.a(EnumHand.MAIN_HAND, ItemStack.a);
                    new BukkitRunnable() {

                        public void run() {
                            if (entityhuman instanceof EntityPlayer) {
                                entityhuman.a(EnumHand.MAIN_HAND, itemStack);
                                Player p = (Player) entityhuman.getBukkitEntity();
                                if (!p.isOnline()) {
                                    p.saveData();
                                }
                            }
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 5);
                }
                getOwner().sendMessage("Ironically pigs can not be ridden right now (Minecraft 1.10 problem)");
                return true;
            }
        }
    }
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack)) {
        return true;
    }
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
            getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack));
            if (!entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
                }
            }
            return true;
        } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
            EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
            entityitem.pickupDelay = 10;
            entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
            this.world.addEntity(entityitem);
            makeSound("entity.sheep.shear", 1.0F, 1.0F);
            getMyPet().setSaddle(null);
            if (!entityhuman.abilities.canInstantlyBuild) {
                itemStack.damage(1, entityhuman);
            }
            return true;
        } else if (Configuration.MyPet.Pig.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
            if (!entityhuman.abilities.canInstantlyBuild) {
                itemStack.subtract(1);
                if (itemStack.getCount() <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
                }
            }
            getMyPet().setBaby(false);
            return true;
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Ride(de.Keyle.MyPet.skill.skills.Ride)

Example 33 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project MyPet by xXKeyleXx.

the class EntityMyPet method handlePlayerInteraction.

// Obfuscated Method handler ------------------------------------------------------------------------------------
/**
 * Is called when player rightclicks this MyPet
 * return:
 * true: there was a reaction on rightclick
 * false: no reaction on rightclick
 */
public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
    if (itemStack != null && itemStack.getItem() == Items.LEAD) {
        ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, null));
        if (!entityhuman.abilities.canInstantlyBuild) {
            new BukkitRunnable() {

                public void run() {
                    ((EntityPlayer) entityhuman).updateInventory(entityhuman.defaultContainer);
                }
            }.runTaskLater(MyPetApi.getPlugin(), 5);
        }
    }
    if (enumhand == EnumHand.OFF_HAND) {
        return true;
    }
    Player owner = this.getOwner().getPlayer();
    if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
        if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isSkillActive(Ride.class) && canMove()) {
                if (Permissions.hasExtendedLegacy(owner, "MyPet.extended.ride")) {
                    ((CraftPlayer) owner).getHandle().startRiding(this);
                    return true;
                } else {
                    getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner().getLanguage()));
                }
            }
        }
        if (Configuration.Skilltree.Skill.CONTROL_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isSkillActive(de.Keyle.MyPet.skill.skills.Control.class)) {
                return true;
            }
        }
        if (itemStack != null) {
            if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasName()) {
                if (Permissions.hasLegacy(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) {
                    final String name = itemStack.getName();
                    getMyPet().setPetName(name);
                    EntityMyPet.super.setCustomName("-");
                    myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Name.New", myPet.getOwner()), name));
                    if (!entityhuman.abilities.canInstantlyBuild) {
                        --itemStack.count;
                    }
                    if (itemStack.count <= 0) {
                        entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                    }
                    new BukkitRunnable() {

                        public void run() {
                            updateNameTag();
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 1L);
                    return true;
                }
            }
            if (canEat(itemStack) && canUseItem()) {
                if (owner != null && !Permissions.hasExtendedLegacy(owner, "MyPet.extended.feed")) {
                    return false;
                }
                if (this.petTargetSelector.hasGoal("DuelTarget")) {
                    BehaviorDuelTarget duelTarget = (BehaviorDuelTarget) this.petTargetSelector.getGoal("DuelTarget");
                    if (duelTarget.getDuelOpponent() != null) {
                        return true;
                    }
                }
                boolean used = false;
                double saturation = Configuration.HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED;
                if (saturation > 0) {
                    if (myPet.getSaturation() < 100) {
                        MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Eat);
                        Bukkit.getPluginManager().callEvent(feedEvent);
                        if (!feedEvent.isCancelled()) {
                            saturation = feedEvent.getSaturation();
                            double missingSaturation = 100 - myPet.getSaturation();
                            myPet.setSaturation(myPet.getSaturation() + saturation);
                            saturation = Math.max(0, saturation - missingSaturation);
                            used = true;
                        }
                    }
                }
                if (saturation > 0) {
                    if (getHealth() < getMaxHealth()) {
                        MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Heal);
                        Bukkit.getPluginManager().callEvent(feedEvent);
                        if (!feedEvent.isCancelled()) {
                            saturation = feedEvent.getSaturation();
                            float missingHealth = getMaxHealth() - getHealth();
                            this.heal(Math.min((float) saturation, missingHealth), RegainReason.EATING);
                            used = true;
                        }
                    }
                }
                if (used) {
                    if (!entityhuman.abilities.canInstantlyBuild) {
                        if (--itemStack.count <= 0) {
                            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                        }
                    }
                    MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getHeadHeight(), 0), "HEART", 0.5F, 0.5F, 0.5F, 0.5F, 5, 20);
                    return true;
                }
            }
        }
    } else {
        if (itemStack != null) {
            if (itemStack.getItem() == Items.NAME_TAG) {
                if (itemStack.hasName()) {
                    EntityMyPet.super.setCustomName("-");
                    new BukkitRunnable() {

                        public void run() {
                            updateNameTag();
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 1L);
                    return false;
                }
            }
        }
    }
    return false;
}
Also used : Ride(de.Keyle.MyPet.skill.skills.Ride) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MyPetFeedEvent(de.Keyle.MyPet.api.event.MyPetFeedEvent) Ride(de.Keyle.MyPet.skill.skills.Ride)

Example 34 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project MyPet by xXKeyleXx.

the class Sprint method finish.

@Override
public void finish() {
    nav.getParameters().removeSpeedModifier("Sprint");
    new BukkitRunnable() {

        public void run() {
            petEntity.setSprinting(false);
        }
    }.runTaskLater(MyPetApi.getPlugin(), 25L);
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 35 with BukkitRunnable

use of org.bukkit.scheduler.BukkitRunnable in project MyPet by xXKeyleXx.

the class EntityMyPig method handlePlayerInteraction.

public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
    if (enumhand == EnumHand.OFF_HAND) {
        if (itemStack != null) {
            if (itemStack.getItem() == Items.LEAD) {
                ((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
                entityhuman.a(EnumHand.OFF_HAND, null);
                new BukkitRunnable() {

                    public void run() {
                        if (entityhuman instanceof EntityPlayer) {
                            entityhuman.a(EnumHand.OFF_HAND, itemStack);
                            Player p = (Player) entityhuman.getBukkitEntity();
                            if (!p.isOnline()) {
                                p.saveData();
                            }
                        }
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 5);
            }
        }
        return true;
    }
    if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
        if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isSkillActive(Ride.class) && canMove()) {
                if (itemStack != null && itemStack.getItem() == Items.LEAD) {
                    ((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
                    entityhuman.a(EnumHand.MAIN_HAND, null);
                    new BukkitRunnable() {

                        public void run() {
                            if (entityhuman instanceof EntityPlayer) {
                                entityhuman.a(EnumHand.MAIN_HAND, itemStack);
                                Player p = (Player) entityhuman.getBukkitEntity();
                                if (!p.isOnline()) {
                                    p.saveData();
                                }
                            }
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 5);
                }
                getOwner().sendMessage("Ironically pigs can not be ridden right now (Minecraft 1.10 problem)");
                return true;
            }
        }
    }
    if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack)) {
        return true;
    }
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
            getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack));
            if (!entityhuman.abilities.canInstantlyBuild) {
                if (--itemStack.count <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                }
            }
            return true;
        } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
            EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
            entityitem.pickupDelay = 10;
            entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
            this.world.addEntity(entityitem);
            makeSound("entity.sheep.shear", 1.0F, 1.0F);
            getMyPet().setSaddle(null);
            if (!entityhuman.abilities.canInstantlyBuild) {
                itemStack.damage(1, entityhuman);
            }
            return true;
        } else if (Configuration.MyPet.Pig.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
            if (!entityhuman.abilities.canInstantlyBuild) {
                if (--itemStack.count <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                }
            }
            getMyPet().setBaby(false);
            return true;
        }
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Ride(de.Keyle.MyPet.skill.skills.Ride)

Aggregations

BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)316 Player (org.bukkit.entity.Player)85 EventHandler (org.bukkit.event.EventHandler)52 Location (org.bukkit.Location)46 Vector (org.bukkit.util.Vector)45 Entity (org.bukkit.entity.Entity)29 ItemStack (org.bukkit.inventory.ItemStack)26 List (java.util.List)25 UUID (java.util.UUID)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)18 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)17 LivingEntity (org.bukkit.entity.LivingEntity)16 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)15 HashMap (java.util.HashMap)12 MyPetFeedEvent (de.Keyle.MyPet.api.event.MyPetFeedEvent)11 Material (org.bukkit.Material)11 EliteEntity (com.magmaguy.elitemobs.mobconstructor.EliteEntity)10 File (java.io.File)10 PotionEffect (org.bukkit.potion.PotionEffect)10