From e03c60356fd13ba0e13d6d78a1c5ac26ae2268b9 Mon Sep 17 00:00:00 2001 From: Xander Date: Sat, 21 Sep 2024 15:32:11 +0200 Subject: [PATCH] Add event for day 3 --- .../gent/zeus/mc13dtl/events/EventRunner.java | 4 +- .../mc13dtl/events/catalog/CraftEvent.java | 39 +++++++++++++++++++ .../events/catalog/KillMobs1Event.java | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/main/java/gent/zeus/mc13dtl/events/catalog/CraftEvent.java diff --git a/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java b/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java index 7c0bd29..dcffeaa 100644 --- a/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java +++ b/src/main/java/gent/zeus/mc13dtl/events/EventRunner.java @@ -1,5 +1,6 @@ package gent.zeus.mc13dtl.events; +import gent.zeus.mc13dtl.events.catalog.CraftEvent; import gent.zeus.mc13dtl.events.catalog.KillMobs1Event; import gent.zeus.mc13dtl.events.catalog.SuicideEvent; import org.bukkit.Bukkit; @@ -17,7 +18,7 @@ import gent.zeus.mc13dtl.MC13DTL; public class EventRunner implements Runnable { static List currentEvents = new ArrayList<>(); - public static List startTimes = List.of(5000, 13000); + public static List startTimes = List.of(5000, 13000, 1000); private long day; @@ -44,6 +45,7 @@ public class EventRunner implements Runnable { Event event = switch ((int) day) { case 0 -> new SuicideEvent(team, difficulty, getDayScore()); case 1 -> new KillMobs1Event(team, difficulty, getDayScore()); + case 2 -> new CraftEvent(team, difficulty, getDayScore()); default -> throw new IllegalStateException("Unexpected day: " + (int) day); }; event.start(); diff --git a/src/main/java/gent/zeus/mc13dtl/events/catalog/CraftEvent.java b/src/main/java/gent/zeus/mc13dtl/events/catalog/CraftEvent.java new file mode 100644 index 0000000..17a2491 --- /dev/null +++ b/src/main/java/gent/zeus/mc13dtl/events/catalog/CraftEvent.java @@ -0,0 +1,39 @@ +package gent.zeus.mc13dtl.events.catalog; + +import gent.zeus.mc13dtl.MC13DTL; +import gent.zeus.mc13dtl.events.Difficulty; +import gent.zeus.mc13dtl.events.Event; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.scoreboard.Team; + + +public class CraftEvent extends Event { + + private final Material item; + + public CraftEvent(Team team, Difficulty difficulty, int scoreOnSuccess) { + super(team, difficulty, scoreOnSuccess); + item = switch (difficulty) { + case BABY -> Material.SHIELD; + case EASY -> Material.ENCHANTING_TABLE; + case MEDIUM -> Material.REDSTONE_LAMP; + case HARD -> Material.BREWING_STAND; + case SWEAT -> Material.STICKY_PISTON; + case IMPOSSIBLE -> Material.BEACON; + }; + } + + @EventHandler + public void onPlayerCraft(CraftItemEvent event) { + if (event.getRecipe().getResult().getType() == item && MC13DTL.board.getPlayers(team).contains(event.getWhoClicked())) { + eventSuccess(); + } + } + + @Override + protected String getMessage() { + return "Craft the following item before dawn: " + item.toString(); + } +} diff --git a/src/main/java/gent/zeus/mc13dtl/events/catalog/KillMobs1Event.java b/src/main/java/gent/zeus/mc13dtl/events/catalog/KillMobs1Event.java index 1a33459..d5849d2 100644 --- a/src/main/java/gent/zeus/mc13dtl/events/catalog/KillMobs1Event.java +++ b/src/main/java/gent/zeus/mc13dtl/events/catalog/KillMobs1Event.java @@ -48,6 +48,6 @@ public class KillMobs1Event extends Event implements Listener { @Override protected String getMessage() { - return "Your team has to kill " + killsLeft + " " + monster.toString(); + return "Your team has to kill " + killsLeft + " " + monster.toString() + " before dawn"; } }