commit 602366a545ae0d41bd14253e62f0be4c90afe019 Author: tenkuma Date: Thu Apr 10 12:54:24 2025 -0300 First commit. diff --git a/.classpath b/.classpath new file mode 100755 index 0000000..a20094d --- /dev/null +++ b/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100755 index 0000000..9296415 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + TimeKeeper + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100755 index 0000000..4824b80 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 0000000..f1d5502 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/README.md b/README.md new file mode 100644 index 0000000..aa534c2 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +This is a plugin for Minecraft beta that syncs the real world time with your in-game time. + +## How it works +It will calculate and change the game time every second (that's 20 ticks and that can be changed in the config), it will use your computer's timezone as default if the config `timezone` value does not exist. + +## Performance +I am not sure if this plugin has any significant performance hit, it runs code every few ticks (you can in/decrease the frequency in the config) and that is not the best approach for doing this, but it's the only that works in beta. Using it with `ticksBetweenUpdate: 1` does not seem to change the performance in any way. The specifications for the computer used for the tests: + +`Host: 83AF IdeaPad 1 14IAU7` +`CPU: 12th Gen Intel i5-1235U (12) @ 1.300GHz` +`GPU: Intel Alder Lake-UP3 GT2 [Iris Xe Graphics]` +`Memory: 10097MiB / 15709MiB` diff --git a/bin/gd/rf/adrianvictor/realtime/Main$1.class b/bin/gd/rf/adrianvictor/realtime/Main$1.class new file mode 100644 index 0000000..875d551 Binary files /dev/null and b/bin/gd/rf/adrianvictor/realtime/Main$1.class differ diff --git a/bin/gd/rf/adrianvictor/realtime/Main.class b/bin/gd/rf/adrianvictor/realtime/Main.class new file mode 100644 index 0000000..2bad7cd Binary files /dev/null and b/bin/gd/rf/adrianvictor/realtime/Main.class differ diff --git a/config.yml b/config.yml new file mode 100755 index 0000000..82b1a32 --- /dev/null +++ b/config.yml @@ -0,0 +1,4 @@ +ticksBetweenUpdate: 20 +timezone: "America/Sao_Paulo" # comment this line to use system's default timezone +worlds: + - "world" \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100755 index 0000000..88c2a42 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,6 @@ +author: tenkuma +database: false +main: gd.rf.adrianvictor.realtime.Main +name: TimeKeeper +url: https://adrianvictor.rf.gd +version: '1.0' \ No newline at end of file diff --git a/src/gd/rf/adrianvictor/realtime/Main.java b/src/gd/rf/adrianvictor/realtime/Main.java new file mode 100755 index 0000000..43a654e --- /dev/null +++ b/src/gd/rf/adrianvictor/realtime/Main.java @@ -0,0 +1,51 @@ +package gd.rf.adrianvictor.realtime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.plugin.java.JavaPlugin; +import gd.rf.adrianvictor.lib.Log; +import gd.rf.adrianvictor.lib.ConfigurationEx; + +public class Main extends JavaPlugin { + Log log; + ConfigurationEx config; + + @Override + public void onDisable() { + log.info("Disabling!"); + } + + @Override + public void onEnable() { + log = new Log(this); + log.info("Starting!"); + config = new ConfigurationEx(this, "config.yml", log); + config.loadConfig(); + int ticksBetweenUpdate = config.getInt("ticksBetweenUpdate", 20); + List worlds = config.getStringList("worlds", null); + Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { + @Override + public void run() { + for (String worldName : worlds) { + World world = Bukkit.getServer().getWorld(worldName); + if (world == null) { + log.severe("World " + worldName + " specified in the config was not found, removing it."); + worlds.remove(worldName); + return; + } + ZonedDateTime time = ZonedDateTime.now(ZoneId.of(config.getString("timezone", ZoneId.systemDefault().toString()))); + int hour = time.getHour(); + int minute = time.getMinute(); + long minecraftTime = (hour * 1000 + minute * 100 / 6 - 6000) % 24000; + if (minecraftTime < 0) { + minecraftTime = minecraftTime * 2; + } + world.setTime(minecraftTime); + } + } + }, 0L, ticksBetweenUpdate); + } +}