Skip to content

Commit

Permalink
Merge pull request #143 from mrgeneralq/5.1.0
Browse files Browse the repository at this point in the history
5.1.0
  • Loading branch information
mrgeneralq authored Aug 31, 2022
2 parents 6406191 + 4aac4ad commit 713a1a6
Show file tree
Hide file tree
Showing 59 changed files with 1,413 additions and 306 deletions.
43 changes: 38 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.mrgeneralq</groupId>
<artifactId>sleep-most</artifactId>
<version>5.0.4</version>
<version>5.1.0</version>
<name>SleepMost</name>

<properties>
Expand Down Expand Up @@ -35,11 +35,12 @@
<target>${java.version}</target>
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<!-- Do not include the <configuration>...</configuration> part if you are using Sponge! -->
<version>3.3.0</version>
Do not include the <configuration>...</configuration> part if you are using Sponge!
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<relocations>
Expand All @@ -57,6 +58,28 @@
</goals>
</execution>
</executions>
</plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>${shade.base}.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
Expand All @@ -80,6 +103,11 @@
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>reposilite-repository-releases</id>
<name>Reposilite Repository</name>
<url>https://repo.mineinabyss.com/releases</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -102,7 +130,6 @@
<version>4.4.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand All @@ -118,7 +145,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.8</version>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -132,5 +159,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>com.gecolay</groupId>
<artifactId>gsit</artifactId>
<version>1.2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
58 changes: 33 additions & 25 deletions src/main/java/me/mrgeneralq/sleepmost/Sleepmost.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package me.mrgeneralq.sleepmost;

import dev.geco.gsit.api.GSitAPI;
import me.mrgeneralq.sleepmost.eventlisteners.*;
import me.mrgeneralq.sleepmost.eventlisteners.hooks.GSitEventListener;
import me.mrgeneralq.sleepmost.interfaces.*;
import me.mrgeneralq.sleepmost.managers.HookManager;
import me.mrgeneralq.sleepmost.mappers.MessageMapper;
import me.mrgeneralq.sleepmost.runnables.Heartbeat;
import me.mrgeneralq.sleepmost.statics.ServerVersion;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -17,8 +21,6 @@

public class Sleepmost extends JavaPlugin {

private String EARLY_ACCESS_VERSION = "";

private static Sleepmost instance;
private Bootstrapper bootstrapper;

Expand Down Expand Up @@ -51,37 +53,40 @@ public void onEnable() {
this.registerBossBars();

//init commands
SleepmostCommand sleepmostCommand = new SleepmostCommand(bootstrapper.getSleepService(), bootstrapper.getMessageService(), bootstrapper.getUpdateService(), bootstrapper.getFlagService(), bootstrapper.getFlagsRepository(), bootstrapper.getConfigRepository(), bootstrapper.getCooldownService(), bootstrapper.getBossBarService(), bootstrapper.getWorldPropertyService());
SleepmostCommand sleepmostCommand = new SleepmostCommand(bootstrapper.getSleepService(), bootstrapper.getMessageService(), bootstrapper.getUpdateService(), bootstrapper.getFlagService(), bootstrapper.getFlagsRepository(), bootstrapper.getConfigRepository(), bootstrapper.getCooldownService(), bootstrapper.getBossBarService(), bootstrapper.getSleepMostWorldService(), bootstrapper.getSleepMostPlayerService(), bootstrapper.getInsomniaService(), bootstrapper.getDebugService());
getCommand("sleepmost").setExecutor(sleepmostCommand);

PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new PlayerBedEnterEventListener(bootstrapper.getSleepService(), bootstrapper.getMessageService(), bootstrapper.getCooldownService(), bootstrapper.getFlagsRepository(), bootstrapper.getBossBarService(), bootstrapper.getWorldPropertyService()), this);
pm.registerEvents(new PlayerQuitEventListener(bootstrapper.getCooldownService(), bootstrapper.getSleepService(), bootstrapper.getBossBarService()), this);

if(ServerVersion.CURRENT_VERSION.hasTimeSkipEvent())
pm.registerEvents(new TimeSkipEventListener(bootstrapper.getSleepService()), this);

pm.registerEvents(new PlayerBedEnterEventListener(bootstrapper.getSleepService(), bootstrapper.getMessageService(), bootstrapper.getCooldownService(), bootstrapper.getFlagsRepository(), bootstrapper.getBossBarService(), bootstrapper.getSleepMostWorldService(), bootstrapper.getInsomniaService()), this);
pm.registerEvents(new PlayerQuitEventListener(bootstrapper.getCooldownService(), bootstrapper.getSleepService(), bootstrapper.getBossBarService(), bootstrapper.getSleepMostPlayerService()), this);
pm.registerEvents(new EntityTargetLivingEntityEventListener(bootstrapper.getFlagsRepository()), this);
pm.registerEvents(new PlayerWorldChangeEventListener(bootstrapper.getSleepService(), bootstrapper.getMessageService(), bootstrapper.getBossBarService()), this);
pm.registerEvents(new PlayerJoinEventListener(this, bootstrapper.getUpdateService(), bootstrapper.getMessageService(), bootstrapper.getBossBarService()), this);
pm.registerEvents(new PlayerJoinEventListener(this, bootstrapper.getUpdateService(), bootstrapper.getMessageService(), bootstrapper.getBossBarService(), bootstrapper.getSleepMostPlayerService()), this);
pm.registerEvents(new EntitySpawnEventListener(bootstrapper.getFlagsRepository()), this);

if(ServerVersion.CURRENT_VERSION.hasTimeSkipEvent()){
pm.registerEvents(new TimeSkipEventListener(bootstrapper.getSleepService()), this);
}


pm.registerEvents(new SleepSkipEventListener(bootstrapper.getMessageService(), bootstrapper.getConfigService(), bootstrapper.getSleepService(), bootstrapper.getFlagsRepository(), bootstrapper.getBossBarService()), this);
pm.registerEvents(new WorldChangeEventListener(bootstrapper.getSleepService()), this);
pm.registerEvents(new PlayerBedLeaveEventListener(bootstrapper.getSleepService()), this);
pm.registerEvents(new WorldLoadEventListener(bootstrapper.getBossBarService(), bootstrapper.getWorldPropertyService()),this);
pm.registerEvents(new WorldLoadEventListener(bootstrapper.getBossBarService(), bootstrapper.getSleepMostWorldService()),this);
pm.registerEvents(new WorldUnloadEventListener(bootstrapper.getBossBarService(), bootstrapper.getSleepMostWorldService()),this);
pm.registerEvents(new PlayerSleepStateChangeEventListener(this, bootstrapper.getSleepService(), bootstrapper.getFlagsRepository(), bootstrapper.getBossBarService(), bootstrapper.getMessageService(), bootstrapper.getCooldownService()), this);
pm.registerEvents(new TimeCycleChangeEventListener(bootstrapper.getSleepService(), bootstrapper.getWorldPropertyService(), bootstrapper.getFlagsRepository()),this );
pm.registerEvents(new TimeCycleChangeEventListener(bootstrapper.getSleepService(), bootstrapper.getSleepMostWorldService(), bootstrapper.getFlagsRepository(), bootstrapper.getInsomniaService()),this );
pm.registerEvents(new PlayerConsumeEventListener(bootstrapper.getSleepService(), bootstrapper.getInsomniaService(), bootstrapper.getMessageService(), bootstrapper.getFlagsRepository()), this);

Bukkit.getScheduler().runTaskAsynchronously(this, () -> notifyIfNewUpdateExists(bootstrapper.getUpdateService()));
if(HookManager.isGSitInstalled()){
getLogger().info("Hooked to GSit!");
pm.registerEvents(new GSitEventListener(bootstrapper.getSleepService(), bootstrapper.getMessageService(), bootstrapper.getCooldownService(), bootstrapper.getFlagsRepository(), bootstrapper.getBossBarService(), bootstrapper.getSleepMostWorldService(), bootstrapper.getInsomniaService()),this);
}

Bukkit.getScheduler().runTaskAsynchronously(this, () -> notifyIfNewUpdateExists(bootstrapper.getUpdateService()));
runPlayerTasks();
runPreTimerTasks();
runTimers(bootstrapper.getSleepService(), bootstrapper.getWorldPropertyService());
runTimers(bootstrapper.getSleepService(), bootstrapper.getSleepMostWorldService(), bootstrapper.getInsomniaService());

}

Expand All @@ -90,32 +95,35 @@ public static Sleepmost getInstance() {
}

private void runPreTimerTasks(){
for(World world: Bukkit.getWorlds())
this.bootstrapper.getWorldPropertyService().createNewWorldProperty(world);
for(World world: Bukkit.getWorlds()){
this.bootstrapper.getSleepMostWorldService().registerWorld(world);

if(ServerVersion.CURRENT_VERSION.supportsGameRules())
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true);
}
}

private void runTimers(ISleepService sleepService, IWorldPropertyService worldPropertyService){
private void runPlayerTasks(){
for(Player p: Bukkit.getOnlinePlayers()){
this.bootstrapper.getSleepMostPlayerService().registerNewPlayer(p);
}
}

new Heartbeat(sleepService, worldPropertyService).runTaskTimer(this, 20,20);
private void runTimers(ISleepService sleepService, ISleepMostWorldService sleepMostWorldService, IInsomniaService insomniaService){
new Heartbeat(sleepService, sleepMostWorldService, insomniaService, bootstrapper.getFlagsRepository()).runTaskTimer(this, 20,20);
}

private void notifyIfNewUpdateExists(IUpdateService updateService)
{

if(updateService.hasUpdate())
getLogger().info("UPDATE FOUND: A newer version of sleep-most is available to download!");
}

void registerBossBars(){
for(World world: Bukkit.getWorlds()){

IBossBarService bossBarService = this.bootstrapper.getBossBarService();
bossBarService.registerBossBar(world);
bossBarService.setVisible(world, false);
}
}

public String getEarlyAccessVersion(){
return this.EARLY_ACCESS_VERSION;
}
}
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 org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -83,4 +84,11 @@ public MessageBuilder setPlayer(String playerName){
this.message = message.replaceAll("%player%", playerName);
return this;
}

public MessageBuilder setEnabledStatus(boolean enabledStatus){

String status = (enabledStatus) ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled";
this.message = message.replaceAll("%status%", status);
return this;
}
}
31 changes: 25 additions & 6 deletions src/main/java/me/mrgeneralq/sleepmost/commands/SleepCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package me.mrgeneralq.sleepmost.commands;

import me.mrgeneralq.sleepmost.enums.MessageKey;
import me.mrgeneralq.sleepmost.interfaces.ICooldownService;
import me.mrgeneralq.sleepmost.interfaces.IFlagsRepository;
import me.mrgeneralq.sleepmost.interfaces.IMessageService;
import me.mrgeneralq.sleepmost.interfaces.ISleepService;
import me.mrgeneralq.sleepmost.interfaces.*;
import me.mrgeneralq.sleepmost.models.SleepMostWorld;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -16,12 +14,14 @@ public class SleepCommand implements CommandExecutor {
private final IMessageService messageService;
private final ICooldownService cooldownService;
private final IFlagsRepository flagsRepository;
private final ISleepMostWorldService sleepMostWorldService;

public SleepCommand(ISleepService sleepService, IMessageService messageService, ICooldownService cooldownService, IFlagsRepository flagsRepository) {
public SleepCommand(ISleepService sleepService, IMessageService messageService, ICooldownService cooldownService, IFlagsRepository flagsRepository, ISleepMostWorldService sleepMostWorldService) {
this.sleepService = sleepService;
this.messageService = messageService;
this.cooldownService = cooldownService;
this.flagsRepository = flagsRepository;
this.sleepMostWorldService = sleepMostWorldService;
}

@Override
Expand All @@ -30,8 +30,15 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
this.messageService.sendMessage(sender, messageService.getMessagePrefixed(MessageKey.NO_CONSOLE_COMMAND).build());
return true;
}

Player player = (Player) sender;

if(this.sleepService.isEnabledAt(player.getWorld())){
this.messageService.sendMessage(player, this.messageService.getMessagePrefixed(MessageKey.NOT_ENABLED_FOR_WORLD).build());
return true;
}


if (!player.hasPermission("sleepmost.sleep")) {
this.messageService.sendMessage(player, this.messageService.getMessagePrefixed(MessageKey.NO_PERMISSION_COMMAND).build());
return true;
Expand Down Expand Up @@ -59,13 +66,25 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
return true;
}

if (!this.sleepService.resetRequired(world)) {
if (!this.sleepService.isSleepingPossible(world)) {
this.messageService.sendMessage(player, messageService.getMessagePrefixed(MessageKey.CANNOT_SLEEP_NOW)
.setPlayer(player)
.setWorld(world)
.build());
return true;
}

SleepMostWorld sleepMostWorld = this.sleepMostWorldService.getWorld(world);

if(sleepMostWorld.isFrozen()){
this.messageService.getMessagePrefixed(MessageKey.SLEEP_PREVENTED_LONGER_NIGHT)
.setWorld(world)
.setPlayer(player)
.build();
return true;
}


boolean updatedSleepStatus = !this.sleepService.isPlayerAsleep(player);

//update the sleeping status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,25 @@ public class SleepmostCommand implements CommandExecutor, TabCompleter {
private final IConfigRepository configRepository;
private final ICooldownService cooldownService;
private final IBossBarService bossBarService;
private final IWorldPropertyService worldPropertyService;

public SleepmostCommand(ISleepService sleepService, IMessageService messageService, IUpdateService updateService, IFlagService flagService, IFlagsRepository flagsRepository, IConfigRepository configRepository, ICooldownService cooldownService, IBossBarService bossBarService, IWorldPropertyService worldPropertyService){
private final ISleepMostWorldService sleepMostWorldService;
private final ISleepMostPlayerService sleepMostPlayerService;
private final IInsomniaService insomniaService;
private final IDebugService debugService;

public SleepmostCommand(
ISleepService sleepService,
IMessageService messageService,
IUpdateService updateService,
IFlagService flagService,
IFlagsRepository flagsRepository,
IConfigRepository configRepository,
ICooldownService cooldownService,
IBossBarService bossBarService,
ISleepMostWorldService sleepMostWorldService,
ISleepMostPlayerService sleepMostPlayerService,
IInsomniaService insomniaService,
IDebugService debugService
){
this.sleepService = sleepService;
this.messageService = messageService;
this.updateService = updateService;
Expand All @@ -36,7 +52,10 @@ public SleepmostCommand(ISleepService sleepService, IMessageService messageServi
this.configRepository = configRepository;
this.cooldownService = cooldownService;
this.bossBarService = bossBarService;
this.worldPropertyService = worldPropertyService;
this.sleepMostWorldService = sleepMostWorldService;
this.sleepMostPlayerService = sleepMostPlayerService;
this.insomniaService = insomniaService;
this.debugService = debugService;
this.registerSubCommands();
}

Expand All @@ -50,12 +69,13 @@ private void registerSubCommands(){
subCommands.put("reset", new ResetSubCommand(this.messageService, this.flagService));
subCommands.put("setops", new SetOnePlayerSleepCommand(this.sleepService, this.messageService,this.flagService, this.flagsRepository));
subCommands.put("bed", new BedSubCommand(this.sleepService,this.messageService));
subCommands.put("sleep", new SleepSubCommand(this.sleepService,this.flagsRepository,this.messageService,this.cooldownService, this.bossBarService, this.worldPropertyService));
subCommands.put("sleep", new SleepSubCommand(this.sleepService,this.flagsRepository,this.messageService,this.cooldownService, this.bossBarService, this.sleepMostWorldService, this.insomniaService));
subCommands.put("kick", new KickSubCommand(this.sleepService,this.messageService, this.flagsRepository));
subCommands.put("insomnia", new InsomniaSubCommand(this.sleepService, this.flagsRepository, this.messageService, this.worldPropertyService));
subCommands.put("insomnia", new InsomniaSubCommand(this.sleepService, this.flagsRepository, this.messageService, this.sleepMostWorldService, this.sleepMostPlayerService, this.insomniaService));
subCommands.put("getflag", new GetFlagSubCommand(this.messageService, this.flagsRepository));
subCommands.put("resetflag", new ResetFlagSubCommand(this.messageService, this.flagsRepository, this.flagService));

subCommands.put("debug", new DebugSubCommand(this.debugService, this.messageService));

//enable when debugging
//subCommands.put("test", new TestCommand(this.messageService, this.flagsRepository, this.configRepository));
}
Expand Down Expand Up @@ -87,6 +107,7 @@ public boolean onCommand(CommandSender sender, Command command, String commandLa
sender.sendMessage(colorize("&e/sm kick &fkick a player from the bed"));
sender.sendMessage(colorize("&e/sm insomnia &fBlock sleeping for the current night"));
sender.sendMessage(colorize("&e/sm getflag &fQuickly grab a flag's value in your world"));
sender.sendMessage(colorize("&e/sm debug &fToggle debugging mode for your player"));
return true;
}

Expand Down
Loading

0 comments on commit 713a1a6

Please sign in to comment.