@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] = cmd.getName(); CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); getWorldEdit().getEventBus().post(event); return true; }
@Override public List<String> onTabComplete(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] = cmd.getName(); CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); getWorldEdit().getEventBus().post(event); return event.getSuggestions(); }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerCommand(PlayerCommandSendEvent event) { CommandLocals locals = new CommandLocals(); locals.put(Actor.class, plugin.wrapCommandSender(event.getPlayer())); Set<String> toRemove = plugin.getWorldEdit().getPlatformManager().getCommandManager().getDispatcher().getCommands().stream() .filter(commandMapping -> !commandMapping.getCallable().testPermission(locals)) .map(CommandMapping::getPrimaryAlias) .collect(Collectors.toSet()); event.getCommands().removeIf(toRemove::contains); }
/** * Called when a player attempts to use a command * * @param event Relevant event details */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String[] split = event.getMessage().split(" "); if (split.length > 0) { split[0] = split[0].substring(1); split = plugin.getWorldEdit().getPlatformManager().getCommandManager().commandDetection(split); } final String newMessage = "/" + StringUtil.joinString(split, " "); if (!newMessage.equals(event.getMessage())) { event.setMessage(newMessage); plugin.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { if (!event.getMessage().isEmpty()) { plugin.getServer().dispatchCommand(event.getPlayer(), event.getMessage().substring(1)); } event.setCancelled(true); } } }
final WorldEdit we = plugin.getWorldEdit();
@Override public void run(String playerID) throws QuestRuntimeException { try { Location location = loc.getLocation(playerID); SchematicFormat schematic = SchematicFormat.getFormat(file); CuboidClipboard clipboard = schematic.load(file); BukkitWorld world = new BukkitWorld(location.getWorld()); EditSession editSession = we.getWorldEdit().getEditSessionFactory().getEditSession(world, 64*64*64); Vector newOrigin = BukkitUtil.toVector(location); clipboard.paste(editSession, newOrigin, noAir); } catch (DataException | IOException | MaxChangedBlocksException e) { Debug.error("Error while pasting a schematic: " + e.getMessage()); } }