Skip to content

Commit

Permalink
ban compat
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Oct 8, 2024
1 parent 796c1d9 commit a4ba539
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 7 deletions.
16 changes: 13 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ repositories {
exclusiveMaven("https://maven.ladysnake.org/releases", "dev.onyxstudios.cardinal-components-api") // Cardinal Components
exclusiveMaven("https://maven.wispforest.io", "me.alphamode")
exclusiveMaven("https://maven.terraformersmc.com/releases/", "com.terraformersmc")
flatDir {
dirs(setOf("libs"))
}
}

dependencies {
Expand All @@ -37,20 +40,27 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:${"fabric_loader_version"()}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${"fabric_api_version"()}")

// Hep
modImplementation("maven.modrinth:hephaestus:${"minecraft_version"()}-${"hephaestus_version"()}")
modImplementation("slimeknights.mantle:Mantle:${"minecraft_version"()}-${"mantle_version"()}")
for (pl_module in "accessors,attributes,base,brewing,client_events,core,common,config,data,entity,extensions,items,models,model_loader,networking,tags,tool_actions,transfer,fluids,lazy_registration,loot,utility".split(",")) {
modRuntimeOnly("io.github.fabricators_of_create.Porting-Lib:${pl_module}:2.3.4+1.20.1")
}

// Create
modImplementation("com.simibubi.create:create-fabric-${"minecraft_version"()}:${"create_version"()}")

modImplementation("com.railwayteam.railways:Steam_Rails-fabric-1.20.1:1.6.4+fabric-mc1.20.1")
modImplementation("dev.ithundxr.createnumismatics:CreateNumismatics-fabric-1.20.1:1.0.6+fabric-mc1.20.1")
// SNR & Numi
modCompileOnly("com.railwayteam.railways:Steam_Rails-fabric-1.20.1:1.6.4+fabric-mc1.20.1")
modCompileOnly("dev.ithundxr.createnumismatics:CreateNumismatics-fabric-1.20.1:1.0.6+fabric-mc1.20.1")

// Workarounds
modCompileOnly("maven.modrinth:copycats:fabric.1.20.1-1.3.2")

modCompileOnly("maven.modrinth:appleskin:2.5.1+mc1.20")

// Compat
modImplementation("maven.modrinth:banhammer:0.7.1+1.20.1")
modImplementation(":ACME_Admin-0.1.0-beta.1+fabric-mc1.20.1-local")
}

tasks.processResources {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ parchment_version = 2023.09.03

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
fabric_loader_version=0.15.7
fabric_api_version=0.92.0+1.20.1
fabric_loader_version=0.16.3
fabric_api_version=0.92.2+1.20.1

# Create
# https://modrinth.com/mod/create-fabric/versions
Expand Down
Binary file not shown.
10 changes: 8 additions & 2 deletions src/main/java/dev/ithundxr/railwaystweaks/RailwaysTweaks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.ithundxr.railwaystweaks;

import dev.ithundxr.railwaystweaks.compat.BanModCompat;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import org.slf4j.Logger;
Expand All @@ -11,13 +13,17 @@ public class RailwaysTweaks implements ModInitializer {
public static final String MODID = "railwaystweaks";
public static final String NAME = "RailwaysTweaks";
public static final Logger LOGGER = LoggerFactory.getLogger(NAME);

@Override
public void onInitialize() {
LOGGER.info("Railways Tweaks is loading...");

RailwaysTweaksCommands.init();

if (FabricLoader.getInstance().isDevelopmentEnvironment())
MixinEnvironment.getCurrentEnvironment().audit();
//if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER)
BanModCompat.init();

//if (FabricLoader.getInstance().isDevelopmentEnvironment())
// MixinEnvironment.getCurrentEnvironment().audit();
}
}
83 changes: 83 additions & 0 deletions src/main/java/dev/ithundxr/railwaystweaks/compat/BanModCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package dev.ithundxr.railwaystweaks.compat;

import dev.ithundxr.railwaystweaks.RailwaysTweaks;
import eu.pb4.banhammer.api.BanHammer;
import eu.pb4.banhammer.api.PunishmentType;
import io.github.slimeistdev.acme_admin.api.v0.events.ACMEBanCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.Util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Properties;
import java.util.UUID;

public class BanModCompat {
private static final String dataFormat = "{\"uuid\": \"%s\"}";

private static final String API_KEY;

static {
File configFile = new File(FabricLoader.getInstance().getConfigDir().toFile(), "railwayTweaks.properties");
Properties properties = new Properties();

if (configFile.exists()) {
try (FileInputStream stream = new FileInputStream(configFile)) {
properties.load(stream);
} catch (IOException e) {
RailwaysTweaks.LOGGER.warn("Could not read property file '{}'", configFile.getAbsolutePath(), e);
}
}

API_KEY = (String) properties.computeIfAbsent("api-key", a -> "null");

try (FileOutputStream stream = new FileOutputStream(configFile)) {
properties.store(stream, null);
} catch (IOException e) {
RailwaysTweaks.LOGGER.warn("Could not store property file '{}'", configFile.getAbsolutePath(), e);
}
}

public static void init() {
BanHammer.registerPunishmentEvent((punishmentData, silent, invisible) -> {
if (!punishmentData.isTemporary() && punishmentData.type == PunishmentType.BAN) {
execute(punishmentData.playerUUID);
}
});

ACMEBanCallback.EVENT.register((bannedPlayer, source, banCause, cancellable) -> {
if (banCause.getExpiration() == null) {
execute(bannedPlayer.getUUID());
}
});
}

public static void execute(UUID uuid) {
if (!"null".equals(API_KEY)) {
Util.ioPool().submit(() -> {
HttpRequest request = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofString(dataFormat.formatted(uuid)))
.header("Authorization", API_KEY)
.uri(URI.create("https://railways.ithundxr.dev/minecraft/ban"))
.build();

try {
HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10L))
.followRedirects(HttpClient.Redirect.ALWAYS)
.build()
.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
} catch (IOException | InterruptedException ignored) {
}
});
}
}
}

0 comments on commit a4ba539

Please sign in to comment.