Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1927 #1935

Merged
merged 2 commits into from
Oct 26, 2023
Merged

#1927 #1935

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/core/db/DBUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/core/db/SpielerTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/core/file/hrf/HRFStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -274,7 +273,7 @@ public void createLastLineUp(MatchLineupTeam matchLineupTeam, Map<String, String
appendKeyValue(lastLineupStringBuilder, "subst"+i+"playerIn", sub.getObjectPlayerID());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"playerOut", sub.getSubjectPlayerID());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"orderType", (int) sub.getOrderType().getId());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"matchMinuteCriteria", (int) sub.getMatchMinuteCriteria());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"matchMinuteCriteria", sub.getMatchMinuteCriteria());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"pos", (int) sub.getRoleId());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"behaviour", (int) sub.getBehaviour());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"card", (int) sub.getRedCardCriteria().getId());
Expand Down Expand Up @@ -416,7 +415,7 @@ public void createPlayers(MatchLineupTeam matchLineupTeam, List<MyHashtable> 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);
Expand Down Expand Up @@ -462,7 +461,10 @@ public void createPlayers(MatchLineupTeam matchLineupTeam, List<MyHashtable> 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"));
Expand Down Expand Up @@ -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();
}
}
Expand Down
62 changes: 29 additions & 33 deletions src/main/java/core/file/xml/ConvertXml2Hrf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -126,29 +126,14 @@ private ConvertXml2Hrf() {

HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.players_information"), progressIncrement);
List<MyHashtable> 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<PlayerAvatar> playersAvatar = XMLAvatarsParser.parseAvatarsFromString(mc.getAvatars(teamId));
ThemeManager.instance().generateAllPlayerAvatar(playersAvatar, 1);

List<MyHashtable> youthplayers=null;
if ( youthTeamId != null && youthTeamId > 0 ){
List<MyHashtable> youthplayers = null;
if (youthTeamId != null && youthTeamId > 0) {
youthplayers = new XMLPlayersParser().parseYouthPlayersFromString(mc.downloadYouthPlayers(youthTeamId));
}
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.economy"), progressIncrement);
Expand All @@ -159,6 +144,23 @@ private ConvertXml2Hrf() {

HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.staff"), progressIncrement);
List<MyHashtable> 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 {
Expand All @@ -172,7 +174,7 @@ private ConvertXml2Hrf() {
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.match_orders"), progressIncrement);
List<MatchKurzInfo> 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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -236,10 +238,4 @@ private ConvertXml2Hrf() {

return hrfSgtringBuilder.createHRF().toString();
}


// //////////////////////////////////////////////////////////////////////////////
// Helper
// //////////////////////////////////////////////////////////////////////////////

}
}
98 changes: 52 additions & 46 deletions src/main/java/core/file/xml/XMLStaffParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyHashtable> parseStaffFromString(String inputStream) {
Document doc = null;
doc = XMLManager.parseString(inputStream);
return createList(doc);
}

private static List<MyHashtable> createList(Document doc) {

final List<MyHashtable> returnList = new ArrayList<MyHashtable>();
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<MyHashtable> parseStaffFromString(String inputStream) {
Document doc;
doc = XMLManager.parseString(inputStream);
return createList(doc);
}

private static List<MyHashtable> createList(Document doc) {

final List<MyHashtable> 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;
}
}
20 changes: 19 additions & 1 deletion src/main/java/core/model/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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")) {
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/core/model/player/TrainerStatus.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
5 changes: 3 additions & 2 deletions src/main/resources/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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