Solved Alternatives to PlayerInteractEvent ?

Discussion in 'Plugin Development' started by Totom3, Oct 7, 2014.

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

    Totom3

    Hey guys,

    So I was making a gun plugin for someone, and everything was great, until I encountered an issue I wasn't expecting. Currently my code works like this: when the player right clicks, do some checks, then fire a single shot. However, as the logs show, PlayerInteractEvent will only trigger at most 5 times per second :

    PlayerInteractEvent Test Logs (open)
    [17:44:39] [Server thread/INFO]: Test
    [17:44:39] [Server thread/INFO]: Test
    [17:44:39] [Server thread/INFO]: Test
    [17:44:39] [Server thread/INFO]: Test
    [17:44:39] [Server thread/INFO]: Test
    [17:44:40] [Server thread/INFO]: Test
    [17:44:40] [Server thread/INFO]: Test
    [17:44:40] [Server thread/INFO]: Test
    [17:44:40] [Server thread/INFO]: Test
    [17:44:40] [Server thread/INFO]: Test
    [17:44:41] [Server thread/INFO]: Test
    [17:44:41] [Server thread/INFO]: Test
    [17:44:41] [Server thread/INFO]: Test
    [17:44:41] [Server thread/INFO]: Test
    [17:44:42] [Server thread/INFO]: Test
    [17:44:42] [Server thread/INFO]: Test
    [17:44:42] [Server thread/INFO]: Test
    [17:44:42] [Server thread/INFO]: Test
    [17:44:42] [Server thread/INFO]: Test

    Even though this might seem enough, this actually limits the rpm to 300 (5 bullets per second) which is in my opinion quite a big limitation. I would like to reach at least 600 rpm, or 10 bullets per second.

    I already though about making a "start/stop system" : as soon as the player clicks it starts shooting. Then it schedules a task 7-8 ticks later, in which it tests if the current time minus the last time PlayerInteractEvent was fired, is bigger than a certain delay (which would mean the player stopped clicking). If that's the case, then stop firing. The problem with this approach is that first it is a lot more CPU-intensive (at least it sounds like it is), and second, a few more shots may be fired even though the player stopped clicking (he releases the mouse but still 1 or 2 more shots are fired).

    I am now wondering if listening for the packets (via ProtocolLib) would fix the problem ? I am also open to other suggestions, feel free to post any idea you have.

    Thanks in advance :)
     
  2. Offline

    DotDash

    Just use System.currentTimeInMillis() instead of scheduling a task.
     
  3. Offline

    Totom3

    DotDash That wouldn't solve the problem, it would just force the player to click to toggle shooting.
     
  4. Offline

    teej107

    So every 4 ticks, something will happen. Well schedule the gun to shoot an extra bullet 2 ticks after.
     
    Totom3 and AdamQpzm like this.
  5. Offline

    Totom3

    teej107 Aaah, great idea. I'll go for that. Thank you so much !
     
Thread Status:
Not open for further replies.

Share This Page