Implements PlayerHandshakeEvent#getOriginalSocketAddressHostname and deprecates PlayerHandshakeEvent(String, boolean) in favour of PlayerHandshakeEvent(String, String, boolean)

This commit is contained in:
Paul Zhang
2021-02-23 16:47:06 +01:00
parent f1400a74c5
commit 1bc1a162c4
2 changed files with 32 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ private static final HandlerList HANDLERS = new HandlerList();
+ @NotNull private final String originalHandshake;
+ @NotNull private final String originalSocketAddressHostname;
+ private boolean cancelled;
+ @Nullable private String serverHostname;
+ @Nullable private String socketAddressHostname;
@@ -50,10 +51,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ *
+ * @param originalHandshake the original handshake string
+ * @param cancelled if this event is enabled
+ *
+ * @deprecated in favour of {@link PlayerHandshakeEvent(String, String, boolean)}
+ */
+ @Deprecated
+ public PlayerHandshakeEvent(@NotNull String originalHandshake, boolean cancelled) {
+ this(originalHandshake, "127.0.0.1", cancelled);
+ }
+
+ /**
+ * Creates a new {@link PlayerHandshakeEvent}.
+ *
+ * @param originalHandshake the original handshake string
+ * @param originalSocketAddressHostname the original socket address hostname
+ * @param cancelled if this event is enabled
+ */
+ public PlayerHandshakeEvent(@NotNull String originalHandshake, @NotNull String originalSocketAddressHostname, boolean cancelled) {
+ super(true);
+ this.originalHandshake = originalHandshake;
+ this.originalSocketAddressHostname = originalSocketAddressHostname;
+ this.cancelled = cancelled;
+ }
+
@@ -94,6 +110,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ /**
+ * Gets the original socket address hostname.
+ *
+ * <p>This does not include the port.</p>
+ * <p>In cases where this event is manually fired and the plugin wasn't updated yet, the default is {@code "127.0.0.1"}.</p>
+ *
+ * @return the original socket address hostname
+ */
+ @NotNull
+ public String getOriginalSocketAddressHostname() {
+ return this.originalSocketAddressHostname;
+ }
+
+ /**
+ * Gets the server hostname string.
+ *
+ * <p>This should not include the port.</p>