Skip to content

Commit

Permalink
Updated PlayerStateChangeEventExample with the new way event are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
LielAmar committed Oct 15, 2021
1 parent 68b9f9c commit 1546898
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class PlayerStateChangeEvent extends Event implements Cancellable {

Expand All @@ -18,6 +20,12 @@ public class PlayerStateChangeEvent extends Event implements Cancellable {
private boolean cancelled = false;
private AuthHandler.AuthState oldAuthState, newAuthState;

@Deprecated
public PlayerStateChangeEvent(Player player, AuthHandler.AuthState authState) {
this.player = player;
this.newAuthState = authState;
}

public PlayerStateChangeEvent(Player player, AuthHandler.AuthState oldAuthState, AuthHandler.AuthState newAuthState) {
this.player = player;
this.oldAuthState = oldAuthState;
Expand Down Expand Up @@ -47,19 +55,30 @@ public Player getPlayer() {
return player;
}

public AuthHandler.AuthState getOldAuthState() {
public @Nullable AuthHandler.AuthState getOldAuthState() {
return oldAuthState;
}

public void setOldAuthState(AuthHandler.AuthState oldAuthState) {
public void setOldAuthState(@NotNull AuthHandler.AuthState oldAuthState) {
this.oldAuthState = oldAuthState;
}

public AuthHandler.AuthState getNewAuthState() {
public @NotNull AuthHandler.AuthState getNewAuthState() {
return newAuthState;
}

public void setNewAuthState(@NotNull AuthHandler.AuthState newAuthState) {
this.newAuthState = newAuthState;
}


@Deprecated
public @NotNull AuthHandler.AuthState getAuthState() {
return newAuthState;
}

public void setNewAuthState(AuthHandler.AuthState newAuthState) {
@Deprecated
public void setAuthState(@NotNull AuthHandler.AuthState authState) {
this.newAuthState = newAuthState;
}
}
2 changes: 1 addition & 1 deletion src/test/java/PlayerStateChangeEventExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PlayerStateChangeEventExample implements Listener {

@EventHandler
public void onStateChange(PlayerStateChangeEvent event) {
if(event.getAuthState() == AuthHandler.AuthState.PENDING_LOGIN) {
if(event.getNewAuthState() == AuthHandler.AuthState.PENDING_LOGIN) {
event.getPlayer().sendMessage(ChatColor.GREEN + "We are waiting for you to authenticate!");
}
}
Expand Down

0 comments on commit 1546898

Please sign in to comment.