entering text in chat

  • trying to build a gui for players to make plugin commands clickable. will have gui with button assigned to some plugins (/ap, /pnb).

    when using the setChat() method, does it just display in chat or does it enter it into chat as if typing the command and pressing enter?

  • That method simply intercepts the chat event and alters the message if your plugin wishes to do so, for example to implement a language filter for swearing

  • There is unfortunately no showChat method in the Java version, but it will be part of the new plugin API ;)


    If you want to send a chat message to a player, you can use the sendTextMessage() method.


    The PlayerChatEvent you've linked, however, is an event, as mentioned by Minotorious : It gets triggered by the game as soon as a player sends a chat message (i.e. after he presses the Return key). At this stage, it's not visible in chat yet, so you can manipulate the chat message through the API (or cancel the event if you don't want the chat message to show up). The message from the PlayerChatEvent will be broadcasted to all players (unless you cancel the event).

  • There is unfortunately no showChat method in the Java version, but it will be part of the new plugin API ;)


    If you want to send a chat message to a player, you can use the sendTextMessage() method.


    The PlayerChatEvent you've linked, however, is an event, as mentioned by Minotorious : It gets triggered by the game as soon as a player sends a chat message (i.e. after he presses the Return key). At this stage, it's not visible in chat yet, so you can manipulate the chat message through the API (or cancel the event if you don't want the chat message to show up). The message from the PlayerChatEvent will be broadcasted to all players (unless you cancel the event).

    thank you, was trying to make it so players didnt have type commands for /ap /pnb.

  • thank you, was trying to make it so players didnt have type commands for /ap /pnb.

    You could implement something like that by triggering the PlayerCommandEvent manually (see example below) ;)


    However, this only works in the Java version, unfortunately this wouldn't work in the new version anymore... the reason is that events in the new version now longer store their related data directly, instead they just contain a pointer referencing the according data on native side. But if a plugin manually creates a new event, there is no data on the native side it could reference - so as soon as an event listener tries to get any information from the event, the API will throw an exception.


    If it's just about invoking commands, we could instead add a separate method for it though? :thinking:


  • I looked at doing this before, but figured it was not possible.


    Would be interested to see if there was a hack to get this to work :)


    There is one other option, you could always decompile the pnb and ap jar files. Then add an event listener (maybe a keyboard key) to launch the UI and then recompile?

    thought about it but didnt feel rite messing with others code.

  • I looked at doing this before, but figured it was not possible.


    Would be interested to see if there was a hack to get this to work :)


    There is one other option, you could always decompile the pnb and ap jar files. Then add an event listener (maybe a keyboard key) to launch the UI and then recompile?

    i beleive this can be achieved byt using the import (

    import java.awt.Robot;

    import java.awt.event.KeyEvent;)

    edit. works on single player but not multiplayer. i must be missing something.

    try {

    robot = new Robot();

    robot.setAutoDelay(125);

    robot.keyPress(KeyEvent.VK_T);

    robot.keyRelease(KeyEvent.VK_T);

    robot.keyPress(KeyEvent.VK_SLASH);

    robot.keyRelease(KeyEvent.VK_SLASH);

    robot.keyPress(KeyEvent.VK_A);

    robot.keyRelease(KeyEvent.VK_A);

    robot.keyPress(KeyEvent.VK_P);

    robot.keyRelease(KeyEvent.VK_P);

    robot.keyPress(KeyEvent.VK_ENTER);

    robot.keyRelease(KeyEvent.VK_ENTER);

    }catch (AWTException e){e.printStackTrace();

  • We could bash out some code together, using Red's example. Which certainly looks good :D:thumbup:


    Java
    //Create a new command event, in this case we want to trigger the "/pnb" command
    PlayerCommandEvent cmd = new PlayerCommandEvent(player, "/pnb");
    //Trigger the event. This invokes all event listeners across all plugins
    triggerEvent(cmd);
  • Untested code - just done this in notepad.


  • Hehe that could be the smallest plugin ever :monocle:




    Edit: Just thought I would add this. It's probably better to use keyboard shortcuts for this as opposed to a GUI. Because using a GUI by definition will create an extra step. The player will have to open the GUI to open pnb or ap. With a keyboard shortcut (I've just used F keys in my example) the player can get straight to pnb or ap - and isn't that the objective?

  • Hehe that could be the smallest plugin ever :monocle:




    Edit: Just thought I would add this. It's probably better to use keyboard shortcuts for this as opposed to a GUI. Because using a GUI by definition will create an extra step. The player will have to open the GUI to open pnb or ap. With a keyboard shortcut (I've just used F keys in my example) the player can get straight to pnb or ap - and isn't that the objective?

    I agree with the hot keys instead of gui. Finaly understand what red was talking about with the command event, still learning. As for smallest plugin. I just made one just to enable the mouse pointer for stuck open gui's.

  • Just a small info about the API in the new version (because the snippet I've posted above won't work there anymore): The new API will have a new executeCommand() method (which replaces the existing executeConsoleCommand() method). It can be used to execute both console commands and API commands (depending on whether or not a preceding slash is added to the command).


    So executing a command "/pnb" (which invokes the PlayerCommandEvent across all plugins) could look like this in the new version:

  • Untested code - just done this in notepad.


    i can confirm this does work. thank you guys for the help. mind if i use the code?

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!