Skip to content

Commit

Permalink
Refactor switch statements and simplify typecasting.
Browse files Browse the repository at this point in the history
Refactored multiple switch statements to use the enhanced switch syntax for better readability and simplicity. Simplified typecasting by combining the instanceof check and cast into a single statement.
  • Loading branch information
nikosgram committed Aug 30, 2024
1 parent 61aa0c9 commit 2ccca35
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/main/java/org/gestern/gringotts/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,10 @@ public static Block chestBlock(Sign sign) {
Block signBlock = sign.getBlock();
BlockData blockData = signBlock.getBlockData();

if (!(blockData instanceof WallSign)) {
if (!(blockData instanceof WallSign signData)) {
return null;
}

WallSign signData = (WallSign) blockData;
BlockFace attached = signData.getFacing().getOppositeFace();

// allow either the block sign is attached to or the block below the sign as
Expand All @@ -197,18 +196,10 @@ public static boolean isValidContainer(Material material) {
return false;
}

switch (material) {
case CHEST:
case TRAPPED_CHEST:
case DISPENSER:
case FURNACE:
case HOPPER:
case DROPPER:
case BARREL:
return true;
default:
return false;
}
return switch (material) {
case CHEST, TRAPPED_CHEST, DISPENSER, FURNACE, HOPPER, DROPPER, BARREL -> true;
default -> false;
};
}

/**
Expand All @@ -218,18 +209,10 @@ public static boolean isValidContainer(Material material) {
* @return whether the given inventory type is valid for Gringotts
*/
public static boolean isValidInventory(InventoryType inventory) {

switch (inventory) {
case CHEST:
case DISPENSER:
case FURNACE:
case HOPPER:
case DROPPER:
case BARREL:
return true;
default:
return false;
}
return switch (inventory) {
case CHEST, DISPENSER, FURNACE, HOPPER, DROPPER, BARREL -> true;
default -> false;
};
}

/**
Expand Down

0 comments on commit 2ccca35

Please sign in to comment.