KillMobs2Event

This commit is contained in:
Mathieu Strypsteen 2024-09-22 15:37:37 +02:00
parent 2646b965ac
commit 6d2af423fd
2 changed files with 52 additions and 2 deletions

View file

@ -15,7 +15,7 @@ import gent.zeus.mc13dtl.MC13DTL;
public class EventRunner implements Runnable { public class EventRunner implements Runnable {
static List<Event> currentEvents = new ArrayList<>(); static List<Event> currentEvents = new ArrayList<>();
public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 100, 1000, 500, 10000, 100); public static List<Integer> startTimes = List.of(5000, 13000, 1000, 13000, 100, 1000, 500, 10000, 5000, 100);
private long day; private long day;
@ -48,7 +48,8 @@ public class EventRunner implements Runnable {
case 5 -> new KillPlayerEvent(team, difficulty, getDayScore()); case 5 -> new KillPlayerEvent(team, difficulty, getDayScore());
case 6 -> new StructureEvent(team, difficulty, getDayScore()); case 6 -> new StructureEvent(team, difficulty, getDayScore());
case 7 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore()); case 7 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore());
case 8 -> new EndEvent(team, difficulty, getDayScore()); // TODO: Move to last day case 8 -> new KillSurvivingTeamEvent(team, difficulty, getDayScore());
case 9 -> new EndEvent(team, difficulty, getDayScore()); // TODO: Move to last day
default -> throw new IllegalStateException("Unexpected day: " + (int) day); default -> throw new IllegalStateException("Unexpected day: " + (int) day);
}; };
event.start(); event.start();

View file

@ -0,0 +1,49 @@
package gent.zeus.mc13dtl.events.catalog;
import com.mojang.datafixers.util.Pair;
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.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.scoreboard.Team;
import java.util.Map;
public class KillMobs2Event extends Event {
private int killsLeft;
private final EntityType monster;
public KillMobs2Event(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
Map<Difficulty, Pair<EntityType, Integer>> monsters = Map.of(
Difficulty.BABY, new Pair<>(EntityType.CREEPER, 3),
Difficulty.EASY, new Pair<>(EntityType.PIGLIN, 3),
Difficulty.MEDIUM, new Pair<>(EntityType.GHAST, 2),
Difficulty.HARD, new Pair<>(EntityType.BLAZE, 3),
Difficulty.IMPOSSIBLE, new Pair<>(EntityType.WITHER, 1));
monster = monsters.get(difficulty).getFirst();
killsLeft = monsters.get(difficulty).getSecond();
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity().getType() == monster && MC13DTL.board.getPlayers(team).contains(event.getDamageSource().getCausingEntity())) {
killsLeft--;
if (killsLeft == 0) {
eventSuccess();
} else {
MC13DTL.board.sendMessageToTeam(team, Component.text(killsLeft + " left.").color(NamedTextColor.BLUE));
}
}
}
@Override
protected String getMessage() {
return "Your team has to kill " + killsLeft + " " + monster.toString() + " before dawn";
}
}