Search in sources :

Example 81 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class BehaviorAggressiveTarget method shouldFinish.

@Override
public boolean shouldFinish() {
    if (!petEntity.canMove()) {
        return true;
    } else if (petEntity.getMyPetTarget() == null) {
        return true;
    }
    EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle();
    if (!target.isAlive()) {
        return true;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill.getBehavior() != BehaviorMode.Aggressive) {
        return true;
    } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return true;
    } else if (target.world != petEntity.world) {
        return true;
    } else if (petEntity.h(target) > 400) {
        return true;
    } else if (petEntity.h(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600) {
        return true;
    }
    return false;
}
Also used : EntityLiving(net.minecraft.server.v1_16_R1.EntityLiving) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R1.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 82 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class BehaviorFarmTarget method shouldFinish.

@Override
public boolean shouldFinish() {
    if (!petEntity.canMove()) {
        return true;
    }
    if (!this.petEntity.hasTarget()) {
        return true;
    }
    EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
    if (!target.isAlive()) {
        return true;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill.getBehavior() != BehaviorMode.Farm) {
        return true;
    } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return true;
    } else if (target.world != petEntity.world) {
        return true;
    } else if (petEntity.h(target) > 400) {
        return true;
    } else if (petEntity.h(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600) {
        return true;
    }
    return false;
}
Also used : EntityLiving(net.minecraft.server.v1_16_R1.EntityLiving) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R1.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 83 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer 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 EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
    new BukkitRunnable() {

        @Override
        public void run() {
            EntityPlayer player = ((EntityPlayer) entityhuman);
            if (player.getBukkitEntity().isOnline()) {
                player.updateInventory(entityhuman.defaultContainer);
            }
        }
    }.runTaskLater(MyPetApi.getPlugin(), 5);
    if (itemStack != null && itemStack.getItem() == Items.LEAD) {
        ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, null));
    }
    if (enumhand == EnumHand.OFF_HAND) {
        return EnumInteractionResult.SUCCESS;
    }
    Player owner = this.getOwner().getPlayer();
    if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
        if ((Configuration.Skilltree.Skill.Ride.RIDE_ITEM == null && !canEat(itemStack) && !owner.isSneaking()) || (Configuration.Skilltree.Skill.Ride.RIDE_ITEM != null && Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack))) {
            if (myPet.getSkills().isActive(RideImpl.class) && canMove()) {
                if (Permissions.hasExtended(owner, "MyPet.extended.ride")) {
                    ((CraftPlayer) owner).getHandle().startRiding(this);
                    return EnumInteractionResult.CONSUME;
                } else {
                    getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner()), 2000);
                }
            }
        }
        if (Configuration.Skilltree.Skill.CONTROL_ITEM.compare(itemStack)) {
            if (myPet.getSkills().isActive(ControlImpl.class)) {
                return EnumInteractionResult.CONSUME;
            }
        }
        if (itemStack != null) {
            if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasName()) {
                if (Permissions.has(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) {
                    final String name = itemStack.getName().getString();
                    getMyPet().setPetName(name);
                    EntityMyPet.super.setCustomName(CraftChatMessage.fromStringOrNull("-"));
                    myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Name.New", myPet.getOwner()), name));
                    if (!entityhuman.abilities.canInstantlyBuild) {
                        itemStack.subtract(1);
                    }
                    if (itemStack.getCount() <= 0) {
                        entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                    }
                    new BukkitRunnable() {

                        @Override
                        public void run() {
                            updateNameTag();
                        }
                    }.runTaskLater(MyPetApi.getPlugin(), 1L);
                    return EnumInteractionResult.CONSUME;
                }
            }
            if (canEat(itemStack) && canUseItem()) {
                if (owner != null && !Permissions.hasExtended(owner, "MyPet.extended.feed")) {
                    return EnumInteractionResult.CONSUME;
                }
                if (this.petTargetSelector.hasGoal("DuelTarget")) {
                    BehaviorDuelTarget duelTarget = (BehaviorDuelTarget) this.petTargetSelector.getGoal("DuelTarget");
                    if (duelTarget.getDuelOpponent() != null) {
                        return EnumInteractionResult.CONSUME;
                    }
                }
                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() < myPet.getMaxHealth()) {
                        MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Heal);
                        Bukkit.getPluginManager().callEvent(feedEvent);
                        if (!feedEvent.isCancelled()) {
                            saturation = feedEvent.getSaturation();
                            double missingHealth = myPet.getMaxHealth() - getHealth();
                            this.heal((float) Math.min(saturation, missingHealth), RegainReason.EATING);
                            used = true;
                        }
                    }
                }
                if (used) {
                    if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
                        itemStack.subtract(1);
                        if (itemStack.getCount() <= 0) {
                            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
                        }
                    }
                    MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getHeadHeight(), 0), ParticleCompat.HEART.get(), 0.5F, 0.5F, 0.5F, 0.5F, 5, 20);
                    return EnumInteractionResult.CONSUME;
                }
            }
        }
        if (!owner.isSneaking() && !Configuration.Misc.RIGHT_CLICK_COMMAND.isEmpty()) {
            String command = Configuration.Misc.RIGHT_CLICK_COMMAND;
            command = command.replaceAll("%pet_name%", myPet.getPetName());
            command = command.replaceAll("%pet_owner%", myPet.getOwner().getName());
            command = command.replaceAll("%pet_level%", "" + myPet.getExperience().getLevel());
            command = command.replaceAll("%pet_status%", "" + myPet.getStatus().name());
            command = command.replaceAll("%pet_type%", myPet.getPetType().name());
            command = command.replaceAll("%pet_uuid%", myPet.getUUID().toString());
            command = command.replaceAll("%pet_world_group%", myPet.getWorldGroup());
            command = command.replaceAll("%pet_skilltree_name%", myPet.getSkilltree() != null ? myPet.getSkilltree().getName() : "");
            return owner.performCommand(command) ? EnumInteractionResult.CONSUME : EnumInteractionResult.PASS;
        }
    } else {
        if (itemStack != null) {
            if (itemStack.getItem() == Items.NAME_TAG) {
                if (itemStack.hasName()) {
                    EntityMyPet.super.setCustomName(CraftChatMessage.fromStringOrNull("-"));
                    new BukkitRunnable() {

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

Example 84 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class BehaviorAggressiveTarget method shouldFinish.

@Override
public boolean shouldFinish() {
    if (!petEntity.canMove()) {
        return true;
    } else if (petEntity.getMyPetTarget() == null) {
        return true;
    }
    EntityLiving target = ((CraftLivingEntity) petEntity.getMyPetTarget()).getHandle();
    if (!target.isAlive()) {
        return true;
    }
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (behaviorSkill.getBehavior() != BehaviorMode.Aggressive) {
        return true;
    } else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return true;
    } else if (target.world != petEntity.world) {
        return true;
    } else if (petEntity.h(target) > 400) {
        return true;
    } else
        return petEntity.h(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600;
}
Also used : EntityLiving(net.minecraft.server.v1_16_R3.EntityLiving) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 85 with CraftPlayer

use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.

the class PlatformHelper method playParticleEffect.

/**
 * @param location   the {@link Location} around which players must be to see the effect
 * @param effectName list of effects: https://gist.github.com/riking/5759002
 * @param offsetX    the amount to be randomly offset by in the X axis
 * @param offsetY    the amount to be randomly offset by in the Y axis
 * @param offsetZ    the amount to be randomly offset by in the Z axis
 * @param speed      the speed of the particles
 * @param count      the number of particles
 * @param radius     the radius around the location
 */
@Override
public void playParticleEffect(Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius, de.Keyle.MyPet.api.compat.Compat<Object> data) {
    Particle effect = IRegistry.PARTICLE_TYPE.get(new MinecraftKey(effectName));
    Validate.notNull(location, "Location cannot be null");
    Validate.notNull(effect, "Effect cannot be null");
    Validate.notNull(location.getWorld(), "World cannot be null");
    ParticleParam particle = null;
    if (effect.d() != null && data != null) {
        try {
            particle = effect.d().b(effect, new StringReader(" " + data.get().toString()));
        } catch (CommandSyntaxException e) {
            e.printStackTrace();
        }
    } else if (effect instanceof ParticleType) {
        particle = (ParticleType) effect;
    }
    if (particle == null) {
        return;
    }
    PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(particle, false, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count);
    radius = radius * radius;
    for (Player player : location.getWorld().getPlayers()) {
        if ((int) MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), location) <= radius) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) StringReader(com.mojang.brigadier.StringReader) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException)

Aggregations

Player (org.bukkit.entity.Player)250 ServerPlayer (net.minecraft.server.level.ServerPlayer)140 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)113 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)90 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)81 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)81 ItemStack (org.bukkit.inventory.ItemStack)80 Location (org.bukkit.Location)75 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)70 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)66 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)57 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)52 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)51 GameProfile (com.mojang.authlib.GameProfile)48 EntityPlayer (net.minecraft.server.level.EntityPlayer)47 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)45 CraftPlayer (org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer)45 Property (com.mojang.authlib.properties.Property)44 CraftPlayer (org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer)42 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)41