Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup minor map & default repo issues #1318

Merged
merged 1 commit into from
May 26, 2024
Merged
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
33 changes: 17 additions & 16 deletions core/src/main/java/tc/oc/pgm/PGMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,13 @@ public void onEnable() {

datastore = new CacheDatastore(datastore);

try {
mapLibrary.loadNewMaps(false).get(30, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException e) {
e.printStackTrace();
}

if (!mapLibrary.getMaps().hasNext()) {
if (!loadInitialMaps()) {
logger.warning("No maps found, adding default repository as a fallback.");
PGMConfig.registerRemoteMapSource(mapSourceFactories, PGMConfig.DEFAULT_REMOTE_REPO);
try {
mapLibrary.loadNewMaps(false).get(30, TimeUnit.SECONDS);
} catch (ExecutionException | InterruptedException | TimeoutException e) {
e.printStackTrace();
} finally {
if (!mapLibrary.getMaps().hasNext()) {
getServer().getPluginManager().disablePlugin(this);
return;
}
if (!loadInitialMaps()) {
logger.severe("No maps were loaded in time, PGM will be disabled");
getServer().getPluginManager().disablePlugin(this);
return;
}
}

Expand Down Expand Up @@ -394,6 +384,17 @@ private void registerListeners() {
registerEvents(new JoinLeaveAnnouncer(matchManager));
}

private boolean loadInitialMaps() {
try {
mapLibrary.loadNewMaps(false).get(30, TimeUnit.SECONDS);
} catch (TimeoutException e) {
getLogger().warning("Loading all maps took >30s, other maps will keep loading async.");
Pablete1234 marked this conversation as resolved.
Show resolved Hide resolved
} catch (ExecutionException | InterruptedException e) {
getLogger().log(Level.WARNING, "Exception loading maps", e);
}
return mapLibrary.getMaps().hasNext();
}

private class InGameHandler extends Handler {

@Override
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/tc/oc/pgm/command/MapCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import cloud.commandframework.annotations.suggestions.Suggestions;
import cloud.commandframework.context.CommandContext;
import com.google.common.collect.ImmutableList;
import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
Expand Down Expand Up @@ -407,7 +408,8 @@ private ComponentLike formatMapSource(CommandSender sender, MapInfo map) {
.hoverEvent(showText(translatable("map.info.xml.path", NamedTextColor.GOLD))));

if (root.getBaseUrl() != null && root.getRemoteHost() != null) {
String mapPath = root.getBaseUrl() + UriEncoder.encode(source.getRelativeXml().toString());
String relativeUrl = source.getRelativeXml().toString().replace(File.separatorChar, '/');
String mapPath = root.getBaseUrl() + UriEncoder.encode(relativeUrl);
xmlText.append(
text()
.color(NamedTextColor.GREEN)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ map:
#
# To enable the default maps, uncomment the repository below.
# - uri: "https://github.com/PGMDev/Maps"
# path: "maps-default"
# path: "default-maps"

# A path to a map pools file, or empty to disable map pools.
pools: "map-pools.yml"
Expand Down