Skip to content

Commit

Permalink
fix caching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 4, 2024
1 parent ba5bd8b commit 2cef6cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ private void onPlayerAttemptPickupItem(PlayerAttemptPickupItemEvent event) {
final Item item = event.getItem();
final UUID itemUUID = item.getUniqueId();
Long itemSize = this.cachedItemSizes.getIfPresent(itemUUID);
if (itemSize == null)
if (itemSize == null) {
itemSize = this.getItemSize(item.getItemStack());
this.cachedItemSizes.put(itemUUID, itemSize);
this.cachedItemSizes.put(itemUUID, itemSize);
}
// If item is bigger than allowed, disallow player picking it up
if (itemSize > maxItemSize) {
event.setCancelled(true);
Expand All @@ -143,9 +144,10 @@ private void onPlayerAttemptPickupItem(PlayerAttemptPickupItemEvent event) {
final Player player = event.getPlayer();
final UUID playerUUID = player.getUniqueId();
Long invSize = this.cachedInventorySizes.getIfPresent(playerUUID);
if (invSize == null)
if (invSize == null) {
invSize = this.getInventorySize(player.getInventory());
this.cachedInventorySizes.put(playerUUID, invSize);
this.cachedInventorySizes.put(playerUUID, invSize);
}
// If picking up item would exceed max inventory size, disallow player picking it up
if (itemSize + invSize > maxInventorySize) {
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ private void onPlayerAttemptPickupItem(PlayerAttemptPickupItemEvent event) {
final Item item = event.getItem();
final UUID itemUUID = item.getUniqueId();
Long itemSize = this.cachedItemSizes.getIfPresent(itemUUID);
if (itemSize == null)
if (itemSize == null) {
itemSize = this.getItemSize(item.getItemStack());
this.cachedItemSizes.put(itemUUID, itemSize);
this.cachedItemSizes.put(itemUUID, itemSize);
}
// If item is bigger than allowed, disallow player picking it up
if (itemSize > maxItemSize) {
event.setCancelled(true);
Expand All @@ -126,9 +127,10 @@ private void onPlayerAttemptPickupItem(PlayerAttemptPickupItemEvent event) {
final Player player = event.getPlayer();
final UUID playerUUID = player.getUniqueId();
Long invSize = this.cachedInventorySizes.getIfPresent(playerUUID);
if (invSize == null)
if (invSize == null) {
invSize = this.getInventorySize(player.getInventory());
this.cachedInventorySizes.put(playerUUID, invSize);
this.cachedInventorySizes.put(playerUUID, invSize);
}
// If picking up item would exceed max inventory size, disallow player picking it up
if (itemSize + invSize > maxInventorySize) {
event.setCancelled(true);
Expand Down

0 comments on commit 2cef6cd

Please sign in to comment.