diff --git a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java index f70c147..e45bae4 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java +++ b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java @@ -24,6 +24,7 @@ import com.google.common.io.ByteStreams; import de.steamwar.comms.handlers.BungeeHandler; import de.steamwar.comms.handlers.InventoryHandler; import de.steamwar.comms.packets.MaterialsReturnPacket; +import de.steamwar.comms.packets.PluginCallbackPacket; import de.steamwar.core.Core; import de.steamwar.sql.*; import org.bukkit.Bukkit; @@ -33,24 +34,18 @@ import org.bukkit.SoundCategory; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import java.util.logging.Level; import java.util.stream.Collectors; public class BungeeReceiver implements PluginMessageListener { private static Map handlerMap = new HashMap<>(); - private static Map backupMap = new HashMap<>(); public static void registerHandler(Byte code, BungeeHandler handler) { handlerMap.put(code, handler); } - public static void registerBackup(Byte code, BungeeHandler handler) { - backupMap.put(code, handler); - } static { registerHandler(PacketIdManager.PING_PACKET, byteArrayDataInput -> { @@ -69,54 +64,12 @@ public class BungeeReceiver implements PluginMessageListener { registerHandler(PacketIdManager.MATERIALS_GET_PACKET, byteArrayDataInput -> { UUID id = UUID.fromString(byteArrayDataInput.readUTF()); MaterialsReturnPacket packet = new MaterialsReturnPacket(id, Material.values()); - packet.send(Bukkit.getOnlinePlayers().stream().limit(1).collect(Collectors.toList()).get(1)); + packet.send(Bukkit.getOnlinePlayers().stream().limit(1).collect(Collectors.toList()).get(0)); }); - registerHandler(PacketIdManager.LOAD_SCHEMATIC, byteArrayDataInput -> { - Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); - Schematic schematic = Schematic.getSchemFromDB(byteArrayDataInput.readInt()); - if(SchematicMember.getAccessibleSchems(player.getUniqueId()).contains(schematic)) { - try { - schematic.loadToPlayer(player); - player.sendMessage("§eSchematic§8» §7" + "Schematic §e" + schematic.getSchemName() + " §7geladen"); - }catch (IOException | NoClipboardException e){ - Bukkit.getLogger().log(Level.SEVERE, "Schematic konnte nicht geladen werden", e); - player.sendMessage("§eSchematic§8» §7" + "§cFehler beim Laden der Schematic. Bitte wende dich an einen Developer"); - } - } - }); - registerHandler(PacketIdManager.SAVE_SCHEMATIC, byteArrayDataInput -> { - Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); - String name = byteArrayDataInput.readUTF(); - Schematic schematic = Schematic.getSchemFromDB(name, player.getUniqueId()); - boolean newSchem = false; - if(schematic == null || schematic.getSchemOwner() != SteamwarUser.get(player.getUniqueId()).getId()){ - newSchem = true; - Schematic.createSchem(name, player.getUniqueId(), "", SchematicType.Normal); - schematic = Schematic.getSchemFromDB(name, player.getUniqueId()); - } - try { - schematic.saveFromPlayer(player); - }catch(IOException ex){ - Bukkit.getLogger().log(Level.SEVERE, "Could not save schematic", ex); - player.sendMessage(Core.SCHEMATIC_PREFIX + "§cFehler beim Speichern der Schematic. Bitte wende dich an einen Developer"); - if(newSchem) - schematic.remove(); - return; - }catch (NoClipboardException e) { - player.sendMessage(Core.SCHEMATIC_PREFIX + "§cDein Clipboard ist leer"); - if(newSchem) - schematic.remove(); - return; - } - if (newSchem) - player.sendMessage(Core.SCHEMATIC_PREFIX + "Schematic §e" + name + " §7gespeichert"); - else - player.sendMessage(Core.SCHEMATIC_PREFIX + "Schematic §e" + name + " §7überschrieben"); - }); - registerBackup((byte) 0x25, byteArrayDataInput -> { - byteArrayDataInput.readInt(); - Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); - player.sendMessage(Core.SCHEMATIC_PREFIX + "§cDieser Server kann keine Schematics prüfen"); + registerHandler(PacketIdManager.CHECK_PLUGIN, byteArrayDataInput -> { + String id = byteArrayDataInput.readUTF(); + String plugin = byteArrayDataInput.readUTF(); + new PluginCallbackPacket(id, Bukkit.getPluginManager().getPlugin(plugin) != null).send(Bukkit.getOnlinePlayers().stream().limit(1).collect(Collectors.toList()).get(0)); }); } @@ -126,8 +79,8 @@ public class BungeeReceiver implements PluginMessageListener { Byte handler = in.readByte(); if(handlerMap.containsKey(handler)) handlerMap.get(handler).handle(in); - else if(backupMap.containsKey(handler)) - backupMap.get(handler).handle(in); + else + throw new SecurityException("Could not find Handler"); } } diff --git a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java index 6ec81d3..5d9bd2e 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java +++ b/SpigotCore_Main/src/de/steamwar/comms/PacketIdManager.java @@ -23,6 +23,8 @@ public class PacketIdManager { //0x0(X) Standalone Packets public final static byte PING_PACKET = 0x01; + public static final byte CHECK_PLUGIN = 0x02; + public static final byte CHECK_PLUGIN_CALLBACK = 0x03; //0x1(X) Bungee Inventory public final static byte INVENTORY_PACKET = 0x10; public final static byte INVENTORY_CALLBACK_PACKET = 0x11; @@ -30,6 +32,4 @@ public class PacketIdManager { //0x2(X) Schematic System public final static byte MATERIALS_GET_PACKET = 0x21; public final static byte MATERIALS_RETURN_PACKET = 0x22; - public static final byte LOAD_SCHEMATIC = 0x23; - public static final byte SAVE_SCHEMATIC = 0x24; } diff --git a/SpigotCore_Main/src/de/steamwar/comms/packets/PluginCallbackPacket.java b/SpigotCore_Main/src/de/steamwar/comms/packets/PluginCallbackPacket.java new file mode 100644 index 0000000..b4feec8 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/comms/packets/PluginCallbackPacket.java @@ -0,0 +1,45 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + */ + +package de.steamwar.comms.packets; + +import com.google.common.io.ByteArrayDataOutput; +import de.steamwar.comms.PacketIdManager; + +public class PluginCallbackPacket extends SpigotPacket { + + private final String id; + private final boolean hasPlugin; + + public PluginCallbackPacket(String id, boolean hasPlugin) { + this.id = id; + this.hasPlugin = hasPlugin; + } + + @Override + public int getName() { + return PacketIdManager.CHECK_PLUGIN_CALLBACK; + } + + @Override + public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { + byteArrayDataOutput.writeUTF(id); + byteArrayDataOutput.writeBoolean(hasPlugin); + } +}