refactor: replace switch with enhanced switch

This commit is contained in:
Breno A. 2024-06-09 09:25:14 -03:00
parent 7db8b6f0c7
commit c9b42a6dfb
2 changed files with 25 additions and 37 deletions

View File

@ -431,26 +431,26 @@ public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
} }
private int getVirtualItemCount(int itemId) { private int getVirtualItemCount(int itemId) {
switch (itemId) { return switch (itemId) {
case 201: // Primogem case 201 -> // Primogem
return this.player.getPrimogems(); this.player.getPrimogems();
case 202: // Mora case 202 -> // Mora
return this.player.getMora(); this.player.getMora();
case 203: // Genesis Crystals case 203 -> // Genesis Crystals
return this.player.getCrystals(); this.player.getCrystals();
case 106: // Resin case 106 -> // Resin
return this.player.getProperty(PlayerProperty.PROP_PLAYER_RESIN); this.player.getProperty(PlayerProperty.PROP_PLAYER_RESIN);
case 107: // Legendary Key case 107 -> // Legendary Key
return this.player.getProperty(PlayerProperty.PROP_PLAYER_LEGENDARY_KEY); this.player.getProperty(PlayerProperty.PROP_PLAYER_LEGENDARY_KEY);
case 204: // Home Coin case 204 -> // Home Coin
return this.player.getHomeCoin(); this.player.getHomeCoin();
default: default -> {
GameItem item = GameItem item =
getInventoryTab(ItemType.ITEM_MATERIAL) getInventoryTab(ItemType.ITEM_MATERIAL)
.getItemById( .getItemById(
itemId); // What if we ever want to operate on weapons/relics/furniture? :S itemId); // What if we ever want to operate on weapons/relics/furniture? :Syield (item == null) ? 0 : item.getCount(); // What if we ever want to operate on weapons/relics/furniture? :S
return (item == null) ? 0 : item.getCount(); }
} };
} }
public synchronized boolean payItem(int id, int count) { public synchronized boolean payItem(int id, int count) {

View File

@ -40,24 +40,12 @@ public class HandlerSetPlayerBirthdayReq extends PacketHandler {
private boolean isValidBirthday(int month, int day) { private boolean isValidBirthday(int month, int day) {
switch (month) { return switch (month) {
case 1: case 1, 3, 5, 7, 8, 10, 12 -> day > 0 & day <= 31;
case 3: case 4, 6, 9, 11 -> day > 0 && day <= 30;
case 5: case 2 -> day > 0 & day <= 29;
case 7: default -> false;
case 8: };
case 10:
case 12:
return day > 0 & day <= 31;
case 4:
case 6:
case 9:
case 11:
return day > 0 && day <= 30;
case 2:
return day > 0 & day <= 29;
}
return false;
} }
} }