-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
407 additions
and
59 deletions.
There are no files selected for viewing
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
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
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
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,81 @@ | ||
package live.crowdcontrol.cc4j; | ||
|
||
import io.leangen.geantyref.TypeToken; | ||
import live.crowdcontrol.cc4j.websocket.payload.PublicEffectPayload; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Objects; | ||
|
||
public class CCEventType<T> { | ||
private final @NotNull String listenerId; | ||
private final @NotNull TypeToken<T> typeToken; | ||
|
||
public CCEventType(@NotNull String listenerId, @NotNull TypeToken<T> typeToken) { | ||
this.listenerId = listenerId; | ||
this.typeToken = typeToken; | ||
} | ||
|
||
public CCEventType(@NotNull String listenerId, @NotNull Class<T> clazz) { | ||
this(listenerId, TypeToken.get(clazz)); | ||
} | ||
|
||
public static CCEventType<Void> ofVoid(@NotNull String listenerId) { | ||
return new CCEventType<>(listenerId, Void.class); | ||
} | ||
|
||
public @NotNull String getListenerId() { | ||
return listenerId; | ||
} | ||
|
||
public @NotNull TypeToken<T> getTypeToken() { | ||
return typeToken; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
CCEventType<?> that = (CCEventType<?>) o; | ||
return Objects.equals(listenerId, that.listenerId) && Objects.equals(typeToken, that.typeToken); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(listenerId, typeToken); | ||
} | ||
|
||
/** | ||
* Called when a player's WebSocket initially establishes its connection. | ||
* The connectionID will be unavailable at this point. | ||
*/ | ||
public static final CCEventType<Void> CONNECTION = ofVoid("connection"); | ||
|
||
/** | ||
* Called when a player's WebSocket connectionID becomes known. | ||
*/ | ||
public static final CCEventType<Void> IDENTIFIED = ofVoid("identified"); | ||
|
||
/** | ||
* Called when a player's WebSocket becomes authenticated. | ||
* The connectionID may be unavailable at this point. | ||
*/ | ||
public static final CCEventType<Void> AUTHENTICATED = ofVoid("authenticated"); | ||
|
||
/** | ||
* Called when a player's authentication token expires. | ||
* This may happen if they have not re-authenticated in about 6 months. | ||
*/ | ||
public static final CCEventType<Void> AUTH_EXPIRED = ofVoid("auth_expired"); | ||
|
||
/** | ||
* Called when a player's auth token is removed for any reason. | ||
* Shares overlap with {@link #AUTH_EXPIRED}. | ||
*/ | ||
public static final CCEventType<Void> UNAUTHENTICATED = ofVoid("unauthenticated"); | ||
|
||
/** | ||
* Called when an {@code effect-request} on the {@code pub} domain comes in from the player. | ||
* Note that the traditional way to receive this information is via {@link CCEffect#onTrigger(PublicEffectPayload, CCPlayer)}. | ||
*/ | ||
public static final CCEventType<PublicEffectPayload> PUB_EFFECT_REQUEST = new CCEventType<>("pub_effect_request", PublicEffectPayload.class); | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,16 @@ | ||
package live.crowdcontrol.cc4j; | ||
|
||
import live.crowdcontrol.cc4j.websocket.payload.PublicEffectPayload; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface CCTimedEffect extends CCEffect { | ||
|
||
/** | ||
* Pauses this effect. | ||
*/ | ||
void onPause(@NotNull PublicEffectPayload request, @NotNull CCPlayer source); | ||
|
||
/** | ||
* Resumes this effect. | ||
*/ | ||
} |
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
Oops, something went wrong.