Originally from https://hub.spigotmc.org/jira/browse/SPIGOT-3015