Skip to content

Dev API

Joey Peter edited this page Apr 27, 2023 · 4 revisions

Dev API

This is the documentation of ChatEx's API. You can include the api as followed:

Maven

<repositories>
   ...
   <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
   ...
   <dependency>
      <groupId>com.github.TheJeterLP</groupId>
       <artifactId>ChatEx</artifactId>
       <version>Version</version>
    </dependency>
</dependencies>

Gradle

allprojects {
   repositories {
      ...
      maven { url 'https://jitpack.io' }
   }
}

dependencies {
   implementation 'com.github.TheJeterLP:ChatEx:Version'
}

Be carefull to include the correct version for your project. To include the ChatEx API in other waysread this site: Jitpack - ChatEx.

Events

ChatEx includes the following events which you can handle as normal bukkit events:

PlayerUsesRangeModeEvent

This event gets fired if a player uses the rangemode.

@EventHandler
public void onEvent(PlayerUsesRangeModeEvent event){
   event.getPlayer();                //returns the player which fired the event
   event.getMessage();               //returns the message which the player wrote
   event.setMessage(String message); //set the message the player will send
}

If this event is cancelled the message will not be sent.

PlayerUsesGlobalChatEvent

This event gets fired if a player uses the global-chat.

@EventHandler
public void onEvent(PlayerUsesGlobalChatEvent event){
   event.getPlayer();                //returns the player which fired the event
   event.getMessage();               //returns the message which the player wrote
   event.setMessage(String message); //set the message the player will send
}

MessageContainsBlockedWordEvent

This event gets fired if a player writes a word from the BlockedWords section in the config.yml

@EventHandler
public void onEvent(MessageContainsBlockedWordEvent event){
   event.getPlayer();                           //returns the player which fired the event
   event.getMessage();                          //returns the message which the player wrote
   event.getPluginMessage();                    //returns the message the plugin will send the player
   event.setMessage(String message);            //set the message the player will send
   event.setPluginMessage(String pluginMessage) //Set the message the message which the plugin will send to the player
}

MessageBlockedByAdManagerEvent

This event gets fired if a players message gets blocked by the AdManager

@EventHandler
public void onEvent(MessageBlockedByAdManagerEvent event){
   event.getPlayer();                           //returns the player which fired the event
   event.getMessage();                          //returns the message which the player wrote
   event.getPluginMessage();                    //returns the message the plugin will send the player
   event.setMessage(String message);            //set the message the player will send
   event.setPluginMessage(String pluginMessage) //Set the message the message which the plugin will send to the player
}

MessageBlockedBySpamManagerEvent

This event gets fired if a players message gets blocked by the SpamManager

@EventHandler
public void onEvent(MessageBlockedBySpamManagerEventevent){
   event.getPlayer();                           //returns the player which fired the event
   event.getMessage();                          //returns the message which the player wrote
   event.getPluginMessage();                    //returns the message the plugin will send the player
   event.getRemainingTime();                    //returns the remaining time (In Seconds) the player cant write
   event.setMessage(String message);            //set the message the player will send
   event.setPluginMessage(String pluginMessage) //Set the message the message which the plugin will send to the player
}

ChatExAPI

The ChatExAPIclass contains many usefull informations of player. You can get it with:

ChatExAPI chatExAPI = new ChatExAPI();

ChatExAPI

String permissionHandlerName = chatExAPI.getPermissionHandlerName();

AntiSpamManager antiSpamManager = chatExAPI.getAntiSpamManager();

String prefix = chatExAPI.getPrefix(Player p);

String Suffix = chatExAPI.getSuffix(Player p);

String[] groupNames = chatExAPI.getGroupNames(Player p);

String messageFormat = chatExAPI.getMessageFormat(Player p);

String globalMessageFormat = chatExAPI.getGlobalMessageFormat(Player p);

AntiSpamManager

The AntiSpamManager contains information about the players cooldown. You can get it with:

AntiSpamManager antiSpamManager = chatExAPI.getAntiSpamManager();

You can get a players remaining mute time with:

long timeInSeconds = antiSpamManager.getRemainingSeconds(Player player); //returns the remaining cooldown in seconds
long timeInMillis = antiSpamManager.getRemainingMillis(Player player); //return the remaining cooldown in milliseconds