Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save Romain-P/f80c97884867083594f6 to your computer and use it in GitHub Desktop.
ça reste correcte niveau verbose comme ça
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.CommandBuilder;
import org.heat.world.commands.builder.CommandProvider;
import org.heat.world.commands.impl.SimpleCommandManager;
import org.heat.world.commands.impl.actions.HelpAction;
import org.heat.world.commands.impl.conditions.StaffAccess;
import java.util.function.Consumer;
/**
* Managed by romain on 08/03/2015.
*/
public class StdCommandsModule extends AbstractModule{
private MapBinder<String, CommandTree> commands;
private MapBinder<Class, CommandCond> conditions;
@Override
protected void configure() {
bind(CommandManager.class).to(SimpleCommandManager.class).asEagerSingleton();
commands = MapBinder.newMapBinder(binder(), String.class, CommandTree.class);
conditions = MapBinder.newMapBinder(binder(), Class.class, CommandCond.class);
loadConditions();
createCommands();
}
private void createCommands() {
createNewCommand("help", (command) -> command
.to(HelpAction.class)
.withArg("command"));
}
private void loadConditions() {
loadNewCondition(StaffAccess.class);
}
private CommandTree createNewCommand(String name, Consumer<CommandBuilder> consumer) {
CommandTree command = CommandProvider.create(name, consumer);
commands.addBinding(name).toInstance(command);
return command;
}
private void loadNewCondition(Class<? extends CommandCond> condClass) {
conditions.addBinding(condClass).to(condClass);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment