@EventHandler
    public void onCustomEvent(ToPlayerInRegionEvent event) {
      Location l = event.getLocation();
      RegionManager rm = getPlugin().getRegionManager();
      Region r = rm.getRegion(l);
      if (r == null) return;
      RegionType rt = rm.getRegionType(r.getType());

      int jumpMult = effect.regionHasEffect(rt.getEffects(), "man_cannon");

      // Check if the region is a teleporter
      if (jumpMult == 0) return;

      // Check to see if the Townships has enough reagents
      if (!effect.hasReagents(l)) {
        return;
      }

      // Run upkeep but don't need to know if upkeep occured
      effect.forceUpkeep(event);

      // Launch the player into the air
      Player player = event.getPlayer();
      float pitch = player.getEyeLocation().getPitch();
      int jumpForwards = 1;
      if (pitch > 45) {
        jumpForwards = 1;
      }
      if (pitch > 0) {
        pitch = -pitch;
      }
      float multiplier = ((90f + pitch) / 50f);
      Vector v =
          player
              .getVelocity()
              .setY(1)
              .add(
                  player
                      .getLocation()
                      .getDirection()
                      .setY(0)
                      .normalize()
                      .multiply(multiplier * jumpForwards));
      NCPExemptionManager.exemptPermanently(player, CheckType.MOVING);
      player.setVelocity(v.multiply(jumpMult));
      player.setFallDistance(-8f * jumpMult);
      NCPExemptionManager.unexempt(player, CheckType.MOVING);
    }
示例#2
0
  public static void openListInventory(
      ArrayList<RegionType> regions,
      ArrayList<SuperRegionType> superRegions,
      Player player,
      String category) {
    int size = 9;
    int actualSize = regions.size() + superRegions.size() + 1;
    if (actualSize > size) {
      size = actualSize + 9 - (actualSize % 9);
      if (actualSize % 9 == 0) {
        size -= 9;
      }
    }
    category = category.toLowerCase();
    // Inventory inv = Bukkit.createInventory(null, size, ChatColor.RED + category + " Regions");
    // Inventory inv = Bukkit.createInventory(new MenuHolder(Bukkit.createInventory(null, size)),
    // size, ChatColor.RED + WordUtils.capitalize(category) +  " Regions");
    Inventory inv =
        Bukkit.createInventory(
            null, size, ChatColor.RED + WordUtils.capitalize(category) + " Regions");

    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    int i = 0;
    for (RegionType r : regions) {
      ItemStack is = new ItemStack(r.getIcon());
      ItemMeta isMeta = is.getItemMeta();
      String displayName = ChatColor.RESET + r.getName();
      ArrayList<String> lore = new ArrayList<String>();
      lore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Region");
      if (r.getDescription() != null && !r.getDescription().equals("")) {
        lore.addAll(Util.textWrap(ChatColor.RESET + "" + ChatColor.GOLD, r.getDescription()));
      }
      if (r.getMoneyRequirement() > 0) {
        lore.add(
            ChatColor.RESET
                + ""
                + ChatColor.BLUE
                + "Cost: "
                + formatter.format(r.getMoneyRequirement()));
      }
      /*if (r.getRequirements().size() > 0) {
          lore.add("Requirements");
          for (ArrayList<TOItem> items : r.getRequirements()) {
              String reagents = "";
              for (TOItem item : items) {
                  if (!reagents.equals("")) {
                      reagents += " or ";
                  }
                  String itemName = "";
                  if (item.isWildDamage()) {
                      itemName = item.getMat().name().replace("_", " ").toLowerCase();
                  } else {
                      ItemStack ist = new ItemStack(item.getMat(), 1, (short) item.getDamage());
                      itemName = Items.itemByStack(ist).getName();
                  }
                  reagents += item.getQty() + " " + itemName;
              }
              lore.addAll(Util.textWrap("", reagents));
          }
      }*/
      isMeta.setDisplayName(displayName);

      // Trim lore
      trimLore:
      {
        boolean addEllipses = lore.size() > 20;
        if (addEllipses) {
          for (int k = lore.size(); k > 19; k--) {
            lore.remove(k - 1);
          }
          lore.add("To be continued...");
        }
      }

      isMeta.setLore(lore);
      is.setItemMeta(isMeta);
      inv.setItem(i, is);
      i++;
    }
    for (SuperRegionType sr : superRegions) {
      ItemStack is = new ItemStack(sr.getIcon());
      ItemMeta isMeta = is.getItemMeta();
      String displayName = ChatColor.RESET + sr.getName();
      ArrayList<String> lore = new ArrayList<String>();
      lore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Super Region");
      if (sr.getDescription() != null && !sr.getDescription().equals("")) {
        lore.addAll(Util.textWrap(ChatColor.GOLD + "", sr.getDescription()));
      }
      if (sr.getChildren().size() > 0) {
        lore.add(ChatColor.GREEN + "Upgrade from:");
        int lineCount = 0;
        String childString = "";
        for (String srt : sr.getChildren()) {
          if (!childString.equals("")) {
            childString += ", ";
          } else {
            childString += ChatColor.GREEN + "";
          }
          lineCount += srt.length();
          if (lineCount > 50) {
            lore.add(childString);
            childString = new String();
            lineCount = srt.length();
          }
          childString += srt;
        }
        lore.add(childString);
      }
      if (sr.getMoneyRequirement() > 0) {
        lore.add("Cost: " + formatter.format(sr.getMoneyRequirement()));
      }
      if (sr.getRequirements().size() > 0) {
        lore.add(ChatColor.BLUE + "Requirements:");
        for (String s : sr.getRequirements().keySet()) {
          lore.add(ChatColor.BLUE + " " + sr.getRequirement(s) + " " + s);
        }
      }
      isMeta.setDisplayName(displayName);

      // Trim lore
      trimLore:
      {
        boolean addEllipses = lore.size() > 20;
        if (addEllipses) {
          for (int k = lore.size(); k > 19; k--) {
            lore.remove(k - 1);
          }
          lore.add("To be continued...");
        }
      }

      isMeta.setLore(lore);
      is.setItemMeta(isMeta);
      inv.setItem(i, is);
      i++;
    }
    ItemStack is = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta isMeta = is.getItemMeta();
    isMeta.setDisplayName(ChatColor.RESET + "Back to Categories");
    ArrayList<String> lore = new ArrayList<String>();
    lore.add("list " + category);
    isMeta.setLore(lore);
    is.setItemMeta(isMeta);
    inv.setItem(size - 1, is);
    player.openInventory(inv);
  }