Example #1
0
	@Override
	public void run()
	{
		if (!active.compareAndSet(false, true))
		{
			return;
		}

		final ISettings settings = ess.getSettings();

		final net.ess3.settings.Backup backupSettings = settings.getData().getGeneral().getBackup();

		String backupCommand = backupSettings.getCommand() == null || backupSettings.getCommand().isEmpty() ? ("NORUN") : backupSettings.getCommand();
		
		/*if (backupCommand.equals("NORUN")) { TODO: Un-comment if you do not want commands to be run if there is no backup command
			return;
		}*/

		ess.getLogger().log(Level.INFO, _("backupStarted"));

		if (!backupSettings.getCommandsBeforeBackup().isEmpty())
		{
			final CommandSender consoleSender = server.getConsoleSender();
			for (String command : backupSettings.getCommandsBeforeBackup())
			{
				server.dispatchCommand(consoleSender, command);
			}
		}

		ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(backupCommand));
	}
Example #2
0
	@Override
	public final void startTask()
	{
		if (running.compareAndSet(false, true))
		{
			final ISettings settings = ess.getSettings();
			final long interval = settings.getData().getGeneral().getBackup().getInterval() * 1200; // minutes -> ticks
			if (interval < 1200)
			{
				running.set(false);
				return;
			}
			taskId = ess.getPlugin().scheduleSyncRepeatingTask(this, interval, interval);
		}
	}
	@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
	public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event)
	{

		final IUser user = userMap.getUser(event.getPlayer());
		if (user.getData().hasUnlimited(event.getBucket()))
		{
			event.getItemStack().setType(event.getBucket());
			ess.getPlugin().scheduleSyncDelayedTask(
					new Runnable()
					{
						@Override
						public void run()
						{
							user.getPlayer().updateInventory();
						}
					});
		}
	}
	private boolean usePowertools(final IUser user)
	{
		final ItemStack is = user.getPlayer().getItemInHand();
		if (is == null || is.getTypeId() == 0)
		{
			return false;
		}

		final List<String> commandList = user.getData().getPowertool(is.getType());
		if (commandList == null || commandList.isEmpty())
		{
			return false;
		}
		boolean used = false;
		// We need to loop through each command and execute
		for (final String command : commandList)
		{
			if (command.matches(".*\\{player\\}.*"))
			{
				//user.sendMessage("Click a player to use this command");
			}
			else if (command.startsWith("c:"))
			{
				used = true;
				user.getPlayer().chat(command.substring(2));
			}
			else
			{
				used = true;
				ess.getPlugin().scheduleSyncDelayedTask(
						new Runnable()
						{
							@Override
							public void run()
							{
								user.getServer().dispatchCommand(user.getPlayer(), command);
							}
						});
			}
		}
		return used;
	}
Example #5
0
	@Override
	public void run()
	{
		if (!active.compareAndSet(false, true))
		{
			return;
		}
		@Cleanup
		final ISettings settings = ess.getSettings();
		settings.acquireReadLock();
		final String command = settings.getData().getGeneral().getBackup().getCommand();
		if (command == null || command.isEmpty())
		{
			return;
		}
		ess.getLogger().log(Level.INFO, _("backupStarted"));
		final CommandSender consoleSender = server.getConsoleSender();
		server.dispatchCommand(consoleSender, "save-all");
		server.dispatchCommand(consoleSender, "save-off");

		ess.getPlugin().scheduleAsyncDelayedTask(new BackupRunner(command));
	}
	public void delayedJoin(final Player player)
	{
		if (!player.isOnline())
		{
			return;
		}
		ess.getBackup().startTask();
		final IUser user = userMap.getUser(player);
		user.setDisplayNick();
		user.updateCompass();
		user.getData().setTimestamp(TimestampType.LOGIN, System.currentTimeMillis());
		user.updateActivity(false);

		if (!ess.getVanishedPlayers().isEmpty() && !Permissions.VANISH_SEE_OTHERS.isAuthorized(user))
		{
			for (String p : ess.getVanishedPlayers())
			{
				final Player toVanish = userMap.getUser(p).getPlayer();
				if (toVanish.isOnline())
				{
					user.setVanished(true);
				}
			}
		}

		if (Permissions.SLEEPINGIGNORED.isAuthorized(user))
		{
			ess.getPlugin().scheduleSyncDelayedTask(
					new Runnable()
					{
						@Override
						public void run()
						{
							user.getPlayer().setSleepingIgnored(true);
						}
					});
		}

		final Commands settings = ess.getSettings().getData().getCommands();

		if (!settings.isDisabled("motd") && Permissions.MOTD.isAuthorized(user))
		{
			try
			{
				final IText input = new TextInput(user, "motd", true, ess);
				final IText output = new KeywordReplacer(input, user, ess);
				final TextPager pager = new TextPager(output, true);
				pager.showPage("1", null, "motd", user);
			}
			catch (IOException ex)
			{
				if (ess.getSettings().isDebug())
				{
					ess.getLogger().log(Level.WARNING, ex.getMessage(), ex);
				}
				else
				{
					ess.getLogger().log(Level.WARNING, ex.getMessage());
				}
			}
		}

		if (!settings.isDisabled("mail") && Permissions.MAIL.isAuthorized(user))
		{
			final List<String> mail = user.getMails();
			if (mail.isEmpty())
			{
				final String msg = _("§6You have no new mail.");
				if (!msg.isEmpty())
				{
					user.sendMessage(msg);
				}
			}
			else
			{
				user.sendMessage(_("§6You have§c {0} §6messages! Type §c/mail read§6 to view your mail.", mail.size()));
			}
		}
		if (Permissions.FLY_SAFELOGIN.isAuthorized(user))
		{
			final Location loc = user.getPlayer().getLocation();
			final World world = loc.getWorld();
			final int x = loc.getBlockX();
			int y = loc.getBlockY();
			final int z = loc.getBlockZ();
			while (LocationUtil.isBlockUnsafe(world, x, y, z) && y > -1)
			{
				y--;
			}

			if (loc.getBlockY() - y > 1 || y < 0)
			{
				user.getPlayer().setAllowFlight(true);
				user.getPlayer().setFlying(true);
				user.sendMessage(_("§6Set fly mode§c {0} §6for {1}§6.", _("enabled"), user.getPlayer().getDisplayName()));
			}
		}
	}
	@EventHandler(priority = EventPriority.MONITOR)
	public void onPlayerJoin(final PlayerJoinEvent event)
	{
		ess.getPlugin().runTaskAsynchronously(
				new Runnable()
				{
					@Override
					public void run()
					{
						delayedJoin(event.getPlayer());
					}
				});
		/* TODO: Make sure my update is good
		 if (!event.getPlayer().isOnline())
		 {
		 return;
		 }

		 ess.getBackup().startTask();

		 final String joinMessage = ess.getSettings().getData().getGeneral().getJoinMessage();
		 if (joinMessage != null)
		 {
		 final IText itOutput = new KeywordReplacer(new SimpleTextInput(joinMessage), ess.getUserMap().getUser(event.getPlayer()), ess);
		 final SimpleTextPager stPager = new SimpleTextPager(itOutput);
		 event.setJoinMessage(FormatUtil.replaceFormat(stPager.getString(0)));
		 }
		 else
		 {
		 event.setJoinMessage(joinMessage);
		 }

		 final IUser user = ess.getUserMap().getUser(event.getPlayer());

		 user.updateDisplayName();
		 user.getData().setIpAddress(user.getPlayer().getAddress().getAddress().getHostAddress());
		 user.updateActivity(false);

		 for (String p : ess.getVanishedPlayers())
		 {
		 if (!Permissions.VANISH_SEE_OTHERS.isAuthorized(user))
		 {
		 user.getPlayer().hidePlayer(ess.getUserMap().getUser(p).getPlayer());
		 }
		 }

		 if (Permissions.SLEEPINGIGNORED.isAuthorized(user))
		 {
		 user.getPlayer().setSleepingIgnored(true);
		 }
		 user.queueSave();


		 final ISettings settings = ess.getSettings();

		 if (!settings.getData().getCommands().isDisabled("motd") && Permissions.MOTD.isAuthorized(user))
		 {
		 try
		 {
		 final IText input = new TextInput(user, "motd", true, ess);
		 final IText output = new KeywordReplacer(input, user, ess);
		 final TextPager pager = new TextPager(output, true);
		 pager.showPage("1", null, "motd", user);
		 }
		 catch (IOException ex)
		 {
		 if (settings.getData().getGeneral().isDebug())
		 {
		 LOGGER.log(Level.WARNING, ex.getMessage(), ex);
		 }
		 else
		 {
		 LOGGER.log(Level.WARNING, ex.getMessage());
		 }
		 }
		 }

		 if (!settings.getData().getCommands().isDisabled("mail") && Permissions.MAIL.isAuthorized(user))
		 {
		 final List<String> mail = user.getData().getMails();
		 if (mail == null || mail.isEmpty())
		 {
		 user.sendMessage(_("§6You have no new mail."));
		 }
		 else
		 {
		 user.sendMessage(_("§6You have§c {0} §6messages! Type §c/mail read§6 to view your mail.", mail.size()));
		 }
		 }*/
	}