[SPIGOT-271] Player Enchanting Exp Issue Created: 24/Dec/14 Updated: 22/Jul/15 Resolved: 24/Dec/14 |
|
| Status: | Closed |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Ryan | Assignee: | Thinkofname |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | bug, bukkit, enchantment | ||
| Description |
|
Hey guys, I had made an XpFly plugin that has been facing a bug in BUKKIT for a while now. When a player enchants something on an enchanting table, the user gets their enchanted item and their levels deducted, however the value Player.getTotalExperience() reflects the total experience BEFORE the enchantment. As an example: A player "John" has 30 exp levels and wants to enchant his wooden axe. John does so by putting it in the enchantment table and spends 3 exp levels and 2 lapis lazuli doing so. On the level bar GUI, John's exp level is now 27. John then decides he wants to fly using XpFly. He types "/xpfly", and his exp level starts decreasing from 30 (and his levels on the GUI change back to 30 as well). I've checked my code over and over and included extra safeguards to ensure I'm not missing anything when updating the player's exp. Here is my method which does so: The method takes a total exp count as an argument as well as a value (in exp, not levels) for the exp to be assigned to the player. An example call would be the following: Thank you for your time, and am eagerly looking forward to your response! |
| Comments |
| Comment by Ryan [ 22/Jul/15 ] |
|
@MWFIAE - I've coded a workaround for this bug that works perfectly. It works by setting the player's total exp accordingly when it decreases (it's not necessary to do this when their level increases). Register this listener to run every time a player's exp level is changed: http://pastebin.com/CybwXXzD |
| Comment by MWFIAE [ 22/Jul/15 ] |
|
I've seen to many bugs because of this issue. The method doesn't return what one would expect it to. I really hope for a method, that would return the correct amount of current xp. For now I will using the "fix" and calculate the xp myself, as others have done before me, but I don't think that's really the solution to this problem. |
| Comment by Ryan [ 25/Dec/14 ] |
|
@Thinkofdeath - Would it be possible to add a "clone" method to the API which has an updated algorithm to fix it? That way, the old API is preserved and new plugins can use the clone method. @Black Hole - Do you mean getLevel() returns the level, and getExp() returns the exp that is currently on that level? |
| Comment by Black Hole [ 24/Dec/14 ] |
|
Player.getTotalExperience() is a value only used as the score if you die. It's never decreased. You should use getExp() and getLevel(). |
| Comment by Thinkofname [ 24/Dec/14 ] |
|
As far as I can tell that is how that method has always worked and changing it would be breaking to other plugins |
| Comment by SpigotMC [ 24/Dec/14 ] |
|
Your build is not the latest and therefor may be the reason you are having this issue. Spigot is 4 version(s) behind. CraftBukkit is 10 version(s) behind. This message was automatically generated and is not guaranteed to be a solution to your issue. |