diff --git a/bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolLibPacketAdapter.java b/bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolLibPacketAdapter.java index 4446d6b..796e623 100644 --- a/bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolLibPacketAdapter.java +++ b/bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolLibPacketAdapter.java @@ -62,6 +62,7 @@ import com.github.juliarn.npclib.common.event.DefaultInteractNpcEvent; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import io.leangen.geantyref.GenericTypeReflector; import io.leangen.geantyref.TypeFactory; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -230,10 +231,20 @@ final class ProtocolLibPacketAdapter implements PlatformPacketAdapter rawSerializerType = GenericTypeReflector.erase(serializerType); + + WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(rawSerializerType, true); + return new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, serializer), value); + } + } + + Class raw = GenericTypeReflector.erase(type); + WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(raw, false); return new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, serializer), value); } else { // mc 1.8: watchable object id diff --git a/bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolUtil.java b/bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolUtil.java deleted file mode 100644 index d3fe95b..0000000 --- a/bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolUtil.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of npc-lib, licensed under the MIT License (MIT). - * - * Copyright (c) 2022-2023 Julian M., Pasqual K. and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.github.juliarn.npclib.bukkit.protocol; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import org.jetbrains.annotations.NotNull; - -final class ProtocolUtil { - - private ProtocolUtil() { - throw new UnsupportedOperationException(); - } - - public static @NotNull Class extractRawType(@NotNull Type type) { - // get the type information of the value to write - if (type instanceof Class) { - // direct access via the given class type - return (Class) type; - } else if (type instanceof ParameterizedType) { - // optional type (access via first type parameter) - ParameterizedType parameterizedType = (ParameterizedType) type; - return (Class) parameterizedType.getActualTypeArguments()[0]; - } else { - // unable to handle that - throw new IllegalArgumentException("Unsupported type: " + type); - } - } -}