[Tut] Chatting with the tab-key

Discussion in 'Resources' started by Plo124, Nov 23, 2013.

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

    Plo124

    I was playing around with the PlayerChatTabCompleteEvent, and I got an amazing idea.

    So, first you want to have your listener and stuff all set up, and then you want to create a PlayerChatTabCompleteEvent.
    Code:java
    1.  
    2. @EventHandler
    3. public void tabChat(PlayerChatTabCompleteEvent e){
    4.  
    5. }
    6.  


    Then you want to setup the listener.
    Code:java
    1.  
    2. //@EventHandler
    3. //public void tabChat(PlayerChatTabCompleteEvent e){
    4. Player p = e.getPlayer();
    5. String m = e.getChatMessage();
    6. //}
    7.  


    Then you want to make sure the player doesn't get any of the spam from hitting tab
    Code:java
    1. e.getTabCompletions().clear();


    Next you want to send the message, you can modify the chat format as you wish
    Code:java
    1.  
    2. //@EventHandler
    3. //public void tabChat(PlayerChatTabCompleteEvent e){
    4. //Player p = e.getPlayer();
    5. //String m= e.getChatMessage();
    6. //e.getTabCompletions().clear();
    7. this.getServer().broadcastMessage("<"+p.getName()+"> "+m);
    8. //}
    9.  


    And then the last step is to close the chat menu.
    I haven't tested this myself, so I hope this works
    This is easy, you just need to open an empty inventory, and close it before the player see's.

    Code:java
    1.  
    2. Inventory inv = this.getServer().createInventory(null, 9);
    3. p.openInventory(inv);
    4. p.closeInventory();
    5.  


    So I ended up with this inside my tab complete event:
    Code:java
    1.  
    2. @EventHandler
    3. public void tabChat(PlayerChatTabCompleteEvent e){
    4. Player p = e.getPlayer();
    5. String m= e.getChatMessage();
    6. e.getTabCompletions().clear();
    7. this.getServer().broadcastMessage("<"+p.getName()+"> "+m);
    8. Inventory inv = this.getServer().createInventory(null, 9);
    9. p.openInventory(inv);
    10. p.closeInventory();
    11. }
    12.  


    And heres the version you can paste into your work without line numbers:
    Thanks, and I would be excited to see how people make use of this trick :D
     
    ChipDev likes this.
  2. Offline

    molenzwiebel

    Just calling p.closeInventory() (without the opening of the custom inventory first) also works
     
  3. Offline

    Plo124

    I found out a server called 'Dungeon Realms' uses this technique. So If anyone wanted to know how to do the tab-chat like on dungeon-realms, here is the place for you.
     
  4. Offline

    Blah1

    Um.. What exactly does this do?
     
  5. Offline

    Plo124

    Blah1
    When you are typing in the chat, you usually hit enter,
    Well with this tutorial, you can add all sorts of new wacky things, because you can also press Tab to send the message, and you can do different things with that.
     
  6. Offline

    bobacadodl

    I actually already had this set up on a custom RPG server I'm developing for. If you chat normally, it sends the message only to people in the town you are currently in, but if you press tab, it sends it to the global chat instead.
     
  7. Offline

    Plo124

    bobacadodl
    May I ask what the server name is?
     
  8. Offline

    bobacadodl

    Its still under development, not released to the public yet ;)

    I stole the idea from another server though. I forget its name.
     
  9. Offline

    Plo124

    bobacadodl
    Think I may be able to join the dev team? I wont be very active, but I am good at plugins.
     
  10. Offline

    bobacadodl

    Plo124
    Better to discuss this in PM ;)
     
  11. Offline

    ChipDev

    Great tut. :)
     
Thread Status:
Not open for further replies.

Share This Page