Example #1
0
  // TODO: Convert this to use one of the new text classes?
  public static String listKits(final IEssentials ess, final User user) throws Exception {
    try {
      final ConfigurationSection kits = ess.getSettings().getKits();
      final StringBuilder list = new StringBuilder();
      for (String kitItem : kits.getKeys(false)) {
        if (user == null) {
          list.append(" ").append(capitalCase(kitItem));
        } else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) {
          String cost = "";
          String name = capitalCase(kitItem);
          BigDecimal costPrice =
              new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
          if (costPrice.signum() > 0) {
            cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess));
          }

          Kit kit = new Kit(kitItem, ess);
          if (kit.getNextUse(user) != 0) {
            name = tl("kitDelay", name);
          }

          list.append(" ").append(name).append(cost);
        }
      }
      return list.toString().trim();
    } catch (Exception ex) {
      throw new Exception(tl("kitError"), ex);
    }
  }
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		if (event.getPlayer().hasPlayedBefore())
		{
			LOGGER.log(Level.FINE, "Old player join");
			return;
		}

		final User user = ess.getUser(event.getPlayer());

		if (!"none".equalsIgnoreCase(ess.getSettings().getNewbieSpawn()))
		{
			ess.scheduleSyncDelayedTask(new NewPlayerTeleport(user), 1L);
		}

		if (ess.getSettings().getAnnounceNewPlayers())
		{
			final IText output = new KeywordReplacer(ess.getSettings().getAnnounceNewPlayerFormat(), user, ess);
			final SimpleTextPager pager = new SimpleTextPager(output);
			ess.broadcastMessage(user, pager.getString(0));
		}

		final String kitName = ess.getSettings().getNewPlayerKit();
		if (!kitName.isEmpty())
		{
			try
			{
				final Map<String, Object> kit = ess.getSettings().getKit(kitName.toLowerCase(Locale.ENGLISH));
				final List<String> items = Kit.getItems(user, kit);
				Kit.expandItems(ess, user, items);
			}
			catch (Exception ex)
			{
				LOGGER.log(Level.WARNING, ex.getMessage());
			}
		}

		LOGGER.log(Level.FINE, "New player join");
	}