Example #1
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 #2
0
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
      Player player = (Player) sender;
      if (args.length == 0) {
        if (MyPetList.hasMyPet(player)) {
          MyPet myPet = MyPetList.getMyPet(player);
          if (myPet.getStatus() == PetState.Despawned) {
            sender.sendMessage(
                Util.formatText(
                    Locales.getString("Message.Call.First", player), myPet.getPetName()));
            return true;
          }
          if (myPet.getStatus() == PetState.Dead) {
            sender.sendMessage(
                Util.formatText(
                    Locales.getString("Message.Call.Dead", player),
                    myPet.getPetName(),
                    myPet.getRespawnTime()));
            return true;
          }
          if (!Permissions.hasExtended(player, "MyPet.user.extended.Inventory")
              && !Permissions.has(player, "MyPet.admin", false)) {
            myPet.sendMessageToOwner(Locales.getString("Message.No.CanUse", player));
            return true;
          }
          if (myPet.getSkills().hasSkill(Inventory.class)) {
            myPet.getSkills().getSkill(Inventory.class).activate();
          }
        } else {
          sender.sendMessage(Locales.getString("Message.No.HasPet", player));
        }
      } else if (args.length == 1 && Permissions.has(player, "MyPet.admin", false)) {
        Player petOwner = Bukkit.getServer().getPlayer(args[0]);

        if (petOwner == null || !petOwner.isOnline()) {
          sender.sendMessage(Locales.getString("Message.No.PlayerOnline", player));
        } else if (MyPetList.hasMyPet(petOwner)) {
          MyPet myPet = MyPetList.getMyPet(petOwner);
          if (myPet.getSkills().isSkillActive(Inventory.class)) {
            myPet.getSkills().getSkill(Inventory.class).openInventory(player);
          }
        }
      }
      return true;
    }
    sender.sendMessage("You can't use this command from server console!");
    return true;
  }
Example #3
0
 public void upgrade(ISkillInfo upgrade, boolean quiet) {
   if (upgrade instanceof SprintInfo) {
     if (!quiet && !active) {
       myPet.sendMessageToOwner(
           Util.formatText(
               Translation.getString(
                   "Message.Skill.Sprint.Upgrade", myPet.getOwner().getLanguage()),
               myPet.getPetName()));
     }
     active = true;
   }
 }
Example #4
0
 public void upgrade(ISkillInfo upgrade, boolean quiet) {
   if (upgrade instanceof HPregenerationInfo) {
     boolean valuesEdit = false;
     if (upgrade.getProperties().getCompoundData().containsKey("hp")) {
       int hp = upgrade.getProperties().getAs("hp", TagInt.class).getIntData();
       upgrade.getProperties().getCompoundData().remove("hp");
       TagDouble TagDouble = new TagDouble(hp);
       upgrade.getProperties().getCompoundData().put("hp_double", TagDouble);
     }
     if (upgrade.getProperties().getCompoundData().containsKey("hp_double")) {
       if (!upgrade.getProperties().getCompoundData().containsKey("addset_hp")
           || upgrade
               .getProperties()
               .getAs("addset_hp", TagString.class)
               .getStringData()
               .equals("add")) {
         increaseHpBy +=
             upgrade.getProperties().getAs("hp_double", TagDouble.class).getDoubleData();
       } else {
         increaseHpBy =
             upgrade.getProperties().getAs("hp_double", TagDouble.class).getDoubleData();
       }
       valuesEdit = true;
     }
     if (upgrade.getProperties().getCompoundData().containsKey("time")) {
       if (!upgrade.getProperties().getCompoundData().containsKey("addset_time")
           || upgrade
               .getProperties()
               .getAs("addset_time", TagString.class)
               .getStringData()
               .equals("add")) {
         regenTime -= upgrade.getProperties().getAs("time", TagInt.class).getIntData();
       } else {
         regenTime = upgrade.getProperties().getAs("time", TagInt.class).getIntData();
       }
       if (regenTime < 1) {
         regenTime = 1;
       }
       timeCounter = regenTime;
       valuesEdit = true;
     }
     if (!quiet && valuesEdit) {
       myPet.sendMessageToOwner(
           Util.formatText(
               Translation.getString(
                   "Message.Skill.HpRegeneration.Upgrade", myPet.getOwner().getLanguage()),
               myPet.getPetName(),
               increaseHpBy,
               regenTime));
     }
   }
 }
  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;
  }