Search in sources :

Example 1 with DynmapCommandSender

use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.

the class DynmapExpCommand method onCommand.

void onCommand(CommandSource sender, String cmd, String[] args) {
    DynmapCommandSender dsender;
    PlayerEntity psender;
    try {
        psender = sender.asPlayer();
    } catch (com.mojang.brigadier.exceptions.CommandSyntaxException x) {
        psender = null;
    }
    if (psender != null) {
        dsender = new ForgePlayer(psender);
    } else {
        dsender = new ForgeCommandSender(sender);
    }
    try {
        core.processCommand(dsender, cmd, cmd, args);
    } catch (Exception x) {
        dsender.sendMessage("Command internal error: " + x.getMessage());
        Log.severe("Error with command: " + cmd + Arrays.deepToString(args), x);
    }
}
Also used : DynmapCommandSender(org.dynmap.common.DynmapCommandSender) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) CommandException(net.minecraft.command.CommandException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) JsonParseException(com.google.gson.JsonParseException) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 2 with DynmapCommandSender

use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.

the class DynmapPlugin method handleCommand.

// TODO: Clean a bit
public void handleCommand(ServerCommandSource commandSource, String cmd, String[] args) throws CommandSyntaxException {
    DynmapCommandSender dsender;
    ServerPlayerEntity psender = null;
    // getPlayer throws a CommandSyntaxException, so getEntity and instanceof for safety
    if (commandSource.getEntity() instanceof ServerPlayerEntity) {
        psender = commandSource.getPlayer();
    }
    if (psender != null) {
        // FIXME: New Player? Why not query the current player list.
        dsender = new FabricPlayer(this, psender);
    } else {
        dsender = new FabricCommandSender(commandSource);
    }
    core.processCommand(dsender, cmd, cmd, args);
}
Also used : DynmapCommandSender(org.dynmap.common.DynmapCommandSender) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 3 with DynmapCommandSender

use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.

the class DynmapPlugin method handleCommand.

// TODO: Clean a bit
public void handleCommand(ServerCommandSource commandSource, String cmd, String[] args) throws CommandSyntaxException {
    DynmapCommandSender dsender;
    ServerPlayerEntity psender = null;
    // getPlayer throws a CommandSyntaxException, so getEntity and instanceof for safety
    if (commandSource.getEntity() instanceof ServerPlayerEntity) {
        psender = commandSource.getPlayer();
    }
    if (psender != null) {
        // FIXME: New Player? Why not query the current player list.
        dsender = new FabricPlayer(this, psender);
    } else {
        dsender = new FabricCommandSender(commandSource);
    }
    core.processCommand(dsender, cmd, cmd, args);
}
Also used : DynmapCommandSender(org.dynmap.common.DynmapCommandSender) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 4 with DynmapCommandSender

use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.

the class DynmapPlugin method handleCommand.

// TODO: Clean a bit
public void handleCommand(ServerCommandSource commandSource, String cmd, String[] args) throws CommandSyntaxException {
    DynmapCommandSender dsender;
    ServerPlayerEntity psender = null;
    // getPlayer throws a CommandSyntaxException, so getEntity and instanceof for safety
    if (commandSource.getEntity() instanceof ServerPlayerEntity) {
        psender = commandSource.getPlayer();
    }
    if (psender != null) {
        // FIXME: New Player? Why not query the current player list.
        dsender = new FabricPlayer(this, psender);
    } else {
        dsender = new FabricCommandSender(commandSource);
    }
    core.processCommand(dsender, cmd, cmd, args);
}
Also used : DynmapCommandSender(org.dynmap.common.DynmapCommandSender) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 5 with DynmapCommandSender

use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.

the class DynmapCore method getTabCompletions.

/**
 * Returns a list of tab completion suggestions for the given sender, command and command arguments.
 *
 * @param sender - The sender of the tab completion, used for permission checks
 * @param cmd - The top level command being tab completed
 * @param args - Array of extra command arguments
 * @return List of tab completion suggestions
 */
public List<String> getTabCompletions(DynmapCommandSender sender, String cmd, String[] args) {
    if (mapManager == null || args.length == 0) {
        return Collections.emptyList();
    }
    if (args.length == 1) {
        return getSubcommandSuggestions(sender, cmd, args[0]);
    }
    if (cmd.equalsIgnoreCase("dmap")) {
        return dmapcmds.getTabCompletions(sender, args, this);
    }
    if (cmd.equalsIgnoreCase("dmarker")) {
        return markerapi.getTabCompletions(sender, args, this);
    }
    if (cmd.equalsIgnoreCase("dynmapexp")) {
        return dynmapexpcmds.getTabCompletions(sender, args, this);
    }
    if (!cmd.equalsIgnoreCase("dynmap")) {
        return Collections.emptyList();
    }
    /* Re-parse args - handle double quotes */
    args = parseArgs(args, sender, true);
    if (args == null || args.length <= 1) {
        return Collections.emptyList();
    }
    String subcommand = args[0];
    DynmapPlayer player = null;
    if (sender instanceof DynmapPlayer) {
        player = (DynmapPlayer) sender;
    }
    if (subcommand.equals("radiusrender") && checkPlayerPermission(sender, "radiusrender")) {
        if (args.length == 2) {
            // /dynmap radiusrender *<world>* <x> <z> <radius> <map>
            return getWorldSuggestions(args[1]);
        }
        if (args.length == 3 && player != null) {
            // /dynmap radiusrender <radius> *<mapname>*
            try (Scanner sc = new Scanner(args[1])) {
                if (sc.hasNextInt(10)) {
                    // Only show map suggestions if a number was entered before
                    return getMapSuggestions(player.getLocation().world, args[2], false);
                }
            }
        } else if (args.length == 6) {
            // /dynmap radiusrender <world> <x> <z> <radius> *<map>*
            return getMapSuggestions(args[1], args[5], false);
        }
    } else if (subcommand.equals("updaterender") && checkPlayerPermission(sender, "updaterender")) {
        if (args.length == 2) {
            // /dynmap updaterender *<world>* <x> <z> <map>/*<map>*
            List<String> suggestions = getWorldSuggestions(args[1]);
            if (player != null) {
                suggestions.addAll(getMapSuggestions(player.getLocation().world, args[1], false));
            }
            return suggestions;
        } else if (args.length == 5) {
            // /dynmap updaterender <world> <x> <z> *<map>*
            return getMapSuggestions(args[1], args[4], false);
        }
    } else if (subcommand.equals("hide") && checkPlayerPermission(sender, "hide.others")) {
        if (args.length == 2) {
            // /dynmap hide *<player>*
            final String arg = args[1];
            return playerList.getVisiblePlayers().stream().map(DynmapPlayer::getName).filter(name -> name.startsWith(arg)).collect(Collectors.toList());
        }
    } else if (subcommand.equals("show") && checkPlayerPermission(sender, "show.others")) {
        if (args.length == 2) {
            // /dynmap show *<player>*
            final String arg = args[1];
            return playerList.getHiddenPlayers().stream().map(DynmapPlayer::getName).filter(name -> name.startsWith(arg)).collect(Collectors.toList());
        }
    } else if (subcommand.equals("fullrender") && checkPlayerPermission(sender, "fullrender")) {
        // World suggestions
        List<String> suggestions = getWorldSuggestions(args[args.length - 1]);
        // world:map suggestions
        suggestions.addAll(getMapSuggestions(args[args.length - 1]));
        // Remove suggestions present in other arguments
        for (String arg : args) {
            suggestions.remove(arg.contains(" ") ? "\"" + arg + "\"" : arg);
        }
        // Add resume if previous argument wasn't resume
        if ("resume".startsWith(args[args.length - 1]) && (args.length == 2 || !args[args.length - 2].equals("resume"))) {
            suggestions.add("resume");
        }
        return suggestions;
    } else if ((subcommand.equals("cancelrender") && checkPlayerPermission(sender, "cancelrender")) || (subcommand.equals("purgequeue") && checkPlayerPermission(sender, "purgequeue"))) {
        List<String> suggestions = getWorldSuggestions(args[args.length - 1]);
        // Remove worlds present in other arguments
        suggestions.removeAll(Arrays.asList(args));
        return suggestions;
    } else if (subcommand.equals("purgemap") && checkPlayerPermission(sender, "purgemap")) {
        if (args.length == 2) {
            // /dynmap purgemap *<world>* <map>
            return getWorldSuggestions(args[1]);
        } else if (args.length == 3) {
            // /dynmap purgemap <world> *<map>*
            return getMapSuggestions(args[1], args[2], false);
        }
    } else if ((subcommand.equals("purgeworld") && checkPlayerPermission(sender, "purgeworld")) || (subcommand.equals("stats") && checkPlayerPermission(sender, "stats")) || (subcommand.equals("resetstats") && checkPlayerPermission(sender, "resetstats"))) {
        if (args.length == 2) {
            return getWorldSuggestions(args[1]);
        }
    } else if (subcommand.equals("pause") && checkPlayerPermission(sender, "pause")) {
        List<String> suggestions = Arrays.asList("full", "update", "all", "none");
        if (args.length == 2) {
            final String arg = args[1];
            return suggestions.stream().filter(suggestion -> suggestion.startsWith(arg)).collect(Collectors.toList());
        }
    } else if ((subcommand.equals("ips-for-id") && checkPlayerPermission(sender, "ips-for-id")) || (subcommand.equals("add-id-for-ip") && checkPlayerPermission(sender, "add-id-for-ip")) || (subcommand.equals("del-id-for-ip") && checkPlayerPermission(sender, "del-id-for-ip")) || (subcommand.equals("webregister") && checkPlayerPermission(sender, "webregister.other"))) {
        if (args.length == 2) {
            final String arg = args[1];
            return Arrays.stream(playerList.getOnlinePlayers()).map(DynmapPlayer::getName).filter(name -> name.startsWith(arg)).collect(Collectors.toList());
        }
    } else if (subcommand.equals("help")) {
        if (args.length == 2) {
            return getSubcommandSuggestions(sender, "dynmap", args[1]);
        }
    }
    return Collections.emptyList();
}
Also used : Arrays(java.util.Arrays) Debug(org.dynmap.debug.Debug) BufferOutputStream(org.dynmap.utils.BufferOutputStream) Enumeration(java.util.Enumeration) URL(java.net.URL) MapStorage(org.dynmap.storage.MapStorage) Scanner(java.util.Scanner) InetAddress(java.net.InetAddress) MySQLMapStorage(org.dynmap.storage.mysql.MySQLMapStorage) Map(java.util.Map) AllowSymLinkAliasChecker(org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker) ZipFile(java.util.zip.ZipFile) URI(java.net.URI) MarkerAPI(org.dynmap.markers.MarkerAPI) ZipEntry(java.util.zip.ZipEntry) Server(org.eclipse.jetty.server.Server) MariaDBMapStorage(org.dynmap.storage.mariadb.MariaDBMapStorage) CustomHeaderFilter(org.dynmap.web.CustomHeaderFilter) DynmapExpCommands(org.dynmap.exporter.DynmapExpCommands) org.dynmap.servlet(org.dynmap.servlet) MicrosoftSQLMapStorage(org.dynmap.storage.mssql.MicrosoftSQLMapStorage) PostgreSQLMapStorage(org.dynmap.storage.postgresql.PostgreSQLMapStorage) NetworkTrafficServerConnector(org.eclipse.jetty.server.NetworkTrafficServerConnector) HttpServlet(javax.servlet.http.HttpServlet) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Set(java.util.Set) Reader(java.io.Reader) DynmapListenerManager(org.dynmap.common.DynmapListenerManager) InetSocketAddress(java.net.InetSocketAddress) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) List(java.util.List) ModSupportImpl(org.dynmap.modsupport.ModSupportImpl) Writer(java.io.Writer) FileTreeMapStorage(org.dynmap.storage.filetree.FileTreeMapStorage) FileNameFilter(org.dynmap.web.FileNameFilter) ImageEncoding(org.dynmap.MapType.ImageEncoding) SQLiteMapStorage(org.dynmap.storage.sqllte.SQLiteMapStorage) AWSS3MapStorage(org.dynmap.storage.aws_s3.AWSS3MapStorage) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Yaml(org.yaml.snakeyaml.Yaml) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) HandlerRouter(org.dynmap.web.HandlerRouter) MarkerAPIImpl(org.dynmap.markers.impl.MarkerAPIImpl) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) HDBlockModels(org.dynmap.hdmap.HDBlockModels) LinkedList(java.util.LinkedList) DynmapServerInterface(org.dynmap.common.DynmapServerInterface) TexturePack(org.dynmap.hdmap.TexturePack) HandlerList(org.eclipse.jetty.server.handler.HandlerList) DynmapPlayer(org.dynmap.common.DynmapPlayer) FileWriter(java.io.FileWriter) FileOutputStream(java.io.FileOutputStream) HDBlockStateTextureMap(org.dynmap.hdmap.HDBlockStateTextureMap) ExecutorThreadPool(org.eclipse.jetty.util.thread.ExecutorThreadPool) IOException(java.io.IOException) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Field(java.lang.reflect.Field) InputStreamReader(java.io.InputStreamReader) UnknownHostException(java.net.UnknownHostException) File(java.io.File) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) BlockStep(org.dynmap.utils.BlockStep) javax.servlet(javax.servlet) EventType(org.dynmap.common.DynmapListenerManager.EventType) DynmapCommandSender(org.dynmap.common.DynmapCommandSender) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Debugger(org.dynmap.debug.Debugger) Connector(org.eclipse.jetty.server.Connector) Collections(java.util.Collections) BanIPFilter(org.dynmap.web.BanIPFilter) FilterHandler(org.dynmap.web.FilterHandler) ImageIOManager(org.dynmap.utils.ImageIOManager) InputStream(java.io.InputStream) Scanner(java.util.Scanner) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HandlerList(org.eclipse.jetty.server.handler.HandlerList) DynmapPlayer(org.dynmap.common.DynmapPlayer)

Aggregations

DynmapCommandSender (org.dynmap.common.DynmapCommandSender)16 JsonParseException (com.google.gson.JsonParseException)7 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)7 CancellationException (java.util.concurrent.CancellationException)7 ExecutionException (java.util.concurrent.ExecutionException)7 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)7 ServerPlayer (net.minecraft.server.level.ServerPlayer)4 CommandException (net.minecraft.command.CommandException)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1