Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title #79

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import net.tiagofar78.prisonescape.game.PrisonEscapePlayer;

public class BukkitMessageSender {

private static final int TICKS_PER_SECOND = 20;
private static final int FADE = (int) (1 * TICKS_PER_SECOND);
private static final int STAY = (int) (3.5 * TICKS_PER_SECOND);

public static List<String> getOnlinePlayersNames() {
return Bukkit.getOnlinePlayers().stream().map(p -> p.getName()).toList();
Expand Down Expand Up @@ -50,7 +54,12 @@ public static void sendChatMessage(String playerName, List<String> message) {
}

public static void sendTitleMessage(String playerName, String titleMessage, String subtitleMessage) {
// TODO
Player bukkitPlayer = Bukkit.getPlayer(playerName);
if (bukkitPlayer == null || !bukkitPlayer.isOnline()) {
return;
}

bukkitPlayer.sendTitle(titleMessage, subtitleMessage, FADE, STAY, FADE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,16 @@ private void startDay() {

_dayPeriod = DayPeriod.DAY;
_currentDay++;

_prison.reloadChests();


for (PrisonEscapePlayer player : _playersOnLobby) {
MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(player.getName());
String title = messages.getNewDayTitleMessage(_currentDay);
String subtitle = messages.getNewDaySubtitleMessage();
BukkitMessageSender.sendTitleMessage(player.getName(), title, subtitle);
}

BukkitScheduler.runSchedulerLater(new Runnable() {

@Override
Expand All @@ -348,6 +355,13 @@ private void startNight() {
}

_dayPeriod = DayPeriod.NIGHT;

for (PrisonEscapePlayer player : _playersOnLobby) {
MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(player.getName());
String title = messages.getNightTitleMessage();
String subtitle = messages.getNightSubtitleMessage();
BukkitMessageSender.sendTitleMessage(player.getName(), title, subtitle);
}

BukkitScheduler.runSchedulerLater(new Runnable() {

Expand Down
Loading