DoubleCheck Plugin: Unified Action Confirmation

My newest project is called DoubleCheck. It’s a simple service plugin that provides a simple API for other plugins.

Motivation

There are many commands and actions that should be confirmed before the execution, for example a world deletion command, a money transfer, a ban command, or when you enter a PvP world.

Every plugin has it’s own command for this. The results are long command names and name conflicts.
It’s also really boring to develop something like this :wink:

DoubleCheck solves the problem with a unified action confirmation service. Plugins can easily use this service to send confirmation requests like this:

Are you sure that you want to send 2.000.000.000$ to Notch?
Please /confirm or /deny this action.

How it works

First of all, you have to build a class that implements the Request interface:

Now, you can send requests:

ConfirmationService service = game.getServiceManager().provideUnchecked(ConfirmationService.class);

service.send(new TeleportRequest(fromPlayer, toPlayer, 30 /*seconds*/));

This is what the player gets:

boformer requested a teleport to you.
Please /confirm or /deny this action.

Configuration

The server admin will be able to change the command aliases (e.g confirm, ok, yes or deny, cancel, no) and all of the messages (and colors). Some examples:

Please confirm with /yes or cancel with /no

Are you sure? Confirm with /ok or deny with /cancel

Use this in your plugin!

Right now the plugin has to be installed on the Sponge server, so your plugins depend on it.
I will work on a version that can be bundled with your plugin.
To make sure that your plugin works even without DoubleCheck, use this fallback:

ConfirmationService service = game.getServiceManager().provide(ConfirmationService.class).orNull();
    
Request myRequest = new TeleportRequest(fromPlayer, toPlayer, 30 /*seconds*/)
    
if(service != null) service.send(myRequest);
else myRequest.confirm(); //just skips confirmation if DoubleCheck not installed

Source and Contributing

Right now some things are still missing (look at the TODO markings). Pull Requests are welcome!

GitHub Repository: GitHub - boformer/DoubleCheck: Action Confirmation Library for Sponge Plugins

6 Likes

Interesting. I will have to see where this goes.

1 Like

Added Usage section…

This seems useful.

2 Likes

It would be a good thing to have for some commands on the server. It would be kind of like the LogBlock questioner plugin, but more global(not just for that plugin.).

It is possible to develop “extensions” for existing plugins.

You can listen for a command call and cancel it, then send the confirmation request, and execute the command when the player enters /confirm.

A side note: With the new chat actions, the player can also click on the Confirm text :wink:

This looks cool :smiley:

Adding GUI would make this more useful.

1 Like

Tell me how to add a GUI with Vanilla Minecraft methods.
The only “GUI” I can imagine is the Title API:

Updated the source. Right now I’m trying to understand @zml’s config lib :frowning:

The getMessages() method was replaced with getMessage() for 2 reasons:

  • Arrays are mutable
  • Message supports multi-line with \n

Right now I am refactoring the project. It will become a library (so no separate plugin is required).

The lib branch on GitHub: https://github.com/boformer/DoubleCheck/tree/lib

The way to create a request also changed:

package example.request;

import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.util.command.CommandSource;

import com.github.boformer.doublecheck.Request;

public class TeleportRequest implements Request
{
	private final Player fromPlayer;
	
	public TeleportRequest(Player fromPlayer) 
	{
		this.fromPlayer = fromPlayer;
	}

	@Override
	public Text getMessage() 
	{
		return Texts.of(fromPlayer.getName() + " requested a teleport to you.");
	}

	@Override
	public void confirm(CommandSource recipient) 
	{
		recipient.sendMessage( Texts.of("You confirmed the teleport request") );
		
		fromPlayer.sendMessage( Texts.of("Teleporting...") );
		fromPlayer.setLocation( ((Player) recipient).getLocation() );
	}

	@Override
	public void deny(CommandSource recipient) 
	{
		recipient.sendMessage( Texts.of("You denied the teleport request") );
		
		fromPlayer.sendMessage( Texts.of("Teleport request denied by " + recipient.getName() + "!") );
	}
}

To send the request:

ConfirmationService service = DoubleCheck.initializeService(game, plugin);

Request myRequest = new TeleportRequest(notchPlayer, jebPlayer)
    
service.send(jebPlayer, myRequest);

Result (sent to Jeb):

Notch requested a teleport to you.
You have 15 seconds to /confirm or /deny the action.

I updated the GitHub repo, added a bit of documentation and a maven repository: