/*
 * MIT License
 *
 * Copyright (c) 2017 Connor Hartley
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package io.github.connorhartley.guardian.sequence;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.MoveEntityEvent;
import org.spongepowered.api.event.filter.Getter;
import org.spongepowered.api.event.filter.cause.First;
import org.spongepowered.api.service.user.UserStorageService;

public class SequenceListener {

    private final SequenceController sequenceController;
    private final UserStorageService userStorageService;

    public SequenceListener(SequenceController sequenceController) {
        this.sequenceController = sequenceController;
        this.userStorageService = Sponge.getServiceManager().provide(UserStorageService.class).orElseThrow(() ->
                new IllegalStateException("SequenceListener was attempted to be loaded before UserStorageService object was provided."));
    }

    /*
     * Listeners will go here. For example:
     *
     * @Listener
     * public void onEntityCollide(CollideEntityEvent event, @First Player player) {
     *     this.userStorageService.get(player.getUniqueId()).ifPresent(user -> this.sequenceController.invoke(user, event));
     * }
     */

    @Listener
    public void onEntityMove(MoveEntityEvent event, @Getter(value = "getTargetEntity") Player player) {
        this.sequenceController.invoke(player, event);
    }

}

@@ -1186,45 +1186,8 @@
 e;%0A%0A
-import org.spongepowered.api.Sponge;%0A
 impo
@@ -1397,125 +1397,8 @@
 ter;
-%0Aimport org.spongepowered.api.event.filter.cause.First;%0Aimport org.spongepowered.api.service.user.UserStorageService;
 %0A%0Apu
@@ -1488,65 +1488,8 @@
 ler;
-%0A    private final UserStorageService userStorageService;
 %0A%0A  
@@ -1613,259 +1613,8 @@
 er;%0A
-        this.userStorageService = Sponge.getServiceManager().provide(UserStorageService.class).orElseThrow(() -%3E%0A                new IllegalStateException(%22SequenceListener was attempted to be loaded before UserStorageService object was provided.%22));%0A
     
@@ -1757,13 +1757,33 @@
 t, @
-First
+Getter(%22getTargetEntity%22)
  Pla
@@ -1810,76 +1810,8 @@
     
- this.userStorageService.get(player.getUniqueId()).ifPresent(user -%3E
  thi
@@ -1838,18 +1838,20 @@
 .invoke(
-us
+play
 er, even
@@ -1852,17 +1852,16 @@
 , event)
-)
 ;%0A     *
@@ -1950,16 +1950,8 @@
 ter(
-value = 
 %22get

Tweak sequence listener