14 Commits
v1.4.1 ... main

Author SHA1 Message Date
Jack
f99eceb46f make time/weather command checks more strict (closes #19) 2025-06-22 23:30:50 -04:00
Jack
df9b8f1fcd Merge pull request #18 from Karotte128/main
fix SunriseSunsetRequest to use right config values
2025-05-29 00:51:17 -04:00
Karotte128
6f5f69ee9e fix SunriseSunsetRequest to use right config variables 2025-02-22 22:09:51 +01:00
Jack
333325c4e0 Clean up fixed calculateWorldTime method 2024-08-06 21:10:22 -04:00
Jack
c83fe91f4e Merge pull request #12 from hunter232/main
Closes #11
2024-08-06 21:03:21 -04:00
Hunter Richardson
6fb3745d64 fixted bug where time was only ever set to sunrise or sunset [result of integer(long) division was either 0 or 1] 2024-08-02 11:55:20 -04:00
Jack
23b64653a8 add ANOTHER missing URISyntaxException catch (they're hiding from me ig) 2024-07-23 23:38:53 -04:00
Jack
5ef5db1cd5 change line endings 2024-07-23 23:37:07 -04:00
Jack
bb14509fbd change line endings 2024-07-23 23:35:23 -04:00
Jack
92b92b5969 use new PluginMeta instead of getDescription 2024-07-23 23:26:43 -04:00
Jack
8280d9b78c use setGameRule instead of setGameRuleValue 2024-07-23 23:26:25 -04:00
Jack
cca328c5ee remove deprecated code and use modern methods/classes/code where applicable 2024-07-23 23:23:11 -04:00
Jack
d2796f7992 move project to Java 21 and the 1.21 Paper API 2024-07-23 23:04:32 -04:00
Jack
c4c5ca7558 updated current features in README 2024-07-23 18:23:00 -04:00
15 changed files with 75 additions and 51 deletions

View File

@@ -1,6 +1,6 @@
name: Bug report
description: Report problems/issues here
labels: bug
labels: [bug]
body:
- type: checkboxes
attributes:

View File

@@ -1,6 +1,6 @@
name: Feature request
description: Use this to request new features and/or changes
labels: enhancement
labels: [enhancement]
body:
- type: checkboxes
attributes:

View File

@@ -1 +1,3 @@
#file: noinspection YAMLSchemaValidation
#IntelliJ IDEA interprets this as another issue template so the above line is required
blank_issues_enabled: false

View File

@@ -1,2 +1,2 @@
language: java
jdk: openjdk17
jdk: openjdk21

View File

@@ -9,6 +9,7 @@ ___
- Supports all Minecraft versions from 1.7+
- Constant time syncing (including custom or real-world sunrise/sunset times)
- Weather syncing (rain/snow and thunder)
- Enable/disable specific worlds
**Upcoming Features:**
- [ ] Commands

View File

@@ -1,33 +1,45 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'io.github.goooler.shadow' version '8.1.8' // TODO: Temporarily using fork
}
group = 'io.github.Jack1424'
version = '1.4.0'
group = 'io.github.jack1424'
version = '2.0.0-DEV'
repositories {
mavenCentral()
maven {
name = 'papermc-repo'
url = 'https://repo.papermc.io/repository/maven-public/'
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:3.0.2")
implementation("org.bukkit:bukkit:1.13-R0.1-SNAPSHOT")
}
shadowJar {
relocate('org.bstats', 'io.github.jack1424.realtimeweather')
relocate('org.bstats', 'io.github.jack1424.realTimeWeather')
}
def targetJavaVersion = 11
tasks.jar {
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
}
tasks.shadowJar {
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
}
def targetJavaVersion = 21
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
@@ -38,8 +50,10 @@ java {
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release = targetJavaVersion
options.release.set(targetJavaVersion)
}
}

0
gradlew vendored Executable file → Normal file
View File

View File

@@ -1,12 +1,13 @@
package io.github.jack1424.realtimeweather;
package io.github.jack1424.realTimeWeather;
import io.github.jack1424.realtimeweather.requests.WeatherRequestObject;
import io.github.jack1424.realTimeWeather.requests.WeatherRequestObject;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.json.simple.parser.ParseException;
import javax.naming.ConfigurationException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
@@ -342,7 +343,7 @@ public class ConfigManager {
} catch (NullPointerException e) {
throw new ConfigurationException("The APIKey cannot be blank");
}
catch (IOException | ParseException e) {
catch (IOException | ParseException | URISyntaxException e) {
rtw.getLogger().severe(e.getMessage());
throw new ConfigurationException("There was an error when validating this APIKey (this does not mean that the API key is invalid)");
}

View File

@@ -1,4 +1,4 @@
package io.github.jack1424.realtimeweather;
package io.github.jack1424.realTimeWeather;
import org.bukkit.World;
import org.bukkit.entity.Player;
@@ -18,8 +18,8 @@ public class EventHandlers implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCommandPreprocess(PlayerCommandPreprocessEvent event) {
if ((config.getBlockTimeSetCommand() && config.isTimeEnabled() && event.getMessage().contains("time set"))
|| (config.getBlockWeatherCommand() && config.isWeatherEnabled() && event.getMessage().contains("weather"))) {
if ((config.getBlockTimeSetCommand() && config.isTimeEnabled() && event.getMessage().toLowerCase().contains("time set "))
|| (config.getBlockWeatherCommand() && config.isWeatherEnabled() && event.getMessage().toLowerCase().contains("weather "))) {
event.setCancelled(true);
event.getPlayer().sendMessage("Command disabled by RealTimeWeather");
}
@@ -27,8 +27,8 @@ public class EventHandlers implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onConsoleCommand(ServerCommandEvent event) {
if ((config.getBlockTimeSetCommand() && config.isTimeEnabled() && event.getCommand().contains("time set"))
|| (config.getBlockWeatherCommand() && config.isWeatherEnabled() && event.getCommand().contains("weather"))) {
if ((config.getBlockTimeSetCommand() && config.isTimeEnabled() && event.getCommand().toLowerCase().contains("time set "))
|| (config.getBlockWeatherCommand() && config.isWeatherEnabled() && event.getCommand().toLowerCase().contains("weather "))) {
event.setCancelled(true);
event.getSender().sendMessage("Command disabled by RealTimeWeather");
}

View File

@@ -1,8 +1,9 @@
package io.github.jack1424.realtimeweather;
package io.github.jack1424.realTimeWeather;
import io.github.jack1424.realtimeweather.requests.*;
import io.github.jack1424.realTimeWeather.requests.*;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
@@ -11,7 +12,6 @@ import java.time.LocalTime;
import java.util.Calendar;
import java.util.logging.Logger;
@SuppressWarnings("deprecation")
public final class RealTimeWeather extends JavaPlugin {
private Logger logger;
private ConfigManager config;
@@ -59,9 +59,9 @@ public final class RealTimeWeather extends JavaPlugin {
debug("Re-enabling normal daylight and weather cycles...");
if (config.isTimeEnabled())
world.setGameRuleValue("doDaylightCycle", "true");
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, true);
if (config.isWeatherEnabled())
world.setGameRuleValue("doWeatherCycle", "true");
world.setGameRule(GameRule.DO_WEATHER_CYCLE, true);
}
logger.info("Stopping...");
@@ -78,7 +78,7 @@ public final class RealTimeWeather extends JavaPlugin {
debug("Using custom sunrise/sunset times. Sunrise: " + config.getSunriseCustomTime() + ", Sunset: " + config.getSunsetCustomTime());
for (World world : config.getTimeSyncWorlds())
world.setGameRuleValue("doDaylightCycle", "false");
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
if (config.isTimeEnabled()) {
@@ -87,7 +87,7 @@ public final class RealTimeWeather extends JavaPlugin {
if (config.getSunriseSunset().equals("real")) {
SunriseSunsetRequestObject sunriseSunset;
try {
sunriseSunset = new SunriseSunsetRequestObject(config.getTimeZone(), config.getWeatherLatitude(), config.getWeatherLongitude());
sunriseSunset = new SunriseSunsetRequestObject(config.getTimeZone(), config.getSunriseSunsetLatitude(), config.getSunriseSunsetLongitude());
world.setTime(calculateWorldTime(cal, sunriseSunset.getSunriseTime(), sunriseSunset.getSunsetTime()));
} catch (Exception e) {
logger.severe(e.getMessage());
@@ -124,9 +124,9 @@ public final class RealTimeWeather extends JavaPlugin {
config.setWeatherEnabled(false);
return;
}
for (World world : config.getWeatherSyncWorlds())
world.setGameRuleValue("doWeatherCycle", "false");
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
debug("Syncing weather...");
@@ -161,20 +161,21 @@ public final class RealTimeWeather extends JavaPlugin {
sunsetMinutes += 720;
LocalTime currentTime = LocalTime.of(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
int currentMinutes = currentTime.getHour() * 60 + currentTime.getMinute();
double currentMinutes = currentTime.getHour() * 60 + currentTime.getMinute();
if (currentMinutes >= sunriseMinutes && currentMinutes < sunsetMinutes) {
return ((currentMinutes - sunriseMinutes) / (sunsetMinutes - sunriseMinutes) * 13569) + 23041;
return (long) (((currentMinutes - sunriseMinutes) / (sunsetMinutes - sunriseMinutes)) * 13569) + 23041;
} else {
if (currentMinutes < sunriseMinutes)
currentMinutes += 1440;
return ((currentMinutes - sunsetMinutes) / (1440 - sunsetMinutes + sunriseMinutes) * 13569) + 12610;
return (long) (((currentMinutes - sunsetMinutes) / (1440 - sunsetMinutes + sunriseMinutes)) * 13569) + 12610;
}
}
@SuppressWarnings("UnstableApiUsage")
public String getUpdateCheck() {
String currentVersion = this.getDescription().getVersion();
String currentVersion = this.getPluginMeta().getVersion();
String latestVersion;
try {
debug("Getting latest version...");

View File

@@ -1,4 +1,4 @@
package io.github.jack1424.realtimeweather.requests;
package io.github.jack1424.realTimeWeather.requests;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@@ -7,16 +7,18 @@ import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Scanner;
public class RequestFunctions {
public static Object makeRequest(String URLString) throws IOException, HTTPResponseException, ParseException {
public static Object makeRequest(String URLString) throws IOException, HTTPResponseException, ParseException, URISyntaxException {
int responseCode = getResponseCode(URLString);
if (responseCode > 399)
throw new HTTPResponseException(responseCode);
Scanner scanner = new Scanner(new URL(URLString).openStream());
Scanner scanner = new Scanner(new URI(URLString).toURL().openStream());
StringBuilder response = new StringBuilder();
while (scanner.hasNextLine())
response.append(scanner.nextLine());
@@ -25,8 +27,8 @@ public class RequestFunctions {
return new JSONParser().parse(response.toString());
}
public static int getResponseCode(String URLString) throws IOException {
URL url = new URL(URLString);
public static int getResponseCode(String URLString) throws IOException, URISyntaxException {
URL url = new URI(URLString).toURL();
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.connect();
@@ -34,7 +36,7 @@ public class RequestFunctions {
}
public static String getLatestVersion() throws Exception {
return ((JSONObject) ((JSONArray) makeRequest("https://api.modrinth.com/v2/project/WRA6ODcm/version")).get(0)).get("version_number").toString();
return ((JSONObject) ((JSONArray) makeRequest("https://api.modrinth.com/v2/project/WRA6ODcm/version")).getFirst()).get("version_number").toString();
}
public static class HTTPResponseException extends Exception {

View File

@@ -1,10 +1,11 @@
package io.github.jack1424.realtimeweather.requests;
package io.github.jack1424.realTimeWeather.requests;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import javax.naming.ConfigurationException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
@@ -15,7 +16,7 @@ import java.util.*;
public class SunriseSunsetRequestObject {
private String sunriseTime, sunsetTime;
public SunriseSunsetRequestObject(TimeZone timeZone, String lat, String lon) throws IOException, ParseException, ConfigurationException {
public SunriseSunsetRequestObject(TimeZone timeZone, String lat, String lon) throws IOException, ParseException, ConfigurationException, URISyntaxException {
JSONObject response;
try {
response = (JSONObject) ((JSONObject) RequestFunctions.makeRequest(String.format("https://api.sunrisesunset.io/json?lat=%s&lng=%s&timezone=UTC", lat, lon))).get("results");

View File

@@ -1,4 +1,4 @@
package io.github.jack1424.realtimeweather.requests;
package io.github.jack1424.realTimeWeather.requests;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@@ -7,11 +7,12 @@ import org.json.simple.parser.ParseException;
import javax.naming.ConfigurationException;
import java.io.IOException;
import java.net.ProtocolException;
import java.net.URISyntaxException;
public class WeatherRequestObject {
private boolean rain = false, thunder = false;
public WeatherRequestObject(String apiKey, String lat, String lon) throws IOException, ParseException, ConfigurationException {
public WeatherRequestObject(String apiKey, String lat, String lon) throws IOException, ParseException, ConfigurationException, URISyntaxException {
JSONArray conditions;
try {
conditions = (JSONArray) ((JSONObject) RequestFunctions.makeRequest(String.format("https://api.openweathermap.org/data/2.5/weather?lat=%s&lon=%s&appid=%s", lat, lon, apiKey))).get("weather");

View File

@@ -1,4 +1,4 @@
# RealTimeWeather Configuration File (v1.4.0)
# RealTimeWeather Configuration File (v2.0.0)
# You can find detailed instructions at: https://github.com/Jack1424/RealTimeWeather/wiki#editing-the-configuration-file
######################################## Real Time Weather Settings ##################################################

View File

@@ -1,7 +1,8 @@
main: io.github.jack1424.realTimeWeather.RealTimeWeather
name: RealTimeWeather
version: '${version}'
description: Sync your server time and weather with the real world
main: io.github.jack1424.realtimeweather.RealTimeWeather
description: Sync your Minecraft server's time and weather with the real world
api-version: '1.21'
load: POSTWORLD
authors: [Jack1424]
website: https://github.com/Jack1424/RealTimeWeather
author: Jack1424
website: github.com/Jack1424/RealTimeWeather