diff --git a/api/src/main/java/fr/atlasworld/network/api/networking/HandshakeInformation.java b/api/src/main/java/fr/atlasworld/network/api/networking/HandshakeInformation.java index 0b37257..21e5642 100644 --- a/api/src/main/java/fr/atlasworld/network/api/networking/HandshakeInformation.java +++ b/api/src/main/java/fr/atlasworld/network/api/networking/HandshakeInformation.java @@ -3,6 +3,7 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import org.jetbrains.annotations.NotNull; + /** * Represents information exchanged during the handshake. * @@ -19,28 +20,6 @@ public HandshakeInformation(@NotNull T value, @NotNull Function facto this.factory = factory; } - public @NotNull T getValue() { - return value; - } - - /** - * Returns a string representation of the current data. - * This will use the provided function to transform the object into string - * before sending it through the handshake packet. - * - * @return A string representation of the object. - */ - public String asString() { - return this.factory.apply(this.value); - } - - @Override - public String toString() { - return "handshake_data[data:" + this.asString() + "]"; - } - - // Static Fields - /** * Returns a new instance of HandshakeInformation with the provided information. * @@ -71,6 +50,7 @@ public static HandshakeInformation asLong(long information) { return new HandshakeInformation<>(information, String::valueOf); } + // Static Fields /** * Returns a new instance of HandshakeInformation with the provided value. @@ -84,4 +64,24 @@ public static HandshakeInformation asLong(long information) { public static HandshakeInformation of(@NotNull T value) { return new HandshakeInformation<>(value, Object::toString); } + + public @NotNull T getValue() { + return value; + } + + /** + * Returns a string representation of the current data. + * This will use the provided function to transform the object into string + * before sending it through the handshake packet. + * + * @return A string representation of the object. + */ + public String asString() { + return this.factory.apply(this.value); + } + + @Override + public String toString() { + return "handshake_data[data:" + this.asString() + "]"; + } } diff --git a/api/src/main/java/fr/atlasworld/network/api/networking/event/HandshakeDataInjectionEvent.java b/api/src/main/java/fr/atlasworld/network/api/networking/event/HandshakeDataInjectionEvent.java index eeafd55..0a2a158 100644 --- a/api/src/main/java/fr/atlasworld/network/api/networking/event/HandshakeDataInjectionEvent.java +++ b/api/src/main/java/fr/atlasworld/network/api/networking/event/HandshakeDataInjectionEvent.java @@ -16,24 +16,24 @@ public interface HandshakeDataInjectionEvent extends Event { /** * Injects the provided information into the handshake using the specified key. * - * @param key The key associated with the information. - * @param information The information to be injected into the handshake. + * @param key The key associated with the information. + * @param information The information to be injected into the handshake. */ void inject(@NotNull String key, @NotNull HandshakeInformation information); /** * Injects the provided information into the handshake using the specified module. * - * @param module The module associated with the information. - * @param information The information to be injected into the handshake. + * @param module The module associated with the information. + * @param information The information to be injected into the handshake. */ void inject(@NotNull Module module, @NotNull HandshakeInformation information); /** * Injects the provided information into the handshake packet associated with the given resource key. * - * @param key The resource key that identifies the handshake packet. - * @param information The information to be injected into the handshake packet. + * @param key The resource key that identifies the handshake packet. + * @param information The information to be injected into the handshake packet. */ void inject(@NotNull ResourceKey key, @NotNull HandshakeInformation information); diff --git a/api/src/main/java/fr/atlasworld/network/api/registry/ResourceKey.java b/api/src/main/java/fr/atlasworld/network/api/registry/ResourceKey.java index e553310..ede51f5 100644 --- a/api/src/main/java/fr/atlasworld/network/api/registry/ResourceKey.java +++ b/api/src/main/java/fr/atlasworld/network/api/registry/ResourceKey.java @@ -27,6 +27,23 @@ public ResourceKey(@NotNull Module module, @NotNull String key) { this.key = key; } + public static ResourceKey fromText(@NotNull String text) { + Preconditions.checkArgument(text != null, "Text may not be null!"); + + if (!text.contains(":")) + throw new IllegalArgumentException("Text does not contain ':' separator!"); + + String[] split = text.split(":", 1); + + String namespace = split[0]; + String key = split[1]; + + if (!namespace.matches(REGEX) || !key.matches(REGEX)) + throw new IllegalArgumentException("Text does not match with '" + REGEX + "'!"); + + return new ResourceKey(namespace, key); + } + /** * Retrieves the namespace of the resource key. * The namespace represents a unique identifier. @@ -68,21 +85,4 @@ public boolean equals(Object obj) { public int hashCode() { return this.toString().hashCode(); } - - public static ResourceKey fromText(@NotNull String text) { - Preconditions.checkArgument(text != null, "Text may not be null!"); - - if (!text.contains(":")) - throw new IllegalArgumentException("Text does not contain ':' separator!"); - - String[] split = text.split(":", 1); - - String namespace = split[0]; - String key = split[1]; - - if (!namespace.matches(REGEX) || !key.matches(REGEX)) - throw new IllegalArgumentException("Text does not match with '" + REGEX + "'!"); - - return new ResourceKey(namespace, key); - } } diff --git a/api/src/test/java/fr/atlasworld/network/api/test/networking/packets/MyCustomPacket.java b/api/src/test/java/fr/atlasworld/network/api/test/networking/packets/MyCustomPacket.java index 97790d7..768f444 100644 --- a/api/src/test/java/fr/atlasworld/network/api/test/networking/packets/MyCustomPacket.java +++ b/api/src/test/java/fr/atlasworld/network/api/test/networking/packets/MyCustomPacket.java @@ -4,8 +4,6 @@ import fr.atlasworld.network.api.networking.exception.packet.PacketExecutionException; import fr.atlasworld.network.api.networking.packet.NetworkPacket; import fr.atlasworld.network.api.networking.packet.PacketByteBuf; -import fr.atlasworld.network.api.registry.ResourceKey; -import fr.atlasworld.network.api.test.TestModule; import org.jetbrains.annotations.NotNull; public class MyCustomPacket implements NetworkPacket { diff --git a/src/main/java/fr/atlasworld/network/core/diagnostics/environment/Environment.java b/src/main/java/fr/atlasworld/network/core/diagnostics/environment/Environment.java index 7f4464b..57dcfa6 100644 --- a/src/main/java/fr/atlasworld/network/core/diagnostics/environment/Environment.java +++ b/src/main/java/fr/atlasworld/network/core/diagnostics/environment/Environment.java @@ -18,7 +18,8 @@ public class Environment { SYSTEM_EXECUTOR = new NioEventLoopGroup(AVAILABLE_LOGIC_PROCESSORS * 4); } - public static void init() {} // Loads the class. + public static void init() { + } // Loads the class. public static long usedMemory() { return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); diff --git a/src/main/java/fr/atlasworld/network/core/logging/LogUtils.java b/src/main/java/fr/atlasworld/network/core/logging/LogUtils.java index b4bd913..1b77fa6 100644 --- a/src/main/java/fr/atlasworld/network/core/logging/LogUtils.java +++ b/src/main/java/fr/atlasworld/network/core/logging/LogUtils.java @@ -8,11 +8,10 @@ import org.slf4j.LoggerFactory; public class LogUtils { + public static final Logger CODE_LINTING_LOGGER = LoggerFactory.getLogger("Code-Linting"); private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); private static final Logger LOGGER = LogUtils.getLogger(); - public static final Logger CODE_LINTING_LOGGER = LoggerFactory.getLogger("Code-Linting"); - public static Logger getLogger() { return LoggerFactory.getLogger(STACK_WALKER.getCallerClass().getSimpleName()); } diff --git a/src/main/java/fr/atlasworld/network/core/networking/handler/DecodeHandler.java b/src/main/java/fr/atlasworld/network/core/networking/handler/DecodeHandler.java index d50f868..4c4f08b 100644 --- a/src/main/java/fr/atlasworld/network/core/networking/handler/DecodeHandler.java +++ b/src/main/java/fr/atlasworld/network/core/networking/handler/DecodeHandler.java @@ -1,7 +1,6 @@ package fr.atlasworld.network.core.networking.handler; import fr.atlasworld.network.api.concurrent.action.FutureAction; -import fr.atlasworld.network.api.networking.ConnectionSource; import fr.atlasworld.network.api.networking.ConnectionState; import fr.atlasworld.network.api.networking.exception.NetworkSynchronisationException; import fr.atlasworld.network.api.networking.exception.NetworkingException; @@ -14,10 +13,8 @@ import fr.atlasworld.network.api.security.exceptions.CryptographyException; import fr.atlasworld.network.api.server.AtlasNetworkServer; import fr.atlasworld.network.api.services.database.Database; -import fr.atlasworld.network.core.AtlasNetwork; import fr.atlasworld.network.core.networking.NetworkClient; import fr.atlasworld.network.core.networking.codec.NetworkCodec; -import fr.atlasworld.network.core.networking.codec.exception.DecodeException; import fr.atlasworld.network.core.networking.packet.PacketByteBufImpl; import fr.atlasworld.network.core.networking.packet.SystemInfoPacket; import fr.atlasworld.network.core.networking.security.authentication.AuthenticationProfile; @@ -29,7 +26,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.util.AttributeKey; import io.netty.util.ReferenceCountUtil; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/fr/atlasworld/network/core/networking/packet/RequestFailPacket.java b/src/main/java/fr/atlasworld/network/core/networking/packet/RequestFailPacket.java index 0649a56..dfdf1c9 100644 --- a/src/main/java/fr/atlasworld/network/core/networking/packet/RequestFailPacket.java +++ b/src/main/java/fr/atlasworld/network/core/networking/packet/RequestFailPacket.java @@ -4,7 +4,6 @@ import fr.atlasworld.network.api.networking.exception.NetworkingException; import fr.atlasworld.network.api.networking.packet.NetworkPacket; import fr.atlasworld.network.api.networking.packet.PacketByteBuf; -import fr.atlasworld.network.api.registry.ResourceKey; import fr.atlasworld.network.core.logging.LogUtils; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; diff --git a/src/main/java/fr/atlasworld/network/core/networking/packet/SystemInfoPacket.java b/src/main/java/fr/atlasworld/network/core/networking/packet/SystemInfoPacket.java index 406845f..e2eb139 100644 --- a/src/main/java/fr/atlasworld/network/core/networking/packet/SystemInfoPacket.java +++ b/src/main/java/fr/atlasworld/network/core/networking/packet/SystemInfoPacket.java @@ -4,7 +4,6 @@ import fr.atlasworld.network.api.networking.ConnectionSource; import fr.atlasworld.network.api.networking.packet.NetworkPacket; import fr.atlasworld.network.api.networking.packet.PacketByteBuf; -import fr.atlasworld.network.api.registry.ResourceKey; import fr.atlasworld.network.api.server.AtlasNetworkServer; import fr.atlasworld.network.api.util.NetworkVersion; import fr.atlasworld.network.core.AtlasNetwork; diff --git a/src/main/java/fr/atlasworld/network/core/networking/packet/WrappedPacket.java b/src/main/java/fr/atlasworld/network/core/networking/packet/WrappedPacket.java index aaa8db7..d10191e 100644 --- a/src/main/java/fr/atlasworld/network/core/networking/packet/WrappedPacket.java +++ b/src/main/java/fr/atlasworld/network/core/networking/packet/WrappedPacket.java @@ -28,6 +28,14 @@ public WrappedPacket(@NotNull ResourceKey packet, @Nullable PacketByteBuf buffer this.alloc = alloc; } + public static WrappedPacket of(@NotNull ResourceKey key, @NotNull NetworkPacket packet, @NotNull ByteBufAllocator alloc) { + return new WrappedPacket(key, null, packet, alloc); + } + + public static WrappedPacket of(@NotNull ResourceKey key, @NotNull PacketByteBuf packet, @NotNull ByteBufAllocator alloc) { + return new WrappedPacket(key, packet, null, alloc); + } + public @NotNull ResourceKey getPacket() { return packet; } @@ -56,12 +64,4 @@ public PacketByteBuf build() throws PacketExecutionException { return buf; } - - public static WrappedPacket of(@NotNull ResourceKey key, @NotNull NetworkPacket packet, @NotNull ByteBufAllocator alloc) { - return new WrappedPacket(key, null, packet, alloc); - } - - public static WrappedPacket of(@NotNull ResourceKey key, @NotNull PacketByteBuf packet, @NotNull ByteBufAllocator alloc) { - return new WrappedPacket(key, packet, null, alloc); - } } diff --git a/src/main/java/fr/atlasworld/network/core/registry/NetworkRegistries.java b/src/main/java/fr/atlasworld/network/core/registry/NetworkRegistries.java index e26f106..987934d 100644 --- a/src/main/java/fr/atlasworld/network/core/registry/NetworkRegistries.java +++ b/src/main/java/fr/atlasworld/network/core/registry/NetworkRegistries.java @@ -2,8 +2,6 @@ import fr.atlasworld.network.api.command.Command; import fr.atlasworld.network.api.command.CommandSource; -import fr.atlasworld.network.api.networking.HandshakeInformation; -import fr.atlasworld.network.api.networking.packet.NetworkPacket; import fr.atlasworld.network.api.registry.ResourceKey; import fr.atlasworld.network.api.registry.SimpleRegistry; import fr.atlasworld.network.core.registry.registries.PacketRegistry; diff --git a/src/main/java/fr/atlasworld/network/core/registry/registries/PacketRegistry.java b/src/main/java/fr/atlasworld/network/core/registry/registries/PacketRegistry.java index b6c5cc6..819d571 100644 --- a/src/main/java/fr/atlasworld/network/core/registry/registries/PacketRegistry.java +++ b/src/main/java/fr/atlasworld/network/core/registry/registries/PacketRegistry.java @@ -1,6 +1,5 @@ package fr.atlasworld.network.core.registry.registries; -import fr.atlasworld.network.api.networking.exception.packet.UnknownPacketException; import fr.atlasworld.network.api.networking.packet.NetworkPacket; import fr.atlasworld.network.api.registry.Registry; import fr.atlasworld.network.api.registry.ResourceKey;