diff --git a/bungee/pom.xml b/bungee/pom.xml index 161c42b..f6417aa 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -14,18 +14,11 @@ NetworkFilterBungee - - - bungeecord-repo - https://oss.sonatype.org/content/repositories/snapshots - - - net.md-5 bungeecord-api - 1.21-R0.1-SNAPSHOT + 1.21-R0.1 provided diff --git a/common/src/main/java/ls/ni/networkfilter/common/config/service/types/NetworkFilterServiceSettings.java b/common/src/main/java/ls/ni/networkfilter/common/config/service/types/NetworkFilterServiceSettings.java index fbf79b8..7cea6ad 100644 --- a/common/src/main/java/ls/ni/networkfilter/common/config/service/types/NetworkFilterServiceSettings.java +++ b/common/src/main/java/ls/ni/networkfilter/common/config/service/types/NetworkFilterServiceSettings.java @@ -1,15 +1,15 @@ package ls.ni.networkfilter.common.config.service.types; -import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.jetbrains.annotations.Nullable; @Data @NoArgsConstructor @AllArgsConstructor public class NetworkFilterServiceSettings { - @NotNull + @Nullable private String key; } diff --git a/common/src/main/java/ls/ni/networkfilter/common/filter/types/NetworkFilterFilterService.java b/common/src/main/java/ls/ni/networkfilter/common/filter/types/NetworkFilterFilterService.java index 25bff83..023b271 100644 --- a/common/src/main/java/ls/ni/networkfilter/common/filter/types/NetworkFilterFilterService.java +++ b/common/src/main/java/ls/ni/networkfilter/common/filter/types/NetworkFilterFilterService.java @@ -1,6 +1,6 @@ package ls.ni.networkfilter.common.filter.types; -import jakarta.validation.constraints.NotBlank; +import kong.unirest.core.HttpRequestWithBody; import kong.unirest.core.HttpResponse; import kong.unirest.core.JsonNode; import kong.unirest.core.Unirest; @@ -10,17 +10,18 @@ import ls.ni.networkfilter.common.filter.FilterResult; import ls.ni.networkfilter.common.filter.FilterService; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; public class NetworkFilterFilterService implements FilterService { - @NotNull + @Nullable private final String apiKey; - public NetworkFilterFilterService(@NotNull @NotBlank String apiKey) { - this.apiKey = apiKey; + public NetworkFilterFilterService(@Nullable String apiKey) { + this.apiKey = apiKey != null && !apiKey.isBlank() ? apiKey : null; } @Override @@ -30,9 +31,14 @@ public NetworkFilterFilterService(@NotNull @NotBlank String apiKey) { @Override public @NotNull FilterResult check(@NotNull String ip) { - HttpResponse response = Unirest.post("https://nf.ni.ls/api/check") - .header("X-API-KEY", this.apiKey) - .header("Content-Type", "application/x-www-form-urlencoded") + HttpRequestWithBody request = Unirest.post("https://nf.ni.ls/api/check") + .header("Content-Type", "application/x-www-form-urlencoded"); + + if (this.apiKey != null) { + request.header("X-API-KEY", this.apiKey); + } + + HttpResponse response = request .field("ip", ip) .asJson(); diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 5d780c3..761c1cb 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -20,7 +20,7 @@ caches: services: # https://nf.ni.ls networkfilter: - # Required + # Optional, needed if rate-limited key: "" # https://ipapi.is