Listening
Describes a way to execute functions when an event is called
package com.example.plugin.listeners;
import net.snackbag.cottonpowered.api.event.Event;
import net.snackbag.cottonpowered.api.event.Listener;
import net.snackbag.cottonpowered.api.event.PlayerJoinEvent;
import net.snackbag.cottonpowered.api.plugin.CottonPlugin;
// Create the Listener which should extend Cotton's Listener
public class JoinListener extends Listener {
public JoinListener(CottonPlugin plugin) {
// We specify which plugin uses this Listener and which
// event we're listening to
super(plugin, new PlayerJoinEvent());
}
@Override
// This function will be executed when the event is called
public void onEvent(Event e) {
// Because we get back an Event class and not a
// PlayerJoinEvent, we will have to cast it.
PlayerJoinEvent event = (PlayerJoinEvent) e;
// We can use the PlayerJoinEvent's getPlayer() method
// to get which player just joined
event.getPlayer().sendMessage("You joined");
}
}Last updated