Add success/failure handlers

This commit is contained in:
Mathieu Strypsteen 2024-09-14 22:46:53 +02:00
parent 1e922c93a8
commit 09f59f4975
3 changed files with 23 additions and 3 deletions

View file

@ -5,11 +5,14 @@ import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import gent.zeus.mc13dtl.MC13DTL;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
public abstract class Event { public abstract class Event implements Listener {
protected Team team; protected Team team;
public Event(Team team) { public Event(Team team) {
@ -17,6 +20,25 @@ public abstract class Event {
for (Player player : getPlayers()) { for (Player player : getPlayers()) {
player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + getMessage()); player.sendMessage(ChatColor.GRAY + "" + ChatColor.ITALIC + getMessage());
} }
MC13DTL.instance.getServer().getPluginManager().registerEvents(this, MC13DTL.instance);
}
private void eventFinished() {
HandlerList.unregisterAll(this);
}
protected void eventSuccess() {
for (Player player : getPlayers()) {
player.sendMessage(ChatColor.GREEN + "Congratulations! You survived this event");
}
eventFinished();
}
protected void eventFailed() {
for (Player player : getPlayers()) {
player.sendMessage(ChatColor.RED + "Try harder next time...");
}
eventFinished();
} }
protected List<Player> getPlayers() { protected List<Player> getPlayers() {

View file

@ -7,7 +7,6 @@ import gent.zeus.mc13dtl.events.Event;
public class TestEvent extends Event { public class TestEvent extends Event {
public TestEvent(Team team) { public TestEvent(Team team) {
super(team); super(team);
System.err.println("test");
} }
@Override @Override

View file

@ -4,7 +4,6 @@ import gent.zeus.mc13dtl.MC13DTL;
import io.papermc.paper.command.brigadier.BasicCommand; import io.papermc.paper.command.brigadier.BasicCommand;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;