Can't make CustomReward
wintermaples opened this issue ยท 20 comments
==solved==
I tried making CustomReward(in Quests module).
but Quests plugin throws the following exception when creating any quest which has CustomReward made and re-edit Reward.
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.util.LinkedList
at me.blackvein.quests.prompts.RewardsPrompt.getPromptText(RewardsPrompt.java:171) ~[?:?]
at org.bukkit.conversations.Conversation.outputNextPrompt(Conversation.java:291) ~[1.8-R3.jar:git-Spigot-044d928-e8c6403]
at org.bukkit.conversations.Conversation.acceptInput(Conversation.java:230) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at org.bukkit.craftbukkit.v1_8_R3.conversations.ConversationTracker.acceptConversationInput(ConversationTracker.java:58) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer.acceptConversationInput(CraftPlayer.java:1033) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at net.minecraft.server.v1_8_R3.PlayerConnection$5.evaluate(PlayerConnection.java:984) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at org.bukkit.craftbukkit.v1_8_R3.util.Waitable.run(Waitable.java:24) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:732) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [1.8-R3.jar:git-Spigot-044d928-e8c6403]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
I wondered the following code has problem because "q.customRewards" is HashMap and the exception is "java.lang.ClassCastException: java.util.HashMap cannot be cast to java.util.LinkedList".
QuestFactory - L1887
cc.setSessionData(CK.REW_CUSTOM, q.customRewards);
so I rewrote the code above as the following code.
QuestFactory - L1887
cc.setSessionData(CK.REW_CUSTOM, new LinkedList<String>(q.customRewards.keySet()));
and then Quests plugin don't throw the exception above.
If my source code has no problem, please rewrite "Before Code" to "After Code" formally.
NathanWolf
I have fixed plugin.
Let's try this plugin.
If I transgress Quests plugin license, I remove this file.
Plugin URL:
http://wintermaples.jpn.ph/Quests-2.5.2-b90-module-fixed.jar
That sounds excellent, but I'd prefer to see the code you fixed, if possible! :) Do you have a fork on github or a patch file you could share or anything like that?
@wintermaples I tried your build, but no luck. https://gist.github.com/NathanWolf/81e4e683aa6729aae4b8
Got a different error, but still an error- this is on save of a quest with a custom reward.
I've got a fork I could give you push rights to if you'd like to try and fix this together :)
Thank you, @wintermaples I will take a look!
I have a similar issue with custom requirements, rewards and objectives:
My module code:
NathanWolf
When and what condition does it throw that exception? please tell me.
If I have a quest with a custom reward, and then I try to edit that quest in-game, it happens on save, preventing me from saving the quest.
Something somewhere is storing the custom data as a Map in REW_CUSTOM- instead of two separate lists. This doesn't seem to happen until you add the quests and do a full reload, so maybe something when loading from Yaml specifically.
I remember digging into this over a year ago and could never figure it out- the Bukkit Conversation API feels like a big pile of mess, to be honest.
I stopped server and booted server.
and it throw that exception when I edit quest.
maybe, Quests plugin doesn't load REW_CUSTOM_DATA when load YAML.
I found cause of this problem.
See following code:
QuestFactory L1886-1888
if (q.customRewards.isEmpty() == false) {
cc.setSessionData(CK.REW_CUSTOM, new LinkedList<String>(q.customRewards.keySet()));
}
This is in loadQuest method.
It is code of loading custom reward.
but it doesn't set REW_CUSTOM_DATA.
so, maybe, it is cause of this problem.
Hm- yes.. I think that's because before you changed that code, it was loading a map of keys to values. But code elsewhere expects two lists.. that may be it!
Try adding this:
cc.setSessionData(CK.REW_CUSTOM_DATA, new LinkedList<Object>(q.customRewards.values()));
I will do the same!
... Tested, that actually seems to work!
I also put some code in around line 1278 to handle loading either a Map or List.. going to take that code out now and see if things still work, I think it may not be necessary anymore.
Here is the full change I made, so far it seems to be working- thank you so much for this!
You're welcome.
I'm going to close this issue because this problem is solved.
Thank you.
I updated
http://wintermaples.jpn.ph/Quests-2.5.2-b90-module-fixed.jar
And I place fixed code to
https://github.com/wintermaples/Quests
You could make a PR though! I would do it, but I have a bunch of other jun in my fork.
And i think you can close this, right? You opened it?