|
20 | 20 | import java.util.List; |
21 | 21 | import java.util.Map; |
22 | 22 | import java.util.UUID; |
| 23 | +import java.util.concurrent.ConcurrentHashMap; |
23 | 24 |
|
24 | 25 | import static de.exceptionflug.protocolize.api.util.ProtocolVersions.MINECRAFT_1_8; |
25 | 26 |
|
26 | 27 | public final class InventoryModule { |
27 | 28 |
|
28 | | - private static final Map<UUID, Map<Integer, Inventory>> WINDOW_MAP = Maps.newHashMap(); |
29 | | - private static final Map<UUID, Map<Integer, Map<Integer, InventoryAction>>> ACTION_MAP = Maps.newHashMap(); |
30 | | - private static final Map<UUID, Integer> WINDOW_ID_COUNTER_MAP = Maps.newHashMap(); |
| 29 | + private static final Map<UUID, Map<Integer, Inventory>> WINDOW_MAP = new ConcurrentHashMap<>(); |
| 30 | + private static final Map<UUID, Map<Integer, Map<Integer, InventoryAction>>> ACTION_MAP = new ConcurrentHashMap<>(); |
| 31 | + private static final Map<UUID, Integer> WINDOW_ID_COUNTER_MAP = new ConcurrentHashMap<>(); |
31 | 32 |
|
32 | 33 | private static boolean spigotInventoryTracking = false; |
33 | 34 |
|
@@ -82,7 +83,10 @@ public static Map<Integer, Inventory> getInventories(final UUID playerId) { |
82 | 83 |
|
83 | 84 | public static Inventory getInventory(final UUID playerId, final int windowId) { |
84 | 85 | if (windowId == 0) { |
85 | | - final PlayerInventory inventory = InventoryManager.getCombinedSendInventory(playerId, ProxyServer.getInstance().getPlayer(playerId).getServer().getInfo().getName()); |
| 86 | + final ProxiedPlayer player = ProxyServer.getInstance().getPlayer(playerId); |
| 87 | + if(player.getServer() == null || player.getServer().getInfo() == null) |
| 88 | + return null; |
| 89 | + final PlayerInventory inventory = InventoryManager.getCombinedSendInventory(playerId, player.getServer().getInfo().getName()); |
86 | 90 | final Inventory out = new Inventory(InventoryType.PLAYER, 46); |
87 | 91 | out.setItems(inventory.getItemsIndexed()); |
88 | 92 | out.setHomebrew(false); |
@@ -128,7 +132,7 @@ public static void sendInventory(final ProxiedPlayer p, Inventory inventory) { |
128 | 132 |
|
129 | 133 | boolean alreadyOpen = false; |
130 | 134 | int windowId = -1; |
131 | | - final Map<Integer, Inventory> playerMap = WINDOW_MAP.computeIfAbsent(p.getUniqueId(), (id) -> Maps.newHashMap()); |
| 135 | + final Map<Integer, Inventory> playerMap = WINDOW_MAP.computeIfAbsent(p.getUniqueId(), (id) -> new ConcurrentHashMap<>()); |
132 | 136 | for (final Integer id : playerMap.keySet()) { |
133 | 137 | final Inventory val = playerMap.get(id); |
134 | 138 | if (val == inventory) { |
|
0 commit comments