Browse Source

Fixed all warnings

remotes/origin/develop
David Hermann 2 years ago
parent
commit
23acbc4946
  1. 4
      src/main/java/org/bitbiome/classes/TravelEngine.java
  2. 21
      src/main/java/org/bitbiome/commands/CollectCommand.java
  3. 12
      src/main/java/org/bitbiome/commands/HelpCommand.java
  4. 2
      src/main/java/org/bitbiome/commands/InventoryCommand.java
  5. 5
      src/main/java/org/bitbiome/commands/LookaroundCommand.java
  6. 5
      src/test/java/org/bitbiome/commands/CollectCommandTest.java
  7. 4
      src/test/java/org/bitbiome/commands/MapCommandTest.java

4
src/main/java/org/bitbiome/classes/TravelEngine.java

@ -106,8 +106,8 @@ public class TravelEngine {
} }
assert location != null; assert location != null;
//TODO Create Location by name and add mobs and times to the location //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<>()); return new Location(name, new ArrayList<>(), new ArrayList<>());
} else { } else {

21
src/main/java/org/bitbiome/commands/CollectCommand.java

@ -13,9 +13,7 @@ import java.util.Scanner;
public class CollectCommand implements CommandAPI { public class CollectCommand implements CommandAPI {
@Override @Override
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { 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"); JSONArray inventory = o.getJSONArray("inventory");
ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList(); ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList();
@ -25,9 +23,9 @@ public class CollectCommand implements CommandAPI {
String item = new String(); String item = new String();
item = scanner.nextLine(); item = scanner.nextLine();
collectItem(location, item, jp, o, inventory,getInventory);
collectItem(location, item, o, inventory,getInventory);
} }
public void collectItem(ArrayList<Item> location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList<Item> getInventory) {
public void collectItem(ArrayList<Item> location, String item, JSONObject o, JSONArray inventory, ArrayList<Item> getInventory) {
for (int i = 0; i < location.size(); i++) { for (int i = 0; i < location.size(); i++) {
if (item.equals(location.get(i).getName())) { if (item.equals(location.get(i).getName())) {
JSONObject o1 = new JSONObject(); JSONObject o1 = new JSONObject();
@ -36,29 +34,28 @@ public class CollectCommand implements CommandAPI {
getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1); getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1);
for (int k = 0; k < inventory.length(); k++) { for (int k = 0; k < inventory.length(); k++) {
if (inventory.getJSONObject(k).getString("name").equals(item)) { if (inventory.getJSONObject(k).getString("name").equals(item)) {
increaseAmountInPlayerConfig(inventory,k,jp,o);
increaseAmountInPlayerConfig(inventory,k,o);
return; 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."); } System.out.println("Es gibt kein Item, dass du einsammeln kannst.");
} }
public void writeNewItem(ArrayList<Item> location, ArrayList<Item> getInventory, JSONObject o1, JSONArray inventory, int i, JsonParser jp, JSONObject o){
public void writeNewItem(ArrayList<Item> location, ArrayList<Item> 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); 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); inventory.put(o1);
jp.writeObject("playerconfig.json", o);
JsonParser.writeObject("playerconfig.json", o);
getInventory.add(location.get(i)); getInventory.add(location.get(i));
location.remove(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; int amountItemsInPlayerconfig = 0;
amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount");
inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); 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); System.out.println(Colors.ANSI_YELLOW +"Du hast das Item eingesammelt."+ Colors.ANSI_RESET);
} }
} }

12
src/main/java/org/bitbiome/commands/HelpCommand.java

@ -27,6 +27,10 @@ public class HelpCommand implements CommandAPI {
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " travel" + Colors.ANSI_RESET + " | Startet das Reise System |\n") .append("|" + Colors.ANSI_GREEN + " travel" + Colors.ANSI_RESET + " | Startet das Reise System |\n")
.append("|--------------|-----------------------------|\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("|" + Colors.ANSI_GREEN + " location" + Colors.ANSI_RESET + " | Gibt deine Location aus |\n")
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " quiz" + Colors.ANSI_RESET + " | Startet das quiz im shop |\n") .append("|" + Colors.ANSI_GREEN + " quiz" + Colors.ANSI_RESET + " | Startet das quiz im shop |\n")
@ -34,19 +38,15 @@ public class HelpCommand implements CommandAPI {
.append("|" + Colors.ANSI_GREEN + " blackjack" + Colors.ANSI_RESET + " | Startet blackjack im shop |\n") .append("|" + Colors.ANSI_GREEN + " blackjack" + Colors.ANSI_RESET + " | Startet blackjack im shop |\n")
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n") .append("|" + Colors.ANSI_GREEN + " inventory" + Colors.ANSI_RESET + " | Gibt dein Inventar aus |\n")
.append("|--------------|-------------------------------|\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n") .append("|" + Colors.ANSI_GREEN + " collect " + Colors.ANSI_RESET + " | Gibt deine Location aus |\n")
.append("|--------------|-------------------------------|\n")
.append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " lookaround" + Colors.ANSI_RESET + " | Zeigt dir deine Umgebung, |\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 + " " + Colors.ANSI_RESET + " | Items und Mobs in der Nähe |\n")
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " map" + Colors.ANSI_RESET + " | Zeigt dir deinen Karte |\n") .append("|" + Colors.ANSI_GREEN + " map" + Colors.ANSI_RESET + " | Zeigt dir deinen Karte |\n")
.append("|--------------|-----------------------------|\n") .append("|--------------|-----------------------------|\n")
.append("|" + Colors.ANSI_GREEN + " gold" + Colors.ANSI_RESET + " | Gibt dein Gold an |\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"); .append("|______________|_____________________________|\n");
return outputMessage.toString(); return outputMessage.toString();

2
src/main/java/org/bitbiome/commands/InventoryCommand.java

@ -1,10 +1,8 @@
package org.bitbiome.commands; package org.bitbiome.commands;
import org.bitbiome.classes.Colors; import org.bitbiome.classes.Colors;
import org.bitbiome.classes.JsonParser;
import org.bitbiome.classes.TravelEngine; import org.bitbiome.classes.TravelEngine;
import org.bitbiome.entities.Item; import org.bitbiome.entities.Item;
import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner; import java.util.Scanner;

5
src/main/java/org/bitbiome/commands/LookaroundCommand.java

@ -7,9 +7,7 @@ import org.bitbiome.classes.TravelEngine;
import org.bitbiome.entities.*; import org.bitbiome.entities.*;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
@ -19,8 +17,7 @@ public class LookaroundCommand implements CommandAPI{
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) {
StringBuilder outputMessage = new StringBuilder(); StringBuilder outputMessage = new StringBuilder();
Location location = travelEngine.getPlayer().getLocation(); 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"); JSONArray locations = gameConfig.getJSONArray("locations");
JSONObject locationObject = getLocationObject(location.getName(), locations); JSONObject locationObject = getLocationObject(location.getName(), locations);
JSONArray items = locationObject.getJSONArray("items"); JSONArray items = locationObject.getJSONArray("items");

5
src/test/java/org/bitbiome/commands/CollectCommandTest.java

@ -13,12 +13,11 @@ public class CollectCommandTest {
@Test @Test
public void testIncreaseAmountInPlayerConfig() { public void testIncreaseAmountInPlayerConfig() {
CollectCommand command = new CollectCommand(); 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"); JSONArray inventory = o.getJSONArray("inventory");
int k = 0; int k = 0;
int initialAmount = inventory.getJSONObject(k).getInt("amount"); 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"); int finalAmount = inventory.getJSONObject(k).getInt("amount");
assertEquals(initialAmount + 1, finalAmount); assertEquals(initialAmount + 1, finalAmount);
} }

4
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.Colors;
import org.bitbiome.classes.TravelEngine; import org.bitbiome.classes.TravelEngine;
import org.bitbiome.entities.Location; import org.bitbiome.entities.Location;
import org.bitbiome.entities.Mob;
import org.bitbiome.entities.Player; import org.bitbiome.entities.Player;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Loading…
Cancel
Save