Skip to content

Commit

Permalink
properties, shadows, and merges
Browse files Browse the repository at this point in the history
  • Loading branch information
Scarlet-Phonavis committed Jul 6, 2024
1 parent 251592f commit 480fb5e
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 188 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Setup JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Build with Gradle
uses: gradle/actions/setup-gradle@v3
with:
arguments: build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: Package
path: "**/build/libs"
83 changes: 83 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ subprojects {
apply plugin: 'dev.architectury.loom'
apply plugin: 'architectury-plugin'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'

configurations {

shadowBundle {
canBeResolved = true
canBeConsumed = false

}
}

base {
// Set up a suffixed format for the mod jar names, e.g. `example-fabric`.
Expand All @@ -34,6 +44,79 @@ subprojects {
dependencies {
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
mappings loom.officialMojangMappings()


shadowBundle(implementation("com.electronwill.night-config:core:$rootProject.nightconfig_version") )
shadowBundle(implementation("com.electronwill.night-config:toml:$rootProject.nightconfig_version"))


tasks.withType(ProcessResources).configureEach {
var replaceProperties = [
minecraft_version : minecraft_version,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description,
maven_group : maven_group,
mod_contact : mod_contact,
mod_git : mod_git,

//Quilt
quilt_architectury : quilt_architectury,
quilt_minecraft : quilt_minecraft,
quilt_quiltloader : quilt_quiltloader,
quilt_quiltbase : quilt_quiltbase,

//Fabric
fabric_fabricloader : fabric_fabricloader,
fabric_minecraft : fabric_minecraft,
fabric_java : fabric_java,
fabric_architectury : fabric_architectury,
fabric_fabricapi : fabric_fabricapi,

//ForgeLikes
forge_loaderversion : forge_loaderversion,
forge_loaderrange : forge_loaderrange,
forge_forgeside : forge_forgeside,
forge_minecraftrange : forge_minecraftrange,
forge_architecturyrange: forge_architecturyrange,
forge_architecturyside : forge_architecturyside,

//NeoForge
neoforge_loaderversion : neoforge_loaderversion,
neoforge_loaderrange : neoforge_loaderrange,
neoforge_neoforgeside : neoforge_neoforgeside,
neoforge_minecraftrange: neoforge_minecraftrange,
neoforge_architecturyrange: neoforge_architecturyrange,
neoforge_architecturyside: neoforge_architecturyside



]
inputs.properties replaceProperties

filesMatching(['META-INF/mods.toml', 'quilt.mod.json', 'fabric.mod.json'] ) {
expand replaceProperties
}
}
}
shadowJar {
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'


// relocate 'redis.clients', 'net.stonebound.shaded.redis.clients'
relocate 'io.prometheus', 'net.stonebound.SimpleIRCBridge.shaded.io.prometheus'
relocate 'com.electronwill', 'net.stonebound.SimpleIRCBridge.shaded.com.electronwill'


dependencies {
exclude(dependency("org.slf4j:.*:.*"))
exclude(dependency("org.jetbrains:.*:.*"))

}
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import dev.architectury.platform.Platform;
import dev.architectury.utils.Env;
import net.stonebound.simpleircbridge.simpleircbridge.ConfigHolder;
import net.stonebound.simpleircbridge.simpleircbridge.SimpleIRCBridgeCommon;

public final class simpleIRCbridgeLoader {
public final class SimpleIRCBridge {
public static final String MOD_ID = "simpleircbridge";

public static SimpleIRCBridgeCommon simpleircbridge;

public static void init() {
if (Platform.getEnvironment() == Env.SERVER && ConfigHolder.SetupConfigs()){
if (Platform.getEnvironment() == Env.SERVER){
simpleircbridge = new SimpleIRCBridgeCommon();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.stonebound.simpleircbridge.simpleircbridge;

import static net.stonebound.simpleircbridge.simpleircbridge.SIBConstants.*;
import static net.stonebound.simpleircbridge.simpleircbridge.Config.*;

import java.net.InetSocketAddress;

import net.stonebound.simpleircbridge.genericircbot.AbstractIRCBot;
import net.stonebound.simpleircbridge.genericircbot.IRCConnectionInfo;
import net.stonebound.simpleircbridge.utils.IRCMinecraftConverter;
import static net.stonebound.simpleircbridge.simpleircbridge.ConfigHolder.*;

public class BridgeIRCBot extends AbstractIRCBot {

Expand All @@ -29,7 +29,11 @@ public class BridgeIRCBot extends AbstractIRCBot {
// }

BridgeIRCBot(SimpleIRCBridgeCommon bridge) {
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
super(new InetSocketAddress (hostname, port ),
tls,
new IRCConnectionInfo(nick,
username, realname),
password
);
this.bridge = bridge;
}
Expand Down Expand Up @@ -71,7 +75,7 @@ protected void logMessage(String msg) {

@Override
protected void onMessage(String channel, String sender, String message) {
if (Boolean.parseBoolean(MemoryConfigs.get("mcFormatting").value)) {
if (mcFormatting) {
message = IRCMinecraftConverter.convIRCtoMinecraft(message);
}
if (sender.equals("bungee")) {
Expand All @@ -98,7 +102,7 @@ protected void onMessage(String channel, String sender, String message) {

@Override
protected void onNumeric001() {
joinChannel((String) MemoryConfigs.get("channel").value);
joinChannel(channel);
}

/** {@inheritDoc} */ // re-declare protected, publish method for package
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package net.stonebound.simpleircbridge.simpleircbridge;

import com.electronwill.nightconfig.core.ConfigSpec;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.electronwill.nightconfig.core.file.FileNotFoundAction;
import dev.architectury.platform.Platform;
import net.minecraft.server.MinecraftServer;
import net.stonebound.simpleircbridge.utils.CommentedConfigSpec;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

public final class Config {
public static final CommentedConfigSpec commonSpec;
public static CommentedFileConfig commonConfig;

private static final Path commonPath = Platform.getConfigFolder().resolve("simpleircbridge-common.toml");

private Config() {
}

public static Boolean ircFormatting = true;
public static Boolean mcFormatting = true;
public static String nick = "bridgebot";
public static String password = "true";
public static String hostname = "localhost";
public static Integer port = 6667;
public static String channel = "#general";
public static Boolean tls = true;
public static String username = "bridgebot";

public static String realname = "SimpleIRCBridge";
public static Boolean timestop = true;

static {
System.setProperty("nightconfig.preserveInsertionOrder", "true");

commonSpec = new CommentedConfigSpec();

commonSpec.comment("ircFormatting", "Whether minecraft formatting should be converted to IRC formatting");
commonSpec.define("ircFormatting", Config.ircFormatting);

commonSpec.comment("mcFormatting", "Whether IRC formatting should be converted to Minecraft formatting");
commonSpec.define("mcFormatting", Config.mcFormatting);

commonSpec.comment("nick", "The nickname that the relay bot will use, remember the 9 char limit");
commonSpec.define("nick", Config.nick);

commonSpec.comment("password", "#IRC Server password (if any), it should be obvious but this is probably accessable to other mods");
commonSpec.define("password", Config.password);

commonSpec.comment("hostname", "Hostname or IP address of your IRC server");
commonSpec.define("hostname", Config.hostname);

commonSpec.comment("port", "Port of the IRC server to connect to. Common values: 6697 for TLS/SSL; 6667 for plaintext connections");
commonSpec.defineInRange("port", Config.port, 1025, 65535);

commonSpec.comment("channel", "IRC channel to relay into");
commonSpec.define("channel", Config.channel);

commonSpec.comment("tls", "Whether TLS/SSL is enabled. Set to 'false' for a plaintext connection");
commonSpec.define("tls", Config.tls);

commonSpec.comment("username", "The username/ident that the relay bot will use");
commonSpec.define("username", Config.username);

commonSpec.comment("realname", "The realname/gecos that the relay bot will use");
commonSpec.define("realname", Config.realname);

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");
commonSpec.define("timestop", Config.timestop);
}

private static final FileNotFoundAction MAKE_DIRECTORIES_AND_FILE = (file, configFormat) -> {
Files.createDirectories(file.getParent());
Files.createFile(file);
configFormat.initEmptyFile(file);
return false;
};

private static CommentedFileConfig buildFileConfig(Path path) {
return CommentedFileConfig.builder(path)
.onFileNotFound(MAKE_DIRECTORIES_AND_FILE)
.preserveInsertionOrder()
.build();
}

private static void saveConfig(UnmodifiableConfig config, CommentedConfigSpec spec, Path path) {
try (CommentedFileConfig fileConfig = buildFileConfig(path)) {
fileConfig.putAll(config);
spec.correct(fileConfig);
fileConfig.save();
}
}

public static void save() {
if (commonConfig != null) {
saveConfig(commonConfig, commonSpec, commonPath);
}
}

public static void serverStarting(MinecraftServer server) {
try (CommentedFileConfig config = buildFileConfig(commonPath)) {
config.load();
commonSpec.correct(config, Config::correctionListener);
config.save();
commonConfig = config;
sync();
}
}

public static void serverStopping(MinecraftServer server) {
commonConfig = null;
}

private static void correctionListener(ConfigSpec.CorrectionAction action, List<String> path, Object incorrectValue,
Object correctedValue) {
String key = String.join(".", path);
switch (action) {
case ADD:
SimpleIRCBridgeCommon.logger.warn("Config key {} missing -> added default value.", key);
break;
case REMOVE:
SimpleIRCBridgeCommon.logger.warn("Config key {} not defined -> removed from config.", key);
break;
case REPLACE:
SimpleIRCBridgeCommon.logger.warn("Config key {} not valid -> replaced with default value.", key);
}
}

public static void sync() {
if (commonConfig != null) {
Config.ircFormatting = commonConfig.<Boolean>get("ircFormatting");
Config.mcFormatting = commonConfig.<Boolean>get("mcFormatting");
Config.nick = commonConfig.<String>get("nick");
Config.password = commonConfig.<String>get("password");
Config.hostname = commonConfig.<String>get("hostname");
Config.port = commonConfig.<Integer>get("port");
Config.channel = commonConfig.<String>get("channel");
Config.tls = commonConfig.<Boolean>get("tls");
Config.username = commonConfig.<String>get("username");
Config.realname = commonConfig.<String>get("realname");
Config.timestop = commonConfig.<Boolean>get("timestop");
}
}
}
Loading

0 comments on commit 480fb5e

Please sign in to comment.