/* The is for enchant objectives.
   * Type: Enchant
   * Display_Name:
   * Objective_ID:
   * Level:
   * Amount:
   * Item_ID:
   */
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  public void onEnchantItemEvent(EnchantItemEvent event) {
    if (plugin.isEnabled() == true) {
      Player player = event.getEnchanter();
      Quester quester = plugin.getQuestInteraction().getQuester(player);
      ;
      if (quester.getQuestID() != -1) {
        int questLevel = 1;
        // Check if quest level scalling is turned on and if so add them.
        if (plugin.isScaleQuestLevels()) {
          questLevel = plugin.getQuestInteraction().getQuestLevel(player) + 1;
        }
        LoadedQuest loadedQuest = plugin.getQuestersQuest(quester);
        Map<Enchantment, Integer> enchants = event.getEnchantsToAdd();
        for (Map.Entry<Enchantment, Integer> e : enchants.entrySet()) {
          String enchantName = UQuestUtils.getEnchantName(e.getKey().getName());
          int itemID = event.getItem().getTypeId();
          int itemDamage = event.getItem().getData().getData();
          if (loadedQuest.checkObjective(plugin, player.getLocation(), "enchant", enchantName)) {
            int objItem = loadedQuest.getObjectiveFromTypes("enchant", enchantName).getItemID();
            int objlevel = loadedQuest.getObjectiveFromTypes("enchant", enchantName).getLevel();
            if (objItem == itemID && itemDamage <= 0 && e.getValue() >= objlevel) {
              int amountNeeded =
                  loadedQuest.getObjectiveFromTypes("enchant", enchantName).getAmountNeeded()
                      * questLevel;
              String iName =
                  UQuestUtils.formatName(event.getItem().getData().getItemType().toString());
              int amount = quester.getTracker(plugin, enchantName);
              if (amount < amountNeeded) {
                event.getInventory().remove(event.getItem());
                String[] levels = {"I", "II", "III", "IV", "V"};
                quester.addToTracker(plugin, enchantName, 1);
                amount = quester.getTracker(plugin, enchantName);
                if (amount == amountNeeded) {
                  player.sendMessage(
                      ChatColor.AQUA
                          + iName
                          + ChatColor.GREEN
                          + " enchanted with "
                          + ChatColor.DARK_PURPLE
                          + enchantName
                          + " "
                          + ChatColor.GOLD
                          + levels[e.getValue() - 1]
                          + ChatColor.GREEN
                          + " "
                          + amount
                          + ChatColor.WHITE
                          + "/"
                          + ChatColor.GREEN
                          + amountNeeded);

                } else {
                  player.sendMessage(
                      ChatColor.AQUA
                          + iName
                          + ChatColor.GREEN
                          + " enchanted with "
                          + ChatColor.DARK_PURPLE
                          + enchantName
                          + " "
                          + ChatColor.GOLD
                          + levels[e.getValue() - 1]
                          + ChatColor.AQUA
                          + " "
                          + amount
                          + ChatColor.WHITE
                          + "/"
                          + ChatColor.GREEN
                          + amountNeeded);
                }
              }
            }
          }
        }
      }
    }
  }
Exemple #2
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    Player player = null;
    boolean process = false;
    if (sender instanceof Player) {
      player = (Player) sender;
    } else {
      // Console can use this command
      process = true;
    }

    if (player != null) {
      if (plugin.isUsePermissions() == true) {
        try {
          if (UQuest.getPermissions().has(player, "uQuest.CanReloadQuests")) {
            process = true;
          }
        } catch (NoClassDefFoundError ncdfe) {
          // they don't have permissions so disable it plugin wide
          plugin.setUsePermissions(false);
          System.err.println(
              UQuest.pluginNameBracket()
                  + " Failed to access Permissions plugin. Disabling support for it.");
        }
      } // Ops can use it too! Just incase we;re not unsing permissions.
      if (player.isOp()) {
        process = true;
      }
    }

    // Actual command studd starts here
    if (process == true) {
      int questsBefore = plugin.getQuestInteraction().getQuestTotal();
      plugin.theQuestsLoadAllIntoArray();
      int questsAfter = plugin.getQuestInteraction().getQuestTotal();

      sender.sendMessage(UQuest.pluginNameBracket() + " uQuest's quest list has been reloaded.");
      sender.sendMessage(
          UQuest.pluginNameBracket()
              + " Total before: "
              + Integer.toString(questsBefore)
              + " | Total After: "
              + Integer.toString(questsAfter));

      if (player != null) {
        System.out.println(
            UQuest.pluginNameBracket() + " " + player.getName() + " reloaded uQuest's quests.");
        System.out.println(
            UQuest.pluginNameBracket()
                + " Total before: "
                + Integer.toString(questsBefore)
                + " | Total After: "
                + Integer.toString(questsAfter));
      }
    } else {
      player.sendMessage(ChatColor.RED + "You don't have permission to use that!");
    }
    return true;
  }