Solved How do I cancel command feedback?

Discussion in 'Plugin Development' started by Adan_Portrum, May 11, 2015.

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

    Adan_Portrum

    Hello! I'm currently working on a plugin where I'm using WorldEdit and I need a way to disable or cancel the "466(or however many) block(s) have been replaced.". I have tried:


    Code:
    @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e){
            if (benabled == 1){
                e.setCancelled(true);
            }
        }
    and:

    Code:
    @EventHandler
        public void onPlayerChat(PlayerChatEvent e){
            if (benabled == 1){
                e.setCancelled(true);
            }
        }
    Both failed to work. Does anybody know of a way I could do this?
     
  2. Offline

    Myrathi

    Moved: >>Plugin Development
     
  3. Offline

    Tecno_Wizard

    @Myrathi, I've never seen you before. New to the forums?

    @Adan_Portrum Use a regular expression and see if the string matches
     
    Last edited: May 11, 2015
  4. Offline

    Konato_K

    @Adan_Portrum I don't think you can change that without a server modification.

    Edit: Thinking a bit about it, I guess you can do it with ProtocolLib by intercepting outgoing packets?
     
    Last edited: May 11, 2015
  5. Offline

    nbrandwine

    Pretty sure that mthod you have won't work because it's a (generally used this way in many plugins, not sure about WE though) broadcast / sendmessage. I have an idea on how to "stop" it but it's basically like stdlib.h's method of system("cls"). If you don't know what that is... it's basically a for loop that adds a new line 100 times.
     
  6. Offline

    Adan_Portrum

    You mean like:
    Code:
    @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e){
            if (e.contains("block(s) have been replaced")){
                e.setCancelled(true);
            }
        }
    I don't think that will work because I already tried blocking all incoming messages, so if I narrow it down it makes logical sense that it would have a lesser chance of working, but please correct me if I'm wrong! I just started coding Bukkit API a week ago(but I have known Java for about a year).

    I have heard of ProtocalLib before... but I don't know how to work it. Could you possibly provide me with a link? :)

    Ok thanks! No offense to you, but I'll keep trying to find a solution ;)

    Oh! I forgot to add: I'm using
    Code:
    Bukkit.getServer().dispatchCommand(player, "/replacenear 5 grass,dirt,sand glass");
    to make the player send the command. Is there a way to make the console run it that way the command feedback/replies go to the console instead of the player's chat? I know that you could also do:
    Code:
    player.performCommand("/replacenear 5 grass,dirt,sand glass");
    but I'm pretty sure that will come up with the same results.

    Oh I'm sorry! This is my first thread :p


    {{Posts merged by Myrathi}}
     
    Last edited by a moderator: May 11, 2015
  7. Offline

    Goblom

    @Adan_Portrum If you dont feel like learning how to do packets or use a lib that manipulates packets you can use bukkits ConversationAPI (although a little unorthodox) . It automatically blocks all messages to the player until the conversation is aborted.
     
  8. Offline

    Tecno_Wizard

    @Adan_Portrum, few things about these forums you should know since it seems you didn't read the rules...
    No double posting, just edit your last post.
    Bumping is only allowed after a thread has not had a post in 24 hours, including previous bumps.
    And don't post links to bukkit jars, they are usually illegal.

    Back to the OP, if the message is broadcasted, there likely isn't a way to stop it without manipulating packets.
     
    Last edited: May 12, 2015
  9. Offline

    Adan_Portrum

    I tried it, and it only worked when I sent a chat message. I think that the command feedback is classified as something other than a chat message... Here is the code I used:

    Code:
    protocolManager.addPacketListener(new PacketAdapter(this, ListenerPriority.NORMAL,
                    PacketType.Play.Client.CHAT) {
                @Override
                public void onPacketReceiving(PacketEvent e) {
                    if (e.getPacketType() == PacketType.Play.Client.CHAT) {
                        PacketContainer packet = e.getPacket();
                        String message = packet.getStrings().read(0);
    
                        if (message.toLowerCase().contains("undo successful") ||
                                message.toLowerCase().contains("block(s) have been replaced")) {
                            e.setCancelled(true);
                        }
                    }
                }
            });
    EDIT: I was playing around with ProtocolLib, and found something that works!

    Code:
    protocolManager.addPacketListener(
            new PacketAdapter(this, ListenerPriority.NORMAL, PacketType.Play.Server.CHAT) {
                @Override
                public void onPacketSending(PacketEvent e) {
                    // Item packets (id: 0x29)
                    if (e.getPacketType() == PacketType.Play.Server.CHAT && byakugan == true) {
                        e.setCancelled(true);
                    }
                }
            });
    Thank you all for helping me! :D

    @Tecno_Wizard
    @Goblom
    @nbrandwine
    @Konato_K
    @Myrathi
     
    Last edited: May 12, 2015
  10. Offline

    nbrandwine

    Good dude. :D My next post would have been "You should try ProtocolLib". Glad you figured it out. =)
     
  11. Offline

    Adan_Portrum

  12. Offline

    Zombie_Striker

    If this thread was solved, mark as solved.
     
  13. Offline

    Adan_Portrum

Thread Status:
Not open for further replies.

Share This Page