Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* #1897 fix copy and paste of own players in transfer scout

* #1897 fix copy and paste of own players in transfer scout

---------

Co-authored-by: Sébastien Le Callonnec <[email protected]>
  • Loading branch information
wsbrenk and tychobrailleur authored Nov 19, 2023
1 parent 592890b commit 23aad23
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 51 deletions.
84 changes: 47 additions & 37 deletions src/main/java/module/transfer/scout/PlayerConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,17 @@ public final Player buildHTCopyButton(String text) {
Mindestgebot: [money]0[/money]
*/

// text block contains 17 lines, when specialty is given, otherwise one less (16)
// if copied from transfer market, the text block contains 17 lines, when specialty is given, otherwise one less (16)
// line index of all pending lines has to be reduced by one, when specialty line is missing
int offsSpeciality = rows.size() - 17;
// if copied from own players the last both lines (deadline on price) are not given
int offsSpeciality = switch (rows.size()){
case 17 -> 0;
case 16 -> -1;
case 15 -> 0;
case 14 -> -1;
default -> throw new IllegalStateException("Unexpected rows count: " + rows.size());
};

// Set index rows
int indexRowNamePlayerId = 0;
int indexRowAge = 1;
Expand All @@ -275,15 +283,15 @@ public final Player buildHTCopyButton(String text) {
// Player Name
sc.useDelimiter("\\[playerid=");
txtTmp = new StringBuilder(sc.next().trim());
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setPlayerName(txtTmp.toString());
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.id"));
}
// Player Id
sc.useDelimiter("\\]");
txtTmp = new StringBuilder(sc.next().trim().substring(10));
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setPlayerID(Integer.parseInt(txtTmp.toString()));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.name"));
Expand All @@ -294,7 +302,7 @@ public final Player buildHTCopyButton(String text) {
sc = new Scanner(row);
sc.useDelimiter(" ");
txtTmp = new StringBuilder(sc.next().trim());
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setAge(Integer.parseInt(txtTmp.toString()));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.age"));
Expand All @@ -308,7 +316,7 @@ public final Player buildHTCopyButton(String text) {
sc.next();
}
}
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setAgeDays(Integer.parseInt(txtTmp.toString()));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("s.player.age.days"));
Expand Down Expand Up @@ -391,7 +399,7 @@ public final Player buildHTCopyButton(String text) {
c = sc.next();
}
}
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setTSI(Integer.parseInt(txtTmp.toString()));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.tsi"));
Expand Down Expand Up @@ -431,7 +439,7 @@ public final Player buildHTCopyButton(String text) {
}
}
}
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setBooked(row.trim());
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.warningstatus"));
Expand All @@ -451,7 +459,7 @@ public final Player buildHTCopyButton(String text) {
}
}
}
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setInjury(Integer.parseInt(txtTmp.toString()));
}
//Form and Stamina
Expand All @@ -471,7 +479,7 @@ public final Player buildHTCopyButton(String text) {
}
}
}
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setForm(Integer.parseInt(txtTmp.toString()));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.form"));
Expand All @@ -489,7 +497,7 @@ public final Player buildHTCopyButton(String text) {
}
}
}
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
player.setStamina(Integer.parseInt(txtTmp.toString()));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.skill.stamina"));
Expand All @@ -507,22 +515,24 @@ public final Player buildHTCopyButton(String text) {
player.setAttack(scanSkill(sc, HOVerwaltung.instance().getLanguageString("ls.player.skill.scoring")));
player.setSetPieces(scanSkill(sc, HOVerwaltung.instance().getLanguageString("ls.player.skill.setpieces")));

// scan deadline
row = rows.get(indexRowDeadline);
String deadlineString = getDeadlineString(row);
try {
player.setExpiryDate(new HODateTime(
new SimpleDateFormat("ddMMyyyyHHmm")
.parse(deadlineString)
.toInstant()
));
} catch (ParseException e) {
HOLogger.instance().warning(PlayerConverter.class, "Error parsing deadline date: " + e.getMessage());
}
if ( rows.size() > indexRowDeadline) {
// scan deadline
row = rows.get(indexRowDeadline);
String deadlineString = getDeadlineString(row);
try {
player.setExpiryDate(new HODateTime(
new SimpleDateFormat("ddMMyyyyHHmm")
.parse(deadlineString)
.toInstant()
));
} catch (ParseException e) {
HOLogger.instance().warning(PlayerConverter.class, "Error parsing deadline date: " + e.getMessage());
}

row = rows.get(indexRoxPrice);
var price = scanMoney(row);
if ( price != null) player.setPrice(price);
row = rows.get(indexRoxPrice);
var price = scanMoney(row);
if (price != null) player.setPrice(price);
}
return player;
}

Expand All @@ -540,7 +550,7 @@ private int scanSkill(Scanner sc, String languageString) {
}
}
}
if (!txtTmp.toString().equals("")) {
if (!txtTmp.toString().isEmpty()) {
return Integer.parseInt(txtTmp.toString());
} else {
addErrorField(languageString);
Expand Down Expand Up @@ -640,7 +650,7 @@ public final Player buildClassicPage(String text) {
}

// If we detected some possible player
if (!feed.equals("")) {
if (!feed.isEmpty()) {
//
// We start reformating given input here and extracting
// only needed lines for player detection
Expand All @@ -656,7 +666,7 @@ public final Player buildClassicPage(String text) {
startFound = true;
}

if (!tmp.equals("") && startFound) {
if (!tmp.isEmpty() && startFound) {
lines.add(tmp);
}

Expand Down Expand Up @@ -717,7 +727,7 @@ public final Player buildClassicPage(String text) {
p++;
}

if (!age.equals("")) {
if (!age.isEmpty()) {
player.setAge(Integer.parseInt(age));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.age"));
Expand Down Expand Up @@ -754,7 +764,7 @@ public final Player buildClassicPage(String text) {
p++;
}

if (!ageDays.equals("")) {
if (!ageDays.isEmpty()) {
player.setAgeDays(Integer.parseInt(ageDays));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.age.days"));
Expand Down Expand Up @@ -810,7 +820,7 @@ public final Player buildClassicPage(String text) {
p++;
}

if (!tsi.toString().equals("")) {
if (!tsi.toString().isEmpty()) {
player.setTSI(Integer.parseInt(tsi.toString()));
} else {
addErrorField(HOVerwaltung.instance().getLanguageString("ls.player.tsi"));
Expand All @@ -836,7 +846,7 @@ public final Player buildClassicPage(String text) {
} else break;
p++;
}
if (!wage.equals("") && Integer.parseInt(wage) >= 500) {
if (!wage.isEmpty() && Integer.parseInt(wage) >= 500) {
found_at_line++;
}
//player.setBaseWage(i);
Expand All @@ -860,7 +870,7 @@ public final Player buildClassicPage(String text) {
}
}

if (!injury.equals("")) {
if (!injury.isEmpty()) {
player.setInjury(Integer.parseInt(injury));
}
} catch (Exception e) { /* ignore */ }
Expand Down Expand Up @@ -934,7 +944,7 @@ public final Player buildClassicPage(String text) {
while (k < tmp.length()) {
if ((tmp.charAt(k) >= '0') && (tmp.charAt(k) <= '9')) {
curbid.append(tmp.charAt(k));
} else if ((tmp.charAt(k) != ' ') && curbid.length()>0) { // avoid to add numbers from bidding team names
} else if ((tmp.charAt(k) != ' ') && !curbid.isEmpty()) { // avoid to add numbers from bidding team names
break;
}

Expand Down Expand Up @@ -1119,7 +1129,7 @@ public final Player buildClassicPage(String text) {
p--;
}

if (foundspecialities.size() > 0) {
if (!foundspecialities.isEmpty()) {
player.setSpeciality(specialitiesvalues.get((Integer) (foundspecialities.get(0)).get(2)));
} else {
player.setSpeciality(0);
Expand Down Expand Up @@ -1173,7 +1183,7 @@ public static int getPrice(String bid, String curbid) {
int price = 0;
try {
price = Integer.parseInt(bid);
if (curbid.length()>0 && Integer.parseInt(curbid) >= Integer.parseInt(bid)) {
if (!curbid.isEmpty() && Integer.parseInt(curbid) >= Integer.parseInt(bid)) {
price = Integer.parseInt(curbid);
}
} catch (Exception e) { /* nothing */ }
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/module/transfer/scout/TransferEingabePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,31 +485,31 @@ private void copyPaste() {
jtfName.setText(player.getPlayerName());
jtfAge.setText(player.getAge() + "." + player.getAgeDays());

jtfPrice.setText(formatCurrency(player.getPrice()/UserParameter.instance().FXrate));
jtfWage.setText(formatCurrency(player.getBaseWage()/UserParameter.instance().FXrate));
jtfPrice.setText(formatCurrency(player.getPrice() / UserParameter.instance().FXrate));
jtfWage.setText(formatCurrency(player.getBaseWage() / UserParameter.instance().FXrate));
jtfTSI.setText(String.valueOf(player.getTSI()));
jtaNotes.setText(player.getInfo());

jcbSpeciality.removeItemListener(this);
Helper.setComboBoxFromID(jcbSpeciality,player.getSpeciality());
Helper.setComboBoxFromID(jcbSpeciality, player.getSpeciality());
jcbSpeciality.addItemListener(this);
jcbExperience.removeItemListener(this);
Helper.setComboBoxFromID(jcbExperience,player.getExperience());
Helper.setComboBoxFromID(jcbExperience, player.getExperience());
jcbExperience.addItemListener(this);
jcbForm.removeItemListener(this);
Helper.setComboBoxFromID(jcbForm, player.getForm());
jcbForm.addItemListener(this);
jcbStamina.removeItemListener(this);
Helper.setComboBoxFromID(jcbStamina,player.getStamina());
Helper.setComboBoxFromID(jcbStamina, player.getStamina());
jcbStamina.addItemListener(this);
jcbDefending.removeItemListener(this);
Helper.setComboBoxFromID(jcbDefending,player.getDefense());
Helper.setComboBoxFromID(jcbDefending, player.getDefense());
jcbDefending.addItemListener(this);
jcbScoring.removeItemListener(this);
Helper.setComboBoxFromID(jcbScoring, player.getAttack());
jcbScoring.addItemListener(this);
jcbKeeper.removeItemListener(this);
Helper.setComboBoxFromID(jcbKeeper,player.getGoalKeeping());
Helper.setComboBoxFromID(jcbKeeper, player.getGoalKeeping());
jcbKeeper.addItemListener(this);
jcbWinger.removeItemListener(this);
Helper.setComboBoxFromID(jcbWinger, player.getWing());
Expand All @@ -518,29 +518,33 @@ private void copyPaste() {
Helper.setComboBoxFromID(jcbPassing, player.getPassing());
jcbPassing.addItemListener(this);
jcbSetPieces.removeItemListener(this);
Helper.setComboBoxFromID(jcbSetPieces,player.getSetPieces());
Helper.setComboBoxFromID(jcbSetPieces, player.getSetPieces());
jcbSetPieces.addItemListener(this);
jcbLoyalty.removeItemListener(this);
Helper.setComboBoxFromID(jcbLoyalty,player.getLoyalty());
Helper.setComboBoxFromID(jcbLoyalty, player.getLoyalty());
jcbLoyalty.addItemListener(this);
jcbLeadership.removeItemListener(this);
Helper.setComboBoxFromID(jcbLeadership,player.getLeadership());
Helper.setComboBoxFromID(jcbLeadership, player.getLeadership());
jcbLeadership.addItemListener(this);
jchHomegrown.removeItemListener(this);
jchHomegrown.setSelected(player.isHomwGrown());
jchHomegrown.addItemListener(this);

// Listener stays here for recalculation of rating
Helper.setComboBoxFromID(jcbPlaymaking,player.getPlayMaking());
Helper.setComboBoxFromID(jcbPlaymaking, player.getPlayMaking());

// Normally not working. Thus last positioned
var deadline =player.getExpiryDate();
jsSpinner.setValue(Date.from(deadline.instant));
var deadline = player.getExpiryDate();
if (deadline != null) {
jsSpinner.setValue(Date.from(deadline.instant));
} else {
jsSpinner.setValue(null);
}

setLabels();
}
} catch (Exception e) {
HOLogger.instance().debug(getClass(), e);
HOLogger.instance().debug(getClass(), e);
message = HOVerwaltung.instance().getLanguageString("scout_error");
message += " <br>" + HOVerwaltung.instance().getLanguageString("bug_ticket");
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
### Statistics

### Transfer
* fix transfer scout's copy and paste of own players (#1897)

### Training

Expand All @@ -37,6 +38,7 @@

## Translations


Reports by Contributors - September 24, 2023 - October 21, 2023

* Georgi 10
Expand Down

0 comments on commit 23aad23

Please sign in to comment.