Skip to content
Open
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
27 changes: 14 additions & 13 deletions src/main/java/bspkrs/mmv/VersionFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,31 @@

public class VersionFetcher
{
private final String jsonUrl = "http://export.mcpbot.bspk.rs/versions.json";
private List<String> versions;
private static final String jsonUrl = "http://export.mcpbot.bspk.rs/versions.json";
private final List<String> versions = new ArrayList<>();
/** Reload if snapshots were downloaded and now aren't, or vice-versa */
private boolean hasSnapshots = false;

@SuppressWarnings("unchecked")
public List<String> getVersions(boolean force) throws IOException
public List<String> getVersions(final boolean snapshots) throws IOException
{
if ((versions == null) || force)
if (snapshots != hasSnapshots || versions.isEmpty())
{
final URL url = new URL(jsonUrl);
final URLConnection connection = url.openConnection();
hasSnapshots = snapshots;
final URLConnection connection = new URL(jsonUrl).openConnection();
connection.addRequestProperty("User-Agent", "MMV/1.0.0");
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));

Map<String, Object> json = new Gson().fromJson(br, Map.class);

versions = new ArrayList<String>();
versions.clear();
for (String mcVer : json.keySet())
for (String channel : ((Map<String, ArrayList<Double>[]>) json.get(mcVer)).keySet())
for (Double ver : ((Map<String, ArrayList<Double>>) json.get(mcVer)).get(channel))
versions.add(mcVer + "_" + channel + "_" + String.format("%.0f", ver));
Collections.sort(versions, Collections.reverseOrder(new SplittedNaturalComparator("_")));
return versions;
if (snapshots || "stable".equals(channel))
for (Double ver : ((Map<String, ArrayList<Double>>) json.get(mcVer)).get(channel))
versions.add(mcVer + "_" + channel + "_" + String.format("%.0f", ver));
versions.sort(Collections.reverseOrder(new SplittedNaturalComparator("_")));
}
else
return versions;
return versions;
}
}
9 changes: 6 additions & 3 deletions src/main/java/bspkrs/mmv/gui/MappingGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class MappingGui extends JFrame
private JButton btnRefreshTables;
private JComboBox<String> cmbMappingVersion;
private JCheckBox chkForceRefresh;
private JCheckBox chkShowSnapshots;
private JPanel pnlProgress;
private JProgressBar progressBar;
private JPanel pnlFilter;
Expand Down Expand Up @@ -500,6 +501,9 @@ public void run()
pnlControls.add(lblMappingVersion);
pnlControls.add(cmbMappingVersion);

chkShowSnapshots = new JCheckBox("Show Snapshots");
chkShowSnapshots.setToolTipText("Show snapshot versions, otherwise only show stable versions.");

btnGetVersions = new JButton("Get Versions");
btnGetVersions.addActionListener(new ActionListener()
{
Expand All @@ -509,16 +513,15 @@ public void actionPerformed(ActionEvent e)
try
{
cmbMappingVersion.removeAllItems();
for (String s : versionFetcher.getVersions(chkForceRefresh.isSelected()))
{
for (String s : versionFetcher.getVersions(chkShowSnapshots.isSelected()))
cmbMappingVersion.addItem(s);
}
}
catch (IOException exc)
{}
}
});
pnlControls.add(btnGetVersions);
pnlControls.add(chkShowSnapshots);

btnRefreshTables = new JButton("Load Mappings");
btnRefreshTables.setEnabled(false);
Expand Down