Search in sources :

Example 1 with ItemTooltip

use of de.Keyle.MyPet.api.util.chat.parts.ItemTooltip in project MyPet by xXKeyleXx.

the class MyPetEntityListener method onMyPet.

@EventHandler
public void onMyPet(final EntityDamageByEntityEvent event) {
    // noinspection ConstantConditions
    if (event.getEntity() == null) {
        // catch invalid events (i.e. EnchantmentAPI)
        return;
    }
    if (WorldGroup.getGroupByWorld(event.getEntity().getWorld()).isDisabled()) {
        return;
    }
    if (event.getEntity() instanceof MyPetBukkitEntity) {
        MyPetBukkitEntity craftMyPet = (MyPetBukkitEntity) event.getEntity();
        MyPet myPet = craftMyPet.getMyPet();
        if (event.getDamager() instanceof Player || (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player)) {
            Player damager;
            if (event.getDamager() instanceof Projectile) {
                damager = (Player) ((Projectile) event.getDamager()).getShooter();
            } else {
                damager = (Player) event.getDamager();
            }
            ItemStack leashItem;
            if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
                leashItem = damager.getEquipment().getItemInMainHand();
            } else {
                leashItem = damager.getItemInHand();
            }
            if (MyPetApi.getMyPetInfo().getLeashItem(myPet.getPetType()).compare(leashItem)) {
                boolean infoShown = false;
                if (CommandInfo.canSee(PetInfoDisplay.Name.adminOnly, damager, myPet)) {
                    damager.sendMessage(ChatColor.AQUA + myPet.getPetName() + ChatColor.RESET + ":");
                    infoShown = true;
                }
                if (CommandInfo.canSee(PetInfoDisplay.Owner.adminOnly, damager, myPet) && myPet.getOwner().getPlayer() != damager) {
                    damager.sendMessage("   " + Translation.getString("Name.Owner", damager) + ": " + myPet.getOwner().getName());
                    infoShown = true;
                }
                if (CommandInfo.canSee(PetInfoDisplay.HP.adminOnly, damager, myPet)) {
                    String msg;
                    double health = myPet.getHealth();
                    double maxHealth = myPet.getMaxHealth();
                    if (health > maxHealth / 3 * 2) {
                        msg = "" + ChatColor.GREEN;
                    } else if (health > maxHealth / 3) {
                        msg = "" + ChatColor.YELLOW;
                    } else {
                        msg = "" + ChatColor.RED;
                    }
                    msg += String.format("%1.2f", health) + ChatColor.WHITE + "/" + String.format("%1.2f", maxHealth);
                    damager.sendMessage("   " + Translation.getString("Name.HP", damager) + ": " + msg);
                    infoShown = true;
                }
                if (myPet.getStatus() == PetState.Dead && CommandInfo.canSee(PetInfoDisplay.RespawnTime.adminOnly, damager, myPet)) {
                    damager.sendMessage("   " + Translation.getString("Name.Respawntime", damager) + ": " + myPet.getRespawnTime());
                    infoShown = true;
                }
                if (myPet.getDamage() > 0 && CommandInfo.canSee(PetInfoDisplay.Damage.adminOnly, damager, myPet)) {
                    damager.sendMessage("   " + Translation.getString("Name.Damage", damager) + ": " + String.format("%1.2f", myPet.getDamage()));
                    infoShown = true;
                }
                if (myPet.getRangedDamage() > 0 && CommandInfo.canSee(PetInfoDisplay.RangedDamage.adminOnly, damager, myPet)) {
                    damager.sendMessage("   " + Translation.getString("Name.RangedDamage", damager) + ": " + String.format("%1.2f", myPet.getRangedDamage()));
                    infoShown = true;
                }
                if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && CommandInfo.canSee(PetInfoDisplay.Hunger.adminOnly, damager, myPet)) {
                    damager.sendMessage("   " + Translation.getString("Name.Hunger", damager) + ": " + Math.round(myPet.getSaturation()));
                    FancyMessage m = new FancyMessage("   " + Translation.getString("Name.Food", damager) + ": ");
                    boolean comma = false;
                    for (ConfigItem material : MyPetApi.getMyPetInfo().getFood(myPet.getPetType())) {
                        ItemStack is = material.getItem();
                        if (is == null) {
                            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 for \"" + myPet.getPetType().name() + "\" caused an error. If you think this is a bug please report it to the MyPet developer.");
                                MyPetApi.getLogger().warning(is.toString());
                                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(damager, m.toJSONString());
                    infoShown = true;
                }
                if (myPet.getSkills().has(Behavior.class) && CommandInfo.canSee(PetInfoDisplay.Behavior.adminOnly, damager, myPet)) {
                    Behavior behavior = myPet.getSkills().get(Behavior.class);
                    damager.sendMessage("   " + Translation.getString("Name.Skill.Behavior", damager) + ": " + Translation.getString("Name." + behavior.getBehavior().name(), damager));
                    infoShown = true;
                }
                if (CommandInfo.canSee(PetInfoDisplay.Skilltree.adminOnly, damager, myPet) && myPet.getSkilltree() != null) {
                    damager.sendMessage("   " + Translation.getString("Name.Skilltree", damager) + ": " + Colorizer.setColors(myPet.getSkilltree().getDisplayName()));
                    infoShown = true;
                }
                if (CommandInfo.canSee(PetInfoDisplay.Level.adminOnly, damager, myPet)) {
                    int lvl = myPet.getExperience().getLevel();
                    damager.sendMessage("   " + Translation.getString("Name.Level", damager) + ": " + lvl);
                    infoShown = true;
                }
                int maxLevel = myPet.getSkilltree() != null ? myPet.getSkilltree().getMaxLevel() : Configuration.LevelSystem.Experience.LEVEL_CAP;
                if (CommandInfo.canSee(PetInfoDisplay.Exp.adminOnly, damager, myPet) && myPet.getExperience().getLevel() < maxLevel) {
                    double exp = myPet.getExperience().getCurrentExp();
                    double reqEXP = myPet.getExperience().getRequiredExp();
                    damager.sendMessage("   " + Translation.getString("Name.Exp", damager) + ": " + 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(), damager) + " ";
                    donationMessage += myPet.getOwner().getDonationRank().getDefaultIcon();
                    damager.sendMessage("   " + donationMessage);
                }
                if (!infoShown) {
                    damager.sendMessage(Translation.getString("Message.No.NothingToSeeHere", myPet.getOwner()));
                }
                event.setCancelled(true);
            } else if (myPet.getOwner().equals(damager) && (!Configuration.Misc.OWNER_CAN_ATTACK_PET)) {
                event.setCancelled(true);
            } else if (!myPet.getOwner().equals(damager) && !MyPetApi.getHookHelper().canHurt(damager, myPet.getOwner().getPlayer(), true)) {
                event.setCancelled(true);
            }
        }
        if (event.getDamager() instanceof CraftMyPetProjectile) {
            EntityMyPetProjectile projectile = ((CraftMyPetProjectile) event.getDamager()).getMyPetProjectile();
            if (projectile != null && projectile.getShooter() != null) {
                if (myPet == projectile.getShooter().getMyPet()) {
                    event.setCancelled(true);
                }
                if (!MyPetApi.getHookHelper().canHurt(projectile.getShooter().getOwner().getPlayer(), myPet.getOwner().getPlayer(), true)) {
                    event.setCancelled(true);
                }
            }
        }
        if (!event.isCancelled() && event.getDamager() instanceof LivingEntity) {
            LivingEntity damager = (LivingEntity) event.getDamager();
            if (damager instanceof Player) {
                if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), (Player) damager, true)) {
                    return;
                }
            }
            if (!isSkillActive) {
                for (Skill skill : myPet.getSkills().all()) {
                    if (skill instanceof OnDamageByEntitySkill) {
                        OnDamageByEntitySkill damageByEntitySkill = (OnDamageByEntitySkill) skill;
                        if (damageByEntitySkill.trigger()) {
                            isSkillActive = true;
                            damageByEntitySkill.apply(damager, event);
                            isSkillActive = false;
                        }
                    }
                }
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) EntityMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile) ConfigItem(de.Keyle.MyPet.api.util.ConfigItem) FancyMessage(de.Keyle.MyPet.api.util.chat.FancyMessage) OnDamageByEntitySkill(de.Keyle.MyPet.api.skill.OnDamageByEntitySkill) EntityMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile) CraftMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile) ItemTooltip(de.Keyle.MyPet.api.util.chat.parts.ItemTooltip) OnDamageByEntitySkill(de.Keyle.MyPet.api.skill.OnDamageByEntitySkill) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) OnHitSkill(de.Keyle.MyPet.api.skill.OnHitSkill) CraftMyPetProjectile(de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile) Behavior(de.Keyle.MyPet.api.skill.skills.Behavior) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ItemTooltip

use of de.Keyle.MyPet.api.util.chat.parts.ItemTooltip 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 3 with ItemTooltip

use of de.Keyle.MyPet.api.util.chat.parts.ItemTooltip in project MyPet by xXKeyleXx.

the class CommandRelease method onCommand.

public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player petOwner = (Player) sender;
        if (WorldGroup.getGroupByWorld(petOwner.getWorld()).isDisabled()) {
            petOwner.sendMessage(Translation.getString("Message.No.AllowedHere", petOwner));
            return true;
        }
        if (MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
            MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
            if (!Permissions.has(petOwner, "MyPet.command.release")) {
                return true;
            }
            if (myPet.getStatus() == PetState.Despawned) {
                sender.sendMessage(Util.formatText(Translation.getString("Message.Call.First", petOwner), myPet.getPetName()));
                return true;
            } else if (myPet.getStatus() == PetState.Dead) {
                sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", petOwner), myPet.getPetName(), myPet.getRespawnTime()));
                return true;
            }
            String name = "";
            if (args.length > 0) {
                for (String arg : args) {
                    if (!name.equals("")) {
                        name += " ";
                    }
                    name += arg;
                }
            }
            if (ChatColor.stripColor(myPet.getPetName()).trim().equalsIgnoreCase(name.trim())) {
                MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.Release);
                Bukkit.getServer().getPluginManager().callEvent(removeEvent);
                if (!MyPetApi.getMyPetInfo().getRemoveAfterRelease(myPet.getPetType())) {
                    LivingEntity normalEntity = (LivingEntity) myPet.getLocation().get().getWorld().spawnEntity(myPet.getLocation().get(), EntityType.valueOf(myPet.getPetType().getBukkitName()));
                    Optional<EntityConverterService> converter = MyPetApi.getServiceManager().getService(EntityConverterService.class);
                    try {
                        converter.ifPresent(entityConverterService -> entityConverterService.convertEntity(myPet, normalEntity));
                    } catch (Exception e) {
                        normalEntity.remove();
                        return true;
                    }
                }
                if (myPet.getSkills().isActive(Backpack.class)) {
                    myPet.getSkills().get(Backpack.class).getInventory().dropContentAt(myPet.getLocation().get());
                }
                if (myPet instanceof MyPetEquipment) {
                    ((MyPetEquipment) myPet).dropEquipment();
                }
                myPet.removePet();
                myPet.getOwner().setMyPetForWorldGroup(WorldGroup.getGroupByWorld(petOwner.getWorld().getName()), null);
                sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Release.Success", petOwner), myPet.getPetName()));
                MyPetApi.getMyPetManager().deactivateMyPet(myPet.getOwner(), false);
                MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
                return true;
            } else {
                FancyMessage message = new FancyMessage(Translation.getString("Message.Command.Release.Confirm", petOwner) + " ");
                List<String> lore = new ArrayList<>();
                lore.add(RESET + Translation.getString("Name.Hunger", petOwner) + ": " + GOLD + Math.round(myPet.getSaturation()));
                if (myPet.getRespawnTime() > 0) {
                    lore.add(RESET + Translation.getString("Name.Respawntime", petOwner) + ": " + GOLD + myPet.getRespawnTime() + "sec");
                } else {
                    lore.add(RESET + Translation.getString("Name.HP", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getHealth()));
                }
                lore.add(RESET + Translation.getString("Name.Exp", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getExp()));
                lore.add(RESET + Translation.getString("Name.Type", petOwner) + ": " + GOLD + Translation.getString("Name." + myPet.getPetType().name(), petOwner));
                lore.add(RESET + Translation.getString("Name.Skilltree", petOwner) + ": " + GOLD + (myPet.getSkilltree() != null ? Colorizer.setColors(myPet.getSkilltree().getDisplayName()) : "-"));
                message.then(myPet.getPetName()).color(ChatColor.AQUA).command("/petrelease " + ChatColor.stripColor(myPet.getPetName())).itemTooltip(new ItemTooltip().addLore(lore).setTitle(myPet.getPetName()));
                MyPetApi.getPlatformHelper().sendMessageRaw((Player) sender, message.toJSONString());
                return true;
            }
        } else {
            sender.sendMessage(Translation.getString("Message.No.HasPet", petOwner));
        }
        return true;
    }
    sender.sendMessage("You can't use this command from server console!");
    return false;
}
Also used : EntityConverterService(de.Keyle.MyPet.api.util.service.types.EntityConverterService) Player(org.bukkit.entity.Player) MyPet(de.Keyle.MyPet.api.entity.MyPet) ArrayList(java.util.ArrayList) FancyMessage(de.Keyle.MyPet.api.util.chat.FancyMessage) LivingEntity(org.bukkit.entity.LivingEntity) MyPetRemoveEvent(de.Keyle.MyPet.api.event.MyPetRemoveEvent) ItemTooltip(de.Keyle.MyPet.api.util.chat.parts.ItemTooltip) MyPetEquipment(de.Keyle.MyPet.api.entity.MyPetEquipment)

Example 4 with ItemTooltip

use of de.Keyle.MyPet.api.util.chat.parts.ItemTooltip in project MyPet by xXKeyleXx.

the class Util method myPetToItemTooltip.

public static ItemTooltip myPetToItemTooltip(StoredMyPet mypet, String lang) {
    List<String> lore = new ArrayList<>();
    lore.add(RESET + Translation.getString("Name.Hunger", lang) + ": " + GOLD + Math.round(mypet.getSaturation()));
    if (!Configuration.Respawn.DISABLE_AUTO_RESPAWN) {
        if (mypet.getRespawnTime() > 0) {
            lore.add(RESET + Translation.getString("Name.Respawntime", lang) + ": " + GOLD + mypet.getRespawnTime() + "sec");
        } else {
            lore.add(RESET + Translation.getString("Name.HP", lang) + ": " + GOLD + String.format("%1.2f", mypet.getHealth()));
        }
    } else if (mypet.getRespawnTime() <= 0) {
        lore.add(RESET + Translation.getString("Name.HP", lang) + ": " + GOLD + String.format("%1.2f", mypet.getHealth()));
    }
    lore.add(RESET + Translation.getString("Name.Exp", lang) + ": " + GOLD + String.format("%1.2f", mypet.getExp()));
    if (mypet.getInfo().containsKey("storage")) {
        TagCompound storage = mypet.getInfo().getAs("storage", TagCompound.class);
        if (storage.containsKey("level")) {
            lore.add(RESET + Translation.getString("Name.Level", lang) + ": " + GOLD + storage.getAs("level", TagInt.class).getIntData());
        }
    }
    lore.add(RESET + Translation.getString("Name.Type", lang) + ": " + GOLD + mypet.getPetType().name());
    lore.add(RESET + Translation.getString("Name.Skilltree", lang) + ": " + GOLD + (mypet.getSkilltree() != null ? Colorizer.setColors(mypet.getSkilltree().getDisplayName()) : "-"));
    if (Configuration.Respawn.DISABLE_AUTO_RESPAWN) {
        if (mypet.getRespawnTime() > 0) {
            lore.add(ChatColor.RED + Translation.getString("Name.Dead", lang));
        }
    }
    return new ItemTooltip().addLore(lore).setTitle(mypet.getPetName());
}
Also used : ItemTooltip(de.Keyle.MyPet.api.util.chat.parts.ItemTooltip) TagInt(de.keyle.knbt.TagInt) TagCompound(de.keyle.knbt.TagCompound)

Aggregations

ItemTooltip (de.Keyle.MyPet.api.util.chat.parts.ItemTooltip)4 FancyMessage (de.Keyle.MyPet.api.util.chat.FancyMessage)3 MyPet (de.Keyle.MyPet.api.entity.MyPet)2 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)2 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 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 MyPetEquipment (de.Keyle.MyPet.api.entity.MyPetEquipment)1 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)1 CraftMyPetProjectile (de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile)1 EntityMyPetProjectile (de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile)1 MyPetRemoveEvent (de.Keyle.MyPet.api.event.MyPetRemoveEvent)1 DonateCheck (de.Keyle.MyPet.api.player.DonateCheck)1 Permissions (de.Keyle.MyPet.api.player.Permissions)1