work
sorry I'm really tired because of school you see it's almost the year's end so there's nothing left to do so we just sit in class doing nothing, what a waste of time
This commit is contained in:
parent
1efd8cb091
commit
b2a474b011
3 changed files with 73 additions and 0 deletions
|
@ -0,0 +1,41 @@
|
|||
package eu.m724.realweather.time;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
import eu.m724.realweather.weather.PlayerWeatherDirectory;
|
||||
import eu.m724.wtapi.object.Coordinates;
|
||||
import eu.m724.wtapi.object.Weather;
|
||||
|
||||
public class AsyncPlayerTimeTask extends BukkitRunnable {
|
||||
private PlayerWeatherDirectory playerWeatherDirectory =
|
||||
GlobalConstants.getPlayerWeatherDirectory();
|
||||
private Server server = GlobalConstants.getPlugin().getServer();
|
||||
private Mapper mapper = GlobalConstants.getMapper();
|
||||
|
||||
private TimeConfig timeConfig;
|
||||
|
||||
AsyncPlayerTimeTask(TimeConfig timeConfig) {
|
||||
this.timeConfig = timeConfig;
|
||||
}
|
||||
|
||||
@Override // TODO TODO TODO
|
||||
public void run() {
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
if (!player.hasPermission("realweather.dynamic")) continue;
|
||||
Weather weather = playerWeatherDirectory.getWeather(player);
|
||||
|
||||
if (weather != null) {
|
||||
// TODO sunrise sunset
|
||||
}
|
||||
|
||||
Coordinates coordinates = mapper.locationToCoordinates(player.getLocation());
|
||||
long offsetTicks = (long) (coordinates.longitude / (360 / 1728000));
|
||||
player.setPlayerTime(offsetTicks, true);
|
||||
}
|
||||
}
|
||||
// TODO make this also a listener for player joins
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package eu.m724.realweather.time;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
|
||||
public class SyncTimeUpdateTask extends BukkitRunnable {
|
||||
private TimeConfig timeConfig;
|
||||
private Mapper mapper = GlobalConstants.getMapper();
|
||||
|
||||
SyncTimeUpdateTask(TimeConfig timeConfig) {
|
||||
this.timeConfig = timeConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long now = System.currentTimeMillis() / 1000;
|
||||
long time = (long) (((now / 3600 * 1000) - 6000) * timeConfig.modifier % 24000); // TODO test this
|
||||
|
||||
mapper.getWorlds().forEach(world -> world.setFullTime(time));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package eu.m724.realweather.time;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import eu.m724.realweather.DebugLogger;
|
||||
import eu.m724.realweather.GlobalConstants;
|
||||
import eu.m724.realweather.mapper.Mapper;
|
||||
|
@ -8,6 +10,7 @@ import eu.m724.realweather.object.UserException;
|
|||
public class TimeMaster {
|
||||
private TimeConfig config;
|
||||
private Mapper mapper = GlobalConstants.getMapper();
|
||||
private Plugin plugin = GlobalConstants.getPlugin();
|
||||
|
||||
public TimeMaster(TimeConfig config) {
|
||||
this.config = config;
|
||||
|
@ -21,6 +24,11 @@ public class TimeMaster {
|
|||
if (!config.enabled)
|
||||
return;
|
||||
|
||||
|
||||
long period = 1; // TODO calculate update period
|
||||
new SyncTimeUpdateTask(config).runTaskTimer(plugin, 0, period);
|
||||
new AsyncPlayerTimeTask(config).runTaskTimerAsynchronously(plugin, 0, period);
|
||||
|
||||
// TODO start task, actually create that task, account for data from weather like sunrise sunset timezone
|
||||
DebugLogger.info("time loaded", 1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue