-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Queue packets if all players are unencrypted
- Loading branch information
1 parent
c9b44b7
commit ada03c7
Showing
11 changed files
with
119 additions
and
13 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
25 changes: 25 additions & 0 deletions
25
api/src/main/java/net/azisaba/azipluginmessaging/api/protocol/PacketQueue.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,25 @@ | ||
package net.azisaba.azipluginmessaging.api.protocol; | ||
|
||
import net.azisaba.azipluginmessaging.api.protocol.message.Message; | ||
import net.azisaba.azipluginmessaging.api.server.PacketSender; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public abstract class PacketQueue { | ||
public static final PacketQueue EMPTY = new Empty(); | ||
|
||
public abstract void add(@NotNull Protocol<?, ?> protocol, @NotNull Message message); | ||
public abstract void flush(@NotNull PacketSender sender); | ||
|
||
private static class Empty extends PacketQueue { | ||
private Empty() { | ||
} | ||
|
||
@Override | ||
public void add(@NotNull Protocol<?, ?> protocol, @NotNull Message message) { | ||
} | ||
|
||
@Override | ||
public void flush(@NotNull PacketSender sender) { | ||
} | ||
} | ||
} |
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
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
30 changes: 30 additions & 0 deletions
30
spigot/src/main/java/net/azisaba/azipluginmessaging/spigot/protocol/SimplePacketQueue.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,30 @@ | ||
package net.azisaba.azipluginmessaging.spigot.protocol; | ||
|
||
import net.azisaba.azipluginmessaging.api.protocol.PacketQueue; | ||
import net.azisaba.azipluginmessaging.api.protocol.Protocol; | ||
import net.azisaba.azipluginmessaging.api.protocol.message.Message; | ||
import net.azisaba.azipluginmessaging.api.server.PacketSender; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class SimplePacketQueue extends PacketQueue { | ||
private final List<Map.Entry<Protocol<?, ?>, Message>> list = new ArrayList<>(); | ||
|
||
public void add(@NotNull Protocol<?, ?> protocol, @NotNull Message message) { | ||
Objects.requireNonNull(protocol, "protocol must not be null"); | ||
Objects.requireNonNull(message, "message must not be null"); | ||
list.add(new AbstractMap.SimpleImmutableEntry<>(protocol, message)); | ||
} | ||
|
||
@SuppressWarnings({ "unchecked", "rawtypes" }) | ||
public void flush(@NotNull PacketSender sender) { | ||
for (Map.Entry<Protocol<?, ? extends Message>, ? extends Message> entry : list) { | ||
((Protocol) entry.getKey()).sendPacket(sender, entry.getValue()); | ||
} | ||
} | ||
} |
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