Commit Graph

4722 Commits

Author SHA1 Message Date
nossr50
cfacd0543e Add PlayerAttackEntityCooldownResetEvent
This event is called when processing a player's attack on an entity
right before their attack strength cd is reset, there are no existing
events that fire within this period of time so it was impossible to
capture the players attack strength via API prior to this commit.

The event is cancellable, which will just skip over the normal reset of
attack strength cd
2020-03-26 20:04:19 -07:00
Mariell Hoversholm
a530d9d70d Allow sleeping players to float
This change lets players who are in their bed have a position which is above
ground for a longer period of time. This is because of the server not setting
their position to the ground/exit location when entering the bed, resulting in
the server believing they're still in the air.
2020-04-19 12:26:07 +02:00
Omer Uddin
93e0c8c61e Fix Bed respawn deviating too far from vanilla (#3195) 2020-04-20 23:14:28 -04:00
2277
5f31a94a22 Move player to spawn point if spawn in unloaded world
The code following this has better support for null worlds to move
them back to the world spawn.
2020-03-31 10:38:18 +01:00
Spottedleaf
d77bc736a0 Improve async login (#3189)
Add helper functions to ChunkProviderServer to make this easier
for other uses

Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
2020-04-19 10:58:02 -07:00
Aikar
909a2454fc Fix Citizens Player NPC tracking issue - Fixes #3186 2020-04-19 13:41:16 -04:00
Aikar
f7e26b47eb Fix Player Tracking issue during join process.
Because we moved entity registration to occur before the PlayerJoinEvent occurs,
We started tracking the entity too early before it was registered to the client.

So delay tracking until after list packets have been sent.
2020-04-19 06:37:10 -04:00
Aikar
9fc8102ef5 Load Spawn Chunks Asynchronously and Spiral Out
Ensures absolute center is first in priority
Speeds up server startup
2020-04-19 06:01:07 -04:00
Aikar
37c7a3af0a Load Chunks for Login Asynchronously
No longer will trigger Synchronous Chunk Loads when a player logs
in to the server.

Will delay PlayerJoinEvent until the chunk has been loaded.

Should have massive performance benefits for larger servers with
lots of players logging in and out.
2020-04-19 04:32:04 -04:00
Aikar
fd9350e9ba Clean up duplicate PlayerInitialSpawnEvent
Confused on this one, as commit history says Spigots version is older
than our version, so i'm not sure how we ended up duplicating this when
the 2 events are 100% identical.

Subclass spigots event and rely on the inheritance system, and clean up
the duplicate event fires.

Fix Spigots setPosition to use setPositionRaw to avoid chunk load prematurely.
2020-04-19 03:11:02 -04:00
Aikar
9cdf9d5502 Fix Longstanding Broken behavior of PlayerJoinEvent
For years, plugin developers have had to delay many things they do
inside of the PlayerJoinEvent by 1 tick to make it actually work.

This all boiled down to 1 reason why: The event fired before the
player was fully ready and joined to the world!

Additionally, if that player logged out on a vehicle, the event
fired before the vehicle was even loaded, so that plugins had no
access to the vehicle during this event either.

This change finally fixes this issue, fully preparing the player
into the world as a fully ready entity, vehicle included.

There should be no plugins that break because of this change, but might
improve consistency with other plugins instead.

For example, if 2 plugins listens to this event, and the first one
teleported the player in the event, then the 2nd plugin actually
would be getting a valid player!

This was very non deterministic. This change will ensure every plugin
receives a deterministic result, and should no longer require 1 tick
delays anymore.
2020-04-19 00:56:43 -04:00
AvrooVulcan
1fb073fb19 Broadcast join messages to console 2020-04-17 00:18:51 +01:00
Aikar
1b04899f1d Don't crash if player is attempted to be removed from untracked chunk.
I suspect it deals with teleporting as it uses players current x/y/z

Fixes #2803
2020-04-18 16:02:37 -04:00
Spottedleaf
dc66fe2c49 Make sure the chunk conversion task is executed immediately
Appending to the tail of the chunk tasks leaves a
window for the chunk to be moved to a
non-ticking status.

Additionally, use CB's callback executor so we
can ensure that we are not incorrectly
scheduling.
2020-04-18 08:41:02 -07:00
Aikar
c293d0a3d8 Fix Chunk Post Processing deadlock risk
See: https://gist.github.com/aikar/dd22bbd2a3d78a2fd3d92e95e9f28dc6

as part of post processing a chunk, we can call ChunkConverter.

ChunkConverter then kicks off major physics updates, and when blocks
that have connections across chunk boundries occur, a recursive risk
can occur where A updates a block that triggers a physics request.

That physics request may trigger a chunk request, that then enqueues
a task into the Mailbox ChunkTaskQueueSorter.

If anything requests that same chunk that is in the middle of conversion,
it's mailbox queue is going to be held up, so the subsequent chunk request
will be unable to proceed.

We delay post processing of Chunk.A() 1 "pass" by re stuffing it back into
the executor so that the mailbox ChunkQueue is now considered empty.

This successfully fixed a reoccurring and highly reproduceable crash
for heightmaps.
2020-04-18 04:44:35 -04:00
Shane Freeder
715a50fd4b Revert "Optimize entity list iteration requiring entities be in"
This reverts commit c1fdcae86a.
2020-04-17 18:24:06 +01:00
Aikar
1cc0c3ac35 Prevent Fire from loading chunks
Had my server die from this twice already as it can cause a chain reaction.
2020-04-17 00:29:53 -04:00
MiniDigger | Martin
d97ce19f49 Add Player Client Options API (#2883) 2020-04-17 06:10:38 +02:00
Spottedleaf
c1fdcae86a Optimize entity list iteration requiring entities be in
loaded chunks

We retain a list of loaded entities specifically for this usage
2020-04-16 16:53:45 -07:00
Spottedleaf
b415ceb617 Optimize ChunkProviderServer's chunk level checking helper methods
These can be hot functions (i.e entity ticking and block ticking),
so inline where possible, and avoid the abstraction of the
Either class.
2020-04-16 20:47:15 -07:00
Aikar
416b2f43e3 Forced Watchdog Crash support and Improve Async Shutdown
If the request to shut down the server is received while we are in
a watchdog hang, immediately treat it as a crash and begin the shutdown
process. Shutdown process is now improved to also shutdown cleanly when
not using restart scripts either.

If a server is deadlocked, a server owner can send SIGHUP (or any other signal
the JVM understands to shut down as it currently does) and the watchdog
will no longer need to wait until the full timeout, allowing you to trigger
a close process and try to shut the server down gracefully, saving player and
world data.

Previously there was no way to trigger this outside of waiting for a full watchdog
timeout, which may be set to a really long time...

Additionally, fix everything to do with shutting the server down asynchronously.

Previously, nearly everything about the process was fragile and unsafe. Main might
not have actually been frozen, and might still be manipulating state.

Or, some reuest might ask main to do something in the shutdown but main is dead.

Or worse, other things might start closing down items such as the Console or Thread Pool
before we are fully shutdown.

This change tries to resolve all of these issues by moving everything into the stop
method and guaranteeing only one thread is stopping the server.

We then issue Thread Death to the main thread of another thread initiates the stop process.
We have to ensure Thread Death propagates correctly though to stop main completely.

This is to ensure that if main isn't truely stuck, it's not manipulating state we are trying to save.
2020-04-16 04:53:50 -04:00
Zach Brown
a94ea15b5a Be less strict with vanilla teleport command limits
Just limit to the same valid location check as BaseBlockPosition, no
reason to restrict to the world border.

Ref: GH-3165
2020-04-16 21:16:35 -05:00
Zach Brown
5041e3e821 Restrict vanilla teleport command to within worldborder
Fixes GH-3165
2020-04-16 20:11:44 -05:00
Aikar
902942d9e4 Fix Optional null issue - Fixes #3155
Also check class loader cache before locking to speed up cached hits to avoid the lock

wasn't gonna make a unique build just for that but can lump it in here.
2020-04-16 03:57:02 -04:00
Spottedleaf
e7f799903e Fix incorect timing of mspt
Move oversleep and all task execution back into the timed area...
2020-04-15 18:48:07 -07:00
Spottedleaf
70131f31d3 Optimise entity hard collision checking
Very few entities actually hard collide, so store them in their own
entity slices and provide a special getEntites type call just for them.
This reduces entity collision checking impact (in my testing) by 25%
for crammed entities (shove 130 cows into an 8x6 area in one chunk).
Less crammed entities are likely to show significantly less benefit.
Effectively, this patch optimises crammed entity situations.
2020-04-16 00:40:47 -04:00
Spottedleaf
1b58ca2161 Don't run entity collision code if not needed
Will not run if max entity craming is disabled and
the max collisions per entity is less than or equal to 0
2020-04-16 00:40:34 -04:00
Spottedleaf
25d0fbed10 Optimise ArraySetSorted#removeIf
Remove iterator allocation and ensure the call is always O(n)
2020-04-15 18:24:39 -07:00
Gergely Sarkozi
26d02ff3c1 Make JavaClassLoader thread-safe (Fixes #3137) (#3144)
* Make PluginClassLoader thread-safe (fixes #3137)

* Clean up implementation of MT safe class loader

Co-authored-by: Aikar <aikar@aikar.co>
2020-04-15 09:39:39 +02:00
Aikar
9b09360ef5 Make the shutdown thread try to shutdown on main 2020-04-13 03:30:12 -04:00
Shane Freeder
207492e613 Prevent opening inventories when frozen 2020-04-13 07:33:46 +01:00
Spottedleaf
973a5271c3 Port 04-Util.patch from Tuinity (#3136) 2020-04-12 22:34:18 -07:00
Aikar
72fae0db1a Fix incorrectly loading chunks on a cancelled interact event
A players previous block break location is held onto permanently, and if
an interact event is cancelled, the client sends a stop breaking block packet
This then tries to update client about that old location.

This old location might then be in a now unloaded chunk, and it caused it to load.

We now also clear reference to it once abort destroy block is ran to stop trying
to send updates about the old block anyways.
2020-04-12 23:56:29 -04:00
Aikar
47c832382c Let invalid positioned entities clean up previous chunk by the chunkCheck
I had did a few of the operations myself, which would have broken chunkCheck
from doing it itself, which would leave some state left in the original chunk
and thats not good....
2020-04-12 22:55:43 -04:00
Spottedleaf
cd7e99804b Multiple memory and performance optimizations (removing streams) 2020-04-12 18:31:14 -04:00
Aikar
73e413e403 Improve the don't save entities patch per leafs feedback 2020-04-12 18:29:52 -04:00
Callahan
bd4c6a566c Port 20w15a Villager AI optimizations 2020-04-08 18:02:26 -05:00
Aikar
bc1203ad20 Restore preventing saving bad entities patch to full effect 2020-04-12 16:50:50 -04:00
Aikar
b03a0ea94b Restore Optimize Pathfinding patch 2020-04-12 16:50:34 -04:00
Aikar
0d4cde25b6 Allow shutting down server during a watchdog hang gracefully
If the request to shut down the server is received while we are in
a watchdog hang, immediately treat it as a crash and begin the shutdown
process. Shutdown process is now improved to also shutdown cleanly when
not using restart scripts either.

If a server is deadlocked, a server owner can send SIGUP (or any other signal
the JVM understands to shut down as it currently does) and the watchdog
will no longer need to wait until the full timeout, allowing you to trigger
a close process and try to shut the server down gracefully, saving player and
world data.

Previously there was no way to trigger this outside of waiting for a full watchdog
timeout, which may be set to a really long time...
2020-04-12 15:56:03 -04:00
Callahan
6dd459625e Async command map building
Reduces lag created on login and world change for sending the command map to client
2020-04-09 01:49:38 -05:00
DrHenchman
1e3eae5e0f Fix method profiler inbalance introduced in b667006 (#3132)
Fixes #3131
2020-04-12 16:41:57 +10:00
Aikar
cb8f1dcc40 Don't delay chunk unloads during entity ticking
Leaf informed me this could cause ordering issues.

So, the risk if this occurring is lowered now anyways, but if an
entity causes a sync chunk load, it could process an unload...

We will tackle the problem better in a future commit

Also fixed another async-chunks=false issue
2020-04-12 00:42:28 -04:00
Aikar
5fc72e41c0 Delay unsafe actions until after entity ticking is done - Fixes #3114
This will help prevent many cases of unregistering entities during entity ticking

Currently delays Chunk Unloads and Async Chunk load callbacks

Also dropped mid ticking chunk tasks during entity ticking to reduce this risk
2020-04-11 21:31:40 -04:00
Aikar
845a0abb0b Disable Sync Events firing Async errors during shutdown
This is how it use to behave on Paper, and this is totally destroying
the ability to try to shut the server down gracefully during the
shutdown process as events firing on the watchdog thread are throwing
errors.

This isn't an issue on Spigot

This has caused me so many rollbacks on watchdog already :(
2020-04-11 21:50:32 -04:00
Aikar
372e545d08 Use better variable for isStopping() API
Previous method only worked for a normal shutdown, and didn't include
when the server enters a closing state due to watchdog crashes

This is the correct variable to detect the server is in the middle of shutdown process
2020-04-11 21:26:16 -04:00
Aikar
a5eb244a55 Remove patch for MC-111480, fixed in 1.14
We were now starting entities at ID 2
2020-04-11 20:39:21 -04:00
Spottedleaf
f654174059 Remove streams from Mob AI System
The streams hurt performance and allocate tons of garbage, so
replace them with the standard iterator.

Also optimise the stream.anyMatch statement to move to a bitset
where we can replace the call with a single bitwise operation.
2020-04-11 20:15:22 -04:00
Aikar
6ad6ec1ac9 Fix Disabling Asynchronous Chunks
This fix is for the few people who are using such low end systems that
asynchronous chunk loading hurts them rather than helping.

The previous build made paper crash if you turned off async chunks, and
this fixes that issue.
2020-04-11 17:15:41 -04:00
Aikar
335e39dca1 Implement Chunk Priority / Urgency System for World Gen
Mark chunks that are blocking main thread for world generation as urgent

Implements a general priority system so that chunks that are sorted in
the generator queues can prioritize certain chunks over another.

Urgent chunks will jump to the front of the line, ensuring that a
sync chunk load on an ungenerated chunk does not lag the server for
a long period of time if the servers generator queues are filled with
lots of chunks already.

This massively reduces the lag spikes from sync chunk gens.

This is also a precursor to my next improvement to prioritize chunks
in front of the player (Frustum Priorization)
2020-04-11 04:44:21 -04:00