Skip to content

Commit

Permalink
fix bug in download lineup (#1852)
Browse files Browse the repository at this point in the history
Co-authored-by: wsbrenk <zissener-weg-brenk.de>
  • Loading branch information
wsbrenk committed Apr 16, 2023
1 parent 70eda80 commit 4cbd90d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/main/java/core/net/MyConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public String getRatingsPrediction(int matchId, int teamId, MatchType matchType)
* The match type connected to the match
* @return The api content (xml)
*/
public String getMatchOrder(int matchId, MatchType matchType, int teamId) {
public String downloadMatchOrder(int matchId, MatchType matchType, int teamId) {
String url = htUrl + "?file=matchorders&matchID=" + matchId + "&sourceSystem=" + matchType.getSourceString() + "&version=" + VERSION_MATCHORDERS;
if (!HOVerwaltung.instance().getModel().getBasics().isNationalTeam()) {
url += "&teamId=" + teamId;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/core/net/OnlineWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ public static MatchLineupTeam getLineupbyMatchId(int matchId, MatchType matchTyp

try {
var teamId = HOVerwaltung.instance().getModel().getBasics().getTeamId();
String xml = MyConnector.instance().getMatchOrder(matchId, matchType, teamId);
String xml = MyConnector.instance().downloadMatchOrder(matchId, matchType, teamId);

if (!StringUtils.isEmpty(xml)) {
Map<String, String> map = XMLMatchOrderParser.parseMatchOrderFromString(xml);
Expand Down Expand Up @@ -960,8 +960,7 @@ private static void saveHRFToFile(JDialog parent, String hrfData) {
file = askForHRFPath(parent, file);
}

if ((file != null)) {
file.getPath();
if (file != null) {
// Save Path
UserParameter.instance().hrfImport_HRFPath = file.getParentFile().getAbsolutePath();

Expand Down Expand Up @@ -1257,7 +1256,7 @@ public static Map<String, String> downloadNextMatchOrder(List<MatchKurzInfo> mat
var match = matches.stream().filter(f -> f.getMatchStatus() == MatchKurzInfo.UPCOMING).min(MatchKurzInfo::compareTo).get();
// Match is always from the normal system, and league will do
// the trick as the type.
return XMLMatchOrderParser.parseMatchOrderFromString(MyConnector.instance().getMatchOrder(
return XMLMatchOrderParser.parseMatchOrderFromString(MyConnector.instance().downloadMatchOrder(
match.getMatchID(), match.getMatchType(), teamId));
}
catch (Exception ignore) {
Expand Down
96 changes: 45 additions & 51 deletions src/main/java/module/lineup/Lineup.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import core.model.player.Player;
import core.rating.RatingPredictionManager;
import core.util.HOLogger;
import core.util.StringUtils;
import module.lineup.assistant.LineupAssistant;
import module.lineup.substitution.model.GoalDiffCriteria;
import module.lineup.substitution.model.MatchOrderType;
Expand Down Expand Up @@ -219,22 +220,22 @@ public Lineup(Properties properties) {
m_vBenchPositions.add(new MatchLineupPosition(IMatchRoleID.substXT2, Integer.parseInt(properties.getProperty("substxt2", "0")), (byte) 0));

var tactic = properties.getProperty("tactictype");
if (tactic == null || tactic.equals("null")) // to avoid exception when match is finish
if (StringUtils.isEmpty(tactic)|| tactic.equals("null")) // to avoid exception when match is finish
settings.m_iTacticType = 0;
else
settings.m_iTacticType = Integer.parseInt(tactic);

String attitude = properties.getProperty("installning", "0");
if (attitude.equals("null") || attitude.equals("")) // to avoid exception when match is finish
if (StringUtils.isEmpty(attitude) || attitude.equals("null") ) // to avoid exception when match is finish
settings.m_iAttitude = 0;
else
settings.m_iAttitude = Integer.parseInt(attitude);

var propStyleOfPlay = properties.getProperty("styleofplay");
if (propStyleOfPlay == null || properties.getProperty("styleofplay").equals("null")) // to avoid exception when match is finish
if (StringUtils.isEmpty(propStyleOfPlay) || propStyleOfPlay.equals("null")) // to avoid exception when match is finish
settings.m_iStyleOfPlay = 0;
else
settings.m_iStyleOfPlay = Integer.parseInt(properties.getProperty("styleofplay", "0"));
settings.m_iStyleOfPlay = Integer.parseInt(propStyleOfPlay);

// and read the sub contents
int iSub = 0;
Expand Down Expand Up @@ -603,11 +604,12 @@ public static String getNameForSystem(byte system) {
*/
public final byte getEffectivePos4PositionID(int positionsid) {
try {
return getPositionById(positionsid).getPosition();
var pos =getPositionById(positionsid);
if ( pos != null ) return pos.getPosition();
} catch (Exception e) {
HOLogger.instance().error(getClass(), "getEffectivePos4PositionID: " + e);
return IMatchRoleID.UNKNOWN;
}
return IMatchRoleID.UNKNOWN;
}

/**
Expand All @@ -634,7 +636,7 @@ public final void setArenaId(int id){
this.m_iArenaId=id;
}
public final int getArenaId() {
if (m_iArenaId == -1 && !isUpcomingMatchLoaded()) {
if (m_iArenaId == -1) {
getUpcomingMatch();
}
return m_iArenaId;
Expand Down Expand Up @@ -737,21 +739,22 @@ public final int getIntValue4Rating(double rating) {
*/
public Player getPlayerByPositionID(int positionId) {
try {
return HOVerwaltung.instance().getModel()
.getCurrentPlayer(getPositionById(positionId).getPlayerId());
var pos = getPositionById(positionId);
if ( pos != null ) return HOVerwaltung.instance().getModel().getCurrentPlayer(pos.getPlayerId());
} catch (Exception e) {
HOLogger.instance()
.error(getClass(), "getPlayerByPositionID(" + positionId + "): " + e);
return null;
}
return null;
}

public String tryGetPlayerNameByPositionID(int positionId) {
try {
return HOVerwaltung.instance().getModel().getCurrentPlayer(getPositionById(positionId).getPlayerId()).getShortName();
} catch (Exception e) {
return " ";
var player = getPlayerByPositionID(positionId);
if ( player != null) return player.getShortName();
} catch (Exception ignored) {
}
return " ";
}

public void printLineup() {
Expand Down Expand Up @@ -869,24 +872,17 @@ public final Vector<MatchLineupPosition> getFieldPositions(){

public Vector<MatchLineupPosition> getReplacedPositions(){return replacedPositions;}

public final Vector<MatchLineupPosition> getBenchPositions(){
return m_vBenchPositions;
}

/**
* Place a player to a certain position and check/solve dependencies.
*/
public final byte setSpielerAtPosition(int positionsid, int spielerid, byte tactic) {
public final void setSpielerAtPosition(int positionsid, int spielerid, byte tactic) {
final MatchLineupPosition pos = getPositionById(positionsid);

if (pos != null) {
setSpielerAtPosition(positionsid, spielerid);
pos.setTaktik(tactic);

return pos.getPosition();
pos.getPosition();
}

return IMatchRoleID.UNKNOWN;
}

/**
Expand Down Expand Up @@ -1060,11 +1056,12 @@ public final String getSystemName(byte system) {
*/
public final byte getTactic4PositionID(int positionsid) {
try {
return getPositionById(positionsid).getTactic();
var pos = getPositionById(positionsid);
if (pos != null) return pos.getTactic();
} catch (Exception e) {
HOLogger.instance().error(getClass(), "getTactic4PositionID: " + e);
return IMatchRoleID.UNKNOWN;
}
return IMatchRoleID.UNKNOWN;
}

public final float getTacticLevel(int type) {
Expand Down Expand Up @@ -1464,7 +1461,7 @@ public void setPullBackMinute(int pullBackMinute) {
/**
* Amend the lineup by applying the Given MatchOrder
*/
public void UpdateLineupWithMatchOrder(Substitution sub){
public void UpdateLineupWithMatchOrder(Substitution sub) {
MatchRoleID matchRoleIDPlayer, matchRoleIDaffectedPlayer;
int newRoleId;
byte tactic;
Expand All @@ -1473,40 +1470,36 @@ public void UpdateLineupWithMatchOrder(Substitution sub){
switch (sub.getOrderType()) {
case SUBSTITUTION:
matchRoleIDaffectedPlayer = this.getPositionByPlayerId(sub.getSubjectPlayerID());
if (matchRoleIDaffectedPlayer == null)
{
if (matchRoleIDaffectedPlayer == null) {
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s cannot do the substitution", sub.getSubjectPlayerID()));
break;
}

matchRoleIDPlayer = getPositionByPlayerId(sub.getObjectPlayerID());
if (matchRoleIDPlayer==null)
{
if (matchRoleIDPlayer == null) {
HOLogger.instance().warning(Lineup.class, String.format("The substitution of player id: %s has not been recognized", sub.getObjectPlayerID()));
break;
}
ObjectPlayer = this.getPlayerByPositionID(matchRoleIDPlayer.getId());
if (ObjectPlayer == null)
{
if (ObjectPlayer == null) {
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s cannot do the substitution", sub.getObjectPlayerID()));
break;
}
ObjectPlayer.setGameStartingTime(sub.getMatchMinuteCriteria());
tactic = sub.getBehaviour();
if (tactic == -1) tactic = matchRoleIDaffectedPlayer.getTactic();
newRoleId = sub.getRoleId();
if ( newRoleId != -1 ) {
if ( getPositionById(newRoleId).getPlayerId() == 0){
if ( newRoleId != matchRoleIDaffectedPlayer.getId() ) {
if (newRoleId != -1) {
var pos = getPositionById(newRoleId);
if (pos != null && pos.getPlayerId() == 0) {
if (newRoleId != matchRoleIDaffectedPlayer.getId()) {
setSpielerAtPosition(matchRoleIDaffectedPlayer.getId(), 0, MatchRoleID.NORMAL); // clear old position
}
}
else {
} else {
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s cannot do the substitution. Position is not free.", sub.getObjectPlayerID()));
break;
}
}
else {
} else {
newRoleId = matchRoleIDaffectedPlayer.getId();
}
setSpielerAtPosition(newRoleId, matchRoleIDPlayer.getPlayerId(), tactic);
Expand All @@ -1515,15 +1508,14 @@ public void UpdateLineupWithMatchOrder(Substitution sub){
case POSITION_SWAP:
matchRoleIDaffectedPlayer = getPositionByPlayerId(sub.getSubjectPlayerID());
matchRoleIDPlayer = getPositionByPlayerId(sub.getObjectPlayerID());
if ( matchRoleIDaffectedPlayer != null && matchRoleIDPlayer != null ){
if (matchRoleIDaffectedPlayer != null && matchRoleIDPlayer != null) {
matchRoleIDaffectedPlayer.setPlayerIdIfValidForLineup(sub.getObjectPlayerID());
matchRoleIDPlayer.setPlayerIdIfValidForLineup(sub.getSubjectPlayerID());
}
else {
if ( matchRoleIDaffectedPlayer == null ){
} else {
if (matchRoleIDaffectedPlayer == null) {
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s is (no longer) in lineup.", sub.getSubjectPlayerID()));
}
if ( matchRoleIDPlayer == null ){
if (matchRoleIDPlayer == null) {
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s is (no longer) in lineup.", sub.getObjectPlayerID()));
}
}
Expand All @@ -1532,19 +1524,21 @@ public void UpdateLineupWithMatchOrder(Substitution sub){
case NEW_BEHAVIOUR:
newRoleId = sub.getRoleId();
matchRoleIDaffectedPlayer = getPositionByPlayerId(sub.getSubjectPlayerID());
if (matchRoleIDaffectedPlayer == null)
{
if (matchRoleIDaffectedPlayer == null) {
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s cannot do the substitution", sub.getSubjectPlayerID()));
break;
}
if ( newRoleId == -1 ) newRoleId = matchRoleIDaffectedPlayer.getId();
else if ( newRoleId != matchRoleIDaffectedPlayer.getId()
&& getPositionById(newRoleId).getPlayerId() > 0 ){
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s cannot do the substitution. Position is not free.", sub.getObjectPlayerID()));
break;
if (newRoleId == -1) {
newRoleId = matchRoleIDaffectedPlayer.getId();
} else if (newRoleId != matchRoleIDaffectedPlayer.getId()) {
var pos = getPositionById(newRoleId);
if (pos != null && pos.getPlayerId() > 0) {
HOLogger.instance().warning(Lineup.class, String.format("The player id: %s cannot do the substitution. Position is not free.", sub.getObjectPlayerID()));
break;
}
}
tactic = sub.getBehaviour();
if ( tactic == -1) tactic = MatchRoleID.NORMAL;
if (tactic == -1) tactic = MatchRoleID.NORMAL;
setSpielerAtPosition(newRoleId, sub.getSubjectPlayerID(), tactic);
break;

Expand Down

0 comments on commit 4cbd90d

Please sign in to comment.