Add new minecraft suicide event

This commit is contained in:
Xander 2024-09-15 22:30:58 +02:00
parent 36d3f7a076
commit 3b6e62a3d1
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
3 changed files with 50 additions and 3 deletions

View file

@ -36,6 +36,6 @@ public class MC13DTL extends JavaPlugin {
scheduler.runTask(this, () -> { scheduler.runTask(this, () -> {
board = new TeamScoreBoard(); board = new TeamScoreBoard();
}); });
scheduler.runTaskTimer(this, new EventRunner(), 0, 100); scheduler.runTaskTimer(this, new EventRunner(), 0, 200);
} }
} }

View file

@ -1,5 +1,6 @@
package gent.zeus.mc13dtl.events; package gent.zeus.mc13dtl.events;
import gent.zeus.mc13dtl.events.catalog.SuicideEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.World;
@ -39,8 +40,9 @@ public class EventRunner implements Runnable {
Team team = teams.get(i); Team team = teams.get(i);
Difficulty difficulty = difficulties.get(i); Difficulty difficulty = difficulties.get(i);
switch ((int) day) { switch ((int) day) {
case 0 -> new TestEvent(team, difficulty, getDayScore()); case 0 -> new SuicideEvent(team, difficulty, getDayScore());
case 1 -> new TestEvent2(team, difficulty, getDayScore()); case 1 -> new TestEvent(team, difficulty, getDayScore());
case 2 -> new TestEvent2(team, difficulty, getDayScore());
} }
} }
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day); world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day);

View file

@ -0,0 +1,45 @@
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 org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.scoreboard.Team;
public class SuicideEvent extends Event {
// Time left for team member to commit suicide in seconds.
private long timeLeft;
public SuicideEvent(Team team, Difficulty difficulty, int scoreOnSuccess) {
super(team, difficulty, scoreOnSuccess);
timeLeft = ((Difficulty.IMPOSSIBLE.ordinal() + 1) - difficulty.ordinal()) * 10;
}
@Override
public void run() {
timeLeft--;
if (timeLeft <= 0) {
eventFailed();
} else {
MC13DTL.board.sendMessageToTeam(this.team, Component.text(timeLeft + " seconds left."));
}
}
@Override
protected String getMessage() {
return "A team member has to die within " + timeLeft + " seconds.";
}
@Override
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
if (MC13DTL.board.getPlayers(team).contains(event.getPlayer())) {
eventSuccess();
}
}
}