/*
 * Copyright 2016 Ali Moghnieh
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.blurengine.blur;

import com.blurengine.blur.events.players.PlayerMoveBlockEvent;
import com.blurengine.blur.session.BlurPlayer;
import com.supaham.commons.bukkit.utils.EventUtils;
import com.supaham.commons.bukkit.utils.LocationUtils;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;

class BlurListener implements Listener {

    private final BlurPlugin plugin;

    public BlurListener(BlurPlugin plugin) {
        this.plugin = plugin;
    }

    @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
    public void callPlayerMoveBlockEvent(PlayerMoveEvent event) {
        if (!LocationUtils.isSameBlock(event.getFrom(), event.getTo())) {
            BlurPlayer blurPlayer = plugin.getBlur().getPlayer(event.getPlayer());
            if (blurPlayer.getSession() != null) {
                EventUtils.callEvent(new PlayerMoveBlockEvent(event, blurPlayer));
            }
        }
    }
}

@@ -620,16 +620,83 @@
 .blur;%0A%0A
+import com.blurengine.blur.events.players.PlayerDamagePlayerEvent;%0A
 import c
@@ -906,16 +906,121 @@
 Utils;%0A%0A
+import org.bukkit.entity.Entity;%0Aimport org.bukkit.entity.LivingEntity;%0Aimport org.bukkit.entity.Player;%0A
 import o
@@ -1150,32 +1150,248 @@
 ent.
-player.PlayerMoveEvent;%0A
+entity.EntityDamageByEntityEvent;%0Aimport org.bukkit.event.player.PlayerMoveEvent;%0A%0A/*%0A * All events extend LOW to call Blur events at an early enough point in time that other code will be able to cancel these Bukkit events if necessary.%0A */
 %0Acla
@@ -2007,11 +2007,732 @@
  %7D%0A    %7D
+%0A%0A    @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)%0A    public void callPlayerDamagePlayerEvent(EntityDamageByEntityEvent event) %7B%0A        LivingEntity damager = EventUtils.getLivingEntityDamager(event);%0A        if (event.getEntity() instanceof Player && damager instanceof Player) %7B%0A            BlurPlayer blurDamager = plugin.getBlur().getPlayer((Player) damager);%0A            BlurPlayer blurVictim = plugin.getBlur().getPlayer((Player) event.getEntity());%0A            %0A            PlayerDamagePlayerEvent damageEvent = new PlayerDamagePlayerEvent(blurDamager, blurVictim, event);%0A            if (damageEvent.isCancelled()) %7B%0A                event.setCancelled(true);%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

Call PlayerDamagePlayerEvent in BlurListener with LOW priority.