add option to enable /time set and /weather commands
This commit is contained in:
@@ -19,7 +19,7 @@ import java.util.logging.Logger;
|
|||||||
public final class RealTimeWeather extends JavaPlugin implements Listener {
|
public final class RealTimeWeather extends JavaPlugin implements Listener {
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
private ZoneId timezone;
|
private ZoneId timezone;
|
||||||
private boolean timeEnabled, weatherEnabled, debug;
|
private boolean timeEnabled, weatherEnabled, debug, blockTimeSetCommand, blockWeatherCommand;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -65,7 +65,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onOperatorSet(PlayerCommandPreprocessEvent event) {
|
public void onOperatorSet(PlayerCommandPreprocessEvent event) {
|
||||||
if ((timeEnabled && event.getMessage().contains("time set")) || (weatherEnabled && event.getMessage().contains("weather"))) {
|
if ((blockTimeSetCommand && timeEnabled && event.getMessage().contains("time set")) || (blockWeatherCommand && weatherEnabled && event.getMessage().contains("weather"))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getPlayer().sendMessage("Command cancelled (RealTimeWeather is controlling this)");
|
event.getPlayer().sendMessage("Command cancelled (RealTimeWeather is controlling this)");
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
public void onOperatorSetConsole(ServerCommandEvent event) {
|
public void onOperatorSetConsole(ServerCommandEvent event) {
|
||||||
if ((timeEnabled && event.getCommand().contains("time set")) || (weatherEnabled && event.getCommand().contains("weather"))) {
|
if ((blockTimeSetCommand && timeEnabled && event.getCommand().contains("time set")) || (blockWeatherCommand && weatherEnabled && event.getCommand().contains("weather"))) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getSender().sendMessage("Command cancelled (RealTimeWeather is controlling this)");
|
event.getSender().sendMessage("Command cancelled (RealTimeWeather is controlling this)");
|
||||||
}
|
}
|
||||||
@@ -85,6 +85,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
try {
|
try {
|
||||||
timezone = ZoneId.of(Objects.requireNonNull(getConfig().getString("Timezone")));
|
timezone = ZoneId.of(Objects.requireNonNull(getConfig().getString("Timezone")));
|
||||||
timeSyncInterval = getConfig().getLong("TimeSyncInterval");
|
timeSyncInterval = getConfig().getLong("TimeSyncInterval");
|
||||||
|
blockTimeSetCommand = getConfig().getBoolean("BlockTimeSetCommand");
|
||||||
} catch (NullPointerException|ZoneRulesException e) {
|
} catch (NullPointerException|ZoneRulesException e) {
|
||||||
logger.severe("Error loading timezone. Check that the values in your configuration file are valid.");
|
logger.severe("Error loading timezone. Check that the values in your configuration file are valid.");
|
||||||
debug(e.getMessage());
|
debug(e.getMessage());
|
||||||
@@ -119,6 +120,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
weatherSyncInterval = getConfig().getLong("WeatherSyncInterval");
|
weatherSyncInterval = getConfig().getLong("WeatherSyncInterval");
|
||||||
|
blockWeatherCommand = getConfig().getBoolean("blockWeatherCommand");
|
||||||
|
|
||||||
RequestObject request = new RequestObject(apiKey, lat, lon);
|
RequestObject request = new RequestObject(apiKey, lat, lon);
|
||||||
|
|
||||||
|
@@ -4,6 +4,9 @@
|
|||||||
# Set to true to enable time syncing, or false to disable #
|
# Set to true to enable time syncing, or false to disable #
|
||||||
SyncTime: false
|
SyncTime: false
|
||||||
# #
|
# #
|
||||||
|
# Set to false to enable the /time set command (not recommended) #
|
||||||
|
BlockTimeSetCommand: true
|
||||||
|
# #
|
||||||
# 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
|
||||||
# #
|
# #
|
||||||
@@ -18,6 +21,9 @@ Timezone: 'Etc/UTC'
|
|||||||
# Set to true to enable weather syncing, or false to disable #
|
# Set to true to enable weather syncing, or false to disable #
|
||||||
SyncWeather: false
|
SyncWeather: false
|
||||||
# #
|
# #
|
||||||
|
# Set to false to enable the /weather command (not recommended) #
|
||||||
|
BlockWeatherCommand: true
|
||||||
|
# #
|
||||||
# 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