From c5dcfb1ba6b5e8110dd38393bacc964915217b35 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 3 Sep 2018 23:45:11 -0400 Subject: [PATCH] Prettier, conciser, and more useful ProtocolVersion#toString() --- .../proxy/protocol/StateRegistry.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java index d45d94040..91fab4eb4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -1,5 +1,6 @@ package com.velocitypowered.proxy.protocol; +import com.google.common.base.Strings; import com.google.common.primitives.ImmutableIntArray; import com.velocitypowered.proxy.protocol.packet.*; import io.netty.util.collection.IntObjectHashMap; @@ -258,9 +259,18 @@ public enum StateRegistry { @Override public String toString() { + StringBuilder mappingAsString = new StringBuilder("{"); + for (Object2IntMap.Entry> entry : packetClassToId.object2IntEntrySet()) { + mappingAsString.append(entry.getKey().getSimpleName()).append(" -> ") + .append("0x") + .append(Strings.padStart(Integer.toHexString(entry.getIntValue()), 2, '0')) + .append(", "); + } + mappingAsString.setLength(mappingAsString.length() - 2); + mappingAsString.append("}"); return "ProtocolVersion{" + "id=" + id + - ", packetClassToId=" + packetClassToId + + ", packetClassToId=" + mappingAsString.toString() + '}'; } }