Skip to content

Commit ef26c50

Browse files
committed
Add documentation for game events
1 parent 9e681c7 commit ef26c50

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

src/main/java/net/minestom/server/game/GameEvent.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,59 @@
99

1010
import java.util.Collection;
1111

12+
/**
13+
* Represents a game event.
14+
* Used for a wide variety of events, from weather to bed use to game mode to demo messages.
15+
*
16+
* @version 1.0.0
17+
* @since 1.6.0
18+
* @author themeinerlp
19+
*/
1220
public sealed interface GameEvent extends StaticProtocolObject permits GameEventImpl {
1321

1422
/**
15-
* Returns the entity registry.
23+
* Returns the game event registry.
1624
*
17-
* @return the entity registry or null if it was created with a builder
25+
* @return the game event registry or null if not found
1826
*/
1927
@Contract(pure = true)
2028
@Nullable
2129
Registry.GameEventEntry registry();
2230

31+
/**
32+
* Gets the namespace ID of this game event.
33+
*
34+
* @return the namespace ID
35+
*/
2336
@Override
2437
@NotNull
2538
NamespaceID namespace();
2639

40+
/**
41+
* Gets the game events from the registry.
42+
*
43+
* @return the game events
44+
*/
2745
static @NotNull Collection<@NotNull GameEvent> values() {
2846
return GameEventImpl.values();
2947
}
3048

49+
/**
50+
* Gets a game event by its namespace ID.
51+
*
52+
* @param namespaceID the namespace ID
53+
* @return the game event or null if not found
54+
*/
3155
static @Nullable GameEvent fromNamespaceId(@NotNull String namespaceID) {
3256
return GameEventImpl.getSafe(namespaceID);
3357
}
3458

59+
/**
60+
* Gets a game event by its namespace ID.
61+
*
62+
* @param namespaceID the namespace ID
63+
* @return the game event or null if not found
64+
*/
3565
static @Nullable GameEvent fromNamespaceId(@NotNull NamespaceID namespaceID) {
3666
return fromNamespaceId(namespaceID.asString());
3767
}

src/main/java/net/minestom/server/game/GameEventImpl.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,63 @@
77
import java.util.Collection;
88
import java.util.concurrent.atomic.AtomicInteger;
99

10-
public record GameEventImpl(Registry.GameEventEntry registry, NamespaceID namespace, int id) implements GameEvent {
10+
/**
11+
* Represents a game event implementation.
12+
* Used for a wide variety of events, from weather to bed use to game mode to demo messages.
13+
*
14+
* @version 1.0.0
15+
* @since 1.6.0
16+
* @author themeinerlp
17+
*/
18+
record GameEventImpl(Registry.GameEventEntry registry, NamespaceID namespace, int id) implements GameEvent {
1119
private static final AtomicInteger INDEX = new AtomicInteger();
1220
private static final Registry.Container<GameEvent> CONTAINER = Registry.createStaticContainer(Registry.Resource.GAMEPLAY_TAGS, GameEventImpl::createImpl);
1321

22+
/**
23+
* Creates a new {@link GameEventImpl} with the given namespace and properties.
24+
*
25+
* @param namespace the namespace
26+
* @param properties the properties
27+
* @return a new {@link GameEventImpl}
28+
*/
1429
private static GameEventImpl createImpl(String namespace, Registry.Properties properties) {
1530
return new GameEventImpl(Registry.gameEventEntry(namespace, properties));
1631
}
1732

33+
/**
34+
* Creates a new {@link GameEventImpl} with the given registry.
35+
*
36+
* @param registry the registry
37+
*/
1838
private GameEventImpl(Registry.GameEventEntry registry) {
1939
this(registry, registry.namespace(), INDEX.getAndIncrement());
2040
}
2141

42+
/**
43+
* Gets the game events from the registry.
44+
*
45+
* @return the game events
46+
*/
2247
static Collection<GameEvent> values() {
2348
return CONTAINER.values();
2449
}
2550

51+
/**
52+
* Gets a game event by its namespace ID.
53+
*
54+
* @param namespace the namespace ID
55+
* @return the game event or null if not found
56+
*/
2657
public static GameEvent get(@NotNull String namespace) {
2758
return CONTAINER.get(namespace);
2859
}
2960

61+
/**
62+
* Gets a game event by its namespace ID.
63+
*
64+
* @param namespace the namespace ID
65+
* @return the game event or null if not found
66+
*/
3067
static GameEvent getSafe(@NotNull String namespace) {
3168
return CONTAINER.getSafe(namespace);
3269
}

src/main/java/net/minestom/server/registry/StaticProtocolObject.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,50 @@
66
import org.jetbrains.annotations.Contract;
77
import org.jetbrains.annotations.NotNull;
88

9+
/**
10+
* Represents a static protocol object.
11+
* Used for objects which are not dynamic and are known at compile time.
12+
*
13+
* @version 1.0.0
14+
* @since 1.0.0
15+
* @author themeinerlp
16+
*/
917
public interface StaticProtocolObject extends ProtocolObject, Keyed {
1018

19+
/**
20+
* Gets the namespace ID of this object.
21+
*
22+
* @return the namespace ID
23+
*/
1124
@Contract(pure = true)
1225
@NotNull NamespaceID namespace();
1326

27+
/**
28+
* Gets the name of this object.
29+
*
30+
* @return the name
31+
*/
1432
@Contract(pure = true)
1533
default @NotNull String name() {
1634
return namespace().asString();
1735
}
1836

37+
/**
38+
* Gets the key of this object.
39+
*
40+
* @return the key
41+
*/
1942
@Override
2043
@Contract(pure = true)
2144
default @NotNull Key key() {
2245
return namespace();
2346
}
2447

48+
/**
49+
* Gets the ID of this object.
50+
*
51+
* @return the ID
52+
*/
2553
@Contract(pure = true)
2654
int id();
2755
}

0 commit comments

Comments
 (0)