more cleanup

This commit is contained in:
okx-code
2026-05-06 05:21:30 +01:00
parent 89bdd109d6
commit 92d94db958
24 changed files with 260 additions and 628 deletions

View File

@@ -16,6 +16,12 @@ subprojects {
options.release = javaVersion
}
tasks.withType<Javadoc> {
options {
(this as CoreJavadocOptions).addBooleanOption("Xdoclint:none", true)
}
}
tasks.withType<ProcessResources> {
filteringCharset = "UTF-8"
}

View File

@@ -2,22 +2,57 @@ package net.civmc.namelayer.sync;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
public record NameLayerInvalidationMessage(Set<Integer> affectedGroupIds, boolean requiresFullResync) {
public record NameLayerInvalidationMessage(
Set<Integer> affectedGroupIds,
Set<UUID> affectedDefaultGroupPlayers,
Set<UUID> affectedAutoAcceptPlayers,
boolean requiresFullResync
) {
public NameLayerInvalidationMessage {
affectedGroupIds = affectedGroupIds == null ? Set.of() : affectedGroupIds;
affectedDefaultGroupPlayers = affectedDefaultGroupPlayers == null ? Set.of() : affectedDefaultGroupPlayers;
affectedAutoAcceptPlayers = affectedAutoAcceptPlayers == null ? Set.of() : affectedAutoAcceptPlayers;
affectedGroupIds = Set.copyOf(validateGroupIds(affectedGroupIds));
if (!requiresFullResync && affectedGroupIds.isEmpty()) {
throw new IllegalArgumentException("affectedGroupIds must not be empty unless requiresFullResync is true");
affectedDefaultGroupPlayers = Set.copyOf(validateUuids(affectedDefaultGroupPlayers, "affectedDefaultGroupPlayers"));
affectedAutoAcceptPlayers = Set.copyOf(validateUuids(affectedAutoAcceptPlayers, "affectedAutoAcceptPlayers"));
if (!requiresFullResync
&& affectedGroupIds.isEmpty()
&& affectedDefaultGroupPlayers.isEmpty()
&& affectedAutoAcceptPlayers.isEmpty()) {
throw new IllegalArgumentException("targeted invalidations must affect at least one cache entry");
}
}
public static NameLayerInvalidationMessage targeted(final Set<Integer> affectedGroupIds) {
return new NameLayerInvalidationMessage(affectedGroupIds, false);
return new NameLayerInvalidationMessage(affectedGroupIds, Set.of(), Set.of(), false);
}
public static NameLayerInvalidationMessage defaultGroups(final Set<UUID> affectedPlayers) {
return new NameLayerInvalidationMessage(Set.of(), affectedPlayers, Set.of(), false);
}
public static NameLayerInvalidationMessage autoAccepts(final Set<UUID> affectedPlayers) {
return new NameLayerInvalidationMessage(Set.of(), Set.of(), affectedPlayers, false);
}
public static NameLayerInvalidationMessage targeted(
final Set<Integer> affectedGroupIds,
final Set<UUID> affectedDefaultGroupPlayers,
final Set<UUID> affectedAutoAcceptPlayers
) {
return new NameLayerInvalidationMessage(
affectedGroupIds,
affectedDefaultGroupPlayers,
affectedAutoAcceptPlayers,
false
);
}
public static NameLayerInvalidationMessage fullResync() {
return new NameLayerInvalidationMessage(Set.of(), true);
return new NameLayerInvalidationMessage(Set.of(), Set.of(), Set.of(), true);
}
private static Set<Integer> validateGroupIds(final Set<Integer> groupIds) {
@@ -29,4 +64,14 @@ public record NameLayerInvalidationMessage(Set<Integer> affectedGroupIds, boolea
}
return groupIds;
}
private static Set<UUID> validateUuids(final Set<UUID> uuids, final String fieldName) {
Objects.requireNonNull(uuids, fieldName);
for (final UUID uuid : uuids) {
if (uuid == null) {
throw new IllegalArgumentException(fieldName + " must not contain null values");
}
}
return uuids;
}
}

View File

@@ -1,55 +0,0 @@
package net.civmc.namelayer.sync;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
public final class NameLayerSyncCodec {
private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
private NameLayerSyncCodec() {
}
public static byte[] encodeWriteRequest(final NameLayerWriteRequest request) {
return encode(request);
}
public static NameLayerWriteRequest decodeWriteRequest(final byte[] body) {
return decode(body, NameLayerWriteRequest.class);
}
public static byte[] encodeWriteResponse(final NameLayerWriteResponse response) {
return encode(response);
}
public static NameLayerWriteResponse decodeWriteResponse(final byte[] body) {
return decode(body, NameLayerWriteResponse.class);
}
public static byte[] encodeInvalidation(final NameLayerInvalidationMessage invalidation) {
return encode(invalidation);
}
public static NameLayerInvalidationMessage decodeInvalidation(final byte[] body) {
return decode(body, NameLayerInvalidationMessage.class);
}
private static byte[] encode(final Object message) {
Objects.requireNonNull(message, "message");
return GSON.toJson(message).getBytes(StandardCharsets.UTF_8);
}
private static <T> T decode(final byte[] body, final Class<T> messageType) {
Objects.requireNonNull(body, "body");
Objects.requireNonNull(messageType, "messageType");
try {
return GSON.fromJson(new String(body, StandardCharsets.UTF_8), messageType);
} catch (final JsonParseException exception) {
throw new IllegalArgumentException("Invalid NameLayer synchronization message", exception);
}
}
}

View File

@@ -5,6 +5,7 @@ public enum NameLayerWriteFailureCode {
DATABASE_UNAVAILABLE,
GROUP_NOT_FOUND,
INVALID_REQUEST,
MAX_GROUPS_REACHED,
MEMBER_NOT_FOUND,
NAME_CONFLICT,
PLAYER_NOT_FOUND,

View File

@@ -1,10 +0,0 @@
package net.civmc.namelayer.sync;
public final class NameLayerWriteRequestPolicy {
public static final long DEFAULT_TIMEOUT_MILLIS = 5_000L;
public static final int AUTOMATIC_RETRY_ATTEMPTS = 0;
private NameLayerWriteRequestPolicy() {
}
}