Skip to content

Commit 480fb5e

Browse files
committed
properties, shadows, and merges
1 parent 251592f commit 480fb5e

20 files changed

Lines changed: 450 additions & 188 deletions

File tree

.github/workflows/build.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout repository
10+
uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
fetch-tags: true
14+
15+
- name: Setup JDK 17
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '17'
19+
distribution: 'temurin'
20+
21+
- name: Build with Gradle
22+
uses: gradle/actions/setup-gradle@v3
23+
with:
24+
arguments: build
25+
26+
- name: Upload build artifacts
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: Package
30+
path: "**/build/libs"

build.gradle

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ subprojects {
1717
apply plugin: 'dev.architectury.loom'
1818
apply plugin: 'architectury-plugin'
1919
apply plugin: 'maven-publish'
20+
apply plugin: 'com.github.johnrengelman.shadow'
21+
22+
configurations {
23+
24+
shadowBundle {
25+
canBeResolved = true
26+
canBeConsumed = false
27+
28+
}
29+
}
2030

2131
base {
2232
// Set up a suffixed format for the mod jar names, e.g. `example-fabric`.
@@ -34,6 +44,79 @@ subprojects {
3444
dependencies {
3545
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
3646
mappings loom.officialMojangMappings()
47+
48+
49+
shadowBundle(implementation("com.electronwill.night-config:core:$rootProject.nightconfig_version") )
50+
shadowBundle(implementation("com.electronwill.night-config:toml:$rootProject.nightconfig_version"))
51+
52+
53+
tasks.withType(ProcessResources).configureEach {
54+
var replaceProperties = [
55+
minecraft_version : minecraft_version,
56+
mod_id : mod_id,
57+
mod_name : mod_name,
58+
mod_license : mod_license,
59+
mod_version : mod_version,
60+
mod_authors : mod_authors,
61+
mod_description : mod_description,
62+
maven_group : maven_group,
63+
mod_contact : mod_contact,
64+
mod_git : mod_git,
65+
66+
//Quilt
67+
quilt_architectury : quilt_architectury,
68+
quilt_minecraft : quilt_minecraft,
69+
quilt_quiltloader : quilt_quiltloader,
70+
quilt_quiltbase : quilt_quiltbase,
71+
72+
//Fabric
73+
fabric_fabricloader : fabric_fabricloader,
74+
fabric_minecraft : fabric_minecraft,
75+
fabric_java : fabric_java,
76+
fabric_architectury : fabric_architectury,
77+
fabric_fabricapi : fabric_fabricapi,
78+
79+
//ForgeLikes
80+
forge_loaderversion : forge_loaderversion,
81+
forge_loaderrange : forge_loaderrange,
82+
forge_forgeside : forge_forgeside,
83+
forge_minecraftrange : forge_minecraftrange,
84+
forge_architecturyrange: forge_architecturyrange,
85+
forge_architecturyside : forge_architecturyside,
86+
87+
//NeoForge
88+
neoforge_loaderversion : neoforge_loaderversion,
89+
neoforge_loaderrange : neoforge_loaderrange,
90+
neoforge_neoforgeside : neoforge_neoforgeside,
91+
neoforge_minecraftrange: neoforge_minecraftrange,
92+
neoforge_architecturyrange: neoforge_architecturyrange,
93+
neoforge_architecturyside: neoforge_architecturyside
94+
95+
96+
97+
]
98+
inputs.properties replaceProperties
99+
100+
filesMatching(['META-INF/mods.toml', 'quilt.mod.json', 'fabric.mod.json'] ) {
101+
expand replaceProperties
102+
}
103+
}
104+
}
105+
shadowJar {
106+
configurations = [project.configurations.shadowBundle]
107+
archiveClassifier = 'dev-shadow'
108+
109+
110+
// relocate 'redis.clients', 'net.stonebound.shaded.redis.clients'
111+
relocate 'io.prometheus', 'net.stonebound.SimpleIRCBridge.shaded.io.prometheus'
112+
relocate 'com.electronwill', 'net.stonebound.SimpleIRCBridge.shaded.com.electronwill'
113+
114+
115+
dependencies {
116+
exclude(dependency("org.slf4j:.*:.*"))
117+
exclude(dependency("org.jetbrains:.*:.*"))
118+
119+
}
37120
}
38121

39122
java {

common/src/main/java/net/stonebound/simpleircbridge/simpleIRCbridgeLoader.java renamed to common/src/main/java/net/stonebound/simpleircbridge/SimpleIRCBridge.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
import dev.architectury.platform.Platform;
44
import dev.architectury.utils.Env;
5-
import net.stonebound.simpleircbridge.simpleircbridge.ConfigHolder;
65
import net.stonebound.simpleircbridge.simpleircbridge.SimpleIRCBridgeCommon;
76

8-
public final class simpleIRCbridgeLoader {
7+
public final class SimpleIRCBridge {
98
public static final String MOD_ID = "simpleircbridge";
109

1110
public static SimpleIRCBridgeCommon simpleircbridge;
1211

1312
public static void init() {
14-
if (Platform.getEnvironment() == Env.SERVER && ConfigHolder.SetupConfigs()){
13+
if (Platform.getEnvironment() == Env.SERVER){
1514
simpleircbridge = new SimpleIRCBridgeCommon();
1615

1716
}

common/src/main/java/net/stonebound/simpleircbridge/simpleircbridge/BridgeIRCBot.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package net.stonebound.simpleircbridge.simpleircbridge;
22

33
import static net.stonebound.simpleircbridge.simpleircbridge.SIBConstants.*;
4+
import static net.stonebound.simpleircbridge.simpleircbridge.Config.*;
45

56
import java.net.InetSocketAddress;
67

78
import net.stonebound.simpleircbridge.genericircbot.AbstractIRCBot;
89
import net.stonebound.simpleircbridge.genericircbot.IRCConnectionInfo;
910
import net.stonebound.simpleircbridge.utils.IRCMinecraftConverter;
10-
import static net.stonebound.simpleircbridge.simpleircbridge.ConfigHolder.*;
1111

1212
public class BridgeIRCBot extends AbstractIRCBot {
1313

@@ -29,7 +29,11 @@ public class BridgeIRCBot extends AbstractIRCBot {
2929
// }
3030

3131
BridgeIRCBot(SimpleIRCBridgeCommon bridge) {
32-
super(new InetSocketAddress (MemoryConfigs.get("hostname").value, Integer.valueOf(MemoryConfigs.get("port").value) ), Boolean.valueOf(MemoryConfigs.get("tls").value), new IRCConnectionInfo((MemoryConfigs.get("nick")).value, MemoryConfigs.get("username").value, MemoryConfigs.get("realname").value), MemoryConfigs.get("password").value
32+
super(new InetSocketAddress (hostname, port ),
33+
tls,
34+
new IRCConnectionInfo(nick,
35+
username, realname),
36+
password
3337
);
3438
this.bridge = bridge;
3539
}
@@ -71,7 +75,7 @@ protected void logMessage(String msg) {
7175

7276
@Override
7377
protected void onMessage(String channel, String sender, String message) {
74-
if (Boolean.parseBoolean(MemoryConfigs.get("mcFormatting").value)) {
78+
if (mcFormatting) {
7579
message = IRCMinecraftConverter.convIRCtoMinecraft(message);
7680
}
7781
if (sender.equals("bungee")) {
@@ -98,7 +102,7 @@ protected void onMessage(String channel, String sender, String message) {
98102

99103
@Override
100104
protected void onNumeric001() {
101-
joinChannel((String) MemoryConfigs.get("channel").value);
105+
joinChannel(channel);
102106
}
103107

104108
/** {@inheritDoc} */ // re-declare protected, publish method for package
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package net.stonebound.simpleircbridge.simpleircbridge;
2+
3+
import com.electronwill.nightconfig.core.ConfigSpec;
4+
import com.electronwill.nightconfig.core.UnmodifiableConfig;
5+
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
6+
import com.electronwill.nightconfig.core.file.FileNotFoundAction;
7+
import dev.architectury.platform.Platform;
8+
import net.minecraft.server.MinecraftServer;
9+
import net.stonebound.simpleircbridge.utils.CommentedConfigSpec;
10+
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.util.List;
14+
15+
public final class Config {
16+
public static final CommentedConfigSpec commonSpec;
17+
public static CommentedFileConfig commonConfig;
18+
19+
private static final Path commonPath = Platform.getConfigFolder().resolve("simpleircbridge-common.toml");
20+
21+
private Config() {
22+
}
23+
24+
public static Boolean ircFormatting = true;
25+
public static Boolean mcFormatting = true;
26+
public static String nick = "bridgebot";
27+
public static String password = "true";
28+
public static String hostname = "localhost";
29+
public static Integer port = 6667;
30+
public static String channel = "#general";
31+
public static Boolean tls = true;
32+
public static String username = "bridgebot";
33+
34+
public static String realname = "SimpleIRCBridge";
35+
public static Boolean timestop = true;
36+
37+
static {
38+
System.setProperty("nightconfig.preserveInsertionOrder", "true");
39+
40+
commonSpec = new CommentedConfigSpec();
41+
42+
commonSpec.comment("ircFormatting", "Whether minecraft formatting should be converted to IRC formatting");
43+
commonSpec.define("ircFormatting", Config.ircFormatting);
44+
45+
commonSpec.comment("mcFormatting", "Whether IRC formatting should be converted to Minecraft formatting");
46+
commonSpec.define("mcFormatting", Config.mcFormatting);
47+
48+
commonSpec.comment("nick", "The nickname that the relay bot will use, remember the 9 char limit");
49+
commonSpec.define("nick", Config.nick);
50+
51+
commonSpec.comment("password", "#IRC Server password (if any), it should be obvious but this is probably accessable to other mods");
52+
commonSpec.define("password", Config.password);
53+
54+
commonSpec.comment("hostname", "Hostname or IP address of your IRC server");
55+
commonSpec.define("hostname", Config.hostname);
56+
57+
commonSpec.comment("port", "Port of the IRC server to connect to. Common values: 6697 for TLS/SSL; 6667 for plaintext connections");
58+
commonSpec.defineInRange("port", Config.port, 1025, 65535);
59+
60+
commonSpec.comment("channel", "IRC channel to relay into");
61+
commonSpec.define("channel", Config.channel);
62+
63+
commonSpec.comment("tls", "Whether TLS/SSL is enabled. Set to 'false' for a plaintext connection");
64+
commonSpec.define("tls", Config.tls);
65+
66+
commonSpec.comment("username", "The username/ident that the relay bot will use");
67+
commonSpec.define("username", Config.username);
68+
69+
commonSpec.comment("realname", "The realname/gecos that the relay bot will use");
70+
commonSpec.define("realname", Config.realname);
71+
72+
commonSpec.comment("timestop", "Sends a message to the bridge for each player that was online at server closing, as the normal PLAYERQUIT event does not fire");
73+
commonSpec.define("timestop", Config.timestop);
74+
}
75+
76+
private static final FileNotFoundAction MAKE_DIRECTORIES_AND_FILE = (file, configFormat) -> {
77+
Files.createDirectories(file.getParent());
78+
Files.createFile(file);
79+
configFormat.initEmptyFile(file);
80+
return false;
81+
};
82+
83+
private static CommentedFileConfig buildFileConfig(Path path) {
84+
return CommentedFileConfig.builder(path)
85+
.onFileNotFound(MAKE_DIRECTORIES_AND_FILE)
86+
.preserveInsertionOrder()
87+
.build();
88+
}
89+
90+
private static void saveConfig(UnmodifiableConfig config, CommentedConfigSpec spec, Path path) {
91+
try (CommentedFileConfig fileConfig = buildFileConfig(path)) {
92+
fileConfig.putAll(config);
93+
spec.correct(fileConfig);
94+
fileConfig.save();
95+
}
96+
}
97+
98+
public static void save() {
99+
if (commonConfig != null) {
100+
saveConfig(commonConfig, commonSpec, commonPath);
101+
}
102+
}
103+
104+
public static void serverStarting(MinecraftServer server) {
105+
try (CommentedFileConfig config = buildFileConfig(commonPath)) {
106+
config.load();
107+
commonSpec.correct(config, Config::correctionListener);
108+
config.save();
109+
commonConfig = config;
110+
sync();
111+
}
112+
}
113+
114+
public static void serverStopping(MinecraftServer server) {
115+
commonConfig = null;
116+
}
117+
118+
private static void correctionListener(ConfigSpec.CorrectionAction action, List<String> path, Object incorrectValue,
119+
Object correctedValue) {
120+
String key = String.join(".", path);
121+
switch (action) {
122+
case ADD:
123+
SimpleIRCBridgeCommon.logger.warn("Config key {} missing -> added default value.", key);
124+
break;
125+
case REMOVE:
126+
SimpleIRCBridgeCommon.logger.warn("Config key {} not defined -> removed from config.", key);
127+
break;
128+
case REPLACE:
129+
SimpleIRCBridgeCommon.logger.warn("Config key {} not valid -> replaced with default value.", key);
130+
}
131+
}
132+
133+
public static void sync() {
134+
if (commonConfig != null) {
135+
Config.ircFormatting = commonConfig.<Boolean>get("ircFormatting");
136+
Config.mcFormatting = commonConfig.<Boolean>get("mcFormatting");
137+
Config.nick = commonConfig.<String>get("nick");
138+
Config.password = commonConfig.<String>get("password");
139+
Config.hostname = commonConfig.<String>get("hostname");
140+
Config.port = commonConfig.<Integer>get("port");
141+
Config.channel = commonConfig.<String>get("channel");
142+
Config.tls = commonConfig.<Boolean>get("tls");
143+
Config.username = commonConfig.<String>get("username");
144+
Config.realname = commonConfig.<String>get("realname");
145+
Config.timestop = commonConfig.<Boolean>get("timestop");
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)