Пример #1
1
	public static void checkTime(final User user, final String kitName, final Map<String, Object> els) throws NoChargeException
	{
		final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L;
		final Calendar c = new GregorianCalendar();
		c.add(Calendar.SECOND, -(int)delay);
		c.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0));

		final long mintime = c.getTimeInMillis();

		final Long lastTime = user.getKitTimestamp(kitName);
		if (lastTime == null || lastTime < mintime)
		{
			final Calendar now = new GregorianCalendar();
			user.setKitTimestamp(kitName, now.getTimeInMillis());
		}
		else
		{
			final Calendar future = new GregorianCalendar();
			future.setTimeInMillis(lastTime);
			future.add(Calendar.SECOND, (int)delay);
			future.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
			user.sendMessage(_("kitTimed", Util.formatDateDiff(future.getTimeInMillis())));
			throw new NoChargeException();
		}
	}
  @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();
    }
  }
  @Override
  public void onPlayerJoin(final PlayerJoinEvent event) {
    ess.getBackup().onPlayerJoin();
    final User user = ess.getUser(event.getPlayer());

    if (ess.getSettings().changeDisplayName()) {
      user.setDisplayName(user.getNick());
    }
    user.updateActivity(false);
    if (user.isAuthorized("essentials.sleepingignored")) {
      user.setSleepingIgnored(true);
    }

    if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd")) {
      for (String m : ess.getMotd(user, null)) {
        if (m == null) {
          continue;
        }
        user.sendMessage(m);
      }
    }

    if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
      final List<String> mail = user.getMails();
      if (mail.isEmpty()) {
        user.sendMessage(Util.i18n("noNewMail"));
      } else {
        user.sendMessage(Util.format("youHaveNewMail", mail.size()));
      }
    }
  }
Пример #4
0
  @Override
  protected void run(Server server, User user, String commandLabel, String[] args)
      throws Exception {
    int page = 1;
    String match = args[0].toLowerCase();
    try {
      if (args.length > 0) {
        page = Integer.parseInt(args[args.length - 1]);
        if (args.length == 1) {
          match = "";
        }
      }

    } catch (Exception ex) {
    }

    List<String> lines = getHelpLines(user, match);
    int start = (page - 1) * 9;
    int pages = lines.size() / 9 + (lines.size() % 9 > 0 ? 1 : 0);

    user.sendMessage(Util.format("helpPages", page, pages));
    for (int i = start; i < lines.size() && i < start + 9; i++) {
      user.sendMessage(lines.get(i));
    }
  }
Пример #5
0
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
    charge(user);

    if (!user.toggleAfk()) {
      user.sendMessage(Util.i18n("markedAsNotAway"));
      ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
    } else {
      user.sendMessage(Util.i18n("markedAsAway"));
      ess.broadcastMessage(user.getName(), Util.format("userIsAway", user.getDisplayName()));
    }
  }
Пример #6
0
  public void checkDelay(final User user) throws Exception {
    long nextUse = getNextUse(user);

    if (nextUse == 0L) {
      return;
    } else if (nextUse < 0L) {
      user.sendMessage(tl("kitOnce"));
      throw new NoChargeException();
    } else {
      user.sendMessage(tl("kitTimed", DateUtil.formatDateDiff(nextUse)));
      throw new NoChargeException();
    }
  }
Пример #7
0
  public void checkActivity() {
    final long autoafkkick = ess.getSettings().getAutoAfkKick();
    if (autoafkkick > 0
        && lastActivity > 0
        && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis()
        && !isHidden()
        && !isAuthorized("essentials.kick.exempt")
        && !isAuthorized("essentials.afk.kickexempt")) {
      final String kickReason = tl("autoAfkKickReason", autoafkkick / 60.0);
      lastActivity = 0;
      this.getBase().kickPlayer(kickReason);

      for (User user : ess.getOnlineUsers()) {
        if (user.isAuthorized("essentials.kick.notify")) {
          user.sendMessage(tl("playerKicked", Console.NAME, getName(), kickReason));
        }
      }
    }
    final long autoafk = ess.getSettings().getAutoAfk();
    if (!isAfk()
        && autoafk > 0
        && lastActivity + autoafk * 1000 < System.currentTimeMillis()
        && isAuthorized("essentials.afk.auto")) {
      setAfk(true);
      if (!isHidden()) {
        setDisplayNick();
        final String msg = tl("userIsAway", getDisplayName());
        if (!msg.isEmpty()) {
          ess.broadcastMessage(this, msg);
        }
      }
    }
  }
Пример #8
0
		@EventHandler(priority = EventPriority.HIGHEST)
		public void onPlayerJoin(final PlayerJoinEvent event)
		{
			final User user = ess.getUser(event.getPlayer());
			if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
			{
				return;
			}

			try
			{
				sendToJail(user, user.getJail());
			}
			catch (Exception ex)
			{
				if (ess.getSettings().isDebug())
				{
					LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
				}
				else
				{
					LOGGER.log(Level.INFO, _("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
				}
			}
			user.sendMessage(_("jailMessage"));
		}
Пример #9
0
	@Override
	protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
	{
		final Trade charge = new Trade(this.getName(), ess);
		charge.isAffordableFor(user);
		user.sendMessage(_("backUsageMsg"));
		user.getTeleport().back(charge);
	}
Пример #10
0
	@Override
	public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		// Which Players(s) / Users(s) are we interested in?
		String userSelector = null;
		if (args.length == 2)
		{
			userSelector = args[1];
		}
		Set<User> users = getUsers(server, sender, userSelector);

		// If no arguments we are reading the time
		if (args.length == 0)
		{
			getUsersTime(sender, users);
			return;
		}

		User user = ess.getUser(sender);
		if (user != null && (!users.contains(user) || users.size() > 1)&& !user.isAuthorized("essentials.ptime.others"))
		{
			user.sendMessage(_("pTimeOthersPermission"));
			return;
		}

		Long ticks;
		// Parse the target time int ticks from args[0]
		String timeParam = args[0];
		boolean relative = true;
		if (timeParam.startsWith("@"))
		{
			relative = false;
			timeParam = timeParam.substring(1);
		}

		if (getAliases.contains(timeParam))
		{
			getUsersTime(sender, users);
			return;
		}
		else if (DescParseTickFormat.meansReset(timeParam))
		{
			ticks = null;
		}
		else
		{
			try
			{
				ticks = DescParseTickFormat.parse(timeParam);
			}
			catch (NumberFormatException e)
			{
				throw new NotEnoughArgumentsException(e);
			}
		}

		setUsersTime(sender, users, ticks, relative);
	}
Пример #11
0
 // Returns true if status expired during this check
 public boolean checkMuteTimeout(final long currentTime) {
   if (getMuteTimeout() > 0 && getMuteTimeout() < currentTime && isMuted()) {
     setMuteTimeout(0);
     sendMessage(tl("canTalkAgain"));
     setMuted(false);
     return true;
   }
   return false;
 }
  @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")));
    }
  }
Пример #13
0
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {

    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }
    charge(user);
    ess.getJail().setJail(user.getLocation(), args[0]);
    user.sendMessage(Util.format("jailSet", args[0]));
  }
Пример #14
0
	@Override
	public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
	{
		final double bal = (args.length < 1
							|| !(user.isAuthorized("essentials.balance.others")
								 || user.isAuthorized("essentials.balance.other"))
							? user
							: getPlayer(server, args, 0, true)).getMoney();
		user.sendMessage(_("balance", Util.displayCurrency(bal, ess)));
	}
  @Override
  public void onPlayerChat(final PlayerChatEvent event) {
    if (isAborted(event)) {
      return;
    }

    /**
     * This file should handle detection of the local chat features... if local chat is enabled, we
     * need to handle it here
     */
    final User user = ess.getUser(event.getPlayer());
    final String chatType = getChatType(event.getMessage());
    long radius = ess.getSettings().getChatRadius();
    if (radius < 1) {
      return;
    }
    radius *= radius;
    try {
      if (event.getMessage().length() > 0 && chatType.length() > 0) {
        StringBuilder permission = new StringBuilder();
        permission.append("essentials.chat.").append(chatType);

        StringBuilder command = new StringBuilder();
        command.append("chat-").append(chatType);

        StringBuilder format = new StringBuilder();
        format.append(chatType).append("Format");

        StringBuilder errorMsg = new StringBuilder();
        errorMsg
            .append("notAllowedTo")
            .append(chatType.substring(0, 1).toUpperCase())
            .append(chatType.substring(1));

        if (user.isAuthorized(permission.toString())) {
          charge(user, command.toString());
          event.setMessage(event.getMessage().substring(1));
          event.setFormat(Util.format(format.toString(), event.getFormat()));
          return;
        }

        user.sendMessage(Util.i18n(errorMsg.toString()));
        event.setCancelled(true);
        return;
      }
    } catch (ChargeException ex) {
      ess.showError(user, ex, "Shout");
      event.setCancelled(true);
      return;
    }
    sendLocalChat(user, radius, event);
  }
Пример #16
0
  @Override
  public void run(
      final Server server, final User user, final String commandLabel, final String[] args)
      throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }

    if (args[0].equalsIgnoreCase("hand")) {
      final ItemStack item = user.getItemInHand();
      if (item == null) {
        throw new Exception(Util.i18n("repairInvalidType"));
      }
      final String itemName = item.getType().toString().toLowerCase();
      final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);

      charge.isAffordableFor(user);

      repairItem(item);

      charge.charge(user);

      user.sendMessage(Util.format("repair", itemName.replace('_', ' ')));
    } else if (args[0].equalsIgnoreCase("all")) {
      final List<String> repaired = new ArrayList<String>();
      repairItems(user.getInventory().getContents(), user, repaired);

      repairItems(user.getInventory().getArmorContents(), user, repaired);

      if (repaired.isEmpty()) {
        throw new Exception(Util.format("repairNone"));
      } else {
        user.sendMessage(Util.format("repair", Util.joinList(repaired)));
      }

    } else {
      throw new NotEnoughArgumentsException();
    }
  }
Пример #17
0
	@Override
	public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
	{
		switch (args.length)
		{
		case 0:
			throw new NotEnoughArgumentsException();

		case 1:
			final User player = getPlayer(server, args, 0);
			if (!player.isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", player.getDisplayName()));
			}
			if (user.getWorld() != player.getWorld() && ess.getSettings().getIsWorldTeleportPermissions()
				&& !user.isAuthorized("essentials.world." + player.getWorld().getName()))
			{
				throw new Exception(_("noPerm", "essentials.world." + player.getWorld().getName()));
			}
			user.sendMessage(_("teleporting"));
			final Trade charge = new Trade(this.getName(), ess);
			charge.isAffordableFor(user);
			user.getTeleport().teleport(player, charge, TeleportCause.COMMAND);
			throw new NoChargeException();

		default:
			if (!user.isAuthorized("essentials.tp.others"))
			{
				throw new Exception(_("noPerm", "essentials.tp.others"));
			}
			user.sendMessage(_("teleporting"));
			final User target = getPlayer(server, args, 0);
			final User toPlayer = getPlayer(server, args, 1);
			target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND);
			target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()));
			break;
		}
	}
	@EventHandler(priority = EventPriority.LOWEST)
	public void onPlayerDeathEvent(final PlayerDeathEvent event)
	{
		final User user = ess.getUser(event.getEntity());
		if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back"))
		{
			user.setLastLocation();
			user.sendMessage(_("backAfterDeath"));
		}
		if (!ess.getSettings().areDeathMessagesEnabled())
		{
			event.setDeathMessage("");
		}
	}
Пример #19
0
	@Override
	public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 2)
		{
			throw new NotEnoughArgumentsException();
		}

		sender.sendMessage(_("teleporting"));
		final User target = getPlayer(server, args, 0);
		final User toPlayer = getPlayer(server, args, 1);
		target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND);
		target.sendMessage(_("teleportAtoB", Console.NAME, toPlayer.getDisplayName()));
	}
Пример #20
0
  @Override
  public void run(Server server, User user, String commandLabel, String[] args) throws Exception {
    if (args.length < 3) {
      throw new NotEnoughArgumentsException();
    }

    int x = Integer.parseInt(args[0]);
    int y = Integer.parseInt(args[1]);
    int z = Integer.parseInt(args[2]);
    Location l = new Location(user.getWorld(), x, y, z);
    Charge charge = new Charge(this.getName(), ess);
    charge.isAffordableFor(user);
    user.sendMessage(Util.i18n("teleporting"));
    user.getTeleport().teleport(l, charge);
  }
Пример #21
0
 public void payUser(final User reciever, final double value) throws Exception {
   if (value == 0) {
     return;
   }
   if (canAfford(value)) {
     setMoney(getMoney() - value);
     reciever.setMoney(reciever.getMoney() + value);
     sendMessage(
         Util.format("moneySentTo", Util.formatCurrency(value, ess), reciever.getDisplayName()));
     reciever.sendMessage(
         Util.format("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName()));
   } else {
     throw new Exception(Util.i18n("notEnoughMoney"));
   }
 }
Пример #22
0
	public static List<String> getItems(final User user, final Map<String, Object> kit) throws Exception
	{
		if (kit == null)
		{
			throw new Exception(_("kitError2"));
		}

		try
		{
			return (List<String>)kit.get("items");
		}
		catch (Exception e)
		{
			user.sendMessage(_("kitError2"));
			throw new Exception(_("kitErrorHelp"));
		}
	}
Пример #23
0
 @Override
 public void payUser(final User reciever, final BigDecimal value)
     throws ChargeException, MaxMoneyException {
   if (value.signum() == 0) {
     return;
   }
   if (canAfford(value)) {
     setMoney(getMoney().subtract(value));
     reciever.setMoney(reciever.getMoney().add(value));
     sendMessage(
         tl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName()));
     reciever.sendMessage(
         tl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName()));
   } else {
     throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(value, ess)));
   }
 }
Пример #24
0
 @Override
 public void giveMoney(final BigDecimal value, final CommandSource initiator)
     throws MaxMoneyException {
   if (value.signum() == 0) {
     return;
   }
   setMoney(getMoney().add(value));
   sendMessage(tl("addedToAccount", NumberUtil.displayCurrency(value, ess)));
   if (initiator != null) {
     initiator.sendMessage(
         tl(
             "addedToOthersAccount",
             NumberUtil.displayCurrency(value, ess),
             this.getDisplayName(),
             NumberUtil.displayCurrency(getMoney(), ess)));
   }
 }
Пример #25
0
 // Returns true if status expired during this check
 public boolean checkJailTimeout(final long currentTime) {
   if (getJailTimeout() > 0 && getJailTimeout() < currentTime && isJailed()) {
     setJailTimeout(0);
     setJailed(false);
     sendMessage(tl("haveBeenReleased"));
     setJail(null);
     try {
       getTeleport().back();
     } catch (Exception ex) {
       try {
         getTeleport().respawn(null, TeleportCause.PLUGIN);
       } catch (Exception ex1) {
       }
     }
     return true;
   }
   return false;
 }
  @Override
  public void onPlayerInteract(final PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
      return;
    }

    if (ess.getSettings().getBedSetsHome()
        && event.getClickedBlock().getType() == Material.BED_BLOCK) {
      try {
        final User user = ess.getUser(event.getPlayer());
        user.setHome();
        user.sendMessage(Util.i18n("homeSetToBed"));
      } catch (Throwable ex) {
      }
    }
  }
 @Override
 public void onPlayerChat(final PlayerChatEvent event) {
   final User user = ess.getUser(event.getPlayer());
   if (user.isMuted()) {
     event.setCancelled(true);
     user.sendMessage(Util.i18n("playerMuted"));
     LOGGER.info(Util.format("mutedUserSpeaks", user.getName()));
   }
   final Iterator<Player> it = event.getRecipients().iterator();
   while (it.hasNext()) {
     final User u = ess.getUser(it.next());
     if (u.isIgnoredPlayer(user.getName())) {
       it.remove();
     }
   }
   user.updateActivity(true);
   if (ess.getSettings().changeDisplayName()) {
     user.setDisplayName(user.getNick());
   }
 }
Пример #28
0
	@Override
	public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		// Which World(s) are we interested in?
		String worldSelector = null;
		if (args.length == 2)
		{
			worldSelector = args[1];
		}
		final Set<World> worlds = getWorlds(server, sender, worldSelector);

		// If no arguments we are reading the time
		if (args.length == 0)
		{
			getWorldsTime(sender, worlds);
			return;
		}

		final User user = ess.getUser(sender);
		if (user != null && !user.isAuthorized("essentials.time.set"))
		{
			user.sendMessage(_("timeSetPermission"));
			return;
		}

		// Parse the target time int ticks from args[0]
		long ticks;
		try
		{
			ticks = DescParseTickFormat.parse(args[0]);
		}
		catch (NumberFormatException e)
		{
			throw new NotEnoughArgumentsException();
		}

		setWorldsTime(sender, worlds, ticks);
	}
Пример #29
0
 @Override
 public void alert(final User user, final String item, final String type) {
   final Location loc = user.getLocation();
   final String warnMessage =
       Util.format(
           "alertFormat",
           user.getName(),
           type,
           item,
           loc.getWorld().getName()
               + ","
               + loc.getBlockX()
               + ","
               + loc.getBlockY()
               + ","
               + loc.getBlockZ());
   LOGGER.log(Level.WARNING, warnMessage);
   for (Player p : this.getServer().getOnlinePlayers()) {
     final User alertUser = ess.getUser(p);
     if (alertUser.isAuthorized("essentials.protect.alerts")) {
       alertUser.sendMessage(warnMessage);
     }
   }
 }
Пример #30
0
 @Override
 public void takeMoney(final BigDecimal value, final CommandSource initiator) {
   if (value.signum() == 0) {
     return;
   }
   try {
     setMoney(getMoney().subtract(value));
   } catch (MaxMoneyException ex) {
     ess.getLogger()
         .log(
             Level.WARNING,
             "Invalid call to takeMoney, total balance can't be more than the max-money limit.",
             ex);
   }
   sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess)));
   if (initiator != null) {
     initiator.sendMessage(
         tl(
             "takenFromOthersAccount",
             NumberUtil.displayCurrency(value, ess),
             this.getDisplayName(),
             NumberUtil.displayCurrency(getMoney(), ess)));
   }
 }