Search in sources :

Example 1 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project solinia3-core by mixxit.

the class CommandPet method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // TODO Auto-generated method stub
    if (sender instanceof Player) {
        try {
            Player player = (Player) sender;
            LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player.getUniqueId());
            if (pet == null) {
                player.sendMessage("You don't have a pet");
                return true;
            }
            if (pet instanceof Sittable) {
                Sittable sittable = (Sittable) pet;
                if (sittable.isSitting()) {
                    player.sendMessage("You cannot control a pet which is sitting");
                    return true;
                }
            }
            ISoliniaLivingEntity petLivingEntity = SoliniaLivingEntityAdapter.Adapt(pet);
            ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
            if (petLivingEntity == null || solPlayer == null)
                return false;
            if (args.length > 0) {
                String petcommand = args[0];
                if (petcommand.equals("leave")) {
                    if (petLivingEntity != null) {
                        petLivingEntity.clearHateList();
                        if (petLivingEntity.IsCorePet()) {
                            solPlayer.killAllPets();
                        } else {
                            StateManager.getInstance().getEntityManager().removePet(player.getUniqueId(), !petLivingEntity.isCharmed());
                            petLivingEntity.clearHateList();
                        }
                        player.setLastDamageCause(null);
                    }
                }
                if (petcommand.equals("back")) {
                    if (petLivingEntity != null) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(petLivingEntity.getNpcid());
                        if (npc != null)
                            if (npc.isPetControllable() == false) {
                                player.sendMessage("This pet is not controllable");
                                return true;
                            }
                        player.setLastDamageCause(null);
                        petLivingEntity.clearHateList();
                        ChatUtils.SendHint(player, HINT.PET_BACKINGOFFTGT, "", false);
                        EntityUtils.teleportSafely(pet, player.getLocation());
                    }
                }
                if (petcommand.equals("attack")) {
                    if (solPlayer.getEntityTarget() == null) {
                        ChatUtils.SendHint(player, HINT.NEED_TARGET, "", false);
                    }
                    LivingEntity targetentity = solPlayer.getEntityTarget();
                    if (targetentity != null && !targetentity.getUniqueId().equals(player.getUniqueId())) {
                        if (petLivingEntity != null) {
                            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(petLivingEntity.getNpcid());
                            if (npc != null)
                                if (npc.isPetControllable() == false) {
                                    player.sendMessage("This pet is not controllable");
                                    return true;
                                }
                        }
                        EntityUtils.teleportSafely(pet, player.getLocation());
                        petLivingEntity.setAttackTarget(null);
                        // Mez cancel target
                        Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed(targetentity);
                        if (mezExpiry != null) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack a mezzed target");
                            return false;
                        }
                        if (pet.getUniqueId().equals(targetentity.getUniqueId())) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack itself");
                            return false;
                        }
                        if (petLivingEntity.getOwnerEntity().getUniqueId().equals(targetentity.getUniqueId())) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack you!");
                            return false;
                        }
                        ISoliniaPlayer tmpPlayer = SoliniaPlayerAdapter.Adapt(player);
                        if (tmpPlayer != null && tmpPlayer.isInGroup(targetentity)) {
                            petLivingEntity.setAttackTarget(null);
                            player.sendMessage("You cannot send your pet to attack your group!");
                            return false;
                        }
                        if (!pet.getUniqueId().equals(targetentity.getUniqueId())) {
                            petLivingEntity.setAttackTarget(targetentity);
                            player.sendMessage("You send your pet to attack!");
                            return true;
                        }
                        ChatUtils.SendHint(player, HINT.PET_ATTACKINGTGT, targetentity.getCustomName(), false);
                    }
                    return true;
                }
                if (petcommand.equals("equip")) {
                    if (petLivingEntity != null) {
                        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(petLivingEntity.getNpcid());
                        if (npc != null)
                            if (npc.isPetControllable() == false) {
                                player.sendMessage("This pet is not controllable/equippable");
                                return true;
                            }
                    }
                    PetEquip(player, pet);
                }
                if (petcommand.equals("hatelist")) {
                    player.sendMessage("Hate List: ");
                    if (petLivingEntity != null) {
                        petLivingEntity.sendHateList(player);
                    }
                }
            }
            player.sendMessage("Pet Name: " + pet.getName() + " Pet Level: " + petLivingEntity.getMentorLevel());
            player.sendMessage("Pet HP: " + pet.getHealth() + "/" + pet.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
            EntityInsentient entityhandle = (EntityInsentient) ((org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) pet).getHandle();
            double dmg = entityhandle.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).getValue();
            player.sendMessage("Pet DMG: " + dmg + " (Hand to Hand)");
            Entity target = ((Creature) pet).getTarget();
            if (target == null) {
                player.sendMessage("Pet Target: None");
            } else {
                player.sendMessage("Pet Target: " + target.getCustomName() + "/" + target.getName());
            }
            player.sendMessage("STR: " + petLivingEntity.getStrength() + " STA: " + petLivingEntity.getStamina() + " AGI: " + petLivingEntity.getAgility() + " DEX: " + petLivingEntity.getDexterity() + " INT: " + petLivingEntity.getIntelligence() + " WIS: " + petLivingEntity.getWisdom() + " CHA: " + petLivingEntity.getCharisma());
            player.sendMessage("Pet Armour Class Mitigation (AC): " + petLivingEntity.getMitigationAC());
            player.sendMessage("Pet Attack Value: " + petLivingEntity.getTotalAtk());
            player.sendMessage("Pet Attack Speed: " + ChatColor.GOLD + petLivingEntity.getHaste() + "%" + ChatColor.RESET);
            player.sendMessage("Pet MainWeapon Attack Rate (Seconds): " + ChatColor.GOLD + petLivingEntity.getAutoAttackTimerFrequencySeconds() + ChatColor.RESET);
            player.sendMessage("Pet Total Rune of: " + petLivingEntity.getRune());
            player.sendMessage("Skills:");
            if (petLivingEntity.getClassObj() != null) {
                if (petLivingEntity.getClassObj().getDodgelevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getDodgelevel())
                        player.sendMessage(ChatColor.GRAY + "Dodge Skill: " + petLivingEntity.getSkill(SkillType.Dodge));
                if (petLivingEntity.getClassObj().getRipostelevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getRipostelevel())
                        player.sendMessage(ChatColor.GRAY + "Riposte Skill: " + petLivingEntity.getSkill(SkillType.Riposte));
                if (petLivingEntity.getClassObj().getDoubleattacklevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getDoubleattacklevel())
                        player.sendMessage(ChatColor.GRAY + "Double Attack Skill: " + petLivingEntity.getSkill(SkillType.DoubleAttack));
                if (petLivingEntity.getClassObj().getSafefalllevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getSafefalllevel())
                        player.sendMessage(ChatColor.GRAY + "Safefall Skill: " + petLivingEntity.getSkill(SkillType.SafeFall));
                if (petLivingEntity.getClassObj().getDualwieldlevel() > 0)
                    if (petLivingEntity.getMentorLevel() >= petLivingEntity.getClassObj().getDualwieldlevel())
                        player.sendMessage(ChatColor.GRAY + "Dual Wield: " + petLivingEntity.getSkill(SkillType.DualWield));
            }
            player.sendMessage("Active Effects:");
            SoliniaEntitySpells spells = StateManager.getInstance().getEntityManager().getActiveEntitySpells(pet);
            for (SoliniaActiveSpell activeSpell : spells.getActiveSpells()) {
                ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                String removetext = "";
                ChatColor spellcolor = ChatColor.GREEN;
                if (spell.isBeneficial()) {
                    removetext = "Removable spell";
                } else {
                    removetext = "Unremovable spell";
                    spellcolor = ChatColor.RED;
                }
                TextComponent tc = new TextComponent();
                tc.setText("- " + spellcolor + spell.getName() + ChatColor.RESET + " " + activeSpell.getTicksLeft() + " ticks left - ");
                TextComponent tc2 = new TextComponent();
                tc2.setText(removetext);
                tc.addExtra(tc2);
                sender.spigot().sendMessage(tc);
            }
            player.sendMessage("Pet subcommands: /pet back | /pet equip | /pet attack | /pet leave");
            return true;
        } catch (CoreStateInitException e) {
        }
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Sittable(org.bukkit.entity.Sittable) Creature(org.bukkit.entity.Creature) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) EntityInsentient(net.minecraft.server.v1_15_R1.EntityInsentient) Timestamp(java.sql.Timestamp) SoliniaEntitySpells(com.solinia.solinia.Models.SoliniaEntitySpells) 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) ChatColor(net.md_5.bungee.api.ChatColor) SoliniaActiveSpell(com.solinia.solinia.Models.SoliniaActiveSpell)

Example 2 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (PATHFINDING_RANGE == null)
        return;
    EntityInsentient handle = (EntityInsentient) en;
    NavigationAbstract navigation = handle.getNavigation();
    try {
        AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.get(navigation);
        inst.setValue(pathfindingRange);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_10_R1.EntityLiving) AttributeInstance(net.minecraft.server.v1_10_R1.AttributeInstance) EntityInsentient(net.minecraft.server.v1_10_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_10_R1.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC)

Example 3 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method getTargetNavigator.

private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<NavigationAbstract, Boolean> function) {
    net.minecraft.server.v1_13_R2.Entity raw = getHandle(entity);
    raw.onGround = true;
    // not sure of a better way around this - if onGround is false, then
    // navigation won't execute, and calling entity.move doesn't
    // entirely fix the problem.
    final NavigationAbstract navigation = NMSImpl.getNavigation(entity);
    final float oldWater = raw instanceof EntityPlayer ? ((EntityHumanNPC) raw).a(PathType.WATER) : ((EntityInsentient) raw).a(PathType.WATER);
    if (params.avoidWater() && oldWater >= 0) {
        if (raw instanceof EntityPlayer) {
            ((EntityHumanNPC) raw).a(PathType.WATER, oldWater + 1F);
        } else {
            ((EntityInsentient) raw).a(PathType.WATER, oldWater + 1F);
        }
    }
    return new MCNavigator() {

        float lastSpeed;

        CancelReason reason;

        @Override
        public CancelReason getCancelReason() {
            return reason;
        }

        @Override
        public Iterable<Vector> getPath() {
            return new NavigationIterable(navigation);
        }

        @Override
        public void stop() {
            if (params.debug() && navigation.m() != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.m().d(); i++) {
                        PathPoint pp = navigation.m().a(i);
                        org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getBlockData());
                    }
                }
            }
            if (oldWater >= 0) {
                if (raw instanceof EntityPlayer) {
                    ((EntityHumanNPC) raw).a(PathType.WATER, oldWater);
                } else {
                    ((EntityInsentient) raw).a(PathType.WATER, oldWater);
                }
            }
            stopNavigation(navigation);
        }

        @Override
        public boolean update() {
            if (params.speed() != lastSpeed) {
                if (Messaging.isDebugging() && lastSpeed > 0) {
                    Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change");
                }
                Entity handle = getHandle(entity);
                float oldWidth = handle.width;
                if (handle instanceof EntityHorse) {
                    handle.width = Math.min(0.99f, oldWidth);
                }
                if (!function.apply(navigation)) {
                    reason = CancelReason.STUCK;
                }
                // minecraft requires that an entity fit onto both blocks if width >= 1f,
                handle.width = oldWidth;
                // but we'd prefer to make it just fit on 1 so hack around it a bit.
                lastSpeed = params.speed();
            }
            if (params.debug() && !NMSImpl.isNavigationFinished(navigation)) {
                BlockData data = Material.DANDELION.createBlockData();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.m().d(); i++) {
                        PathPoint pp = navigation.m().a(i);
                        player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), data);
                    }
                }
            }
            navigation.a(params.speed());
            return NMSImpl.isNavigationFinished(navigation);
        }
    };
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_13_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityInsentient(net.minecraft.server.v1_13_R2.EntityInsentient) Entity(net.minecraft.server.v1_13_R2.Entity) NavigationAbstract(net.minecraft.server.v1_13_R2.NavigationAbstract) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC) PathPoint(net.minecraft.server.v1_13_R2.PathPoint) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) EntityHorse(net.minecraft.server.v1_13_R2.EntityHorse) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) EntityPlayer(net.minecraft.server.v1_13_R2.EntityPlayer) BlockData(org.bukkit.block.data.BlockData) IBlockData(net.minecraft.server.v1_13_R2.IBlockData) Vector(org.bukkit.util.Vector)

Example 4 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class PlayerControllerMove method a.

@Override
public void a() {
    this.a.bj = 0F;
    if (this.f) {
        this.f = false;
        BoundingBox bb = NMSBoundingBox.wrap(this.a.getBoundingBox());
        int i = MathHelper.floor(bb.minY + 0.5D);
        double d0 = this.b - this.a.locX;
        double d1 = this.d - this.a.locZ;
        double d2 = this.c - i;
        double d3 = d0 * d0 + d2 * d2 + d1 * d1;
        if (d3 < 2.500000277905201E-007D) {
            // bi
            this.a.bj = (0.0F);
            return;
        }
        float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
        this.a.yaw = a(this.a.yaw, f, 90.0F);
        NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw);
        AttributeInstance speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
        if (!(this.a instanceof EntitySlime)) {
            speed.setValue(0.1D * this.e);
        }
        float movement = (float) (this.e * speed.getValue()) * 10;
        this.a.o(movement);
        this.a.bj = movement;
        if (shouldSlimeJump() || ((d2 >= NMS.getStepHeight(a.getBukkitEntity())) && (d0 * d0 + d1 * d1 < 1.0D))) {
            this.h = cg();
            this.h /= 3;
            if (this.a instanceof EntityHumanNPC) {
                ((EntityHumanNPC) this.a).getControllerJump().a();
            } else {
                ((EntityInsentient) this.a).getControllerJump().a();
            }
        }
    }
}
Also used : BoundingBox(net.citizensnpcs.api.util.BoundingBox) AttributeInstance(net.minecraft.server.v1_13_R2.AttributeInstance) EntitySlime(net.minecraft.server.v1_13_R2.EntitySlime) EntityHumanNPC(net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC)

Example 5 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method getDestination.

@Override
public Location getDestination(org.bukkit.entity.Entity entity) {
    Entity handle = getHandle(entity);
    ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
    return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) EntityInsentient(net.minecraft.server.v1_13_R2.EntityInsentient) ControllerMove(net.minecraft.server.v1_13_R2.ControllerMove) EntityHumanNPC(net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC) Location(org.bukkit.Location)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)43 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)42 Location (org.bukkit.Location)18 EntityInsentient (net.minecraft.server.v1_16_R3.EntityInsentient)12 EntityInsentient (net.minecraft.server.v1_15_R1.EntityInsentient)11 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)9 CommandException (net.citizensnpcs.api.command.exception.CommandException)8 EntityHumanNPC (net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC)8 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)8 EntityInsentient (net.minecraft.server.v1_12_R1.EntityInsentient)8 EntityInsentient (net.minecraft.server.v1_14_R1.EntityInsentient)8 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)7 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)7 EntityHumanNPC (net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)7 MCNavigator (net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator)7 EntityInsentient (net.minecraft.server.v1_11_R1.EntityInsentient)7 PathEntity (net.minecraft.server.v1_13_R2.PathEntity)7 PathEntity (net.minecraft.server.v1_15_R1.PathEntity)7 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)7 Vector (org.bukkit.util.Vector)7