@Override
 public boolean onCommandOption(CommandSender sender, String[] args) {
   if (sender instanceof Player && MyPetApi.getPlayerManager().isMyPetPlayer((Player) sender)) {
     MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer((Player) sender);
     myPetPlayer.setHealthBarActive(!myPetPlayer.isHealthBarActive());
     sender.sendMessage(Translation.getString("Message.Command.Success", sender));
     return true;
   }
   sender.sendMessage(Translation.getString("Message.Command.Fail", sender));
   return true;
 }
Exemple #2
0
 public String getFormattedValue() {
   return ""
       + ChatColor.GOLD
       + damage
       + ChatColor.RESET
       + " "
       + Translation.getString("Name.Damage", myPet.getOwner());
 }
 public String getName(String locale) {
   SkillName sn = this.getClass().getAnnotation(SkillName.class);
   if (sn != null) {
     if (sn.translationNode().equalsIgnoreCase("")) {
       return sn.value();
     } else {
       String translatedName = Translation.getString(sn.translationNode(), locale);
       if (translatedName.equals(sn.translationNode())) {
         return sn.value();
       } else {
         return translatedName;
       }
     }
   }
   return null;
 }
Exemple #4
0
 public void upgrade(SkillInfo upgrade, boolean quiet) {
   if (upgrade instanceof DamageInfo) {
     boolean isPassive = damage <= 0;
     if (upgrade.getProperties().getCompoundData().containsKey("damage")) {
       int damage = upgrade.getProperties().getAs("damage", TagInt.class).getIntData();
       upgrade.getProperties().getCompoundData().remove("damage");
       TagDouble TagDouble = new TagDouble(damage);
       upgrade.getProperties().getCompoundData().put("damage_double", TagDouble);
     }
     if (upgrade.getProperties().getCompoundData().containsKey("damage_double")) {
       if (!upgrade.getProperties().getCompoundData().containsKey("addset_damage")
           || upgrade
               .getProperties()
               .getAs("addset_damage", TagString.class)
               .getStringData()
               .equals("add")) {
         damage += upgrade.getProperties().getAs("damage_double", TagDouble.class).getDoubleData();
       } else {
         damage = upgrade.getProperties().getAs("damage_double", TagDouble.class).getDoubleData();
       }
       if (!quiet) {
         myPet
             .getOwner()
             .sendMessage(
                 Util.formatText(
                     Translation.getString(
                         "Message.Skill.Damage.Upgrade", myPet.getOwner().getLanguage()),
                     myPet.getPetName(),
                     damage));
       }
     }
     if (isPassive != (damage <= 0)) {
       if (myPet.getStatus() == PetState.Here) {
         getMyPet().getEntity().get().getHandle().getPathfinder().clearGoals();
         getMyPet().getEntity().get().getHandle().getTargetSelector().clearGoals();
         getMyPet().getEntity().get().getHandle().setPathfinder();
         if (damage == 0) {
           getMyPet().getEntity().get().setTarget(null);
         }
       }
     }
   }
 }
Exemple #5
0
  public boolean onCommand(
      final 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 (!Permissions.hasLegacy(player, "MyPet.command.switch")) {
      player.sendMessage(Translation.getString("Message.No.Allowed", player));
      return true;
    }

    if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
      final MyPetPlayer owner = MyPetApi.getPlayerManager().getMyPetPlayer(player);

      MyPetApi.getRepository()
          .getMyPets(
              owner,
              new RepositoryCallback<List<StoredMyPet>>() {
                @Override
                public void callback(List<StoredMyPet> pets) {
                  if (pets.size() - (owner.hasMyPet() ? 1 : 0) == 0) {
                    owner.sendMessage(
                        Translation.getString("Message.Command.Switch.NoStoredPets", owner));
                    return;
                  }
                  if (owner.isOnline()) {
                    String worldGroup =
                        WorldGroup.getGroupByWorld(owner.getPlayer().getWorld().getName())
                            .getName();
                    int inactivePetCount = getInactivePetCount(pets, worldGroup);
                    int maxPetCount = getMaxPetCount(owner.getPlayer());

                    String title;
                    if (owner.hasMyPet()) {
                      inactivePetCount--;
                      title = Translation.getString("Message.Npc.SwitchTitle", owner);
                    } else {
                      title = Translation.getString("Message.SelectMyPet", owner);
                    }

                    String stats = "(" + inactivePetCount + "/" + maxPetCount + ")";

                    final MyPetSelectionGui gui = new MyPetSelectionGui(owner, title + " " + stats);
                    gui.open(
                        pets,
                        new RepositoryCallback<StoredMyPet>() {
                          @Override
                          public void callback(StoredMyPet storedMyPet) {
                            Optional<MyPet> activePet =
                                MyPetApi.getMyPetManager().activateMyPet(storedMyPet);
                            if (activePet.isPresent() && owner.isOnline()) {
                              Player player = owner.getPlayer();
                              activePet
                                  .get()
                                  .getOwner()
                                  .sendMessage(
                                      Util.formatText(
                                          Translation.getString("Message.Npc.ChosenPet", owner),
                                          activePet.get().getPetName()));
                              WorldGroup wg =
                                  WorldGroup.getGroupByWorld(player.getWorld().getName());
                              owner.setMyPetForWorldGroup(wg, activePet.get().getUUID());

                              switch (activePet.get().createEntity()) {
                                case Canceled:
                                  owner.sendMessage(
                                      Util.formatText(
                                          Translation.getString("Message.Spawn.Prevent", owner),
                                          activePet.get().getPetName()));
                                  break;
                                case NoSpace:
                                  owner.sendMessage(
                                      Util.formatText(
                                          Translation.getString("Message.Spawn.NoSpace", owner),
                                          activePet.get().getPetName()));
                                  break;
                                case NotAllowed:
                                  owner.sendMessage(
                                      Util.formatText(
                                          Translation.getString("Message.No.AllowedHere", owner),
                                          activePet.get().getPetName()));
                                  break;
                                case Dead:
                                  owner.sendMessage(
                                      Util.formatText(
                                          Translation.getString("Message.Spawn.Respawn.In", owner),
                                          activePet.get().getPetName(),
                                          activePet.get().getRespawnTime()));
                                  break;
                                case Spectator:
                                  sender.sendMessage(
                                      Util.formatText(
                                          Translation.getString("Message.Spawn.Spectator", owner),
                                          activePet.get().getPetName()));
                                  break;
                              }
                            }
                          }
                        });
                  }
                }
              });
    } else {
      sender.sendMessage(Translation.getString("Message.No.HasPet", player));
    }
    return true;
  }