Anvil and "Too Expensive"

Discussion in 'Plugin Development' started by Rexcantor64, Apr 14, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Rexcantor64

    I want to disable the "Too Expensive" message on the Anvil. I know you can't do it because it's calculated on the client side. But I read a thing here:
    So, I was wondering to do this: when a player opens an anvil, the gamemode is changed to creative (only if it's inside an WG region), an action bar is sent with the current EXP and the player can bypass this. I only have one BIG problem: the EXP is not consumed from the player, so I can repair a thing that costs 42 EXP and I don't have to pay anything. I don't know if I can cancel the InventoryClickEvent... (Note: I'm using 1.8 so I don't have PrepareAnvilEvent or something like it). I hope if I can do this, it will help a lot of people!
    Thanks for everything,
    Rexcantor64
     
    Last edited: Apr 27, 2016
  2. Offline

    Gonmarte

    If a player right click an anvil, give him creative. If he tries to leave the anvil give him survival mode, if he disconects the server while he was in the anvil, give him survival mode.
     
  3. Offline

    Rexcantor64

    That's not my problem... My problem is the EXP that is not consumed while in creative mode.
     
  4. Offline

    Konato_K

    @Rexcantor64 Have you tried manually setting the exp after the player takes the item from the anvil?
     
  5. Offline

    Rexcantor64

    But if the played doesn't have the enough EXP? I can't set a negative EXP... And I will know the amount of EXP? It's calculated on the client side ;(
     
  6. Offline

    Konato_K

    @Rexcantor64 What do you mean with "calculated on the client side"? There is a method to get the player's xp level, so if they have enough remove the levels, otherwise cancel the click so they can't take the item.
     
  7. Offline

    cococow123

    Get player's xp amount.
    Set player's xp level to like 50.
    When player exits game or closes anvil, set player's xp back


    Magikal Coconess
     
  8. Offline

    elian1203

    Maybe a PrepareAnvilEvent could help you? There are getResult and setResult methods, and the getResult can return null so you may be able to do something with that.
     
  9. Offline

    Rexcantor64

    The cost of EXP on the anvil is calculated on the client side.

    What do you mean?

    The PrepareAnvilEvent was only added on 1.9. I'm using 1.8.
     
  10. Offline

    mcdorli

    Please, read the question.
     
  11. Offline

    cococow123

    Whatever.. Good luck figuring it out, though.

    (I don't see a clear question, I just thought maybe you wanted to allow players to use an anvil without taking away their xp)


    Magikal Coconess
     
  12. Offline

    Konato_K

    @Rexcantor64 I'm pretty sure the amount it costs is not in the client (maybe the client displays it, but that's why you're setting the gamemode to creative on anvil, and when they click to get it you put them back on survival and remove the xp)

    The cost is stored in the item as an NBT tag, can't remember what is called, but I've seen it before.
     
  13. Offline

    Rexcantor64

    https://bukkit.org/threads/too-expensive-anvil-fix.132759/
     
  14. Offline

    Konato_K

    @Rexcantor64 Just because it is in a post doesn't mean is truth.

    [​IMG]

    The cost is stored in a NBT Tag as I said, of course, there is no Bukkit way to get it, so you'll have to use a library or something to get the NBT stuff
     
  15. Offline

    Rexcantor64

    Your post will be useful, but this only solve ONE of my problems... And if I put 2 items in the anvil (e.g. A sword and an enchanted book)?
     
  16. Offline

    Konato_K

    @Rexcantor64 Then find out how is the level calculated in that case (which is still related to the weapon's repair cost) and apply it, I don't have all the answers, I'm just helping.
     
  17. Offline

    Rexcantor64

    Thanks for everything you did, I will try to do it quickly. If I need more help I will post here. Thanks again!
     
  18. Offline

    Rexcantor64

  19. Offline

    Rexcantor64

    @Konato_K Thanks for all you did! I'm almost finishing the plugin but I've a problem here.... I want to add 1 to the cost if the item is renamed, but I need to do it in real time... Isn't there an "Packet Event" that fires when I change the name on the rename section (or a KeyboardClickEvent)? Do I need to have a task to check all opened anvil inventories and checking if the initial name is equals to the result name? Better than the second question is to activate the system when the cost is in 38 instead of 39... so they can rename and it doesn't get "Too Expensive"... I already tried AnvilAPI but it only fire an event when the they pickup the result item (which I can do easily)...
    EDIT: Also, I'm getting other problem... I need to know if the item is damaged or not... With almost all durabilities it works, but when the durability is 0, it bugs because when the item is not damaged it also returns 0... Any ideas?
     
    Last edited: Apr 28, 2016
  20. Offline

    Konato_K

    @Rexcantor64 There is no way to know when a player pushes a key, I'm not sure if you can get when they try to rename an item and I was unable to find them in the packet list http://wiki.vg/Protocol

    Maybe someone else knows how or I'm blind when looking at that
     
  21. Offline

    Rexcantor64

    @Konato_K I also edited my post above. Take a look
    EDIT: OMG! Why didn't you show me this page before! Here(Scroll down to WindowType: Anvil) there's a propriety where you can get the EXP amount! Now, how can I do that? Any ideas?
     
  22. Offline

    Konato_K

    @Rexcantor64 You'll need to use ProtocolLib (or another way to intercept the packet), there should be some tutorials in this forums or so.

    And considering the packet I guess you can as well modify the value of it and get it with protocol lib, not sure if this will only affect the window or actually change the value of the anvil repair though.

    As far I remember 0 only means the item is new, and item that shows with durability of 0/384 and will break in one use usually has a durability of 384 in Bukkit, for some reason the durability is actually damage, how damaged it is, are you sure you get 0 in both cases?
     
  23. Offline

    Rexcantor64

    I tried to use it, but it's the first time... I found some tutorials but I think they're outdated because Packets is deprecated.
    And other problem... I didn't found the packet on the packet list. The packet ID is 0x15 (21 in decimal) and on the list it can be PacketPlayInSettings (Client) or PacketPlayOutRelEntityMove (Server).

    If I can use the packets, this method will not be needed.
     
  24. Offline

    Konato_K

    @Rexcantor64 I wasn't able to find it in the javadocs either http://ci.dmulloy2.net/job/ProtocolLib/javadoc/

    Maybe it's just a new packet or something? It can't be PlayInSettings since that's what the client uses to tell the server their Mc settings, and OutRelEntityMove is for entity movement as far as I know
     
  25. Offline

    Rexcantor64

    Looking at packet list again, I found 5 packets with "Window" in the name(3 out, 2 in)... Excluding the out packets, I have 2 options: "PacketPlayInCloseWindow"(id 13) or "PacketPlayInWindowClick"(id 14). Maybe the packet 14 have the anvil XP cost?
     
  26. Offline

    I Al Istannen

  27. Offline

    Rexcantor64

    Thank you so much!!! Looks good! I will test it later!
     
  28. Offline

    I Al Istannen

    @Rexcantor64
    Sorry to disappoint you, but read the edit. It seems like it was added in 1.9 :/
    I didn't read the 1.8 thing before.
     
  29. Offline

    Rexcantor64

    @Konato_K
    ;(... Will look at it... Maybe I can do something to change it...

    Good news! PacketPlayOutWindowData is available in 1.8!
    Code:
    import net.minecraft.server.v1_8_R3.PacketPlayOutWindowData;
    Now, is there anyway to get this packet? Basically I want to retrieve the EXP amount displayed on the anvil... Any ideas?
    This packet doesn't appear in com.comphenix.protocol.Packets, so I think I can't use ProtocolLib ;(
     
    Last edited: Apr 29, 2016
  30. Offline

    Rexcantor64

    @Konato_K @I Al Istannen
    Forget about the packets... The packet is "OUT", so it's send by the server, not from the client... I will go back to the original project. Read my post above (about the renaming and the item durability) - Post #19.
     
Thread Status:
Not open for further replies.

Share This Page