Skip to content

Commit 1c213d9

Browse files
authored
Lifecycle Events v1 (#38)
* 1.0.0 lifecycle events start * update existing events to v1 * lifecycle v1 good * fix * fix my workspaces and update config api to use halfmaven * shut up compileTestJava
1 parent 81a0a05 commit 1c213d9

File tree

21 files changed

+479
-40
lines changed

21 files changed

+479
-40
lines changed

build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ allprojects {
7373
name = 'Jitpack'
7474
url 'https://jitpack.io/'
7575
}
76+
maven {
77+
name = 'HalfOf2'
78+
url = 'https://storage.googleapis.com/devan-maven/'
79+
}
7680
}
7781

7882
configurations {
@@ -94,11 +98,9 @@ allprojects {
9498
//to change the versions see the gradle.properties file
9599
minecraft "com.mojang:minecraft:${project.minecraft_version}"
96100

97-
mappings loom.fromCommit('minecraft-cursed-legacy/Plasma', "build.${project.plasma_build}") {spec ->
98-
spec.version = "b1.7.3-${project.plasma_build}"
99-
}
101+
mappings "io.github.minecraft-cursed-legacy:plasma:b1.7.3-build.${project.plasma_build}"
100102

101-
modImplementation("com.github.minecraft-cursed-legacy:cursed-fabric-loader:${project.loader_version}") {
103+
modImplementation("io.github.minecraft-cursed-legacy:cursed-fabric-loader:${project.loader_version}") {
102104
transitive false //Avoid leaking Loader's dependencies forwards
103105
}
104106

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
minecraft_version=b1.7.3
6-
loader_version=5ce86c8
6+
loader_version=1.0.0
77
plasma_build=18
88

99
# Mod Properties
10-
mod_version = 1.0.6
10+
mod_version = 1.1.0
1111
maven_group = io.github.minecraftcursedlegacy
1212
archives_base_name = cursed-legacy-api

legacy-config-v0/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply plugin: 'java-library'
55

66
moduleDependencies(project, 'legacy-api-base')
77
dependencies {
8-
include api('com.github.valoeghese:ZoesteriaConfig:1.3.6')
8+
include api('valoeghese:ZoesteriaConfig:1.3.6')
99
}
1010

1111
minecraft {

legacy-lifecycle-events-v0/build.gradle

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
archivesBaseName = 'legacy-lifecycle-events-v1'
2+
version = getSubprojectVersion(project, '1.0.0')
3+
4+
moduleDependencies(project, 'legacy-api-base')
5+
dependencies {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2020 The Cursed Legacy Team.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
package io.github.minecraftcursedlegacy.api.event.lifecycle;
25+
26+
import net.fabricmc.api.EnvType;
27+
import net.fabricmc.api.Environment;
28+
import net.fabricmc.fabric.api.event.Event;
29+
import net.fabricmc.fabric.api.event.EventFactory;
30+
import net.minecraft.client.Minecraft;
31+
32+
/**
33+
* Lifecycle events for the client.
34+
* @since 1.1.0
35+
*/
36+
@Environment(EnvType.CLIENT)
37+
public class ClientLifecycleEvents {
38+
/**
39+
* Event for the start of the client tick.
40+
*/
41+
public static final Event<Tick> START_TICK = EventFactory.createArrayBacked(Tick.class,
42+
listeners -> client -> {
43+
for (Tick listener : listeners) {
44+
listener.onClientTick(client);
45+
}
46+
});
47+
48+
/**
49+
* Event for the end of the client tick.
50+
*/
51+
public static final Event<Tick> END_TICK = EventFactory.createArrayBacked(Tick.class,
52+
listeners -> client -> {
53+
for (Tick listener : listeners) {
54+
listener.onClientTick(client);
55+
}
56+
});
57+
58+
@FunctionalInterface
59+
public interface Tick {
60+
/**
61+
* Called when the client ticks.
62+
* @param client the minecraft client instance.
63+
*/
64+
void onClientTick(Minecraft client);
65+
}
66+
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@
2424
package io.github.minecraftcursedlegacy.api.event.lifecycle;
2525

2626
import net.fabricmc.fabric.api.event.Event;
27-
import net.fabricmc.fabric.api.event.EventFactory;
2827
import net.minecraft.client.Minecraft;
2928

3029
/**
3130
* Callback for ticks on the client.
31+
* @deprecated use {@linkplain ClientLifecycleEvents#END_TICK} instead.
3232
*/
3333
@FunctionalInterface
34-
public interface ClientTickCallback {
35-
Event<ClientTickCallback> EVENT = EventFactory.createArrayBacked(ClientTickCallback.class,
36-
listeners -> client -> {
37-
for (ClientTickCallback listener : listeners) {
38-
listener.onClientTick(client);
39-
}
40-
});
34+
@Deprecated
35+
public interface ClientTickCallback extends ClientLifecycleEvents.Tick {
36+
Event<ClientLifecycleEvents.Tick> EVENT = ClientLifecycleEvents.END_TICK;
4137

4238
/**
4339
* Called when the client ticks.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020 The Cursed Legacy Team.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
package io.github.minecraftcursedlegacy.api.event.lifecycle;
25+
26+
import net.fabricmc.fabric.api.event.Event;
27+
import net.fabricmc.fabric.api.event.EventFactory;
28+
import net.minecraft.entity.player.Player;
29+
30+
/**
31+
* Collection of common events that pertain to the game lifecycle.
32+
* @since 1.1.0
33+
*/
34+
public class CommonLifecycleEvents {
35+
/**
36+
* Event for the player respawning.
37+
*/
38+
public static final Event<PlayerRespawn> PLAYER_RESPAWN = EventFactory.createArrayBacked(PlayerRespawn.class,
39+
listeners -> player -> {
40+
for (PlayerRespawn listener : listeners) {
41+
listener.onRespawn(player);
42+
}
43+
});
44+
45+
@FunctionalInterface
46+
public interface PlayerRespawn {
47+
/**
48+
* Called after the player respawns.
49+
* @param player the player that has respawned.
50+
*/
51+
void onRespawn(Player player);
52+
}
53+
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@
2424
package io.github.minecraftcursedlegacy.api.event.lifecycle;
2525

2626
import net.fabricmc.fabric.api.event.Event;
27-
import net.fabricmc.fabric.api.event.EventFactory;
2827
import net.minecraft.server.MinecraftServer;
2928

3029
/**
3130
* Callback for ticks on the dedicated server. Does *not* run in singleplayer!
31+
* @deprecated use {@linkplain ServerLifecycleEvents#END_TICK} instead.
3232
*/
3333
@FunctionalInterface
34-
public interface DedicatedServerTickCallback {
35-
Event<DedicatedServerTickCallback> EVENT = EventFactory.createArrayBacked(DedicatedServerTickCallback.class,
36-
listeners -> server -> {
37-
for (DedicatedServerTickCallback listener : listeners) {
38-
listener.onServerTick(server);
39-
}
40-
});
34+
@Deprecated
35+
public interface DedicatedServerTickCallback extends ServerLifecycleEvents.Tick {
36+
Event<ServerLifecycleEvents.Tick> EVENT = ServerLifecycleEvents.END_TICK;
4137

4238
/**
4339
* Called when the dedicated server ticks.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright (c) 2020 The Cursed Legacy Team.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*/
23+
24+
package io.github.minecraftcursedlegacy.api.event.lifecycle;
25+
26+
import net.fabricmc.api.EnvType;
27+
import net.fabricmc.api.Environment;
28+
import net.fabricmc.fabric.api.event.Event;
29+
import net.fabricmc.fabric.api.event.EventFactory;
30+
import net.minecraft.server.MinecraftServer;
31+
import net.minecraft.server.network.ServerLoginPacketHandler;
32+
import net.minecraft.server.player.ServerPlayer;
33+
34+
/**
35+
* Lifecycle events for the server.
36+
* @since 1.1.0
37+
* @apiNote Remember: None of these events run in singleplayer!
38+
*/
39+
@Environment(EnvType.SERVER)
40+
public class ServerLifecycleEvents {
41+
/**
42+
* Event for the start of the dedicated server tick.
43+
*/
44+
public static final Event<Tick> START_TICK = EventFactory.createArrayBacked(Tick.class,
45+
listeners -> server -> {
46+
for (Tick listener : listeners) {
47+
listener.onServerTick(server);
48+
}
49+
});
50+
51+
/**
52+
* Event for the end of the dedicated server tick.
53+
*/
54+
public static final Event<Tick> END_TICK = EventFactory.createArrayBacked(Tick.class,
55+
listeners -> server -> {
56+
for (Tick listener : listeners) {
57+
listener.onServerTick(server);
58+
}
59+
});
60+
61+
/**
62+
* Event for a player logging in to the server.
63+
*/
64+
public static final Event<PlayerLogin> PLAYER_LOGIN = EventFactory.createArrayBacked(PlayerLogin.class,
65+
listeners -> (player, packetHandler) -> {
66+
for (PlayerLogin listener : listeners) {
67+
listener.onPlayerLogin(player, packetHandler);
68+
69+
// In case a mod's listener has disconnected the player for some reason
70+
// This is the equivalent of cancelling the login, but with vanilla functionality handling it.
71+
if (packetHandler.closed) {
72+
break;
73+
}
74+
}
75+
});
76+
77+
/**
78+
* Event for a player being disconnected / disconnecting from the server
79+
*/
80+
public static final Event<PlayerDisconnect> PLAYER_DISCONNECT = EventFactory.createArrayBacked(PlayerDisconnect.class,
81+
listeners -> player -> {
82+
for (PlayerDisconnect listener : listeners) {
83+
listener.onPlayerDisconnect(player);
84+
}
85+
});
86+
87+
@FunctionalInterface
88+
public interface Tick {
89+
/**
90+
* Called when the dedicated server ticks.
91+
* @param server the dedicated server instance.
92+
*/
93+
void onServerTick(MinecraftServer server);
94+
}
95+
96+
@FunctionalInterface
97+
public interface PlayerLogin {
98+
/**
99+
* Called when a player successfully logs in to the server.
100+
* @param player the player that has just logged in.
101+
* @param packetHandler the login packetHandler.
102+
* @apiNote {@linkplain ServerLoginPacketHandler#drop(String)} can be used to prevent the player connecting.
103+
*/
104+
void onPlayerLogin(ServerPlayer player, ServerLoginPacketHandler packetHandler);
105+
}
106+
107+
@FunctionalInterface
108+
public interface PlayerDisconnect {
109+
/**
110+
* Called when a player disconnects from the server.
111+
* @param player the player that has disconnected.
112+
*/
113+
void onPlayerDisconnect(ServerPlayer player);
114+
}
115+
}

0 commit comments

Comments
 (0)