diff --git a/src/main/java/me/mrgeneralq/sleepmost/builders/MessageBuilder.java b/src/main/java/me/mrgeneralq/sleepmost/builders/MessageBuilder.java index 803da4a..86ec605 100644 --- a/src/main/java/me/mrgeneralq/sleepmost/builders/MessageBuilder.java +++ b/src/main/java/me/mrgeneralq/sleepmost/builders/MessageBuilder.java @@ -2,6 +2,7 @@ import me.mrgeneralq.sleepmost.enums.SleepSkipCause; import me.mrgeneralq.sleepmost.statics.ChatColorUtils; +import me.mrgeneralq.sleepmost.utils.TimeUtils; import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.entity.Player; @@ -91,4 +92,9 @@ public MessageBuilder setEnabledStatus(boolean enabledStatus){ this.message = message.replaceAll("%status%", status); return this; } + + public MessageBuilder setTime(int time){ + this.message = message.replaceAll("%time%", TimeUtils.getTimeStringByTicks( time)); + return this; + } } \ No newline at end of file diff --git a/src/main/java/me/mrgeneralq/sleepmost/enums/MessageKey.java b/src/main/java/me/mrgeneralq/sleepmost/enums/MessageKey.java index bbca005..c1c723f 100644 --- a/src/main/java/me/mrgeneralq/sleepmost/enums/MessageKey.java +++ b/src/main/java/me/mrgeneralq/sleepmost/enums/MessageKey.java @@ -50,5 +50,9 @@ public enum MessageKey { NIGHT_SKIPPED_SUBTITLE, STORM_SKIPPED_SUBTITLE, - SLEEP_PREVENTED_LONGER_NIGHT + SLEEP_PREVENTED_LONGER_NIGHT, + + //CLOCK + CLOCK_TITLE, + CLOCK_SUBTITLE } diff --git a/src/main/java/me/mrgeneralq/sleepmost/mappers/MessageMapper.java b/src/main/java/me/mrgeneralq/sleepmost/mappers/MessageMapper.java index 5c027aa..fb4d160 100644 --- a/src/main/java/me/mrgeneralq/sleepmost/mappers/MessageMapper.java +++ b/src/main/java/me/mrgeneralq/sleepmost/mappers/MessageMapper.java @@ -2,6 +2,7 @@ import me.mrgeneralq.sleepmost.enums.MessageKey; import me.mrgeneralq.sleepmost.models.ConfigMessage; +import org.bukkit.ChatColor; import java.util.*; @@ -72,6 +73,9 @@ public void loadMessages(){ this.messages.put(MessageKey.STORM_SKIPPED_SUBTITLE, new ConfigMessage("user.storm-skipped-subtitle", "&bWhat a weather...")); this.messages.put(MessageKey.SLEEP_PREVENTED_LONGER_NIGHT, new ConfigMessage("user.longer-night.sleep-prevented", "&cThe night is longer than usual, you don't feel sleepy yet")); + + this.messages.put(MessageKey.CLOCK_TITLE, new ConfigMessage("clock.title", "&b%time%")); + this.messages.put(MessageKey.CLOCK_SUBTITLE, new ConfigMessage("clock.subtitle", "&a>>>")); } public ConfigMessage getMessage(MessageKey message){ diff --git a/src/main/java/me/mrgeneralq/sleepmost/runnables/NightcycleAnimationTask.java b/src/main/java/me/mrgeneralq/sleepmost/runnables/NightcycleAnimationTask.java index ff1c8b5..423029f 100644 --- a/src/main/java/me/mrgeneralq/sleepmost/runnables/NightcycleAnimationTask.java +++ b/src/main/java/me/mrgeneralq/sleepmost/runnables/NightcycleAnimationTask.java @@ -1,6 +1,8 @@ package me.mrgeneralq.sleepmost.runnables; +import me.mrgeneralq.sleepmost.enums.MessageKey; import me.mrgeneralq.sleepmost.interfaces.IFlagsRepository; +import me.mrgeneralq.sleepmost.interfaces.IMessageService; import me.mrgeneralq.sleepmost.interfaces.ISleepMostWorldService; import me.mrgeneralq.sleepmost.models.SleepMostWorld; import me.mrgeneralq.sleepmost.statics.DataContainer; @@ -22,6 +24,7 @@ public class NightcycleAnimationTask extends BukkitRunnable { private final ISleepService sleepService; private final DataContainer dataContainer = DataContainer.getContainer(); private final ISleepMostWorldService sleepMostWorldService; + private final IMessageService messageService; private final IFlagsRepository flagsRepository; private final World world; private final String lastSleeperName; @@ -30,7 +33,7 @@ public class NightcycleAnimationTask extends BukkitRunnable { private final List peopleWhoSlept; private int iterationCount = 1; - public NightcycleAnimationTask(ISleepService sleepService, IFlagsRepository flagsRepository, World world, Player lastSleeper, List peopleWhoSlept, SleepSkipCause sleepSkipCause, ISleepMostWorldService sleepMostWorldService) { + public NightcycleAnimationTask(ISleepService sleepService, IFlagsRepository flagsRepository, World world, Player lastSleeper, List peopleWhoSlept, SleepSkipCause sleepSkipCause, ISleepMostWorldService sleepMostWorldService, IMessageService messageService) { this.sleepService = sleepService; this.flagsRepository = flagsRepository; this.world = world; @@ -40,6 +43,7 @@ public NightcycleAnimationTask(ISleepService sleepService, IFlagsRepository flag this.peopleWhoSlept = peopleWhoSlept; this.sleepMostWorldService = sleepMostWorldService; + this.messageService = messageService; } @Override @@ -60,8 +64,16 @@ public void run() { peopleWhoSlept.stream().filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList())); for(Player p: playerList){ - String timeString = TimeUtils.getTimeStringByTicks(0); - p.sendTitle(ChatColor.AQUA + timeString ,ChatColor.GREEN + ">>>", 0,70,20); + + String clockTitle = this.messageService.getMessage(MessageKey.CLOCK_TITLE) + .setTime(0) + .build(); + + String clockSubTitle = this.messageService.getMessage(MessageKey.CLOCK_SUBTITLE) + .build(); + + + p.sendTitle( clockTitle ,clockSubTitle, 0,70,20); } } @@ -78,8 +90,16 @@ public void run() { peopleWhoSlept.stream().filter(OfflinePlayer::isOnline).map(OfflinePlayer::getPlayer).collect(Collectors.toList())); for(Player p: playerList){ - String timeString = TimeUtils.getTimeStringByTicks(world.getTime()); - p.sendTitle(ChatColor.AQUA + timeString ,ChatColor.GREEN + ">>>", 0,70,20); + + String clockTitle = this.messageService.getMessage(MessageKey.CLOCK_TITLE) + .setTime((int) world.getTime()) + .build(); + + String clockSubTitle = this.messageService.getMessage(MessageKey.CLOCK_SUBTITLE) + .build(); + + + p.sendTitle( clockTitle ,clockSubTitle, 0,70,20); } } } diff --git a/src/main/java/me/mrgeneralq/sleepmost/services/SleepService.java b/src/main/java/me/mrgeneralq/sleepmost/services/SleepService.java index 64b1824..3b2f2b0 100644 --- a/src/main/java/me/mrgeneralq/sleepmost/services/SleepService.java +++ b/src/main/java/me/mrgeneralq/sleepmost/services/SleepService.java @@ -37,6 +37,7 @@ public class SleepService implements ISleepService { private final DataContainer dataContainer = DataContainer.getContainer(); private final ISleepMostWorldService sleepMostWorldService; private final IHookService hookService; + private final IMessageService messageService; private static final int NIGHT_START_TIME = 12541, @@ -51,7 +52,8 @@ public SleepService( IPlayerService playerService, IDebugService debugService, ISleepMostWorldService sleepMostWorldService, - IHookService hookService + IHookService hookService, + IMessageService messageService ) { this.main = main; @@ -63,6 +65,7 @@ public SleepService( this.debugService = debugService; this.sleepMostWorldService = sleepMostWorldService; this.hookService = hookService; + this.messageService = messageService; } @Override @@ -307,7 +310,7 @@ public void runSkipAnimation(Player player, SleepSkipCause sleepSkipCause) { SleepMostWorld sleepMostWorld = this.sleepMostWorldService.getWorld(world); sleepMostWorld.setTimeCycleAnimationIsRunning(true); - new NightcycleAnimationTask(this, this.flagsRepository , world, player, sleepingPlayers , sleepSkipCause, sleepMostWorldService).runTaskTimer(this.main, 0, 1); + new NightcycleAnimationTask(this, this.flagsRepository , world, player, sleepingPlayers , sleepSkipCause, sleepMostWorldService, messageService).runTaskTimer(this.main, 0, 1); } diff --git a/src/main/java/me/mrgeneralq/sleepmost/statics/Bootstrapper.java b/src/main/java/me/mrgeneralq/sleepmost/statics/Bootstrapper.java index 518feac..c047790 100644 --- a/src/main/java/me/mrgeneralq/sleepmost/statics/Bootstrapper.java +++ b/src/main/java/me/mrgeneralq/sleepmost/statics/Bootstrapper.java @@ -67,7 +67,7 @@ public void initialize(Sleepmost main, PluginManager pluginManager){ this.flagService = new FlagService(flagsRepository, configRepository, configService, messageService, hookService); this.playerService = new PlayerService(); - this.sleepService = new SleepService(main, configService, configRepository, flagsRepository, flagService, playerService, debugService, sleepMostWorldService, hookService); + this.sleepService = new SleepService(main, configService, configRepository, flagsRepository, flagService, playerService, debugService, sleepMostWorldService, hookService, messageService); this.configMessageMapper = ConfigMessageMapper.getMapper(); this.configMessageMapper.initialize(main); diff --git a/src/main/tests/me/mrgeneralq/sleepmost/services/SleepServiceTest.java b/src/main/tests/me/mrgeneralq/sleepmost/services/SleepServiceTest.java index 05d122f..90090d9 100644 --- a/src/main/tests/me/mrgeneralq/sleepmost/services/SleepServiceTest.java +++ b/src/main/tests/me/mrgeneralq/sleepmost/services/SleepServiceTest.java @@ -36,6 +36,7 @@ public class SleepServiceTest { private IDebugService debugService; private ISleepMostWorldService sleepMostWorldService; private IHookService hookService; + private IMessageService messageService; @BeforeEach public void setUp() { @@ -48,7 +49,8 @@ public void setUp() { this.mockFlagRepository = mock(IFlagsRepository.class); this.mockFlagService = mock(IFlagService.class); this.playerService = mock(IPlayerService.class); - this.sleepService = new SleepService(this.mockSleepmost, this.mockConfigService, this.mockConfigRepository,this.mockFlagRepository,this.mockFlagService, this.playerService, this.debugService, this.sleepMostWorldService, this.hookService); + this.messageService = mock(IMessageService.class); + this.sleepService = new SleepService(this.mockSleepmost, this.mockConfigService, this.mockConfigRepository,this.mockFlagRepository,this.mockFlagService, this.playerService, this.debugService, this.sleepMostWorldService, this.hookService, this.messageService); } @Test