Skip to content

Commit

Permalink
Merge pull request #14 from sisby-folk/main
Browse files Browse the repository at this point in the history
Add avatar URL configuration and texture ID support
  • Loading branch information
maximumpower55 authored Jul 28, 2023
2 parents 6bf3a80 + 19f3790 commit 0a2ecfe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/main/java/one/devos/nautical/teabridge/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;

import one.devos.nautical.teabridge.util.JsonUtils;

public class Config {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().setLenient().disableHtmlEscaping().create();
public static Config INSTANCE;

public static void load() throws Exception {
var configPath = PlatformUtil.getConfigDir().resolve("teabridge.json");

if (Files.exists(configPath)) {
INSTANCE = JsonUtils.GSON.fromJson(Files.readString(configPath), Config.class);
INSTANCE = GSON.fromJson(Files.readString(configPath), Config.class);
} else {
INSTANCE = new Config();
}
Files.writeString(configPath, JsonUtils.GSON.toJson(INSTANCE), StandardCharsets.UTF_8);
Files.writeString(configPath, GSON.toJson(INSTANCE), StandardCharsets.UTF_8);
}

@Expose public Discord discord = new Discord();
@Expose public Avatars avatars = new Avatars();
@Expose public Game game = new Game();
@Expose public Crashes crashes = new Crashes();

Expand All @@ -35,6 +37,11 @@ public static class Discord {
@Expose public boolean pkMessageDelayMilliseconds = true;
}

public static class Avatars {
@Expose public String avatarUrl = "https://api.nucleoid.xyz/skin/face/256/%s";
@Expose public boolean useTextureId = false;
}

public static class Game {
@Expose public String serverStartingMessage = "Server is starting...";
@Expose public String serverStartMessage = "Server has started!";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package one.devos.nautical.teabridge.mixin;

import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
Expand All @@ -16,7 +17,14 @@
public abstract class ServerPlayerMixin implements PlayerWebHook {
private final WebHook teabridge$webHook = new WebHook(
() -> StyledChatCompat.TEMP_USERNAME.orElse(((ServerPlayer) (Object) this).getDisplayName().getString()),
() -> "https://api.nucleoid.xyz/skin/face/256/" + ((ServerPlayer) (Object) this).getStringUUID()
() -> {
ServerPlayer self = (ServerPlayer) (Object) this;
if (Config.INSTANCE.avatars.useTextureId) {
MinecraftProfileTexture skin = self.getServer().getSessionService().getTextures(self.getGameProfile(), true).get(MinecraftProfileTexture.Type.SKIN);
if (skin != null) return Config.INSTANCE.avatars.avatarUrl.formatted(skin.getHash());
}
return Config.INSTANCE.avatars.avatarUrl.formatted(self.getStringUUID());
}
);

@Override
Expand Down

0 comments on commit 0a2ecfe

Please sign in to comment.