Search in sources :

Example 6 with BehaviorImpl

use of de.Keyle.MyPet.skill.skills.BehaviorImpl in project MyPet by xXKeyleXx.

the class BehaviorDuelTarget method shouldStart.

@Override
public boolean shouldStart() {
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (!behaviorSkill.isActive() || behaviorSkill.getBehavior() != BehaviorMode.Duel) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    if (!petEntity.canMove()) {
        return false;
    }
    if (petEntity.hasTarget()) {
        return false;
    }
    if (duelOpponent != null) {
        this.target = duelOpponent;
        return true;
    }
    for (EntityMyPet entityMyPet : this.petEntity.world.a(EntityMyPet.class, this.petOwnerEntity.getBoundingBox().grow(range, range, range))) {
        MyPet targetMyPet = entityMyPet.getMyPet();
        if (entityMyPet != petEntity && entityMyPet.isAlive()) {
            if (!targetMyPet.getSkills().isActive(BehaviorImpl.class) || !targetMyPet.getEntity().get().canMove()) {
                continue;
            }
            BehaviorImpl targetbehavior = targetMyPet.getSkills().get(BehaviorImpl.class);
            if (targetbehavior.getBehavior() != BehaviorMode.Duel) {
                continue;
            }
            if (targetMyPet.getDamage() == 0) {
                continue;
            }
            this.target = entityMyPet;
            return true;
        }
    }
    return false;
}
Also used : EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_16_R3.entity.EntityMyPet) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 7 with BehaviorImpl

use of de.Keyle.MyPet.skill.skills.BehaviorImpl in project MyPet by xXKeyleXx.

the class EntityMyEnderman method doMyPetTick.

@Override
protected void doMyPetTick() {
    super.doMyPetTick();
    BehaviorImpl skill = getMyPet().getSkills().get(BehaviorImpl.class);
    Behavior.BehaviorMode behavior = skill.getBehavior();
    if (behavior == Behavior.BehaviorMode.Aggressive) {
        if (!getMyPet().isScreaming()) {
            getMyPet().setScreaming(true);
        }
    } else {
        if (getMyPet().isScreaming()) {
            getMyPet().setScreaming(false);
        }
    }
}
Also used : BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 8 with BehaviorImpl

use of de.Keyle.MyPet.skill.skills.BehaviorImpl in project MyPet by xXKeyleXx.

the class BehaviorDuelTarget method shouldStart.

@Override
public boolean shouldStart() {
    Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
    if (!behaviorSkill.isActive() || behaviorSkill.getBehavior() != BehaviorMode.Duel) {
        return false;
    }
    if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
        return false;
    }
    if (!petEntity.canMove()) {
        return false;
    }
    if (petEntity.hasTarget()) {
        return false;
    }
    if (duelOpponent != null) {
        this.target = duelOpponent;
        return true;
    }
    for (EntityMyPet entityMyPet : this.petEntity.level.getEntitiesOfClass(EntityMyPet.class, this.petOwnerEntity.getBoundingBox().inflate(range, range, range))) {
        MyPet targetMyPet = entityMyPet.getMyPet();
        if (entityMyPet != petEntity && entityMyPet.isAlive()) {
            if (!targetMyPet.getSkills().isActive(BehaviorImpl.class) || !targetMyPet.getEntity().get().canMove()) {
                continue;
            }
            BehaviorImpl targetbehavior = targetMyPet.getSkills().get(BehaviorImpl.class);
            if (targetbehavior.getBehavior() != BehaviorMode.Duel) {
                continue;
            }
            if (targetMyPet.getDamage() == 0) {
                continue;
            }
            this.target = entityMyPet;
            return true;
        }
    }
    return false;
}
Also used : EntityMyPet(de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet) BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) MyPet(de.Keyle.MyPet.api.entity.MyPet) EntityMyPet(de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Example 9 with BehaviorImpl

use of de.Keyle.MyPet.skill.skills.BehaviorImpl in project MyPet by xXKeyleXx.

the class CommandInfo method onCommand.

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    MyPetPlayer petOwner;
    if (args.length == 0 && sender instanceof Player) {
        Player player = (Player) sender;
        if (WorldGroup.getGroupByWorld(player.getWorld()).isDisabled()) {
            player.sendMessage(Translation.getString("Message.No.AllowedHere", player));
            return true;
        }
        if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
            petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(player);
        } else {
            sender.sendMessage(Translation.getString("Message.No.HasPet", player));
            return true;
        }
    } else if (args.length > 0 && (!(sender instanceof Player) || Permissions.has((Player) sender, "MyPet.command.info.other"))) {
        Player p = Bukkit.getServer().getPlayer(args[0]);
        if (p == null || !p.isOnline()) {
            sender.sendMessage(Translation.getString("Message.No.PlayerOnline", sender));
            return true;
        }
        if (MyPetApi.getPlayerManager().isMyPetPlayer(args[0])) {
            petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(args[0]);
        } else {
            sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", sender), args[0]));
            return true;
        }
    } else {
        if (sender instanceof Player) {
            sender.sendMessage(Translation.getString("Message.No.AllowedHere", sender));
        } else {
            sender.sendMessage("You can't use this command from server console!");
        }
        return true;
    }
    if (petOwner.hasMyPet()) {
        boolean infoShown = false;
        MyPet myPet = petOwner.getMyPet();
        if (canSee(PetInfoDisplay.Name.adminOnly, sender, myPet)) {
            sender.sendMessage(ChatColor.AQUA + myPet.getPetName() + ChatColor.RESET + ":");
            infoShown = true;
        }
        if (!petOwner.equals(sender) && canSee(!PetInfoDisplay.Owner.adminOnly, sender, myPet)) {
            sender.sendMessage("   " + Translation.getString("Name.Owner", sender) + ": " + myPet.getOwner().getName());
            infoShown = true;
        }
        if (canSee(PetInfoDisplay.HP.adminOnly, sender, myPet)) {
            String msg;
            if (myPet.getStatus() == PetState.Dead) {
                msg = ChatColor.RED + Translation.getString("Name.Dead", sender);
            } else {
                if (myPet.getHealth() > myPet.getMaxHealth() / 3 * 2) {
                    msg = "" + ChatColor.GREEN;
                } else if (myPet.getHealth() > myPet.getMaxHealth() / 3) {
                    msg = "" + ChatColor.YELLOW;
                } else {
                    msg = "" + ChatColor.RED;
                }
                msg += String.format("%1.2f", myPet.getHealth()) + ChatColor.WHITE + "/" + String.format("%1.2f", myPet.getMaxHealth());
            }
            sender.sendMessage("   " + Translation.getString("Name.HP", sender) + ": " + msg);
            infoShown = true;
        }
        if (canSee(PetInfoDisplay.RespawnTime.adminOnly, sender, myPet)) {
            if (myPet.getStatus() == PetState.Dead) {
                sender.sendMessage("   " + Translation.getString("Name.Respawntime", sender) + ": " + myPet.getRespawnTime());
                infoShown = true;
            }
        }
        if (myPet.getDamage() > 0 && canSee(PetInfoDisplay.Damage.adminOnly, sender, myPet)) {
            sender.sendMessage("   " + Translation.getString("Name.Damage", sender) + ": " + String.format("%1.2f", myPet.getDamage()));
            infoShown = true;
        }
        if (myPet.getRangedDamage() > 0 && canSee(PetInfoDisplay.RangedDamage.adminOnly, sender, myPet)) {
            sender.sendMessage("   " + Translation.getString("Name.RangedDamage", sender) + ": " + String.format("%1.2f", myPet.getRangedDamage()));
            infoShown = true;
        }
        if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && canSee(PetInfoDisplay.Hunger.adminOnly, sender, myPet)) {
            sender.sendMessage("   " + Translation.getString("Name.Hunger", sender) + ": " + Math.round(myPet.getSaturation()));
            if (sender instanceof Player) {
                Player player = (Player) sender;
                FancyMessage m = new FancyMessage("   " + Translation.getString("Name.Food", player) + ": ");
                boolean comma = false;
                for (ConfigItem material : MyPetApi.getMyPetInfo().getFood(myPet.getPetType())) {
                    ItemStack is = material.getItem();
                    if (is == null || is.getType() == Material.AIR) {
                        continue;
                    }
                    if (comma) {
                        m.then(", ");
                    }
                    if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
                        m.then(is.getItemMeta().getDisplayName());
                    } else {
                        try {
                            m.thenTranslate(MyPetApi.getPlatformHelper().getVanillaName(is));
                        } catch (Exception e) {
                            MyPetApi.getLogger().warning("A food item caused an error. If you think this is a bug please report it to the MyPet developer.");
                            MyPetApi.getLogger().warning("" + is);
                            e.printStackTrace();
                            continue;
                        }
                    }
                    m.color(ChatColor.GOLD);
                    ItemTooltip it = new ItemTooltip();
                    it.setMaterial(is.getType());
                    if (is.hasItemMeta()) {
                        if (is.getItemMeta().hasDisplayName()) {
                            it.setTitle(is.getItemMeta().getDisplayName());
                        }
                        if (is.getItemMeta().hasLore()) {
                            it.setLore(is.getItemMeta().getLore().toArray(new String[0]));
                        }
                    }
                    m.itemTooltip(it);
                    comma = true;
                }
                MyPetApi.getPlatformHelper().sendMessageRaw(player, m.toJSONString());
            } else {
                String foodString = "   " + Translation.getString("Name.Food", sender) + ": ";
                foodString += String.join(", ", MyPetApi.getMyPetInfo().getFood(myPet.getPetType()).stream().filter(configItem -> configItem.getItem() != null && configItem.getItem().getType() != Material.AIR).map(configItem -> configItem.getItem().getType().name()).collect(Collectors.toList()));
                sender.sendMessage(foodString);
            }
            infoShown = true;
        }
        if (canSee(PetInfoDisplay.Behavior.adminOnly, sender, myPet)) {
            if (myPet.getSkills().has(BehaviorImpl.class)) {
                BehaviorImpl behavior = myPet.getSkills().get(BehaviorImpl.class);
                sender.sendMessage("   " + Translation.getString("Name.Skill.Behavior", sender) + ": " + Translation.getString("Name." + behavior.getBehavior().name(), sender));
                infoShown = true;
            }
        }
        if (canSee(PetInfoDisplay.Skilltree.adminOnly, sender, myPet) && myPet.getSkilltree() != null) {
            sender.sendMessage("   " + Translation.getString("Name.Skilltree", sender) + ": " + Colorizer.setColors(myPet.getSkilltree().getDisplayName()));
            infoShown = true;
        }
        if (canSee(PetInfoDisplay.Level.adminOnly, sender, myPet)) {
            int lvl = myPet.getExperience().getLevel();
            sender.sendMessage("   " + Translation.getString("Name.Level", sender) + ": " + lvl);
            infoShown = true;
        }
        int maxLevel = myPet.getSkilltree() != null ? myPet.getSkilltree().getMaxLevel() : Configuration.LevelSystem.Experience.LEVEL_CAP;
        if (canSee(PetInfoDisplay.Exp.adminOnly, sender, myPet) && myPet.getExperience().getLevel() < maxLevel) {
            double exp = myPet.getExperience().getCurrentExp();
            double reqEXP = myPet.getExperience().getRequiredExp();
            sender.sendMessage("   " + Translation.getString("Name.Exp", sender) + ": " + String.format("%1.2f", exp) + "/" + String.format("%1.2f", reqEXP));
            infoShown = true;
        }
        if (myPet.getOwner().getDonationRank() != DonateCheck.DonationRank.None) {
            infoShown = true;
            String donationMessage = "" + ChatColor.GOLD;
            donationMessage += myPet.getOwner().getDonationRank().getDefaultIcon();
            donationMessage += " " + Translation.getString("Name.Title." + myPet.getOwner().getDonationRank().name(), sender) + " ";
            donationMessage += myPet.getOwner().getDonationRank().getDefaultIcon();
            sender.sendMessage("   " + donationMessage);
        }
        if (!infoShown) {
            sender.sendMessage(Translation.getString("Message.CantViewPetInfo", sender));
        }
        return true;
    } else {
        if (args.length > 0) {
            sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", sender), args[0]));
        } else {
            sender.sendMessage(Translation.getString("Message.No.HasPet", sender));
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) DonateCheck(de.Keyle.MyPet.api.player.DonateCheck) WorldGroup(de.Keyle.MyPet.api.WorldGroup) Configuration(de.Keyle.MyPet.api.Configuration) ConfigItem(de.Keyle.MyPet.api.util.ConfigItem) Translation(de.Keyle.MyPet.api.util.locale.Translation) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) MyPet(de.Keyle.MyPet.api.entity.MyPet) Util(de.Keyle.MyPet.api.Util) CommandSender(org.bukkit.command.CommandSender) PetState(de.Keyle.MyPet.api.entity.MyPet.PetState) MyPetApi(de.Keyle.MyPet.MyPetApi) BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) CommandTabCompleter(de.Keyle.MyPet.api.commands.CommandTabCompleter) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) Colorizer(de.Keyle.MyPet.api.util.Colorizer) List(java.util.List) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) Permissions(de.Keyle.MyPet.api.player.Permissions) FancyMessage(de.Keyle.MyPet.api.util.chat.FancyMessage) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) Collections(java.util.Collections) ItemTooltip(de.Keyle.MyPet.api.util.chat.parts.ItemTooltip) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) MyPet(de.Keyle.MyPet.api.entity.MyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) ConfigItem(de.Keyle.MyPet.api.util.ConfigItem) FancyMessage(de.Keyle.MyPet.api.util.chat.FancyMessage) ItemTooltip(de.Keyle.MyPet.api.util.chat.parts.ItemTooltip) ItemStack(org.bukkit.inventory.ItemStack)

Example 10 with BehaviorImpl

use of de.Keyle.MyPet.skill.skills.BehaviorImpl in project MyPet by xXKeyleXx.

the class EntityMyEnderman method doMyPetTick.

@Override
protected void doMyPetTick() {
    super.doMyPetTick();
    BehaviorImpl skill = getMyPet().getSkills().get(BehaviorImpl.class);
    Behavior.BehaviorMode behavior = skill.getBehavior();
    if (behavior == Behavior.BehaviorMode.Aggressive) {
        if (!getMyPet().isScreaming()) {
            getMyPet().setScreaming(true);
        }
    } else {
        if (getMyPet().isScreaming()) {
            getMyPet().setScreaming(false);
        }
    }
}
Also used : BehaviorImpl(de.Keyle.MyPet.skill.skills.BehaviorImpl) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior)

Aggregations

BehaviorImpl (de.Keyle.MyPet.skill.skills.BehaviorImpl)24 Behavior (de.Keyle.MyPet.api.skill.skills.Behavior)23 MyPet (de.Keyle.MyPet.api.entity.MyPet)8 MyPetApi (de.Keyle.MyPet.MyPetApi)1 Configuration (de.Keyle.MyPet.api.Configuration)1 Util (de.Keyle.MyPet.api.Util)1 WorldGroup (de.Keyle.MyPet.api.WorldGroup)1 CommandTabCompleter (de.Keyle.MyPet.api.commands.CommandTabCompleter)1 PetState (de.Keyle.MyPet.api.entity.MyPet.PetState)1 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)1 DonateCheck (de.Keyle.MyPet.api.player.DonateCheck)1 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)1 Permissions (de.Keyle.MyPet.api.player.Permissions)1 Colorizer (de.Keyle.MyPet.api.util.Colorizer)1 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)1 FancyMessage (de.Keyle.MyPet.api.util.chat.FancyMessage)1 ItemTooltip (de.Keyle.MyPet.api.util.chat.parts.ItemTooltip)1 Translation (de.Keyle.MyPet.api.util.locale.Translation)1 EntityMyPet (de.Keyle.MyPet.compat.v1_12_R1.entity.EntityMyPet)1 EntityMyPet (de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet)1