Packet for ProtocolLib to listen for Player Blocking with a sword.

Discussion in 'Plugin Development' started by Cloaking_Ocean, Aug 20, 2014.

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

    Cloaking_Ocean

    Hey there, I've looked into the ProtocolLib library and some of the examples of what you can do. I wanted to make a plugin where you block your sword for a certain amount of time and then it would have an enchanted look, then when you stopped blocking it would give you speed and strength potion effects. This is something from an anime called SAO and the name of the plugin would be called Sword Art Online. I've seen how a developer checked for when a player stopped breaking a block here: https://forums.bukkit.org/threads/detect-left-click-release.148713/. I've looked a bit for the player blocking stop packet but haven't had any look. I was wondering if any experienced developers would know what packet it is and maybe even how to implement it for my purposes, thanks in advanced.
     
  2. Offline

    Cloaking_Ocean

    Bump, Hopefully with some results
     
  3. Offline

    indyetoile

    Cloaking_Ocean
    It would be much more convenient to check if the player has an item in its hand, then optionally for the type of sword, and then check if the player is right clicking a block or air with it. This would avoid a lot of hassle.
     
  4. Offline

    Cloaking_Ocean

    indyetoile the idea is that when the player right clicks with his sword his sword will become enchanted for a while and then when he releases he'll havve potion effects but there isn't a Bukkit API Listener for when a button is released but I believe there is a packet for when a player stops blocking otherwise the server wouldn't know if the attack should've been blocked.
     
  5. Offline

    teej107


    I think all the server does to tell is something like this method. I may be wrong though.
    http://jd.bukkit.org/dev/apidocs/org/bukkit/entity/HumanEntity.html#isBlocking()
    Getting if the player is blocking is all you need to tell if an attack should have been blocked. I don't know if there is something to tell when a player stops blocking though using Bukkit.

    EDIT: Apart from using schedulers.
     
    Cloaking_Ocean likes this.
  6. Offline

    fireblast709

    Cloaking_Ocean expanding on indyetoile , you could use that as an initial trigger to schedule a repeating task. Basically create a BukkitRunnable (for their ability to self cancel) and schedule it with 0 ticks delay and a 1 tick interval. Then, on each tick you would check if Player#isBlocking() like teej107 suggested. As long as that is true, keep incrementing a counter to keep track of the blocking time. If not, simply call cancel() from within the BukkitRunnable to cancel the task.

    For an example, look at the first self cancelling task here. The only differences are that
    1. You are incrementing your counter instead of decrementing.
    2. You cancel either when the player stopped blocking or (and I assume this) when you blocked long enough for the effect.
     
    Cloaking_Ocean likes this.
  7. Offline

    Cloaking_Ocean

Thread Status:
Not open for further replies.

Share This Page