Compare commits
No commits in common. "8fabcd0be8adba8e203ee43ef10af9fc4e8ba25d" and "7db5b2c32cd6e41fc209693022f64d0b1bafa267" have entirely different histories.
8fabcd0be8
...
7db5b2c32c
15
README.md
15
README.md
@ -1,15 +0,0 @@
|
||||
# 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/Paper servers.</description>
|
||||
<description>A plugin to enhance the sleeping system on Spigot servers.</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -1,23 +1,11 @@
|
||||
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...");
|
||||
@ -30,23 +18,4 @@ 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