diff --git a/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitNetwork.java b/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitNetwork.java index 5066014b7..c4ef09b05 100644 --- a/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitNetwork.java +++ b/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitNetwork.java @@ -91,24 +91,6 @@ public void register() { )); } ); - - - - Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, Network.CHANNEL); - Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, Network.CHANNEL, - (channel, player, bytes) -> { - ByteArrayDataInput in = in(bytes); - int protocol = in.readInt(); - if (protocol != Constants.PROTOCOL) { - return; - } - int action = in.readInt(); - switch (action) { - case Constants.SERVER_DATA -> sendServerData(player); - case Constants.MAP_DATA -> sendMapData(player, in.readInt()); - } - } - ); } @NotNull @@ -117,8 +99,10 @@ private static void sendCustomPayloadPacket(ServerPlayer player, CustomPacketPay } public void unregister() { - Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, Network.CHANNEL); - Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, Network.CHANNEL); + Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, ClientboundServerPayload.TYPE.id().toString()); + Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, ClientboundMapPayload.TYPE.id().toString()); + Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, ServerboundServerPayload.TYPE.id().toString()); + Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, ServerboundMapPayload.TYPE.id().toString()); } @Override @@ -126,47 +110,14 @@ protected void sendServerData(T player) { } + @Override protected void sendMapData(T player, int id) { - ByteArrayDataOutput out = out(); - - out.writeInt(Constants.PROTOCOL); - out.writeInt(Constants.MAP_DATA); - out.writeInt(Constants.RESPONSE_SUCCESS); - - MapView map = Bukkit.getMap(id); - if (map == null) { - out.writeInt(Constants.ERROR_NO_SUCH_MAP); - out.writeInt(id); - return; - } - - World world = map.getWorld(); - if (world == null) { - out.writeInt(Constants.ERROR_NO_SUCH_WORLD); - out.writeInt(id); - return; - } - - for (MapRenderer renderer : map.getRenderers()) { - if (!renderer.getClass().getName().equals(CraftMapRenderer.class.getName())) { - out.writeInt(Constants.ERROR_NOT_VANILLA_MAP); - out.writeInt(id); - return; - } - } - - out.writeInt(id); - out.writeByte(getScale(map)); - out.writeInt(map.getCenterX()); - out.writeInt(map.getCenterZ()); - out.writeUTF(world.getName()); - - send(player, out); + } @Override protected void send(T player, ByteArrayDataOutput out) { - ((Player) player).sendPluginMessage(this.plugin, Network.CHANNEL, out.toByteArray()); + } @SuppressWarnings("deprecation")