Skip to content

Commit

Permalink
ho-dev#1913 fix Player.getMotherclubId download recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbrenk committed Sep 8, 2023
1 parent b8ac12d commit d938e9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/core/gui/model/UserColumnFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ public IHOTableEntry getTableEntry(Player player, Player playerCompare) {
playerAdditionalArray[19] = new PlayerColumn(893, "ls.player.motherclub.name", 50) {
@Override
public IHOTableEntry getTableEntry(Player player, Player playerCompare) {
return new ColorLabelEntry(player.getMotherclubName(), ColorLabelEntry.FG_STANDARD, ColorLabelEntry.BG_STANDARD, SwingConstants.LEFT);
return new ColorLabelEntry(player.getOrDownloadMotherclubName(), ColorLabelEntry.FG_STANDARD, ColorLabelEntry.BG_STANDARD, SwingConstants.LEFT);
}
};

Expand Down
29 changes: 19 additions & 10 deletions src/main/java/core/model/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,19 @@ public Player(java.util.Properties properties, HODateTime hrfdate, int hrf_id) {

String temp = properties.getProperty("trainertype", "-1");

if ((temp != null) && !temp.equals("")) {
if ((temp != null) && !temp.isEmpty()) {
m_iTrainerTyp = TrainerType.fromInt(Integer.parseInt(temp));
}

temp = properties.getProperty("trainerskill", "0");

if ((temp != null) && !temp.equals("")) {
if ((temp != null) && !temp.isEmpty()) {
m_iTrainer = Integer.parseInt(temp);
}

temp = properties.getProperty("playernumber", "");

if ((temp != null) && !temp.equals("") && !temp.equals("null")) {
if ((temp != null) && !temp.isEmpty() && !temp.equals("null")) {
shirtNumber = Integer.parseInt(temp);
}

Expand Down Expand Up @@ -474,17 +474,17 @@ public Player(java.util.Properties properties, HODateTime hrfdate, int hrf_id) {
if (oldPlayer != null) {
// Training blocked (could be done in the past)
m_bTrainingBlock = oldPlayer.hasTrainingBlock();
motherclubId = oldPlayer.getMotherclubId();
motherclubName = oldPlayer.getMotherclubName();
motherclubId = oldPlayer.getOrDownloadMotherclubId();
motherclubName = oldPlayer.getOrDownloadMotherclubName();
}
}

public String getMotherclubName() {
public String getOrDownloadMotherclubName() {
downloadMotherclubInfoIfMissing();
return this.motherclubName;
}

public Integer getMotherclubId() {
public Integer getOrDownloadMotherclubId() {
downloadMotherclubInfoIfMissing();
return this.motherclubId;
}
Expand All @@ -498,6 +498,7 @@ private void downloadMotherclubInfoIfMissing() {
// try to download missing mother club info
var playerDetails = OnlineWorker.downloadPlayerDetails(String.valueOf(this.getPlayerID()));
if (playerDetails != null) {
// do not use download again since this could lead to endless recursion if the playerdetails file has errors
motherclubId = playerDetails.getMotherclubId();
motherclubName = playerDetails.getMotherclubName();
}
Expand All @@ -511,6 +512,14 @@ private void downloadMotherclubInfoIfMissing() {
}
}

private String getMotherclubName() {
return this.motherclubName;
}

private Integer getMotherclubId() {
return this.motherclubId;
}

//~ Methods ------------------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -2226,7 +2235,7 @@ public void setSubExperience( Double experience){
public List<FuturePlayerTraining> getFuturePlayerTrainings(){
if ( futurePlayerTrainings == null){
futurePlayerTrainings = DBManager.instance().getFuturePlayerTrainings(this.getPlayerID());
if (futurePlayerTrainings.size()>0) {
if (!futurePlayerTrainings.isEmpty()) {
var start = HOVerwaltung.instance().getModel().getBasics().getHattrickWeek();
var remove = new ArrayList<FuturePlayerTraining>();
for (var t : futurePlayerTrainings) {
Expand Down Expand Up @@ -2358,7 +2367,7 @@ public void calcSubskills(int previousID, List<TrainingPerWeek> trainingWeeks) {
var valueBeforeTraining = playerBefore.getValue4Skill(skill);
var valueAfterTraining = this.getValue4Skill(skill);

if (trainingWeeks.size() > 0) {
if (!trainingWeeks.isEmpty()) {
if ( valueAfterTraining > valueBeforeTraining) {
// Check if skill up is available
var skillUps = this.getAllLevelUp(skill);
Expand All @@ -2382,7 +2391,7 @@ public void calcSubskills(int previousID, List<TrainingPerWeek> trainingWeeks) {
sub += trainingPerPlayer.calcSubskillIncrement(skill, valueBeforeTraining + sub, training.getTrainingDate());
if (valueAfterTraining > valueBeforeTraining) {
if (sub > 1) {
sub -= 1.;
sub -= 1.F;
} else {
sub = 0.f;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bug fixes

### Squad
* fix display of wrong homegrown heart in player details (#1901)
* fix recursive download of mother club info. Handle chpp error in playerdetails file (#1913)

### Team Analyzer

Expand Down

0 comments on commit d938e9a

Please sign in to comment.