Skip to content

Commit

Permalink
fix(Event): Override isCancel and cancel methods
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeV220 committed Apr 23, 2023
1 parent 3861de3 commit 650df6b
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 9 deletions.
Expand Up @@ -10,6 +10,7 @@ public class PlayerObjectConnectionEvent extends PlayerObjectEvent implements Ca
private static final HandlerList handlers = new HandlerList();

private final ConnectionType connectionType;
private boolean cancelled = false;

/**
* Constructs a {@code PlayerObjectConnectionEvent} with the specified player object, connection type and asynchronous status.
Expand All @@ -27,6 +28,26 @@ public ConnectionType getConnectionType() {
return connectionType;
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down
Expand Up @@ -13,7 +13,7 @@ public class PlayerObjectEvent extends Event implements Cancellable {

private static final HandlerList handlers = new HandlerList();

private boolean cancelled;
private boolean cancelled = false;

/**
* The player object associated with this event.
Expand Down
Expand Up @@ -18,6 +18,7 @@ public class PlayerObjectUserEvent extends UserEvent implements Cancellable {
* The player object associated with this event.
*/
private final PlayerObject playerObject;
private boolean cancelled = false;

/**
* Constructs a {@code PlayerObjectUserEvent} with the specified user, player object, and asynchronous status.
Expand All @@ -41,6 +42,26 @@ public PlayerObject getPlayerObject() {
return playerObject;
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down
Expand Up @@ -6,7 +6,6 @@
import com.georgev22.skinoverlay.event.events.player.PlayerObjectUserEvent;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Represents an event that is called before the player's skin is updated.
Expand All @@ -15,6 +14,8 @@ public class PlayerObjectPreUpdateSkinEvent extends PlayerObjectUserEvent implem

private static final HandlerList handlers = new HandlerList();

private boolean cancelled = false;

/**
* This event is called when a player's skin is about to be updated.
* It is called before the new skin options are applied to the player
Expand All @@ -26,13 +27,33 @@ public class PlayerObjectPreUpdateSkinEvent extends PlayerObjectUserEvent implem
* <p>The event is fired asynchronously by default.</p>
*
* @param playerObject The player object being updated.
* @param user The user associated with the player object, or null if the player is not a valid user.
* @param user The user associated with the player object.
* @param async Whether the event is asynchronous.
*/
public PlayerObjectPreUpdateSkinEvent(PlayerObject playerObject, UserManager.@Nullable User user, boolean async) {
public PlayerObjectPreUpdateSkinEvent(PlayerObject playerObject, UserManager.User user, boolean async) {
super(playerObject, user, async);
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}


@NotNull
@Override
Expand Down
Expand Up @@ -28,6 +28,7 @@ public class PlayerObjectUpdateSkinEvent extends PlayerObjectUserEvent implement
* The skin options of the player.
*/
private SkinOptions skinOptions;
private boolean cancelled = false;

/**
* Constructs a new PlayerObjectUpdateSkinEvent.
Expand Down Expand Up @@ -65,6 +66,26 @@ public void setSkinOptions(SkinOptions skinOptions) {
getUser().addCustomData("skinOptions", this.skinOptions = skinOptions);
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}

/**
* Returns a list of all registered handlers for this event.
*
Expand Down
Expand Up @@ -15,7 +15,7 @@ public class SPropertyAddEvent extends Event implements Cancellable {

private String propertyName;
private SProperty property;
private boolean cancelled;
private boolean cancelled = false;

/**
* Constructs a new SPropertyAddEvent with the given property name, SProperty, and whether the event should be run asynchronously.
Expand Down
Expand Up @@ -15,7 +15,7 @@ public class SPropertyRemoveEvent extends Event implements Cancellable {

private final String propertyName;
private final SProperty property;
private boolean cancelled;
private boolean cancelled = false;

/**
* Constructs a new SPropertyRemoveEvent with the given property name, SProperty, and whether the event should be run asynchronously.
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class UserEvent extends Event implements Cancellable {
/**
* Whether this event has been cancelled.
*/
private boolean cancelled;
private boolean cancelled = false;

/**
* Constructs a {@code UserEvent} with the specified user and asynchronous status.
Expand Down
Expand Up @@ -13,6 +13,8 @@ public class UserModifyDataEvent extends UserEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();

private boolean cancelled = false;

/**
* Constructs a {@code UserModifyDataEvent} with the specified user and asynchronous status.
*
Expand All @@ -23,6 +25,26 @@ public UserModifyDataEvent(@NotNull UserManager.User user, boolean async) {
super(user, async);
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down
Expand Up @@ -15,6 +15,7 @@ public class UserAddDataEvent extends UserModifyDataEvent implements Cancellable
private static final HandlerList handlers = new HandlerList();

private ObjectMap.Pair<String, ?> objectPair;
private boolean cancelled = false;

/**
* Constructs a {@code UserAddDataEvent} with the specified user, asynchronous status, and data.
Expand Down Expand Up @@ -46,6 +47,26 @@ public void setData(ObjectMap.Pair<String, ?> objectPair) {
this.objectPair = objectPair;
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down
Expand Up @@ -3,15 +3,18 @@
import com.georgev22.library.utilities.UserManager;
import com.georgev22.skinoverlay.event.HandlerList;
import com.georgev22.skinoverlay.event.events.user.UserEvent;
import com.georgev22.skinoverlay.event.interfaces.Cancellable;
import org.jetbrains.annotations.NotNull;

/**
* An event that is triggered after a user's data is loaded.
*/
public class UserPostLoadEvent extends UserEvent {
public class UserPostLoadEvent extends UserEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();

private boolean cancelled = false;

/**
* Constructs a {@code UserPostLoadEvent} with the specified user and asynchronous status.
*
Expand All @@ -22,6 +25,26 @@ public UserPostLoadEvent(@NotNull UserManager.User user, boolean async) {
super(user, async);
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down
Expand Up @@ -3,18 +3,20 @@
import com.georgev22.library.utilities.UserManager;
import com.georgev22.skinoverlay.event.HandlerList;
import com.georgev22.skinoverlay.event.events.user.UserEvent;
import com.georgev22.skinoverlay.event.interfaces.Cancellable;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

/**
* An event that is triggered before a user's data is loaded.
*/
public class UserPreLoadEvent extends UserEvent {
public class UserPreLoadEvent extends UserEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();

private final UUID uuid;
private boolean cancelled = false;

/**
* Constructs a {@code UserPreLoadEvent} with the specified UUID and asynchronous status.
Expand All @@ -36,6 +38,26 @@ public UUID getUUID() {
return uuid;
}

/**
* Cancels the event.
*
* @return {@code true} if the event was successfully cancelled, {@code false} otherwise
*/
@Override
public boolean cancel() {
return cancelled = true;
}

/**
* Returns whether the event has been cancelled.
*
* @return {@code true} if the event has been cancelled, {@code false} otherwise
*/
@Override
public boolean isCancelled() {
return cancelled;
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down

0 comments on commit 650df6b

Please sign in to comment.