Skip to content

Commit 7da27a0

Browse files
authored
Clean up new errorprone warnings (#419)
MenuType is no longer an enum Offhand is fine with equality check InventoryManager really does intend to check if the references match
1 parent 180ceaf commit 7da27a0

5 files changed

Lines changed: 19 additions & 14 deletions

File tree

internal/paper26_2/src/main/java/com/lishid/openinv/internal/paper26_2/container/menu/OpenChestMenu.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,17 @@ public InventoryType.SlotType getSlotType(int slot) {
163163

164164
private int getTopSize(ServerPlayer viewer) {
165165
MenuType<?> menuType = getType();
166-
if (menuType == MenuType.GENERIC_9x1) {
166+
if (MenuType.GENERIC_9x1.equals(menuType)) {
167167
return 9;
168-
} else if (menuType == MenuType.GENERIC_9x2) {
168+
} else if (MenuType.GENERIC_9x2.equals(menuType)) {
169169
return 18;
170-
} else if (menuType == MenuType.GENERIC_9x3) {
170+
} else if (MenuType.GENERIC_9x3.equals(menuType)) {
171171
return 27;
172-
} else if (menuType == MenuType.GENERIC_9x4) {
172+
} else if (MenuType.GENERIC_9x4.equals(menuType)) {
173173
return 36;
174-
} else if (menuType == MenuType.GENERIC_9x5) {
174+
} else if (MenuType.GENERIC_9x5.equals(menuType)) {
175175
return 45;
176-
} else if (menuType == MenuType.GENERIC_9x6) {
176+
} else if (MenuType.GENERIC_9x6.equals(menuType)) {
177177
return 54;
178178
}
179179
// This is a bit gross, but allows us a safe fallthrough.

internal/paper26_2/src/main/java/com/lishid/openinv/internal/paper26_2/container/slot/ContentOffHand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.bukkit.event.inventory.InventoryType;
1111
import org.jetbrains.annotations.NotNull;
1212

13+
import java.util.Objects;
14+
1315
/**
1416
* A slot for equipment that updates held items if necessary.
1517
*/
@@ -37,7 +39,7 @@ public Slot asSlot(Container container, int slot, int x, int y) {
3739
return new SlotEquipment(container, slot, x, y) {
3840
@Override
3941
public void setChanged() {
40-
if (OpenPlayer.isConnected(holder.connection) && holder.containerMenu != holder.inventoryMenu) {
42+
if (OpenPlayer.isConnected(holder.connection) && !Objects.equals(holder.containerMenu, holder.inventoryMenu)) {
4143
holder.connection.send(
4244
new ClientboundContainerSetSlotPacket(
4345
holder.inventoryMenu.containerId,

internal/spigot26_2/src/main/java/com/github/jikoo/openinv/internal/spigot26_2/container/menu/OpenChestMenu.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,17 +164,17 @@ public int convertSlot(int rawSlot) {
164164

165165
private int getTopSize(ServerPlayer viewer) {
166166
MenuType<?> menuType = getType();
167-
if (menuType == MenuType.GENERIC_9x1) {
167+
if (MenuType.GENERIC_9x1.equals(menuType)) {
168168
return 9;
169-
} else if (menuType == MenuType.GENERIC_9x2) {
169+
} else if (MenuType.GENERIC_9x2.equals(menuType)) {
170170
return 18;
171-
} else if (menuType == MenuType.GENERIC_9x3) {
171+
} else if (MenuType.GENERIC_9x3.equals(menuType)) {
172172
return 27;
173-
} else if (menuType == MenuType.GENERIC_9x4) {
173+
} else if (MenuType.GENERIC_9x4.equals(menuType)) {
174174
return 36;
175-
} else if (menuType == MenuType.GENERIC_9x5) {
175+
} else if (MenuType.GENERIC_9x5.equals(menuType)) {
176176
return 45;
177-
} else if (menuType == MenuType.GENERIC_9x6) {
177+
} else if (MenuType.GENERIC_9x6.equals(menuType)) {
178178
return 54;
179179
}
180180
// This is a bit gross, but allows us a safe fallthrough.

internal/spigot26_2/src/main/java/com/github/jikoo/openinv/internal/spigot26_2/container/slot/ContentOffHand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.bukkit.event.inventory.InventoryType;
1111
import org.jetbrains.annotations.NotNull;
1212

13+
import java.util.Objects;
14+
1315
public class ContentOffHand extends ContentEquipment {
1416

1517
private ServerPlayer holder;
@@ -34,7 +36,7 @@ public Slot asSlot(Container container, int slot, int x, int y) {
3436
return new SlotEquipment(container, slot, x, y) {
3537
@Override
3638
public void setChanged() {
37-
if (OpenPlayer.isConnected(holder.connection) && holder.containerMenu != holder.inventoryMenu) {
39+
if (OpenPlayer.isConnected(holder.connection) && !Objects.equals(holder.containerMenu, holder.inventoryMenu)) {
3840
holder.connection.send(
3941
new ClientboundContainerSetSlotPacket(
4042
holder.inventoryMenu.containerId,

plugin/src/main/java/com/lishid/openinv/util/InventoryManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ private void onWorldChanged(@NotNull PlayerChangedWorldEvent event) {
133133

134134
@Keep
135135
@EventHandler
136+
@SuppressWarnings("ReferenceEquality") // We do really want to check that we have the same ref here.
136137
private void onInventoryClose(@NotNull InventoryCloseEvent event) {
137138
ISpecialInventory inventory = InventoryAccess.getInventory(event.getInventory());
138139

0 commit comments

Comments
 (0)