Adapted and improved version of Spigot commit eb9e4c0460a8acd55ccd58bd54b0b82473876591 By: md_5 <git@md-5.net>