diff --git a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java index e45bae4..3778223 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java +++ b/SpigotCore_Main/src/de/steamwar/comms/BungeeReceiver.java @@ -23,12 +23,9 @@ import com.google.common.io.ByteArrayDataInput; 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; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.SoundCategory; import org.bukkit.entity.Player; @@ -61,11 +58,6 @@ public class BungeeReceiver implements PluginMessageListener { Player player = Bukkit.getPlayer(SteamwarUser.get(byteArrayDataInput.readInt()).getUUID()); player.closeInventory(); }); - 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(0)); - }); registerHandler(PacketIdManager.CHECK_PLUGIN, byteArrayDataInput -> { String id = byteArrayDataInput.readUTF(); String plugin = byteArrayDataInput.readUTF(); diff --git a/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java b/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java index 433aa86..521755e 100644 --- a/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java +++ b/SpigotCore_Main/src/de/steamwar/comms/handlers/InventoryHandler.java @@ -28,6 +28,7 @@ import de.steamwar.inventory.SWItem; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import de.steamwar.comms.packets.*; +import org.bukkit.event.inventory.InventoryType; import java.util.*; @@ -45,12 +46,17 @@ public class InventoryHandler implements BungeeHandler { for (int i = 0; i < length; i++) { JsonObject itemJson = array.get(i).getAsJsonObject(); SWItem item = SWItem.getItemFromJson(itemJson); - item.setCallback(click -> new InventoryCallbackPacket(itemJson, click, player).send(Bukkit.getPlayer(player))); + item.setCallback(click -> { + new InventoryCallbackPacket(itemJson, click, player).send(Bukkit.getPlayer(player)); + }); items.put(itemJson.get("position").getAsInt(), item); } SWInventory inventory = new SWInventory(Bukkit.getPlayer(player), size, title, items); - inventory.addCloseCallback(click -> new InventoryCallbackPacket(player).send(Bukkit.getPlayer(player))); + inventory.addCloseCallback(click -> { + if(Bukkit.getPlayer(player).getOpenInventory().getType() == InventoryType.CRAFTING) + new InventoryCallbackPacket(player).send(Bukkit.getPlayer(player)); + }); inventory.open(); } } diff --git a/SpigotCore_Main/src/de/steamwar/comms/packets/MaterialsReturnPacket.java b/SpigotCore_Main/src/de/steamwar/comms/packets/MaterialsReturnPacket.java deleted file mode 100644 index 6feb97d..0000000 --- a/SpigotCore_Main/src/de/steamwar/comms/packets/MaterialsReturnPacket.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - 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 com.google.gson.JsonArray; -import de.steamwar.comms.PacketIdManager; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -import java.util.UUID; - -public class MaterialsReturnPacket extends SpigotPacket{ - - final UUID id; - final Material[] array; - - public MaterialsReturnPacket(UUID id, Material[] array) { - this.id = id; - this.array = array; - } - - @Override - public int getName() { - return PacketIdManager.MATERIALS_RETURN_PACKET; - } - - @Override - public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { - byteArrayDataOutput.writeUTF(id.toString()); - JsonArray array = new JsonArray(); - for (int i = 0; i < this.array.length; i++) { - if(new ItemStack(this.array[i]).getItemMeta() != null && this.array[i].isItem()) - array.add(this.array[i].name()); - } - byteArrayDataOutput.writeUTF(array.toString()); - } -} diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java index fb4846f..00bff09 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java @@ -61,8 +61,8 @@ public class Schematic { } public static void createSchem(String schemName, int schemOwner, String item, SchematicType schemType){ - SQL.update("INSERT INTO Schematic (SchemName, SchemOwner, Item, SchemType) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), SchemType = VALUES(SchemType)", - schemName, schemOwner, item, schemType.toDB()); + SQL.update("INSERT INTO Schematic (SchemName, SchemOwner, Item, SchemType, Rank) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), SchemType = VALUES(SchemType)", + schemName, schemOwner, item, schemType.toDB(), 0); } public static Schematic getSchemFromDB(String schemName, UUID schemOwner){