From 4903b3354d27ed6e19bf718c4464f2271c962ba5 Mon Sep 17 00:00:00 2001 From: SEG Date: Sun, 2 Jun 2024 14:55:31 -0600 Subject: [PATCH 1/4] feat(event): define the event priority in the game event model --- .../devblook/pepitocore/plugin/module/event/EventPool.java | 2 +- .../pepitocore/plugin/module/event/model/GameEvent.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java index 379b6eb..965b075 100644 --- a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java +++ b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java @@ -72,7 +72,7 @@ public void run() { Bukkit.getPluginManager().registerEvent( entry.getKey(), current, - EventPriority.NORMAL, + current.priority(), entry.getValue(), plugin ); diff --git a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java index 6d75143..a30bb83 100644 --- a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java +++ b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java @@ -5,6 +5,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.title.Title; import org.bukkit.event.Event; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import team.devblook.pepitocore.api.Identity; import team.devblook.pepitocore.plugin.module.event.GameEventExecutor; @@ -39,4 +40,8 @@ default void end() { default Map, GameEventExecutor> events() { return DEFAULT_EVENTS; } + + default EventPriority priority() { + return EventPriority.NORMAL; + } } \ No newline at end of file From 059f4c1ffee273582009a31fe5f46522f9e8f97e Mon Sep 17 00:00:00 2001 From: SEG Date: Sun, 2 Jun 2024 14:55:58 -0600 Subject: [PATCH 2/4] feat(event): add a method in the game event model to be able to subtract the duration of the event from the interval --- .../devblook/pepitocore/plugin/module/event/EventPool.java | 7 ++++++- .../pepitocore/plugin/module/event/model/GameEvent.java | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java index 965b075..15ad624 100644 --- a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java +++ b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java @@ -95,9 +95,14 @@ public void run() { } } + int interval = configuration.get().getInt("events.interval", 10); + + if (current.subtractDuration()) { + interval -= current.duration(); + } + current = null; - int interval = configuration.get().getInt("events.interval", 10); if (interval < 1) { run(); return; diff --git a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java index a30bb83..eb1321b 100644 --- a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java +++ b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/model/GameEvent.java @@ -44,4 +44,8 @@ default Map, GameEventExecutor> events() default EventPriority priority() { return EventPriority.NORMAL; } + + default boolean subtractDuration() { + return false; + } } \ No newline at end of file From 15b8582104eedd12608f84f2d6559ae4ec4f87a7 Mon Sep 17 00:00:00 2001 From: SEG Date: Sun, 2 Jun 2024 14:56:10 -0600 Subject: [PATCH 3/4] feat(skip-night): ignore the bed enter event if it is cancelled --- .../plugin/module/sleep/listener/SkipSleepListener.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/sleep/listener/SkipSleepListener.java b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/sleep/listener/SkipSleepListener.java index 725b44e..03a6216 100644 --- a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/sleep/listener/SkipSleepListener.java +++ b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/sleep/listener/SkipSleepListener.java @@ -22,6 +22,10 @@ public void onEnterBed(PlayerBedEnterEvent event) { return; } + if (event.isCancelled()) { + return; + } + int sleeping = SLEEPING.incrementAndGet(); int needed = needed(); From 9c2d538a4352e8f38a2b03da1c516ec30f057dba Mon Sep 17 00:00:00 2001 From: SEG Date: Sun, 2 Jun 2024 14:56:33 -0600 Subject: [PATCH 4/4] feat(event): add insomnia game mode event --- .../plugin/module/event/EventPool.java | 3 +- .../plugin/module/event/type/Insomnia.java | 123 ++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/type/Insomnia.java diff --git a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java index 15ad624..14f650e 100644 --- a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java +++ b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/EventPool.java @@ -26,7 +26,8 @@ public class EventPool implements Runnable { new SuperJumpEvent(), new OneHeartEvent(), new IncreasedMobDamageEvent(), - new AdventureEvent() + new AdventureEvent(), + new Insomnia() ); private @Inject Plugin plugin; diff --git a/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/type/Insomnia.java b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/type/Insomnia.java new file mode 100644 index 0000000..00b8872 --- /dev/null +++ b/plugin/src/main/java/team/devblook/pepitocore/plugin/module/event/type/Insomnia.java @@ -0,0 +1,123 @@ +package team.devblook.pepitocore.plugin.module.event.type; + +import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.title.Title; +import org.bukkit.Bukkit; +import org.bukkit.event.Event; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerBedEnterEvent; +import team.devblook.pepitocore.plugin.module.event.GameEventExecutor; +import team.devblook.pepitocore.plugin.module.event.model.GameEvent; + +import java.time.Duration; +import java.util.Map; + +public class Insomnia implements GameEvent { + + private final BossBar bossBar = BossBar.bossBar( + this::name, + 1.0f, + BossBar.Color.BLUE, + BossBar.Overlay.PROGRESS + ); + + @Override + public Component name() { + return Component.text("ɪɴѕᴏᴍɴɪᴏ", TextColor.fromHexString("#2661e0")); + } + + @Override + public Component description() { + return Component.text() + .appendNewline() + .appendNewline() + .appendNewline() + .appendNewline() + .append(Component.text("¡No podrás dormir!", TextColor.fromHexString("#2661e0"))) + .appendNewline() + .appendNewline() + .append(Component.text(" Ahora es de noche y parece que por el mal día no puedes", TextColor.color(0xE4FFE5))) + .appendNewline() + .append(Component.text(" dormir, cuidado con los peligros de la noche.", TextColor.color(0xE4FFE5))) + .appendNewline() + .appendNewline() + .appendNewline() + .build(); + } + + @Override + public Title title() { + return Title.title( + Component.text("¡ɪɴѕᴏᴍɴɪᴏ!", TextColor.fromHexString("#2661e0")), + Component.text("Nos quedamos sin píldoras para dormir", TextColor.color(0xE4FFE5)), + Title.Times.times( + Duration.ofSeconds(2), + Duration.ofSeconds(5), + Duration.ofSeconds(2) + ) + ); + } + + @Override + public Sound sound() { + return Sound.sound( + Key.key("minecraft", "entity.enderman.death"), + Sound.Source.PLAYER, + 1.0f, + 1.0f + ); + } + + @Override + public BossBar bossBar() { + return this.bossBar; + } + + @Override + public int duration() { + return 9; + } + + @Override + public String id() { + return "insomnia"; + } + + @Override + public void begin() { + Bukkit.getWorlds().get(0).setTime(13000); + } + + @Override + public Map, GameEventExecutor> events() { + return Map.of( + PlayerBedEnterEvent.class, + new GameEventExecutor<>( + PlayerBedEnterEvent.class, + event -> { + if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) { + event.getPlayer().sendMessage(Component.text( + "No puedes dormir ahora, no tienes sueño.", + TextColor.fromHexString("#E7783C") + )); + event.setCancelled(true); + } + } + ) + ); + } + + @Override + public EventPriority priority() { + return EventPriority.LOWEST; + } + + @Override + public boolean subtractDuration() { + return true; + } +}