Assistant v0.1 - Create Chat-driven assistants

Discussion in 'Resources' started by narrowtux, May 24, 2011.

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


    Assistant v0.1
    I created an Assistant API for simplifying the process of writing a chat assistant. A chat assistant guides the player through a process like setting up something or buying items and so on.
    With the Assistant-API, you can easily provide your users this experience.

    • Reimplement the Assistant class to create your own assistant
    • Multiple-Page handling (flexible)
    • Player can "run away" to cancel the Assistant (optional)
    • Chat is held back for the player who is in an assistant. If some other players chat, he will receive their messages after he has finished the assistant.
    There are 2 classes:
    • Assistant - represents an assistant.
    • AssistantPage - represents a page within an assistant.
    Methods for Assistant
    Assistant(Player p) - Constructs the Assistant for the given player.
    static boolean onPlayerChat(PlayerChatEvent event) - dispatches a chat event to the right assistant.
    static void onPlayerMove(PlayerMoveEvent event) - dispatches a move event to the right assistant. Is used to see if a player went away from the position where he started the assistant.
    Player getPlayer() - gets the player object of the assistant
    AssistantPage currentPage() - gets the current active page of the assistant
    List<AssistantPage> getPages() - gets all pages of the assistant
    void addPage(AssistantPage) - adds a new page to the end of the pages
    void setTitle(String title) / String getTitle() - sets/gets the title of the assistant
    void onAssistantCancel() - Is called when the player cancels the assistant. Reimplement to do your own handling
    void onAssistantFinish() - Is called when the assistant finished normally. Reimplement to do your own handling
    void start() - Used to start the assistant after creation
    void stop() - Finishes the assistant
    void sendMessage(String) - sends a message to the Player
    String getSeparator() - gets a separator (see the screenshot)
    String formatLine(String) - formats a string to fit in the visual appearance
    void setAssistantStartLocation(Location) - sets the start location for the run-away-trigger (optional)
    Location getAssistantStartLocation() - gets the start location
    Methods for AssistantPage:
    property title - The title of the page (see screenshot) - accessible by setTitle / getTitle
    property text - The body of the page (see screenshot) - accessible by setText / getText
    property assistant - the assistant of this page - accessible by setAssistant / getAssistant
    boolean onPageInput(String text) - Is called when the player inputs something on this page. Reimplement this to create your handling for this
    void play() - Plays the page (displays title and text). You won't have to use it, it will automatically be called by the Assistant
    void sendMessage(String) - Convenience Method for getAssistant().sendMessage(String)
    How to create a basic assistant:
    First, set up a player listener who listens to the PlayerChatEvent and, if you want the run-away-cancel feature, the PlayerMoveEvent.
    class PlayerListener extends PlayerListener {
        public void onPlayerChat(PlayerChatEvent event){
        public void onPlayerMove(PlayerMoveEvent event){
    Then, you can create your assistant:
    Assistant a = new Assistant(thePlayer){
    public void onAssistantFinish(){
    public void onAssistantCancel(){
    a.setTitle("My fancy Assistant");
    AssistantPage page = new AssistantPage(){
    public boolean onPageInput(String message){
        sendMessage("you typed: "+message);
        //do what you want with the message
        return true; // true means success, if you return false here, the assistant will be cancelled
    And that's it!
    Screenshot of the Layout:
    Assistant Layout.png
  2. Offline


    Nice! :D

    Cant you just upload a plugin so we can download like shop assisstant :D?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 16, 2016
Thread Status:
Not open for further replies.

Share This Page