36 lines
1.2 KiB
Java
36 lines
1.2 KiB
Java
package games.dmg.spigotstealth;
|
|
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Function;
|
|
import org.bukkit.entity.Player;
|
|
|
|
/** Marshals unlock presentation onto the server thread. */
|
|
public final class BukkitUnlockNotifier implements Consumer<UUID> {
|
|
private final Function<UUID, Player> playerLookup;
|
|
private final Consumer<Runnable> mainThread;
|
|
private final String chatMessage;
|
|
|
|
public BukkitUnlockNotifier(
|
|
Function<UUID, Player> playerLookup,
|
|
Consumer<Runnable> mainThread,
|
|
String chatMessage) {
|
|
this.playerLookup = Objects.requireNonNull(playerLookup, "playerLookup");
|
|
this.mainThread = Objects.requireNonNull(mainThread, "mainThread");
|
|
this.chatMessage = Objects.requireNonNull(chatMessage, "chatMessage");
|
|
}
|
|
|
|
@Override
|
|
public void accept(UUID playerId) {
|
|
mainThread.accept(() -> {
|
|
Player player = playerLookup.apply(playerId);
|
|
if (player == null || !player.isOnline()) {
|
|
return;
|
|
}
|
|
player.sendTitle("Stealth Unlocked", "Your identity can now be concealed", 10, 100, 20);
|
|
player.sendMessage(chatMessage);
|
|
});
|
|
}
|
|
}
|