From 929b4e7e4a9a82dfe0271cdfa034a309fe2f6ae7 Mon Sep 17 00:00:00 2001 From: wsbrenk Date: Sat, 21 Oct 2023 16:31:30 +0200 Subject: [PATCH] #1927 (#1934) * #1927 new chpp file versions * adjust rating string format --- .../java/core/file/xml/XMLEconomyParser.java | 4 +- .../core/gui/comp/entry/PlayerLabelEntry.java | 34 ++++------ src/main/java/core/net/MyConnector.java | 64 ++++++++----------- .../lineup/lineup/PlayerPositionPanel.java | 2 +- 4 files changed, 42 insertions(+), 62 deletions(-) diff --git a/src/main/java/core/file/xml/XMLEconomyParser.java b/src/main/java/core/file/xml/XMLEconomyParser.java index d12f8bfa9..b7bd2566c 100644 --- a/src/main/java/core/file/xml/XMLEconomyParser.java +++ b/src/main/java/core/file/xml/XMLEconomyParser.java @@ -8,8 +8,6 @@ import org.jetbrains.annotations.Nullable; import org.w3c.dom.Document; import org.w3c.dom.Element; -import static core.net.MyConnector.VERSION_ECONOMY; - public class XMLEconomyParser { @@ -26,7 +24,7 @@ public static Map parseEconomyFromString(String inputStream) { var fetchedDate = HODateTime.fromHT(mapEconomy.get("FetchedDate")); var htWeek = fetchedDate.toHTWeek(); var season = htWeek.season; - if ((Float.parseFloat(VERSION_ECONOMY) >= 1.3f ) && (season >= 80)){ + if (season >= 80){ var iSponsorBonusIncome = assessSponsorBonusIncome(mapEconomy, new String[]{"IncomeSpectators", "IncomeSponsors", "IncomeFinancial", "IncomeTemporary", "IncomeSoldPlayers", "IncomeSoldPlayersCommission"}, "IncomeSum"); mapEconomy.put("IncomeSponsorsBonus", iSponsorBonusIncome.toString()); diff --git a/src/main/java/core/gui/comp/entry/PlayerLabelEntry.java b/src/main/java/core/gui/comp/entry/PlayerLabelEntry.java index 9d17ebcae..ef492d498 100644 --- a/src/main/java/core/gui/comp/entry/PlayerLabelEntry.java +++ b/src/main/java/core/gui/comp/entry/PlayerLabelEntry.java @@ -78,11 +78,11 @@ public PlayerLabelEntry(@Nullable Player player, @Nullable MatchRoleID playerMat } //~ Methods ------------------------------------------------------------------------------------ - public final JComponent getComponent(boolean isSelected) { + public JComponent getComponent(boolean isSelected) { return getComponent(isSelected, false); } - public final JComponent getComponent(boolean isSelected, boolean forceDefaultBackground) { + public JComponent getComponent(boolean isSelected, boolean forceDefaultBackground) { m_clComponent.setOpaque(true); if (forceDefaultBackground) { m_clComponent.setBackground(ThemeManager.getColor(HOColorName.BACKGROUND_CONTAINER)); @@ -116,11 +116,11 @@ public void setIsAssit(boolean isSelect) { } - public final @Nullable Player getSpieler() { + public @Nullable Player getSpieler() { return m_clPlayer; } - public final void clear() { + public void clear() { m_clPlayer = null; m_clPlayerMatchRoleID = null; m_rating = 0f; @@ -128,20 +128,16 @@ public final void clear() { updateComponent(); } - - public final int compareTo(@NotNull IHOTableEntry obj) { - if (obj instanceof PlayerLabelEntry) { - final PlayerLabelEntry entry = (PlayerLabelEntry) obj; - + public int compareTo(@NotNull IHOTableEntry obj) { + if (obj instanceof PlayerLabelEntry entry) { return Objects.requireNonNull(m_clPlayer).getFullName().compareTo(Objects.requireNonNull(entry.getSpieler()).getFullName()); } return 0; } - public final int compareToThird(IHOTableEntry obj) { - if (obj instanceof PlayerLabelEntry) { - final PlayerLabelEntry entry = (PlayerLabelEntry) obj; + public int compareToThird(IHOTableEntry obj) { + if (obj instanceof PlayerLabelEntry entry) { int num1 = TrainingPreviewPlayers.instance().getTrainPreviewPlayer(m_clPlayer).getSortIndex(); int num2 = TrainingPreviewPlayers.instance().getTrainPreviewPlayer(entry.m_clPlayer).getSortIndex(); @@ -156,8 +152,7 @@ public final int compareToThird(IHOTableEntry obj) { return 0; } - - public final void createComponent() { + public void createComponent() { m_clComponent = new JPanel(); final GridBagLayout layout = new GridBagLayout(); @@ -308,7 +303,7 @@ private JLabel createPlayerStatusLabel(Icon icon) { return playerStatusLabel; } - public final void updateComponent() { + public void updateComponent() { if (m_clPlayer != null) { showJersey(); updateDisplay(m_clPlayer); @@ -320,8 +315,8 @@ public final void updateComponent() { /** * Update the entry. */ - public final void updateComponent(Player player, MatchRoleID positionAktuell, - float rating, boolean alternativePosition, String nameText) { + public void updateComponent(Player player, MatchRoleID positionAktuell, + float rating, boolean alternativePosition, String nameText) { m_clPlayer = player; m_clPlayerMatchRoleID = positionAktuell; m_rating = rating; @@ -357,11 +352,10 @@ private void showJersey() { } } - private void showGroupIcon() { String teamInfoSmilie = Objects.requireNonNull(m_clPlayer).getTeamGroup(); - if (teamInfoSmilie.trim().equals("")) + if (teamInfoSmilie.trim().isEmpty()) m_jlTeam.setIcon(ImageUtilities.MINILEER); else m_jlTeam.setIcon(GroupTeamFactory.instance().getActiveGroupIcon(teamInfoSmilie, 15)); @@ -392,7 +386,7 @@ private void updateDisplay(Player player) { // positionValue if (m_rating != 0f) { - m_jlSkill.setText("(" + m_rating + ")"); + m_jlSkill.setText(String.format("(%.2f)", m_rating )); } else { m_jlSkill.setText(""); } diff --git a/src/main/java/core/net/MyConnector.java b/src/main/java/core/net/MyConnector.java index 2f34d0932..5b585ac6c 100644 --- a/src/main/java/core/net/MyConnector.java +++ b/src/main/java/core/net/MyConnector.java @@ -40,19 +40,6 @@ public class MyConnector { private static final String htUrl = "https://chpp.hattrick.org/chppxml.ashx"; public static String m_sIDENTIFIER = "HO! Hattrick Organizer V" + HO.VERSION; private static MyConnector m_clInstance; - public final static String VERSION_AVATARS = "1.1"; - public final static String VERSION_ECONOMY = "1.3"; - private final static String VERSION_TRAINING = "2.1"; - private final static String VERSION_MATCHORDERS = "3.0"; -// private final static String VERSION_MATCHORDERS_NT = "2.1"; - private final static String VERSION_MATCHLINEUP = "2.0"; - private final static String VERSION_MATCHDETAILS = "3.0"; - private final static String VERSION_TEAM_DETAILS = "3.5"; - private final static String VERSION_PLAYERS = "2.5"; - private final static String VERSION_YOUTHPLAYERLIST = "1.1"; - private final static String VERSION_WORLDDETAILS = "1.9"; - private final static String VERSION_TOURNAMENTDETAILS = "1.0"; - private final static String VERSION_LEAGUE_DETAILS = "1.5"; private final static String CONSUMER_KEY = ">Ij-pDTDpCq+TDrKA^nnE9"; private final static String CONSUMER_SECRET = "2/Td)Cprd/?q`nAbkAL//F+eGD@KnnCc>)dQgtP,p+p"; private ProxySettings proxySettings; @@ -134,7 +121,7 @@ public String getRegion(int regionId) { * holt die Finanzen */ public String getEconomy(int teamId){ - final String url = htUrl + "?file=economy&version=" + VERSION_ECONOMY + "&teamId=" + teamId; + final String url = htUrl + "?file=economy&version=1.3&teamId=" + teamId; return getCHPPWebFile(url); } @@ -172,7 +159,7 @@ public String getHattrickXMLFile(String file){ * lädt die Tabelle */ public String getLeagueDetails(String leagueUnitId) { - String url = htUrl + "?file=leaguedetails&version=" + VERSION_LEAGUE_DETAILS + "&leagueLevelUnitID=" + leagueUnitId; + String url = htUrl + "?file=leaguedetails&version=1.5&leagueLevelUnitID=" + leagueUnitId; return getCHPPWebFile(url); } @@ -247,7 +234,7 @@ public String getMatchesArchive(SourceSystem sourceSystem, int teamId, HODateTim * Get information about a tournament. This is only available for the current season. */ public String getTournamentDetails(int tournamentId) throws IOException{ - String url = htUrl + "?file=tournamentdetails&version=" + VERSION_TOURNAMENTDETAILS + "&tournamentId=" + tournamentId; + String url = htUrl + "?file=tournamentdetails&version=1.0&tournamentId=" + tournamentId; return getCHPPWebFile(url); } @@ -255,7 +242,7 @@ public String getTournamentDetails(int tournamentId) throws IOException{ * lädt die Aufstellungsbewertung zu einem Spiel */ public String downloadMatchLineup(int matchId, int teamId, MatchType matchType) { - String url = htUrl + "?file=matchlineup&version=" + VERSION_MATCHLINEUP; + String url = htUrl + "?file=matchlineup&version=2.0"; if (matchId > 0) { url += ("&matchID=" + matchId); @@ -269,12 +256,12 @@ public String downloadMatchLineup(int matchId, int teamId, MatchType matchType) return getCHPPWebFile(url); } + /** * lädt die Aufstellungsbewertung zu einem Spiel */ public String getRatingsPrediction(int matchId, int teamId, MatchType matchType) { - String url = htUrl + "?file=matchorders&version=" + VERSION_MATCHORDERS; - url += "&actionType=predictratings"; + String url = getMatchOrdersURl() + "&actionType=predictratings"; if (matchId > 0) { url += ("&matchID=" + matchId); @@ -287,6 +274,10 @@ public String getRatingsPrediction(int matchId, int teamId, MatchType matchType) return getCHPPWebFile(url); } + private String getMatchOrdersURl() { + return htUrl + "?file=matchorders&version=3.0"; + } + /** * Fetches the match order xml from Hattrick * @@ -297,7 +288,7 @@ public String getRatingsPrediction(int matchId, int teamId, MatchType matchType) * @return The api content (xml) */ public String downloadMatchOrder(int matchId, MatchType matchType, int teamId) { - String url = htUrl + "?file=matchorders&matchID=" + matchId + "&sourceSystem=" + matchType.getSourceString() + "&version=" + VERSION_MATCHORDERS; + String url = getMatchOrdersURl() + "&matchID=" + matchId + "&sourceSystem=" + matchType.getSourceString(); if (!HOVerwaltung.instance().getModel().getBasics().isNationalTeam()) { url += "&teamId=" + teamId; } @@ -318,8 +309,7 @@ public String downloadMatchOrder(int matchId, MatchType matchType, int teamId) { */ public String uploadMatchOrder(int matchId, int teamId, MatchType matchType, String orderString) throws IOException { - StringBuilder urlpara = new StringBuilder(); - urlpara.append("?file=matchorders&version=").append(VERSION_MATCHORDERS); + StringBuilder urlpara = new StringBuilder(getMatchOrdersURl()); if (teamId > 0 && !HOVerwaltung.instance().getModel().getBasics().isNationalTeam()) { urlpara.append("&teamId=").append(teamId); } @@ -332,7 +322,7 @@ public String uploadMatchOrder(int matchId, int teamId, MatchType matchType, Str Map paras = new HashMap<>(); paras.put("lineup", orderString); - String result = readStream(postWebFileWithBodyParameters(htUrl + urlpara, paras, true, + String result = readStream(postWebFileWithBodyParameters(urlpara.toString(), paras, true, "set_matchorder")); String sError = XMLCHPPPreParser.getError(result); if (!sError.isEmpty()) { @@ -345,7 +335,7 @@ public String uploadMatchOrder(int matchId, int teamId, MatchType matchType, Str * Download match details, including match events */ public String downloadMatchdetails(int matchId, MatchType matchType) { - String url = htUrl + "?file=matchdetails&version=" + VERSION_MATCHDETAILS; + String url = htUrl + "?file=matchdetails&version=3.0"; if (matchId > 0) { url += ("&matchID=" + matchId); } @@ -422,18 +412,18 @@ public String getMatches(int teamId, boolean forceRefresh, boolean upcoming) thr } /** - * Get Players + * Download Players */ public String downloadPlayers(int teamId) { - String url = htUrl + "?file=players&version=" + VERSION_PLAYERS + "&includeMatchInfo=true&teamID=" + teamId; + String url = htUrl + "?file=players&version=2.6&includeMatchInfo=true&teamID=" + teamId; return getCHPPWebFile(url); } public String downloadPlayerDetails(String playerID) { - return getCHPPWebFile(htUrl+"?file=playerdetails&version=2.9&includeMatchInfo=true&playerID=" + playerID); + return getCHPPWebFile(htUrl+"?file=playerdetails&version=3.0&includeMatchInfo=true&playerID=" + playerID); } public String downloadYouthPlayers(int youthteamId) { - String url = htUrl + "?file=youthplayerlist&version=" + VERSION_YOUTHPLAYERLIST + "&actionType=unlockskills&showScoutCall=true&showLastMatch=true&youthTeamID=" + youthteamId; + String url = htUrl + "?file=youthplayerlist&version=1.1&actionType=unlockskills&showScoutCall=true&showLastMatch=true&youthTeamID=" + youthteamId; var silent = setSilentDownload(true); // try unlock skills var ret = getCHPPWebFile(url); @@ -446,16 +436,15 @@ public String downloadYouthPlayers(int youthteamId) { } /** - * Get Staff + * Download Staff */ - public String getStaff(int teamId) { - String url = htUrl + "?file=stafflist&version=1.1&teamId=" + teamId; + String url = htUrl + "?file=stafflist&version=1.2&teamId=" + teamId; return getCHPPWebFile(url); } /** - * holt die Teamdetails + * Download team details */ public String getTeamdetails(int teamId) throws IOException { String url = htUrl + "?file=teamdetails&version=3.5"; @@ -467,10 +456,10 @@ public String getTeamdetails(int teamId) throws IOException { } /** - * holt die Teamdetails + * Download player avatars */ public String getAvatars(int teamId) { - String url = htUrl + "?file=avatars&version=" + VERSION_AVATARS +"&actionType=players"; + String url = htUrl + "?file=avatars&version=1.1&actionType=players"; if (teamId > 0) { url += ("&teamID=" + teamId); } @@ -478,12 +467,11 @@ public String getAvatars(int teamId) { return getCHPPWebFile(url); } - /** * Get the training XML data. */ public String getTraining(int teamId) { - final String url = htUrl + "?file=training&version=" + VERSION_TRAINING + "&teamId=" + teamId; + final String url = htUrl + "?file=training&version=2.1&teamId=" + teamId; return getCHPPWebFile(url); } @@ -509,7 +497,7 @@ public String getVerein(int teamId) { * holt die Weltdaten */ public String getWorldDetails(int leagueId) throws IOException { - String url = htUrl + "?file=worlddetails&version=" + VERSION_WORLDDETAILS; + String url = htUrl + "?file=worlddetails&version=1.9"; if (leagueId > 0) url += "&leagueID=" + leagueId; return getCHPPWebFile(url); @@ -594,7 +582,7 @@ public String fetchRegionID(int teamId) { public String fetchTeamDetails(int teamId) { try { - String xmlFile = htUrl + "?file=teamdetails&version=" + VERSION_TEAM_DETAILS + "&teamID=" + teamId; + String xmlFile = htUrl + "?file=teamdetails&version=3.5&teamID=" + teamId; return getCHPPWebFile(xmlFile); } catch (Exception e) { HOLogger.instance().log(getClass(), e); diff --git a/src/main/java/module/lineup/lineup/PlayerPositionPanel.java b/src/main/java/module/lineup/lineup/PlayerPositionPanel.java index bed4a23a6..5de5607d8 100644 --- a/src/main/java/module/lineup/lineup/PlayerPositionPanel.java +++ b/src/main/java/module/lineup/lineup/PlayerPositionPanel.java @@ -627,7 +627,7 @@ private void addTactic(@Nullable Player currentPlayer, String text, byte playerP else { rating = ratingPredictionModel.getPlayerRating(currentPlayer, m_iPositionID, playerPosition, matchMinute); } - text += " (" + rating + ")"; + text += String.format(" (%.2f)", rating); } m_jcbTactic.addItem(new CBItem(text, playerPosition)); }