-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add some basic api interfaces
- Loading branch information
Showing
13 changed files
with
141 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.protocollib.api; | ||
|
||
public interface BinaryPacket { | ||
|
||
int id(); | ||
|
||
byte[] payload(); | ||
} |
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,30 @@ | ||
package dev.protocollib.api; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
public interface Connection { | ||
|
||
@Nullable | ||
Player player(); | ||
|
||
InetSocketAddress address(); | ||
|
||
int protocolVersion(); | ||
|
||
ProtocolPhase protocolPhase(PacketDirection packetDirection); | ||
|
||
boolean isConnected(); | ||
|
||
void sendPacket(BinaryPacket packet); | ||
|
||
void sendPacket(PacketContainer packet); | ||
|
||
void receivePacket(PacketContainer packet); | ||
|
||
void disconnect(String reason); | ||
|
||
} |
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,9 @@ | ||
package dev.protocollib.api; | ||
|
||
public interface PacketContainer { | ||
|
||
PacketType packetType(); | ||
|
||
Object packet(); | ||
|
||
} |
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,7 @@ | ||
package dev.protocollib.api; | ||
|
||
public enum PacketDirection { | ||
|
||
SERVERBOUND, CLIENTBOUND; | ||
|
||
} |
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,11 @@ | ||
package dev.protocollib.api; | ||
|
||
import org.bukkit.event.Cancellable; | ||
|
||
public interface PacketEvent extends Cancellable { | ||
|
||
Connection connection(); | ||
|
||
PacketContainer packet(); | ||
|
||
} |
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,8 @@ | ||
package dev.protocollib.api; | ||
|
||
@FunctionalInterface | ||
public interface PacketListener { | ||
|
||
void handlePacket(PacketEvent event); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/dev/protocollib/api/PacketListenerBuilder.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,16 @@ | ||
package dev.protocollib.api; | ||
|
||
import java.util.Collection; | ||
|
||
public interface PacketListenerBuilder { | ||
|
||
PacketListenerBuilder types(PacketType...packetTypes); | ||
|
||
PacketListenerBuilder types(Collection<PacketType> packetTypes); | ||
|
||
PacketListenerBuilder priority(PacketListenerPriority priority); | ||
|
||
PacketListenerBuilder listener(PacketListener listener); | ||
|
||
PacketListenerRegistration register(); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/dev/protocollib/api/PacketListenerPriority.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,7 @@ | ||
package dev.protocollib.api; | ||
|
||
public enum PacketListenerPriority { | ||
|
||
LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR; | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/dev/protocollib/api/PacketListenerRegistration.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,6 @@ | ||
package dev.protocollib.api; | ||
|
||
public interface PacketListenerRegistration { | ||
|
||
void unregister(); | ||
} |
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,13 @@ | ||
package dev.protocollib.api; | ||
|
||
public interface PacketType { | ||
|
||
PacketDirection packetDirection(); | ||
|
||
Class<?> packetClass(); | ||
|
||
boolean isSupported(); | ||
|
||
boolean isDeprecated(); | ||
|
||
} |
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,7 @@ | ||
package dev.protocollib.api; | ||
|
||
public class PacketTypes { | ||
|
||
// TODO should contain all packet types as public static final fields | ||
|
||
} |
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,12 @@ | ||
package dev.protocollib.api; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
public interface ProtocolLib { | ||
|
||
PacketListenerBuilder createListener(Plugin plugin); | ||
|
||
Connection connection(Player player); | ||
|
||
} |
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,7 @@ | ||
package dev.protocollib.api; | ||
|
||
public enum ProtocolPhase { | ||
|
||
HANDSHAKE, PLAY, STATUS, LOGIN, CONFIGURATION, UNKNOWN; | ||
|
||
} |