use of com.sk89q.worldedit.event.platform.CommandEvent in project FastAsyncWorldEdit by IntellectualSites.
the class ToolUtilCommands method secondary.
@Command(name = "secondary", aliases = { "/secondary" }, desc = "Set the left click brush", descFooter = "Set the left click brush")
@CommandPermissions("worldedit.brush.secondary")
public void secondary(Player player, LocalSession session, @Arg(desc = "The brush command", variable = true) List<String> commandStr) throws WorldEditException {
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
BrushTool tool = session.getBrushTool(player, false);
session.setTool(item, null, player);
String cmd = "brush " + StringMan.join(commandStr, " ");
CommandEvent event = new CommandEvent(player, cmd);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
BrushTool newTool = session.getBrushTool(item, player, false);
if (newTool != null && tool != null) {
newTool.setPrimary(tool.getPrimary());
}
}
use of com.sk89q.worldedit.event.platform.CommandEvent 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 com.sk89q.worldedit.event.platform.CommandEvent in project FastAsyncWorldEdit by IntellectualSites.
the class CLIWorldEdit method run.
public void run(InputStream inputStream) {
try (Scanner scanner = new Scanner(inputStream)) {
while (true) {
System.err.print("> ");
if (!scanner.hasNextLine()) {
break;
}
String line = scanner.nextLine();
if (line.isEmpty()) {
continue;
}
if (line.equals("stop")) {
commandSender.print(Caption.of("worldedit.cli.stopping"));
break;
}
CommandEvent event = new CommandEvent(commandSender, line);
WorldEdit.getInstance().getEventBus().post(event);
if (!event.isCancelled()) {
commandSender.print(Caption.of("worldedit.cli.unknown-command"));
} else {
saveAllWorlds(false);
}
}
} finally {
saveAllWorlds(false);
}
}
use of com.sk89q.worldedit.event.platform.CommandEvent in project FastAsyncWorldEdit by IntellectualSites.
the class WorldEditPlugin method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
// Add the command to the array because the underlying command handling
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = commandLabel.startsWith("fastasyncworldedit:") ? commandLabel.replace("fastasyncworldedit:", "") : commandLabel;
CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split));
getWorldEdit().getEventBus().post(event);
return true;
}
use of com.sk89q.worldedit.event.platform.CommandEvent in project FastAsyncWorldEdit by IntellectualSites.
the class ToolUtilCommands method primary.
// FAWE start
@Command(name = "primary", aliases = { "/primary" }, desc = "Set the right click brush", descFooter = "Set the right click brush")
@CommandPermissions("worldedit.brush.primary")
public void primary(Player player, LocalSession session, @Arg(desc = "The brush command", variable = true) List<String> commandStr) throws WorldEditException {
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
BrushTool tool = session.getBrushTool(player, false);
session.setTool(item, null, player);
String cmd = "brush " + StringMan.join(commandStr, " ");
CommandEvent event = new CommandEvent(player, cmd);
PlatformCommandManager.getInstance().handleCommandOnCurrentThread(event);
BrushTool newTool = session.getBrushTool(item, player, false);
if (newTool != null && tool != null) {
newTool.setSecondary(tool.getSecondary());
}
}
Aggregations