Class ServerPropertiesManager

java.lang.Object
com.ultikits.ultitools.manager.ServerPropertiesManager

@Internal public class ServerPropertiesManager extends Object
Safe server.properties manager for remote editing via WebSocket. Only exposes a curated whitelist of non-sensitive keys.
  • Field Details

  • Constructor Details

    • ServerPropertiesManager

      public ServerPropertiesManager(File serverRoot)
  • Method Details

    • setWebSocketClient

      public void setWebSocketClient(UltiPanelWebSocketClient client)
    • getSafeProperties

      public Map<String,String> getSafeProperties()
    • setProperty

      public boolean setProperty(String key, String value)
    • writeProperty

      private ServerPropertiesManager.WriteOutcome writeProperty(String key, String value)
      Why this exists next to setProperty(String, String): the boolean is lossy. A false could mean "the key is not on the whitelist", "there is no server.properties to write to", or "the write itself failed" — three situations with three different fixes, collapsed into one value. The batch path has to tell the caller which one happened, so the real outcome is produced here and setProperty keeps its original contract by narrowing it.

      为什么要在 setProperty(String, String) 旁边多这一个:那个布尔值是有损的。 false 可能是「键不在白名单」「没有 server.properties 可写」或「写入本身失败」, 三种处置完全不同的情况被压成了同一个值。批量路径必须告诉调用方是哪一种, 所以真实结果在这里产生,setProperty 通过收窄它来保持原有契约。

    • handleServerProperties

      public void handleServerProperties(com.google.gson.JsonObject data)
      Handle WebSocket message for server properties operations.
      Parameters:
      data - the message data
    • handleGet

      private void handleGet()
    • handleSet

      private void handleSet(com.google.gson.JsonObject data)
    • handleSetAll

      private void handleSetAll(com.google.gson.JsonObject data)
    • applySetAll

      public ServerPropertiesManager.SetAllResult applySetAll(com.google.gson.JsonObject values)
      Apply a batch of properties, report it over the socket, and hand the outcome back.

      The return value is the point. handleSetAll does not need it — it only ever builds a message — but update_config with fileName: server_properties routes through here too, and its config_update_response is supposed to distinguish "delivered" from "took effect". Before this returned anything, that path had no way to learn the answer and reported success unconditionally.

      应用一批属性、把结果发回面板,并把结果交还给调用方。 返回值才是重点handleSetAll 用不到它(它只负责拼一条消息), 但 fileName: server_propertiesupdate_config 也走这里, 而它的 config_update_response 要区分「已下发」和「已生效」。 在这个方法有返回值之前,那条路径没有任何途径知道答案,只能无条件报成功。

      Parameters:
      values - key → value, an explicit JSON null meaning "leave this key alone"
      Returns:
      what happened to each key
    • buildSetAllResponse

      private com.google.gson.JsonObject buildSetAllResponse(ServerPropertiesManager.SetAllResult result)
    • toJsonArray

      private static com.google.gson.JsonArray toJsonArray(List<String> keys)
    • warnIfIncomplete

      private void warnIfIncomplete(ServerPropertiesManager.SetAllResult result)
      The response above is what the panel reads; this is what a server operator reads. Both are needed: someone changing a setting that silently does not apply otherwise finds nothing on either side.

      上面那条响应是给面板读的,这条是给服主读的。两边都要有: 否则改了个设置没生效的人,面板和服务器日志两头都查不到原因。

    • sendResponse

      private void sendResponse(com.google.gson.JsonObject response)