generated from minecraft-cursed-legacy/Example-Mod
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
1 parent
81a0a05
commit 1c213d9
Showing
21 changed files
with
479 additions
and
40 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 was deleted.
Oops, something went wrong.
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,6 @@ | ||
archivesBaseName = 'legacy-lifecycle-events-v1' | ||
version = getSubprojectVersion(project, '1.0.0') | ||
|
||
moduleDependencies(project, 'legacy-api-base') | ||
dependencies { | ||
} |
66 changes: 66 additions & 0 deletions
66
.../main/java/io/github/minecraftcursedlegacy/api/event/lifecycle/ClientLifecycleEvents.java
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,66 @@ | ||
/* | ||
* Copyright (c) 2020 The Cursed Legacy Team. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package io.github.minecraftcursedlegacy.api.event.lifecycle; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.client.Minecraft; | ||
|
||
/** | ||
* Lifecycle events for the client. | ||
* @since 1.1.0 | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
public class ClientLifecycleEvents { | ||
/** | ||
* Event for the start of the client tick. | ||
*/ | ||
public static final Event<Tick> START_TICK = EventFactory.createArrayBacked(Tick.class, | ||
listeners -> client -> { | ||
for (Tick listener : listeners) { | ||
listener.onClientTick(client); | ||
} | ||
}); | ||
|
||
/** | ||
* Event for the end of the client tick. | ||
*/ | ||
public static final Event<Tick> END_TICK = EventFactory.createArrayBacked(Tick.class, | ||
listeners -> client -> { | ||
for (Tick listener : listeners) { | ||
listener.onClientTick(client); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface Tick { | ||
/** | ||
* Called when the client ticks. | ||
* @param client the minecraft client instance. | ||
*/ | ||
void onClientTick(Minecraft client); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
.../main/java/io/github/minecraftcursedlegacy/api/event/lifecycle/CommonLifecycleEvents.java
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,53 @@ | ||
/* | ||
* Copyright (c) 2020 The Cursed Legacy Team. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package io.github.minecraftcursedlegacy.api.event.lifecycle; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.entity.player.Player; | ||
|
||
/** | ||
* Collection of common events that pertain to the game lifecycle. | ||
* @since 1.1.0 | ||
*/ | ||
public class CommonLifecycleEvents { | ||
/** | ||
* Event for the player respawning. | ||
*/ | ||
public static final Event<PlayerRespawn> PLAYER_RESPAWN = EventFactory.createArrayBacked(PlayerRespawn.class, | ||
listeners -> player -> { | ||
for (PlayerRespawn listener : listeners) { | ||
listener.onRespawn(player); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface PlayerRespawn { | ||
/** | ||
* Called after the player respawns. | ||
* @param player the player that has respawned. | ||
*/ | ||
void onRespawn(Player player); | ||
} | ||
} |
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
115 changes: 115 additions & 0 deletions
115
.../main/java/io/github/minecraftcursedlegacy/api/event/lifecycle/ServerLifecycleEvents.java
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,115 @@ | ||
/* | ||
* Copyright (c) 2020 The Cursed Legacy Team. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package io.github.minecraftcursedlegacy.api.event.lifecycle; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ServerLoginPacketHandler; | ||
import net.minecraft.server.player.ServerPlayer; | ||
|
||
/** | ||
* Lifecycle events for the server. | ||
* @since 1.1.0 | ||
* @apiNote Remember: None of these events run in singleplayer! | ||
*/ | ||
@Environment(EnvType.SERVER) | ||
public class ServerLifecycleEvents { | ||
/** | ||
* Event for the start of the dedicated server tick. | ||
*/ | ||
public static final Event<Tick> START_TICK = EventFactory.createArrayBacked(Tick.class, | ||
listeners -> server -> { | ||
for (Tick listener : listeners) { | ||
listener.onServerTick(server); | ||
} | ||
}); | ||
|
||
/** | ||
* Event for the end of the dedicated server tick. | ||
*/ | ||
public static final Event<Tick> END_TICK = EventFactory.createArrayBacked(Tick.class, | ||
listeners -> server -> { | ||
for (Tick listener : listeners) { | ||
listener.onServerTick(server); | ||
} | ||
}); | ||
|
||
/** | ||
* Event for a player logging in to the server. | ||
*/ | ||
public static final Event<PlayerLogin> PLAYER_LOGIN = EventFactory.createArrayBacked(PlayerLogin.class, | ||
listeners -> (player, packetHandler) -> { | ||
for (PlayerLogin listener : listeners) { | ||
listener.onPlayerLogin(player, packetHandler); | ||
|
||
// In case a mod's listener has disconnected the player for some reason | ||
// This is the equivalent of cancelling the login, but with vanilla functionality handling it. | ||
if (packetHandler.closed) { | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
/** | ||
* Event for a player being disconnected / disconnecting from the server | ||
*/ | ||
public static final Event<PlayerDisconnect> PLAYER_DISCONNECT = EventFactory.createArrayBacked(PlayerDisconnect.class, | ||
listeners -> player -> { | ||
for (PlayerDisconnect listener : listeners) { | ||
listener.onPlayerDisconnect(player); | ||
} | ||
}); | ||
|
||
@FunctionalInterface | ||
public interface Tick { | ||
/** | ||
* Called when the dedicated server ticks. | ||
* @param server the dedicated server instance. | ||
*/ | ||
void onServerTick(MinecraftServer server); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface PlayerLogin { | ||
/** | ||
* Called when a player successfully logs in to the server. | ||
* @param player the player that has just logged in. | ||
* @param packetHandler the login packetHandler. | ||
* @apiNote {@linkplain ServerLoginPacketHandler#drop(String)} can be used to prevent the player connecting. | ||
*/ | ||
void onPlayerLogin(ServerPlayer player, ServerLoginPacketHandler packetHandler); | ||
} | ||
|
||
@FunctionalInterface | ||
public interface PlayerDisconnect { | ||
/** | ||
* Called when a player disconnects from the server. | ||
* @param player the player that has disconnected. | ||
*/ | ||
void onPlayerDisconnect(ServerPlayer player); | ||
} | ||
} |
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.