Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Persistence + No More Singleton #44

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

dmccoystephenson
Copy link
Member

The changes in this PR are intended to make factions, power records and territory chunks persistent.

@dmccoystephenson
Copy link
Member Author

@Mr-Deej @VoChiDanh
I added you guys to this PR because I thought you might find it interesting.

@dmccoystephenson
Copy link
Member Author

@Pasarus
I'd love to get your input as well if you have time since you work with JSON so much and created the original JSON solution for Medieval Factions.

@VoChiDanh
Copy link

hmmmmm 🤔

fileInputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
this.data = new HashMap<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you don't want to just exit out if it fails to load? Or are you ok with what I am guessing is a brand new vanilla factions implementation, the issue being what happens after? does it just save over the old bits?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it looks like as of right now if it fails, the data is essentially cleared? Yeah we might want to exit here.

*
*/
public void save() {
// TODO: implement
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably implement this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably over-complicating it, but I have had trouble wrapping my head around how to implement this method with the new system.

fileInputStream.close();
} catch (Exception ex) {
ex.printStackTrace();
this.data = new HashMap<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered above

*
*/
public void save() {
// TODO: implement
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered above

@dmccoystephenson
Copy link
Member Author

The data handler classes now implement the data interfaces. This will make it easier to transition to using them instead of the PersistentData class.

@dmccoystephenson
Copy link
Member Author

It is now possible to save faction data, but loading doesn't appear to work correctly.

I'm also running into this error upon faction creation:

[24-04-2022 00:12:25] DanTheTechMan issued server command: /mf create ok
[24-04-2022 00:12:25] null
[24-04-2022 00:12:25] org.bukkit.command.CommandException: Unhandled exception executing command 'mf' in plugin MiniFactions v0.1-ALPHA
[24-04-2022 00:12:25] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
[24-04-2022 00:12:25] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
[24-04-2022 00:12:25] at org.bukkit.craftbukkit.v1_18_R1.CraftServer.dispatchCommand(CraftServer.java:897) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.server.network.ServerGamePacketListenerImpl.handleCommand(ServerGamePacketListenerImpl.java:2293) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.server.network.ServerGamePacketListenerImpl.handleChat(ServerGamePacketListenerImpl.java:2104) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.server.network.ServerGamePacketListenerImpl.handleChat(ServerGamePacketListenerImpl.java:2085) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.network.protocol.game.ServerboundChatPacket.handle(ServerboundChatPacket.java:46) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.network.protocol.game.ServerboundChatPacket.a(ServerboundChatPacket.java:6) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:56) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:149) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:23) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1413) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:189) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:122) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1391) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1384) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:132) ~[?:?]
[24-04-2022 00:12:25] at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1362) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1268) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.18.1.jar:git-Paper-187]
[24-04-2022 00:12:25] at java.lang.Thread.run(Thread.java:833) ~[?:?]
[24-04-2022 00:12:25] Caused by: java.lang.ClassCastException: class dansplugins.minifactions.objects.FactionImpl cannot be cast to class java.util.Map (dansplugins.minifactions.objects.FactionImpl is in unnamed module of loader 'MiniFactions-0.1-ALPHA.jar' @7c9e2528; java.util.Map is in module java.base of loader 'bootstrap')
[24-04-2022 00:12:25] at dansplugins.minifactions.api.data.handlers.FactionHandler.getFaction(FactionHandler.java:94) ~[MiniFactions-0.1-ALPHA.jar:?]
[24-04-2022 00:12:25] at dansplugins.minifactions.api.data.handlers.FactionHandler.addFaction(FactionHandler.java:164) ~[MiniFactions-0.1-ALPHA.jar:?]
[24-04-2022 00:12:25] at dansplugins.minifactions.factories.FactionFactory.createFaction(FactionFactory.java:30) ~[MiniFactions-0.1-ALPHA.jar:?]
[24-04-2022 00:12:25] at dansplugins.minifactions.commands.social.CreateCommand.execute(CreateCommand.java:47) ~[MiniFactions-0.1-ALPHA.jar:?]
[24-04-2022 00:12:25] at preponderous.ponder.minecraft.bukkit.services.CommandService.interpretAndExecuteCommand(CommandService.java:68) ~[MiniFactions-0.1-ALPHA.jar:?]
[24-04-2022 00:12:25] at dansplugins.minifactions.MiniFactions.onCommand(MiniFactions.java:104) ~[MiniFactions-0.1-ALPHA.jar:?]
[24-04-2022 00:12:25] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.18.1-R0.1-SNAPSHOT.jar:?]
[24-04-2022 00:12:25] ... 21 more

@dmccoystephenson dmccoystephenson changed the title Persistence Persistence + No More Singleton Jun 30, 2022
@dmccoystephenson
Copy link
Member Author

I might move to a database solution for this project, rather than using JSON.

@dmccoystephenson
Copy link
Member Author

@alyphen
I added you because I thought you might be interested in this PR. No pressure to reply 👍

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

Successfully merging this pull request may close these issues.

3 participants