diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java index 6b65471a2c58742ba339dd052d65228d7757a41f..50c3ed17121754815da851fe8dbd355e4de9ed59 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/AzureDB.java @@ -1,7 +1,7 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.CryptoException; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseError; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.SQLException; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities.CryptoUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -33,7 +33,7 @@ public class AzureDB implements ISQLDataBase { } @Override - public Connection connect() throws DatabaseError { + public Connection connect() throws SQLException { try { getLoginData(); String url = "jdbc:sqlserver://battlearena.database.windows.net;encrypt=true;user=" + user + ";password=" + password + ";databaseName=battleArena;"; @@ -48,12 +48,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("SQL Connection Error"); + throw new SQLException("SQL Connection Error"); } } @Override - public ArrayList<MapData> getCoreMaps() throws DatabaseError{ + public ArrayList<MapData> getCoreMaps() throws SQLException { try(Connection connection = connect()) { ArrayList<MapData> newMaps = new ArrayList<MapData>(); String sql = "SELECT * FROM CoreMaps"; @@ -72,12 +72,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving Coremaps"); + throw new SQLException("Error retrieving Coremaps"); } } @Override - public ArrayList<MapInfo> getCommunityMapsList() throws DatabaseError{ + public ArrayList<MapInfo> getCommunityMapsList() throws SQLException { try(Connection connection = connect()) { ArrayList<MapInfo> tempList = new ArrayList<MapInfo>(); String sql = "SELECT map_id, map_name, map_width, map_height, map_downloads FROM communitymaps"; @@ -96,12 +96,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving community map names"); + throw new SQLException("Error retrieving community map names"); } } @Override - public MapData getCommunityMapByID(String mapID) throws DatabaseError{ + public MapData getCommunityMapByID(String mapID) throws SQLException { try(Connection connection = connect()) { String sql = "SELECT * FROM communitymaps WHERE map_ID = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -110,6 +110,9 @@ public class AzureDB implements ISQLDataBase { log.info("Sending SQL statement"); ResultSet rs = stmt.executeQuery(); MapData mapChosen = new MapData("", "",0,0, ""); + if(rs.next() == false){ //if no data matches + throw new SQLException("No match on Database"); + } while(rs.next()) { mapChosen = new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data")); } @@ -128,12 +131,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving community map"); + throw new SQLException("Error retrieving community map"); } } @Override - public void uploadCommunityMap(MapData map) throws DatabaseError{ + public void uploadCommunityMap(MapData map) throws SQLException { try(Connection connection = connect()) { String sql = "INSERT INTO communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -151,12 +154,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error uploading created community map"); + throw new SQLException("Error uploading created community map"); } } @Override - public void createPlayer(String playerName, String playerPW) throws DatabaseError{ + public void createPlayer(String playerName, String playerPW) throws SQLException { try(Connection connection = connect()) { String sql = "INSERT INTO players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES (?, ?, 0, 0, 0, 0, 0, 0)"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -171,12 +174,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error creating online account"); + throw new SQLException("Error creating online account"); } } @Override - public String checkCredentials(String playerName) throws DatabaseError{ + public String checkCredentials(String playerName) throws SQLException { try(Connection connection = connect()) { String sql = "SELECT player_pw FROM players WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -196,12 +199,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving retrieving player credentials"); + throw new SQLException("Error retrieving retrieving player credentials"); } } @Override - public PlayerStatistics getStatistics(String playerName) throws DatabaseError{ + public PlayerStatistics getStatistics(String playerName) throws SQLException { try(Connection connection = connect()) { String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM players WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -209,10 +212,12 @@ public class AzureDB implements ISQLDataBase { log.info("Sending SQL statement"); ResultSet rs = stmt.executeQuery(); - - PlayerStatistics stats = new PlayerStatistics(false, 0, 0, 0, 0, 0, 0); + if(rs.next() == false){ //if no data matches + throw new SQLException("No match on Database"); + } + PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0); while(rs.next()) { - stats = new PlayerStatistics(true, rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); + stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); } rs.close(); stmt.close(); @@ -221,12 +226,12 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving player statistics"); + throw new SQLException("Error retrieving player statistics"); } } @Override - public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws DatabaseError{ + public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { try(Connection connection = connect()) { String sql = "UPDATE players SET games_won = ?, games_lost = ?, kills = ?, deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -246,7 +251,7 @@ public class AzureDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error updating player statistics"); + throw new SQLException("Error updating player statistics"); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/DatabaseException.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/DatabaseException.java new file mode 100644 index 0000000000000000000000000000000000000000..57a4b7f978103f55a4a83525db1353be7b1fe4fb --- /dev/null +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/DatabaseException.java @@ -0,0 +1,12 @@ +package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions; + +public class DatabaseException extends Exception{ + + public DatabaseException() {} + + public DatabaseException(String message2) + { + super(message2); + } + +} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/DatabaseError.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/GSONException.java similarity index 50% rename from src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/DatabaseError.java rename to src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/GSONException.java index c115cf6e1d55cfff67d28c9a3049ada22df0ca9c..f16aa2d2831903fca6ccbd1555c798b53132f872 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/DatabaseError.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/GSONException.java @@ -1,10 +1,10 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions; -public class DatabaseError extends Exception{ +public class GSONException extends Exception{ - public DatabaseError() {} + public GSONException() {} - public DatabaseError(String message2) + public GSONException(String message2) { super(message2); } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/ParserException.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/ParserException.java new file mode 100644 index 0000000000000000000000000000000000000000..27bd887ed9a7b5cb604d63e2194c818c91cae56a --- /dev/null +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/ParserException.java @@ -0,0 +1,12 @@ +package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions; + +public class ParserException extends Exception{ + + public ParserException() {} + + public ParserException(String message2) + { + super(message2); + } + +} diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/ParserError.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/SQLException.java similarity index 50% rename from src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/ParserError.java rename to src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/SQLException.java index a1f67ba38dc9ad7d181e9f891b927877636ade37..adbdfa7fac0321fd39687bd957c7f05f542aaaa9 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/ParserError.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Exceptions/SQLException.java @@ -1,10 +1,10 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions; -public class ParserError extends Exception{ +public class SQLException extends Exception{ - public ParserError() {} + public SQLException() {} - public ParserError(String message2) + public SQLException(String message2) { super(message2); } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java index 6742c97134e13cd614ddbb69396357280b33c1a1..b330be1f110d65125e9dfb9b413adcac5c90a10e 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/GsonHandler.java @@ -3,7 +3,7 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseError; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.GSONException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -27,7 +27,7 @@ public class GsonHandler { private final String filePathPlayerAccount = "src/main/resources/player/playerAccount.json"; private final String filePathSettings = "src/main/resources/player/appSettings.json"; - public ArrayList<MapData> loadMaps(MapType type) throws DatabaseError{ + public ArrayList<MapData> loadMaps(MapType type) throws GSONException { String filePath; if(type == MapType.COREMAP){ filePath = filePathCoreMaps; @@ -42,11 +42,11 @@ public class GsonHandler { } catch (Exception e) { log.info(e); log.info("GSON - Loading maps from JSON failed"); - throw new DatabaseError("Error loading maps!"); + throw new GSONException("Error loading maps!"); } } - public void saveMaps(ArrayList<MapData> maps, MapType type) throws DatabaseError{ + public void saveMaps(ArrayList<MapData> maps, MapType type) throws GSONException { String filePath; if(type == MapType.COREMAP){ filePath = filePathCoreMaps; @@ -60,11 +60,11 @@ public class GsonHandler { } catch (Exception e) { log.info(e); log.info("GSON - Saving maps to JSON failed"); - throw new DatabaseError("Error saving maps!"); + throw new GSONException("Error saving maps!"); } } - public PlayerStatistics loadStats() throws DatabaseError{ + public PlayerStatistics loadStats() throws GSONException { try (FileReader reader = new FileReader(filePathPlayerStats)) { PlayerStatistics stats = gson.fromJson(reader, playerStatsType); log.info("GSON - Player statistics successfully loaded from JSON"); @@ -72,22 +72,22 @@ public class GsonHandler { } catch (Exception e) { log.info(e); log.info("GSON - Loading player statistics from JSON failed"); - throw new DatabaseError("Error loading player statistics!"); + throw new GSONException("Error loading player statistics!"); } } - public void saveStats(PlayerStatistics stats) throws DatabaseError{ + public void saveStats(PlayerStatistics stats) throws GSONException { try (FileWriter writer = new FileWriter(filePathPlayerStats)) { gson.toJson(stats, writer); log.info("GSON - Player statistics successfully saved to JSON"); } catch (Exception e) { log.info(e); log.info("GSON - Saving player statistics to JSON failed"); - throw new DatabaseError("Error saving player statistics!"); + throw new GSONException("Error saving player statistics!"); } } - public AppSettings loadSettings() throws DatabaseError{ + public AppSettings loadSettings() throws GSONException { try (FileReader reader = new FileReader(filePathSettings)) { AppSettings settings = gson.fromJson(reader, settingsType); log.info("GSON - Settings successfully loaded from JSON"); @@ -95,22 +95,22 @@ public class GsonHandler { } catch (Exception e) { log.info(e); log.info("GSON - Loading settings from JSON failed"); - throw new DatabaseError("Error Loading settings!"); + throw new GSONException("Error Loading settings!"); } } - public void saveSettings(AppSettings settings) throws DatabaseError{ + public void saveSettings(AppSettings settings) throws GSONException { try (FileWriter writer = new FileWriter(filePathSettings)) { gson.toJson(settings, writer); log.info("GSON - Settings successfully saved to JSON"); } catch (Exception e) { log.info(e); log.info("GSON - Saving settings to JSON failed"); - throw new DatabaseError("Error saving settings!"); + throw new GSONException("Error saving settings!"); } } - public PlayerAccount loadAccount() throws DatabaseError{ + public PlayerAccount loadAccount() throws GSONException { try (FileReader reader = new FileReader(filePathPlayerAccount)) { PlayerAccount account = gson.fromJson(reader, accountType); log.info("GSON - Player account information successfully loaded from JSON"); @@ -118,18 +118,18 @@ public class GsonHandler { } catch (Exception e) { log.info(e); log.info("GSON - Loading player account information from JSON failed"); - throw new DatabaseError("Error loading player account information!"); + throw new GSONException("Error loading player account information!"); } } - public void saveAccount(PlayerAccount account) throws DatabaseError{ + public void saveAccount(PlayerAccount account) throws GSONException { try (FileWriter writer = new FileWriter(filePathPlayerAccount)) { gson.toJson(account, writer); log.info("GSON - Player account information successfully saved to JSON"); } catch (Exception e) { log.info(e); log.info("GSON - Saving player account information to JSON failed"); - throw new DatabaseError("Error loading player account information!"); + throw new GSONException("Error loading player account information!"); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java index a51f71a0205053db9e067b4ef6835095c27c9c33..dd7bb2f0eb72ddd6eac0a59ce72e0654f522a3ab 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/ISQLDataBase.java @@ -1,6 +1,6 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseError; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.SQLException; import java.sql.Connection; import java.util.ArrayList; @@ -8,16 +8,16 @@ import java.util.ArrayList; public interface ISQLDataBase { //Establish Connection - Connection connect() throws DatabaseError; + Connection connect() throws SQLException; //CRUD Operations in SQL - ArrayList<MapData> getCoreMaps() throws DatabaseError; - ArrayList<MapInfo> getCommunityMapsList() throws DatabaseError; - MapData getCommunityMapByID(String mapID) throws DatabaseError; - void uploadCommunityMap(MapData map) throws DatabaseError; - void createPlayer(String playerName, String playerPW) throws DatabaseError; - String checkCredentials(String playerName) throws DatabaseError; - PlayerStatistics getStatistics(String playerName) throws DatabaseError; - void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws DatabaseError; + ArrayList<MapData> getCoreMaps() throws SQLException; + ArrayList<MapInfo> getCommunityMapsList() throws SQLException; + MapData getCommunityMapByID(String mapID) throws SQLException; + void uploadCommunityMap(MapData map) throws SQLException; + void createPlayer(String playerName, String playerPW) throws SQLException; + String checkCredentials(String playerName) throws SQLException; + PlayerStatistics getStatistics(String playerName) throws SQLException; + void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException; } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java index 72626e7c409de523a0a13a6515364b1cd66b204b..44e2a5a1489f8c66b2d035bb354af7063f6bb7d8 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/OracleDB.java @@ -2,7 +2,7 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities.CryptoUtils; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.CryptoException; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseError; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.SQLException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -32,7 +32,7 @@ public class OracleDB implements ISQLDataBase { } @Override - public Connection connect() throws DatabaseError{ + public Connection connect() throws SQLException { try { getLoginData(); OracleDataSource ods = new OracleDataSource(); @@ -47,12 +47,12 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("SQL connection error"); + throw new SQLException("SQL connection error"); } } @Override - public ArrayList<MapData> getCoreMaps() throws DatabaseError{ + public ArrayList<MapData> getCoreMaps() throws SQLException { try(Connection connection = connect()) { ArrayList<MapData> newMaps = new ArrayList<MapData>(); String sql = "SELECT * FROM battlearenadata.coremaps"; @@ -71,12 +71,12 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving coremaps"); + throw new SQLException("Error retrieving coremaps"); } } @Override - public ArrayList<MapInfo> getCommunityMapsList() throws DatabaseError{ + public ArrayList<MapInfo> getCommunityMapsList() throws SQLException { try(Connection connection = connect()) { ArrayList<MapInfo> tempList = new ArrayList<MapInfo>(); String sql = "SELECT map_id, map_name, map_width, map_height, map_downloads FROM battlearenadata.communitymaps"; @@ -95,12 +95,12 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving community map names"); + throw new SQLException("Error retrieving community map names"); } } @Override - public MapData getCommunityMapByID(String mapID) throws DatabaseError{ + public MapData getCommunityMapByID(String mapID) throws SQLException { try(Connection connection = connect()) { String sql = "SELECT * FROM battlearenadata.communitymaps WHERE map_ID = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -109,6 +109,9 @@ public class OracleDB implements ISQLDataBase { log.info("Sending SQL statement"); ResultSet rs = stmt.executeQuery(); MapData mapChosen = new MapData("", "",0,0, ""); + if(rs.next() == false){ //if no data matches + throw new SQLException("No match on Database"); + } while(rs.next()) { mapChosen = new MapData(rs.getString("map_id"), rs.getString("map_name"), rs.getInt("map_width"), rs.getInt("map_height"), rs.getString("map_data")); } @@ -126,13 +129,13 @@ public class OracleDB implements ISQLDataBase { return mapChosen; } catch(Exception e){ - log.error(e); - throw new DatabaseError("Error retrieving community map"); + log.error(e.getMessage()); + throw new SQLException(e.getMessage()); } } @Override - public void uploadCommunityMap(MapData map) throws DatabaseError{ + public void uploadCommunityMap(MapData map) throws SQLException { try(Connection connection = connect()) { String sql = "INSERT INTO battlearenadata.communitymaps (map_id, map_name, map_width, map_height, map_data) VALUES (?, ?, ?, ?, ?)"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -150,12 +153,12 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error uploading created community map"); + throw new SQLException("Error uploading created community map"); } } @Override - public void createPlayer(String playerName, String playerPW) throws DatabaseError{ + public void createPlayer(String playerName, String playerPW) throws SQLException { try(Connection connection = connect()) { String sql = "INSERT INTO battlearenadata.players (player_name, player_pw, games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time) VALUES (?, ?, 0, 0, 0, 0, 0, 0)"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -170,12 +173,12 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error creating online account"); + throw new SQLException("Error creating online account"); } } @Override - public String checkCredentials(String playerName) throws DatabaseError{ + public String checkCredentials(String playerName) throws SQLException { try(Connection connection = connect()) { String sql = "SELECT player_pw FROM battlearenadata.players WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -195,12 +198,12 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving retrieving player credentials"); + throw new SQLException("Error retrieving retrieving player credentials"); } } @Override - public PlayerStatistics getStatistics(String playerName) throws DatabaseError{ + public PlayerStatistics getStatistics(String playerName) throws SQLException { try(Connection connection = connect()) { String sql = "SELECT games_won, games_lost, kills, deaths, blocks_destroyed, ingame_time FROM battlearenadata.players WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -208,10 +211,12 @@ public class OracleDB implements ISQLDataBase { log.info("Sending SQL statement"); ResultSet rs = stmt.executeQuery(); - - PlayerStatistics stats = new PlayerStatistics(false, 0, 0, 0, 0, 0, 0); + if(rs.next() == false){ //if no data matches + throw new SQLException("No match on database"); + } + PlayerStatistics stats = new PlayerStatistics(0, 0, 0, 0, 0, 0); while(rs.next()) { - stats = new PlayerStatistics(true, rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); + stats = new PlayerStatistics(rs.getInt("games_won"), rs.getInt("games_lost"), rs.getInt("kills"), rs.getInt("deaths"), rs.getInt("blocks_destroyed"), rs.getInt("ingame_time")); } rs.close(); stmt.close(); @@ -220,12 +225,12 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error retrieving player statistics"); + throw new SQLException("Error retrieving player statistics"); } } @Override - public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws DatabaseError{ + public void updatePlayerStats(PlayerStatistics stats, PlayerAccount account) throws SQLException { try(Connection connection = connect()) { String sql = "UPDATE battlearenadata.players SET games_won = ?, games_lost = ?, kills = ?, deaths = ?, blocks_destroyed = ?, ingame_time = ? WHERE player_name = ?"; PreparedStatement stmt = connection.prepareStatement(sql); @@ -245,7 +250,7 @@ public class OracleDB implements ISQLDataBase { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error updating player statistics"); + throw new SQLException("Error updating player statistics"); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java index db91d1b662c3ff94c97d1aa3b6360a85ea5603f5..f6e453604625bdd38185c7bb4273fa79bd057949 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Persistence.java @@ -1,7 +1,7 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities.HashGenerator; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseError; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseException; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -23,79 +23,122 @@ public class Persistence { private Persistence (){} - public static Persistence getInstance(){ + protected static Persistence getInstance(){ return persistenceSingleton; } - public void loadCoreMaps() throws DatabaseError{ + protected void loadCoreMaps() throws DatabaseException { try { coreMaps = gsonHandler.loadMaps(MapType.COREMAP); log.info("Core-Maps successfully loaded from file"); - //log.info(coreMaps.get(0).getMapName()); //for testing purposes } catch(Exception e){ log.error(e); + throw new DatabaseException("Loading core maps from local storage failed!"); } } - public void loadCommunityMaps() throws DatabaseError{ + protected void loadCommunityMaps() throws DatabaseException { try { communityMaps = gsonHandler.loadMaps(MapType.COMMUNITYMAP); log.info("Community-Maps successfully loaded from file"); - //log.info(coreMaps.get(0).getMapName()); //for testing purposes } catch(Exception e){ log.error(e); + throw new DatabaseException("Loading community maps from local storage failed!"); } } - public void updateCoreMaps() throws DatabaseError{ + protected void updateCoreMaps() throws DatabaseException { try { coreMaps = db.getCoreMaps(); gsonHandler.saveMaps(coreMaps, MapType.COREMAP); log.info("Maps successfully updated from SQL-Server"); - //log.info(coreMaps.get(0).getMapName()); //for testing purposes } catch(Exception e){ log.error(e); + if(e.getMessage().contains("ORA-17868") | e.getMessage().contains("ORA-01017")){ + throw new DatabaseException("No connection to SQL server!"); + } + else{ + throw new DatabaseException("Unknown Database Error. Retrieving Core-Map update failed!"); + } } } - public void getCommunityMap(String mapSelected) throws DatabaseError{ + protected void getCommunityMap(String mapID) throws DatabaseException { try { - communityMaps.add(db.getCommunityMapByID(mapSelected)); + communityMaps.add(db.getCommunityMapByID(mapID)); gsonHandler.saveMaps(communityMaps, MapType.COMMUNITYMAP); log.info("Community Map successfully retrieved from SQL-Server!"); } catch(Exception e){ log.error(e); + if(e.getMessage().contains("ORA-17868") | e.getMessage().contains("ORA-01017")){ + throw new DatabaseException("No connection to SQL server!"); + } + else if(e.getMessage().equals("No match on Database")){ + throw new DatabaseException("No map existing for mapID: " + mapID); + } + else{ + throw new DatabaseException("Unknown Database Error. Retrieving Community-Map failed!"); + } } } - public void uploadCommunityMap(MapData map) throws DatabaseError{ + protected void saveCreatedMapLocally(MapData map) throws DatabaseException { try { - db.uploadCommunityMap(map); - communityMaps.add(map); //hier noch prüfen, ob die Map lokal bereits existiert (falls eine Verbindung zur DB scheitern sollte, kann man sie dennoch lokal speichern (müsste dann in finally block) + for(int i = 0; communityMaps.size() > i; i++){ + if(communityMaps.get(i).getMapID().equals(map.getMapID())){ + throw new DatabaseException("Identical map already saved locally. See map name: " + communityMaps.get(i).getMapID()); + } + } + communityMaps.add(map); gsonHandler.saveMaps(communityMaps, MapType.COMMUNITYMAP); - log.info("Community-Maps successfully published"); + log.info("Newly created map stored successfully in JSON"); } catch(Exception e){ log.error(e); + if(e.getMessage().contains("Identical map already saved") | e.getMessage().contains("ORA-01017")){ + throw new DatabaseException(e.getMessage()); + } + else{ + throw new DatabaseException("Unknown Database Error. Saving newly created Community-Map failed!"); + } } } - public void loadSettings() throws DatabaseError{ + protected void uploadCreatedMap(MapData map) throws DatabaseException { + try { + db.uploadCommunityMap(map); + log.info("Newly created Community-Map successfully published!"); + } + catch(Exception e){ + log.error(e); + if(e.getMessage().contains("ORA-17868") | e.getMessage().contains("ORA-01017")){ + throw new DatabaseException("No connection to SQL server!"); + } + else if(e.getMessage().contains("ORA-00001")){ + throw new DatabaseException("Map already existing on communityMaps server!\n Look for mapID: " + map.getMapID()); + } + else{ + throw new DatabaseException("Unknown Database Error. Saving to SQL communityMap server failed!"); + } + } + } + + protected void loadSettings() throws DatabaseException { try { settings = gsonHandler.loadSettings(); log.info("Application settings successfully loaded from file"); - //log.info(coreMaps.get(0).getMapName()); //for testing purposes } catch(Exception e){ log.error(e); + throw new DatabaseException("Loading settings from local storage failed!"); } } - public void createAccount(String name, String password, AccountType type) throws DatabaseError { + protected void createAccount(String name, String password, AccountType type) throws DatabaseException { try { String hashedPassword = HashGenerator.hashAndHex(password); @@ -105,7 +148,7 @@ public class Persistence { db.createPlayer(name, hashedPassword); } catch (Exception e) { log.error(e); - throw new DatabaseError("SQL Error"); + throw new DatabaseException("SQL Error"); } } @@ -115,23 +158,24 @@ public class Persistence { } catch(Exception e){ log.error(e); - throw new DatabaseError("Error Creating Account\n" + e.getMessage()); + throw new DatabaseException("Error Creating Account\n" + e.getMessage()); } } - public void loadPlayerAccount() throws DatabaseError{ + protected void loadPlayerAccount() throws DatabaseException { try { gsonHandler.loadAccount(); } catch(Exception e){ log.error(e); - } + throw new DatabaseException("Loading player account data from local storage failed!"); + } } - public void loadPlayerStatistics() throws DatabaseError{ + protected void loadPlayerStatistics() throws DatabaseException { try { if (account.getAccountState() == AccountType.NONE) { - throw new DatabaseError("Must create playerAccount first"); + throw new DatabaseException("Must create playerAccount first"); } else if (account.getAccountState() == AccountType.LOCAL) { statistics = gsonHandler.loadStats(); } else { @@ -139,12 +183,13 @@ public class Persistence { statistics = db.getStatistics(account.getPlayerName()); } else{ - throw new DatabaseError("Wrong Password"); + throw new DatabaseException("Wrong Password"); } } } catch(Exception e){ log.error(e); + throw new DatabaseException(e.getMessage()); } } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java index 25ce6a994c0784e644cba77c93a0922ce1850b38..532324238dd5b1b7a19c8de5a0555bc3e2c83fba 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/PlayerStatistics.java @@ -6,7 +6,6 @@ import org.apache.logging.log4j.LogManager; public class PlayerStatistics { private static final Logger log = LogManager.getLogger(PlayerStatistics.class); - private boolean statsLoaded = false; //indicator, if stats were loaded at startup from JSON/SQL private int gamesLost = 0; private int gamesWon = 0; private int kills = 0; @@ -14,8 +13,7 @@ public class PlayerStatistics { private int blocksDestroyed = 0; private int gameTime = 0; - public PlayerStatistics(boolean statsLoaded, int gamesLost, int gamesWon, int kills, int deaths, int blocksDestroyed, int gameTime) { - this.statsLoaded = statsLoaded; + public PlayerStatistics(int gamesLost, int gamesWon, int kills, int deaths, int blocksDestroyed, int gameTime) { this.gamesLost = gamesLost; this.gamesWon = gamesWon; this.kills = kills; @@ -73,8 +71,4 @@ public class PlayerStatistics { this.gameTime = gameTime; } - public boolean isStatsLoaded() { - return statsLoaded; - } - } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java index e7365fe9b1a860461a21cd661bb1b733d2518c95..da42301d5940db9af609ea09829d2172f141353e 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/RuntimeInfo.java @@ -1,5 +1,6 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.DatabaseException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -11,55 +12,75 @@ public class RuntimeInfo { private static final Logger log = LogManager.getLogger(RuntimeInfo.class); private static final RuntimeInfo runtimeInfoSingleton = new RuntimeInfo(); private final Persistence persistenceInst = Persistence.getInstance(); - private LinkedHashMap<String, String> mapNames; - protected MapData mapCreated; //to store parsed Data from MapCreator for Upload to SQL - protected String communityMapSelected; - protected ArrayList<String> coreMapsListLocal; - protected ArrayList<String> communityMapsListLocal; - protected ArrayList<MapInfo> communityMapsListRemote; + private LinkedHashMap<String, String> mapNames; //????? + protected ArrayList<String> coreMapsListLocal; //for drop-down list + protected ArrayList<String> communityMapsListLocal; //for drop-down list + protected ArrayList<MapInfo> communityMapsListRemote; //for community map browser protected String mapDataGame; + protected boolean startupComplete = false; private RuntimeInfo(){}; + public static RuntimeInfo getInstance(){ return runtimeInfoSingleton; } - public String getMapDataGame() { - return mapDataGame; - } - - public MapData getMapCreated() { - return mapCreated; + public boolean isStartupComplete() { + return startupComplete; } - public void setMapCreated(MapData mapCreated) { - this.mapCreated = mapCreated; + public void setStartupComplete(boolean startupComplete) { + this.startupComplete = startupComplete; } - public String getCommunityMapSelected() { - return communityMapSelected; - } - - public void setCommunityMapSelected(String communityMapSelected) { - this.communityMapSelected = communityMapSelected; - } - - public void startup(){ + public void startupPhase1(){ try { persistenceInst.loadPlayerAccount(); //must be called before "loadPlayerStatistics()" //wenn playerAccount type "none" ist, dann Create-Player scene und dafür noch eine "Create account" methode schreiben, die dann auch die Daten mit GSON speichert (verschlüsselt) //nachdem Player Account erstellt hat, wird die Methode "startup()" neu gestartet + persistenceInst.loadPlayerStatistics(); + } + catch(Exception e){ + log.error(e); + } + } + + public void startupPhase2(){ + try { persistenceInst.loadSettings(); persistenceInst.loadCoreMaps(); persistenceInst.loadCommunityMaps(); - persistenceInst.loadPlayerStatistics(); } catch(Exception e){ log.error(e); } } + public String getMapDataGame() { + return mapDataGame; + } + + public void uploadCreatedMap(MapData mapCreated) throws DatabaseException { + try { + persistenceInst.uploadCreatedMap(mapCreated); + } + catch(Exception e){ + log.error(e); + throw new DatabaseException(e.getMessage()); + } + } + + public void saveCreatedMap(MapData mapCreated) throws DatabaseException { + try { + persistenceInst.saveCreatedMapLocally(mapCreated); + } + catch(Exception e){ + log.error(e); + throw new DatabaseException(e.getMessage()); + } + } + private void setGameMap(String mapSelected, boolean choseCoremaps){ mapSelected = mapSelected.substring(mapSelected.indexOf("(") + 1, mapSelected.length() - 1); @@ -79,24 +100,20 @@ public class RuntimeInfo { } } - public void getCommunityMap(){ - try { - persistenceInst.getCommunityMap(communityMapSelected); - } - catch(Exception e){ - log.error(e); + public void getCommunityMap(String mapID) throws DatabaseException { + for(int i = 0; persistenceInst.communityMaps.size() > i; i++){ + if(persistenceInst.communityMaps.get(i).getMapID().equals(mapID)){ + throw new DatabaseException("Identical map already saved locally. See map name: " + persistenceInst.communityMaps.get(i).getMapID()); + } } - } - - public void uploadMapCreated(){ try { - persistenceInst.uploadCommunityMap(mapCreated); + persistenceInst.getCommunityMap(mapID); } catch(Exception e){ log.error(e); + throw new DatabaseException(e.getMessage()); } } - //add Hash-Creator for creating map_ID and parse if map_data is according to specs private void updateStats(String outcome, String kills, String deaths, int gameTime){ //update PlayerStatistics @@ -132,8 +149,5 @@ public class RuntimeInfo { } } -/* public void getStatsByID(String playerID){ - //fetches from SQL stats by player with provided ID - players can display stats of other players in "Statistics" Scene - }*/ } diff --git a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java index 1cfc5927db8db8aded9a73b013eb9797b0fb2aa0..f4e716faab16d231a0ab1914f2c7bceaecc9df7c 100644 --- a/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java +++ b/src/main/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/Parser.java @@ -1,6 +1,6 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.ParserError; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.ParserException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -16,83 +16,83 @@ public class Parser { -Parser for mapData from newly created map (length, formatting (spaces), tile-types, border-tiles etc.) */ - public static void usernameValid(String username) throws ParserError{ + public static void usernameValid(String username) throws ParserException { if(username.length() < 4){ - throw new ParserError("Username too short! Min length is 4 characters."); + throw new ParserException("Username too short! Min length is 4 characters."); } if(username.length() > 40){ - throw new ParserError("Username too long! Max length is 40 characters."); + throw new ParserException("Username too long! Max length is 40 characters."); } Pattern pat = Pattern.compile("[^a-z0-9_-]", Pattern.CASE_INSENSITIVE); Matcher mat = pat.matcher(username); boolean result = mat.find(); if(result){ - throw new ParserError("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !"); + throw new ParserException("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !"); } } - public static void passwordValid(String password) throws ParserError{ + public static void passwordValid(String password) throws ParserException { if(password.length() < 4){ - throw new ParserError("Password too short! Min length is 4 characters."); + throw new ParserException("Password too short! Min length is 4 characters."); } if(password.length() > 40){ - throw new ParserError("Password too long! Max length is 40 characters."); + throw new ParserException("Password too long! Max length is 40 characters."); } Pattern pat = Pattern.compile("[^a-z0-9_-]", Pattern.CASE_INSENSITIVE); Matcher mat = pat.matcher(password); boolean result = mat.find(); if(result){ - throw new ParserError("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !"); + throw new ParserException("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !"); } } - public static void mapNameValid(String mapName) throws ParserError{ + public static void mapNameValid(String mapName) throws ParserException { if(mapName.length() < 4){ - throw new ParserError("Map-Name too short! Min length is 4 characters."); + throw new ParserException("Map-Name too short! Min length is 4 characters."); } if(mapName.length() > 30){ - throw new ParserError("Map-Name too long! Max length is 30 characters."); + throw new ParserException("Map-Name too long! Max length is 30 characters."); } Pattern pat = Pattern.compile("[^a-z0-9_-]", Pattern.CASE_INSENSITIVE); Matcher mat = pat.matcher(mapName); boolean result = mat.find(); if(result){ - throw new ParserError("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !"); + throw new ParserException("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !"); } } - public static void mapIDValid(String mapID) throws ParserError{ + public static void mapIDValid(String mapID) throws ParserException { if(!(mapID.length() == 40)){ - throw new ParserError("Map-ID length not correct. Must have length of 40 characters!"); + throw new ParserException("Map-ID length not correct. Must have length of 40 characters!"); } Pattern pat = Pattern.compile("[^a-f0-9]"); //maybe make case-insensitive -> letters can be uppercase and still be valid hex number Matcher mat = pat.matcher(mapID); boolean result = mat.find(); if(result){ - throw new ParserError("Forbidden characters used! Map ID only consists out of letters a-f and/or numbers 0-9!"); + throw new ParserException("Forbidden characters used! Map ID only consists out of letters a-f and/or numbers 0-9!"); } } - public static void ipAddressValid(String address) throws ParserError{ + public static void ipAddressValid(String address) throws ParserException { if(address.length() > 15){ - throw new ParserError("IP-Address too long. Must have length of 15 characters including octet dividers (.) !"); + throw new ParserException("IP-Address too long. Must have length of 15 characters including octet dividers (.) !"); } if(address.length() < 7){ - throw new ParserError("IP-Address too short. Must have length of 7 characters including octet dividers (.) !"); + throw new ParserException("IP-Address too short. Must have length of 7 characters including octet dividers (.) !"); } if(address.charAt(0) == '.' | address.charAt(address.length()-1) == '.'){ - throw new ParserError("IP-Address must not start nor end with octet dividers (.) !"); + throw new ParserException("IP-Address must not start nor end with octet dividers (.) !"); } int counter = 0; @@ -102,7 +102,7 @@ public class Parser { } } if(!(counter == 3)){ - throw new ParserError("IP-Address must contain exactly 3 octet dividers (.) !"); + throw new ParserException("IP-Address must contain exactly 3 octet dividers (.) !"); } Pattern pat = Pattern.compile("[^0-9]"); @@ -111,7 +111,7 @@ public class Parser { Matcher mat = pat.matcher(address.substring(i, i+1)); boolean result = mat.find(); if(result){ - throw new ParserError("IP address does not consist out of numbers 0-9 and separators (.))!"); + throw new ParserException("IP address does not consist out of numbers 0-9 and separators (.))!"); } } } @@ -128,7 +128,7 @@ public class Parser { } for(int i = 0; 4 > i; i++){ if(Integer.parseInt(address.substring(positions[i], positions[i+1])) > 255){ - throw new ParserError("Octets of IP-address must not exceed 255!"); + throw new ParserException("Octets of IP-address must not exceed 255!"); } if(i < 3) { positions[i + 1] = positions[i + 1] + 1; @@ -136,54 +136,54 @@ public class Parser { } } - public static void mapDataValid(String mapData) throws ParserError{ + public static void mapDataValid(String mapData) throws ParserException { if(!(mapData.length() == 647)){ - throw new ParserError("Map-Data corrupted - must have length of 647 chars including spaces!"); + throw new ParserException("Map-Data corrupted - must have length of 647 chars including spaces!"); } for(int i = 1; i < 647; i = i + 2){ if(!(mapData.charAt(i) == ' ')){ - throw new ParserError("Map-Data corrupted - must use space every other character!"); + throw new ParserException("Map-Data corrupted - must use space every other character!"); } } for(int i = 0; i < 647; i = i + 2){ if((Integer.parseInt(mapData.substring(i, i+1)) > 4) | (Integer.parseInt(mapData.substring(i, i+1)) <= 0)){ - throw new ParserError("Map-Data corrupted - Tile number must be between 1 and 4!"); + throw new ParserException("Map-Data corrupted - Tile number must be between 1 and 4!"); } } for(int i = 0; i < 18; i = i + 2){ if(!(Integer.parseInt(mapData.substring(i, i+1)) == 3)){ - throw new ParserError("Map-Data corrupted - Top-Line must be border tiles!"); + throw new ParserException("Map-Data corrupted - Top-Line must be border tiles!"); } } for(int i = 628; i < 647; i = i + 2){ if(!(Integer.parseInt(mapData.substring(i, i+1)) == 3)){ - throw new ParserError("Map-Data corrupted - Bottom-Line must be border tiles!"); + throw new ParserException("Map-Data corrupted - Bottom-Line must be border tiles!"); } } for(int i = 0; i < 647; i = i + 2){ if(i % 36 == 0 && !(Integer.parseInt(mapData.substring(i, i+1)) == 3)){ - throw new ParserError("Map-Data corrupted - Left Edge must be border tiles!"); + throw new ParserException("Map-Data corrupted - Left Edge must be border tiles!"); } } for(int i = 2; i < 647; i = i + 2){ if(i % 36 == 0 && !(Integer.parseInt(mapData.substring(i-2, i-1)) == 3)){ - throw new ParserError("Map-Data corrupted - Right Edge must be border tiles!"); + throw new ParserException("Map-Data corrupted - Right Edge must be border tiles!"); } } if(!(Integer.parseInt(mapData.substring(38, 39)) == 1) | !(Integer.parseInt(mapData.substring(68, 69)) == 1)){ - throw new ParserError("Map-Data corrupted - Player spawn must use walkable tile!"); + throw new ParserException("Map-Data corrupted - Player spawn must use walkable tile!"); } if(!(Integer.parseInt(mapData.substring(578, 579)) == 1) | !(Integer.parseInt(mapData.substring(608, 609)) == 1)){ - throw new ParserError("Map-Data corrupted - Player spawn must use walkable tile!"); + throw new ParserException("Map-Data corrupted - Player spawn must use walkable tile!"); } } diff --git a/src/main/resources/database/AzureDB_logindetails b/src/main/resources/database/AzureDB_logindetails index 11cffc1152b19a4766475c01b85b0325c973d29b..88e4927a50d6dbc1bdf561cf31ab96067cc6286c 100644 --- a/src/main/resources/database/AzureDB_logindetails +++ b/src/main/resources/database/AzureDB_logindetails @@ -1,2 +1 @@ -ŠÑz°ÜèÑ%ëˆ\<ÜÁ$û,wso© -»CÊÀw‹ÂØmZ\xf*:Ndˆáa?Áå \ No newline at end of file +��z����%�\<��$�d<iA�pA5��ś]\&q<��#����ߤVr \ No newline at end of file diff --git a/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java index 2dda41fae4441462b03eb16c1cb10517373b2b18..77b58ca19bf2c61744cec92ae08944c88a7b8315 100644 --- a/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java +++ b/src/test/java/de/hdm_stuttgart/battlearena/Model/DataStorage/Classes/Utilities/ParserTest.java @@ -1,6 +1,6 @@ package de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Utilities; -import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.ParserError; +import de.hdm_stuttgart.battlearena.Model.DataStorage.Classes.Exceptions.ParserException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -19,13 +19,13 @@ class ParserTest { @Test void usernameValidException() { - ParserError testMe = assertThrows(ParserError.class, () -> Parser.usernameValid("hi")); + ParserException testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("hi")); assertTrue(testMe.getMessage().contains("Username too short! Min length is 4 characters.")); - testMe = assertThrows(ParserError.class, () -> Parser.usernameValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); assertTrue(testMe.getMessage().contains("Username too long! Max length is 40 characters.")); - testMe = assertThrows(ParserError.class, () -> Parser.usernameValid("SELECT * FROM")); + testMe = assertThrows(ParserException.class, () -> Parser.usernameValid("SELECT * FROM")); assertTrue(testMe.getMessage().contains("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !")); } @@ -39,13 +39,13 @@ class ParserTest { @Test void passwordValidException() { - ParserError testMe = assertThrows(ParserError.class, () -> Parser.passwordValid("hi")); + ParserException testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("hi")); assertTrue(testMe.getMessage().contains("Password too short! Min length is 4 characters.")); - testMe = assertThrows(ParserError.class, () -> Parser.passwordValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); assertTrue(testMe.getMessage().contains("Password too long! Max length is 40 characters.")); - testMe = assertThrows(ParserError.class, () -> Parser.passwordValid("SELECT * FROM")); + testMe = assertThrows(ParserException.class, () -> Parser.passwordValid("SELECT * FROM")); assertTrue(testMe.getMessage().contains("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !")); } @@ -59,13 +59,13 @@ class ParserTest { @Test void mapNameValidException() { - ParserError testMe = assertThrows(ParserError.class, () -> Parser.mapNameValid("hi")); + ParserException testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("hi")); assertTrue(testMe.getMessage().contains("Map-Name too short! Min length is 4 characters.")); - testMe = assertThrows(ParserError.class, () -> Parser.mapNameValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); assertTrue(testMe.getMessage().contains("Map-Name too long! Max length is 30 characters.")); - testMe = assertThrows(ParserError.class, () -> Parser.mapNameValid("SELECT * FROM")); + testMe = assertThrows(ParserException.class, () -> Parser.mapNameValid("SELECT * FROM")); assertTrue(testMe.getMessage().contains("Forbidden characters used! Only user letters A-Z or numbers 0-9 or symbols '-' or '_' !")); } @@ -80,10 +80,10 @@ class ParserTest { @Test void mapIDValidException() { - ParserError testMe = assertThrows(ParserError.class, () -> Parser.mapIDValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); + ParserException testMe = assertThrows(ParserException.class, () -> Parser.mapIDValid("jiaodjidsfjoisjdiofjsiofjidosfijsodfjisdfjoi")); assertTrue(testMe.getMessage().contains("Map-ID length not correct. Must have length of 40 characters!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapIDValid("XYZ3cafd1d061f0f463a2d2051bf4718aaaf5c48")); + testMe = assertThrows(ParserException.class, () -> Parser.mapIDValid("XYZ3cafd1d061f0f463a2d2051bf4718aaaf5c48")); assertTrue(testMe.getMessage().contains("Forbidden characters used! Map ID only consists out of letters a-f and/or numbers 0-9!")); } @@ -98,22 +98,22 @@ class ParserTest { @Test void ipAddressValidException() { - ParserError testMe = assertThrows(ParserError.class, () -> Parser.ipAddressValid("255.255.255.255.255.255")); + ParserException testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("255.255.255.255.255.255")); assertTrue(testMe.getMessage().contains("IP-Address too long. Must have length of 15 characters including octet dividers (.) !")); - testMe = assertThrows(ParserError.class, () -> Parser.ipAddressValid("0.0.0")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("0.0.0")); assertTrue(testMe.getMessage().contains("IP-Address too short. Must have length of 7 characters including octet dividers (.) !")); - testMe = assertThrows(ParserError.class, () -> Parser.ipAddressValid(".25.255.25.")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid(".25.255.25.")); assertTrue(testMe.getMessage().contains("IP-Address must not start nor end with octet dividers (.) !")); - testMe = assertThrows(ParserError.class, () -> Parser.ipAddressValid("12.3.0.12.12")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("12.3.0.12.12")); assertTrue(testMe.getMessage().contains("IP-Address must contain exactly 3 octet dividers (.) !")); - testMe = assertThrows(ParserError.class, () -> Parser.ipAddressValid("255.ff.12.12")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("255.ff.12.12")); assertTrue(testMe.getMessage().contains("IP address does not consist out of numbers 0-9 and separators (.))!")); - testMe = assertThrows(ParserError.class, () -> Parser.ipAddressValid("2555.800.12.12")); + testMe = assertThrows(ParserException.class, () -> Parser.ipAddressValid("2555.800.12.12")); assertTrue(testMe.getMessage().contains("Octets of IP-address must not exceed 255!")); } @@ -127,37 +127,37 @@ class ParserTest { @Test void mapDataValidException() { - ParserError testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("hi")); + ParserException testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("hi")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - must have length of 647 chars including spaces!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("3 3 3 3 3a3a3a3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3a3a3a3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - must use space every other character!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("3 3 3 8 9 7 7 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 8 9 7 7 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Tile number must be between 1 and 4!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("3 3 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Top-Line must be border tiles!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 1 1 1 1 1 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1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3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Left Edge must be border tiles!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 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 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Right Edge must be border tiles!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3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.getMessage().contains("Map-Data corrupted - Player spawn must use walkable tile!")); - testMe = assertThrows(ParserError.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); + testMe = assertThrows(ParserException.class, () -> Parser.mapDataValid("3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3")); assertTrue(testMe.getMessage().contains("Map-Data corrupted - Player spawn must use walkable tile!")); }