Skip to content

Commit 911eb3a

Browse files
feat: Finished events
1 parent 597deab commit 911eb3a

17 files changed

+362
-127
lines changed

api/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dependencies {
2-
compileOnlyApi("studio.o7:octopus-plugin-api:0.0.1")
2+
compileOnlyApi("studio.o7:octopus-plugin-api:0.1.1")
33
}
44

55
information {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package studio.o7.cheetah.plugin.api.events;
2+
3+
import org.bukkit.event.Event;
4+
5+
public abstract class ProxyEvent extends Event {
6+
public ProxyEvent() {
7+
super(true);
8+
}
9+
}

api/src/main/java/studio/o7/cheetah/plugin/api/events/ProxyPlayerEvent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
import lombok.Getter;
44
import lombok.NonNull;
5-
import org.bukkit.event.Event;
65
import studio.o7.cheetah.plugin.api.player.ProxyPlayer;
76

87
@Getter
9-
public abstract class ProxyPlayerEvent extends Event {
8+
public abstract class ProxyPlayerEvent extends ProxyEvent {
109
private final ProxyPlayer player;
1110

1211
public ProxyPlayerEvent(@NonNull ProxyPlayer player) {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package studio.o7.cheetah.plugin.api.events;
2+
3+
import lombok.Getter;
4+
import lombok.NonNull;
5+
import lombok.RequiredArgsConstructor;
6+
import lombok.Setter;
7+
import net.kyori.adventure.resource.ResourcePackInfo;
8+
import org.bukkit.event.HandlerList;
9+
import org.jetbrains.annotations.NotNull;
10+
import studio.o7.cheetah.plugin.api.player.ProxyPlayer;
11+
12+
import java.util.Arrays;
13+
import java.util.Optional;
14+
15+
/**
16+
* {@link ProxyResourcePackStatusEvent} is fired when the status of a resource pack sent to the player by the server is
17+
* changed. Depending on the result of this event (which the proxy will wait until completely fired),
18+
* the player may be kicked from the network.
19+
*/
20+
@Getter
21+
public final class ProxyResourcePackStatusEvent extends ProxyPlayerEvent {
22+
private static final HandlerList HANDLER_LIST = new HandlerList();
23+
24+
@NonNull
25+
private final PackStatus status;
26+
@NonNull
27+
private final ResourcePackInfo info;
28+
29+
private boolean overrideKick = false;
30+
31+
public ProxyResourcePackStatusEvent(@NonNull ProxyPlayer player, @NonNull PackStatus status, @NonNull ResourcePackInfo info) {
32+
super(player);
33+
this.status = status;
34+
this.info = info;
35+
}
36+
37+
@Override
38+
public @NotNull HandlerList getHandlers() {
39+
return HANDLER_LIST;
40+
}
41+
42+
public static HandlerList getHandlerList() {
43+
return HANDLER_LIST;
44+
}
45+
46+
/**
47+
* Method can set to true to prevent ResourcePackInfo.ShouldForce()
48+
* from kicking the player. Overwriting this kick is only possible on versions older than 1.17,
49+
* as the client or server will enforce this regardless. Cancelling the resulting
50+
* kick-events will not prevent the player from disconnecting from the proxy.
51+
*/
52+
public void setOverrideKick(boolean overrideKick) {
53+
this.overrideKick = overrideKick;
54+
}
55+
56+
@RequiredArgsConstructor
57+
@Getter
58+
public enum PackStatus {
59+
SUCCESSFUL_RESPONSE("successful"),
60+
DECLINED_RESPONSE("declined"),
61+
FAILED_DOWNLOAD_RESPONSE("failed_download"),
62+
ACCEPTED_RESPONSE("accepted"),
63+
DOWNLOADED_RESPONSE("downloaded"),
64+
INVALID_URL_RESPONSE("invalid_url"),
65+
FAILED_TO_RELOAD_RESPONSE("failed_reload"),
66+
DISCARDED_RESPONSE("discarded");
67+
68+
private final String name;
69+
70+
public static Optional<PackStatus> getStatusByName(@NonNull String name) {
71+
return Arrays.stream(values()).filter(status -> status.name.equalsIgnoreCase(name)).findAny();
72+
}
73+
}
74+
}

api/src/main/java/studio/o7/cheetah/plugin/api/events/ProxyServerResourcePackSendEvent.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

api/src/main/java/studio/o7/cheetah/plugin/api/events/cookies/ProxyCookieReceiveEvent.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

api/src/main/java/studio/o7/cheetah/plugin/api/events/cookies/ProxyCookieRequestEvent.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

api/src/main/java/studio/o7/cheetah/plugin/api/events/cookies/ProxyCookieStoreEvent.java

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
package studio.o7.cheetah.plugin.api.events.server;
22

3+
import lombok.Getter;
34
import lombok.NonNull;
5+
import net.kyori.adventure.text.Component;
46
import org.bukkit.event.HandlerList;
57
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
69
import studio.o7.cheetah.plugin.api.events.ProxyPlayerEvent;
710
import studio.o7.cheetah.plugin.api.player.ProxyPlayer;
11+
import studio.o7.cheetah.plugin.api.server.ProxyServer;
812

913
/**
1014
* Fired when a player is kicked from a server. You may either allow the proxy to kick the player
1115
* (with an optional reason override) or redirect the player to a separate server. By default,
1216
* the proxy will notify the user (if they are already connected to a server) or disconnect them
1317
* (if they are not on a server and no other servers are available).
1418
*/
19+
@Getter
1520
public final class ProxyKickedFromServerEvent extends ProxyPlayerEvent {
1621
private static final HandlerList HANDLER_LIST = new HandlerList();
1722

18-
public ProxyKickedFromServerEvent(@NonNull ProxyPlayer player) {
23+
@NonNull
24+
private final ProxyServer server;
25+
@Nullable
26+
private final Component originalReason;
27+
private final boolean duringServerConnect;
28+
29+
30+
public ProxyKickedFromServerEvent(@NonNull ProxyPlayer player, @NonNull ProxyServer server, @Nullable Component originalReason, boolean duringServerConnect) {
1931
super(player);
32+
this.server = server;
33+
this.originalReason = originalReason;
34+
this.duringServerConnect = duringServerConnect;
2035
}
2136

2237
@Override
@@ -27,7 +42,4 @@ public ProxyKickedFromServerEvent(@NonNull ProxyPlayer player) {
2742
public static HandlerList getHandlerList() {
2843
return HANDLER_LIST;
2944
}
30-
31-
32-
3345
}

api/src/main/java/studio/o7/cheetah/plugin/api/events/server/ProxyServerConnectedEvent.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package studio.o7.cheetah.plugin.api.events.server;
22

3+
import lombok.Getter;
34
import lombok.NonNull;
45
import org.bukkit.event.HandlerList;
56
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Nullable;
68
import studio.o7.cheetah.plugin.api.events.ProxyPlayerEvent;
79
import studio.o7.cheetah.plugin.api.player.ProxyPlayer;
10+
import studio.o7.cheetah.plugin.api.server.ProxyServer;
811

912
/**
1013
* {@link ProxyServerConnectedEvent} is fired before the player completely transitions
@@ -13,11 +16,19 @@
1316
* Use Server to get the target server since {@link ProxyPlayer#getCurrentServer} is yet Empty or
1417
* listen for {@link ProxyServerPostConnectEvent} instead.
1518
*/
19+
@Getter
1620
public final class ProxyServerConnectedEvent extends ProxyPlayerEvent {
1721
private static final HandlerList HANDLER_LIST = new HandlerList();
1822

19-
public ProxyServerConnectedEvent(@NonNull ProxyPlayer player) {
23+
@NonNull
24+
private final ProxyServer server;
25+
@Nullable
26+
private final ProxyServer previousServer;
27+
28+
public ProxyServerConnectedEvent(@NonNull ProxyPlayer player, @NonNull ProxyServer server, @Nullable ProxyServer previousServer) {
2029
super(player);
30+
this.server = server;
31+
this.previousServer = previousServer;
2132
}
2233

2334
@Override

0 commit comments

Comments
 (0)