Giter VIP home page Giter VIP logo

commandcreator's Introduction

CommandCreator

Creating commands in BungeeCord and Bukkit never was this simple!

With CommandCreator, you can create custom commands for your Bukkit server, or your BungeeCord proxy.

Demonstration

List of features:

  • Tab completion
  • Custom help messages
  • Dispatch command to your methods
  • All messages are configurables
  • Player-only commands (And Console-only commands)
  • Custom argument parsing
  • Default argument parsing (All primitives, Player, CommandSender, OfflinePlayer)
  • Optional arguments
  • 'Array as last argument'
  • Choice lists (enum)
  • Per-argument description, type, name
  • Source code fully (yes, fully) documented
  • Command compounds

Exemple:

@Command("myTestCommand") //-- Usage: /myTestCommand <name|testCompound> ...
public final class MyTestCommand
{
	@Command(value = "name", description = "Description!", aliases = {"tp"})
	//-- Usage: /myTestCommand name {index} {player} [index2] [action]
	public static void test1(CommandSender sender, //Sender of the command
	                         @Arg("index") int i1, //Primitive serialization
	                         @Arg(value = "player", desc = "Awesome!") Player player, //Default serialization
	                         @Opt @Arg("index2") Integer i2, //@Opt = Optional
	                         @Opt @Arg("action") Action choice) //Enum choice list
	{/* Whatever */}


	@Command(aliases = {"testcmp"}) //-- Usage: /myTestCommand testCompound <subCommand|whisper> ...
	public static final class TestCompound
	{
		@Command //-- Usage: /myTestCommand testCompound subCommand {uuid}
		public static void subCommand(Player sender, //Only player can send messages
		                              @Arg("uuid") @Serial(MyObjectSerializer.class) UUID uuid) //Custom serialization
		{/* Whatever */}

		@Command
		public static void whisper(CommandSender sender,
		                           @Arg("receiver") Player receiver,
		                           @Arg("message") String... message) //Array as last argument
		{receiver.sendMessage(String.join(" ", message));}
	}

	// +-----------------+

	public enum Action //Custom choice list
	{
		CHOICE_1("choice1"),
		CHOICE_2("choice2"),
		CHOICE_3("choice3");

		private final String name;

		Action(String name) {this.name = name;}

		@Override
		public String toString() {return name;}
	}

	public static class MyObjectSerializer implements CommandSerializer<UUID> //Custom serializer
	{
		@Override
		public UUID serialize(String arg) throws CommandSerializationException
		{
			try {return UUID.fromString(arg);}
			catch (IllegalArgumentException ignored) {throw new CommandSerializationException("Invalid UUID");}
		}

		@Override
		public String valueType() {return "UUID";}
	}
}

Register command:

CommandCreator.registerCommands(MyTestCommand.class, plugin);

You can find a full demonstration here and here.


As I suck at creating neat colored text, I would love your contribution for the default configuration.

I don't think this color config is really great right now, but everything you see is configurable.

  • Root command:

Root command

  • Simple command:

Simple command

  • Simple compound:

Simple compound

Configuration

Here is the default configuration at ./plugins/CommandCreator/messages.yml in your server.

helpHeader: '§cUsage: §7/%1s'
helpEntry: '§c- §7%1s'
optional: '§e§oOptional'
simpleUsageCompound: '<%1s>'
simpleUsageRequired: '{%1s}'
simpleUsageOptional: '[%1s]'
compoundSuffix: '...'
separator: '|'
descriptionSeparator: ' - '
serializerNames:
  string: 'String'
  boolean: 'boolean'
  character: 'char'
  byte: 'byte'
  short: 'short'
  integer: 'int'
  long: 'long'
  float: 'float'
  double: 'double'
  player: 'Player'
  offlinePlayer: 'Offline Player'
  commandSender: 'Command Sender'
invalidSenderTypeMessage: '§cYou cannot execute this command as a %1s.'
noPermissionMessage: '§cYou do not have the permission to use this command.'
serializationError: '§c%s'
senderTypes:
  player: 'Player'
  console: 'Console'
  all: 'All'
  unknown: 'Unknown'

Installation

Plugin

To install CommandCreator on your server/proxy, you need to download a release.

Compatibility:

  • Bukkit
  • BungeeCord

[Latest release]

API

The API for Bukkit and BungeeCord is the same.

To add the CommandCreator API to your plugin, use this dependency:

Maven:

  • In repositories:
<repository>
  <id>skybeast-repo</id>
  <url>https://dl.bintray.com/skybeastmc/maven</url>
</repository>
  • In dependencies:
<dependency>
  <groupId>fr.skybeast</groupId>
  <artifactId>commandcreator-api</artifactId>
  <version>1.2</version>
</dependency>

Gradle:

  • In repositories:
maven {
    name = 'skybeast-repo'
    url = 'https://dl.bintray.com/skybeastmc/maven'
}
  • In dependencies:
compile 'fr.skybeast:commandcreator-api:1.2'

commandcreator's People

Contributors

cchudant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

commandcreator's Issues

Multiple command with single label

I though of a feature to create multiple commands with a single label like this:

	@Command
	public static void teleport(CommandSender sender,
	                            Player player,
	                            Player anotherPlayer)
	{/* Whatever */}

	@Command
	public static void teleport(CommandSender sender,
	                            Player player,
	                            double x, double y, double z)
	{/* Whatever */}

It would be nice to have that.
But I have no idea how to implement it on existing code.

Any contribution would be appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.