where changelog??
I don't keep track of the changes because I do some work and commit at the end of the day you can see what changed looking at the code and files changed
This commit is contained in:
parent
a8fd1c4214
commit
ab6df79cae
8 changed files with 91 additions and 20 deletions
1
TODO.md
1
TODO.md
|
@ -4,3 +4,4 @@
|
||||||
- fix realtime
|
- fix realtime
|
||||||
- cache cleaning
|
- cache cleaning
|
||||||
- prevent packets
|
- prevent packets
|
||||||
|
- tests
|
|
@ -22,11 +22,11 @@ public class RW extends JavaPlugin {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
config = getConfig();
|
config = getConfig();
|
||||||
|
|
||||||
WorldMap worldMap = WorldMap.fromConfig(
|
WorldMap.init(
|
||||||
config.getConfigurationSection("map")
|
config.getConfigurationSection("map")
|
||||||
);
|
);
|
||||||
|
|
||||||
WeatherCommander weatherCommander = new WeatherCommander(worldMap, this);
|
WeatherCommander weatherCommander = new WeatherCommander(this);
|
||||||
try {
|
try {
|
||||||
weatherCommander.init(
|
weatherCommander.init(
|
||||||
config.getConfigurationSection("weather")
|
config.getConfigurationSection("weather")
|
||||||
|
|
|
@ -6,17 +6,25 @@ import org.bukkit.entity.Player;
|
||||||
import pl.minecon724.realweather.map.exceptions.GeoIPException;
|
import pl.minecon724.realweather.map.exceptions.GeoIPException;
|
||||||
|
|
||||||
public class WorldMap {
|
public class WorldMap {
|
||||||
|
private static WorldMap INSTANCE;
|
||||||
|
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
private Coordinates point;
|
private Coordinates point;
|
||||||
|
|
||||||
|
public static WorldMap getInstance() {
|
||||||
|
if (INSTANCE == null)
|
||||||
|
throw new NullPointerException("No WorldMap");
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
public WorldMap(Type type,
|
public WorldMap(Type type,
|
||||||
Coordinates point) {
|
Coordinates point) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.point = point;
|
this.point = point;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WorldMap fromConfig(ConfigurationSection config)
|
public static void init(ConfigurationSection config)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
|
@ -49,10 +57,7 @@ public class WorldMap {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldMap worldMap = new WorldMap(type, point);
|
INSTANCE = new WorldMap(type, point);
|
||||||
|
|
||||||
return worldMap;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package pl.minecon724.realweather.realtime;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import pl.minecon724.realweather.map.Coordinates;
|
||||||
|
import pl.minecon724.realweather.map.WorldMap;
|
||||||
|
import pl.minecon724.realweather.map.exceptions.GeoIPException;
|
||||||
|
|
||||||
|
public class PlayerTimeSyncTask extends BukkitRunnable {
|
||||||
|
private WorldMap worldMap = WorldMap.getInstance();
|
||||||
|
private Logger logger = Logger.getLogger("timezone sync");
|
||||||
|
|
||||||
|
private List<World> worlds;
|
||||||
|
|
||||||
|
public PlayerTimeSyncTask(List<World> worlds) {
|
||||||
|
this.worlds = worlds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (!worlds.contains(player.getWorld())) {
|
||||||
|
player.resetPlayerTime();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Coordinates coordinates;
|
||||||
|
|
||||||
|
try {
|
||||||
|
coordinates = worldMap.getCoordinates(player);
|
||||||
|
} catch (GeoIPException e) {
|
||||||
|
logger.warning(
|
||||||
|
String.format("Unable to determine GeoIP for %s (%s)",
|
||||||
|
player.getAddress().getHostString()));
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// longitude
|
||||||
|
// / 15 as 15 degrees is 1 hour
|
||||||
|
// * 60 to minutes
|
||||||
|
// * 60 again to seconds
|
||||||
|
// * 20 to ticks
|
||||||
|
long offset = (long) (coordinates.longitude / 15 * 72000);
|
||||||
|
|
||||||
|
player.setPlayerTime(offset, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,8 +19,12 @@ public class RealTimeCommander implements Listener {
|
||||||
List<String> worldNames;
|
List<String> worldNames;
|
||||||
double scale;
|
double scale;
|
||||||
ZoneId timezone;
|
ZoneId timezone;
|
||||||
|
boolean perPlayer;
|
||||||
|
|
||||||
|
volatile List<World> worlds;
|
||||||
|
|
||||||
RealTimeTask task;
|
RealTimeTask task;
|
||||||
|
PlayerTimeSyncTask playerTimeSyncTask;
|
||||||
|
|
||||||
public RealTimeCommander(RW plugin) {
|
public RealTimeCommander(RW plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -39,16 +43,20 @@ public class RealTimeCommander implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
worldNames = config.getStringList("worlds");
|
worldNames = config.getStringList("worlds");
|
||||||
|
|
||||||
scale = config.getDouble("scale");
|
scale = config.getDouble("scale");
|
||||||
|
perPlayer = config.getBoolean("per_player");
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
task = new RealTimeTask(scale, timezone);
|
task = new RealTimeTask(scale, timezone, worlds);
|
||||||
|
|
||||||
task.runTaskTimer(plugin, 0, 1);
|
task.runTaskTimer(plugin, 0, 1);
|
||||||
|
|
||||||
|
if (perPlayer) {
|
||||||
|
playerTimeSyncTask = new PlayerTimeSyncTask(worlds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -56,13 +64,13 @@ public class RealTimeCommander implements Listener {
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
|
|
||||||
if (worldNames.contains(world.getName()))
|
if (worldNames.contains(world.getName()))
|
||||||
task.worlds.add(world);
|
worlds.add(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onWorldUnload(WorldUnloadEvent event) {
|
public void onWorldUnload(WorldUnloadEvent event) {
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
|
|
||||||
task.worlds.remove(world);
|
worlds.remove(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package pl.minecon724.realweather.realtime;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -11,11 +10,12 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||||
public class RealTimeTask extends BukkitRunnable {
|
public class RealTimeTask extends BukkitRunnable {
|
||||||
double timeScale;
|
double timeScale;
|
||||||
ZoneId timezone;
|
ZoneId timezone;
|
||||||
List<World> worlds = new ArrayList<>();
|
List<World> worlds;
|
||||||
|
|
||||||
public RealTimeTask(double timeScale, ZoneId timezone) {
|
public RealTimeTask(double timeScale, ZoneId timezone, List<World> worlds) {
|
||||||
this.timeScale = timeScale;
|
this.timeScale = timeScale;
|
||||||
this.timezone = timezone;
|
this.timezone = timezone;
|
||||||
|
this.worlds = worlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,7 +10,7 @@ import pl.minecon724.realweather.weather.exceptions.DisabledException;
|
||||||
import pl.minecon724.realweather.weather.provider.Provider;
|
import pl.minecon724.realweather.weather.provider.Provider;
|
||||||
|
|
||||||
public class WeatherCommander {
|
public class WeatherCommander {
|
||||||
WorldMap worldMap;
|
private WorldMap worldMap = WorldMap.getInstance();
|
||||||
RW plugin;
|
RW plugin;
|
||||||
|
|
||||||
boolean enabled;
|
boolean enabled;
|
||||||
|
@ -21,8 +21,7 @@ public class WeatherCommander {
|
||||||
|
|
||||||
GetStateTask getStateTask;
|
GetStateTask getStateTask;
|
||||||
|
|
||||||
public WeatherCommander(WorldMap worldMap, RW plugin) {
|
public WeatherCommander(RW plugin) {
|
||||||
this.worldMap = worldMap;
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +33,7 @@ public class WeatherCommander {
|
||||||
*/
|
*/
|
||||||
public void init(ConfigurationSection config)
|
public void init(ConfigurationSection config)
|
||||||
throws DisabledException, IllegalArgumentException {
|
throws DisabledException, IllegalArgumentException {
|
||||||
|
|
||||||
enabled = config.getBoolean("enabled");
|
enabled = config.getBoolean("enabled");
|
||||||
|
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
|
|
|
@ -61,7 +61,8 @@ time:
|
||||||
# x day cycles / 24 hrs
|
# x day cycles / 24 hrs
|
||||||
scale: 1.0
|
scale: 1.0
|
||||||
|
|
||||||
# TODO
|
|
||||||
# time based on... time?
|
# time based on... time?
|
||||||
|
# each player has time offset like timezones
|
||||||
|
# uses timezone as base, unless auto
|
||||||
# uses settings from map
|
# uses settings from map
|
||||||
real: false
|
per_player: false
|
||||||
|
|
Loading…
Reference in a new issue