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

Add dynamic key recipe to configuration #27

Merged
merged 14 commits into from
Jun 28, 2021
Merged

Conversation

AtriusX
Copy link
Owner

@AtriusX AtriusX commented Jun 14, 2021

This PR adds the ability to determine a custom crafting recipe for warp keys as requested by #26. Crafting recipes are defined by the key-recipe property in the configuration file in the format of [ "item1", "item2", "item3" ]. Acceptable lengths for this list are 1, 4, or 9 (corresponding to the squares of 1, 2, and 3). Each item in this list should correspond to the name of a value in the Material enum.

Testing was done locally and it appears to function, however further testing should be done to make sure it behaves properly and as expected.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 14, 2021

@NathanAdhitya If you would like you can test this out.

@AtriusX AtriusX added the enhancement New feature or request label Jun 14, 2021
@NathanAdhitya
Copy link

NathanAdhitya commented Jun 15, 2021

@NathanAdhitya If you would like you can test this out.

I have never compiled a kotlin project myself, this is going to be a challenge. 🤣
EDIT: a guide in the README or in the wiki would be nice. On the other hand, the gradle wrapper might be broken. I had to install the standalone gradle to get it working.

@NathanAdhitya
Copy link

NathanAdhitya commented Jun 15, 2021

java.lang.IllegalArgumentException: Crafting rows should be 1, 2, or 3 characters, not 12
        at org.apache.commons.lang.Validate.isTrue(Validate.java:93) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.inventory.ShapedRecipe.shape(ShapedRecipe.java:70) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at xyz.atrius.waystones.data.crafting.CraftingRecipe.setup(CraftingRecipe.kt:20) ~[?:?]
        at xyz.atrius.waystones.utility.PluginKt.registerRecipes(Plugin.kt:36) ~[?:?]
        at xyz.atrius.waystones.Waystones.onEnable(Waystones.kt:38) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:495) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:409) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.MinecraftServer.loadWorld(MinecraftServer.java:607) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:264) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:986) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:307) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at java.lang.Thread.run(Thread.java:831) [?:?]

It seems like default configuration in the config.yml is improper (?). My config.yml had config values that worked for the original version.

key-recipe: '[, IRON_INGOT, , IRON_INGOT, REDSTONE_BLOCK, IRON_INGOT, , IRON_INGOT]'

Attempting:

key-recipe:
  - 
  - IRON_INGOT
  - 
  - IRON_INGOT
  - REDSTONE_BLOCK
  - IRON_INGOT
  - 
  -
  - IRON_INGOT

causes

java.lang.ExceptionInInitializerError: null
        at xyz.atrius.waystones.Waystones.onEnable(Waystones.kt:39) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:495) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:409) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.MinecraftServer.loadWorld(MinecraftServer.java:607) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:264) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:986) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:307) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at java.lang.Thread.run(Thread.java:831) [?:?]
Caused by: java.lang.IllegalArgumentException: No enum constant org.bukkit.Material.null
        at java.lang.Enum.valueOf(Enum.java:273) ~[?:?]
        at org.bukkit.Material.valueOf(Material.java:1) ~[server.jar:3121-Spigot-66f9d3c-eeae1b1]
        at xyz.atrius.waystones.data.crafting.CompassRecipe.<clinit>(CompassRecipe.kt:24) ~[?:?]
        ... 11 more

There's room for improvement for stupid-proofing it, I guess. ¯_(ツ)_/¯. I'm the stupid one not reading the PR instructions. Will try later with the given format.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 15, 2021

There probably is room for improving the config side at least, but I believe it should be able to parse the current config string properly. The latter solution is definitely preferable though.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 15, 2021

Seems like the property system relies on toString() to make the conversion to the config. This generally works well for simple data but I guess this doesn't translate well for list types. I'll see about making an adjustment to this in a bit.

@NathanAdhitya
Copy link

NathanAdhitya commented Jun 18, 2021

I've tried out the new commits. They are still spitting out errors for me for an existing config.

This is the migrated config from the previous (without key-recipe)

key-recipe:
- ''
- IRON_INGOT
- ''
- IRON_INGOT
- REDSTONE_BLOCK
- IRON_INGOT
- ''
- IRON_INGOT
- ''

Could this be a platform issue? 🤔
I suppose a better mechanism to handle config-induced errors at startup would be nice. As it will make it possible to reload the configs later instead of the plugin failing to enable.

I have also tried according to the instructions mentioned, using
key-recipe: [AIR, IRON_INGOT, AIR, IRON_INGOT, REDSTONE_BLOCK, IRON_INGOT, AIR, IRON_INGOT, AIR]
and it seems to spit out the same error as previously. (This could be my fault, only tested this once.)

This is stock after removing the config.yml.

[08:04:57] [Server thread/ERROR]: Error occurred while enabling Waystones v1.0-1.16.3 (Is it up to date?)
java.lang.IllegalArgumentException: Crafting rows should be 1, 2, or 3 characters, not 12
        at org.apache.commons.lang.Validate.isTrue(Validate.java:93) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at org.bukkit.inventory.ShapedRecipe.shape(ShapedRecipe.java:70) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at xyz.atrius.waystones.data.crafting.CraftingRecipe.setup(CraftingRecipe.kt:20) ~[?:?]
        at xyz.atrius.waystones.utility.PluginKt.registerRecipes(Plugin.kt:36) ~[?:?]
        at xyz.atrius.waystones.Waystones.onEnable(Waystones.kt:38) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(CraftServer.java:495) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(CraftServer.java:409) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at net.minecraft.server.MinecraftServer.loadWorld(MinecraftServer.java:608) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at net.minecraft.server.dedicated.DedicatedServer.init(DedicatedServer.java:264) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:987) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:307) ~[server.jar:3147-Spigot-9472b09-d7ef1e9]
        at java.lang.Thread.run(Thread.java:831) [?:?]
locale: en
wait-time: 60
damage-stops-warping: true
limit-distance: true
base-distance: 100
max-boost: 150
max-warp-size: 50
jump-worlds: true
world-ratio: 8
warp-animations: true
single-use: false
require-power: INTER_DIMENSION
power-cost: 1
enable-portal-sickness: true
portal-sickness-warping: DAMAGE_ON_TELEPORT
portal-sickness-damage: 5.0
relinkable-keys: true
enable-key-items: true
key-recipe:
- ''
- IRON_INGOT
- ''
- IRON_INGOT
- REDSTONE_BLOCK
- IRON_INGOT
- ''
- IRON_INGOT
- ''
portal-sickness-chance: '0.05'

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 18, 2021

Probably will have to look into things a bit deeper I think. I'll see if I can deal with it soon, have been a bit busy lately.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 18, 2021

I believe I fixed it, after testing it appears to work well. Apparently I forgot to convert the recipe's hashcodes back into chars so it was causing size problems.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 19, 2021

@NathanAdhitya Able to check this for any other issues?

@NathanAdhitya
Copy link

Will check it soon. It's like midnight here and I must sleep, hahaha. Will give an update.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 19, 2021

Alright thanks for the heads up

@NathanAdhitya
Copy link

NathanAdhitya commented Jun 20, 2021

Hello, I have tested it, the server ran properly. Perhaps tests should be in place to see if the plugin runs correctly in a server 😁. The new config entry is not displayed in /waystones config, but I suppose it is a simple fix.

There is an error during reloading, but it might be because of a stale branch.

org.bukkit.command.CommandException: Unhandled exception executing command 'waystones' in plugin Waystones v1.0-1.16.3
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at org.bukkit.craftbukkit.v1_17_R1.CraftServer.dispatchCommand(CraftServer.java:760) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.network.PlayerConnection.handleCommand(PlayerConnection.java:1944) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1783) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1764) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:46) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.network.protocol.game.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:30) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.TickTask.run(SourceFile:18) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.util.thread.IAsyncTaskHandler.executeTask(SourceFile:151) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.util.thread.IAsyncTaskHandler.executeNext(SourceFile:125) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.MinecraftServer.bg(MinecraftServer.java:1125) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.MinecraftServer.executeNext(MinecraftServer.java:1118) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.util.thread.IAsyncTaskHandler.executeAll(SourceFile:110) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.MinecraftServer.sleepForTick(MinecraftServer.java:1101) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1031) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:307) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        at java.lang.Thread.run(Thread.java:831) [?:?]
Caused by: java.lang.RuntimeException: default localization file not in jar, corrupt download?
        at xyz.atrius.waystones.data.config.Localization.reload(Localization.kt:47) ~[?:?]
        at xyz.atrius.waystones.data.config.Config$locale$1.invoke(Config.kt:20) ~[?:?]
        at xyz.atrius.waystones.data.config.Config$locale$1.invoke(Config.kt) ~[?:?]
        at xyz.atrius.waystones.data.Property.invoke(Property.kt:33) ~[?:?]
        at xyz.atrius.waystones.data.config.ConfigManager.reload(ConfigManager.kt:31) ~[?:?]
        at xyz.atrius.waystones.commands.ReloadCommand.execute(ReloadCommand.kt:17) ~[?:?]
        at xyz.atrius.waystones.commands.CommandNamespace.onCommand(CommandNamespace.kt:34) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[server.jar:3156-Spigot-cd36723-1c39efa]
        ... 19 more

Can confirm it works so far. Some more extensive testing may be required, but I think it seems good for now.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 20, 2021

From my testing the entry does display in the config but in order for it to be loaded you have to run /waystones config or /waystones reload. Attempts were made in the past to make this apply new settings to the config at startup but I couldn't get it working unfortunately.

The localization issue isn't something I've run into myself, so I would need a bit more information on how it occurred and if you can reproduce it.

I also pushed a few more adjustments to the config system so it would be a bit easier to follow and represent each item as the appropriate data type (it was apparently saving everything as a string before this).

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 22, 2021

@NathanAdhitya Have you tested the recent changes? Config values should be properly represented in-file now.

@NathanAdhitya
Copy link

Sorry for the long inactivity 😅.
I have tested this branch on a test server and everything seems to be working fine (so far).
I suppose more testing would be a good idea, I haven't really gotten time to validate the code.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 26, 2021

I see, good to hear. Let me know if you want to take a bit more time to validate things, I'll probably merge it soon otherwise.

@NathanAdhitya
Copy link

Looks good enough at a glance. Unit tests for proving the stability would be more desirable, but I think this shall suffice.

@AtriusX
Copy link
Owner Author

AtriusX commented Jun 28, 2021

Alright then, merging!

@AtriusX AtriusX merged commit b874cbb into master Jun 28, 2021
@AtriusX AtriusX deleted the dev/custom-key-recipe branch June 28, 2021 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants