Skip to content

Commit

Permalink
Optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Apr 28, 2024
1 parent 400f1b4 commit beb00d6
Show file tree
Hide file tree
Showing 213 changed files with 710 additions and 605 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.geysermc.mcprotocollib.network.example;

import io.netty.buffer.ByteBuf;
import org.geysermc.mcprotocollib.network.codec.PacketCodecHelper;
import org.geysermc.mcprotocollib.network.packet.Packet;
import io.netty.buffer.ByteBuf;

public class PingPacket implements Packet {
private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) {
KeyGenerator gen = KeyGenerator.getInstance("AES");
gen.init(128);
key = gen.generateKey();
} catch(NoSuchAlgorithmException e) {
} catch (NoSuchAlgorithmException e) {
System.err.println("AES algorithm not supported, exiting...");
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.geysermc.mcprotocollib.network.example;

import io.netty.buffer.ByteBuf;
import org.geysermc.mcprotocollib.network.Server;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.codec.BasePacketCodecHelper;
Expand All @@ -11,7 +12,6 @@
import org.geysermc.mcprotocollib.network.packet.DefaultPacketHeader;
import org.geysermc.mcprotocollib.network.packet.PacketHeader;
import org.geysermc.mcprotocollib.network.packet.PacketProtocol;
import io.netty.buffer.ByteBuf;

import javax.crypto.SecretKey;
import java.security.GeneralSecurityException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@
import com.github.steveice10.mc.auth.service.AuthenticationService;
import com.github.steveice10.mc.auth.service.MojangAuthenticationService;
import com.github.steveice10.mc.auth.service.SessionService;
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
import org.geysermc.mcprotocollib.protocol.ServerLoginHandler;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
import org.geysermc.mcprotocollib.protocol.data.ProtocolState;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerSpawnInfo;
import org.geysermc.mcprotocollib.protocol.data.status.PlayerInfo;
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
import org.geysermc.mcprotocollib.protocol.data.status.VersionInfo;
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerInfoBuilder;
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerInfoHandler;
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerPingTimeHandler;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.geysermc.mcprotocollib.network.ProxyInfo;
import org.geysermc.mcprotocollib.network.Server;
import org.geysermc.mcprotocollib.network.Session;
Expand All @@ -33,9 +20,18 @@
import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.network.tcp.TcpClientSession;
import org.geysermc.mcprotocollib.network.tcp.TcpServer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
import org.geysermc.mcprotocollib.protocol.data.ProtocolState;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerSpawnInfo;
import org.geysermc.mcprotocollib.protocol.data.status.PlayerInfo;
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
import org.geysermc.mcprotocollib.protocol.data.status.VersionInfo;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;

import java.net.Proxy;
import java.nio.charset.StandardCharsets;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package org.geysermc.mcprotocollib.network;

import org.geysermc.mcprotocollib.network.event.server.*;
import org.geysermc.mcprotocollib.network.event.server.ServerBoundEvent;
import org.geysermc.mcprotocollib.network.event.server.ServerClosedEvent;
import org.geysermc.mcprotocollib.network.event.server.ServerClosingEvent;
import org.geysermc.mcprotocollib.network.event.server.ServerEvent;
import org.geysermc.mcprotocollib.network.event.server.ServerListener;
import org.geysermc.mcprotocollib.network.event.server.SessionAddedEvent;
import org.geysermc.mcprotocollib.network.event.server.SessionRemovedEvent;
import org.geysermc.mcprotocollib.network.packet.PacketProtocol;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

public abstract class AbstractServer implements Server {
Expand Down Expand Up @@ -59,13 +69,13 @@ public <T> T getGlobalFlag(Flag<T> flag) {
@Override
public <T> T getGlobalFlag(Flag<T> flag, T def) {
Object value = this.flags.get(flag.key());
if(value == null) {
if (value == null) {
return def;
}

try {
return flag.cast(value);
} catch(ClassCastException e) {
} catch (ClassCastException e) {
throw new IllegalStateException("Tried to get flag \"" + flag.key() + "\" as the wrong type. Actual type: " + value.getClass().getName());
}
}
Expand All @@ -91,7 +101,7 @@ public void removeListener(ServerListener listener) {
}

protected void callEvent(ServerEvent event) {
for(ServerListener listener : this.listeners) {
for (ServerListener listener : this.listeners) {
event.call(listener);
}
}
Expand All @@ -108,7 +118,7 @@ public void addSession(Session session) {

public void removeSession(Session session) {
this.sessions.remove(session);
if(session.isConnected()) {
if (session.isConnected()) {
session.disconnect("Connection closed.");
}

Expand All @@ -129,7 +139,7 @@ public AbstractServer bind(boolean wait) {
public AbstractServer bind(boolean wait, Runnable callback) {
this.bindImpl(wait, () -> {
callEvent(new ServerBoundEvent(AbstractServer.this));
if(callback != null) {
if (callback != null) {
callback.run();
}
});
Expand All @@ -152,15 +162,15 @@ public void close(boolean wait) {
@Override
public void close(boolean wait, Runnable callback) {
this.callEvent(new ServerClosingEvent(this));
for(Session session : this.getSessions()) {
if(session.isConnected()) {
for (Session session : this.getSessions()) {
if (session.isConnected()) {
session.disconnect("Server closed.");
}
}

this.closeImpl(wait, () -> {
callEvent(new ServerClosedEvent(AbstractServer.this));
if(callback != null) {
if (callback != null) {
callback.run();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ProxyInfo {
/**
* Creates a new unauthenticated ProxyInfo instance.
*
* @param type Type of proxy.
* @param type Type of proxy.
* @param address Network address of the proxy.
*/
public ProxyInfo(Type type, SocketAddress address) {
Expand All @@ -27,7 +27,7 @@ public ProxyInfo(Type type, SocketAddress address) {
/**
* Creates a new authenticated ProxyInfo instance.
*
* @param type Type of proxy.
* @param type Type of proxy.
* @param address Network address of the proxy.
* @param username Username to authenticate with.
* @param password Password to authenticate with.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public interface Server {
/**
* Binds the listener to its host and port.
*
* @param wait Whether to wait for the listener to finish binding.
* @param wait Whether to wait for the listener to finish binding.
* @param callback Callback to call when the listener has finished binding.
* @return The server.
*/
Expand All @@ -153,7 +153,7 @@ public interface Server {
/**
* Closes the listener.
*
* @param wait Whether to wait for the listener to finish closing.
* @param wait Whether to wait for the listener to finish closing.
* @param callback Callback to call when the listener has finished closing.
*/
void close(boolean wait, Runnable callback);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.geysermc.mcprotocollib.network;

import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.mcprotocollib.network.codec.PacketCodecHelper;
import org.geysermc.mcprotocollib.network.crypt.PacketEncryption;
import org.geysermc.mcprotocollib.network.event.session.SessionEvent;
import org.geysermc.mcprotocollib.network.event.session.SessionListener;
import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.network.packet.PacketProtocol;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.net.SocketAddress;
import java.util.List;
Expand Down Expand Up @@ -270,7 +270,7 @@ public interface Session {
* Disconnects the session.
*
* @param reason Reason for disconnecting.
* @param cause Throwable responsible for disconnecting.
* @param cause Throwable responsible for disconnecting.
*/
void disconnect(@Nullable String reason, Throwable cause);

Expand All @@ -285,7 +285,7 @@ public interface Session {
* Disconnects the session.
*
* @param reason Reason for disconnecting.
* @param cause Throwable responsible for disconnecting.
* @param cause Throwable responsible for disconnecting.
*/
void disconnect(@Nullable Component reason, Throwable cause);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.geysermc.mcprotocollib.network.codec;

import org.geysermc.mcprotocollib.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import org.geysermc.mcprotocollib.network.packet.Packet;

/**
* Represents a definition of a packet with various
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.geysermc.mcprotocollib.network.codec;

import org.geysermc.mcprotocollib.network.packet.Packet;
import io.netty.buffer.ByteBuf;
import org.geysermc.mcprotocollib.network.packet.Packet;

public interface PacketSerializer<T extends Packet, H extends PacketCodecHelper> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public interface PacketEncryption {
/**
* Decrypts the given data.
*
* @param input Input data to decrypt.
* @param inputOffset Offset of the data to start decrypting at.
* @param inputLength Length of the data to be decrypted.
* @param output Array to output decrypted data to.
* @param input Input data to decrypt.
* @param inputOffset Offset of the data to start decrypting at.
* @param inputLength Length of the data to be decrypted.
* @param output Array to output decrypted data to.
* @param outputOffset Offset of the output array to start at.
* @return The number of bytes stored in the output array.
* @throws Exception If an error occurs.
Expand All @@ -36,10 +36,10 @@ public interface PacketEncryption {
/**
* Encrypts the given data.
*
* @param input Input data to encrypt.
* @param inputOffset Offset of the data to start encrypting at.
* @param inputLength Length of the data to be encrypted.
* @param output Array to output encrypted data to.
* @param input Input data to encrypt.
* @param inputOffset Offset of the data to start encrypting at.
* @param inputLength Length of the data to be encrypted.
* @param output Array to output encrypted data to.
* @param outputOffset Offset of the output array to start at.
* @return The number of bytes stored in the output array.
* @throws Exception If an error occurs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SessionAddedEvent implements ServerEvent {
/**
* Creates a new SessionAddedEvent instance.
*
* @param server Server the session is being added to.
* @param server Server the session is being added to.
* @param session Session being added.
*/
public SessionAddedEvent(Server server, Session session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SessionRemovedEvent implements ServerEvent {
/**
* Creates a new SessionRemovedEvent instance.
*
* @param server Server the session is being removed from.
* @param server Server the session is being removed from.
* @param session Session being removed.
*/
public SessionRemovedEvent(Server server, Session session) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.geysermc.mcprotocollib.network.event.session;

import org.geysermc.mcprotocollib.network.Session;
import net.kyori.adventure.text.Component;
import org.geysermc.mcprotocollib.network.Session;

/**
* Called when the session is disconnected.
Expand All @@ -15,8 +15,8 @@ public class DisconnectedEvent implements SessionEvent {
* Creates a new DisconnectedEvent instance.
*
* @param session Session being disconnected.
* @param reason Reason for the session to disconnect.
* @param cause Throwable that caused the disconnect.
* @param reason Reason for the session to disconnect.
* @param cause Throwable that caused the disconnect.
*/
public DisconnectedEvent(Session session, Component reason, Throwable cause) {
this.session = session;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.geysermc.mcprotocollib.network.event.session;

import org.geysermc.mcprotocollib.network.Session;
import net.kyori.adventure.text.Component;
import org.geysermc.mcprotocollib.network.Session;

/**
* Called when the session is about to disconnect.
Expand All @@ -15,8 +15,8 @@ public class DisconnectingEvent implements SessionEvent {
* Creates a new DisconnectingEvent instance.
*
* @param session Session being disconnected.
* @param reason Reason for the session to disconnect.
* @param cause Throwable that caused the disconnect.
* @param reason Reason for the session to disconnect.
* @param cause Throwable that caused the disconnect.
*/
public DisconnectingEvent(Session session, Component reason, Throwable cause) {
this.session = session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PacketErrorEvent implements SessionEvent {
* Creates a new SessionErrorEvent instance.
*
* @param session Session that the error came from.
* @param cause Cause of the error.
* @param cause Cause of the error.
*/
public PacketErrorEvent(Session session, Throwable cause) {
this.session = session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PacketSendingEvent implements SessionEvent {
* Creates a new PacketSendingEvent instance.
*
* @param session Session sending the packet.
* @param packet Packet being sent.
* @param packet Packet being sent.
*/
public PacketSendingEvent(Session session, Packet packet) {
this.session = session;
Expand All @@ -42,7 +42,7 @@ public Session getSession() {
public <T extends Packet> T getPacket() {
try {
return (T) this.packet;
} catch(ClassCastException e) {
} catch (ClassCastException e) {
throw new IllegalStateException("Tried to get packet as the wrong type. Actual type: " + this.packet.getClass().getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.geysermc.mcprotocollib.network.event.session;

import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.packet.Packet;

/**
* An adapter for picking session events to listen for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public enum TransportMethod {
}

public static TransportMethod determineTransportMethod() {
if (isClassAvailable("io.netty.incubator.channel.uring.IOUring") && IOUring.isAvailable()) return TransportMethod.IO_URING;
if (isClassAvailable("io.netty.incubator.channel.uring.IOUring") && IOUring.isAvailable())
return TransportMethod.IO_URING;
if (isClassAvailable("io.netty.channel.epoll.Epoll") && Epoll.isAvailable()) return TransportMethod.EPOLL;
if (isClassAvailable("io.netty.channel.kqueue.KQueue") && KQueue.isAvailable()) return TransportMethod.KQUEUE;
return TransportMethod.NIO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.geysermc.mcprotocollib.network.packet;

import io.netty.buffer.ByteBuf;
import org.geysermc.mcprotocollib.network.codec.PacketCodecHelper;
import org.geysermc.mcprotocollib.network.codec.PacketDefinition;
import org.geysermc.mcprotocollib.network.codec.PacketSerializer;
import io.netty.buffer.ByteBuf;

public class BufferedPacket implements Packet, PacketSerializer<BufferedPacket, PacketCodecHelper> {
private final Class<? extends Packet> packetClass;
Expand Down
Loading

0 comments on commit beb00d6

Please sign in to comment.