@Override public List<String> onTabComplete( CommandSender commandSender, Command command, String s, String[] strings) { Player player = (Player) commandSender; if (MyPetList.hasActiveMyPet(player)) { MyPet myPet = MyPetList.getMyPet(player); if (Configuration.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) { return CommandAdmin.EMPTY_LIST; } else if (myPet.getSkillTree() != null && Configuration.CHOOSE_SKILLTREE_ONLY_ONCE && !myPet.getOwner().isMyPetAdmin()) { return CommandAdmin.EMPTY_LIST; } else if (SkillTreeMobType.hasMobType(myPet.getPetType().getTypeName())) { SkillTreeMobType skillTreeMobType = SkillTreeMobType.getMobTypeByName(myPet.getPetType().getTypeName()); List<String> skilltreeList = new ArrayList<>(); for (SkillTree skillTree : skillTreeMobType.getSkillTrees()) { if (Permissions.has(player, "MyPet.custom.skilltree." + skillTree.getPermission())) { skilltreeList.add(skillTree.getName()); } } return skilltreeList; } } return CommandAdmin.EMPTY_LIST; }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { return false; } Player player = (Player) sender; if (MyPetList.hasMyPet(player)) { MyPet myPet = MyPetList.getMyPet(player); if (myPet.getSkillTree() != null && MyPetConfig.chooseSkilltreeOnce && !MyPetPermissions.has(myPet.getOwner().getPlayer(), "MyPet.admin")) { sender.sendMessage( MyPetUtil.setColors( MyPetLanguage.getString("Msg_OnlyChooseSkilltreeOnce") .replace("%petname%", myPet.petName))); } else if (MyPetSkillTreeMobType.hasMobType(myPet.getPetType().getTypeName())) { MyPetSkillTreeMobType skillTreeMobType = MyPetSkillTreeMobType.getMobTypeByName(myPet.getPetType().getTypeName()); if (args.length == 1) { if (skillTreeMobType.hasSkillTree(args[0])) { MyPetSkillTree skillTree = skillTreeMobType.getSkillTree(args[0]); if (MyPetPermissions.has( myPet.getOwner().getPlayer(), "MyPet.custom.skilltree." + skillTree.getName())) { if (myPet.setSkilltree(skillTree)) { sender.sendMessage( MyPetUtil.setColors( MyPetLanguage.getString("Msg_SkilltreeSwitchedTo") .replace("%name%", skillTree.getName()))); } else { sender.sendMessage( MyPetUtil.setColors(MyPetLanguage.getString("Msg_SkilltreeNotSwitched"))); } } else { sender.sendMessage( MyPetUtil.setColors( MyPetLanguage.getString("Msg_CantFindSkilltree").replace("%name%", args[0]))); } } else { sender.sendMessage( MyPetUtil.setColors( MyPetLanguage.getString("Msg_CantFindSkilltree").replace("%name%", args[0]))); } } else { sender.sendMessage( MyPetUtil.setColors( MyPetLanguage.getString("Msg_AvailableSkilltrees") .replace("%petname%", myPet.petName))); for (String skillTreeName : skillTreeMobType.getSkillTreeNames()) { if (MyPetPermissions.has(player, "MyPet.custom.skilltree." + skillTreeName)) { sender.sendMessage(" " + skillTreeName); } } } } } else { sender.sendMessage(MyPetUtil.setColors(MyPetLanguage.getString("Msg_DontHavePet"))); } return true; }
public static int countMyPets(MyPetType myPetType) { int counter = 0; for (MyPet myPet : lActivePets) { if (myPet.getPetType() == myPetType) { counter++; } } for (InactiveMyPet inactiveMyPet : lInactivePets) { if (inactiveMyPet.getPetType() == myPetType) { counter++; } } return counter; }
private static InactiveMyPet getInactiveMyPet(MyPet activeMyPet) { InactiveMyPet inactiveMyPet = new InactiveMyPet(activeMyPet.getOwner()); inactiveMyPet.setPetName(activeMyPet.petName); inactiveMyPet.setExp(activeMyPet.getExperience().getExp()); inactiveMyPet.setHealth(activeMyPet.getHealth()); inactiveMyPet.setHungerValue(activeMyPet.getHungerValue()); inactiveMyPet.setLocation(activeMyPet.getLocation()); inactiveMyPet.setRespawnTime(activeMyPet.respawnTime); inactiveMyPet.setSkills(activeMyPet.getSkills().getSkills()); inactiveMyPet.setInfo(activeMyPet.getExtendedInfo()); inactiveMyPet.setPetType(activeMyPet.getPetType()); inactiveMyPet.setSkillTree(activeMyPet.getSkillTree()); return inactiveMyPet; }
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 (MyPetList.hasActiveMyPet(player)) { final MyPet myPet = MyPetList.getMyPet(player); final MyPetPlayer myPetOwner = myPet.getOwner(); if (Configuration.AUTOMATIC_SKILLTREE_ASSIGNMENT && !myPet.getOwner().isMyPetAdmin()) { myPet.autoAssignSkilltree(); sender.sendMessage( Translation.getString( "Message.Command.ChoseSkilltree.AutomaticSkilltreeAssignment", myPet.getOwner().getLanguage())); } else if (myPet.getSkillTree() != null && Configuration.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().getTypeName())) { SkillTreeMobType skillTreeMobType = SkillTreeMobType.getMobTypeByName(myPet.getPetType().getTypeName()); 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.has(player, "MyPet.custom.skilltree." + skillTree.getPermission())) { int requiredLevel = skillTree.getRequiredLevel(); if (requiredLevel > 1 && myPet.getExperience().getLevel() < requiredLevel) { myPet.sendMessageToOwner( 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_PENALTY_ADMIN) || !myPet.getOwner().isMyPetAdmin()) { double switchPenalty = Configuration.SKILLTREE_SWITCH_PENALTY_FIXED; switchPenalty += myPet.getExperience().getExp() * Configuration.SKILLTREE_SWITCH_PENALTY_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.has(player, "MyPet.custom.skilltree." + skillTree.getPermission())) { availableSkilltrees.add(skillTree); } } if (availableSkilltrees.size() == 0) { sender.sendMessage(Translation.getString("Message.No.CanUse", player)); 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), (int) (Math.ceil(availableSkilltrees.size() / 9.) * 9), 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.sendMessageToOwner( Util.formatText( Translation.getString( "Message.Skilltree.RequiresLevel.Message", myPetOwner), myPet.getPetName(), requiredLevel)); } else if (myPet.setSkilltree(selecedSkilltree)) { myPet.sendMessageToOwner( Util.formatText( Translation.getString( "Message.Skilltree.SwitchedTo", myPetOwner), selecedSkilltree.getName())); if ((myPet.getOwner().isMyPetAdmin() && Configuration.SKILLTREE_SWITCH_PENALTY_ADMIN) || !myPet.getOwner().isMyPetAdmin()) { double switchPenalty = Configuration.SKILLTREE_SWITCH_PENALTY_FIXED; switchPenalty += myPet.getExperience().getExp() * Configuration.SKILLTREE_SWITCH_PENALTY_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.sendMessageToOwner( Translation.getString("Message.Skilltree.NotSwitched", myPetOwner)); } } } event.setWillClose(true); event.setWillDestroy(true); } }, MyPetPlugin.getPlugin()); for (int i = 0; i < availableSkilltrees.size(); i++) { SkillTree addedSkilltree = availableSkilltrees.get(i); TagCompound tag = addedSkilltree.getIconItem(); net.minecraft.server.v1_8_R3.ItemStack is = ItemStackNBTConverter.compundToItemStack(tag); IconMenuItem option = IconMenuItem.fromNmsItemStack(is); option.setTitle( ChatColor.RESET + "❱❱❱ " + ChatColor.DARK_GREEN + 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); } description.addAll(addedSkilltree.getDescription()); 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; }