feat: 完善插件稳定性与兼容性
Build / build (push) Has been cancelled

This commit is contained in:
2026-08-01 00:36:17 +08:00
parent 5c760b26c6
commit 18cfbc2002
44 changed files with 1523 additions and 471 deletions
@@ -0,0 +1,41 @@
package cn.infstar.essentialsC;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class ConfigurationResourcesTest {
@ParameterizedTest
@ValueSource(strings = {
"config.yml",
"modules.yml",
"maintenance.yml",
"blocks-menu.yml",
"paper-plugin.yml",
"lang/zh_CN.yml",
"lang/en_US.yml"
})
void bundledYamlIsValid(String resourcePath) throws Exception {
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
assertNotNull(input, resourcePath);
YamlConfiguration configuration = new YamlConfiguration();
configuration.load(new InputStreamReader(input, StandardCharsets.UTF_8));
if (resourcePath.equals("config.yml")) {
assertEquals(2, configuration.getInt("config-version"));
assertEquals(5, configuration.getInt("tpa.max-pending-requests"));
}
if (resourcePath.equals("paper-plugin.yml")) {
assertEquals("1.21.11", configuration.getString("api-version"));
}
}
}
}
@@ -0,0 +1,32 @@
package cn.infstar.essentialsC.teleport;
import org.junit.jupiter.api.Test;
import java.util.ArrayDeque;
import java.util.Deque;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class TeleportRequestQueuePolicyTest {
@Test
void keepsNewestRequestsWithinConfiguredLimit() {
Deque<String> requests = new ArrayDeque<>();
TeleportRequestQueuePolicy.addFirstBounded(requests, "first", 2);
TeleportRequestQueuePolicy.addFirstBounded(requests, "second", 2);
TeleportRequestQueuePolicy.addFirstBounded(requests, "third", 2);
assertEquals(java.util.List.of("third", "second"), java.util.List.copyOf(requests));
}
@Test
void retainsRecentlyExpiredRequestsForUserFeedback() {
long now = 120_000L;
assertFalse(TeleportRequestQueuePolicy.shouldPrune(90_000L, now, 60_000L));
assertTrue(TeleportRequestQueuePolicy.shouldPrune(60_000L, now, 60_000L));
}
}