/*
 * This file is part of SpongeSurvivalGamesPlugin, licensed under the MIT License (MIT).
 *
 * Copyright (c) Matthew Broomfield <m0pt0pmatt17@gmail.com>
 * Copyright (c) contributors
 *
 * 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.m0pt0pmatt.spongesurvivalgames.events;

import io.github.m0pt0pmatt.spongesurvivalgames.BukkitSurvivalGamesPlugin;
import io.github.m0pt0pmatt.spongesurvivalgames.SurvivalGameState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;

/**
 * Listener class for the plugin.
 */
@SuppressWarnings("unused")
public class PlayerEventListener implements Listener {

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {

        Player player = event.getEntity();
        BukkitSurvivalGamesPlugin.survivalGameMap.values()
                .parallelStream()
                .filter( g -> g.getState().equals(SurvivalGameState.RUNNING) || g.getState().equals(SurvivalGameState.DEATHMATCH))
                .filter( g -> g.getPlayerUUIDs().contains(player.getUniqueId()))
                .forEach(g -> {
                    g.reportDeath(player.getUniqueId());
                    player.setBedSpawnLocation(g.getExitLocation().get(), true);
                });
    }

    @EventHandler
    public void onPlayerDisconnect(PlayerQuitEvent event) {

        Player player = event.getPlayer();
        BukkitSurvivalGamesPlugin.survivalGameMap.values()
                .parallelStream()
                .filter( g -> g.getPlayerUUIDs().contains(player.getUniqueId()))
                .forEach(g -> g.reportDeath(player.getUniqueId()));
    }

    @EventHandler
    public void onPlayerUseBed(PlayerBedEnterEvent event){

        Player player = event.getPlayer();
        if (BukkitSurvivalGamesPlugin.survivalGameMap.values()
                .parallelStream()
                .filter( g -> g.getPlayerUUIDs().contains(player.getUniqueId()))
                .count() > 0) event.setCancelled(true);
    }

    @EventHandler
    public void event(PlayerKickEvent event){
        Player player = event.getPlayer();
        BukkitSurvivalGamesPlugin.survivalGameMap.values()
                .parallelStream()
                .filter( g -> g.getPlayerUUIDs().contains(player.getUniqueId()))
                .forEach(g -> g.reportDeath(player.getUniqueId()));
    }
}

@@ -1560,24 +1560,74 @@
 t.Listener;%0A
+import org.bukkit.event.entity.EntityDamageEvent;%0A
 import org.b
@@ -1936,16 +1936,632 @@
 stener %7B
+%0A%09%0A%09@EventHandler%0A%09public void onPlayerStupid(EntityDamageEvent e) %7B%0A%09%09if (!(e.getEntity() instanceof Player)) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09%0A%09%09Player player = (Player) e.getEntity();%0A%09%09%0A%09%09long count = BukkitSurvivalGamesPlugin.survivalGameMap.values().parallelStream()%0A        %09.filter( g -%3E g.getState().equals(SurvivalGameState.RUNNING) %7C%7C g.getState().equals(SurvivalGameState.DEATHMATCH))%0A        %09.filter( g -%3E g.getPlayerUUIDs().contains(player.getUniqueId()))%0A        %09.count();%0A%09%09%0A%09%09if (count %3C 1) %7B%0A%09%09%09e.setCancelled(true);%0A%09%09%7D%0A%09%09%0A%09%09System.out.print(%22omffffffffffffffffffffuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuug%22);%0A%09%09%0A%09%09%0A%09%7D
 %0A%0A    @E

stop damage from happening to non-players