From 23acbc4946eb7d5fd03b5e51f45ac4f0d299c171 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 8 Feb 2023 12:23:02 +0100 Subject: [PATCH] Fixed all warnings --- .../org/bitbiome/classes/TravelEngine.java | 4 ++-- .../org/bitbiome/commands/CollectCommand.java | 21 ++++++++----------- .../org/bitbiome/commands/HelpCommand.java | 20 +++++++++--------- .../bitbiome/commands/InventoryCommand.java | 2 -- .../bitbiome/commands/LookaroundCommand.java | 5 +---- .../bitbiome/commands/CollectCommandTest.java | 5 ++--- .../org/bitbiome/commands/MapCommandTest.java | 4 ++-- 7 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/bitbiome/classes/TravelEngine.java b/src/main/java/org/bitbiome/classes/TravelEngine.java index d084831..18bce77 100644 --- a/src/main/java/org/bitbiome/classes/TravelEngine.java +++ b/src/main/java/org/bitbiome/classes/TravelEngine.java @@ -106,8 +106,8 @@ public class TravelEngine { } assert location != null; //TODO Create Location by name and add mobs and times to the location - JSONArray items = location.getJSONArray("items"); - JSONArray mobs = location.getJSONArray("mobs"); + // JSONArray items = location.getJSONArray("items"); + // JSONArray mobs = location.getJSONArray("mobs"); return new Location(name, new ArrayList<>(), new ArrayList<>()); } else { diff --git a/src/main/java/org/bitbiome/commands/CollectCommand.java b/src/main/java/org/bitbiome/commands/CollectCommand.java index 41d8fc0..9fee517 100644 --- a/src/main/java/org/bitbiome/commands/CollectCommand.java +++ b/src/main/java/org/bitbiome/commands/CollectCommand.java @@ -13,9 +13,7 @@ import java.util.Scanner; public class CollectCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { - StringBuilder s = new StringBuilder(); - JsonParser jp = new JsonParser(); - JSONObject o = jp.getJSONObject("playerconfig.json"); + JSONObject o = JsonParser.getJSONObject("src/main/resources/playerconfig.json"); JSONArray inventory = o.getJSONArray("inventory"); ArrayList location = travelEngine.getPlayer().getLocation().getItemList(); @@ -25,9 +23,9 @@ public class CollectCommand implements CommandAPI { String item = new String(); item = scanner.nextLine(); - collectItem(location, item, jp, o, inventory,getInventory); + collectItem(location, item, o, inventory,getInventory); } - public void collectItem(ArrayList location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList getInventory) { + public void collectItem(ArrayList location, String item, JSONObject o, JSONArray inventory, ArrayList getInventory) { for (int i = 0; i < location.size(); i++) { if (item.equals(location.get(i).getName())) { JSONObject o1 = new JSONObject(); @@ -36,29 +34,28 @@ public class CollectCommand implements CommandAPI { getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1); for (int k = 0; k < inventory.length(); k++) { if (inventory.getJSONObject(k).getString("name").equals(item)) { - increaseAmountInPlayerConfig(inventory,k,jp,o); + increaseAmountInPlayerConfig(inventory,k,o); return; } } } } - writeNewItem(location, getInventory, o1, inventory, i, jp, o); + writeNewItem(location, getInventory, o1, inventory, i, o); } } System.out.println("Es gibt kein Item, dass du einsammeln kannst."); } - public void writeNewItem(ArrayList location, ArrayList getInventory, JSONObject o1, JSONArray inventory, int i, JsonParser jp, JSONObject o){ + public void writeNewItem(ArrayList location, ArrayList getInventory, JSONObject o1, JSONArray inventory, int i, JSONObject o){ o1.put("name", location.get(i).getName()).put("doesDamage", location.get(i).doesDamage()).put("damage", location.get(i).getDamage()).put("amount", 1).put("durability", 1000); inventory.put(o1); - jp.writeObject("playerconfig.json", o); + JsonParser.writeObject("playerconfig.json", o); getInventory.add(location.get(i)); location.remove(i); } - public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JsonParser jp, JSONObject o){ - JSONObject o2 = new JSONObject(); + public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JSONObject o){ int amountItemsInPlayerconfig = 0; amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); - jp.writeObject("playerconfig.json", o); + JsonParser.writeObject("playerconfig.json", o); System.out.println(Colors.ANSI_YELLOW +"Du hast das Item eingesammelt."+ Colors.ANSI_RESET); } } diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java index 61051c0..55338f4 100644 --- a/src/main/java/org/bitbiome/commands/HelpCommand.java +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -27,26 +27,26 @@ public class HelpCommand implements CommandAPI { .append("|--------------|-----------------------------|\n") .append("|" + Colors.ANSI_GREEN + " travel" + Colors.ANSI_RESET + " | Startet das Reise System |\n") .append("|--------------|-----------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " quiz" + Colors.ANSI_RESET + " | Startet das quiz im shop |\n") + .append("|--------------|-----------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " blackjack" + Colors.ANSI_RESET + " | Startet blackjack im shop |\n") + .append("|--------------|-----------------------------|\n") .append("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") .append("|--------------|-----------------------------|\n") .append("|" + Colors.ANSI_GREEN + " quiz" + Colors.ANSI_RESET + " | Startet das quiz im shop |\n") .append("|--------------|-----------------------------|\n") .append("|" + Colors.ANSI_GREEN + " blackjack" + Colors.ANSI_RESET + " | Startet blackjack im shop |\n") .append("|--------------|-----------------------------|\n") - .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") - .append("|--------------|-------------------------------|\n") - .append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") - .append("|--------------|-------------------------------|\n") - .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") - .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") + .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") + .append("|--------------|-----------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") + .append("|--------------|-----------------------------|\n") + .append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\n") + .append("|" + Colors.ANSI_GREEN + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n") .append("|--------------|-----------------------------|\n") .append("|" + Colors.ANSI_GREEN + " map" + Colors.ANSI_RESET + " | Zeigt dir deinen Karte |\n") .append("|--------------|-----------------------------|\n") .append("|" + Colors.ANSI_GREEN + " gold" + Colors.ANSI_RESET + " | Gibt dein Gold an |\n") - .append("|______________|_____________________________|\n") - .append("|" + Colors.ANSI_GREEN + " use" + Colors.ANSI_RESET + " | Benutze ein Item |\n") - .append("|______________|_____________________________|\n") - .append("|" + Colors.ANSI_GREEN + " runaway" + Colors.ANSI_RESET + " | Fliehe aus einem Kampf |\n") .append("|______________|_____________________________|\n"); return outputMessage.toString(); diff --git a/src/main/java/org/bitbiome/commands/InventoryCommand.java b/src/main/java/org/bitbiome/commands/InventoryCommand.java index 08d37a4..c889df0 100644 --- a/src/main/java/org/bitbiome/commands/InventoryCommand.java +++ b/src/main/java/org/bitbiome/commands/InventoryCommand.java @@ -1,10 +1,8 @@ package org.bitbiome.commands; import org.bitbiome.classes.Colors; -import org.bitbiome.classes.JsonParser; import org.bitbiome.classes.TravelEngine; import org.bitbiome.entities.Item; -import org.json.JSONObject; import java.util.ArrayList; import java.util.Scanner; diff --git a/src/main/java/org/bitbiome/commands/LookaroundCommand.java b/src/main/java/org/bitbiome/commands/LookaroundCommand.java index b1ae8ed..e9b4d8c 100644 --- a/src/main/java/org/bitbiome/commands/LookaroundCommand.java +++ b/src/main/java/org/bitbiome/commands/LookaroundCommand.java @@ -7,9 +7,7 @@ import org.bitbiome.classes.TravelEngine; import org.bitbiome.entities.*; import org.json.JSONArray; import org.json.JSONObject; -import org.json.JSONTokener; -import java.io.InputStream; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; @@ -19,8 +17,7 @@ public class LookaroundCommand implements CommandAPI{ public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { StringBuilder outputMessage = new StringBuilder(); Location location = travelEngine.getPlayer().getLocation(); - JsonParser jp = new JsonParser(); - JSONObject gameConfig = jp.getJSONObject("src/main/resources/gameconfig.json"); + JSONObject gameConfig = JsonParser.getJSONObject("src/main/resources/gameconfig.json"); JSONArray locations = gameConfig.getJSONArray("locations"); JSONObject locationObject = getLocationObject(location.getName(), locations); JSONArray items = locationObject.getJSONArray("items"); diff --git a/src/test/java/org/bitbiome/commands/CollectCommandTest.java b/src/test/java/org/bitbiome/commands/CollectCommandTest.java index 75564dd..bbecb6c 100644 --- a/src/test/java/org/bitbiome/commands/CollectCommandTest.java +++ b/src/test/java/org/bitbiome/commands/CollectCommandTest.java @@ -13,12 +13,11 @@ public class CollectCommandTest { @Test public void testIncreaseAmountInPlayerConfig() { CollectCommand command = new CollectCommand(); - JsonParser jp = new JsonParser(); - JSONObject o = jp.getJSONObject("src/main/resources/playerconfig.json"); + JSONObject o = JsonParser.getJSONObject("src/main/resources/playerconfig.json"); JSONArray inventory = o.getJSONArray("inventory"); int k = 0; int initialAmount = inventory.getJSONObject(k).getInt("amount"); - command.increaseAmountInPlayerConfig(inventory, k, jp, o); + command.increaseAmountInPlayerConfig(inventory, k, o); int finalAmount = inventory.getJSONObject(k).getInt("amount"); assertEquals(initialAmount + 1, finalAmount); } diff --git a/src/test/java/org/bitbiome/commands/MapCommandTest.java b/src/test/java/org/bitbiome/commands/MapCommandTest.java index 3a85c7d..2513d67 100644 --- a/src/test/java/org/bitbiome/commands/MapCommandTest.java +++ b/src/test/java/org/bitbiome/commands/MapCommandTest.java @@ -3,11 +3,11 @@ package org.bitbiome.commands; import org.bitbiome.classes.Colors; import org.bitbiome.classes.TravelEngine; import org.bitbiome.entities.Location; -import org.bitbiome.entities.Mob; + import org.bitbiome.entities.Player; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +