Skip to content

Commit 3789d0c

Browse files
Merge pull request #846 from ArikSquad/agent/fairysouls-configuration
feat: move configuration out of mongodb
2 parents 2c4e9c9 + 440d13c commit 3789d0c

34 files changed

Lines changed: 2834 additions & 772 deletions

commons/src/main/java/net/swofty/commons/ServerType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public enum ServerType {
1818
SKYBLOCK_GALATEA(true),
1919
SKYBLOCK_BACKWATER_BAYOU(true),
2020
SKYBLOCK_JERRYS_WORKSHOP(true),
21+
SKYBLOCK_LOTUS_ATOLL(true),
22+
SKYBLOCK_SAFARI(true),
2123
PROTOTYPE_LOBBY(false),
2224
BEDWARS_LOBBY(false),
2325
BEDWARS_GAME(false),
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package net.swofty.commons.config;
2+
3+
import de.exlll.configlib.NameFormatters;
4+
import de.exlll.configlib.YamlConfigurationProperties;
5+
import de.exlll.configlib.YamlConfigurations;
6+
7+
import java.io.FileNotFoundException;
8+
import java.io.IOException;
9+
import java.io.InputStream;
10+
import java.nio.charset.StandardCharsets;
11+
import java.nio.file.AtomicMoveNotSupportedException;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.nio.file.StandardCopyOption;
15+
16+
public final class YamlConfigLoader {
17+
private static final YamlConfigurationProperties PROPERTIES = YamlConfigurationProperties.newBuilder()
18+
.setNameFormatter(NameFormatters.IDENTITY)
19+
.charset(StandardCharsets.UTF_8)
20+
.build();
21+
22+
private YamlConfigLoader() {
23+
}
24+
25+
public static <T> T load(Path location, Class<?> resourceOwner, String resource, Class<T> configurationType) {
26+
try (InputStream source = openSource(location, resourceOwner, resource)) {
27+
return YamlConfigurations.read(source, configurationType, PROPERTIES);
28+
} catch (IOException exception) {
29+
throw new IllegalStateException("Unable to read YAML configuration " + location, exception);
30+
}
31+
}
32+
33+
public static <T> void save(Path location, Class<T> configurationType, T configuration) {
34+
Path target = location.toAbsolutePath();
35+
Path temporary = null;
36+
try {
37+
Path directory = target.getParent();
38+
Files.createDirectories(directory);
39+
temporary = Files.createTempFile(directory, target.getFileName().toString(), ".tmp");
40+
YamlConfigurations.save(temporary, configurationType, configuration, PROPERTIES);
41+
try {
42+
Files.move(temporary, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
43+
} catch (AtomicMoveNotSupportedException exception) {
44+
Files.move(temporary, target, StandardCopyOption.REPLACE_EXISTING);
45+
}
46+
temporary = null;
47+
} catch (IOException exception) {
48+
throw new IllegalStateException("Unable to write YAML configuration " + location, exception);
49+
} finally {
50+
if (temporary != null) {
51+
try {
52+
Files.deleteIfExists(temporary);
53+
} catch (IOException ignored) {
54+
}
55+
}
56+
}
57+
}
58+
59+
private static InputStream openSource(Path location, Class<?> resourceOwner, String resource) throws IOException {
60+
if (Files.isRegularFile(location)) {
61+
return Files.newInputStream(location);
62+
}
63+
64+
InputStream source = resourceOwner.getResourceAsStream(resource);
65+
if (source == null) {
66+
throw new FileNotFoundException(location.toString());
67+
}
68+
return source;
69+
}
70+
}

configuration/mongo-init.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

configuration/skyblock/Minestom.crystals.csv

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
crystals:
2+
- id: 1
3+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
4+
x: 43.13005921622691
5+
y: 75.1118727240194
6+
z: -122.24967766591506
7+
serverType: HUB
8+
itemType: WHEAT_CRYSTAL
9+
- id: 2
10+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
11+
x: 28.31150256073339
12+
y: 75.48551224990652
13+
z: -140.6871747405607
14+
serverType: HUB
15+
itemType: WHEAT_CRYSTAL
16+
- id: 3
17+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
18+
x: 63.414336674908704
19+
y: 76.97180664240655
20+
z: -134.42058576459584
21+
serverType: HUB
22+
itemType: WHEAT_CRYSTAL
23+
- id: 4
24+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
25+
x: 73.69529306049547
26+
y: 79.21654074104354
27+
z: -160.75138423775255
28+
serverType: HUB
29+
itemType: WHEAT_CRYSTAL
30+
- id: 5
31+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
32+
x: 59.50817153963336
33+
y: 79.21654074104354
34+
z: -182.6970617412972
35+
serverType: HUB
36+
itemType: WHEAT_CRYSTAL
37+
- id: 6
38+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
39+
x: 23.69214972882618
40+
y: 77.72147472159656
41+
z: -178.00258311237133
42+
serverType: HUB
43+
itemType: WHEAT_CRYSTAL
44+
- id: 7
45+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
46+
x: -7.1
47+
y: 78.1
48+
z: -27.1
49+
serverType: HUB
50+
itemType: FLOWER_CRYSTAL
51+
- id: 8
52+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
53+
x: 134.8683294293372
54+
y: 78.83531391075113
55+
z: -212.77871289031293
56+
serverType: THE_FARMING_ISLANDS
57+
itemType: WHEAT_CRYSTAL
58+
- id: 9
59+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
60+
x: 118.09829197561052
61+
y: 78.0854154409095
62+
z: -221.89615973940928
63+
serverType: THE_FARMING_ISLANDS
64+
itemType: WHEAT_CRYSTAL
65+
- id: 10
66+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
67+
x: 179.6704613500174
68+
y: 82.90219669149552
69+
z: -216.48506739711638
70+
serverType: THE_FARMING_ISLANDS
71+
itemType: PUMPKIN_AND_MELON_CRYSTAL
72+
- id: 11
73+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
74+
x: 168.39194062684598
75+
y: 90.78562053479897
76+
z: -269.59782005232177
77+
serverType: THE_FARMING_ISLANDS
78+
itemType: POTATO_CRYSTAL
79+
- id: 12
80+
url: 9265f96f54b78885c46e7d2f86b1c1dbfe643c6060fc7fcc9834c3e3fd595135
81+
x: 132.578203624726
82+
y: 91.16748587959599
83+
z: -284.62450974516634
84+
serverType: THE_FARMING_ISLANDS
85+
itemType: CARROT_CRYSTAL

0 commit comments

Comments
 (0)