diff --git a/src/main/java/core/db/DBUpdater.java b/src/main/java/core/db/DBUpdater.java index 107948963..39f1968d2 100644 --- a/src/main/java/core/db/DBUpdater.java +++ b/src/main/java/core/db/DBUpdater.java @@ -85,6 +85,7 @@ void updateDB(int DBVersion) { private void updateDBv800(int dbVersion) throws SQLException { var playerTable = dbManager.getTable(SpielerTable.TABLENAME); playerTable.tryAddColumn("LineupDisabled", "BOOLEAN"); + playerTable.tryAddColumn("ContractDate", "VARCHAR(100)"); playerTable.tryChangeColumn("OwnerNotes", "VARCHAR(512)"); updateDBVersion(dbVersion, 800); } diff --git a/src/main/java/core/db/SpielerTable.java b/src/main/java/core/db/SpielerTable.java index 0136c7e11..a2d6bd9fc 100644 --- a/src/main/java/core/db/SpielerTable.java +++ b/src/main/java/core/db/SpielerTable.java @@ -93,7 +93,8 @@ protected void initColumns() { ColumnDescriptor.Builder.newInstance().setColumnName("MotherclubId").setGetter((p)->((Player)p).getOrDownloadMotherclubId()).setSetter((p, v)->((Player)p).setMotherClubId((Integer) v)).setType(Types.INTEGER).isNullable(true).build(), ColumnDescriptor.Builder.newInstance().setColumnName("MotherclubName").setGetter((p)->((Player)p).getOrDownloadMotherclubName()).setSetter((p, v)->((Player)p).setMotherClubName((String)v)).setType(Types.VARCHAR).isNullable(true).setLength(255).build(), ColumnDescriptor.Builder.newInstance().setColumnName("MatchesCurrentTeam").setGetter((p)->((Player)p).getMatchesCurrentTeam()).setSetter((p,v)->((Player)p).setMatchesCurrentTeam((Integer) v)).setType(Types.INTEGER).isNullable(true).build(), - ColumnDescriptor.Builder.newInstance().setColumnName("LineupDisabled").setGetter((p)->((Player)p).isLineupDisabled()).setSetter((p,v)->((Player)p).setLineupDisabled((Boolean) v)).setType(Types.BOOLEAN).isNullable(true).build() + ColumnDescriptor.Builder.newInstance().setColumnName("LineupDisabled").setGetter((p)->((Player)p).isLineupDisabled()).setSetter((p,v)->((Player)p).setLineupDisabled((Boolean) v)).setType(Types.BOOLEAN).isNullable(true).build(), + ColumnDescriptor.Builder.newInstance().setColumnName("ContractDate").setGetter((p)->((Player)p).getContractDate()).setSetter((p,v)->((Player)p).setContractDate((String)v)).setType(Types.VARCHAR).isNullable(true).setLength(100).build() }; } diff --git a/src/main/java/core/file/hrf/HRFStringBuilder.java b/src/main/java/core/file/hrf/HRFStringBuilder.java index 8d873ef25..7717d4d09 100644 --- a/src/main/java/core/file/hrf/HRFStringBuilder.java +++ b/src/main/java/core/file/hrf/HRFStringBuilder.java @@ -21,7 +21,6 @@ import module.training.Skills; import module.youth.YouthPlayer; import org.apache.commons.lang3.math.NumberUtils; - import java.util.List; import java.util.Map; @@ -274,7 +273,7 @@ public void createLastLineUp(MatchLineupTeam matchLineupTeam, Map pla var firstName = ht.get("FirstName"); var lastName = ht.get("LastName"); var nickName = ht.get("NickName"); - if (nickName.length() > 0) { + if (!nickName.isEmpty()) { appendKeyValue(playersStringBuilder, "name", firstName + " '" + nickName + "' " + lastName); } else { appendKeyValue(playersStringBuilder, "name", firstName + " " + lastName); @@ -462,7 +461,10 @@ public void createPlayers(MatchLineupTeam matchLineupTeam, List pla appendKeyValue(playersStringBuilder, "AggressivenessLabel", PlayerAggressiveness.toString(Integer.parseInt(ht.get("Aggressiveness")))); appendKeyValue(playersStringBuilder, "TrainerType", ht.get("TrainerType")); - appendKeyValue(playersStringBuilder, "TrainerSkill", ht.get("TrainerSkill")); + appendKeyValue(playersStringBuilder, "ContractDate", ht.get("ContractDate")); + appendKeyValue(playersStringBuilder, "Cost", ht.get("Cost")); + appendKeyValue(playersStringBuilder, "TrainerSkillLevel", ht.get("TrainerSkillLevel")); + appendKeyValue(playersStringBuilder, "TrainerStatus", ht.get("TrainerStatus")); appendKeyValue(playersStringBuilder, "LastMatch_Date", ht.get("LastMatch_Date")); appendKeyValue(playersStringBuilder, "LastMatch_Rating", ht.get("LastMatch_Rating")); @@ -671,7 +673,7 @@ private static String getPlayerOrderForNextLineup(String position, if (ret != null) { ret = ret.trim(); - if (!"null".equals(ret) && !"".equals(ret)) { + if (!"null".equals(ret) && !ret.isEmpty()) { return ret.trim(); } } diff --git a/src/main/java/core/file/xml/ConvertXml2Hrf.java b/src/main/java/core/file/xml/ConvertXml2Hrf.java index 1a2bf92da..3617ab629 100644 --- a/src/main/java/core/file/xml/ConvertXml2Hrf.java +++ b/src/main/java/core/file/xml/ConvertXml2Hrf.java @@ -13,6 +13,7 @@ import core.model.HOVerwaltung; import core.model.match.*; import core.model.player.PlayerAvatar; +import core.model.player.TrainerStatus; import core.net.OnlineWorker; import core.util.Helper; import core.module.config.ModuleConfig; @@ -62,9 +63,9 @@ private ConvertXml2Hrf() { // user has only one single team teamId = teamInfoList.get(0).getTeamId(); youthTeamId = teamInfoList.get(0).getYouthTeamId(); - } else if (teamInfoList.size() >= 2){ + } else if (teamInfoList.size() >= 2) { // user has more than one team - if ( teamId <=0) { + if (teamId <= 0) { // Select one of user's teams, if not done before CursorToolkit.stopWaitCursor(HOMainFrame.instance().getRootPane()); TeamSelectionDialog selection = new TeamSelectionDialog(HOMainFrame.instance(), teamInfoList); @@ -74,15 +75,14 @@ private ConvertXml2Hrf() { } teamId = selection.getSelectedTeam().getTeamId(); youthTeamId = selection.getSelectedTeam().getYouthTeamId(); - } - else { + } else { // team id is in DB and this is the first time we download youth team information int finalTeamId = teamId; var teaminfo = teamInfoList.stream() .filter(x -> x.getTeamId() == finalTeamId) .findAny() .orElse(null); - if ( teaminfo != null){ + if (teaminfo != null) { youthTeamId = teaminfo.getYouthTeamId(); } } @@ -110,8 +110,8 @@ private ConvertXml2Hrf() { // Currency fix var lastPremierId = ModuleConfig.instance().getInteger("UsersPremierTeamId"); - if ( lastPremierId != null && lastPremierId == usersPremierTeamId ){ - //if (ModuleConfig.instance().containsKey("CurrencyRate")) { + if (lastPremierId != null && lastPremierId == usersPremierTeamId) { + //if (ModuleConfig.instance().containsKey("CurrencyRate")) { worldDataMap.put("CurrencyRate", ModuleConfig.instance().getString("CurrencyRate")); worldDataMap.put("CountryID", ModuleConfig.instance().getString("CountryId")); } else { @@ -126,29 +126,14 @@ private ConvertXml2Hrf() { HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.players_information"), progressIncrement); List playersData = new XMLPlayersParser().parsePlayersFromString(mc.downloadPlayers(teamId)); - var trainerId = String.valueOf(teamdetailsDataMap.get("TrainerID")); - // If trainer is not in players data, download trainer info from player details - var found = false; - for ( var p : playersData){ - if ( p.get("PlayerID").equals(trainerId)){ - found=true; - break; - } - } - if ( !found){ - var xml = MyConnector.instance().downloadPlayerDetails(trainerId); - var properties = new XMLPlayersParser().parsePlayerDetails(xml); - properties.put("LineupDisabled", "true"); - playersData.add(properties); - } // Download players' avatar HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.players_avatars"), progressIncrement); List playersAvatar = XMLAvatarsParser.parseAvatarsFromString(mc.getAvatars(teamId)); ThemeManager.instance().generateAllPlayerAvatar(playersAvatar, 1); - List youthplayers=null; - if ( youthTeamId != null && youthTeamId > 0 ){ + List youthplayers = null; + if (youthTeamId != null && youthTeamId > 0) { youthplayers = new XMLPlayersParser().parseYouthPlayersFromString(mc.downloadYouthPlayers(youthTeamId)); } HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.economy"), progressIncrement); @@ -159,6 +144,23 @@ private ConvertXml2Hrf() { HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.staff"), progressIncrement); List staffData = XMLStaffParser.parseStaffFromString(mc.getStaff(teamId)); + var trainer = staffData.get(0); + var trainerId = String.valueOf(trainer.get("TrainerId")); + if (trainer.containsKey("TrainerId")) { + var trainerStatus = TrainerStatus.fromInt(Integer.parseInt(trainer.get("TrainerStatus"))); + if (trainerStatus == TrainerStatus.PlayingTrainer){ + for (var p : playersData) { + if (p.get("PlayerID").equals(trainerId)) { + p.putAll(trainer); + break; + } + } + } + else { + trainer.put("LineupDisabled", "true"); + playersData.add(trainer); + } + } int arenaId = 0; try { @@ -172,7 +174,7 @@ private ConvertXml2Hrf() { HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.match_orders"), progressIncrement); List matches = XMLMatchesParser .parseMatchesFromString(mc.getMatches(Integer - .parseInt(teamdetailsDataMap.get("TeamID")), + .parseInt(teamdetailsDataMap.get("TeamID")), false, true)); HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.match_info"), progressIncrement); @@ -217,7 +219,7 @@ private ConvertXml2Hrf() { hrfSgtringBuilder.createPlayers(matchLineupTeam, playersData); // youth players - if ( youthplayers != null){ + if (youthplayers != null) { HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.create_youth_players"), progressIncrement); hrfSgtringBuilder.appendYouthPlayers(youthplayers); } @@ -236,10 +238,4 @@ private ConvertXml2Hrf() { return hrfSgtringBuilder.createHRF().toString(); } - - - // ////////////////////////////////////////////////////////////////////////////// - // Helper - // ////////////////////////////////////////////////////////////////////////////// - -} +} \ No newline at end of file diff --git a/src/main/java/core/file/xml/XMLStaffParser.java b/src/main/java/core/file/xml/XMLStaffParser.java index 216cc1664..c4ed171d4 100644 --- a/src/main/java/core/file/xml/XMLStaffParser.java +++ b/src/main/java/core/file/xml/XMLStaffParser.java @@ -7,52 +7,58 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import static core.file.xml.XMLManager.xmlValue2Hash; + public class XMLStaffParser { - - /** - * Utility class - private constructor enforces noninstantiability. - */ - private XMLStaffParser() { - } - - - public static List parseStaffFromString(String inputStream) { - Document doc = null; - doc = XMLManager.parseString(inputStream); - return createList(doc); - } - - private static List createList(Document doc) { - - final List returnList = new ArrayList(); - NodeList nodeList; - MyHashtable hash = null; - Element ele = null; - Element root = doc.getDocumentElement(); - - root = (Element) root.getElementsByTagName("StaffMembers").item(0); - nodeList = root.getElementsByTagName("Staff"); - - for (int i = 0; (nodeList != null) && (i < nodeList.getLength()); i++) { - hash = new MyHashtable(); - root = (Element) nodeList.item(i); - - ele = (Element) root.getElementsByTagName("Name").item(0); - hash.put("Name", (XMLManager.getFirstChildNodeValue(ele))); - ele = (Element) root.getElementsByTagName("StaffId").item(0); - hash.put("StaffId", (XMLManager.getFirstChildNodeValue(ele))); - ele = (Element) root.getElementsByTagName("StaffType").item(0); - hash.put("StaffType", (XMLManager.getFirstChildNodeValue(ele))); - ele = (Element) root.getElementsByTagName("StaffLevel").item(0); - hash.put("StaffLevel", (XMLManager.getFirstChildNodeValue(ele))); - ele = (Element) root.getElementsByTagName("Cost").item(0); - hash.put("Cost", (XMLManager.getFirstChildNodeValue(ele))); - - - returnList.add(hash); - - } - return returnList; - } + + /** + * Utility class - private constructor enforces noninstantiability. + */ + private XMLStaffParser() { + } + + + public static List parseStaffFromString(String inputStream) { + Document doc; + doc = XMLManager.parseString(inputStream); + return createList(doc); + } + + private static List createList(Document doc) { + + final List returnList = new ArrayList<>(); + NodeList nodeList; + MyHashtable hash; + Element root = doc.getDocumentElement(); + var trainer = (Element) root.getElementsByTagName("Trainer").item(0); + hash = new MyHashtable(); + xmlValue2Hash(hash, trainer, "TrainerId"); + xmlValue2Hash(hash, trainer, "Name"); + xmlValue2Hash(hash, trainer, "Age"); + xmlValue2Hash(hash, trainer, "AgeDays"); + xmlValue2Hash(hash, trainer, "ContractDate"); + xmlValue2Hash(hash, trainer, "Cost"); + xmlValue2Hash(hash, trainer, "CountryID"); + xmlValue2Hash(hash, trainer, "TrainerType"); + xmlValue2Hash(hash, trainer, "Leadership"); + xmlValue2Hash(hash, trainer, "TrainerSkillLevel"); + xmlValue2Hash(hash, trainer, "TrainerStatus"); + returnList.add(hash); + + root = (Element) root.getElementsByTagName("StaffMembers").item(0); + nodeList = root.getElementsByTagName("Staff"); + for (int i = 0; i < nodeList.getLength(); i++) { + hash = new MyHashtable(); + root = (Element) nodeList.item(i); + + xmlValue2Hash(hash, root, "Name"); + xmlValue2Hash(hash, root, "StaffId"); + xmlValue2Hash(hash, root, "StaffType"); + xmlValue2Hash(hash, root, "StaffLevel"); + xmlValue2Hash(hash, root, "Cost"); + returnList.add(hash); + } + return returnList; + } } diff --git a/src/main/java/core/model/player/Player.java b/src/main/java/core/model/player/Player.java index 775891852..49a01ec39 100644 --- a/src/main/java/core/model/player/Player.java +++ b/src/main/java/core/model/player/Player.java @@ -46,6 +46,19 @@ public class Player extends AbstractTable.Storable { */ private String m_arrivalDate; + public String getContractDate() { + return contractDate; + } + + public void setContractDate(String contractDate) { + this.contractDate = contractDate; + } + + /** + * Trainer contract date + */ + private String contractDate; + /** * Download date */ @@ -404,7 +417,12 @@ public Player(Properties properties, HODateTime hrfdate, int hrf_id) { this.lineupDisabled = getBooleanIfNotNull(properties, "lineupdisabled"); this.m_iBewertung = getIntegerIfNotNull(properties, "rating", 0); this.m_iTrainerTyp = TrainerType.fromInt(getIntegerIfNotNull(properties, "trainertype", -1)); - this.m_iTrainer = getIntegerIfNotNull(properties, "trainerskill", 0); + this.m_iTrainer = getIntegerIfNotNull(properties, "trainerskilllevel", 0); + if (this.m_iTrainer > 0) { + this.m_iTrainer+=3; // trainer level 5 is an excellent (8) trainer + m_iGehalt = Integer.parseInt(properties.getProperty("cost", "0")); + contractDate = properties.getProperty("contractdate"); + } var temp = properties.getProperty("playernumber", ""); if ((temp != null) && !temp.isEmpty() && !temp.equals("null")) { diff --git a/src/main/java/core/model/player/TrainerStatus.java b/src/main/java/core/model/player/TrainerStatus.java new file mode 100644 index 000000000..ce09f6264 --- /dev/null +++ b/src/main/java/core/model/player/TrainerStatus.java @@ -0,0 +1,36 @@ +package core.model.player; + +public enum TrainerStatus { + // 1 = PlayingTrainer, 2 = OnlyTrainer, 3 = HoFTrainer + PlayingTrainer(1), + OnlyTrainer(2), + HoFTrainer(3); + + private final int id; + + TrainerStatus(int i) { + this.id = i; + } + + public static TrainerStatus fromInt(Integer i){ + if ( i != null) { + return switch (i) { + case 1 -> PlayingTrainer; + case 2 -> OnlyTrainer; + case 3 -> HoFTrainer; + default -> null; + }; + } + return null; + } + + public static Integer toInteger(TrainerStatus trainerStatus) { + if ( trainerStatus != null) return trainerStatus.toInt(); + return null; + } + + public int toInt(){ + return this.id; + } + +} diff --git a/src/main/resources/release_notes.md b/src/main/resources/release_notes.md index fdc7729dc..5f9b7b8ac 100644 --- a/src/main/resources/release_notes.md +++ b/src/main/resources/release_notes.md @@ -36,9 +36,10 @@ ## Translations -Reports by Contributors - September 24, 2023 - October 02, 2023 +Reports by Contributors - September 24, 2023 - October 21, 2023 +* Georgi 10 * Lidegand 3 * wsbrenk 3 -Total 6 +Total 16