1.15.2 Getting Output of a Vanilla Command

Discussion in 'Spigot Plugin Development' started by 14er, Mar 21, 2020.

  1. Hello,

    I'm trying to get the output of a Minecraft command (specifically a data get block command, which is a vanilla command). I created a class that implements a command sender. Based on my understanding, the sendMessage function should get called with the output, but it never gets called.
    If I change RemoteConsoleCommandSender to ConsoleCommandSender, the output still appears in console but doesn't get updated into message. If I make it just a CommandSender, it can't get cast to a vanilla command wrapper by Spigot (which leads to an error with data, it does work if I change the data command to a Spigot command like pl).

    Calling code:
    Code (Java):
    NBTExtractor nbtExtractor = new NBTExtractor();
    Bukkit.getServer().dispatchCommand(nbtExtractor, command);
    String message = nbtExtractor.getMessage();
    NBTExtractor class (with a lot of the functions cut out that don't impact anything best I can tell - all needed functions exist):
    Code (Java):
    public class NBTExtractor implements RemoteConsoleCommandSender {

        String message = "";
     
        public String getMessage() {
            return message;
        }

        @Override
        public void sendMessage(String message) {
            this.message = message;
        }

        @Override
        public void sendMessage(String[] messages) {
            message = "";
            for (String s : messages) {
                message += s + "\n";
            }
        }
    }
    I'm obviously not understanding something, but I can't seem to figure out what. A pointer in the right direction would be appreciated. Thanks!
     
    #1 14er, Mar 21, 2020
    Last edited: Mar 21, 2020