Skip to content

Instantly share code, notes, and snippets.

@Dykam
Created September 4, 2011 22:06
Show Gist options
  • Save Dykam/1193595 to your computer and use it in GitHub Desktop.
Save Dykam/1193595 to your computer and use it in GitHub Desktop.
[SpoutCraft] Proposal for centralized input

#The problem Currently plugins are supposed to listen to input using the InputManager. There are three issues to this.

  • Binding conflicts. Plugins might use the same key. This is mostly an issue with the tab and ctrl keys.
  • Rebinding confusion. Each plugin, if it is configurable, defines its own way of redefining keybindings. This is confusing.
  • By default all presses are mapped, including when for example chat is open.

#The solution Let plugins define keybindings by means of a simple string as key. Conflicts between plugins are solved because the plugin is part of the key. Client side the user can set the keybinding to an actual key, which is defaulted to a configurable default. The client side part is done by SpoutCraft, possibly by modifying the keybindings screen to add plugin keybindings. Here's the code the plugin has to use:

plugin.yml

The keybindings are a bit like the commands node, but now for keybindings.

Usual stuff

spout:
  keybindings:
    launch:
      description: Launches the focused player in the air.
      default: l
    burn:
      description: Sets the focused player on fire.
      default: b

The same, but from code:

SpoutManger.InputManager.set(this, "launch", "Launches the focused player in the air.", "l");
SpoutManger.InputManager.set(this, "burn", "Sets the focused player on fire.", "b");

The actual usage:

pm.registerEvent(Event.Type.CUSTOM_EVENT, new InputListener() {
	@Override
	public void onInputDown(PlayerJoinEvent event) {
		SpoutPlayer player = SpoutManager.getPlayer(event.getPlayer());
		if(event.getInput().equals("burn") && event.getPlugin() == this)
		// set player on fire
	}
}, Priority.Normal, this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment