-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a60dd4
commit 60e0a18
Showing
19 changed files
with
258 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
api/src/main/java/net/hypejet/jet/protocol/packet/clientbound/login/DisconnectPacket.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...n/java/net/hypejet/jet/protocol/packet/clientbound/login/disconnect/DisconnectPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.hypejet.jet.protocol.packet.clientbound.login.disconnect; | ||
|
||
import net.hypejet.jet.protocol.packet.clientbound.ClientBoundPacket; | ||
import net.kyori.adventure.text.Component; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
/** | ||
* Represents a {@link ClientBoundPacket client-bound packet} sent by a server to disconnect a player. | ||
* | ||
* @since 1.0 | ||
* @author Codestech | ||
*/ | ||
public sealed interface DisconnectPacket extends ClientBoundPacket permits DisconnectPacketImpl { | ||
/** | ||
* Gets a reason of the disconnection. | ||
* | ||
* @return the reason | ||
* @since 1.0 | ||
*/ | ||
@NonNull Component reason(); | ||
|
||
/** | ||
* Creates a new {@link Builder disconnect packet builder}. | ||
* | ||
* @return the builder | ||
* @since 1.0 | ||
*/ | ||
static @NonNull Builder builder() { | ||
return new DisconnectPacketImpl.Builder(); | ||
} | ||
|
||
/** | ||
* Represents a builder that creates a {@link DisconnectPacket disconnect packet}. | ||
* | ||
* @since 1.0 | ||
* @author Codestech | ||
*/ | ||
interface Builder { | ||
/** | ||
* Sets a reason of the disconnection. | ||
* | ||
* @param reason the reason | ||
* @return the builder | ||
* @since 1.0 | ||
*/ | ||
@NonNull Builder reason(@NonNull Component reason); | ||
|
||
/** | ||
* Builds the {@link DisconnectPacket disconnect packet}. | ||
* | ||
* @return the disconnect packet | ||
* @since 1.0 | ||
*/ | ||
@NonNull DisconnectPacket build(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...va/net/hypejet/jet/protocol/packet/clientbound/login/disconnect/DisconnectPacketImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.hypejet.jet.protocol.packet.clientbound.login.disconnect; | ||
|
||
import net.hypejet.jet.buffer.NetworkBuffer; | ||
import net.hypejet.jet.protocol.ProtocolState; | ||
import net.kyori.adventure.text.Component; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
/** | ||
* Represents an implementation of {@link DisconnectPacket disconnect packet}. | ||
* | ||
* @param reason a reason of the disconnection | ||
* @since 1.0 | ||
* @author Codestech | ||
* @see DisconnectPacket | ||
*/ | ||
record DisconnectPacketImpl(@NonNull Component reason) implements DisconnectPacket { | ||
|
||
@Override | ||
public void write(@NonNull NetworkBuffer buffer) { | ||
buffer.writeJsonTextComponent(this.reason); | ||
} | ||
|
||
@Override | ||
public int getPacketId() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public @NonNull ProtocolState getProtocolState() { | ||
return ProtocolState.LOGIN; | ||
} | ||
|
||
/** | ||
* Represents an implementation of {@link DisconnectPacket.Builder disconnect packet builder}. | ||
* | ||
* @since 1.0 | ||
* @author Codestech | ||
* @see DisconnectPacket.Builder | ||
*/ | ||
static final class Builder implements DisconnectPacket.Builder { | ||
|
||
private Component reason = Component.empty(); | ||
|
||
@Override | ||
public DisconnectPacket.@NonNull Builder reason(@NonNull Component reason) { | ||
this.reason = reason; | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NonNull DisconnectPacket build() { | ||
return new DisconnectPacketImpl(this.reason); | ||
} | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
api/src/main/java/net/hypejet/jet/protocol/packet/serverbound/ServerBoundPacketRegistry.java
This file was deleted.
Oops, something went wrong.
41 changes: 35 additions & 6 deletions
41
api/src/main/java/net/hypejet/jet/protocol/packet/serverbound/handshake/HandshakePacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,47 @@ | ||
package net.hypejet.jet.protocol.packet.serverbound.handshake; | ||
|
||
import net.hypejet.jet.player.PlayerConnection; | ||
import net.hypejet.jet.protocol.ProtocolState; | ||
import net.hypejet.jet.protocol.packet.serverbound.ServerBoundPacket; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
|
||
/** | ||
* Represents a {@link ServerBoundPacket server-bound packet} that initializes connection of a player. | ||
* | ||
* @param protocolVersion a version of the Minecraft protocol | ||
* @param serverAddress an address of the server | ||
* @param serverPort a port of the server | ||
* @param nextState a next protocol state, which the connection will switch to | ||
* @since 1.0 | ||
* @author Codestech | ||
*/ | ||
public record HandshakePacket(int protocolVersion, @NonNull String serverAddress, | ||
int serverPort, @NonNull ProtocolState nextState) implements ServerBoundPacket {} | ||
public interface HandshakePacket extends ServerBoundPacket { | ||
/** | ||
* Gets a version of the Minecraft protocol. | ||
* | ||
* @return the version | ||
* @since 1.0 | ||
*/ | ||
int protocolVersion(); | ||
|
||
/** | ||
* Gets an address of a server that the client tries to connect to. | ||
* | ||
* @return the address | ||
* @since 1.0 | ||
*/ | ||
@NonNull String serverAddress(); | ||
|
||
/** | ||
* Gets a port of a server that the client tries to connect to. | ||
* | ||
* @return the port | ||
* @since 1.0 | ||
*/ | ||
int serverPort(); | ||
|
||
/** | ||
* Gets a next {@link ProtocolState protocol state}, which a {@link PlayerConnection player connection} will switch | ||
* to. | ||
* | ||
* @return the protocol state | ||
* @since 1.0 | ||
*/ | ||
@NonNull ProtocolState nextState(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.