supress server console echo when tyiping

Discussion in 'Plugin Development' started by atesin, Mar 29, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    atesin

    EDIT: moderators, please add the [workaround] label since i couldn't found where edit the title

    like me, if somebody for some reason wants to cancel ServerCommandEvent but can't due this bug, i bring a temporary solution... you just need:

    - add a dummy command that does nothing in plugin.yml
    - on ServerCommandEvent, change the command itself

    look my post #4 below as an example, confirmed now it works

    ------------------ original post-------------------
    hi ... i am trying to do a mail/chat plugin ... i "capture" console input while typing message

    when i do AsyncPlayerChatEvent.cancel() or PlayerCommandPreprocessEvent.cancel() they work flawlessly

    but as i can't cancel() ServerCommandEvent due this bug , i found a suggestion in another thread that is create a "dummy" command in plugin.yml and use setCommand("dummy") .. it works quite fine

    but the problem with this technique is every text i type in the console are echoed turning hard to read... here is a console sample
    Code:
    >sendmail myFriend say hello
    [17:56:51 INFO]: type your message, end with a dot
    my dear friend
    [17:56:52 INFO]: my dear friend
    i hope you were fine
    [17:56:53 INFO]: i hope you were fine
    bye
    [17:56:54 INFO]: bye
    .
    [17:56:55 INFO]: message sent to myFriend
    ... does anybody know some way to supress those annoying echoes?, maybe lowering the log priority of entered text?, or some trick to force command event cancellation or hide replies?

    thanks
     
    Last edited: Mar 30, 2016
  2. Offline

    Konato_K

    @atesin I believe you could do this by hooking into the logger's system or something like that, I have never done it (nor tried it) so I don't really know if it's possible with that, but it's kinda worth giving it a shot
     
  3. Offline

    mine-care

    Well lets have a look in the source code
    Before 1.9:
    Code:
    ServerCommand servercommand = (ServerCommand)this.i.remove(0);
    ServerCommandEvent event = new ServerCommandEvent(this.console, servercommand.command);
    this.server.getPluginManager().callEvent(event);
    servercommand = new ServerCommand(event.getCommand(), servercommand.source);
    
    The issue was adressed in 1.9:
    Code:
    ServerCommand servercommand = (ServerCommand)this.serverCommandQueue.remove(0);
    ServerCommandEvent event = new ServerCommandEvent(this.console, servercommand.command);
    this.server.getPluginManager().callEvent(event);
    if (!event.isCancelled()){
       servercommand = new ServerCommand(event.getCommand(), servercommand.source);
       this.server.dispatchServerCommand(this.console, servercommand);
    }
    }
    
    But ofcourse you need to be backwards compatible, so relying on the fact that it is fixed in 1.9, doesn't solve the issue for server versions before that.

    Mabe you need to check if the server is in any version bellow 1.9, and if it is, register a dummy command like /randomnonsensecharactersgohere that won't be registered in your plugin.yml (I made a tutorial on how to do that) and then set the command to that random thing that will do nothing ofcourse since it doesn't have any code to execute (unless you want it to do something) and will not show anywhere :D So it will essentially be as if you canceled the event ;)

    That will do as you said, i don't know about loggers but that seems like a good solution to me :S
     
  4. Offline

    atesin

    @mine-care thanks for your suggestion on dummy command but i don't understand...

    this is exactly (i guess) what i've done and echoes are coming on every line i enter... please tell me if i am missing something
    Code:
    # plugin.yml
    commands:
      donothing:
        description: dummy command that does nothing, used to supress some messages
    Code:
    @EventHandler
    public void onServerCommand(ServerCommandEvent e)
    {
       if (isComposing(e.getSender(), e.getCommand()))
         e.setCommand("donothing");
    }
    it seems by registering command on plugin.yml prevents "Unknown command. Type "/help" for help." message to be displayed, but still got "[hh:mm:ss INFO]: " echoes as if it were "valid" commands

    any idea?, thanks
     
    Last edited: Mar 30, 2016
  5. Offline

    mine-care

    @atesin Well, i dont really know what "isComposing" does, but thats what i mean more or less :S
    I recomended you register the command without a plugin.yml section as seen here: https://bukkit.org/threads/register-commands-without-plugin-yml.349373/
    (i know, i need to update it :S) and make a dummy command like fdsfsdjkgasldgjkdflashdjkf and in the event, call that command that has an empty body and always returns true. This way no message should be seen back :/ I tried it and it seems to have worked: [​IMG]
    (I decided to take over the command rl) and i did the same as you, but i dont see any message back from it :/
    I may be missing the point here, if that is the case please tell me!
     
  6. Offline

    atesin

    @mine-care thanks .. i will devoure that document

    what isCompsing() does is check if CommandSender is composing against a Collection i have (containsKey(getName()))... if does it stores "command" introduced and return true, if not it returns false

    does this mean i will need to register every command i type dinamically?, or can i just register "donothing" and then change command with setCommand("donothing") ?
     
  7. Offline

    mine-care

    @atesin Oh i see,

    You can register one 'donothing' command and if the sender belongs in the collection, set the command to "donothing" ;)
    The reason i recomended you go with a dynamically registered one is because that is a patchy solution, and if the server is in version 1.9, you don't need to implement it. So onEnable check if the server is 1.9 but if it is less register the command. Then in the ServerCommandEvent, if the server is 1.9 just cancel the event otherwise set the command to "donothing"
     
  8. Offline

    atesin

    i do use 1.9 and i suffer from this bug (version git-Bukkit-69e196f API 1.9-R0.1-SNAPSHOT).. so i will implement it anyway

    i am trying to simplify your code to register just one static command, i just need to supress echoes ... btw i find you a typo, in onEnable() you reference "FakeCommandRegister" while it should be "FakeCommandRegistry"
     
  9. Offline

    mine-care

    @atesin You forgot to tahg me ;)
    Well yeah it is not the only issue, the constructor does not need a JavaPlugin parameter although in the sample code i provide one, the exception catch block is huge and needs wraping up with "ReflectiveOperationException" etc. etc.
    Thats why
    But i also need time (hard) and a working brain (impossible) to do it :p
    Good luck with that!
     
  10. Offline

    atesin

    i guess i successfully registered the command with your method ... i simplified your method to only this application, but it still sends echo messages when i type in console, so for me using this is equivalent to using plugin.yml

    maybe the way of achieving is to set a log filter that filters and skips all "donothing" commands... do you know how to do it?.. or am i doing something wrong?
    Code:
    public void onEnable()
    {
       registerDummyCommand();
    }
    
    private void registerDummyCommand()
    {
       Command dummy = new Command("donothing")
       {
         @Override
         public boolean execute(CommandSender sender, String commandLabel, String[] args)
         {
           return true;
         }
       };
    
       CommandMap commandMap = null;
       try
       {
          commandMap = (CommandMap) getServer().getClass().getMethod("getCommandMap").invoke(getServer());
       }
       catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
       {
         e.printStackTrace();
       }
       if (commandMap != null)
         commandMap.register("donothing", dummy);
    }
     
    Last edited: Mar 30, 2016
  11. Offline

    mine-care

    Err can you show me what it does in your console? I'm a litle confused :(
    As you see in my console it does nothing :S

    Edit: in your code I don't see anywhere where you listen for ServerCommandEvent :S
     
  12. Offline

    atesin

    MY FAULT!

    i discovered, with my techique (register command in plugin.yml) and yours (register command runtime) works the same

    with both methods when i type "donothing" in server console it doesn't echo, like your screenshot above
    but when i use trought my plugin, command got echoed, in both cases

    that turned me suspicious.. i remembered i possibly echoed messages to the mc chat area that does not echo typed commands... and when i went to confirm, gotcha! ... so now i got a litle check before (manually) echo messages... i gonna update main thread
    Code:
    if (sender instanceof Player)
        sender.sendMessage("\u00A77"+line);
     
    Last edited: Mar 30, 2016
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page