Skip to content

Commit

Permalink
Merge pull request #168 from mrgeneralq/157-clock-editing
Browse files Browse the repository at this point in the history
added customization option
  • Loading branch information
mrgeneralq authored Dec 27, 2022
2 parents 863b87c + 4cc0478 commit b88932c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
6 changes: 5 additions & 1 deletion src/main/java/me/mrgeneralq/sleepmost/enums/MessageKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.mrgeneralq.sleepmost.enums.MessageKey;
import me.mrgeneralq.sleepmost.models.ConfigMessage;
import org.bukkit.ChatColor;

import java.util.*;

Expand Down Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -30,7 +33,7 @@ public class NightcycleAnimationTask extends BukkitRunnable {
private final List<OfflinePlayer> peopleWhoSlept;
private int iterationCount = 1;

public NightcycleAnimationTask(ISleepService sleepService, IFlagsRepository flagsRepository, World world, Player lastSleeper, List<OfflinePlayer> peopleWhoSlept, SleepSkipCause sleepSkipCause, ISleepMostWorldService sleepMostWorldService) {
public NightcycleAnimationTask(ISleepService sleepService, IFlagsRepository flagsRepository, World world, Player lastSleeper, List<OfflinePlayer> peopleWhoSlept, SleepSkipCause sleepSkipCause, ISleepMostWorldService sleepMostWorldService, IMessageService messageService) {
this.sleepService = sleepService;
this.flagsRepository = flagsRepository;
this.world = world;
Expand All @@ -40,6 +43,7 @@ public NightcycleAnimationTask(ISleepService sleepService, IFlagsRepository flag
this.peopleWhoSlept = peopleWhoSlept;

this.sleepMostWorldService = sleepMostWorldService;
this.messageService = messageService;
}

@Override
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -51,7 +52,8 @@ public SleepService(
IPlayerService playerService,
IDebugService debugService,
ISleepMostWorldService sleepMostWorldService,
IHookService hookService
IHookService hookService,
IMessageService messageService
) {

this.main = main;
Expand All @@ -63,6 +65,7 @@ public SleepService(
this.debugService = debugService;
this.sleepMostWorldService = sleepMostWorldService;
this.hookService = hookService;
this.messageService = messageService;
}

@Override
Expand Down Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class SleepServiceTest {
private IDebugService debugService;
private ISleepMostWorldService sleepMostWorldService;
private IHookService hookService;
private IMessageService messageService;

@BeforeEach
public void setUp() {
Expand All @@ -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
Expand Down

0 comments on commit b88932c

Please sign in to comment.