Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Optional In the Wild
package com.krinchan.minecraft.spongediamondfinder.listeners;
import org.slf4j.Logger;
import org.spongepowered.api.entity.living.player.Player;
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;
}
@Listener
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())
.orElse("UNKNOWN");
String blockName = event.getTransactions().get(0).getFinal().getState().getType().getName();
logger.info(String.format("Player %s broke %s",
playerString, blockName));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.