🤖Auto Responses
Create predefined auto responses
Overview
The AutoResponses class provides a utility for automatically responding to specific triggers in chat messages. This class allows you to define trigger-response pairs, play sounds, and display titles to players when a trigger is detected in a chat message.
Methods
autoResponses
autoResponsespublic AutoResponses autoResponses(String trigger, String response)Adds a trigger-response pair to the auto-responses map.
Parameters
trigger: The trigger string to be detected in chat messages.response: The response string to be sent when the trigger is detected.
Returns
AutoResponses: ThisAutoResponsesinstance for method chaining.
playSound
playSoundpublic AutoResponses playSound(Sound sound, float volume, float pitch)Sets the sound to be played when a trigger is detected.
Parameters
sound: The Sound enum representing the sound to be played.volume: The volume of the sound (0.0 to 1.0).pitch: The pitch of the sound (0.5 to 2.0).
Returns
AutoResponses: ThisAutoResponsesinstance for method chaining.
sendTitle
sendTitlepublic AutoResponses sendTitle(String title, String subtitle)Sets the title and subtitle to be displayed when a trigger is detected.
Parameters
title: The title text to be displayed.subtitle: The subtitle text to be displayed.
Returns
AutoResponses: ThisAutoResponsesinstance for method chaining.
build
buildpublic void build(Player player, String message)Processes the chat message and triggers the corresponding response actions.
Parameters
player: The player who sent the chat message.message: The chat message to be processed.
Usage
Create an instance of the
AutoResponsesclass.Add trigger-response pairs using the
autoResponsesmethod.Optionally, set sound and title/subtitle using the
playSoundandsendTitlemethods, respectively.Call the
buildmethod with the player and chat message to process the message and trigger responses.
Example
// Create an instance of AutoResponses
AutoResponses autoResponses = new AutoResponses();
// Add trigger-response pairs
autoResponses.autoResponses("hello", "Hi there!");
// Set sound and title/subtitle
autoResponses.playSound(Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 1.0f)
.sendTitle("Title", "Subtitle");
// Process chat message and trigger responses
autoResponses.build(player, chatMessage);Last updated