Award score on event finish

This commit is contained in:
Mathieu Strypsteen 2024-09-15 09:20:09 +02:00
parent dfb5999d02
commit fedb9a56a3
4 changed files with 25 additions and 2 deletions

View file

@ -41,6 +41,11 @@ public class TeamScoreBoard {
return objective.getScore(team.getName()).getScore(); return objective.getScore(team.getName()).getScore();
} }
public void addScore(Team team, int score) {
int current_score = getScore(team);
setScore(team, current_score + score);
}
public Team getTeam(Integer team_index) { public Team getTeam(Integer team_index) {
Team team = scoreboard.getTeam(team_index.toString()); Team team = scoreboard.getTeam(team_index.toString());
@ -50,6 +55,7 @@ public class TeamScoreBoard {
team.color(colors.get(team_index % colors.size())); team.color(colors.get(team_index % colors.size()));
team.prefix(Component.text("Team " + team_index.toString() + " ")); team.prefix(Component.text("Team " + team_index.toString() + " "));
team.setAllowFriendlyFire(false); team.setAllowFriendlyFire(false);
setScore(team, 0);
} }
return team; return team;
@ -67,7 +73,6 @@ public class TeamScoreBoard {
team.addPlayer(player); team.addPlayer(player);
team.addEntry(player.getUniqueId().toString()); team.addEntry(player.getUniqueId().toString());
player.sendRichMessage("<rainbow>You have been added to team " + team.getName()); player.sendRichMessage("<rainbow>You have been added to team " + team.getName());
this.setScore(team, 0);
player.setGlowing(true); player.setGlowing(true);
} }

View file

@ -30,6 +30,7 @@ public abstract class Event implements Listener {
protected void eventSuccess() { protected void eventSuccess() {
MC13DTL.board.sendMessageToTeam(team, Component.text("Congratulations! You survived this event").color(NamedTextColor.GREEN)); MC13DTL.board.sendMessageToTeam(team, Component.text("Congratulations! You survived this event").color(NamedTextColor.GREEN));
MC13DTL.board.addScore(team, scoreAwarded());
eventFinished(); eventFinished();
} }
@ -53,4 +54,6 @@ public abstract class Event implements Listener {
} }
protected abstract String getMessage(); protected abstract String getMessage();
protected abstract int scoreAwarded();
} }

View file

@ -1,5 +1,7 @@
package gent.zeus.mc13dtl.events.catalog; package gent.zeus.mc13dtl.events.catalog;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import gent.zeus.mc13dtl.events.Event; import gent.zeus.mc13dtl.events.Event;
@ -13,4 +15,17 @@ public class TestEvent extends Event {
protected String getMessage() { protected String getMessage() {
return "test"; return "test";
} }
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer() == null) {
return;
}
eventSuccess();
}
@Override
protected int scoreAwarded() {
return 5;
}
} }

View file

@ -20,7 +20,7 @@ public class GroupRemoveCommand implements BasicCommand {
team.removeEntry(player.getName()); team.removeEntry(player.getName());
player.sendMessage("You have been removed from your team"); player.sendMessage("You have been removed from your team");
} else { } else {
commandSourceStack.getSender().sendMessage("Player not a team!"); commandSourceStack.getSender().sendMessage("Player not in a team!");
} }
} else { } else {
commandSourceStack.getSender().sendMessage("Player " + args[0] + " does not exist."); commandSourceStack.getSender().sendMessage("Player " + args[0] + " does not exist.");