From f713c3b5d93df90451eeb697ecf936173b6a9096 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 13 Jun 2017 21:12:15 -0700 Subject: [PATCH 1/2] Send elapsed time and day length (E, command) --- .../github/satoshinm/WebSandboxMC/bridge/BlockBridge.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java b/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java index 2a52a29..9a2a515 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java @@ -133,6 +133,13 @@ public void sendWorld(final Channel channel) { webSocketServerThread.sendLine(channel, "m,0"); } + int day_length = 60 * 20; // 20 minutes + + double fraction = world.getTime() / 1000.0 / 24.0; // 0-1 + double elapsed = (fraction + 6.0 / 24) * day_length; + System.out.println("day_length = "+day_length+", elapsed="+elapsed); + webSocketServerThread.sendLine(channel, "E," + elapsed + "," + day_length); + // Send a multi-block update message announcement that a binary chunk is coming /* int startx = -radius; From cf92e2ca4729e01bfdfbc8bddc91373a73f06f2e Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Tue, 13 Jun 2017 21:17:38 -0700 Subject: [PATCH 2/2] Add see_time option to enable/disable time --- README.md | 1 + .../github/satoshinm/WebSandboxMC/Settings.java | 1 + .../WebSandboxMC/bridge/BlockBridge.java | 15 +++++++++++---- .../WebSandboxMC/bukkit/SettingsBukkit.java | 2 ++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dd75851..f4e3e6d 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Configures the NetCraft web client: * `allow_chatting` (true): allow web users to send chat messages to the server * `see_chat` (true): allow web users to receive chat messages from the server * `see_players` (true): allow web users to see other player positions +* `see_time` (true): sync server time to web client time if true, if false then fixed at noon * `creative_mode` (true): if true, the web client is set to creative mode by default, else survival mode (warning: survival mode is incomplete and experiemntal) * `blocks_to_web_override`: map of Bukkit material names to NetCraft web client IDs -- you can add additional block types here if they don't show up correctly * This overrides the built-in map, and by default is empty (`blocks_to_web` pre-1.4.2 is no longer used). diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java b/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java index 6089139..32fa4df 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/Settings.java @@ -47,6 +47,7 @@ abstract public class Settings { public boolean allowChatting = true; public boolean seeChat = true; public boolean seePlayers = true; + public boolean seeTime = true; public boolean creativeMode = true; public Map blocksToWebOverride = new HashMap(); diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java b/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java index 9a2a515..4823911 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/bridge/BlockBridge.java @@ -30,6 +30,7 @@ public class BlockBridge { public Location spawnLocation; private boolean allowBreakPlaceBlocks; private boolean allowSigns; + private boolean seeTime; private Map blocksToWeb; private int blocksToWebMissing; // unknown/unsupported becomes cloud, if key missing private boolean warnMissing; @@ -69,6 +70,7 @@ public BlockBridge(WebSocketServerThread webSocketServerThread, Settings setting this.allowBreakPlaceBlocks = settings.allowBreakPlaceBlocks; this.allowSigns = settings.allowSigns; + this.seeTime = settings.seeTime; this.blocksToWeb = new HashMap(); this.blocksToWebMissing = 16; // unknown/unsupported becomes cloud @@ -135,10 +137,15 @@ public void sendWorld(final Channel channel) { int day_length = 60 * 20; // 20 minutes - double fraction = world.getTime() / 1000.0 / 24.0; // 0-1 - double elapsed = (fraction + 6.0 / 24) * day_length; - System.out.println("day_length = "+day_length+", elapsed="+elapsed); - webSocketServerThread.sendLine(channel, "E," + elapsed + "," + day_length); + if (seeTime) { + double fraction = world.getTime() / 1000.0 / 24.0; // 0-1 + double elapsed = (fraction + 6.0 / 24) * day_length; + System.out.println("day_length = "+day_length+", elapsed="+elapsed); + webSocketServerThread.sendLine(channel, "E," + elapsed + "," + day_length); + // TODO: listen for server time change and resend E, command + } else { + webSocketServerThread.sendLine(channel, "E,0,0"); + } // Send a multi-block update message announcement that a binary chunk is coming /* diff --git a/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java b/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java index 764ec9b..935d4ec 100644 --- a/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java +++ b/src/main/java/io/github/satoshinm/WebSandboxMC/bukkit/SettingsBukkit.java @@ -52,6 +52,7 @@ public SettingsBukkit(Plugin plugin) { config.addDefault("nc.allow_chatting", this.allowChatting); config.addDefault("nc.see_chat", this.seeChat); config.addDefault("nc.see_players", this.seePlayers); + config.addDefault("nc.see_time", this.seeTime); config.addDefault("nc.creative_mode", this.creativeMode); config.addDefault("nc.blocks_to_web_override", this.blocksToWebOverride); @@ -92,6 +93,7 @@ public SettingsBukkit(Plugin plugin) { this.allowChatting = plugin.getConfig().getBoolean("nc.allow_chatting"); this.seeChat = plugin.getConfig().getBoolean("nc.see_chat"); this.seePlayers = plugin.getConfig().getBoolean("nc.see_players"); + this.seeTime = plugin.getConfig().getBoolean("nc.see_time"); this.creativeMode = plugin.getConfig().getBoolean("nc.creative_mode"); if (plugin.getConfig().getConfigurationSection("nc.blocks_to_web") != null) { this.log(Level.WARNING, "blocks_to_web is now ignored, you can remove it or add to blocks_to_web_override instead");