Solved Interacting with NPC [PacketPlayInUseEntity]

Discussion in 'Plugin Development' started by ASHninja1997, Aug 21, 2017.

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

    ASHninja1997

    I've been researching around and found some articles on protocalLib, however while I've found everything I need on creating a custom NPC, I'm having trouble finding a good way to tell when a player interacts with the NPC (left or right click). I understand you use the PacketPlayInUseEntity, however I need some assistance creating a method with it as this is my first time using protocalLib.

    (I've googled this a couple times but couldn't find anything that significantly helped me understand how it fully works)
     
  2. Offline

    ASHninja1997

  3. Offline

    AlvinB

    @ASHninja1997
    Isn't it just easier to use an API, like Citizens?
     
  4. Offline

    ASHninja1997

    @AlvinB
    I'm open to using it, however would rather not.
     
  5. Offline

    AlvinB

    @ASHninja1997
    Well why not? It's less code you have to manage..
     
  6. Offline

    ASHninja1997

    @AlvinB
    I don't mind having to deal with a lot of code or complex methods. Knowing fully how to work with ProtocolLib will give me better opportunities to further customize things in the future.
     
  7. Offline

    AlvinB

    @ASHninja1997
    Well you might not mind writing the NMS, but I'm pretty sure the users of your plugin will care if your plugin isn't working. And about the customization, why not add that on to the API? Rewriting the entire API just to add one small bit seems quite odd to me.
     
  8. Offline

    TheTrixsta

    I agree, just use an API that already exist. No need to re-invent the wheel. Save yourself the time and effort. Like @AlvinB stated. Just add onto the API.
     
  9. Offline

    ASHninja1997

    @TheTrixsta @AlvinB
    I get what you're saying. However the plugin I'm developing is for my own server, and I only need to get when a player clicks on the NPC. I'd rather take a couple days and learn something new then take the simple route and learn a little.
     
  10. Offline

    AlvinB

    @ASHninja1997
    Well if you insist on reinventing the wheel...

    I'm not sure what your current system looks like, but you need store the entity ID of the NPC you create so you can keep track of which entity is being acted upon. You can then listen for the Use Entity packet using ProtocolLib (you can also have a custom channel injector as a backup if protocollib is not found). Then use the first VarInt parameter of the packet (which is the entity ID) and do a lookup of the entity ID. You can then also get the action from the packet to take the appropriate action.
     
  11. Offline

    ASHninja1997

    @AlvinB
    I'd be turning a Firestone into a Michelin :p (is what happens when you "reinvent"/improve the wheel)

    I found a better alternative method but thanks
     
  12. Offline

    TheTrixsta

    Not familiar with ProtocolLib, but @AlvinB seems to have a good answer here.

    @ASHninja1997 You should post your solution here for anyone else who has this question in the future.
     
  13. Offline

    ASHninja1997

    I used NMS instead of PortocolLIB using this method by @Jacek
     
  14. Offline

    AlvinB

    @ASHninja1997
    Well, what does that tutorial have to do with anything? Setting attributes doesn't have a whole lot to do with interacting with fake players.

    Also, Bukkit now has an API for Entity Attributes, so no need to use NMS in that case.
     
Thread Status:
Not open for further replies.

Share This Page