Skip to content

Commit

Permalink
feat(api): add some basic api interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingrim4 committed Sep 22, 2024
1 parent fb08567 commit 8d2efb3
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/dev/protocollib/api/BinaryPacket.java
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();
}
30 changes: 30 additions & 0 deletions src/main/java/dev/protocollib/api/Connection.java
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);

}
9 changes: 9 additions & 0 deletions src/main/java/dev/protocollib/api/PacketContainer.java
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();

}
7 changes: 7 additions & 0 deletions src/main/java/dev/protocollib/api/PacketDirection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.protocollib.api;

public enum PacketDirection {

SERVERBOUND, CLIENTBOUND;

}
11 changes: 11 additions & 0 deletions src/main/java/dev/protocollib/api/PacketEvent.java
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();

}
8 changes: 8 additions & 0 deletions src/main/java/dev/protocollib/api/PacketListener.java
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 src/main/java/dev/protocollib/api/PacketListenerBuilder.java
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 src/main/java/dev/protocollib/api/PacketListenerPriority.java
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;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.protocollib.api;

public interface PacketListenerRegistration {

void unregister();
}
13 changes: 13 additions & 0 deletions src/main/java/dev/protocollib/api/PacketType.java
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();

}
7 changes: 7 additions & 0 deletions src/main/java/dev/protocollib/api/PacketTypes.java
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

}
12 changes: 12 additions & 0 deletions src/main/java/dev/protocollib/api/ProtocolLib.java
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);

}
7 changes: 7 additions & 0 deletions src/main/java/dev/protocollib/api/ProtocolPhase.java
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;

}

0 comments on commit 8d2efb3

Please sign in to comment.