use of org.enginehub.piston.inject.InjectedValueStore in project FastAsyncWorldEdit by IntellectualSites.
the class BukkitCommandInspector method testPermission.
@Override
public boolean testPermission(CommandSender sender, Command command) {
Optional<org.enginehub.piston.Command> mapping = dispatcher.getCommand(command.getName());
if (mapping.isPresent()) {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> Optional.of(plugin.wrapCommandSender(sender)));
return mapping.get().getCondition().satisfied(store);
} else {
LOGGER.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return false;
}
}
use of org.enginehub.piston.inject.InjectedValueStore in project FastAsyncWorldEdit by IntellectualSites.
the class PlatformCommandManager method initializeInjectedValues.
// FAWE end
// FAWE start - Event & suggestions, make method public
public MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor, Event event, boolean isSuggestions) {
// FAWE end
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
if (actor instanceof Player) {
store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor));
} else {
store.injectValue(Key.of(Player.class), context -> {
throw new CommandException(Caption.of("worldedit.command.player-only"), ImmutableList.of());
});
}
store.injectValue(Key.of(Arguments.class), ValueProvider.constant(arguments));
store.injectValue(Key.of(LocalSession.class), context -> {
LocalSession localSession = worldEdit.getSessionManager().get(actor);
localSession.tellVersion(actor);
return Optional.of(localSession);
});
store.injectValue(Key.of(boolean.class), context -> Optional.of(isSuggestions));
store.injectValue(Key.of(InjectedValueStore.class), ValueProvider.constant(store));
store.injectValue(Key.of(Event.class), ValueProvider.constant(event));
// FAWE start - allow giving editsessions
if (event instanceof CommandEvent) {
EditSession session = ((CommandEvent) event).getSession();
if (session != null) {
store.injectValue(Key.of(EditSession.class), context -> Optional.of(session));
}
}
// FAWE end
return MemoizingValueAccess.wrap(MergedValueAccess.of(store, globalInjectedValues));
}
use of org.enginehub.piston.inject.InjectedValueStore in project FastAsyncWorldEdit by IntellectualSites.
the class WorldEditListener method onPlayerCommandSend.
// FAWE end
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandSend(PlayerCommandSendEvent event) {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> Optional.of(plugin.wrapCommandSender(event.getPlayer())));
CommandManager commandManager = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().getCommandManager();
event.getCommands().removeIf(name -> commandManager.getCommand(name).filter(command -> !command.getCondition().satisfied(store)).isPresent());
}
use of org.enginehub.piston.inject.InjectedValueStore in project FastAsyncWorldEdit by IntellectualSites.
the class MethodInjector method beforeCall.
@Override
public void beforeCall(Method commandMethod, CommandParameters parameters) {
InjectedValueStore store = parameters.injectedValue(Key.of(InjectedValueStore.class)).get();
store.injectValue(Key.of(Method.class), ValueProvider.constant(commandMethod));
}
use of org.enginehub.piston.inject.InjectedValueStore in project FastAsyncWorldEdit by IntellectualSites.
the class PrintCommandHelp method printCommands.
private static void printCommands(int page, Stream<Command> commandStream, Actor actor, List<Command> commandList, String helpRootCommand) throws InvalidComponentException {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> Optional.of(actor));
// Get a list of aliases
List<Command> commands = commandStream.filter(command -> command.getCondition().satisfied(store)).sorted(byCleanName()).collect(toList());
String used = commandList.isEmpty() ? null : toCommandString(commandList);
CommandListBox box = new CommandListBox((used == null ? "Help" : "Subcommands: " + used), helpRootCommand + " -s -p %page%" + (used == null ? "" : " " + used), helpRootCommand);
if (!actor.isPlayer()) {
box.formatForConsole();
}
for (Command mapping : commands) {
String alias = (commandList.isEmpty() ? "/" : "") + mapping.getName();
String command = Stream.concat(commandList.stream(), Stream.of(mapping)).map(Command::getName).collect(Collectors.joining(" ", "/", ""));
box.appendCommand(alias, mapping.getDescription(), command);
}
actor.print(box.create(page));
}
Aggregations