From 271532d3c42830c2312a10587192be743d4fab89 Mon Sep 17 00:00:00 2001 From: Max Gerbeth Date: Sun, 15 Jan 2023 17:58:43 +0100 Subject: [PATCH] Test if item still available in the shop --- src/main/java/org/bitbiome/shop/Shop.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/bitbiome/shop/Shop.java b/src/main/java/org/bitbiome/shop/Shop.java index 0fdd3c5..8753169 100644 --- a/src/main/java/org/bitbiome/shop/Shop.java +++ b/src/main/java/org/bitbiome/shop/Shop.java @@ -37,6 +37,21 @@ public class Shop { String content3 = new String(Files.readAllBytes(Paths.get(fileItem.toURI())), "UTF-8"); JSONArray itemJSON = new JSONArray(content3); + //Test if item still available in the shop + int itemIndex = -1; + for(int i = 0; i < currentShopItems.size(); i++){ + if(currentShopItems.get(i).getName().equals(itemName)){ + itemIndex = i; + } + } + if(itemIndex == -1){ + System.out.println("Dieses Item gibt es nicht"); + return false; + } + if(!(currentShopItems.get(itemIndex).amount > 0)){ + System.out.println("Es gibt zu wenige Items"); + return false; + } }catch (Exception e){