add options to disable beds during night/thunder
This commit is contained in:
@@ -14,9 +14,9 @@ public class Configurator {
|
|||||||
private final RealTimeWeather rtw;
|
private final RealTimeWeather rtw;
|
||||||
private final FileConfiguration configFile;
|
private final FileConfiguration configFile;
|
||||||
private TimeZone timeZone;
|
private TimeZone timeZone;
|
||||||
private boolean debug, timeEnabled, weatherEnabled, blockTimeSetCommand, blockWeatherCommand;
|
private boolean debug, timeEnabled, weatherEnabled, blockTimeSetCommand, blockWeatherCommand, disableBedsAtNight, disableBedsDuringThunder;
|
||||||
private long timeSyncInterval, weatherSyncInterval;
|
private long timeSyncInterval, weatherSyncInterval;
|
||||||
private String apiKey, lat, lon;
|
private String apiKey, lat, lon, disableBedsAtNightMessage, disableBedsDuringThunderMessage;
|
||||||
|
|
||||||
public Configurator(RealTimeWeather rtw) {
|
public Configurator(RealTimeWeather rtw) {
|
||||||
this.rtw = rtw;
|
this.rtw = rtw;
|
||||||
@@ -30,6 +30,8 @@ public class Configurator {
|
|||||||
if (isTimeEnabled())
|
if (isTimeEnabled())
|
||||||
try {
|
try {
|
||||||
setBlockTimeSetCommand(configFile.getBoolean("BlockTimeSetCommand"));
|
setBlockTimeSetCommand(configFile.getBoolean("BlockTimeSetCommand"));
|
||||||
|
setDisableBedsAtNight(configFile.getBoolean("DisableBedsAtNight"));
|
||||||
|
setDisableBedsAtNightMessage(configFile.getString("DisableBedsAtNightMessage"));
|
||||||
setTimeSyncInterval(configFile.getLong("TimeSyncInterval"));
|
setTimeSyncInterval(configFile.getLong("TimeSyncInterval"));
|
||||||
setTimeZone(configFile.getString("Timezone"));
|
setTimeZone(configFile.getString("Timezone"));
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
@@ -44,6 +46,8 @@ public class Configurator {
|
|||||||
if (isWeatherEnabled())
|
if (isWeatherEnabled())
|
||||||
try {
|
try {
|
||||||
setBlockWeatherCommand(configFile.getBoolean("BlockWeatherCommand"));
|
setBlockWeatherCommand(configFile.getBoolean("BlockWeatherCommand"));
|
||||||
|
setDisableBedsDuringThunder(configFile.getBoolean("DisableBedsDuringThunder"));
|
||||||
|
setDisableBedsDuringThunderMessage(configFile.getString("DisableBedsDuringThunderMessage"));
|
||||||
setWeatherSyncInterval(configFile.getLong("WeatherSyncInterval"));
|
setWeatherSyncInterval(configFile.getLong("WeatherSyncInterval"));
|
||||||
setAPIKey(configFile.getString("APIKey"));
|
setAPIKey(configFile.getString("APIKey"));
|
||||||
setLat(configFile.getString("Latitude"));
|
setLat(configFile.getString("Latitude"));
|
||||||
@@ -84,6 +88,24 @@ public class Configurator {
|
|||||||
rtw.debug("BlockTimeSetCommand set to " + value);
|
rtw.debug("BlockTimeSetCommand set to " + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getDisableBedsAtNight() {
|
||||||
|
return disableBedsAtNight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisableBedsAtNight(boolean value) {
|
||||||
|
disableBedsAtNight = value;
|
||||||
|
rtw.debug("DisableBedsAtNight set to " + value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisableBedsAtNightMessage() {
|
||||||
|
return disableBedsAtNightMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisableBedsAtNightMessage(String value) {
|
||||||
|
disableBedsAtNightMessage = value;
|
||||||
|
rtw.debug("NightDisabledBedMessage set to " + value);
|
||||||
|
}
|
||||||
|
|
||||||
public long getTimeSyncInterval() {
|
public long getTimeSyncInterval() {
|
||||||
return timeSyncInterval;
|
return timeSyncInterval;
|
||||||
}
|
}
|
||||||
@@ -128,6 +150,24 @@ public class Configurator {
|
|||||||
rtw.debug("BlockWeatherCommand set to " + value);
|
rtw.debug("BlockWeatherCommand set to " + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getDisableBedsDuringThunder() {
|
||||||
|
return disableBedsDuringThunder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisableBedsDuringThunder(boolean value) {
|
||||||
|
disableBedsDuringThunder = value;
|
||||||
|
rtw.debug("DisableBedsDuringThunder set to " + value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisableBedsDuringThunderMessage() {
|
||||||
|
return disableBedsDuringThunderMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisableBedsDuringThunderMessage(String value) {
|
||||||
|
disableBedsDuringThunderMessage = value;
|
||||||
|
rtw.debug("ThunderDisabledBedMessage set to " + value);
|
||||||
|
}
|
||||||
|
|
||||||
public long getWeatherSyncInterval() {
|
public long getWeatherSyncInterval() {
|
||||||
return weatherSyncInterval;
|
return weatherSyncInterval;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
package io.github.jack1424.realtimeweather;
|
package io.github.jack1424.realtimeweather;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventPriority;
|
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.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
@@ -29,4 +32,22 @@ public class EventHandler implements Listener {
|
|||||||
event.getSender().sendMessage("Command disabled by RealTimeWeather");
|
event.getSender().sendMessage("Command disabled by RealTimeWeather");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@org.bukkit.event.EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
World playerWorld = player.getWorld();
|
||||||
|
long worldTime = playerWorld.getTime();
|
||||||
|
|
||||||
|
if (config.isTimeEnabled() && config.getDisableBedsAtNight() && ((!playerWorld.hasStorm() && worldTime >= 12542 && worldTime <= 23459)
|
||||||
|
|| (playerWorld.hasStorm() && worldTime >= 12010 && worldTime <= 23991))) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(config.getDisableBedsAtNightMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.isWeatherEnabled() && config.getDisableBedsDuringThunder() && playerWorld.isThundering()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(config.getDisableBedsDuringThunderMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,12 @@ SyncTime: false
|
|||||||
# Set to false to enable the /time set command (not recommended) #
|
# Set to false to enable the /time set command (not recommended) #
|
||||||
BlockTimeSetCommand: true
|
BlockTimeSetCommand: true
|
||||||
# #
|
# #
|
||||||
|
# Prevent players from sleeping in beds at night (they will still be able to set their spawn point) #
|
||||||
|
# If you disable this, strange things could happen #
|
||||||
|
DisableBedsAtNight: true
|
||||||
|
# The message sent to players when they try to sleep at night when beds are disabled #
|
||||||
|
DisableBedsAtNightMessage: ''
|
||||||
|
# #
|
||||||
# You can change the time between time syncs from the default (5 seconds) below #
|
# You can change the time between time syncs from the default (5 seconds) below #
|
||||||
TimeSyncInterval: 100
|
TimeSyncInterval: 100
|
||||||
# #
|
# #
|
||||||
@@ -25,6 +31,12 @@ SyncWeather: false
|
|||||||
# Set to false to enable the /weather command (not recommended) #
|
# Set to false to enable the /weather command (not recommended) #
|
||||||
BlockWeatherCommand: true
|
BlockWeatherCommand: true
|
||||||
# #
|
# #
|
||||||
|
# Prevent players from sleeping in beds during a thunderstorm (they will still be able to set their spawn point) #
|
||||||
|
# If you disable this, it could break weather syncing #
|
||||||
|
DisableBedsDuringThunder: true
|
||||||
|
# The message sent to players when they try to sleep during a thunderstorm when beds are disabled #
|
||||||
|
DisableBedsDuringThunderMessage: ''
|
||||||
|
# #
|
||||||
# You can change the time between weather syncs from the default (5 minutes) below #
|
# You can change the time between weather syncs from the default (5 minutes) below #
|
||||||
# Due to OpenWeather's restrictions, setting this value below 2400 (2 minutes) will cause problems #
|
# Due to OpenWeather's restrictions, setting this value below 2400 (2 minutes) will cause problems #
|
||||||
# You can find a handy tick calculator here: https://mapmaking.fr/tick/ #
|
# You can find a handy tick calculator here: https://mapmaking.fr/tick/ #
|
||||||
|
Reference in New Issue
Block a user