Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created March 15, 2015 17:07
Show Gist options
  • Select an option

  • Save Romain-P/ccb278021d399e159883 to your computer and use it in GitHub Desktop.

Select an option

Save Romain-P/ccb278021d399e159883 to your computer and use it in GitHub Desktop.
package org.heat.world;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.MapBinder;
import org.heat.world.commands.CommandCond;
import org.heat.world.commands.CommandManager;
import org.heat.world.commands.CommandTree;
import org.heat.world.commands.builder.CommandProvider;
import org.heat.world.commands.impl.SimpleCommandManager;
import org.heat.world.commands.impl.actions.HelloAction;
import org.heat.world.commands.impl.actions.HelloFckAction;
import org.heat.world.commands.impl.conditions.StaffCondition;
/**
* Managed by romain on 08/03/2015.
*/
public class StdCommandsModule extends AbstractModule{
@Override
protected void configure() {
bind(CommandManager.class).to(SimpleCommandManager.class).asEagerSingleton();
MapBinder<Class, CommandCond> conditions = MapBinder.newMapBinder(binder(), Class.class, CommandCond.class);
conditions.addBinding(StaffCondition.class).to(StaffCondition.class);
MapBinder<String, CommandTree> commands = MapBinder.newMapBinder(binder(), String.class, CommandTree.class);
commands.addBinding("hello")
.toInstance(CommandProvider.create("hello", (builder) -> builder
.to(HelloAction.class)
.iff(StaffCondition.class)
.withSub("heykaka", (c) -> c.to(HelloAction.class))
.withSub("fuckoff", (c) -> c
.to(HelloFckAction.class)
.withRequiredArg("tosend")
.withArg("caca", "on", "off")
.withSpacedArg("msg"))
.withAlias("jajaja")));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment