Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
84f3050820 | ||
|
829462243c | ||
|
2858457303 | ||
|
1d2513f8b7 | ||
|
6558d82f5c |
@@ -1,16 +1,18 @@
|
|||||||
# RealTimeWeather [](https://app.travis-ci.com/Jack1424/RealTimeWeather)
|
# RealTimeWeather [](https://app.travis-ci.com/Jack1424/RealTimeWeather)
|
||||||
A lightweight Minecraft Java server plugin that allows you to sync your server's time and weather with the real world
|
A lightweight Minecraft Java server plugin that allows you to sync your server's time and weather with the real world.
|
||||||
|
|
||||||
**Current Features:**
|
**Current Features:**
|
||||||
- Lightweight
|
- Lightweight
|
||||||
|
- Supports all Minecraft versions from 1.7+
|
||||||
- Constant time syncing
|
- Constant time syncing
|
||||||
- Weather syncing (rain and thunder)
|
- Weather syncing (rain and thunder)
|
||||||
|
|
||||||
**Upcoming Features:**
|
**Upcoming Features:**
|
||||||
- [ ] Use WeatherPlusAPI (more weather states)
|
- [ ] Use WeatherPlusAPI (more weather states)
|
||||||
- [ ] Support for more Minecraft verions
|
- [X] Support for more Minecraft versions
|
||||||
|
- [ ] Wiki
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
I'm open to any help/ideas that you have. Just open an issue or a pull request and I'll be sure to look at it as soon as I can. Builds with `gradlew shadowJar`.
|
I'm open to any help/ideas that you have. Just open an issue or a pull request, and I'll be sure to look at it as soon as I can. Builds with `gradlew shadowJar`.
|
||||||
|
|
||||||
License: GPL-3.0
|
License: GPL-3.0
|
||||||
|
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'io.github.Jack1424'
|
group = 'io.github.Jack1424'
|
||||||
version = '1.1.2'
|
version = '1.2.0'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -20,14 +20,14 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT'
|
implementation("org.bukkit:bukkit:1.13-R0.1-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
relocate('org.bstats', 'io.github.jack1424.realtimeweather')
|
relocate('org.bstats', 'io.github.jack1424.realtimeweather')
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 17
|
def targetJavaVersion = 11
|
||||||
java {
|
java {
|
||||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||||
sourceCompatibility = javaVersion
|
sourceCompatibility = javaVersion
|
||||||
|
@@ -2,7 +2,6 @@ package io.github.jack1424.realtimeweather;
|
|||||||
|
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bstats.charts.SimplePie;
|
import org.bstats.charts.SimplePie;
|
||||||
import org.bukkit.GameRule;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -23,6 +22,7 @@ import java.time.zone.ZoneRulesException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
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;
|
||||||
@@ -62,9 +62,9 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
debug("Re-enabling normal daylight and weather cycles...");
|
debug("Re-enabling normal daylight and weather cycles...");
|
||||||
|
|
||||||
if (timeEnabled)
|
if (timeEnabled)
|
||||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true);
|
world.setGameRuleValue("doDaylightCycle", "true");
|
||||||
if (weatherEnabled)
|
if (weatherEnabled)
|
||||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, true);
|
world.setGameRuleValue("doWeatherCycle", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Stopping...");
|
logger.info("Stopping...");
|
||||||
@@ -87,8 +87,11 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupTime() {
|
private void setupTime() {
|
||||||
|
long timeSyncInterval;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
timezone = ZoneId.of(Objects.requireNonNull(getConfig().getString("Timezone")));
|
timezone = ZoneId.of(Objects.requireNonNull(getConfig().getString("Timezone")));
|
||||||
|
timeSyncInterval = getConfig().getLong("TimeSyncInterval");
|
||||||
} 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());
|
||||||
@@ -98,30 +101,35 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Enabling time zone sync (every second)");
|
debug("Enabling time zone sync...");
|
||||||
debug("Syncing time with " + timezone.toString());
|
debug("Syncing time with " + timezone.toString());
|
||||||
|
|
||||||
for (World world : getServer().getWorlds())
|
for (World world : getServer().getWorlds())
|
||||||
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
||||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
world.setGameRuleValue("doDaylightCycle", "false");
|
||||||
|
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
||||||
if (timeEnabled) {
|
if (timeEnabled) {
|
||||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timezone));
|
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timezone));
|
||||||
for (World world : getServer().getWorlds())
|
for (World world : getServer().getWorlds())
|
||||||
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
||||||
world.setTime((1000 * cal.get(Calendar.HOUR_OF_DAY)) + (16 * cal.get(Calendar.MINUTE)) - 6000); // TODO: Time is one minute behind
|
world.setTime((1000 * cal.get(Calendar.HOUR_OF_DAY)) + (16 * (cal.get(Calendar.MINUTE) + 1)) - 6000);
|
||||||
}
|
}
|
||||||
}, 0L, 20L); // TODO: Does this really need to update every second?
|
}, 0L, timeSyncInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupWeather() {
|
private void setupWeather() {
|
||||||
|
long weatherSyncInterval;
|
||||||
|
|
||||||
String apiKey = getConfig().getString("APIKey");
|
String apiKey = getConfig().getString("APIKey");
|
||||||
String zipCode = getConfig().getString("ZipCode");
|
String zipCode = getConfig().getString("ZipCode");
|
||||||
String countryCode = getConfig().getString("CountryCode");
|
String countryCode = getConfig().getString("CountryCode");
|
||||||
|
|
||||||
String lat, lon;
|
String lat, lon;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
weatherSyncInterval = getConfig().getLong("WeatherSyncInterval");
|
||||||
|
|
||||||
HttpsURLConnection con = (HttpsURLConnection) new URL(String.format("https://api.openweathermap.org/geo/1.0/zip?zip=%s,%s&appid=%s", zipCode, countryCode, apiKey)).openConnection();
|
HttpsURLConnection con = (HttpsURLConnection) new URL(String.format("https://api.openweathermap.org/geo/1.0/zip?zip=%s,%s&appid=%s", zipCode, countryCode, apiKey)).openConnection();
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
con.connect();
|
con.connect();
|
||||||
@@ -129,15 +137,18 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
int response = con.getResponseCode();
|
int response = con.getResponseCode();
|
||||||
if (response > 499) {
|
if (response > 499) {
|
||||||
logger.severe("There was a server error when requesting weather information. Please try again later");
|
logger.severe("There was a server error when requesting weather information. Please try again later");
|
||||||
throw new Exception("Server error");
|
throw new Exception("Server/client error");
|
||||||
}
|
}
|
||||||
else if (response > 399) {
|
else if (response > 399) {
|
||||||
String message = "Error when getting weather information: ";
|
String message = "Error when getting weather information: ";
|
||||||
switch (response) {
|
|
||||||
case 401 -> logger.severe(message + "API key incorrect");
|
if (response == 401)
|
||||||
case 404 -> logger.severe(message + "Zip/Country code incorrect");
|
logger.severe(message + "API key incorrect");
|
||||||
default -> logger.severe("Unknown error");
|
else if (response == 404)
|
||||||
}
|
logger.severe(message + "Zip/Country code incorrect");
|
||||||
|
else
|
||||||
|
logger.severe("Unknown error");
|
||||||
|
|
||||||
logger.severe("Please check that the values set in the config file are correct");
|
logger.severe("Please check that the values set in the config file are correct");
|
||||||
|
|
||||||
throw new Exception("Configuration error");
|
throw new Exception("Configuration error");
|
||||||
@@ -156,7 +167,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
for (World world : getServer().getWorlds())
|
for (World world : getServer().getWorlds())
|
||||||
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
if (world.getEnvironment().equals(World.Environment.NORMAL))
|
||||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
world.setGameRuleValue("doWeatherCycle", "false");
|
||||||
|
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
||||||
debug("Syncing weather...");
|
debug("Syncing weather...");
|
||||||
@@ -190,7 +201,7 @@ public final class RealTimeWeather extends JavaPlugin implements Listener {
|
|||||||
world.setStorm(rain);
|
world.setStorm(rain);
|
||||||
world.setThundering(thunder);
|
world.setThundering(thunder);
|
||||||
}
|
}
|
||||||
}, 0L, 6000L);
|
}, 0L, weatherSyncInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject makeWeatherRequest(URL url) throws IOException, ParseException {
|
private JSONObject makeWeatherRequest(URL url) throws IOException, ParseException {
|
||||||
|
@@ -4,6 +4,9 @@
|
|||||||
################################# TIME SYNC SETTINGS #################################################################
|
################################# TIME SYNC SETTINGS #################################################################
|
||||||
# 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
|
||||||
|
#
|
||||||
|
# You can change the time between time syncs from the default (5 seconds) below #
|
||||||
|
TimeSyncInterval: 100
|
||||||
# #
|
# #
|
||||||
# Enter the time zone that you want to sync your world(s) with #
|
# Enter the time zone that you want to sync your world(s) with #
|
||||||
# This location CAN be different from your chosen weather location #
|
# This location CAN be different from your chosen weather location #
|
||||||
@@ -15,6 +18,11 @@ Timezone: 'America/New_York'
|
|||||||
################################# WEATHER SYNC SETTINGS ##############################################################
|
################################# WEATHER SYNC SETTINGS ##############################################################
|
||||||
# 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
|
||||||
|
#
|
||||||
|
# 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 #
|
||||||
|
# You can find a handy tick calculator here: https://mapmaking.fr/tick/ #
|
||||||
|
WeatherSyncInterval: 6000
|
||||||
# #
|
# #
|
||||||
# In order to access the weather sync feature, create an account at https://openweathermap.org/ #
|
# In order to access the weather sync feature, create an account at https://openweathermap.org/ #
|
||||||
# Then, create an API key at https://openweathermap.org/appid and copy it #
|
# Then, create an API key at https://openweathermap.org/appid and copy it #
|
||||||
|
@@ -2,6 +2,5 @@ name: RealTimeWeather
|
|||||||
version: '${version}'
|
version: '${version}'
|
||||||
description: Sync your server time and weather with the real world
|
description: Sync your server time and weather with the real world
|
||||||
main: io.github.jack1424.realtimeweather.RealTimeWeather
|
main: io.github.jack1424.realtimeweather.RealTimeWeather
|
||||||
api-version: 1.19
|
|
||||||
authors: [ Jack1424 ]
|
authors: [ Jack1424 ]
|
||||||
website: https://github.com/Jack1424/RealTimeWeather
|
website: https://github.com/Jack1424/RealTimeWeather
|
||||||
|
Reference in New Issue
Block a user