package us.myles.ViaVersion.api.type.types;

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.type.Type;

public class StringType extends Type<String> {
    // String#length() (used to limit the string in Minecraft source code) uses char[]#length
    private static final int maxJavaCharUtf8Length = Character.toString(Character.MAX_VALUE)
            .getBytes(Charsets.UTF_8).length;

    public StringType() {
        super(String.class);
    }

    @Override
    public String read(ByteBuf buffer) throws Exception {
        int len = Type.VAR_INT.read(buffer);

        Preconditions.checkArgument(len <= Short.MAX_VALUE * maxJavaCharUtf8Length,
                "Cannot receive string longer than Short.MAX_VALUE * "  + maxJavaCharUtf8Length + " bytes (got %s bytes)", len);

        byte[] b = new byte[len];
        buffer.readBytes(b);
        String string = new String(b, Charsets.UTF_8);
        Preconditions.checkArgument(string.length() <= Short.MAX_VALUE,
                "Cannot receive string longer than Short.MAX_VALUE characters (got %s bytes)", string.length());

        return string;
    }

    @Override
    public void write(ByteBuf buffer, String object) throws Exception {
        Preconditions.checkArgument(object.length() <= Short.MAX_VALUE, "Cannot send string longer than Short.MAX_VALUE (got %s characters)", object.length());

        byte[] b = object.getBytes(Charsets.UTF_8);
        Type.VAR_INT.write(buffer, b.length);
        buffer.writeBytes(b);
    }
}

@@ -42,48 +42,8 @@
 s;%0A%0A
-import com.google.common.base.Charsets;%0A
 impo
@@ -83,16 +83,16 @@
 itions;%0A
+
 import i
@@ -158,16 +158,59 @@
 .Type;%0A%0A
+import java.nio.charset.StandardCharsets;%0A%0A
 public c
@@ -449,32 +449,40 @@
       .getBytes(
+Standard
 Charsets.UTF_8).
@@ -896,117 +896,123 @@
     
-byte%5B%5D b = new byte%5Blen%5D;%0A        buffer.readBytes(b);%0A        String string = new String(b, Charsets.UTF_8);
+String string = buffer.toString(buffer.readerIndex(), len, StandardCharsets.UTF_8);%0A        buffer.skipBytes(len);%0A
 %0A   
@@ -1463,32 +1463,32 @@
 ect.length());%0A%0A
-
         byte%5B%5D b
@@ -1506,16 +1506,24 @@
 etBytes(
+Standard
 Charsets

Remove indirection in StringType decoding