Add event for day 2

This commit is contained in:
Xander 2024-09-21 15:04:07 +02:00
parent 5c488dc8e1
commit 4d0702e1cf
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
3 changed files with 63 additions and 3 deletions

View file

@ -22,9 +22,12 @@ public abstract class Event implements Listener, Runnable {
this.team = team; this.team = team;
this.difficulty = difficulty; this.difficulty = difficulty;
this.scoreOnSuccess = scoreOnSuccess; this.scoreOnSuccess = scoreOnSuccess;
}
public void start() {
MC13DTL.board.sendMessageToTeam(team, Component.text("Difficulty is " + this.difficulty.toString())); MC13DTL.board.sendMessageToTeam(team, Component.text("Difficulty is " + this.difficulty.toString()));
MC13DTL.board.sendMessageToTeam(team, Component.text(getMessage()).color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC)); MC13DTL.board.sendMessageToTeam(team, Component.text(getMessage()).color(NamedTextColor.GRAY).decorate(TextDecoration.ITALIC));
MC13DTL.instance.getServer().getPluginManager().registerEvents(this, MC13DTL.instance); MC13DTL.instance.getServer().getPluginManager().registerEvents(this, MC13DTL.instance);
BukkitScheduler scheduler = MC13DTL.instance.getServer().getScheduler(); BukkitScheduler scheduler = MC13DTL.instance.getServer().getScheduler();
taskId = scheduler.runTaskTimer(MC13DTL.instance, this, 0, 20).getTaskId(); taskId = scheduler.runTaskTimer(MC13DTL.instance, this, 0, 20).getTaskId();

View file

@ -1,5 +1,6 @@
package gent.zeus.mc13dtl.events; package gent.zeus.mc13dtl.events;
import gent.zeus.mc13dtl.events.catalog.KillMobs1Event;
import gent.zeus.mc13dtl.events.catalog.SuicideEvent; import gent.zeus.mc13dtl.events.catalog.SuicideEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -16,7 +17,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); public static List<Integer> startTimes = List.of(5000, 13000);
private long day; private long day;
@ -40,9 +41,12 @@ public class EventRunner implements Runnable {
for (int i = 0; i < teams.size() && i < difficulties.size(); i++) { for (int i = 0; i < teams.size() && i < difficulties.size(); i++) {
Team team = teams.get(i); Team team = teams.get(i);
Difficulty difficulty = difficulties.get(i); Difficulty difficulty = difficulties.get(i);
switch ((int) day) { Event event = switch ((int) day) {
case 0 -> new SuicideEvent(team, difficulty, getDayScore()); case 0 -> new SuicideEvent(team, difficulty, getDayScore());
} case 1 -> new KillMobs1Event(team, difficulty, getDayScore());
default -> throw new IllegalStateException("Unexpected day: " + (int) day);
};
event.start();
} }
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day); world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day);
} }

View file

@ -0,0 +1,53 @@
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.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.scoreboard.Team;
import java.util.Map;
public class KillMobs1Event extends Event implements Listener {
private int killsLeft;
private final EntityType monster;
public KillMobs1Event(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
Map<Difficulty, Pair<EntityType, Integer>> monsters = Map.of(
Difficulty.BABY, new Pair<>(EntityType.ZOMBIE, 1),
Difficulty.EASY, new Pair<>(EntityType.ZOMBIE, 3),
Difficulty.MEDIUM, new Pair<>(EntityType.ZOMBIE, 6),
Difficulty.HARD, new Pair<>(EntityType.SKELETON, 5),
Difficulty.IMPOSSIBLE, new Pair<>(EntityType.ENDERMAN, 4)
);
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();
}
}