public void setMyPet(MyPet myPet) {
    if (myPet != null) {
      super.setMyPet(myPet);
      final MySkeleton mySkeleton = (MySkeleton) myPet;
      final EntityMySkeleton entityMySkeleton = this;

      this.setWither(mySkeleton.isWither());

      MyPetPlugin.getPlugin()
          .getServer()
          .getScheduler()
          .runTaskLater(
              MyPetPlugin.getPlugin(),
              new Runnable() {
                public void run() {
                  if (mySkeleton.getStatus() == PetState.Here) {
                    for (EquipmentSlot slot : EquipmentSlot.values()) {
                      if (mySkeleton.getEquipment(slot) != null) {
                        entityMySkeleton.setPetEquipment(
                            slot.getSlotId(), mySkeleton.getEquipment(slot));
                      }
                    }
                  }
                }
              },
              5L);
    }
  }
  @Override
  public boolean onCommandOption(CommandSender sender, String[] args) {
    MyPetPlugin.getPlugin().reloadConfig();
    Configuration.config = MyPetPlugin.getPlugin().getConfig();
    Configuration.loadConfiguration();
    DebugLogger.info("Config reloaded.");
    sender.sendMessage(
        "[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] config (config.yml) reloaded!");

    return true;
  }
Exemple #3
0
  public static ResourceBundle loadLocale(String localeString) {

    JarFile jarFile;
    try {
      jarFile = new JarFile(MyPetPlugin.getPlugin().getFile());
    } catch (IOException ignored) {
      return null;
    }

    ResourceBundle newLocale = null;
    try {
      JarEntry jarEntry = jarFile.getJarEntry("locale/MyPet_" + localeString + ".properties");
      if (jarEntry != null) {
        java.util.ResourceBundle defaultBundle =
            new PropertyResourceBundle(
                new InputStreamReader(jarFile.getInputStream(jarEntry), "UTF-8"));
        newLocale = new ResourceBundle(defaultBundle);
      } else {
        throw new IOException();
      }
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      DebugLogger.printThrowable(e);
    } catch (IOException ignored) {
    }

    File localeFile =
        new File(
            MyPetPlugin.getPlugin().getDataFolder()
                + File.separator
                + "locale"
                + File.separator
                + "MyPet_"
                + localeString
                + ".properties");
    if (localeFile.exists()) {
      if (newLocale == null) {
        newLocale = new ResourceBundle();
      }
      try {
        java.util.ResourceBundle optionalBundle =
            new PropertyResourceBundle(
                new InputStreamReader(new FileInputStream(localeFile), "UTF-8"));
        newLocale.addExtensionBundle(optionalBundle);
      } catch (IOException e) {
        e.printStackTrace();
        DebugLogger.printThrowable(e);
      }
    }
    return newLocale;
  }
Exemple #4
0
  public void addPotionGraphicalEffect(CraftMyPet entity, int color, int duration) {
    final EntityLiving entityLiving = entity.getHandle();
    entityLiving.getDataWatcher().watch(7, new Integer(color));

    Bukkit.getScheduler()
        .scheduleSyncDelayedTask(
            MyPetPlugin.getPlugin(),
            new Runnable() {
              public void run() {
                int potionEffects = 0;
                if (!entityLiving.effects.isEmpty()) {
                  potionEffects = PotionBrewer.a(entityLiving.effects.values());
                }
                entityLiving.getDataWatcher().watch(7, new Integer(potionEffects));
              }
            },
            duration);
  }
Exemple #5
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;
  }
  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;
  }