add kill player event

This commit is contained in:
Xander 2024-09-21 17:15:58 +02:00
parent ce5af1bffd
commit 113426e0c0
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
2 changed files with 53 additions and 5 deletions

View file

@ -1,9 +1,6 @@
package gent.zeus.mc13dtl.events;
import gent.zeus.mc13dtl.events.catalog.ClimbEvent;
import gent.zeus.mc13dtl.events.catalog.CraftEvent;
import gent.zeus.mc13dtl.events.catalog.KillMobs1Event;
import gent.zeus.mc13dtl.events.catalog.SuicideEvent;
import gent.zeus.mc13dtl.events.catalog.*;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
@ -18,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);
public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 1000);
private long day;
@ -47,6 +44,7 @@ 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);
default -> throw new IllegalStateException("Unexpected day: " + (int) day);
};
event.start();

View file

@ -0,0 +1,50 @@
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;
import java.util.List;
public class KillPlayerEvent extends Event {
private Team huntingTeam;
public KillPlayerEvent(Team team, Difficulty difficulty, int scoreOnSuccess, List<Team> teams) {
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)))) {
huntingTeam = t;
}
}
}
@Override
public void start() {
super.start();
MC13DTL.board.sendMessageToTeam(huntingTeam, Component.text("Your team is being hunted by team " + team.getName()).color(NamedTextColor.BLUE));
}
@EventHandler
@Override
public void onPlayerDeath(PlayerDeathEvent event) {
if (MC13DTL.board.getPlayers(huntingTeam).contains(event.getPlayer()) && MC13DTL.board.getPlayers(team).contains(event.getDamageSource().getCausingEntity())) {
eventSuccess();
} else if (MC13DTL.board.getPlayers(team).contains(event.getPlayer())) {
eventFailed();
}
}
@Override
protected String getMessage() {
return "Your team has to kill another player in team " + huntingTeam.getName() + " before dawn";
}
}