Skip to content

Plugin API

4drian3d edited this page Dec 10, 2021 · 10 revisions

This guide is updated for version 2.0.0 of the plugin, several things have changed that do not work in version 1.x.x.

Currently the plugin has 2 events and methods to handle InfractionPlayers.

Events

ChatViolationEvent

@Subscribe
public void onPlayerMessageInfraction(ChatViolationEvent event){
    // --------------------- Getters ---------------------
    // Get the Infractionplayer that was detected in the detection
    InfractionPlayer infractionPlayer = event.getInfractionPlayer();

    /**
     * Obtain the detection performed
     * With this object, you can get the pattern,
     * the detected string and more.
     * @return the detection performed
     */
    AbstractCheck check = event.getDetection();

    // Get the type of infraction of the event
    InfractionType infractionType = event.getType();

    // Get the message that was detected
    String message = event.getMessage();

    // Get the result of the event, if it is cancelled or allowed
    GenericResult result = event.getResult();
    
    // --------------------- Setters ---------------------
    // Sets the status of the event. Here you can cancel the event
    event.setResult(result);
}

CommandViolationEvent

@Subscribe
public void onPlayerCommandInfraction(CommandViolationEvent event){
    // --------------------- Getters ---------------------
    // Get the Infractionplayer that was detected in the detection
    InfractionPlayer infractionPlayer = event.getInfractionPlayer();

    /**
     * Obtain the detection performed
     * With this object, you can get the pattern,
     * the detected string and more.
     * @return the detection performed
     */
    AbstractCheck check = event.getDetection();

    // Get the type of infraction of the event
    InfractionType infractionType = event.getType();

    // Get the command that was detected
    String command = event.getCommand();

    // Get the result of the event, if it is cancelled or allowed
    GenericResult result = event.getResult();
    
    // --------------------- Setters ---------------------
    // Sets the status of the event. Here you can cancel the event
    event.setResult(result);
}

Objects

InfractionPlayer

An InfractionPlayer is an object that stores a player's infringement variables.

Get a InfractionPlayer

Player player = event.getPlayer();

// Based on a Player
InfractionPlayer infractionPlayer = InfractionPlayer.get(player);

//Based on an UUID
InfractionPlayer infractionPlayer = InfractionPlayer.get(player.getUniqueId());

InfractionPlayer Methods

// -------------------- 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 methods

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)

Checks

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();