Skip to content

Commit

Permalink
Merge pull request #93 from satoshinm/time
Browse files Browse the repository at this point in the history
Add time synchronization
  • Loading branch information
satoshinm authored Jun 14, 2017
2 parents a072bc6 + cf92e2c commit 93ea9f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> blocksToWebOverride = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class BlockBridge {
public Location spawnLocation;
private boolean allowBreakPlaceBlocks;
private boolean allowSigns;
private boolean seeTime;
private Map<Material, Integer> blocksToWeb;
private int blocksToWebMissing; // unknown/unsupported becomes cloud, if key missing
private boolean warnMissing;
Expand Down Expand Up @@ -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<Material, Integer>();
this.blocksToWebMissing = 16; // unknown/unsupported becomes cloud
Expand Down Expand Up @@ -133,6 +135,18 @@ public void sendWorld(final Channel channel) {
webSocketServerThread.sendLine(channel, "m,0");
}

int day_length = 60 * 20; // 20 minutes

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
/*
int startx = -radius;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 93ea9f9

Please sign in to comment.