Compare commits
10 Commits
7db5b2c32c
...
8fabcd0be8
Author | SHA1 | Date | |
---|---|---|---|
8fabcd0be8 | |||
|
9ab6362e97 | ||
|
0c6261973c | ||
|
52a4fa93bb | ||
|
ec2a01b129 | ||
|
41fbc8ea90 | ||
|
e25674f4f3 | ||
|
23c2c95a31 | ||
|
2b8dfad337 | ||
|
334cbc10c4 |
15
README.md
Normal file
15
README.md
Normal 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.
|
2
pom.xml
2
pom.xml
@ -11,7 +11,7 @@
|
||||
|
||||
<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>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -1,11 +1,23 @@
|
||||
package xyz.louisvallat.sweetdreams;
|
||||
|
||||
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.player.PlayerBedEnterEvent;
|
||||
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class SweetDreams extends JavaPlugin implements Listener {
|
||||
|
||||
private final Map<Player, Integer> sleepingSchedulers = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Enabling plugin...");
|
||||
@ -18,4 +30,23 @@ public final class SweetDreams extends JavaPlugin implements Listener {
|
||||
getLogger().info("Disabling plugin...");
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user