9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

修复速率限制不存在

This commit is contained in:
XiaoMoMi
2025-11-23 00:33:49 +08:00
parent ba55f91f55
commit 1be0af7b1b
4 changed files with 87 additions and 3 deletions

View File

@@ -111,12 +111,21 @@ tasks {
publishing {
repositories {
maven {
name = "releases"
url = uri("https://repo.momirealms.net/releases")
credentials(PasswordCredentials::class) {
username = System.getenv("REPO_USERNAME")
password = System.getenv("REPO_PASSWORD")
}
}
maven {
name = "snapshot"
url = uri("https://repo.momirealms.net/snapshots")
credentials(PasswordCredentials::class) {
username = System.getenv("REPO_USERNAME")
password = System.getenv("REPO_PASSWORD")
}
}
}
publications {
create<MavenPublication>("mavenJava") {
@@ -137,5 +146,35 @@ publishing {
}
}
}
create<MavenPublication>("mavenJavaSnapshot") {
groupId = "net.momirealms"
artifactId = "craft-engine-bukkit"
version = "${rootProject.properties["project_version"]}-SNAPSHOT"
artifact(tasks["sourcesJar"])
from(components["shadow"])
pom {
name = "CraftEngine API"
url = "https://github.com/Xiao-MoMi/craft-engine"
licenses {
license {
name = "GNU General Public License v3.0"
url = "https://www.gnu.org/licenses/gpl-3.0.html"
distribution = "repo"
}
}
}
}
}
}
tasks.register("publishRelease") {
group = "publishing"
description = "Publishes to the release repository"
dependsOn("publishMavenJavaPublicationToReleaseRepository")
}
tasks.register("publishSnapshot") {
group = "publishing"
description = "Publishes to the snapshot repository"
dependsOn("publishMavenJavaSnapshotPublicationToSnapshotRepository")
}

View File

@@ -116,12 +116,21 @@ tasks {
publishing {
repositories {
maven {
name = "releases"
url = uri("https://repo.momirealms.net/releases")
credentials(PasswordCredentials::class) {
username = System.getenv("REPO_USERNAME")
password = System.getenv("REPO_PASSWORD")
}
}
maven {
name = "snapshot"
url = uri("https://repo.momirealms.net/snapshots")
credentials(PasswordCredentials::class) {
username = System.getenv("REPO_USERNAME")
password = System.getenv("REPO_PASSWORD")
}
}
}
publications {
create<MavenPublication>("mavenJava") {
@@ -142,5 +151,35 @@ publishing {
}
}
}
create<MavenPublication>("mavenJavaSnapshot") {
groupId = "net.momirealms"
artifactId = "craft-engine-core"
version = "${rootProject.properties["project_version"]}-SNAPSHOT"
artifact(tasks["sourcesJar"])
from(components["shadow"])
pom {
name = "CraftEngine API"
url = "https://github.com/Xiao-MoMi/craft-engine"
licenses {
license {
name = "GNU General Public License v3.0"
url = "https://www.gnu.org/licenses/gpl-3.0.html"
distribution = "repo"
}
}
}
}
}
}
tasks.register("publishRelease") {
group = "publishing"
description = "Publishes to the release repository"
dependsOn("publishMavenJavaPublicationToReleaseRepository")
}
tasks.register("publishSnapshot") {
group = "publishing"
description = "Publishes to the snapshot repository"
dependsOn("publishMavenJavaSnapshotPublicationToSnapshotRepository")
}

View File

@@ -294,9 +294,8 @@ public class SelfHostHttpServer {
}
private boolean checkIpRateLimit(String clientIp) {
Bucket rateLimiter = ipRateLimiters.get(clientIp, k ->
Bucket.builder().addLimit(limitPerIp).build()
);
if (limitPerIp == null) return true;
Bucket rateLimiter = ipRateLimiters.get(clientIp, k -> Bucket.builder().addLimit(limitPerIp).build());
assert rateLimiter != null;
return rateLimiter.tryConsume(1);
}

View File

@@ -6,6 +6,8 @@ public interface LazyReference<T> {
T get();
boolean initialized();
static <T> LazyReference<T> lazyReference(final Supplier<T> supplier) {
return new LazyReference<>() {
private T value;
@@ -17,6 +19,11 @@ public interface LazyReference<T> {
}
return this.value;
}
@Override
public boolean initialized() {
return this.value != null;
}
};
}
}