Skip to content

Commit 23cbb6d

Browse files
committed
implement minestom properties & finish docs
1 parent 5a71210 commit 23cbb6d

File tree

6 files changed

+172
-19
lines changed

6 files changed

+172
-19
lines changed

docs/developers/minestom.mdx

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Tab, Tabs } from 'nextra-theme-docs';
2+
import { Callout } from 'nextra-theme-docs'
23

34
# Apollo for Minestom
45

@@ -51,14 +52,14 @@ Next, add the `apollo-minestom` dependency to your project.
5152
<Tab>
5253
```kotlin filename="build.gradle.kts"
5354
dependencies {
54-
implementation("com.lunarclient:apollo-minestom:1.1.9")
55+
implementation("com.lunarclient:apollo-minestom:1.2.0")
5556
}
5657
```
5758
</Tab>
5859
<Tab>
5960
```groovy filename="build.gradle"
6061
dependencies {
61-
implementation 'com.lunarclient:apollo-minestom:1.1.9'
62+
implementation 'com.lunarclient:apollo-minestom:1.2.0'
6263
}
6364
```
6465
</Tab>
@@ -68,7 +69,7 @@ Next, add the `apollo-minestom` dependency to your project.
6869
<dependency>
6970
<groupId>com.lunarclient</groupId>
7071
<artifactId>apollo-minestom</artifactId>
71-
<version>1.1.9</version>
72+
<version>1.2.0</version>
7273
<scope>compile</scope>
7374
</dependency>
7475
</dependencies>
@@ -78,7 +79,7 @@ Next, add the `apollo-minestom` dependency to your project.
7879

7980
## Initialization
8081

81-
To initialize Apollo, simply call `ApolloMinestomPlatform.init()` in your server's startup code, before you start the server. This will set up all the necessary listeners and modules.
82+
To initialize Apollo, simply call `ApolloMinestomPlatform.init(ApolloMinestomProperties.DEFAULT_PROPERTIES)` in your server's startup code, before you start the server. This will set up all the necessary listeners and modules.
8283

8384
Here is an example of a simple Minestom server with Apollo integrated:
8485

@@ -87,6 +88,7 @@ package com.lunarclient.apollo.example;
8788

8889
import com.lunarclient.apollo.Apollo;
8990
import com.lunarclient.apollo.ApolloMinestomPlatform;
91+
import com.lunarclient.apollo.ApolloMinestomProperties;
9092
import com.lunarclient.apollo.common.location.ApolloBlockLocation;
9193
import com.lunarclient.apollo.event.EventBus;
9294
import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent;
@@ -116,7 +118,7 @@ public final class ApolloMinestomExample {
116118
eventHandler.addListener(AsyncPlayerConfigurationEvent.class, event -> event.setSpawningInstance(instance));
117119

118120
// Initialize Apollo
119-
ApolloMinestomPlatform.init();
121+
ApolloMinestomPlatform.init(ApolloMinestomProperties.DEFAULT_PROPERTIES);
120122

121123
// Display a Apollo Waypoint example
122124
EventBus.getBus().register(ApolloRegisterPlayerEvent.class, event -> {
@@ -146,10 +148,49 @@ public final class ApolloMinestomExample {
146148
}
147149
```
148150

151+
## Properties
152+
153+
Apollo exposes several properties to configure its behavior at startup. By default, you can simply call `ApolloMinestomPlatform.init(ApolloMinestomProperties.DEFAULT_PROPERTIES)`. However, there are situations where you may not want to rely on the defaults:
154+
155+
`sendRegisterPacket` (default: `true`)
156+
157+
Unlike Bukkit/Spigot, Minestom does **not** maintain a global registry of plugin channels. This means there is no automatic tracking or registration of channels, so Apollo must explicitly send the `minecraft:register` packet to let the client know about its channel (`lunar:apollo`).
158+
159+
By default, `sendRegisterPacket` is set to `true`, and Apollo will send this packet automatically.
160+
161+
<Callout type="warning" emoji="⚠️">
162+
If you disable this, you must ensure your server or another plugin sends the `lunar:apollo` channel registration manually.
163+
</Callout>
164+
165+
To disable this behavior, set the property to false:
166+
167+
```java
168+
sendRegisterPacket(false)
169+
```
170+
171+
`configPath` (default: `./Apollo/`)
172+
173+
By default, Apollo stores its configuration in an Apollo folder at the root of your server directory.
174+
If you want Apollo’s config files to live elsewhere (e.g., inside a configs/ folder you already manage), override this value.
175+
176+
```java
177+
configPath(/* Your config path */)
178+
```
179+
180+
The final initialization call with both properties overridden may look like this:
181+
182+
```java
183+
ApolloMinestomPlatform.init(ApolloMinestomProperties.builder()
184+
.sendRegisterPacket(false)
185+
.configPath(/* Your config path here */)
186+
.build());
187+
```
188+
189+
149190
## Permissions
150191

151192
Since Minestom does not have a traditional permissions system, Apollo uses Minestom's built-in permission levels. Here are the default permission levels required for various features:
152193

153-
- **`/apollo <reload|update>`**: `level 2`
154-
- **`/lunarclient <player>`**: `level 2`
155-
- **Receive Apollo update notifications**: `level 4`
194+
- `/apollo <reload|update>`: `2`
195+
- `/lunarclient <player>`: `2`
196+
- Receive Apollo update notifications: `4`

example/minestom/api/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ dependencies {
1313

1414
implementation(libs.minestom)
1515
}
16+
17+
tasks {
18+
jar {
19+
manifest {
20+
attributes["Main-Class"] = "com.lunarclient.apollo.example.ApolloMinestomExample"
21+
}
22+
}
23+
}

example/minestom/api/src/main/java/com/lunarclient/apollo/example/ApolloMinestomExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.lunarclient.apollo.Apollo;
2727
import com.lunarclient.apollo.ApolloMinestomPlatform;
28+
import com.lunarclient.apollo.ApolloMinestomProperties;
2829
import com.lunarclient.apollo.common.location.ApolloBlockLocation;
2930
import com.lunarclient.apollo.event.EventBus;
3031
import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent;
@@ -59,7 +60,7 @@ public static void main(String[] args) {
5960
});
6061

6162
// Initialize Apollo
62-
ApolloMinestomPlatform.init();
63+
ApolloMinestomPlatform.init(ApolloMinestomProperties.DEFAULT_PROPERTIES);
6364

6465
// Display a Apollo Waypoint example
6566
EventBus.getBus().register(ApolloRegisterPlayerEvent.class, event -> {

minestom/src/main/java/com/lunarclient/apollo/ApolloMinestomPlatform.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
import com.lunarclient.apollo.option.OptionsImpl;
8888
import com.lunarclient.apollo.stats.ApolloStats;
8989
import com.lunarclient.apollo.wrapper.MinestomApolloStats;
90-
import java.io.File;
9190
import java.util.logging.Level;
9291
import java.util.logging.Logger;
92+
import lombok.Getter;
9393
import net.minestom.server.MinecraftServer;
9494
import net.minestom.server.command.CommandManager;
9595
import net.minestom.server.event.Event;
@@ -102,36 +102,38 @@
102102
*/
103103
public final class ApolloMinestomPlatform implements ApolloPlatform {
104104

105-
public static boolean SEND_REGISTER_PACKET = true;
106-
107-
private static ApolloMinestomPlatform instance;
105+
@Getter private static ApolloMinestomPlatform instance;
108106

109107
private final Options options;
110108
private final Logger logger;
111109
private final ApolloStats stats;
110+
@Getter private final ApolloMinestomProperties properties;
112111

113112
/**
114113
* Constructs the {@link ApolloMinestomPlatform}.
115114
*
115+
* @param properties the Apollo minestom properties
116116
* @since 1.2.0
117117
*/
118-
public ApolloMinestomPlatform() {
118+
public ApolloMinestomPlatform(ApolloMinestomProperties properties) {
119119
this.options = new OptionsImpl(null);
120120
this.logger = Logger.getLogger(ApolloMinestomPlatform.class.getName());
121121
this.stats = new MinestomApolloStats();
122+
this.properties = properties;
122123
}
123124

124125
/**
125126
* Initialize Apollo for Minestom.
126127
*
128+
* @param properties the Apollo minestom properties
127129
* @since 1.2.0
128130
*/
129-
public static void init() {
131+
public static void init(ApolloMinestomProperties properties) {
130132
if (instance != null) {
131133
throw new IllegalStateException("ApolloMinestomPlatform is already initialized!");
132134
}
133135

134-
instance = new ApolloMinestomPlatform();
136+
instance = new ApolloMinestomPlatform(properties);
135137

136138
ApolloManager.bootstrap(instance);
137139
ApolloManager.setMetadataManager(new MinestomMetadataManager());
@@ -177,8 +179,7 @@ public static void init() {
177179
.addModule(WaypointModule.class, new WaypointModuleImpl());
178180

179181
try {
180-
// TODO: config path
181-
ApolloManager.setConfigPath(new File("").toPath());
182+
ApolloManager.setConfigPath(properties.getConfigPath());
182183
ApolloManager.loadConfiguration();
183184
((ApolloModuleManagerImpl) Apollo.getModuleManager()).enableModules();
184185
ApolloManager.saveConfiguration();
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2023 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo;
25+
26+
import java.io.File;
27+
import java.nio.file.Path;
28+
import java.nio.file.Paths;
29+
import lombok.Builder;
30+
import lombok.Getter;
31+
import lombok.experimental.Accessors;
32+
33+
/**
34+
* Configuration properties for initializing the Apollo Minestom platform.
35+
*
36+
* @since 1.2.0
37+
*/
38+
@Getter
39+
@Builder
40+
@Accessors
41+
public class ApolloMinestomProperties {
42+
43+
/**
44+
* An instance of {@link ApolloMinestomProperties} with default properties.
45+
*/
46+
public static final ApolloMinestomProperties DEFAULT_PROPERTIES = ApolloMinestomProperties.builder().build();
47+
48+
/**
49+
* Determines whether Apollo should skip sending the {@code minecraft:register}
50+
* packet for its plugin channels.
51+
*
52+
* <p>By default, this is {@code false}, and Apollo will automatically register its
53+
* {@code lunar:apollo} plugin channel to communicate with the client.</p>
54+
*
55+
* <p>Set this to {@code true} if another plugin or system is responsible
56+
* for sending the register packet, to avoid conflicts where
57+
* multiple plugins attempt registration at the same time.</p>
58+
*
59+
* <p>If you disable channel registration, you must ensure that your server
60+
* or another plugin sends the {@code lunar:apollo} registration packet
61+
* if you want Apollo to function correctly.</p>
62+
*
63+
* @return true if channel registration is disabled, false otherwise
64+
* @since 1.2.0
65+
*/
66+
@Builder.Default
67+
private final boolean sendRegisterPacket = true;
68+
69+
/**
70+
* The path where Apollo will store and load its configuration files.
71+
*
72+
* <p>By default, this path points to the {@code ./Apollo/} directory,
73+
* relative to the server's working directory. If this directory does not
74+
* exist, it will be created automatically.</p>
75+
*
76+
* <p>Override this path if you want to keep Apollo's configuration files in a different location</p>
77+
*
78+
* @return the path to Apollo's configuration directory
79+
* @since 1.2.0
80+
*/
81+
@Builder.Default
82+
private final Path configPath = ApolloMinestomProperties.getDefaultConfigPath();
83+
84+
/**
85+
* Computes the default configuration path ({@code ./Apollo/}).
86+
*
87+
* @return the resolved config path
88+
* @since 1.2.0
89+
*/
90+
private static Path getDefaultConfigPath() {
91+
Path serverDir = Paths.get("").toAbsolutePath();
92+
Path apolloDir = serverDir.resolve("Apollo");
93+
File apolloFile = apolloDir.toFile();
94+
95+
if (!apolloFile.exists()) {
96+
apolloFile.mkdirs();
97+
}
98+
99+
return apolloDir;
100+
}
101+
102+
}

minestom/src/main/java/com/lunarclient/apollo/listener/ApolloPlayerListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void onPlayerDisconnect(PlayerDisconnectEvent event) {
100100
private void onPlayerSpawn(PlayerSpawnEvent event) {
101101
Player player = event.getPlayer();
102102

103-
if (ApolloMinestomPlatform.SEND_REGISTER_PACKET) {
103+
if (ApolloMinestomPlatform.getInstance().getProperties().isSendRegisterPacket()) {
104104
player.sendPluginMessage("minecraft:register", ApolloManager.PLUGIN_MESSAGE_CHANNEL);
105105
}
106106

0 commit comments

Comments
 (0)