Get shop as Optional

This commit is contained in:
P0nk
2023-03-30 06:40:16 +02:00
parent fe9dd75a23
commit 39d759595d
4 changed files with 13 additions and 16 deletions

View File

@@ -30,7 +30,6 @@ import net.packet.InPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scripting.npc.NPCScriptManager;
import server.Shop;
import server.ShopFactory;
import server.life.NPC;
import server.life.PlayerNPC;
@@ -106,14 +105,10 @@ public final class NPCTalkHandler extends AbstractPacketHandler {
}
private boolean hasShop(NPC npc) {
return shopFactory.getShop(npc.getId()) != null;
return shopFactory.getShop(npc.getId()).isPresent();
}
private void sendShop(NPC npc, Client c) {
Shop shop = shopFactory.getShop(npc.getId());
if (shop == null) {
return;
}
shop.sendShop(c);
shopFactory.getShop(npc.getId()).ifPresent(shop -> shop.sendShop(c));
}
}

View File

@@ -54,6 +54,7 @@ import tools.Pair;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -511,9 +512,9 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
}
} else if (itemType == 545) { // MiuMiu's travel store
if (player.getShop() == null) {
Shop shop = shopFactory.getShop(MIU_MIU_SHOP_ID);
if (shop != null) {
shop.sendShop(c);
Optional<Shop> shop = shopFactory.getShop(MIU_MIU_SHOP_ID);
if (shop.isPresent()) {
shop.get().sendShop(c);
remove(c, position, itemId);
}
} else {