SteamWar/FightSystem
Archiviert
13
1

Add message
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-10-08 17:00:44 +02:00
Ursprung b750433f91
Commit b24e9a8b89

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());
}
}