add kill best surviving team event

# Conflicts:
#	src/main/java/gent/zeus/mc13dtl/events/EventRunner.java
This commit is contained in:
Xander 2024-09-21 19:35:12 +02:00
parent ad6b6966e0
commit 6ebb48f7ce
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
4 changed files with 58 additions and 9 deletions

View file

@ -97,7 +97,7 @@ public class TeamScoreBoard {
List<Player> players = new ArrayList<>();
for (String entry : team.getEntries()) {
Player player = Bukkit.getPlayer(entry);
if (player != null) {
if (player != null && player.isOnline()) {
players.add(player);
}
}

View file

@ -15,7 +15,7 @@ import gent.zeus.mc13dtl.MC13DTL;
public class EventRunner implements Runnable {
static List<Event> currentEvents = new ArrayList<>();
public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 1000, 500);
public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 1000, 500, 10000);
private long day;
@ -44,8 +44,9 @@ public class EventRunner implements Runnable {
case 1 -> new KillMobs1Event(team, difficulty, getDayScore());
case 2 -> new CraftEvent(team, difficulty, getDayScore());
case 3 -> new ClimbEvent(team, difficulty, getDayScore());
case 4 -> new KillPlayerEvent(team, difficulty, getDayScore(), teams);
case 4 -> new KillPlayerEvent(team, difficulty, getDayScore());
case 5 -> new StructureEvent(team, difficulty, getDayScore());
case 6 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore());
default -> throw new IllegalStateException("Unexpected day: " + (int) day);
};
event.start();

View file

@ -9,18 +9,19 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.scoreboard.Team;
import java.util.List;
public class KillPlayerEvent extends Event {
private Team huntingTeam;
public KillPlayerEvent(Team team, Difficulty difficulty, int scoreOnSuccess, List<Team> teams) {
public KillPlayerEvent(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
for (Team t : teams) {
if (t != team && (huntingTeam == null ||
Math.abs(MC13DTL.board.getScore(t) - MC13DTL.board.getScore(team)) < Math.abs(MC13DTL.board.getScore(huntingTeam) - MC13DTL.board.getScore(team)))) {
for (Team t : MC13DTL.board.getTeams()) {
if (!MC13DTL.board.getPlayers(t).isEmpty()
&& t != team
&& (huntingTeam == null ||
Math.abs(MC13DTL.board.getScore(t) - MC13DTL.board.getScore(team)) < Math.abs(MC13DTL.board.getScore(huntingTeam) - MC13DTL.board.getScore(team))
)) {
huntingTeam = t;
}
}

View file

@ -0,0 +1,47 @@
package gent.zeus.mc13dtl.events.catalog;
import gent.zeus.mc13dtl.MC13DTL;
import gent.zeus.mc13dtl.events.Difficulty;
import gent.zeus.mc13dtl.events.Event;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.scoreboard.Team;
public class KillSurvivingTeamEvent extends Event {
private Team huntingTeam;
public KillSurvivingTeamEvent(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
for (Team t : MC13DTL.board.getTeams()) {
if (!MC13DTL.board.getPlayers(t).isEmpty()
&& (huntingTeam == null || MC13DTL.board.getDaysAlive(t) > MC13DTL.board.getDaysAlive(huntingTeam)
)) {
huntingTeam = t;
}
}
}
@EventHandler
@Override
public void onPlayerDeath(PlayerDeathEvent event) {
if (MC13DTL.board.getPlayers(team).contains(event.getPlayer())) {
eventFailed();
} else if (MC13DTL.board.getPlayers(huntingTeam).contains(event.getPlayer())) {
eventSuccess();
}
}
@Override
protected String getMessage() {
if (team.getName().equals(huntingTeam.getName())) {
return "Your team is being hunted by everyone!!! RUN";
} else {
return "A member of team " + huntingTeam.getName() + " has to die before dawn because this team has survived the longest (cross teaming is allowed)";
}
}
}