better messaging

This commit is contained in:
Xander 2024-09-21 19:01:18 +02:00
parent eb9262991d
commit ad6b6966e0
No known key found for this signature in database
GPG key ID: 79979C7BA303E003
3 changed files with 38 additions and 16 deletions

View file

@ -28,7 +28,7 @@ public class TeamScoreBoard {
}
daysAliveObjective = scoreboard.getObjective("days-alive");
if (daysAliveObjective == null) {
daysAliveObjective = scoreboard.registerNewObjective("days-alive", Criteria.DUMMY, Component.text("Days alive"));
daysAliveObjective = scoreboard.registerNewObjective("days-alive", Criteria.DUMMY, Component.text("Team Days alive"));
}
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
}

View file

@ -3,6 +3,8 @@ package gent.zeus.mc13dtl.events;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
@ -48,8 +50,9 @@ public abstract class Event implements Listener, Runnable {
}
protected void eventSuccess() {
MC13DTL.board.sendMessageToTeam(team, Component.text("Congratulations! You survived this event").color(NamedTextColor.GREEN));
MC13DTL.board.addScore(team, scoreOnSuccess);
MC13DTL.instance.getServer().broadcast(Component.text("Team " + team.getName()).color(team.color()).append(
Component.text(" successfully completed and survived the event!").color(NamedTextColor.WHITE)));
eventFinished();
}

View file

@ -1,5 +1,8 @@
package gent.zeus.mc13dtl.group;
import com.mojang.datafixers.util.Pair;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
@ -8,20 +11,36 @@ import org.bukkit.scoreboard.Team;
import gent.zeus.mc13dtl.MC13DTL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class SurvivalRunner implements Runnable {
@Override
public void run() {
World world = Bukkit.getWorld("world");
NamespacedKey eventKey = new NamespacedKey(MC13DTL.instance, "last-survival-check-day");
long lastRunDay = world.getPersistentDataContainer().get(eventKey, PersistentDataType.LONG);
long day = Bukkit.getWorld("world").getFullTime() / 24000;
if (day > lastRunDay) {
for (Team team : MC13DTL.board.getTeams().stream().toList()) {
int currentDays = MC13DTL.board.getDaysAlive(team) + 1;
MC13DTL.board.setDaysAlive(team, currentDays);
MC13DTL.board.addScore(team, (int) Math.pow(2, currentDays));
}
@Override
public void run() {
World world = Bukkit.getWorld("world");
NamespacedKey eventKey = new NamespacedKey(MC13DTL.instance, "last-survival-check-day");
long lastRunDay = world.getPersistentDataContainer().get(eventKey, PersistentDataType.LONG);
long day = Bukkit.getWorld("world").getFullTime() / 24000;
if (day > lastRunDay) {
List<Pair<Team, Integer>> grantedScores = new ArrayList<>();
for (Team team : MC13DTL.board.getTeams().stream().toList()) {
int currentDays = MC13DTL.board.getDaysAlive(team) + 1;
int score = (int) Math.pow(2, currentDays);
MC13DTL.board.setDaysAlive(team, currentDays);
MC13DTL.board.addScore(team, score);
grantedScores.add(new Pair<>(team, score));
}
grantedScores.sort(Comparator.comparing(p -> -p.getSecond()));
for (Pair<Team, Integer> p : grantedScores) {
MC13DTL.instance.getServer().broadcast(
Component.text("Team " + p.getFirst().getName()).color(p.getFirst().color()).append(
Component.text(" survived " + MC13DTL.board.getDaysAlive(p.getFirst()) + " days and was given " + p.getSecond() + " points").color(NamedTextColor.WHITE)
));
}
}
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day);
}
world.getPersistentDataContainer().set(eventKey, PersistentDataType.LONG, day);
}
}