• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    Java
  • License
    GNU Lesser Genera...
  • Created about 10 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

IoC-oriented Java command parsing library

Intake

Intake is a IoC-oriented command parsing library.

Consider the following command:

/body settype pluto dwarfplanet

Consider a theoretical Body class and CelestialType enum in the project. The command above presumably would execute the following code:

pluto.setType(CelestialType.DWARF_PLANET);

Rather than write argument parsing code in the routine for that command, it'd be simpler to simply request a Body and a CelestialType from the user, so it'd be possible to write the command like so:

void setType(Body body, CelestialType type) {
	body.setType(type);
}

The purpose of Intake is to make that possible.

Overview

Intake consists of four parts:

Command Framework

The command framework consists of some basic interfaces and classes:

  • Commands are modeled by CommandCallable
  • Groups of sub-commands are modeled by Dispatcher
  • Descriptions of commands are modeled by Description
  • Individual parameters (for introspection) are modeled by Parameter
  • Commands that can suggest completions are modeled by CommandCompleter
  • Arguments (accessed as a stack) are represented by CommandArgs

There is also support for:

  • Boolean single-character flags (/command -f)
  • Value flags (/command -v value)
  • Testing whether a user has permission to execute a command

The goal of the framework is to provide a compromise between a heavily-opinionated framework and a flexible one.

Parameter Injection

The parameter injection framework provides IoC-oriented argument parsing and completion.

Raw use of the injection framework can be best seen in an example:

Injector injector = Intake.createInjector();
injector.install(new PrimitivesModule());
injector.install(new UniverseModule());

Builder argParserBuilder = new Builder(injector);
argParserBuilder.addParameter(Body.class);
argParserBuilder.addParameter(CelestialType.class);

ArgumentParser parser = argParserBuilder.build();
parser.parseArguments(Arguments.of("pluto", "dwarfplanet")));

ArgumentParser finds "providers" for the Body and CelestialType Java types, which are then later utilized to create object instances from the provided arguments.

UniverseModule might look like this:

public class UniverseModule extends AbstractModule {

    private final Universe universe;

    public UniverseModule(Universe universe) {
        this.universe = universe;
    }

    @Override
    protected void configure() {
        bind(Universe.class).toInstance(universe);
        bind(Body.class).toProvider(new BodyProvider(universe));
        bind(CelestialType.class).toProvider(
				new EnumProvider<CelestialType>(CelestialType.class));
    }

}

The parameter injection framework has strong similarity to Google Guice's API.

Parametric Commands

The parametric command framework provides an opinionated method of defining commands using classes:

public class UniverseCommands {

    @Command(aliases = "settype", desc = "Set the type of an object")
    public void setType(Body body, CelestialType type) {
        body.setType(type);
    }

}

It makes use of the parameter injection framework.

Fluent API

There is also a fluent API that combines the command framework with the parametric command framework.

Examples

To see some example code, check out the example projects.

Usage

There are two major versions of Intake:

  • 3.x (available via Git tags)
  • 4.x (in the master branch)

There was a major overhaul in 4.0 to decompule the IoC portion from the parametric binding. Previously they were an inseperable couple.

The documentation in the wiki is for 3.x. The examples in this README are for 4.x.

Resolution

Currently, Intake is available in sk89q's Maven repository:

<repositories>
  <repository>
    <id>maven.enginehub.org</id>
    <url>https://maven.enginehub.org/repo/</url>
  </repository>
</repositories>

or for Gradle users:

repositories {
    maven { url "https://maven.enginehub.org/repo/" }
}

Depending on whether you want to use 3.x (3.1.2 is recommended) or 4.x, the Maven group ID will vary:

  • 3.1.2:
    • Group ID: com.sk89q
    • Artifact ID: intake
    • Version: 3.1.2
  • 4.0:
    • Group ID: com.sk89q.intake
    • Artifact ID: intake
    • Version: 4.0-SNAPSHOT

Note: The API is subject to change in snapshot builds.

Migration

If you are coming from the command framework that was used in WorldEdit since 2010, then there have been many changes.

If you are moving from 3.x to 4.x, then the changes have not been too major (except for registering bindings). Some classes were moved around or renamed.

Documentation

If you are using 3.x, find work-in-progress documentation at https://github.com/sk89q/Intake/wiki

However, if you are using 4.x, you are better looking at examples found in the repository.

Compiling

Use Gradle to compile Intake.

If you are on Linux or Mac OS X, run the following in your terminal:

./gradlew clean build

If you are on Windows, run the following in your command prompt:

gradlew clean build

Contributing

Intake is available under the GNU Lesser General Public License.

We happily accept contributions, especially through pull requests on GitHub.

Links

More Repositories

1

WorldEdit

πŸ—ΊοΈ Minecraft map editor and mod
Java
3,083
star
2

WorldGuard

πŸ›‘οΈ Protect your Minecraft server and lets players claim areas
Java
826
star
3

CraftBook

πŸ”§ Machines, ICs, PLCs, and more!
Java
301
star
4

CommandBook

General and administrative commands
Java
145
star
5

CommandHelper

Rapid scripting and command aliases for Minecraft owners
Java
120
star
6

SchematicWebViewer

An NPM package to facilitate importing and viewing of modern Minecraft schematics.
TypeScript
62
star
7

SquirrelID

Mojang profile / UUID lookup and last known UUID -> name cache Java library
Java
53
star
8

Piston

A generic command system, with tie-ins to many Minecraft platforms such as Bukkit, Forge, and Sponge.
Java
17
star
9

SchematicJS

A TypeScript/JavaScript library for loading and saving WorldEdit schematics.
TypeScript
15
star
10

PRTree

PRTree library from http://www.khelekore.org/prtree/index.shtml
Java
14
star
11

worldedit-adapters

CBukkit & Spigot bindings for WE
Java
14
star
12

libcomponents

A component system currently used in CommandBook.
Java
14
star
13

CraftAPI

XML-RPC interface for hMod with support for streaming APIs
Java
10
star
14

WorldGourd

πŸ›‘οΈ Protect your Minecraft gourds
Java
9
star
15

Precogs

Precogs - A Bukkit/Sponge AntiCheat service API, allowing plugins to easily support multiple AntiCheats
Java
9
star
16

MinerHat

Protocol analysis and proxy for Minecraft
Java
8
star
17

JingleNote

NoteBlock sequencer for Minecraft, accepting MIDI, Strings, and more!
Java
4
star
18

CraftBookNMS

NMS Extensions for CraftBook
Java
3
star
19

worldedit-ref

Source to the WE reference PDF
3
star
20

WorldEditDocs

User docs for https://github.com/EngineHub/WorldEdit
Python
3
star
21

wg-regions-six2five

Downgrade WG 6 regions.yml to a WG 5 regions.yml
Java
3
star
22

CraftBookDocs

Python
2
star
23

ForgeUtils

Replaced by EngineHub/MCUtils
Java
2
star
24

permscompat

Legacy compatibility library for WEPIF
Java
2
star
25

enginehub-website

A monorepo containing all of the EngineHub-related websites.
TypeScript
2
star
26

lin-bus

A simple and concise library for reading, writing, and working with the Named Binary Tag format.
Java
2
star
27

EngineHub-Bot

EngineHub Bot - Discord bot to make software support slightly more tolerable
Java
1
star
28

gradle-codecov-plugin

Kotlin
1
star
29

MCUtils

Replacement library for ForgeUtils. Runs in an IDE and currently uses the magic of Fabric
Java
1
star
30

remote-glovebox

An open-source javadoc.io-alike.
Kotlin
1
star
31

WorldEditVisualizer

Java
1
star