Search in sources :

Example 31 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class PvPArenaHook method onJoinPvPArena.

@EventHandler
public void onJoinPvPArena(PAJoinEvent event) {
    if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
        MyPetPlayer player = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
        if (player.hasMyPet() && player.getMyPet().getStatus() == MyPet.PetState.Here) {
            player.getMyPet().removePet();
            player.getPlayer().sendMessage(Translation.getString("Message.No.AllowedHere", player.getPlayer()));
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 32 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class SkillApiHook method on.

@EventHandler
public void on(PlayerExperienceGainEvent event) {
    if (Configuration.Hooks.SkillAPI.GRANT_EXP) {
        Player player = event.getPlayerData().getPlayer();
        if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
            MyPetPlayer petPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(player);
            if (petPlayer.hasMyPet()) {
                MyPet myPet = petPlayer.getMyPet();
                if (Configuration.Skilltree.PREVENT_LEVELLING_WITHOUT_SKILLTREE && myPet.getSkilltree() == null) {
                    if (!myPet.autoAssignSkilltree()) {
                        return;
                    }
                }
                myPet.getExperience().addExp(event.getExp() * Configuration.Hooks.SkillAPI.EXP_PERCENT / 100);
            }
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) MyPet(de.Keyle.MyPet.api.entity.MyPet) EventHandler(org.bukkit.event.EventHandler)

Example 33 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class SurvivalGamesHook method onJoinPvPArena.

@EventHandler
public void onJoinPvPArena(PlayerJoinArenaEvent event) {
    if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getPlayer())) {
        MyPetPlayer player = MyPetApi.getPlayerManager().getMyPetPlayer(event.getPlayer());
        if (player.hasMyPet() && player.getMyPet().getStatus() == MyPet.PetState.Here) {
            player.getMyPet().removePet();
            player.getPlayer().sendMessage(Translation.getString("Message.No.AllowedHere", player.getPlayer()));
        }
    }
}
Also used : MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 34 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class CommandChooseSkilltree method onCommand.

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage("You can't use this command from server console!");
        return true;
    }
    Player player = (Player) sender;
    if (MyPetApi.getMyPetManager().hasActiveMyPet(player)) {
        final MyPet myPet = MyPetApi.getMyPetManager().getMyPet(player);
        final MyPetPlayer myPetOwner = myPet.getOwner();
        if (Configuration.Skilltree.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) {
            myPet.autoAssignSkilltree();
            sender.sendMessage(Translation.getString("Message.Command.ChooseSkilltree.AutomaticSkilltreeAssignment", myPet.getOwner().getLanguage()));
        } else if (myPet.getSkilltree() != null && Configuration.Skilltree.CHOOSE_SKILLTREE_ONLY_ONCE && !myPet.getOwner().isMyPetAdmin()) {
            sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.OnlyOnce", myPet.getOwner().getLanguage()), myPet.getPetName()));
        } else if (SkillTreeMobType.hasMobType(myPet.getPetType())) {
            SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(myPet.getPetType());
            if (args.length >= 1) {
                String skilltreeName = "";
                for (String arg : args) {
                    skilltreeName += arg + " ";
                }
                skilltreeName = skilltreeName.substring(0, skilltreeName.length() - 1);
                if (skillTreeMobType.hasSkillTree(skilltreeName)) {
                    SkillTree skillTree = skillTreeMobType.getSkillTree(skilltreeName);
                    if (Permissions.hasLegacy(player, "MyPet.skilltree.", skillTree.getPermission())) {
                        int requiredLevel = skillTree.getRequiredLevel();
                        if (requiredLevel > 1 && myPet.getExperience().getLevel() < requiredLevel) {
                            myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Message", player), myPet.getPetName(), requiredLevel));
                        } else if (myPet.setSkilltree(skillTree)) {
                            sender.sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", player), skillTree.getName()));
                            if (!myPet.getOwner().isMyPetAdmin() || Configuration.Skilltree.SWITCH_FEE_ADMIN) {
                                double switchPenalty = Configuration.Skilltree.SWITCH_FEE_FIXED;
                                switchPenalty += myPet.getExperience().getExp() * Configuration.Skilltree.SWITCH_FEE_PERCENT / 100.;
                                if (requiredLevel > 1) {
                                    double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
                                    switchPenalty = myPet.getExp() - switchPenalty < minExp ? myPet.getExp() - minExp : switchPenalty;
                                }
                                myPet.getExperience().removeExp(switchPenalty);
                            }
                        } else {
                            sender.sendMessage(Translation.getString("Message.Skilltree.NotSwitched", player));
                        }
                    } else {
                        sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", player), skilltreeName));
                    }
                } else {
                    sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skilltree.CantFindSkilltree", player), skilltreeName));
                }
            } else {
                List<SkillTree> availableSkilltrees = new ArrayList<>();
                for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) {
                    if (Permissions.hasLegacy(player, "MyPet.skilltree.", skillTree.getPermission())) {
                        availableSkilltrees.add(skillTree);
                    }
                }
                if (availableSkilltrees.size() == 0) {
                    sender.sendMessage(Util.formatText(Translation.getString("Message.Command.ChooseSkilltree.NoneAvailable", player), myPet.getPetName()));
                    return true;
                }
                final Map<Integer, SkillTree> skilltreeSlotMap = new HashMap<>();
                IconMenu menu = new IconMenu(Util.cutString(Util.formatText(Translation.getString("Message.Skilltree.Available", myPetOwner), myPet.getPetName()), 32), new IconMenu.OptionClickEventHandler() {

                    @Override
                    public void onOptionClick(IconMenu.OptionClickEvent event) {
                        if (myPet != myPetOwner.getMyPet()) {
                            event.setWillClose(true);
                            event.setWillDestroy(true);
                            return;
                        }
                        if (skilltreeSlotMap.containsKey(event.getPosition())) {
                            SkillTree selecedSkilltree = skilltreeSlotMap.get(event.getPosition());
                            if (selecedSkilltree != null) {
                                int requiredLevel = selecedSkilltree.getRequiredLevel();
                                if (requiredLevel > 1 && myPet.getExperience().getLevel() < requiredLevel) {
                                    myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Message", myPetOwner), myPet.getPetName(), requiredLevel));
                                } else if (myPet.setSkilltree(selecedSkilltree)) {
                                    myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skilltree.SwitchedTo", myPetOwner), selecedSkilltree.getName()));
                                    if (!myPet.getOwner().isMyPetAdmin() || Configuration.Skilltree.SWITCH_FEE_ADMIN) {
                                        double switchPenalty = Configuration.Skilltree.SWITCH_FEE_FIXED;
                                        switchPenalty += myPet.getExperience().getExp() * Configuration.Skilltree.SWITCH_FEE_PERCENT / 100.;
                                        if (requiredLevel > 1) {
                                            double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
                                            switchPenalty = myPet.getExp() - switchPenalty < minExp ? myPet.getExp() - minExp : switchPenalty;
                                        }
                                        myPet.getExperience().removeExp(switchPenalty);
                                    }
                                } else {
                                    myPet.getOwner().sendMessage(Translation.getString("Message.Skilltree.NotSwitched", myPetOwner));
                                }
                            }
                        }
                        event.setWillClose(true);
                        event.setWillDestroy(true);
                    }
                }, MyPetApi.getPlugin());
                for (int i = 0; i < availableSkilltrees.size(); i++) {
                    SkillTree addedSkilltree = availableSkilltrees.get(i);
                    TagCompound tag = addedSkilltree.getIconItem();
                    IconMenuItem option = IconMenuItem.fromTagCompund(tag);
                    option.setTitle(ChatColor.RESET + "❱❱❱  " + ChatColor.DARK_GREEN + Colorizer.setColors(addedSkilltree.getDisplayName()) + ChatColor.RESET + "  ❰❰❰");
                    boolean selectable = false;
                    int requiredLevel = addedSkilltree.getRequiredLevel();
                    if (requiredLevel > 1) {
                        selectable = myPet.getExperience().getLevel() >= addedSkilltree.getRequiredLevel();
                    }
                    List<String> description = new ArrayList<>();
                    if (requiredLevel > 1) {
                        String reqLevelMessage = ChatColor.RESET + "▶▶▶  ";
                        if (selectable) {
                            reqLevelMessage += ChatColor.GREEN;
                        } else {
                            reqLevelMessage += ChatColor.DARK_RED;
                        }
                        reqLevelMessage += Util.formatText(Translation.getString("Message.Skilltree.RequiresLevel.Item", myPetOwner), requiredLevel) + ChatColor.RESET + "  ◀◀◀";
                        description.add(reqLevelMessage);
                    }
                    for (String line : addedSkilltree.getDescription()) {
                        description.add(Colorizer.setColors(line));
                    }
                    option.addLore(description);
                    menu.setOption(i, option);
                    skilltreeSlotMap.put(i, addedSkilltree);
                }
                menu.open(player);
            }
        }
    } else {
        sender.sendMessage(Translation.getString("Message.No.HasPet", player));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) IconMenu(de.Keyle.MyPet.api.gui.IconMenu) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) HashMap(java.util.HashMap) MyPet(de.Keyle.MyPet.api.entity.MyPet) ArrayList(java.util.ArrayList) TagCompound(de.keyle.knbt.TagCompound) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType) IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem)

Example 35 with MyPetPlayer

use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.

the class CommandInfo method onCommand.

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        MyPetPlayer petOwner;
        if (args.length == 0) {
            if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
                petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(player);
            } else {
                sender.sendMessage(Translation.getString("Message.No.HasPet", player));
                return true;
            }
        } else if (Permissions.hasLegacy(player, "MyPet.command.info.other")) {
            Player p = Bukkit.getServer().getPlayer(args[0]);
            if (p == null || !p.isOnline()) {
                sender.sendMessage(Translation.getString("Message.No.PlayerOnline", player));
                return true;
            }
            if (MyPetApi.getPlayerManager().isMyPetPlayer(args[0])) {
                petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(args[0]);
            } else {
                sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", player), args[0]));
                return true;
            }
        } else {
            sender.sendMessage(Translation.getString("Message.No.Allowed", player));
            return true;
        }
        if (petOwner.hasMyPet()) {
            boolean infoShown = false;
            MyPet myPet = petOwner.getMyPet();
            if (canSee(PetInfoDisplay.Name.adminOnly, player, myPet)) {
                player.sendMessage(ChatColor.AQUA + myPet.getPetName() + ChatColor.RESET + ":");
                infoShown = true;
            }
            if (!petOwner.equals(player) && canSee(!PetInfoDisplay.Owner.adminOnly, player, myPet)) {
                player.sendMessage("   " + Translation.getString("Name.Owner", player) + ": " + myPet.getOwner().getName());
                infoShown = true;
            }
            if (canSee(PetInfoDisplay.HP.adminOnly, player, myPet)) {
                String msg;
                if (myPet.getStatus() == PetState.Dead) {
                    msg = ChatColor.RED + Translation.getString("Name.Dead", player);
                } 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());
                }
                player.sendMessage("   " + Translation.getString("Name.HP", player) + ": " + msg);
                infoShown = true;
            }
            if (canSee(PetInfoDisplay.RespawnTime.adminOnly, player, myPet)) {
                if (myPet.getStatus() == PetState.Dead) {
                    player.sendMessage("   " + Translation.getString("Name.Respawntime", player) + ": " + myPet.getRespawnTime());
                    infoShown = true;
                }
            }
            if (!myPet.isPassiv() && canSee(PetInfoDisplay.Damage.adminOnly, player, myPet)) {
                double damage = (myPet.getSkills().isSkillActive(Damage.class) ? myPet.getSkills().getSkill(Damage.class).get().getDamage() : 0);
                player.sendMessage("   " + Translation.getString("Name.Damage", player) + ": " + String.format("%1.2f", damage));
                infoShown = true;
            }
            if (myPet.getRangedDamage() > 0 && CommandInfo.canSee(PetInfoDisplay.RangedDamage.adminOnly, player, myPet)) {
                double damage = myPet.getRangedDamage();
                player.sendMessage("   " + Translation.getString("Name.RangedDamage", player) + ": " + String.format("%1.2f", damage));
                infoShown = true;
            }
            if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && canSee(PetInfoDisplay.Hunger.adminOnly, player, myPet)) {
                player.sendMessage("   " + Translation.getString("Name.Hunger", player) + ": " + Math.round(myPet.getSaturation()));
                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) + ".name");
                        } 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[is.getItemMeta().getLore().size()]));
                        }
                    }
                    m.itemTooltip(it);
                    comma = true;
                }
                MyPetApi.getPlatformHelper().sendMessageRaw(player, m.toJSONString());
                infoShown = true;
            }
            if (canSee(PetInfoDisplay.Behavior.adminOnly, player, myPet)) {
                if (myPet.getSkills().hasSkill(Behavior.class)) {
                    Behavior behavior = myPet.getSkills().getSkill(Behavior.class).get();
                    player.sendMessage("   " + Translation.getString("Name.Skill.Behavior", player) + ": " + Translation.getString("Name." + behavior.getBehavior().name(), player));
                    infoShown = true;
                }
            }
            if (canSee(PetInfoDisplay.Skilltree.adminOnly, player, myPet) && myPet.getSkilltree() != null) {
                player.sendMessage("   " + Translation.getString("Name.Skilltree", player) + ": " + myPet.getSkilltree().getName());
                infoShown = true;
            }
            if (canSee(PetInfoDisplay.Level.adminOnly, player, myPet)) {
                int lvl = myPet.getExperience().getLevel();
                player.sendMessage("   " + Translation.getString("Name.Level", player) + ": " + lvl);
                infoShown = true;
            }
            int maxLevel = myPet.getSkilltree() != null ? myPet.getSkilltree().getMaxLevel() : Configuration.LevelSystem.Experience.LEVEL_CAP;
            if (canSee(PetInfoDisplay.Exp.adminOnly, player, myPet) && myPet.getExperience().getLevel() < maxLevel) {
                double exp = myPet.getExperience().getCurrentExp();
                double reqEXP = myPet.getExperience().getRequiredExp();
                player.sendMessage("   " + Translation.getString("Name.Exp", player) + ": " + 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(), player) + " ";
                donationMessage += myPet.getOwner().getDonationRank().getDefaultIcon();
                sender.sendMessage("   " + donationMessage);
            }
            if (!infoShown) {
                sender.sendMessage(Translation.getString("Message.CantViewPetInfo", player));
            }
            return true;
        } else {
            if (args.length > 0) {
                sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", player), args[0]));
            } 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) ConfigItem(de.Keyle.MyPet.api.util.ConfigItem) FancyMessage(de.keyle.fanciful.FancyMessage) ItemTooltip(de.keyle.fanciful.ItemTooltip) Behavior(de.Keyle.MyPet.skill.skills.Behavior) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)46 EventHandler (org.bukkit.event.EventHandler)19 MyPet (de.Keyle.MyPet.api.entity.MyPet)17 Player (org.bukkit.entity.Player)16 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)14 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)8 WorldGroup (de.Keyle.MyPet.api.WorldGroup)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 TagCompound (de.keyle.knbt.TagCompound)5 List (java.util.List)5 UUID (java.util.UUID)4 Optional (com.google.common.base.Optional)3 RepositoryCallback (de.Keyle.MyPet.api.repository.RepositoryCallback)3 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)3 SqLiteRepository (de.Keyle.MyPet.repository.types.SqLiteRepository)3 MyPetPlayerImpl (de.Keyle.MyPet.util.player.MyPetPlayerImpl)3 FancyMessage (de.keyle.fanciful.FancyMessage)3 IOException (java.io.IOException)3 MyPetSaveEvent (de.Keyle.MyPet.api.event.MyPetSaveEvent)2 ConfigItem (de.Keyle.MyPet.api.util.ConfigItem)2