Compare commits

...

10 Commits

Author SHA1 Message Date
8fabcd0be8
misc: removed useless gitlab ci
Signed-off-by: Louis Vallat <contact@louis-vallat.dev>
2024-09-08 18:45:22 +02:00
Louis Vallat
9ab6362e97 removed ignoreSleep as it was causing more problems than it solves 2020-06-14 17:05:52 +02:00
Louis Vallat
0c6261973c ignoring player sleeping when going to bed, and not ignoring it anymore when they wake up 2020-06-14 14:27:07 +02:00
Louis Vallat
52a4fa93bb fixed my way to detect if a player could sleep or not, now using BedEnterResult to know if the player is actually in the bed 2020-06-14 13:24:45 +02:00
Louis Vallat
ec2a01b129 added README 2020-06-14 12:42:15 +02:00
Louis Vallat
41fbc8ea90 added a way to scale up the system to more players 2020-06-13 22:49:44 +02:00
Louis Vallat
e25674f4f3 added a better detection system 2020-06-13 21:32:22 +02:00
Louis Vallat
23c2c95a31 Setup CI 2020-04-16 10:30:37 +00:00
Louis Vallat
2b8dfad337 added proof of concept 2020-04-16 12:28:27 +02:00
Louis Vallat
334cbc10c4 updated description 2020-04-16 11:14:57 +02:00
3 changed files with 47 additions and 1 deletions

15
README.md Normal file
View File

@ -0,0 +1,15 @@
# Sweet Dreams
> A plugin made to enhance sleeping in multiplayer servers.
## Why
I faced a number of times, on my private server, people wanting to sleep, but not everyone was sleeping, so I coded this little plugin.
## How
If a player goes to sleep during the night or a thunderstorm, then the player will skip the night or the thunderstorm for the whole server, after 100 ticks (5 seconds, in vanilla it's 101 ticks).
## Setup or configuration
There's none.

View File

@ -11,7 +11,7 @@
<name>SweetDreams</name> <name>SweetDreams</name>
<description>A plugin to enhance the sleeping system on Spigot servers.</description> <description>A plugin to enhance the sleeping system on Spigot/Paper servers.</description>
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,11 +1,23 @@
package xyz.louisvallat.sweetdreams; package xyz.louisvallat.sweetdreams;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
import java.util.Map;
public final class SweetDreams extends JavaPlugin implements Listener { public final class SweetDreams extends JavaPlugin implements Listener {
private final Map<Player, Integer> sleepingSchedulers = new HashMap<>();
@Override @Override
public void onEnable() { public void onEnable() {
getLogger().info("Enabling plugin..."); getLogger().info("Enabling plugin...");
@ -18,4 +30,23 @@ public final class SweetDreams extends JavaPlugin implements Listener {
getLogger().info("Disabling plugin..."); getLogger().info("Disabling plugin...");
getLogger().info("Done disabling."); getLogger().info("Done disabling.");
} }
@EventHandler(priority = EventPriority.HIGHEST)
public void onSleep(PlayerBedEnterEvent event) {
final Player player = event.getPlayer();
final World world = player.getWorld();
if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) {
sleepingSchedulers.put(player, this.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
if (world.isThundering()) world.setThundering(false);
else world.setTime(1000);
getServer().broadcastMessage(ChatColor.YELLOW + player.getName() + ChatColor.GOLD + " went to bed.");
}, 100 // 100 ticks = 5 seconds
));
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onWake(PlayerBedLeaveEvent event) {
this.getServer().getScheduler().cancelTask(sleepingSchedulers.get(event.getPlayer()));
}
} }