nikosgram / gringotts

Gringotts is an item-based economy plugin for the Bukkit Minecraft server platform. Unlike earlier economy plugins, all currency value and money transactions are based on actual items in Minecraft, per default emeralds.
https://www.spigotmc.org/resources/gringotts.42071/
BSD 2-Clause "Simplified" License
43 stars 35 forks source link

1.21 Compability #176

Open gurkleffe opened 3 months ago

gurkleffe commented 3 months ago

I've tried running the plugin with Minecraft 1.21 which gives the error Encountered an error parsing currency. Please check your Gringotts configuration. Error was: amount must be greater than 0, followed by these messages:

[15:16:38 INFO]: [Gringotts] Disabling Gringotts v2.12.5 [15:16:38 INFO]: [Gringotts] Disabling dependency Towny [15:16:38 INFO]: [Gringotts] Disabling dependency Vault [15:16:38 INFO]: [Gringotts] disabled [15:16:38 WARN]: [Gringotts] Gringotts disabled due to startup errors.

There is also another error which seems to be related to this and which is triggered earlier than the ones mentioned above:

[15:25:38 ERROR]: [com.avaje.ebean.config.PropertyMapLoader] ebean.properties not found

I'd love to see a new version of it being compatible!

sprydagger commented 3 months ago

Exact same problem. I am hosting it on falixnodes and also have Chestshop, Dynmap, floodgate, geyser, gringotts, maptowny, towny, townychat, townycombat, townyprovinces, and vault installed.

[11:32:28 ERROR]: [com.avaje.ebean.config.PropertyMapLoader] ebean.properties not found

[11:20:00 ERROR]: [Gringotts] Encountered an error parsing currency. Please check your Gringotts configuration. Error was: amount must be greater than 0 [11:20:00 INFO]: [Gringotts] Disabling Gringotts v2.12.7-SNAPSHOT [11:20:00 INFO]: [Gringotts] Disabling dependency Vault [11:20:00 INFO]: [Gringotts] disabled [11:20:00 WARN]: [Gringotts] Gringotts disabled due to startup errors.

beepee123 commented 3 months ago

I'm not a git pro or a programmer, BUT I was able to fix/work around this (probably incorrectly) by changing line 106 of Configuration.java:

Change: return new ItemStack(material, 0); to return new ItemStack(material, 1);

and recompile. With this hack, was able to get the mod to successfully load on paper-1.21-63.jar

Haven't done much testing yet, just running a small server for my kids. Hope this helps someone!

XorrDev commented 3 months ago

Hi. I'm going to try to do the same. Where is the configuration.java file located?

Shadownite7 commented 3 months ago

I'm not a git pro or a programmer, BUT I was able to fix/work around this (probably incorrectly) by changing line 106 of Configuration.java:

Change: return new ItemStack(material, 0); to return new ItemStack(material, 1);

and recompile. With this hack, was able to get the mod to successfully load on paper-1.21-63.jar

Haven't done much testing yet, just running a small server for my kids. Hope this helps someone!

This may have got the plugin to compile with 1.21 but I am unable to withdraw/deposit money

DocSplinters commented 2 months ago

Same situation, including me not being much of a (Java) programmer. To make the plugin load I've changed the same line in itemByName() to return new ItemStack(material); and compiled (same consequence behind the scenes, amount is set to 1 instead of 0). I have a much bigger issue though: My currency item is poisonous_potato, and in v1.20.6 the commands /balance and /money showed the correct amounts in inventory and my vault (e.g. 30). However, in v1.21 the overall balance is much higher (~200!) and also, regular potatoes add to my balance, i.e. after harvesting my potato patch (and only gaining one poisonous potato) my balance was up to 500+ instead of 31. It is counting regular potatoes for sure because my balance changes when I remove them from my inventory by tossing them on the ground or putting them into a chest that's not my vault.

DocSplinters commented 2 months ago

Hi. I'm going to try to do the same. Where is the configuration.java file located?

You have to clone this repository, then edit the file \src\main\java\org\gestern\gringotts\Configuration.java as described and compile the whole thing using Apache Maven.

DocSplinters commented 2 months ago

[...] It is counting regular potatoes for sure [...]

Correction: It is counting everything in my inventory, including armor and off-hand items. Please see the attached pictures showing the difference between 60 carrots on the ground vs. in my hot bar. 2024-07-22_21 37 44 2024-07-22_21 38 09

DocSplinters commented 2 months ago

ebean.properties not found

@gurkleffe - This error is fixed by creating an empty file called "ebean.properties" in the server's main directory, the same place your server.jar, server.properties ... live. The ebean Java classes provide database connectivity, that's what Gringotts is using to interact with its SQLite database.

DrJekyllH commented 2 months ago

According to my survey to the source code, It can't get the currency correctly on balance() in AccountInvenrtory.java, or It can't get the denomination material correctly on getDenominationOf() in GringottsCurrency.java.

Even though the Material of Denomination is set to Emerald in the configuration file, it is AIR in the code. As a result, withdraw/deposit may be made in AIR.

1.20.6 image

1.21 image

DocSplinters commented 2 months ago

@DrJekyllH Thanks for your post, it gave me the idea to print to stdout, since the logger can't be used everywhere ...

My search also led me to the method getDenominationOf(ItemStack stack) in GringottsCurrency.java. I added the line System.out.println("Map 'denoms' " + (denoms.containsKey(d) ? "contains": "does NOT contain") + " a value for key " + d.typeMaterial.toString()); right before return denoms.get(d); and compiled/tested with some poisonous potatoes (my currency) and some sand in my vault. With v1.20.6 the output is: [18:00:15] [Server thread/INFO]: [Gringotts] [STDOUT] Map 'denoms' contains a value for key POISONOUS_POTATO [18:00:15] [Server thread/INFO]: [Gringotts] [STDOUT] Map 'denoms' does NOT contain a value for key SAND while with v1.21 it is: [18:10:13] [Server thread/INFO]: [Gringotts] [STDOUT] Map 'denoms' contains a value for key POISONOUS_POTATO [18:10:13] [Server thread/INFO]: [Gringotts] [STDOUT] Map 'denoms' contains a value for key SAND

Somehow I figured out that "denoms" - an instance of "Map<Denominationkey, Denomination>" is using the method equals(Object o) in Denominationkey.java when checking if sand is a valid currency, so I added the line System.out.println("DenominationKey for " + this.type.toString() + (this.type.equals (that.type) ? " equals" : does NOT equal") + " that for " + that.type.toString()); just before the return statement. With v1.20.6 this leads to: [19:18:06] [Server thread/INFO]: [Gringotts] [STDOUT] DenominationKey for ItemStack{POISONOUS_POTATO X 0} equals that for ItemStack{ POISONOUS POTATO x 0} while with 1.21 I got: [19:25:01] [Server thread/INFO]: [Gringotts] [STDOUT] Denominationkey for ItemStack{AIR x 0} equals that for ItemStack{AIR x 0} [19:25:01] [Server thread/INFO]: [Gringotts] [STDOUT] Map 'denoms' contains a value for key POISONOUS_POTATO [19:25:01] [Server thread/INFO]: [Gringotts] [STDOUT] Denominationkey for ItemStack{AIR x 0} equals that for ItemStack{AIR X 0} [19:25:01] [Server thread/INFO]: [Gringotts] [STDOUT] Map 'denoms' contains a value for key SAND So as @DrJekyllH already found - instead of looking at emeralds, poisonous potatoes and sand - the plugin is always looking at air, and everything is a match.

What I eventually noticed was the "ItemStack{AIR x 0}". At the beginning of this issue, it was first determined by @beepee123 that return new ItemStack (material, 0); will keep the plugin from starting up successfully, so that might be related to why we're getting "{AIR x 0}" instead of "{EMERALD x 0}" or "{ POISONOUS_POTATO x 0}". What I did to fix that was changing private final Map<Denominationkey, Denomination> denoms = new HashMap<>(); in GringottsCurrency.java to private final Map<Material, Denomination> denoms = new HashMap<>(); so we don't end up with the ItemStack constructor trouble inside the code of the class java.util.Map which we don't have any control over. This requires two more lines in GringottsCurrency.java to change, namely denoms.put(k, d); in the method addDenomination(...) to denoms.put(k.typeMaterial, d); and return denoms.get(d); in the method getDenominationOf(ItemStack stack) to return denoms.get(d.typeMaterial);

With those changes made, /balance resp. /money are now coming up with the correct amounts. However, /deposit and /withdraw still don't work ... Maybe the change in the ItemStack constructor is breaking things in more places, or maybe it's a different issue, I don't know. Just wanted to post what I've found so far, hoping this can get someone who's more proficient with Java and Minecraft plugins on the (hopefully) right track!

DocSplinters commented 2 months ago

Found a better solution, one that's less invasive AND seems to fix /deposit and /withdraw, please see pull request #178.

In a nutshell: Leave the Map instance "denoms" alone, instead add denominations with amount 1 in the DenominationKey constructor.

DrJekyllH commented 2 months ago

I tested #178 by @DocSplinters under the Paper 1.21 As a result, it seems to work fine for me. Thank you.

DrJekyllH commented 2 months ago

I am not familiar with the etiquette of Github and the open source community, and I am concerned that introducing an alternative plugin here violates that etiquette. If there is any issue, I will delete this post immediately.

Since it was discovered that gringotts is not compatible with 1.21, I was looking for an alternative plugin in parallel with fixing the source. I found the following modern plugin. It is not full-featured yet, but there are very few plugins that have this kind of functionality and work properly.

Until an official 1.21-compatible version of gringotts is released, using this alternative plugin is an option.

banco https://www.spigotmc.org/resources/banco-1-20-1-21-item-based-economy.118393/ I am on the Discord for this plugin and the author has listened to the users and is actively developing it.

DocSplinters commented 1 month ago

N00b question: What's the next step, just waiting for the maintainers of this repo to decide whether they want to incorporate #178? Or is there anything I can or have to do to move forward?

nikosgram commented 1 month ago

@DocSplinters that's correct :) I'm currently running tests to ensure that is compatible with older versions of Gringotts and is not gonna cause any issues updating to the new version as they are a lot of changes. :)

GroobleDierne commented 1 month ago

Spoiler: there are breaking changes, so you will need to update your database, I'm currently writing instructions on how to do that. The good news is that you will likely never have to do it again for future versions as it will be automatic from now on. Instructions should be published by the end of the day.

Ethansito commented 2 weeks ago

Spoiler: there are breaking changes, so you will need to update your database, I'm currently writing instructions on how to do that. The good news is that you will likely never have to do it again for future versions as it will be automatic from now on. Instructions should be published by the end of the day.

Where can we find the instructions for updating the database?

GroobleDierne commented 2 weeks ago

Spoiler: there are breaking changes, so you will need to update your database, I'm currently writing instructions on how to do that. The good news is that you will likely never have to do it again for future versions as it will be automatic from now on. Instructions should be published by the end of the day.

Where can we find the instructions for updating the database?

Here https://github.com/nikosgram/gringotts/commit/8b51eee4dd269da3319bb387f18f32edada8c8f4