-
-
Notifications
You must be signed in to change notification settings - Fork 7
Plugin API
Adrian edited this page Feb 27, 2025
·
11 revisions
repositories {
mavenCentral()
}
dependencies {
compileOnly("io.github.4drian3d:chatregulator-api:4.0.0")
}
@Subscribe
public void onPlayerMessageInfraction(ChatInfractionEvent event){
// Get the Infractionplayer that was detected in the detection
InfractionPlayer infractor = event.getInfractor();
/**
* Obtain the detection performed
* With this object, you can get the pattern,
* the detected string and more.
* @return the detection performed
*/
CheckResult getDetectionResult();
// Get the type of infraction of the event
InfractionType infractionType = event.getType();
// Get the message that was detected
String message = event.getMessage();
}
@Subscribe
public void onPlayerCommandInfraction(CommandViolationEvent event){
// Get the Infractionplayer that was detected in the detection
InfractionPlayer infractor = event.getInfractor();
/**
* Obtain the detection performed
* With this object, you can get the pattern,
* the detected string and more.
* @return the detection performed
*/
CheckResult getDetectionResult();
// Get the type of infraction of the event
InfractionType infractionType = event.getType();
// Get the command that was detected
String command = event.getCommand();
}
An InfractionPlayer is an object that stores a player's infringement variables.
Player player = event.getPlayer();
ChatRegulatorAPI chatRegulator = (ChatregulatorAPI) pluginInstance;
// Based on a Player
InfractionPlayer infractionPlayer = chatRegulator.getPlayerManager().getPlayer(player.getUniqueId());
// -------------------- Getters --------------------
// Get the player's name
String name = infractionPlayer.username();
// Obtain the player's online status
// An InfractionPlayer can be online or offline so that you can use its methods at any time.
boolean online = infractionplayer.isOnline()
// Get the message prior to the player's last message
String preLastMessage = infractionPlayer.preLastMessage();
// Get the last message sent by the player
String lastMessage = infractionPlayer.lastMessage();
// Get the command prior to the player's last command
String preLastCommand = infractionPlayer.preLastCommand();
// Get the last command executed by the player
String lastCommand = infractionPlayer.lastCommand();
/**
* Get the time in milliseconds
* when the player was last seen.
* @return time in microseconds of the
* moment when the user exited
*/
long lastTimeSeen = infractionPlayer.getLastSeen();
/**
* Get the time in milliseconds since the last message of the player
* @return time in milliseconds since the last message
*/
long lastTimeSinceMessage = infractionPlayer.getTimeSinceLastMessage();
/**
* Get the time in milliseconds since the last command of the player
* @return time in milliseconds since the last command
*/
long lastTimeSinceCommand = infractionPlayer.getTimeSinceLastCommand();
/**
* Get the violations count of the player
* @return the violations count
* @since 2.0.0
*/
ViolationCount count = infractionPlayer.getViolations();
// -------------------- Setters --------------------
// Set the player's online status
infractionPlayer.isOnline(boolean status);
// Set the player last message
infractionPlayer.lastMessage(String message);
// Set the player last command
infractionPlayer.lastCommand(String message);
ViolationCount count = infractionPlayer.getViolations();
// Adds a violation to the count of a player's infraction.
count.addViolation(InfractionType type);
// Sets the count of any player infringement.
count.setViolations(InfractionType type, int newViolationsCount);
/**
* Reset the count of infraction of any type of this player
* @param types the types
*/
count.resetViolations(InfractionType... types)
/**
* Get the ammount of violations of any type
* @param type the violation type
* @return the count
*/
int violationCount = count.getCount(InfractionType type)
The checks provide useful information about the detection performed, such as the violation, the resulting pattern and other parameters.
/**
* Get the InfractionType
* @return the infraction type
*/
InfractionType type = check.type();
/**
* Check the detection result
* @return the result
*/
boolean detected = check.isInfraction();
/**
* Gets the regex pattern by which the word was detected.
* @return the regex pattern by which the string was detected
*/
String pattern = check.getPattern();
/**
* Get the word involved in the detection
* @return the infraction word
*/
String infraction = check.getInfractionWord();