Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Optional In the Wild
package com.krinchan.minecraft.spongediamondfinder.listeners;
import org.slf4j.Logger;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
* Created by david on 2/6/16.
public class StoneBreakingListener {
Logger logger;
public StoneBreakingListener(Logger logger) {
this.logger = logger;
public void handle(ChangeBlockEvent.Break event) throws Exception {
String playerString = event.getCause().first(Player.class) //Returns Optional<Player>
.map(player -> player.getName() + "/" + player.getUniqueId().toString())
String blockName = event.getTransactions().get(0).getFinal().getState().getType().getName();"Player %s broke %s",
playerString, blockName));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment