diff --git a/src/main/java/org/dynmap/ClientUpdateComponent.java b/src/main/java/org/dynmap/ClientUpdateComponent.java index 7154835d..b96d0e9c 100644 --- a/src/main/java/org/dynmap/ClientUpdateComponent.java +++ b/src/main/java/org/dynmap/ClientUpdateComponent.java @@ -6,8 +6,10 @@ import static org.dynmap.JSONUtils.s; import java.util.Set; import org.bukkit.ChatColor; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -28,6 +30,8 @@ public class ClientUpdateComponent extends Component { JSONObject u = e.update; long since = e.timestamp; String worldName = world.getName(); + int hideifshadow = configuration.getInteger("hideifshadow", 15); + int hideifunder = configuration.getInteger("hideifundercover", 15); s(u, "servertime", world.getTime() % 24000); s(u, "hasStorm", world.hasStorm()); @@ -39,14 +43,26 @@ public class ClientUpdateComponent extends Component { Player p = players[i]; Location pl = p.getLocation(); JSONObject jp = new JSONObject(); + boolean hide = false; + s(jp, "type", "player"); s(jp, "name", ChatColor.stripColor(p.getDisplayName())); s(jp, "account", p.getName()); + if(hideifshadow < 15) { + if(pl.getBlock().getLightLevel() <= hideifshadow) + hide = true; + } + if(hideifunder < 15) { + /*TODO: when pull accepted for getSkyLightLevel(), switch to that */ + if(pl.getWorld().getHighestBlockYAt(pl) > pl.getBlockY()) + hide = true; + } + /* Don't leak player location for world not visible on maps, or if sendposition disbaled */ DynmapWorld pworld = MapManager.mapman.worldsLookup.get(p.getWorld().getName()); /* Fix typo on 'sendpositon' to 'sendposition', keep bad one in case someone used it */ if(configuration.getBoolean("sendposition", true) && configuration.getBoolean("sendpositon", true) && - (pworld != null) && pworld.sendposition) { + (pworld != null) && pworld.sendposition && (!hide)) { s(jp, "world", p.getWorld().getName()); s(jp, "x", pl.getX()); s(jp, "y", pl.getY()); @@ -59,7 +75,7 @@ public class ClientUpdateComponent extends Component { s(jp, "z", 0.0); } /* Only send health if enabled AND we're on visible world */ - if (configuration.getBoolean("sendhealth", false) && (pworld != null) && pworld.sendhealth) { + if (configuration.getBoolean("sendhealth", false) && (pworld != null) && pworld.sendhealth && (!hide)) { s(jp, "health", p.getHealth()); s(jp, "armor", Armor.getArmorPoints(p)); } diff --git a/src/main/resources/configuration.txt b/src/main/resources/configuration.txt index 83966e73..9f9887b0 100644 --- a/src/main/resources/configuration.txt +++ b/src/main/resources/configuration.txt @@ -22,6 +22,10 @@ components: hidewebchatip: false trustclientname: false includehiddenplayers: false + # # Optional - make players hidden when they are inside/underground/in shadows (#=light level: 0=full shadow,15=sky) + # hideifshadow: 4 + # # Optional - make player hidden when they are under cover (#=sky light level,0=underground,15=open to sky) + # hideifundercover: 14 #- class: org.dynmap.JsonFileClientUpdateComponent # writeinterval: 1 # sendhealth: true @@ -30,7 +34,9 @@ components: # webchat-interval: 5 # hidewebchatip: false # includehiddenplayers: false - + # hideifshadow: 4 + # hideifundercover: 14 + - class: org.dynmap.SimpleWebChatComponent allowchat: true #- class: org.dynmap.herochat.HeroWebChatComponent