-
Notifications
You must be signed in to change notification settings - Fork 174
keepalive.sc supporting multiple fake-players and flight saving #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
95ad48b
642819a
994f1c7
9465188
2d2892f
31006ff
2a9ab53
c1947bb
08f8990
77f2545
f276526
9f2c470
f2322c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,59 @@ | ||
| // re-logs fake players upon server restart | ||
| // must need to place it directly in the world scripts folder | ||
|
|
||
| __config() -> {'scope' -> 'global'}; | ||
| __config() -> { | ||
| requires -> { | ||
| 'minecraft' -> '>=1.8', // spectator was not a thing prior to 1.8 | ||
| }, | ||
| 'scope' -> 'global' | ||
| }; | ||
|
|
||
| __on_connect(e) -> ( | ||
| // forcing the fake-players that were spawned in spectator back into creative to retain flight per their data | ||
| if(e:'gm' == 'creative' && e:'fly' == 1, | ||
| sleep(50); // the direct delay is needed to force it back into the proper gamemode. it cannot for the life of it do so at the exact same moment and requires the delay. | ||
| for([str('gamemode %s %s', e:'gm', e:'name')], | ||
| logger('warn', _); | ||
| run(_); | ||
| ); | ||
|
||
| ); | ||
| ); | ||
|
|
||
| __on_player_connects(player) -> ( | ||
| data = load_app_data(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loading this data on every player connection (even non fake ones and after server startup) feels unnecesary. I would suggest loading this data once in |
||
| if (data && data:'players', | ||
| data = parse_nbt(data:'players'); | ||
|
|
||
| player_name = player()~'name'; | ||
|
|
||
| for (data, | ||
| // we're detecting if the player connecting is a fake-player, thus guaranteeing that the player entity object exists and can be used | ||
| if (_:'name' == player_name, | ||
| task('__on_connect', _) | ||
| ); | ||
| ); | ||
| ); | ||
| ); | ||
|
|
||
|
|
||
| __spawn_players() -> ( | ||
| data = load_app_data(); | ||
| if (data && data:'players', | ||
| data = parse_nbt(data:'players'); | ||
| for (data, | ||
| for([str('player %s spawn at %f %f %f facing %f %f in %s', | ||
| _:'name', _:'x', _:'y', _:'z', _:'yaw', _:'pitch', _:'dim'), | ||
| str('gamemode %s %s', _:'gm', _:'name')], | ||
| logger('warn', _); | ||
| run(_); | ||
| ); | ||
| modify(player(_:'name'), 'flying', _:'fly') | ||
| ) | ||
| data = load_app_data(); | ||
| if (data && data:'players', | ||
| data = parse_nbt(data:'players'); | ||
| for (data, | ||
| if (_:'gm' == 'creative' && _:'fly' == 1, | ||
| // spawning creative fake-players in spectator to force the flying state as using modify throws an error due to potential race conditions | ||
| for([str('player %s spawn at %f %f %f facing %f %f in %s in spectator', _:'name', _:'x', _:'y', _:'z', _:'yaw', _:'pitch', _:'dim')], | ||
| logger('warn', _); | ||
| run(_); | ||
| ); | ||
| , _:'gm' != 'creative', | ||
| for([str('player %s spawn at %f %f %f facing %f %f in %s in %s',_:'name', _:'x', _:'y', _:'z', _:'yaw', _:'pitch', _:'dim', _:'gm')], | ||
| logger('warn', _); | ||
| run(_); | ||
| ); | ||
| ); | ||
|
||
| ); | ||
| ); | ||
| ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using sleep and running this in a task might introduce other race conditions. I would suggest just running it at the end of the tick with
schedule(0, ...)and not in a task