Skip to content

Plugin API

4drian3d edited this page Dec 8, 2021 · 11 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();

    // 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(GenericResult result);
}

CommandViolationEvent

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

    // 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(GenericResult 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.preLastMessage();

// Get the last command executed by the player
String lastCommand = infractionPlayer.lastCommand();

// Get the amount of flood infractions the player already has.
int floodInfractions = infractionPlayer.getFloodInfractions();

// Get the amount of regular infractions the player already has.
int regularInfractions = infractionPlayer.getRegularInfractions();

// Get the amount of spam infractions the player already has.
int spamInfractions = infractionPlayer.getSpamInfractions();

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

// Adds a violation to the count of a player's infraction.
infractionPlayer.addViolation(InfractionType type);

// Sets the count of any player infringement.
infractionPlayer.setViolations(InfractionType type, int newViolationsCount);

Clone this wiki locally