Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Failed to resolve nEntity index paths" issue #12

Open
APPenchev opened this issue Feb 22, 2024 · 1 comment
Open

"Failed to resolve nEntity index paths" issue #12

APPenchev opened this issue Feb 22, 2024 · 1 comment

Comments

@APPenchev
Copy link

APPenchev commented Feb 22, 2024

I had a problem while trying to serialize org.bukkit.Location

@NTable(name = "lobbies")
public class Lobby extends NEntity<String> {
...

...
@JsonSerialize(using = LocationSerializer.class)
@JsonDeserialize(using = LocationDeserializer.class)
@JsonProperty("pos")
private Location pos;
...

The serializer

public class LocationSerializer extends JsonSerializer<Location> {

    @Override
    public void serialize(Location location, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("worldName", location.getWorld().getName());
        jsonGenerator.writeNumberField("x", location.getX());
        jsonGenerator.writeNumberField("y", location.getY());
        jsonGenerator.writeNumberField("z", location.getZ());
        jsonGenerator.writeNumberField("yaw", (double) location.getYaw());
        jsonGenerator.writeNumberField("pitch", (double) location.getPitch());
        jsonGenerator.writeEndObject();
    }
}

The deserializer

public class LocationDeserializer extends JsonDeserializer<Location> {
    @Override
    public Location deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
        JsonNode node = jsonParser.getCodec().readTree(jsonParser);
        String worldName = node.get("worldName").asText();
        double x = node.get("x").asDouble();
        double y = node.get("y").asDouble();
        double z = node.get("z").asDouble();
        float yaw = (float) node.get("yaw").asDouble();
        float pitch = (float) node.get("pitch").asDouble();
        return new Location(Bukkit.getWorld(worldName), x, y, z, yaw, pitch);
    }
}

I use this:

public static Promise.AsyncEmptyResult saveLobby(Lobby lobby) {
      Repository<String, Lobby> lobbyRepository = NDatabase.api().getOrCreateRepository(Lobby.class);
      return lobbyRepository.insertAsync(lobby);
}

This is what I get when I run:

org.bukkit.command.CommandException: Unhandled exception executing command 'pg' in plugin PGUtils v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R3.CraftServer.dispatchCommand(CraftServer.java:887) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at org.bukkit.craftbukkit.v1_20_R3.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:50) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.2.9.jar:?]
        at net.minecraft.commands.execution.tasks.ExecuteCommand.a(SourceFile:29) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(SourceFile:13) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.commands.execution.UnboundEntryAction.a(SourceFile:8) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.commands.execution.CommandQueueEntry.a(SourceFile:8) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.commands.execution.ExecutionContext.a(SourceFile:107) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:413) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.commands.CommandDispatcher.performCommand(CommandDispatcher.java:335) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.commands.CommandDispatcher.a(CommandDispatcher.java:322) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1856) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.network.PlayerConnection.lambda$15(PlayerConnection.java:1818) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.util.thread.IAsyncTaskHandler.b(SourceFile:67) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
        at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:156) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1191) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:1) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.util.thread.IAsyncTaskHandler.x(SourceFile:130) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.MinecraftServer.bl(MinecraftServer.java:1170) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1163) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:139) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.MinecraftServer.w_(MinecraftServer.java:1147) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1060) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4046-Spigot-c198da2-38fd4bd]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: com.nivixx.ndatabase.api.exception.DatabaseCreationException: Failed to resolve nEntity index paths
        at com.nivixx.ndatabase.core.RepositoryManager.getOrCreateRepository(RepositoryManager.java:57) ~[?:?]
        at com.nivixx.ndatabase.core.NDatabaseAPIImpl.getOrCreateRepository(NDatabaseAPIImpl.java:20) ~[?:?]
        at com.github.pgutils.entities.service.LobbyService.saveLobby(LobbyService.java:19) ~[?:?]
        at com.github.pgutils.utils.UltimateUtilsX.createLobby(UltimateUtilsX.java:27) ~[?:?]
        at com.github.pgutils.commands.all.LobbyCommand.execute(LobbyCommand.java:86) ~[?:?]
        at com.github.pgutils.commands.PGUtilsCommand.onCommand(PGUtilsCommand.java:47) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        ... 29 more
Caused by: java.lang.NoSuchMethodException: org.bukkit.Location.<init>()
        at java.lang.Class.getConstructor0(Class.java:3585) ~[?:?]
        at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?]
        at com.nivixx.ndatabase.core.reflection.NReflectionUtil.resolveIndexedFieldsFromEntity(NReflectionUtil.java:50) ~[?:?]
        at com.nivixx.ndatabase.core.RepositoryManager.getOrCreateRepository(RepositoryManager.java:55) ~[?:?]
        at com.nivixx.ndatabase.core.NDatabaseAPIImpl.getOrCreateRepository(NDatabaseAPIImpl.java:20) ~[?:?]
        at com.github.pgutils.entities.service.LobbyService.saveLobby(LobbyService.java:19) ~[?:?]
        at com.github.pgutils.utils.UltimateUtilsX.createLobby(UltimateUtilsX.java:27) ~[?:?]
        at com.github.pgutils.commands.all.LobbyCommand.execute(LobbyCommand.java:86) ~[?:?]
        at com.github.pgutils.commands.PGUtilsCommand.onCommand(PGUtilsCommand.java:47) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        ... 29 more

It seems like it's trying to get an instance of a non-existent constructor, but I can't figure out a way to fix it.

@NivixX
Copy link
Owner

NivixX commented Feb 23, 2024

Hello, thank you for sharing all the details.
I have been able to reproduce the problem and did a fix for that !

Note that if you need to index bukkit related domain object, the best approach is to create your own DTO (as you can use the Index annotation) and do a mapper to convert your DTO object to Bukkit.
This approach also avoid having dependency between your data layer and bukkit API

Fix:
https://github.com/NivixX/NDatabase/releases/tag/1.2.0

I added unit tests to validate it work but please try on your server and let me know if it work on a Bukkit env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants