@Override
  public void run(
      final Server server, final User user, final String commandLabel, final String[] args)
      throws Exception {
    List<ItemStack> is = new ArrayList<>();

    boolean validateReverse = false;
    if (args.length > 0) {
      is = ess.getItemDb().getMatching(user, args);
    } else {
      for (ItemStack stack : user.getBase().getInventory().getContents()) {
        if (stack == null || stack.getType() == Material.AIR) {
          continue;
        }
        is.add(stack);
      }
      validateReverse = true;
    }

    boolean didConvert = false;
    for (final ItemStack itemStack : is) {
      if (condenseStack(user, itemStack, validateReverse)) {
        didConvert = true;
      }
    }
    user.getBase().updateInventory();

    if (didConvert) {
      user.sendMessage(tl("itemsConverted"));
    } else {
      user.sendMessage(tl("itemsNotConverted"));
      throw new NoChargeException();
    }
  }
Пример #2
0
	@Override
	public User getOfflineUser(final String name)
	{
		final User user = userMap.getUser(name);
		if (user != null && user.getBase() instanceof OfflinePlayer)
		{
			((OfflinePlayer)user.getBase()).setName(name);
		}
		return user;
	}
Пример #3
0
 @Override
 public void setVanished(final boolean set) {
   vanished = set;
   if (set) {
     for (User user : ess.getOnlineUsers()) {
       if (!user.isAuthorized("essentials.vanish.see")) {
         user.getBase().hidePlayer(getBase());
       }
     }
     setHidden(true);
     ess.getVanishedPlayers().add(getName());
     if (isAuthorized("essentials.vanish.effect")) {
       this.getBase()
           .addPotionEffect(
               new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
     }
   } else {
     for (Player p : ess.getOnlinePlayers()) {
       p.showPlayer(getBase());
     }
     setHidden(false);
     ess.getVanishedPlayers().remove(getName());
     if (isAuthorized("essentials.vanish.effect")) {
       this.getBase().removePotionEffect(PotionEffectType.INVISIBILITY);
     }
   }
 }
Пример #4
0
	@Override
	public User getUser(final Object base)
	{
		if (base instanceof Player)
		{
			return getUser((Player)base);
		}
		if (base instanceof String)
		{
			final User user = userMap.getUser((String)base);
			if (user != null && user.getBase() instanceof OfflinePlayer)
			{
				((OfflinePlayer)user.getBase()).setName((String)base);
			}
			return user;
		}
		return null;
	}
Пример #5
0
 @Override
 public void requestTeleport(final User player, final boolean here) {
   teleportRequestTime = System.currentTimeMillis();
   teleportRequester = player == null ? null : player.getBase().getUniqueId();
   teleportRequestHere = here;
   if (player == null) {
     teleportLocation = null;
   } else {
     teleportLocation = here ? player.getLocation() : this.getLocation();
   }
 }
  @Override
  void togglePlayer(CommandSource sender, User user, Boolean enabled)
      throws NotEnoughArgumentsException {
    if (enabled == null) {
      enabled = !user.isVanished();
    }

    user.setVanished(enabled);
    user.sendMessage(tl("vanish", user.getDisplayName(), enabled ? tl("enabled") : tl("disabled")));

    if (enabled == true) {
      user.sendMessage(tl("vanished"));
    }
    if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) {
      sender.sendMessage(
          tl("vanish", user.getDisplayName(), enabled ? tl("enabled") : tl("disabled")));
    }
  }
  private boolean condenseStack(
      final User user, final ItemStack stack, final boolean validateReverse)
      throws ChargeException, MaxMoneyException {
    final SimpleRecipe condenseType = getCondenseType(stack);
    if (condenseType != null) {
      final ItemStack input = condenseType.getInput();
      final ItemStack result = condenseType.getResult();

      if (validateReverse) {
        boolean pass = false;
        for (Recipe revRecipe : ess.getServer().getRecipesFor(input)) {
          if (getStackOnRecipeMatch(revRecipe, result) != null) {
            pass = true;
            break;
          }
        }
        if (!pass) {
          return false;
        }
      }

      int amount = 0;

      for (final ItemStack contents : user.getBase().getInventory().getContents()) {
        if (contents != null && contents.isSimilar(stack)) {
          amount += contents.getAmount();
        }
      }

      int output = ((amount / input.getAmount()) * result.getAmount());
      amount -= amount % input.getAmount();

      if (amount > 0) {
        input.setAmount(amount);
        result.setAmount(output);
        final Trade remove = new Trade(input, ess);
        final Trade add = new Trade(result, ess);
        remove.charge(user);
        add.pay(user, OverflowType.DROP);
        return true;
      }
    }
    return false;
  }
Пример #8
0
  public User getUser(final String name) {
    try {
      final String sanitizedName = StringUtil.safeString(name);
      if (names.containsKey(sanitizedName)) {
        final UUID uuid = names.get(sanitizedName);
        return getUser(uuid);
      }

      final File userFile = getUserFileFromString(sanitizedName);
      if (userFile.exists()) {
        ess.getLogger().info("Importing user " + name + " to usermap.");
        User user = new User(new OfflinePlayer(sanitizedName, ess.getServer()), ess);
        trackUUID(user.getBase().getUniqueId(), user.getName(), true);
        return user;
      }
      return null;
    } catch (UncheckedExecutionException ex) {
      return null;
    }
  }
		@Override
		public void run()
		{
			if (user.getBase() instanceof OfflinePlayer)
			{
				return;
			}

			try
			{
				final Location spawn = spawns.getSpawn(ess.getSettings().getNewbieSpawn());
				if (spawn != null)
				{
					user.getTeleport().now(spawn, false, TeleportCause.PLUGIN);
				}
			}
			catch (Exception ex)
			{
				Bukkit.getLogger().log(Level.WARNING, _("teleportNewPlayerError"), ex);
			}
		}
Пример #10
0
  public void expandItems(final User user, final List<String> items) throws Exception {
    try {
      IText input = new SimpleTextInput(items);
      IText output = new KeywordReplacer(input, user.getSource(), ess);

      boolean spew = false;
      final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
      for (String kitItem : output.getLines()) {
        if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) {
          BigDecimal value =
              new BigDecimal(
                  kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim());
          Trade t = new Trade(value, ess);
          t.pay(user, OverflowType.DROP);
          continue;
        }

        if (kitItem.startsWith("/")) {
          String command = kitItem.substring(1);
          String name = user.getName();
          command = command.replace("{player}", name);
          Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
          continue;
        }

        final String[] parts = kitItem.split(" +");
        final ItemStack parseStack =
            ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);

        if (parseStack.getType() == Material.AIR) {
          continue;
        }

        final MetaItemStack metaStack = new MetaItemStack(parseStack);

        if (parts.length > 2) {
          // We pass a null sender here because kits should not do perm checks
          metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess);
        }

        final Map<Integer, ItemStack> overfilled;
        final boolean allowOversizedStacks = user.isAuthorized("essentials.oversizedstacks");
        if (allowOversizedStacks) {
          overfilled =
              InventoryWorkaround.addOversizedItems(
                  user.getBase().getInventory(),
                  ess.getSettings().getOversizedStackSize(),
                  metaStack.getItemStack());
        } else {
          overfilled =
              InventoryWorkaround.addItems(user.getBase().getInventory(), metaStack.getItemStack());
        }
        for (ItemStack itemStack : overfilled.values()) {
          int spillAmount = itemStack.getAmount();
          if (!allowOversizedStacks) {
            itemStack.setAmount(
                spillAmount < itemStack.getMaxStackSize()
                    ? spillAmount
                    : itemStack.getMaxStackSize());
          }
          while (spillAmount > 0) {
            user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
            spillAmount -= itemStack.getAmount();
          }
          spew = true;
        }
      }
      user.getBase().updateInventory();
      if (spew) {
        user.sendMessage(tl("kitInvFull"));
      }
    } catch (Exception e) {
      user.getBase().updateInventory();
      ess.getLogger().log(Level.WARNING, e.getMessage());
      throw new Exception(tl("kitError2"), e);
    }
  }