SteamWar/SpigotCore
Archiviert
13
0

Fix packet receiver
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-06-23 17:01:24 +02:00
Ursprung a5748f6a1b
Commit 6d0d3e1437

Datei anzeigen

@ -28,28 +28,28 @@ import de.steamwar.network.packets.client.InventoryCallbackPacket;
import de.steamwar.network.packets.server.InventoryPacket; import de.steamwar.network.packets.server.InventoryPacket;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
public class InventoryHandler extends PacketHandler { public class InventoryHandler extends PacketHandler {
@Handler @Handler
public static void handleInventoryPacket(InventoryPacket packet) { public static void handleInventoryPacket(InventoryPacket packet) {
Player player = Bukkit.getPlayer(SteamwarUser.get(packet.getPlayer()).getUUID());
Map<Integer, SWItem> items = new HashMap<>(); Map<Integer, SWItem> items = new HashMap<>();
packet.getItems().forEach((i, item) -> { packet.getItems().forEach((i, item) -> {
@SuppressWarnings("deprecation") SWItem it = SWItem.getItemFromJson(new JsonParser().parse(item).getAsJsonObject()); @SuppressWarnings("deprecation") SWItem it = SWItem.getItemFromJson(new JsonParser().parse(item).getAsJsonObject());
it.setCallback(click -> NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).position(i).type(InventoryCallbackPacket.CallbackType.CLICK).clickType(InventoryCallbackPacket.ClickType.getByName(click.name())).build())); it.setCallback(click -> NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).position(i).type(InventoryCallbackPacket.CallbackType.CLICK).clickType(InventoryCallbackPacket.ClickType.getByName(click.name())).build(), player));
items.put(i, it); items.put(i, it);
}); });
UUID player = SteamwarUser.get(packet.getPlayer()).getUUID();
SWInventory inventory = new SWInventory(Bukkit.getPlayer(player), packet.getSize(), packet.getTitle(), items); SWInventory inventory = new SWInventory(player, packet.getSize(), packet.getTitle(), items);
inventory.addCloseCallback(click -> { inventory.addCloseCallback(click -> {
if(Bukkit.getPlayer(player).getOpenInventory().getType() != InventoryType.CHEST) if(player.getOpenInventory().getType() != InventoryType.CHEST)
NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).type(InventoryCallbackPacket.CallbackType.CLOSE).build()); NetworkSender.send(InventoryCallbackPacket.builder().owner(packet.getPlayer()).type(InventoryCallbackPacket.CallbackType.CLOSE).build(), player);
}); });
inventory.open(); inventory.open();
} }