Class AgentEventEncoders

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

final class AgentEventEncoders extends Object
Pure encoders for the outbound protocol 2 event payloads: player.command, player.join/player.leave and error.report.

Each method returns a payload JsonObject that the connection wraps in an envelope, or null when the input cannot satisfy the contract. A null means "do not send": the gateway answers a non-conforming frame with invalid_message and closes, so dropping an unencodable event locally is the only safe answer. No method throws.

Redaction. Text handed to these encoders is already redacted by the phase's builders (D-20): an error report's message, trigger detail and stack trace come from the collector's serialisation path, which replaces a sensitive command's arguments with ***. A player.command payload carries the command name only because the schema has no field for an argument (D-20).

Package-private: wired by the session plan (22-22), not part of the public API.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static interface 
    The values an error.report payload is built from, as the session plan maps them out of the error-report collector's report.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Pattern
    packages/contracts: player.command payload name.
    private static final int
     
    private static final int
     
    private static final Pattern
    packages/contracts: error.report fingerprint, at least eight lower-case hex digits.
    private static final int
    The fingerprint width the collector's Integer.toHexString output is padded to.
    private static final int
     
    private static final long
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final long
     
    private static final long
     
    private static final int
     
    private static final double
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    addNullableText(com.google.gson.JsonObject payload, String key, String value)
     
    private static String
    cut(String value, int maxCodePoints)
    Cuts a string to a number of code points, so a supplementary character is never split into an unpaired surrogate.
    (package private) static com.google.gson.JsonObject
    Encodes an error.report payload.
    private static String
    Left-pads the collector's fingerprint with zeros to the contract's minimum width without changing it otherwise, so a panel error group keeps the same id across restarts and versions.
    private static com.google.gson.JsonElement
    jsonOf(String value)
     
    private static com.google.gson.JsonElement
    megabytes(Long value)
     
    private static com.google.gson.JsonElement
     
    private static String
    Trims a short field and turns a blank one into null, which the contract allows where an empty string would fail its minLength.
    (package private) static com.google.gson.JsonObject
    playerCommand(String normalisedName)
    Encodes a player.command payload.
    private static String
    Keeps a player name only when the contract's name pattern accepts it.
    (package private) static com.google.gson.JsonObject
    playerRef(String uuid, String name)
    Encodes the payload shared by player.join and player.leave.
    private static long
    seenAt(long value)
     
    private static com.google.gson.JsonObject
    Clamps a snapshot to the contract's shape: four keys, each a number or JSON null.
    private static com.google.gson.JsonElement
    tps(Double value)
     
    private static String
    Maps a trigger type onto the contract's enumeration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • COMMAND_NAME

      private static final Pattern COMMAND_NAME
      packages/contracts: player.command payload name.
    • FINGERPRINT

      private static final Pattern FINGERPRINT
      packages/contracts: error.report fingerprint, at least eight lower-case hex digits.
    • EXCEPTION_TYPE_MAX

      private static final int EXCEPTION_TYPE_MAX
      See Also:
    • MESSAGE_MAX

      private static final int MESSAGE_MAX
      See Also:
    • STACK_TRACE_MAX

      private static final int STACK_TRACE_MAX
      See Also:
    • MODULE_NAME_MAX

      private static final int MODULE_NAME_MAX
      See Also:
    • DETAIL_MAX

      private static final int DETAIL_MAX
      See Also:
    • LOCATION_MAX

      private static final int LOCATION_MAX
      See Also:
    • OCCURRENCES_MAX

      private static final int OCCURRENCES_MAX
      See Also:
    • TPS_MAX

      private static final double TPS_MAX
      See Also:
    • MEMORY_MB_MAX

      private static final long MEMORY_MB_MAX
      See Also:
    • ONLINE_PLAYERS_MAX

      private static final long ONLINE_PLAYERS_MAX
      See Also:
    • SEEN_AT_MAX

      private static final long SEEN_AT_MAX
      See Also:
    • FINGERPRINT_WIDTH

      private static final int FINGERPRINT_WIDTH
      The fingerprint width the collector's Integer.toHexString output is padded to.
      See Also:
  • Constructor Details

    • AgentEventEncoders

      private AgentEventEncoders()
  • Method Details

    • playerCommand

      static com.google.gson.JsonObject playerCommand(String normalisedName)
      Encodes a player.command payload.
      Parameters:
      normalisedName - the command name after the framework's normalisation (leading slash and namespace removed, lower-cased), or null
      Returns:
      { name } when the name satisfies the schema, otherwise null
    • playerRef

      static com.google.gson.JsonObject playerRef(String uuid, String name)
      Encodes the payload shared by player.join and player.leave.
      Parameters:
      uuid - the player's UUID in canonical lower-case hyphenated form, or null
      name - the player's name, including a Floodgate prefix, or null
      Returns:
      { playerUuid, playerName } when both satisfy the contract, otherwise null
    • errorReport

      static com.google.gson.JsonObject errorReport(AgentEventEncoders.ErrorReportView view)
      Encodes an error.report payload.

      Bounds are applied, not rejected: text is cut to its contract length, occurrence counts below one become one, and a player name that cannot satisfy the schema becomes JSON null, because losing one optional field is better than losing the report. Only a payload that could never be valid — a fingerprint that is not hexadecimal, an empty exception type — returns null.

      Parameters:
      view - the report's values, or null
      Returns:
      the payload, or null when it cannot be made valid
    • fingerprint

      private static String fingerprint(String raw)
      Left-pads the collector's fingerprint with zeros to the contract's minimum width without changing it otherwise, so a panel error group keeps the same id across restarts and versions.
      Parameters:
      raw - the collector's fingerprint, or null
      Returns:
      a lower-case hexadecimal fingerprint of at least eight digits, or null
    • snapshot

      private static com.google.gson.JsonObject snapshot(AgentEventEncoders.ErrorReportView view)
      Clamps a snapshot to the contract's shape: four keys, each a number or JSON null.
      Parameters:
      view - the report's values
      Returns:
      the snapshot object
    • tps

      private static com.google.gson.JsonElement tps(Double value)
    • megabytes

      private static com.google.gson.JsonElement megabytes(Long value)
    • onlinePlayers

      private static com.google.gson.JsonElement onlinePlayers(Long value)
    • triggerKind

      private static String triggerKind(String raw)
      Maps a trigger type onto the contract's enumeration.

      The collector stores TriggerContext.TriggerType#name(): COMMAND, EVENT, SCHEDULED, AOP and UNCAUGHT. The contract knows only event, command, scheduler and other, so an AOP interception and an uncaught exception report as other, and so does anything else unknown. Matching ignores case, so the contract's own names pass through as they are.

      Parameters:
      raw - the collector's trigger type, or null
      Returns:
      one of event, command, scheduler, other
    • playerName

      private static String playerName(String raw)
      Keeps a player name only when the contract's name pattern accepts it.
      Parameters:
      raw - the player's name, or null
      Returns:
      the name, or null when it cannot be sent
    • cut

      private static String cut(String value, int maxCodePoints)
      Cuts a string to a number of code points, so a supplementary character is never split into an unpaired surrogate.
      Parameters:
      value - the text, possibly null
      maxCodePoints - the largest allowed length in code points
      Returns:
      the text, cut when longer; an empty string for null
    • optionalText

      private static String optionalText(String value)
      Trims a short field and turns a blank one into null, which the contract allows where an empty string would fail its minLength.
      Parameters:
      value - the already cut text, possibly null
      Returns:
      the trimmed text, or null when blank
    • addNullableText

      private static void addNullableText(com.google.gson.JsonObject payload, String key, String value)
    • jsonOf

      private static com.google.gson.JsonElement jsonOf(String value)
    • seenAt

      private static long seenAt(long value)