From b24e9a8b89839c5d5c56ebe689cfb39bb3a7b934 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 8 Oct 2022 17:00:44 +0200 Subject: [PATCH] Add message --- .../winconditions/WinconditionAmongUs.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java index 720fec9..3b1ece5 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAmongUs.java @@ -22,15 +22,22 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; +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.PlayerQuitEvent; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Random; -public class WinconditionAmongUs extends Wincondition { +public class WinconditionAmongUs extends Wincondition implements Listener { private final Random random = new Random(); @@ -43,10 +50,35 @@ public class WinconditionAmongUs extends Wincondition { FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", redPlayer.getPlayer()); FightSystem.getMessage().send("AMONG_US_IMPOSTER_MESSAGE", bluePlayer.getPlayer()); }); + new StateDependentListener(Winconditions.AMONG_US, FightState.Ingame, this); } private FightPlayer getRandomPlayer(Collection fightPlayers) { List fightPlayerList = new ArrayList<>(fightPlayers); return fightPlayerList.get(random.nextInt(fightPlayerList.size())); } + + @EventHandler + public void handlePlayerDeath(PlayerDeathEvent event) { + handleDeath(event.getEntity().getPlayer()); + } + + @EventHandler + public void handlePlayerQuit(PlayerQuitEvent event) { + handleDeath(event.getPlayer()); + } + + private void handleDeath(Player player){ + // TODO: Adapt this + FightTeam team = isTarget(player); + if(team == null) + return; + + for(FightPlayer fp : team.getPlayers()) { + if(fp.isLiving() && fp.getPlayer() != player) + return; + } + + win(Fight.getOpposite(team), "WIN_ALL_DEAD", team.getPrefix()); + } }