Skip to content

Commit d022b25

Browse files
committed
Fix several exceptions related to concurrency and version is now 1.1
1 parent f835e97 commit d022b25

File tree

13 files changed

+45
-37
lines changed

13 files changed

+45
-37
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ This is the full portfolio of protocolize dependencies:
2020
<dependency>
2121
<groupId>de.exceptionflug</groupId>
2222
<artifactId>protocolize-api</artifactId>
23-
<version>1.0-SNAPSHOT</version>
23+
<version>1.1-SNAPSHOT</version>
2424
<scope>provided</scope>
2525
</dependency>
2626
<dependency>
2727
<groupId>de.exceptionflug</groupId>
2828
<artifactId>protocolize-items</artifactId>
29-
<version>1.0-SNAPSHOT</version>
29+
<version>1.1-SNAPSHOT</version>
3030
<scope>provided</scope>
3131
</dependency>
3232
<dependency>
3333
<groupId>de.exceptionflug</groupId>
3434
<artifactId>protocolize-inventory</artifactId>
35-
<version>1.0-SNAPSHOT</version>
35+
<version>1.1-SNAPSHOT</version>
3636
<scope>provided</scope>
3737
</dependency>
3838
<dependency>
3939
<groupId>de.exceptionflug</groupId>
4040
<artifactId>protocolize-world</artifactId>
41-
<version>1.0-SNAPSHOT</version>
41+
<version>1.1-SNAPSHOT</version>
4242
<scope>provided</scope>
4343
</dependency>
4444
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>de.exceptionflug</groupId>
88
<artifactId>protocolize</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.1-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<modules>

protocolize-api/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
<parent>
4747
<groupId>de.exceptionflug</groupId>
4848
<artifactId>protocolize</artifactId>
49-
<version>1.0-SNAPSHOT</version>
49+
<version>1.1-SNAPSHOT</version>
5050
</parent>
5151

5252
<groupId>de.exceptionflug</groupId>
5353
<artifactId>protocolize-api</artifactId>
54-
<version>1.0-SNAPSHOT</version>
54+
<version>${parent.version}</version>
5555

5656
</project>

protocolize-examples/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@
77
<parent>
88
<groupId>de.exceptionflug</groupId>
99
<artifactId>protocolize</artifactId>
10-
<version>1.0-SNAPSHOT</version>
10+
<version>1.1-SNAPSHOT</version>
1111
</parent>
1212

1313
<groupId>de.exceptionflug</groupId>
1414
<artifactId>protocolize-examples</artifactId>
15-
<version>1.0-SNAPSHOT</version>
15+
<version>${parent.version}</version>
1616

1717
<dependencies>
1818
<dependency>
1919
<groupId>de.exceptionflug</groupId>
2020
<artifactId>protocolize-api</artifactId>
21-
<version>1.0-SNAPSHOT</version>
21+
<version>1.1-SNAPSHOT</version>
2222
<scope>provided</scope>
2323
</dependency>
2424
<dependency>
2525
<groupId>de.exceptionflug</groupId>
2626
<artifactId>protocolize-items</artifactId>
27-
<version>1.0-SNAPSHOT</version>
27+
<version>1.1-SNAPSHOT</version>
2828
<scope>provided</scope>
2929
</dependency>
3030
<dependency>
3131
<groupId>de.exceptionflug</groupId>
3232
<artifactId>protocolize-inventory</artifactId>
33-
<version>1.0-SNAPSHOT</version>
33+
<version>1.1-SNAPSHOT</version>
3434
<scope>provided</scope>
3535
</dependency>
3636
</dependencies>

protocolize-inventory/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@
1919
<parent>
2020
<groupId>de.exceptionflug</groupId>
2121
<artifactId>protocolize</artifactId>
22-
<version>1.0-SNAPSHOT</version>
22+
<version>1.1-SNAPSHOT</version>
2323
</parent>
2424

2525
<groupId>de.exceptionflug</groupId>
2626
<artifactId>protocolize-inventory</artifactId>
27-
<version>1.0-SNAPSHOT</version>
27+
<version>${parent.version}</version>
2828

2929
<dependencies>
3030
<dependency>
3131
<groupId>de.exceptionflug</groupId>
3232
<artifactId>protocolize-api</artifactId>
33-
<version>1.0-SNAPSHOT</version>
33+
<version>${parent.version}</version>
3434
<scope>provided</scope>
3535
</dependency>
3636
<dependency>
3737
<groupId>de.exceptionflug</groupId>
3838
<artifactId>protocolize-world</artifactId>
39-
<version>1.0-SNAPSHOT</version>
39+
<version>${parent.version}</version>
4040
<scope>provided</scope>
4141
</dependency>
4242
<dependency>
4343
<groupId>de.exceptionflug</groupId>
4444
<artifactId>protocolize-items</artifactId>
45-
<version>1.0-SNAPSHOT</version>
45+
<version>${parent.version}</version>
4646
<scope>provided</scope>
4747
</dependency>
4848
</dependencies>

protocolize-inventory/src/main/java/de/exceptionflug/protocolize/inventory/InventoryModule.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
import java.util.List;
2121
import java.util.Map;
2222
import java.util.UUID;
23+
import java.util.concurrent.ConcurrentHashMap;
2324

2425
import static de.exceptionflug.protocolize.api.util.ProtocolVersions.MINECRAFT_1_8;
2526

2627
public final class InventoryModule {
2728

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<>();
3132

3233
private static boolean spigotInventoryTracking = false;
3334

@@ -82,7 +83,10 @@ public static Map<Integer, Inventory> getInventories(final UUID playerId) {
8283

8384
public static Inventory getInventory(final UUID playerId, final int windowId) {
8485
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());
8690
final Inventory out = new Inventory(InventoryType.PLAYER, 46);
8791
out.setItems(inventory.getItemsIndexed());
8892
out.setHomebrew(false);
@@ -128,7 +132,7 @@ public static void sendInventory(final ProxiedPlayer p, Inventory inventory) {
128132

129133
boolean alreadyOpen = false;
130134
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<>());
132136
for (final Integer id : playerMap.keySet()) {
133137
final Inventory val = playerMap.get(id);
134138
if (val == inventory) {

protocolize-inventory/src/main/java/de/exceptionflug/protocolize/inventory/adapter/CloseWindowAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public CloseWindowAdapter(final Stream stream) {
1818
@Override
1919
public void receive(final PacketReceiveEvent<CloseWindow> event) {
2020
final Inventory inv = InventoryModule.getInventory(event.getPlayer().getUniqueId(), event.getPacket().getWindowId());
21+
if(inv == null)
22+
return;
2123
InventoryModule.registerInventory(event.getPlayer().getUniqueId(), event.getPacket().getWindowId(), null);
2224
ProxyServer.getInstance().getPluginManager().callEvent(new InventoryCloseEvent(event.getPlayer(), inv, null, event.getPacket().getWindowId()));
2325
}

protocolize-items/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
<parent>
2020
<groupId>de.exceptionflug</groupId>
2121
<artifactId>protocolize</artifactId>
22-
<version>1.0-SNAPSHOT</version>
22+
<version>1.1-SNAPSHOT</version>
2323
</parent>
2424

2525
<groupId>de.exceptionflug</groupId>
2626
<artifactId>protocolize-items</artifactId>
27-
<version>1.0-SNAPSHOT</version>
27+
<version>${parent.version}</version>
2828

2929
<dependencies>
3030
<dependency>
3131
<groupId>de.exceptionflug</groupId>
3232
<artifactId>protocolize-api</artifactId>
33-
<version>1.0-SNAPSHOT</version>
33+
<version>${parent.version}</version>
3434
<scope>provided</scope>
3535
</dependency>
3636
<dependency>

protocolize-items/src/main/java/de/exceptionflug/protocolize/items/adapter/BlockPlacementAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public BlockPlacementAdapter() {
2121
@Override
2222
public void receive(final PacketReceiveEvent<BlockPlacement> event) {
2323
final ProxiedPlayer p = event.getPlayer();
24+
if(event.getServerInfo() == null)
25+
return;
2426
final PlayerInventory playerInventory = InventoryManager.getCombinedSendInventory(p.getUniqueId(), event.getServerInfo().getName());
2527
final ItemStack inHand = playerInventory.getItem(playerInventory.getHeldItem()+36);
2628
if(inHand == null || inHand.getType() == ItemType.NO_DATA)

protocolize-plugin/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<parent>
88
<groupId>de.exceptionflug</groupId>
99
<artifactId>protocolize</artifactId>
10-
<version>1.0-SNAPSHOT</version>
10+
<version>1.1-SNAPSHOT</version>
1111
</parent>
1212

1313
<groupId>de.exceptionflug</groupId>
1414
<artifactId>protocolize-plugin</artifactId>
15-
<version>1.0-SNAPSHOT</version>
15+
<version>1.1-SNAPSHOT</version>
1616

1717
<properties>
1818
<plugin.main>de.exceptionflug.protocolize.ProtocolizePlugin</plugin.main>
@@ -23,22 +23,22 @@
2323
<dependency>
2424
<groupId>de.exceptionflug</groupId>
2525
<artifactId>protocolize-api</artifactId>
26-
<version>1.0-SNAPSHOT</version>
26+
<version>1.1-SNAPSHOT</version>
2727
</dependency>
2828
<dependency>
2929
<groupId>de.exceptionflug</groupId>
3030
<artifactId>protocolize-items</artifactId>
31-
<version>1.0-SNAPSHOT</version>
31+
<version>1.1-SNAPSHOT</version>
3232
</dependency>
3333
<dependency>
3434
<groupId>de.exceptionflug</groupId>
3535
<artifactId>protocolize-world</artifactId>
36-
<version>1.0-SNAPSHOT</version>
36+
<version>1.1-SNAPSHOT</version>
3737
</dependency>
3838
<dependency>
3939
<groupId>de.exceptionflug</groupId>
4040
<artifactId>protocolize-inventory</artifactId>
41-
<version>1.0-SNAPSHOT</version>
41+
<version>1.1-SNAPSHOT</version>
4242
</dependency>
4343
</dependencies>
4444

0 commit comments

Comments
 (0)