-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make explosion spawn radius configurable separately
- Loading branch information
Showing
4 changed files
with
79 additions
and
6 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
34 changes: 34 additions & 0 deletions
34
src/main/java/io/github/modrinthsmp/modrinthsmp/ModrinthServerConfig.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,34 @@ | ||
package io.github.modrinthsmp.modrinthsmp; | ||
|
||
import org.quiltmc.json5.JsonReader; | ||
import org.quiltmc.json5.JsonWriter; | ||
|
||
import java.io.IOException; | ||
|
||
public final class ModrinthServerConfig { | ||
private int explosionSpawnRadius = 512; | ||
|
||
public int getExplosionSpawnRadius() { | ||
return explosionSpawnRadius; | ||
} | ||
|
||
public void writeConfig(JsonWriter writer) throws IOException { | ||
writer.beginObject(); { | ||
writer.comment("Spawn radius to disable explosions within. Same value as server.properties"); | ||
writer.name("explosionSpawnRadius").value(explosionSpawnRadius); | ||
} writer.endObject(); | ||
} | ||
|
||
public void readConfig(JsonReader reader) throws IOException { | ||
reader.beginObject(); | ||
while (reader.hasNext()) { | ||
final String key; | ||
//noinspection SwitchStatementWithTooFewBranches | ||
switch (key = reader.nextName()) { | ||
case "explosionSpawnRadius" -> explosionSpawnRadius = reader.nextInt(); | ||
default -> ModrinthSmp.LOGGER.warn("Unknown config key: {}", key); | ||
} | ||
} | ||
reader.endObject(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/io/github/modrinthsmp/modrinthsmp/ModrinthSmp.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 |
---|---|---|
@@ -1,9 +1,46 @@ | ||
package io.github.modrinthsmp.modrinthsmp; | ||
|
||
import com.mojang.logging.LogUtils; | ||
import net.fabricmc.api.ModInitializer; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import org.quiltmc.json5.JsonReader; | ||
import org.quiltmc.json5.JsonWriter; | ||
import org.slf4j.Logger; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public class ModrinthSmp implements ModInitializer { | ||
public static final Logger LOGGER = LogUtils.getLogger(); | ||
private static final ModrinthServerConfig CONFIG = new ModrinthServerConfig(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
readConfig(); | ||
} | ||
|
||
public static void readConfig() { | ||
try (final JsonReader reader = JsonReader.json5(getConfigPath())) { | ||
CONFIG.readConfig(reader); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to load config", e); | ||
} | ||
writeConfig(); | ||
} | ||
|
||
public static void writeConfig() { | ||
try (final JsonWriter writer = JsonWriter.json5(getConfigPath())) { | ||
CONFIG.writeConfig(writer); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to save config", e); | ||
} | ||
} | ||
|
||
public static Path getConfigPath() { | ||
return FabricLoader.getInstance().getConfigDir().resolve("modrinth-smp.json5"); | ||
} | ||
|
||
public static ModrinthServerConfig getConfig() { | ||
return CONFIG; | ||
} | ||
} |
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