Esempio n. 1
0
 public static MyPet getMyPet(int entityID) {
   for (MyPet pet : lActivePets) {
     if (pet.getStatus() == PetState.Here && pet.getCraftPet().getEntityId() == entityID) {
       return pet;
     }
   }
   return null;
 }
Esempio n. 2
0
 private static void removeMyPet(MyPet myPet) {
   if (myPet == null) {
     return;
   }
   lActivePets.remove(myPet);
   if (mActivePets.containsKey(myPet.getOwner())) {
     mActivePets.remove(myPet.getOwner());
   }
 }
Esempio n. 3
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;
  }
Esempio n. 4
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;
   }
 }
Esempio n. 5
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));
     }
   }
 }
Esempio n. 6
0
 public void schedule() {
   if (increaseHpBy > 0 && myPet.getStatus() == PetState.Here) {
     if (timeCounter-- <= 0) {
       if (myPet.getHealth() < myPet.getMaxHealth()) {
         addPotionGraphicalEffect(myPet.getCraftPet(), 0x00FF00, 40); // Green Potion Effect
         myPet
             .getCraftPet()
             .getHandle()
             .heal((float) increaseHpBy, EntityRegainHealthEvent.RegainReason.REGEN);
       }
       timeCounter = regenTime;
     }
   }
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 public String getFormattedValue() {
   return "+"
       + increaseHpBy
       + Translation.getString("Name.HP", myPet.getOwner().getLanguage())
       + " ->"
       + regenTime
       + "sec";
 }
Esempio n. 9
0
 public static InactiveMyPet setMyPetInactive(Player owner) {
   if (mActivePets.containsKey(MyPetPlayer.getMyPetPlayer(owner))) {
     MyPet activeMyPet = getMyPet(owner);
     MyPetSelectSetInactiveEvent event = new MyPetSelectSetInactiveEvent(activeMyPet);
     getServer().getPluginManager().callEvent(event);
     if (event.isCancelled()) {
       return null;
     }
     activeMyPet.removePet();
     InactiveMyPet inactiveMyPet = getInactiveMyPet(activeMyPet);
     removeMyPet(activeMyPet);
     addInactiveMyPet(inactiveMyPet);
     MyPetUtil.getDebugLogger().info("   I: " + inactiveMyPet);
     MyPetUtil.getDebugLogger().info("   A: " + activeMyPet);
     return inactiveMyPet;
   }
   return null;
 }
Esempio n. 10
0
  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;
  }
Esempio n. 11
0
 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;
 }
Esempio n. 12
0
  @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;
  }
Esempio n. 13
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;
  }
Esempio n. 14
0
 private static void addMyPet(MyPet myPet) {
   mActivePets.put(myPet.getOwner(), myPet);
   lActivePets.add(myPet);
 }
Esempio n. 15
0
  private static MyPet getMyPet(InactiveMyPet inactiveMyPet) {
    if (inactiveMyPet.getPetOwner().isOnline()) {
      MyPet activeMyPet =
          inactiveMyPet.getPetType().getNewMyPetInstance(inactiveMyPet.getPetOwner());
      activeMyPet.setLocation(
          inactiveMyPet.getLocation() == null
              ? inactiveMyPet.getPetOwner().getPlayer().getLocation()
              : inactiveMyPet.getLocation());
      activeMyPet.petName = inactiveMyPet.getPetName();
      activeMyPet.respawnTime = inactiveMyPet.getRespawnTime();
      activeMyPet.setSkilltree(inactiveMyPet.getSkillTree());
      activeMyPet.setExtendedInfo(inactiveMyPet.getInfo());

      if (activeMyPet.respawnTime > 0) {
        activeMyPet.status = PetState.Dead;
      } else {
        activeMyPet.status = PetState.Despawned;
      }

      activeMyPet.getExperience().setExp(inactiveMyPet.getExp());
      Collection<MyPetGenericSkill> skills = activeMyPet.getSkills().getSkills();
      if (skills.size() > 0) {
        for (MyPetGenericSkill skill : skills) {
          if (inactiveMyPet.getSkills().hasKey(skill.getName())) {
            skill.load(inactiveMyPet.getSkills().getCompound(skill.getName()));
          }
        }
      }
      activeMyPet.setHealth(inactiveMyPet.getHealth());
      activeMyPet.setHungerValue(inactiveMyPet.getHungerValue());
      return activeMyPet;
    }
    return null;
  }
Esempio n. 16
0
  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;
  }