Search in sources :

Example 6 with FancyMessage

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

the class CommandTrade method onCommand.

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (WorldGroup.getGroupByWorld(player.getWorld()).isDisabled()) {
            player.sendMessage(Translation.getString("Message.No.AllowedHere", player));
            return true;
        }
        if (args.length == 0) {
            return false;
        }
        if (args[0].equalsIgnoreCase("accept")) {
            if (offers.containsKey(player.getUniqueId())) {
                Offer offer = offers.get(player.getUniqueId());
                Player owner = Bukkit.getServer().getPlayer(offer.getOwner());
                if (owner == null || !owner.isOnline()) {
                    sender.sendMessage(Translation.getString("Message.Command.Trade.Receiver.PetUnavailable", player));
                    offers.remove(player.getUniqueId());
                    return true;
                }
                if (!Permissions.has(player, "MyPet.command.trade.receive." + offer.getPet().getPetType().name())) {
                    sender.sendMessage(Translation.getString("Message.Command.Trade.Receiver.NoPermission", player));
                    owner.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Owner.Reject", owner), player.getName(), offer.getPet().getPetName()));
                    offers.remove(player.getUniqueId());
                    return true;
                }
                if (MyPetApi.getPlayerManager().isMyPetPlayer(owner)) {
                    final MyPetPlayer oldOwner = MyPetApi.getPlayerManager().getMyPetPlayer(owner);
                    if (!oldOwner.hasMyPet() || oldOwner.getMyPet() != offer.getPet()) {
                        sender.sendMessage(Translation.getString("Message.Command.Trade.Receiver.PetUnavailable", player));
                        offers.remove(player.getUniqueId());
                        return true;
                    }
                    if (MyPetApi.getPlayerManager().isMyPetPlayer(player) && MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
                        sender.sendMessage(Translation.getString("Message.Command.Trade.Receiver.HasPet", player));
                        return true;
                    }
                    if (!player.getWorld().equals(owner.getWorld()) || MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), owner.getLocation()) > 100) {
                        sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Receiver.Distance", player), owner.getName()));
                        return true;
                    }
                    if (offer.getPrice() > 0) {
                        if (!MyPetApi.getHookHelper().isEconomyEnabled()) {
                            player.sendMessage(Translation.getString("Message.No.Economy", player));
                            return true;
                        }
                        if (!MyPetApi.getHookHelper().getEconomy().transfer(player, owner, offer.getPrice())) {
                            sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Receiver.NotEnoughMoney", player), MyPetApi.getHookHelper().getEconomy().format(offer.getPrice())));
                            return true;
                        }
                    }
                    offers.remove(player.getUniqueId());
                    final MyPetPlayer newOwner = MyPetApi.getPlayerManager().isMyPetPlayer(player) ? MyPetApi.getPlayerManager().getMyPetPlayer(player) : MyPetApi.getPlayerManager().registerMyPetPlayer(player);
                    final String worldGroup = offer.getPet().getWorldGroup();
                    MyPetApi.getMyPetManager().deactivateMyPet(oldOwner, false);
                    final StoredMyPet pet = MyPetApi.getMyPetManager().getInactiveMyPetFromMyPet(offer.getPet());
                    final Repository repo = MyPetApi.getRepository();
                    repo.removeMyPet(pet, new RepositoryCallback<Boolean>() {

                        @Override
                        public void callback(Boolean value) {
                            pet.setOwner(newOwner);
                            MyPetSaveEvent event = new MyPetSaveEvent(pet);
                            Bukkit.getServer().getPluginManager().callEvent(event);
                            repo.addMyPet(pet, null);
                            Optional<MyPet> myPet = MyPetApi.getMyPetManager().activateMyPet(pet);
                            oldOwner.setMyPetForWorldGroup(worldGroup, null);
                            newOwner.setMyPetForWorldGroup(worldGroup, pet.getUUID());
                            repo.updateMyPetPlayer(oldOwner, null);
                            repo.updateMyPetPlayer(newOwner, null);
                            if (myPet.isPresent()) {
                                newOwner.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Receiver.Success", newOwner), oldOwner.getName(), myPet.get().getPetName()));
                                oldOwner.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Owner.Success", oldOwner), newOwner.getName(), myPet.get().getPetName()));
                                switch(myPet.get().createEntity()) {
                                    case Canceled:
                                        newOwner.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", newOwner), myPet.get().getPetName()));
                                        break;
                                    case NoSpace:
                                        newOwner.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", newOwner), myPet.get().getPetName()));
                                        break;
                                    case NotAllowed:
                                        newOwner.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", newOwner), myPet.get().getPetName()));
                                        break;
                                    case Dead:
                                        if (!Configuration.Respawn.DISABLE_AUTO_RESPAWN) {
                                            newOwner.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", newOwner), myPet.get().getPetName(), myPet.get().getRespawnTime()));
                                        }
                                        break;
                                    case Spectator:
                                        newOwner.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Spectator", newOwner), myPet.get().getPetName()));
                                        break;
                                }
                            } else {
                                newOwner.sendMessage(Translation.getString("Message.Command.Trade.Receiver.Error", newOwner));
                            }
                        }
                    });
                } else {
                    sender.sendMessage(Translation.getString("Message.Command.Trade.Receiver.PetUnavailable", player));
                    offers.remove(player.getUniqueId());
                    return true;
                }
            } else {
                sender.sendMessage(Translation.getString("Message.Command.Trade.Receiver.NoOffer", player));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("reject")) {
            if (offers.containsKey(player.getUniqueId())) {
                Offer offer = offers.get(player.getUniqueId());
                Player owner = Bukkit.getServer().getPlayer(offer.getOwner());
                if (owner != null && owner.isOnline()) {
                    owner.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Owner.Reject", owner), player.getName(), offer.getPet().getPetName()));
                }
                sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Receiver.Reject", player), offer.getOwnerName()));
                offers.remove(player.getUniqueId());
            } else {
                sender.sendMessage(Translation.getString("Message.Command.Trade.Receiver.NoOffer", player));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("cancel")) {
            UUID ownerUUID = player.getUniqueId();
            for (Offer offer : offers.values()) {
                if (offer.getOwner().equals(ownerUUID)) {
                    offers.remove(offer.getReceiver());
                    sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Owner.Cancel", player), offer.getReceiverName()));
                    Player receiver = Bukkit.getPlayer(offer.getReceiver());
                    if (receiver != null && receiver.isOnline()) {
                        receiver.sendMessage(Translation.getString("Message.Command.Trade.Receiver.PetUnavailable", player));
                    }
                    return true;
                }
            }
            sender.sendMessage(Translation.getString("Message.Command.Trade.Owner.NoOffer", player));
            return true;
        } else {
            if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
                MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
                if (!Permissions.has((Player) sender, "MyPet.command.trade.offer." + myPet.getPetType().name())) {
                    player.sendMessage(Translation.getString("Message.No.Allowed", player));
                    return true;
                }
                Player receiver = Bukkit.getPlayer(args[0]);
                if (receiver == null) {
                    sender.sendMessage(Translation.getString("Message.No.PlayerOnline", player));
                    return true;
                }
                if (offers.containsKey(receiver.getUniqueId())) {
                    sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Owner.OpenOffer", player), receiver.getName()));
                    return true;
                }
                if (receiver.equals(player)) {
                    sender.sendMessage(Translation.getString("Message.Command.Trade.Owner.Yourself", player));
                    return true;
                }
                double price = 0;
                if (args.length >= 2) {
                    if (MyPetApi.getHookHelper().isEconomyEnabled()) {
                        if (Util.isDouble(args[1])) {
                            price = Double.parseDouble(args[1]);
                        } else {
                            receiver.sendMessage(Translation.getString("Message.Command.Trade.Owner.InvalidPrice", player));
                            return true;
                        }
                    } else {
                        sender.sendMessage(Translation.getString("Message.No.Economy", player));
                        return true;
                    }
                }
                Offer offer = new Offer(price, myPet, player.getUniqueId(), receiver.getUniqueId(), receiver.getName(), player.getName());
                offers.put(receiver.getUniqueId(), offer);
                if (price > 0) {
                    sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Owner.Offer.Price", player), myPet.getPetName(), receiver.getName(), MyPetApi.getHookHelper().getEconomy().format(price)));
                    receiver.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Receiver.Offer.Price", receiver), player.getName(), MyPetApi.getHookHelper().getEconomy().format(price)));
                } else {
                    sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Owner.Offer", player), myPet.getPetName(), receiver.getName()));
                    receiver.sendMessage(Util.formatText(Translation.getString("Message.Command.Trade.Receiver.Offer", receiver), player.getName()));
                }
                FancyMessage petMessage = new FancyMessage(" »» ").then(myPet.getPetName()).itemTooltip(Util.myPetToItemTooltip(myPet, MyPetApi.getPlatformHelper().getPlayerLanguage(receiver))).command("/pettrade accept");
                MyPetApi.getPlatformHelper().sendMessageRaw(receiver, petMessage.toJSONString());
                return true;
            } else {
                sender.sendMessage(Translation.getString("Message.No.HasPet", player));
                return true;
            }
        }
    }
    sender.sendMessage("You can't use this command from server console!");
    return true;
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPet(de.Keyle.MyPet.api.entity.MyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) FancyMessage(de.Keyle.MyPet.api.util.chat.FancyMessage) MyPetSaveEvent(de.Keyle.MyPet.api.event.MyPetSaveEvent) Repository(de.Keyle.MyPet.api.repository.Repository) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 7 with FancyMessage

use of de.Keyle.MyPet.api.util.chat.FancyMessage 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 8 with FancyMessage

use of de.Keyle.MyPet.api.util.chat.FancyMessage 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)

Aggregations

FancyMessage (de.Keyle.MyPet.api.util.chat.FancyMessage)8 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)6 Player (org.bukkit.entity.Player)5 MyPet (de.Keyle.MyPet.api.entity.MyPet)4 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)4 ItemTooltip (de.Keyle.MyPet.api.util.chat.parts.ItemTooltip)3 List (java.util.List)3 WorldGroup (de.Keyle.MyPet.api.WorldGroup)2 CraftMyPetProjectile (de.Keyle.MyPet.api.entity.skill.ranged.CraftMyPetProjectile)2 EntityMyPetProjectile (de.Keyle.MyPet.api.entity.skill.ranged.EntityMyPetProjectile)2 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)2 ItemStack (org.bukkit.inventory.ItemStack)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 MyPetApi (de.Keyle.MyPet.MyPetApi)1 Configuration (de.Keyle.MyPet.api.Configuration)1 Util (de.Keyle.MyPet.api.Util)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