Skip to content

Commit 4209237

Browse files
committed
Add RegisterFreezeEvent
Reserving Pre event for modifications, design tbd
1 parent 93d4552 commit 4209237

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.event.lifecycle;
26+
27+
import org.spongepowered.api.Engine;
28+
import org.spongepowered.api.ResourceKey;
29+
import org.spongepowered.api.event.GenericEvent;
30+
import org.spongepowered.api.registry.Registry;
31+
import org.spongepowered.api.registry.RegistryHolder;
32+
import org.spongepowered.api.registry.RegistryType;
33+
34+
import java.util.function.Consumer;
35+
36+
public interface RegisterFreezeEvent extends LifecycleEvent {
37+
38+
/**
39+
* Fired after a layer has established its registries
40+
* and is no longer accepting any type of modifications.
41+
*
42+
* <p><strong>Note:</strong> Layers might be reloadable!
43+
* When a registry is being reloaded, this event is fired
44+
* again for the relevant registries.</p>
45+
*/
46+
interface Post extends RegisterFreezeEvent {
47+
48+
/**
49+
* Gets the built {@link RegistryHolder registry holder}.
50+
*
51+
* @return The registry holder.
52+
*/
53+
RegistryHolder holder();
54+
55+
/**
56+
* <p>Fetch a registry by its type.</p>
57+
*
58+
* <p>The consumer will be called if it matches the current set of
59+
* registries being created.</p>
60+
*
61+
* @param registryType The registry type to fetch.
62+
* @param consumer The consumer to be called if found.
63+
*/
64+
default <T> void registry(RegistryType<T> registryType, Consumer<Registry<T>> consumer) {
65+
this.holder().findRegistry(registryType).ifPresent(consumer);
66+
}
67+
68+
interface GameScoped extends Post {
69+
}
70+
71+
interface EngineScoped<E extends Engine> extends Post, GenericEvent<E> {
72+
}
73+
74+
interface WorldScoped extends Post {
75+
76+
ResourceKey worldKey();
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)