No arrow gravity

Discussion in 'Archived: Plugin Requests' started by alexlab963, Jul 14, 2014.

  1. Offline

    alexlab963

    Plugin category: idk

    Suggested name: Noarrowfall

    What I want: I want a plugin which the player with the right permssions when fires an arrow from the bow the arrow will straight at where the mouse is pointing anyway after an amount of block the gravity will aplied to the arrow so we prevent the lag.Version: 1.7.2

    Ideas for commands: arrowfall on/off to toggle. Or no commands

    Ideas for permissions: noarrowfall.enabled

    When I'd like it by: As soon as possible
     
  2. Offline

    luke_smiff

    I could probably develop this for you, However.
    How far would you want the arrow to go into the sky before it freezes.. Otherwise it would just be an endless arrow flying into sky.
    Eventually causing lag.
     
  3. Offline

    alexlab963

    Well i Dont know exaclty but i believe that about 150-200 blocks are fine and wont make a lot of lag

    luke_smiff Or maybe you can change how far it is travelling config

    Config example

    #Config#
    #Edit the value to change the distance (in blocks) before the arrow freeze
    arrowfallafter: 300

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    alexlab963

  5. Offline

    MomsKnife

    If someone wants to make this - here's the code - can't make it into a plugin atm working on something else

    Code:java
    1. @EventHandler
    2. public void onShootBow(EntityShootBowEvent e) {
    3. Player p = (Player) e.getEntity();
    4. if (p.hasPermission("bow.straight")){
    5. e.getProjectile().setVelocity(e.getProjectile().getVelocity().multiply(5)); new BukkitRunnable() {
    6. @Override
    7. public void run() {
    8. e.remove();
    9. }
    10. }.runTaskLater(this.plugin, 80);
    11. }
    12. }
    13.  
    14.  
    15.  
     
  6. Okay, this is the first plugin request I take, so be gentle. I know how to code plugins (I've made many for my own servers), but I never published one. I was also never taught programming (I'm 14 but not stupid), I learned it all online, so there may be things that could be more efficient and blah. Constructive feedback is welcome. If it works well, I'll publish it as my first plugin.
    NoArrowGravity version 0.1: download This one's broken, download 0.2 ASAP to avoid excessive CPU usage!
    How to use:
    Download and install to plugins folder.
    Run server once.
    Open config.yml, read the instructions and config to maximize precision while not overloading the server. The current default configuration is tailored for home computers that evaluate false for "instanceof Toaster" like mine. If you run on a remote host, you can use 1 second checking delay.
    Reload config file.
    Commands:
    /arrowfall <on|off|reload>: "on" and "off" toggle arrow gravity (requires noarrowgravity.toggle), "reload" reloads the configuration file (requires noarrowgravity.reload)

    Known issues:
    - I haven't added the permissions to the plugin.yml, it's literally 6am and I need to sleep! Will be fixed in a future version.
    - Arrow fall after certain distance may not work sometimes, I'll work on that after some god darned sleep!

    If you want any features/changes or find any bugs, I'll be happy to add/change/fix stuff for you.
     
  7. Offline

    Not2EXceL

    bruno.paschoalinoto

    Take a look at your runnables, and all the useless code that was written for intended functionality, but never actually implemented. Also you can change an entity's gravity using nms, else its a hacky teleporting style no gravity.
     
  8. Offline

    alexlab963

  9. Not2EXceL Well, first of all, the "useless" code was left there in case I needed to change the way I updated the velocity. Also, I personally hate using NMS code unless strictly necessary because that means users will bug me for a fix every time the game is updated. I know it's a hacky way, but I'd rather use a hacky way than rendering my plugin useless on a monthly basis. If it can be done with the API only and won't freeze the server...
    But I'm curious now... why "teleporting style"? A repeating task updates the arrow's velocity very fast, it looked fine on my local server.
     
  10. Offline

    Not2EXceL

    It should look fine, but its not going to always look that way. Also local server is a terrible way to test for lag compensation visual but that's another topic.

    And by useless code, I was referring to the task never actually being cancelled. Also resetting velocity doesn't reset for the miniscule drop that occurs during a tick from the gravity.
     
  11. Not2EXceL Yeah, I found this bug a few hours ago and I'm making a way to cancel the velocity updating task, then the distance checking task to avoid CPU leaks and the like. It's almost done. The code will also look nicer, lots of useless stuff were removed.

    By the way, version 0.2 is here, I suggest you update as soon as possible to avoid server errors and excessive CPU usage.

    Bugfixes:
    - Arrows will actually fall after said distance - actually fixed in v0.3 :p
    - [Important] Fixed a bug where tasks would last forever and would probably generate NPEs when arrows despawned
    - [Important] Fixed a bug where tasks would use more CPU than necessary
    - Removed unused code

    To-do:
    - State permissions in plugin.yml, will be done when I come back, I promise, it's really important, I'm in a hurry here

    Download link: NoArrowGravity v0.2 - v0.3 is available below, please use that one.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  12. Offline

    alexlab963

    Well now the command doesnt exist you can only access it with the plugins name (i dont care so much) can you plz add permissions to reload and enable/disable arrow fall?
     
  13. What do you mean the command doesn't exist? You suggested it used on/off as an argument yourself:
    There is a permission to turn arrow fall on/off (noarrowgravity.toggle) and another for reloading the configuration file (noarrowgravity.reload). Did you mean you wanted a permission that determined whether a player's arrow should bypass the presence/absence of arrow gravity no matter what? I'm working on another version to fix a few issues, and if you want any tweaks to the plugin, be more specific, so I can apply them to the next release.

    Okay, release 0.3 is here, fixing an issue someone downloading the plugin other than the requester might find annoying.

    Bugfixes:
    - [Important] Fixed a bug where many server reloads would cause memory leaks by not removing pending tasks, eventually either clogging up the CPU and making the server impossible to close without the task manager or filling up the memory and causing an OutOfMemoryError.
    - Fixed a bug where arrows would just go down after reaching the minimum distance instead of starting to fall naturally.

    Features:
    - Added the two permissions (noarrowgravity.toggle and noarrowgravity.reload) to the plugin.yml.

    To-do:
    - Do whatever tweak the requester may be asking for, he was really unclear about what he actually wanted.

    Download link: NoArrowGravity v0.3
    v0.4 is available, fixing a CPU overload bug, please use that one!

    Another release, fixing probably the VERY LAST memory/CPU leak in this plugin, sorry for the inconvenience.

    Bugfixes:
    - Fixed a bug where arrows that were made to fall after travelling the set distance didn't have their tasks removed, therefore causing a CPU overload after many arrows were made to fall that way.
    - Improved task removal speed to save CPU usage.

    To-do:
    - Suggestions..?

    Download link: NoArrowGravity v0.4

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  14. Offline

    _Filip

  15. TheSpherret An error in a piece of code like a function that, when called many times, starts using more and more CPU eventually rendering the program unusable after some time.
     
  16. Offline

    _Filip

  17. TheSpherret Pseudo-code:

    1.Your EventHandler fires.
    2. It schedules a sync repeating task.
    3. Task does what it needs to do.
    4. Task keeps on running, using up CPU, and never gets removed.
    5. Same EventHandler fires again. And again.
    6. Lots of repeating tasks start clogging up the main thread, slowing down the server.
    8. Server fails to count.
    N. Server fails to define what a number even is.
    ยง. Server crashes.
    x. Players lose their progress, server keeps on crashing until they find out plugin X is doing it.

    You lose users, servers lose players. End.
    when (new Plugin.isCreated()) {
    goto 1
    }
     
  18. Offline

    _Filip

    bruno.paschoalinoto
    what kinds of calculations were you doing on the sync repeating thread
     
  19. TheSpherret One of them, the CheckingTask, uses a (costly) sqrt() method to tell what distance the arrow has travelled. Before, it used to last forever calling the distance method, and eventually generating NPEs after the arrow despawned. Now, the tasks' IDs are mapped to the arrow's entity ID so when the arrow hits something or reaches the maximum distance, both tasks (the CheckingTask the the VelocityUpdatingTask) get cancelled, the arrow's entity ID gets removed from the HashMap and the dedicated machine doesn't catch on fire/explode/both.
     
  20. Offline

    _Filip

  21. TheSpherret The CheckingTask implements Runnable and repeats every once in a while (user-defined time), checking whether the arrow has travelled more meters than specified by the user in the configuration file. If so, it cancels this arrow's VelocityUpdatingTask (self-explaining), removes the arrow from the HashMap and then cancels itself.
     
  22. Offline

    _Filip

  23. TheSpherret I tried to, but there wasn't a class BukkitRunnable inside org.bukkit.scheduler, where the wiki said it was. >_<
     
  24. Offline

    _Filip

  25. TheSpherret I first tried typing "implements BukkitRunnable", but Eclipse couldn't find the import anywhere, neither did I when trying to manually add it. After lots of searching, I couldn't find it anywhere, so I thought, Runnable it is!
     
  26. Offline

    alexlab963

  27. Offline

    _Filip

  28. TheSpherret I tried that, and got an error because the IDE complained there was no such import, so it wouldn't compile :-/
     
  29. Online

    timtower Administrator Administrator Moderator

  30. Offline

    alexlab963

    @bruno.paschoalinoto can you make it so a player with the right permissions can fire 3 arrows at once that have always the same short distance of 2 block each and also if possible add it to the configuration file
     

Share This Page