Skip to content

Commit

Permalink
1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
phit committed Aug 24, 2024
1 parent 1c50071 commit 468e96f
Show file tree
Hide file tree
Showing 25 changed files with 175 additions and 785 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build

on: [push, pull_request]
on: [ push, pull_request ]

jobs:
build:
Expand All @@ -22,7 +22,7 @@ jobs:
uses: gradle/actions/setup-gradle@v3
with:
arguments: build

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
59 changes: 15 additions & 44 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,64 +49,39 @@ subprojects {
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
mappings loom.officialMojangMappings()

shadowBundle(implementation ("io.prometheus:simpleclient:0.14.1"))
shadowBundle(implementation ("io.prometheus:simpleclient_httpserver:0.14.1"))
shadowBundle(implementation ("io.prometheus:simpleclient_common:0.14.1"))
shadowBundle(implementation ("io.prometheus:simpleclient_hotspot:0.14.1"))
shadowBundle(implementation ("com.electronwill.night-config:core:3.6.4"))
shadowBundle(implementation ("com.electronwill.night-config:toml:3.6.4"))



shadowBundle(implementation("io.prometheus:simpleclient:0.14.1"))
shadowBundle(implementation("io.prometheus:simpleclient_httpserver:0.14.1"))
shadowBundle(implementation("io.prometheus:simpleclient_common:0.14.1"))
shadowBundle(implementation("io.prometheus:simpleclient_hotspot:0.14.1"))

tasks.withType(ProcessResources).configureEach {
var replaceProperties = [
minecraft_version : minecraft_version,
architectury_api_version: architectury_api_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_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,
fabric_java : fabric_java,
fabric_fabricapi : fabric_fabricapi,
fabric_api_version : fabric_api_version,
fabric_loader_version : fabric_loader_version,

//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



neoforge_version : neoforge_version,
]
inputs.properties replaceProperties

filesMatching(['META-INF/mods.toml', 'quilt.mod.json', 'fabric.mod.json'] ) {
filesMatching(['META-INF/neoforge.mods.toml', 'fabric.mod.json']) {
expand replaceProperties
}
}
Expand All @@ -116,16 +91,12 @@ subprojects {
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'


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


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

}
}

Expand All @@ -135,12 +106,12 @@ subprojects {
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 17
it.options.release = 21
}

// Configure Maven publishing.
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ dependencies {

// Architectury API. This is optional, and you can comment it out if you don't need it.
modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version"

api("com.electronwill.night-config:toml:$rootProject.nightconfig_version")
}
16 changes: 6 additions & 10 deletions common/src/main/java/net/stonebound/sbprometheus/SbPrometheus.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class SbPrometheus {
private HTTPServer server;

Expand Down Expand Up @@ -46,9 +45,10 @@ public SbPrometheus() {
LifecycleEvent.SERVER_STOPPING.register(this::onServerStop);
LifecycleEvent.SERVER_STOPPED.register(this::onServerStopped);
TickEvent.SERVER_POST.register(this::onServerTick);
LifecycleEvent.SERVER_STARTING.register(Config::serverStarting);
LifecycleEvent.SERVER_STOPPING.register(Config::serverStopping);
}


public void onServerStarted(MinecraftServer instance) {
try {
server = new HTTPServer(Config.jettysport, false);
Expand All @@ -59,7 +59,6 @@ public void onServerStarted(MinecraftServer instance) {
}
}


public void onServerStop(MinecraftServer instance) {
if (server != null) {
try {
Expand All @@ -83,7 +82,6 @@ public void onServerStopped(MinecraftServer instance) {

private int serverTicks = 0;


public void onServerTick(MinecraftServer instance) {
if (serverTicks % 600 == 0) {

Expand All @@ -107,7 +105,7 @@ public void onServerTick(MinecraftServer instance) {
}
double meanTickTime = mean(instance.getTickTimesNanos()) * 1.0E-6D;

tps.labels("tps").set(Math.min(1000.0/meanTickTime, 20));
tps.labels("tps").set(Math.min(1000.0 / meanTickTime, 20));
tps.labels("meanticktime").set(meanTickTime);
memory.labels("max").set(Runtime.getRuntime().maxMemory());
memory.labels("free").set(Runtime.getRuntime().freeMemory());
Expand All @@ -116,12 +114,10 @@ public void onServerTick(MinecraftServer instance) {
serverTicks++;
}

private static long mean(long[] values)
{
private static long mean(long[] values) {
long sum = 0l;
for (long v : values)
{
sum+=v;
for (long v : values) {
sum += v;
}

return sum / values.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

import dev.architectury.platform.Platform;
import dev.architectury.utils.Env;
import net.stonebound.sbprometheus.config.Config;

public final class SbPrometheusCommon {
public static final String MOD_ID = "sbprometheus";
public static SbPrometheus sbprometheus;

public static void init() {
// Write common init code here.
if (Platform.getEnvironment() == Env.SERVER) {
Config.Start();
sbprometheus = new SbPrometheus();
}
new SbPrometheus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@

//ripped from phit's cwl
public class CommentedConfigSpec extends ConfigSpec {
private final Map<List<String>, String> comments = new HashMap<>();

public void comment(List<String> path, String comment) {
comments.put(path, comment);
}

public void comment(String path, String comment) {
comment(split(path, '.'), comment);
}

@Override
public int correct(Config config) {
return correct(config, (action, path, incorrectValue, correctedValue) -> {
});
}

@Override
public int correct(Config config, CorrectionListener listener) {
int corrections = super.correct(config, listener);
if (config instanceof CommentedConfig) {
insertComments((CommentedConfig) config);
}
return corrections;
}

private void insertComments(CommentedConfig config) {
for (Map.Entry<List<String>, String> entry : comments.entrySet()) {
config.setComment(entry.getKey(), entry.getValue());
}
}
private final Map<List<String>, String> comments = new HashMap<>();

public void comment(List<String> path, String comment) {
comments.put(path, comment);
}

public void comment(String path, String comment) {
comment(split(path, '.'), comment);
}

@Override
public int correct(Config config) {
return correct(config, (action, path, incorrectValue, correctedValue) -> {
});
}

@Override
public int correct(Config config, CorrectionListener listener) {
int corrections = super.correct(config, listener);
if (config instanceof CommentedConfig) {
insertComments((CommentedConfig) config);
}
return corrections;
}

private void insertComments(CommentedConfig config) {
for (Map.Entry<List<String>, String> entry : comments.entrySet()) {
config.setComment(entry.getKey(), entry.getValue());
}
}
}
Loading

0 comments on commit 468e96f

Please sign in to comment.