PreSendQRCodeEvent

The PreSendQRCodeEvent is a custom event in the Bukkit API. It is triggered before a QR code is sent to a player. This event is cancellable, meaning you can prevent the QR code from being sent to the player by cancelling this event in your event handler.

Class Structure

MethodReturn TypeDescription

getPlayer()

Player

Returns the player to whom the QR code is about to be sent.

isCancelled()

boolean

Checks if the event is cancelled.

setCancelled(boolean)

void

Sets the cancellation state of this event. A cancelled event will not be executed in the server, but will still pass to other plugins.

Example Usage

Here is an example of how to listen to this event using the Bukkit event API:

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import ir.taher7.melodymine.api.events.PreSendQRCodeEvent;

public class QRCodeListener implements Listener {

    @EventHandler
    public void onPreSendQRCode(PreSendQRCodeEvent event) {
        // Get the player to whom the QR code is about to be sent
        Player player = event.getPlayer();

        // Print a message to the console
        Bukkit.getLogger().info("About to send a QR code to " + player.getName());

        // You can cancel the event to prevent the QR code from being sent
        // For example, let's not send the QR code to players named "TAHER7"
        if (player.getName().equalsIgnoreCase("TAHER7")) {
            event.setCancelled(true);
            Bukkit.getLogger().info("Cancelled sending QR code to " + player.getName());
        }
    }
}

In this example, we're listening for the PreSendQRCodeEvent. When the event is triggered, we're logging a message to the console. If the player's name is "TAHER7", we're cancelling the event, which prevents the QR code from being sent, and logging another message to the console.

Remember to register your event listener in your plugin's onEnable() method, otherwise Bukkit won't know to pass events to it.

Last updated