@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;
  }
Example #2
0
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
      Player owner = (Player) sender;
      if (MyPetList.hasActiveMyPet(owner)) {
        MyPet myPet = MyPetList.getMyPet(owner);

        if (!Permissions.hasExtended(myPet.getOwner().getPlayer(), "MyPet.user.extended.Pickup")) {
          sender.sendMessage(Translation.getString("Message.No.Allowed", owner));
          return true;
        } else if (myPet.getStatus() == PetState.Despawned) {
          sender.sendMessage(
              Util.formatText(
                  Translation.getString("Message.Call.First", owner), myPet.getPetName()));
          return true;
        } else if (myPet.getStatus() == PetState.Dead) {
          sender.sendMessage(
              Util.formatText(
                  Translation.getString("Message.Call.Dead", owner),
                  myPet.getPetName(),
                  myPet.getRespawnTime()));
          return true;
        }
        if (myPet.getSkills().hasSkill(Pickup.class)) {
          myPet.getSkills().getSkill(Pickup.class).activate();
        }
      } else {
        sender.sendMessage(Translation.getString("Message.No.HasPet", owner));
      }
      return true;
    }
    sender.sendMessage("You can't use this command from server console!");
    return true;
  }
Example #3
0
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
      if (!Permissions.has((Player) sender, "MyPet.admin", false)) {
        return true;
      }
    }

    if (args.length < 1) {
      sender.sendMessage(MyPetPlugin.getPlugin().getCommand("mypetadmin").getDescription());
      return false;
    }

    String[] parameter = Arrays.copyOfRange(args, 1, args.length);
    CommandOption option = commandOptions.get(args[0].toLowerCase());

    if (option != null) {
      return option.onCommandOption(sender, parameter);
    }
    return false;
  }
Example #4
0
 @Override
 public List<String> onTabComplete(
     CommandSender commandSender, Command command, String s, String[] strings) {
   if (commandSender instanceof Player
       && !Permissions.has((Player) commandSender, "MyPet.admin", false)) {
     return emptyList;
   }
   if (strings.length == 1) {
     if (optionsList.size() != commandOptions.keySet().size()) {
       optionsList = new ArrayList<>(commandOptions.keySet());
       Collections.sort(optionsList);
     }
     return optionsList;
   } else if (strings.length >= 1) {
     CommandOption co = commandOptions.get(strings[0]);
     if (co != null) {
       if (co instanceof CommandOptionTabCompleter) {
         return ((CommandOptionTabCompleter) co).onTabComplete(commandSender, strings);
       }
     }
   }
   return emptyList;
 }
  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;
  }