Skip to content

Commit

Permalink
Small improvements, make webserver more accessible for addons
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed May 20, 2024
1 parent 93d8876 commit ce25eb5
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

public class BlueMapAPIImpl extends BlueMapAPI {
Expand Down Expand Up @@ -107,8 +106,7 @@ public Optional<BlueMapWorld> getWorldUncached(Object world) {
if (coreWorld != null) world = coreWorld;
}

if (world instanceof World) {
var coreWorld = (World) world;
if (world instanceof World coreWorld) {
return Optional.of(new BlueMapWorldImpl(plugin, coreWorld));
}

Expand Down Expand Up @@ -146,15 +144,15 @@ public String getBlueMapVersion() {
public void register() {
try {
BlueMapAPI.registerInstance(this);
} catch (ExecutionException ex) {
} catch (Exception ex) {
Logger.global.logError("BlueMapAPI: A BlueMapAPI listener threw an exception (onEnable)!", ex.getCause());
}
}

public void unregister() {
try {
BlueMapAPI.unregisterInstance(this);
} catch (ExecutionException ex) {
} catch (Exception ex) {
Logger.global.logError("BlueMapAPI: A BlueMapAPI listener threw an exception (onDisable)!", ex.getCause());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import de.bluecolored.bluemap.common.rendermanager.MapPurgeTask;
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;

import java.io.IOException;
import java.util.Collection;

public class RenderManagerImpl implements RenderManager {
Expand Down Expand Up @@ -59,7 +58,7 @@ public boolean scheduleMapUpdateTask(BlueMapMap map, Collection<Vector2i> region
}

@Override
public boolean scheduleMapPurgeTask(BlueMapMap map) throws IOException {
public boolean scheduleMapPurgeTask(BlueMapMap map) {
BlueMapMapImpl cmap = castMap(map);
return renderManager.scheduleRenderTask(new MapPurgeTask(cmap.getBmMap()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@
import de.bluecolored.bluemap.common.web.http.HttpResponse;
import de.bluecolored.bluemap.common.web.http.HttpStatusCode;
import de.bluecolored.bluemap.core.BlueMap;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

@Getter @Setter
public class BlueMapResponseModifier implements HttpRequestHandler {

private final HttpRequestHandler delegate;
private final String serverName;
private @NonNull HttpRequestHandler delegate;
private @NonNull String serverName;

public BlueMapResponseModifier(HttpRequestHandler delegate) {
this.delegate = delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
package de.bluecolored.bluemap.common.web;

import de.bluecolored.bluemap.common.web.http.*;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.io.File;
Expand All @@ -38,9 +41,10 @@
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

@Getter @Setter
public class FileRequestHandler implements HttpRequestHandler {

private final Path webRoot;
private @NonNull Path webRoot;

public FileRequestHandler(Path webRoot) {
this.webRoot = webRoot.normalize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
import de.bluecolored.bluemap.common.web.http.HttpRequestHandler;
import de.bluecolored.bluemap.common.web.http.HttpResponse;
import de.bluecolored.bluemap.common.web.http.HttpStatusCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

import java.util.function.Supplier;

@Getter @Setter
public class JsonDataRequestHandler implements HttpRequestHandler {

private final Supplier<String> dataSupplier;
private @NonNull Supplier<String> dataSupplier;

public JsonDataRequestHandler(Supplier<String> dataSupplier) {
this.dataSupplier = dataSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@

import de.bluecolored.bluemap.common.web.http.*;
import de.bluecolored.bluemap.core.logger.Logger;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

@Getter
@Getter @Setter
@AllArgsConstructor
public class LoggingRequestHandler implements HttpRequestHandler {

private final HttpRequestHandler delegate;
private final Logger logger;
private final String format;
private @NonNull HttpRequestHandler delegate;
private @NonNull String format;
private @NonNull Logger logger;

public LoggingRequestHandler(HttpRequestHandler delegate) {
this(delegate, Logger.global);
Expand All @@ -47,12 +51,6 @@ public LoggingRequestHandler(HttpRequestHandler delegate, String format) {
this(delegate, format, Logger.global);
}

public LoggingRequestHandler(HttpRequestHandler delegate, String format, Logger logger) {
this.delegate = delegate;
this.format = format;
this.logger = logger;
}

@Override
public HttpResponse handle(HttpRequest request) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
import de.bluecolored.bluemap.core.storage.MapStorage;
import de.bluecolored.bluemap.core.storage.compression.CompressedInputStream;
import de.bluecolored.bluemap.core.storage.compression.Compression;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.commons.io.IOUtils;

import java.io.ByteArrayInputStream;
Expand All @@ -47,11 +50,12 @@
import java.util.regex.Pattern;

@RequiredArgsConstructor
@Getter @Setter
public class MapStorageRequestHandler implements HttpRequestHandler {

private static final Pattern TILE_PATTERN = Pattern.compile("tiles/([\\d/]+)/x(-?[\\d/]+)z(-?[\\d/]+).*");

private final MapStorage mapStorage;
private @NonNull MapStorage mapStorage;

@SuppressWarnings("resource")
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@
import lombok.Setter;
import org.intellij.lang.annotations.Language;

import java.util.LinkedList;
import java.util.Deque;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Getter
public class RoutingRequestHandler implements HttpRequestHandler {

public final LinkedList<Route> routes;
private final Deque<Route> routes;

public RoutingRequestHandler() {
this.routes = new LinkedList<>();
this.routes = new ConcurrentLinkedDeque<>();
}

public void register(@Language("RegExp") String pattern, HttpRequestHandler handler) {
Expand Down

0 comments on commit ce25eb5

Please sign in to comment.