Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
bde3704890
Commit
d3607d8265
@ -20,8 +20,6 @@
|
|||||||
package de.steamwar.bausystem.utils;
|
package de.steamwar.bausystem.utils;
|
||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -36,23 +34,7 @@ public class ProtocolAPI {
|
|||||||
private static final Map<Class<?>, BiFunction<Player, Object, Object>> outgoingHandler = new HashMap<>();
|
private static final Map<Class<?>, BiFunction<Player, Object, Object>> outgoingHandler = new HashMap<>();
|
||||||
private static final Map<Class<?>, BiFunction<Player, Object, Object>> incomingHandler = new HashMap<>();
|
private static final Map<Class<?>, BiFunction<Player, Object, Object>> incomingHandler = new HashMap<>();
|
||||||
|
|
||||||
public static final TinyProtocol tinyProtocol = new TinyProtocol(BauSystem.getInstance()) {
|
public static final TinyProtocol tinyProtocol = TinyProtocol.instance;
|
||||||
@Override
|
|
||||||
public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) {
|
|
||||||
BiFunction<Player, Object, Object> handler = outgoingHandler.get(packet.getClass());
|
|
||||||
if (handler == null)
|
|
||||||
return packet;
|
|
||||||
return handler.apply(receiver, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object onPacketInAsync(Player sender, Channel channel, Object packet) {
|
|
||||||
BiFunction<Player, Object, Object> handler = incomingHandler.get(packet.getClass());
|
|
||||||
if (handler == null)
|
|
||||||
return packet;
|
|
||||||
return handler.apply(sender, packet);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static void setOutgoingHandler(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
public static void setOutgoingHandler(Class<?> packetClass, BiFunction<Player, Object, Object> handler) {
|
||||||
outgoingHandler.put(packetClass, handler);
|
outgoingHandler.put(packetClass, handler);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren