Examples
Listen to sofyCore events
Complete example that reacts to rank changes, vanish and moderation events and safely schedules Bukkit work.
import java.util.ArrayList;
import java.util.List;
import net.sofycore.api.SofyCoreApi;
import net.sofycore.api.moderation.ModerationEvent;
import net.sofycore.api.rank.RankStateEvent;
import net.sofycore.api.staff.VanishStateEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public final class SofyListeners {
private final List<AutoCloseable> subs = new ArrayList<>();
public SofyListeners(Plugin plugin, SofyCoreApi api) {
subs.add(api.events().subscribe(RankStateEvent.class, e -> {
if (!e.available) return;
Player p = Bukkit.getPlayer(e.playerId);
if (p != null) plugin.getLogger().info(p.getName() + " rank view revision " + e.revision);
}));
subs.add(api.events().subscribe(VanishStateEvent.class, e ->
plugin.getLogger().info(e.playerId + (e.vanished ? " vanished" : " is visible"))));
subs.add(api.events().subscribe(ModerationEvent.class, e -> {
if (e.sanction != null) plugin.getLogger().info("Sanction " + e.action + ": " + e.sanction.type);
}));
}
public void close() {
for (AutoCloseable s : subs) {
try { s.close(); } catch (Exception ignored) { }
}
subs.clear();
}
}These three events are published on the server thread, so Bukkit calls inside them are safe.