-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add Event for Handling Server Connection Failures #3638
Open
Kamesuta
wants to merge
2
commits into
SpigotMC:master
Choose a base branch
from
Kamesuta:feature/serverconnectfailevent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
api/src/main/java/net/md_5/bungee/api/event/ServerConnectFailEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.md_5.bungee.api.event; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
import net.md_5.bungee.api.ServerConnectRequest; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.connection.Server; | ||
import net.md_5.bungee.api.plugin.Event; | ||
|
||
/** | ||
* This event is called when a connection to a server fails (e.g. the server is down). | ||
* Only called when the server cannot be connected to, and is not called when kicked from a server (e.g. the server is full). | ||
* Cancelling this event will cancel the transfer to the fallback lobby and prevent the default error message from being shown. | ||
* <p> | ||
* If you are using {@link ProxiedPlayer#connect}, this event will be called after the callback is called. | ||
* So, you can't cancel the callback by cancelling this event. | ||
*/ | ||
@Data | ||
@ToString(callSuper = false) | ||
@EqualsAndHashCode(callSuper = false) | ||
public class ServerConnectFailEvent extends Event | ||
{ | ||
|
||
/** | ||
* Player whom the server is for. | ||
*/ | ||
private final ProxiedPlayer player; | ||
/** | ||
* The server itself. | ||
*/ | ||
private final Server server; | ||
/** | ||
* Request used to connect to given server. | ||
*/ | ||
private final ServerConnectRequest request; | ||
/** | ||
* Cancelled state. | ||
*/ | ||
private boolean cancelled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If you cancel this doesn't the player just get stuck in limbo?
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.
Yes, when your plugin cancels the event without disconnect or sendMessage,
/server
, etc., the server move will be canceled and nothing will happen.I think this is the correct behavior, since the point of canceling this event is to handle it on the plugin side.
Your plugin can for example do the following
Do you have any ideas for a more appropriate behavior for cancellations?
I will be glad to implement it if you request it!
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.
Let me think about it. I think this is a hard one because already have callback and connect events