do real time properly

+ tidy config
+ bump version
fixes #2
This commit is contained in:
Minecon724 2023-08-29 09:22:40 +00:00
parent 33055172e4
commit e2254f6c67
8 changed files with 40 additions and 25 deletions

View file

@ -3,6 +3,7 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
@ -36,6 +37,13 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>

4
.gitignore vendored
View file

@ -1,5 +1,7 @@
target/
# CLI files
# IDE files
org.eclipse.*
.vscode/
.classpath
.project

View file

@ -22,12 +22,12 @@
</natures>
<filteredResources>
<filter>
<id>1650700979358</id>
<id>1693298440613</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>

View file

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pl.minecon724</groupId>
<artifactId>realweather</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
@ -20,7 +20,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -32,7 +32,7 @@
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>3.0.1</version>
<version>4.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

View file

@ -94,7 +94,7 @@ public class RW extends JavaPlugin {
realtimeSec.getDouble("timeScale"),
zone,
realtimeSec.getStringList("worlds")
).runTaskTimerAsynchronously(this, 0, realtimeSec.getLong("interval"));
).runTaskTimer(this, 0, realtimeSec.getLong("interval"));
}
Metrics metrics = new Metrics(this, 15020);

View file

@ -1,6 +1,5 @@
package pl.minecon724.realweather.realtime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
@ -29,7 +28,17 @@ public class RTTask extends BukkitRunnable {
@Override
public void run() {
long now = ZonedDateTime.now(timezone).toInstant().getEpochSecond();
double time = now / 72 - 18000;
now *= timeScale;
now %= 86400;
// day irl is 86400 secs
// in game, its 1200 secs
// to align, 86400 / 1200 = 72
// then we convert to ticks by multiplying 20 (1s = 20t)
// we subtract 24000 - 18000 = 6000 because 18000 is midnight
double time = (now / 72.0) * 20 - 6000;
time %= 24000;
for (World w : worlds) {
w.setFullTime((long)time);
}

View file

@ -1,23 +1,20 @@
weather:
# In which worlds weather control is allowed?
# If a world doesn't exist nothing will happen
worlds:
- world
- second_world
- third_world
# "point" - static location
# "player" - player's location (fake weather)
# "player" - player's IP location (fake weather)
# "map" - world resembles a real-world globe
source: point
point:
latitude: 41.84201
longitude: -89.485937
player:
# Get your own @ https://www.maxmind.com/en/geolite2/signup
geolite2_accountId: 710438
geolite2_apiKey: 'qLeseHp4QNQcqRGn' # Get your own @ https://www.maxmind.com/en/geolite2/signup
geolite2_apiKey: 'qLeseHp4QNQcqRGn'
map:
# Man I've really suffered while working on this one (i hate maths)
# Info:
# Valid latitude range: -90 to 90
# Valid longitude range: -180 to 180
# 1 degree of latitude and longitude is about 111 km
@ -29,20 +26,19 @@ weather:
# What to do if player exceeds the range specified above
# 1 - do nothing (clamp to nearest allowed value)
# 2 - wrap the number
# for example; if the calculated player's latitude is 94 degrees (bad), it'll be converted to -86 degrees (good)
# for example; if a player's position on map converts to 94 degrees (out of bounds), it becomes -86 degrees
on_exceed: 2
provider:
# Your provider choice
# Case insensitive
# Weather provider
choice: openweathermap
# Provider settings here
# Unlike the previous option, these are case sensitive
# Configure it here
openweathermap:
apiKey: 'd3d37fd3511ef1d4b44c7d574e9b56b8' # PLEASE get your own @ https://home.openweathermap.org/users/sign_up
# More providers soon!
realtime:
# warning: this removes sleep
enabled: false
worlds:
- world
@ -50,15 +46,14 @@ realtime:
# Alternatively choose one of these: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
timezone: 'auto'
# x day cycles / 24 hrs
# Not implemented yet
timeScale: 1.0
# How often should we recalculate the time (in ticks)
# Very minimal, if any, impact on performance
# Very minimal impact on performance
interval: 1
settings:
# Delay between rechecking weather
# 20 is one second
# in ticks, 20 is one second
# Shouldn't affect performance
timeBetweenRecheck: 600
# Whether to display an actionbar containing info
@ -70,6 +65,7 @@ settings:
debugAllowDox: false
messages:
# settings.actionbar toggles this
# %weather_full% - full state description, such as "extreme thunder"
# %weather% - short state description, such as "rain"
actionbarInfo: "&b%weather_full%"

View file

@ -5,7 +5,7 @@ author: Minecon724
main: pl.minecon724.realweather.RW
libraries:
- org.json:json:20220320
- com.maxmind.geoip2:geoip2:3.0.1
- com.maxmind.geoip2:geoip2:4.1.0
commands:
realweather:
alias: rw