package com.blocklaunch.blwarps.eventhandlers;

import com.blocklaunch.blwarps.Warp;
import com.blocklaunch.blwarps.data.WarpKeys;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.tileentity.Sign;
import org.spongepowered.api.block.tileentity.TileEntityTypes;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.InteractBlockEvent;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.Optional;

/**
 * Listens for Players interacting with blocks If
 */
public class InteractBlockEventHandler {

    @Listener
    // InteractBlockEvent.Secondary = right click
            public
            void handle(InteractBlockEvent.Secondary event) throws Exception {
        if (!event.getTargetBlock().getLocation().isPresent()) {
            return;
        }

        Location<World> block = event.getTargetBlock().getLocation().get();

        // Ensure the block is a tile entity
        if (!block.getTileEntity().isPresent()) {
            return;
        }

        // Ensure the tile entity is a sign
        if (!(block.getTileEntity().get().getType() == TileEntityTypes.SIGN)) {
            return;
        }

        Sign sign = (Sign) block.getTileEntity().get();

        Optional<Warp> optWarp = sign.get(WarpKeys.WARP);
        if (!optWarp.isPresent()) {
            // Sign is not a warp sign
            return;
        }

        String command = "warp " + optWarp.get().getName();

        Optional<Player> player = event.getCause().first(Player.class);

        if (!player.isPresent()) {
            return;
        }

        Sponge.getCommandManager().process(player.get(), command);
    }

}

@@ -41,16 +41,72 @@
 dlers;%0A%0A
+import org.spongepowered.api.event.filter.cause.First;%0A%0A
 import c
@@ -134,16 +134,16 @@
 s.Warp;%0A
-
 import c
@@ -853,16 +853,38 @@
 ry event
+, @First Player player
 ) throws
@@ -1636,147 +1636,8 @@
 );%0A%0A
-        Optional%3CPlayer%3E player = event.getCause().first(Player.class);%0A%0A        if (!player.isPresent()) %7B%0A            return;%0A        %7D%0A%0A
     
@@ -1681,22 +1681,16 @@
 s(player
-.get()
 , comman

Use the @First annotation to specify a Player causing the block interaction