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:
Minecon724 2024-01-16 19:32:21 +00:00
parent a8fd1c4214
commit ab6df79cae
8 changed files with 91 additions and 20 deletions

View file

@ -4,3 +4,4 @@
- fix realtime
- cache cleaning
- prevent packets
- tests

View file

@ -22,11 +22,11 @@ public class RW extends JavaPlugin {
saveDefaultConfig();
config = getConfig();
WorldMap worldMap = WorldMap.fromConfig(
WorldMap.init(
config.getConfigurationSection("map")
);
WeatherCommander weatherCommander = new WeatherCommander(worldMap, this);
WeatherCommander weatherCommander = new WeatherCommander(this);
try {
weatherCommander.init(
config.getConfigurationSection("weather")

View file

@ -6,17 +6,25 @@ import org.bukkit.entity.Player;
import pl.minecon724.realweather.map.exceptions.GeoIPException;
public class WorldMap {
private static WorldMap INSTANCE;
private final Type type;
private Coordinates point;
public static WorldMap getInstance() {
if (INSTANCE == null)
throw new NullPointerException("No WorldMap");
return INSTANCE;
}
public WorldMap(Type type,
Coordinates point) {
this.type = type;
this.point = point;
}
public static WorldMap fromConfig(ConfigurationSection config)
public static void init(ConfigurationSection config)
throws IllegalArgumentException {
Type type;
@ -49,10 +57,7 @@ public class WorldMap {
);
}
WorldMap worldMap = new WorldMap(type, point);
return worldMap;
INSTANCE = new WorldMap(type, point);
}
/**

View file

@ -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);
}
}
}

View file

@ -19,8 +19,12 @@ public class RealTimeCommander implements Listener {
List<String> worldNames;
double scale;
ZoneId timezone;
boolean perPlayer;
volatile List<World> worlds;
RealTimeTask task;
PlayerTimeSyncTask playerTimeSyncTask;
public RealTimeCommander(RW plugin) {
this.plugin = plugin;
@ -39,16 +43,20 @@ public class RealTimeCommander implements Listener {
}
worldNames = config.getStringList("worlds");
scale = config.getDouble("scale");
perPlayer = config.getBoolean("per_player");
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
public void start() {
task = new RealTimeTask(scale, timezone);
task = new RealTimeTask(scale, timezone, worlds);
task.runTaskTimer(plugin, 0, 1);
if (perPlayer) {
playerTimeSyncTask = new PlayerTimeSyncTask(worlds);
}
}
@EventHandler
@ -56,13 +64,13 @@ public class RealTimeCommander implements Listener {
World world = event.getWorld();
if (worldNames.contains(world.getName()))
task.worlds.add(world);
worlds.add(world);
}
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
World world = event.getWorld();
task.worlds.remove(world);
worlds.remove(world);
}
}

View file

@ -2,7 +2,6 @@ package pl.minecon724.realweather.realtime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.World;
@ -11,11 +10,12 @@ import org.bukkit.scheduler.BukkitRunnable;
public class RealTimeTask extends BukkitRunnable {
double timeScale;
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.timezone = timezone;
this.worlds = worlds;
}
@Override

View file

@ -10,7 +10,7 @@ import pl.minecon724.realweather.weather.exceptions.DisabledException;
import pl.minecon724.realweather.weather.provider.Provider;
public class WeatherCommander {
WorldMap worldMap;
private WorldMap worldMap = WorldMap.getInstance();
RW plugin;
boolean enabled;
@ -21,8 +21,7 @@ public class WeatherCommander {
GetStateTask getStateTask;
public WeatherCommander(WorldMap worldMap, RW plugin) {
this.worldMap = worldMap;
public WeatherCommander(RW plugin) {
this.plugin = plugin;
}
@ -34,6 +33,7 @@ public class WeatherCommander {
*/
public void init(ConfigurationSection config)
throws DisabledException, IllegalArgumentException {
enabled = config.getBoolean("enabled");
if (!enabled)

View file

@ -61,7 +61,8 @@ time:
# x day cycles / 24 hrs
scale: 1.0
# TODO
# time based on... time?
# each player has time offset like timezones
# uses timezone as base, unless auto
# uses settings from map
real: false
per_player: false