SteamWar/FightSystem
Archiviert
13
1

AmongUS #367

Zusammengeführt
Lixfel hat 9 Commits von AmongUS nach master 2022-10-08 18:30:11 +02:00 zusammengeführt
Nur Änderungen aus Commit b24e9a8b89 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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<FightPlayer> fightPlayers) {
List<FightPlayer> 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());
}
}