Skip to content

Commit

Permalink
Fix #19, and fix player messages randomly not sending
Browse files Browse the repository at this point in the history
  • Loading branch information
maximumpower55 committed Aug 28, 2023
1 parent e345de2 commit 1b107fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/main/java/one/devos/nautical/teabridge/discord/Discord.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Supplier;
Expand All @@ -21,12 +20,19 @@

public class Discord {
private static JDA jda;
private static long guild;
private static long guildId;
public static long selfId;

private static Member cachedSelfMember;
private static Supplier<Member> cachingSelfMemberGet = () -> {
if (cachedSelfMember == null) cachedSelfMember = jda.getGuildById(guild).getSelfMember();
if (cachedSelfMember == null) {
var guild = jda.getGuildById(guildId);
if (guild != null) {
cachedSelfMember = guild.getSelfMember();
} else {
throw new RuntimeException("Guild is null. This most likely means you are missing the message content intent, please enable it within the app's settings in the discord developer portal.");
}
}
return cachedSelfMember;
};

Expand Down Expand Up @@ -58,11 +64,11 @@ public static void start() {
if (response.statusCode() / 100 != 2) throw new Exception("Non-success status code from request " + response);
var webHookDataResponse = JsonUtils.GSON.fromJson(response.body(), WebHookDataResponse.class);
if (Config.INSTANCE.debug) TeaBridge.LOGGER.warn("Webhook response : " + response.body());
guild = Long.parseLong(webHookDataResponse.guildId);
guildId = Long.parseLong(webHookDataResponse.guildId);
ChannelListener.INSTANCE.setChannel(Long.parseLong(webHookDataResponse.channelId));

jda = JDABuilder.createDefault(Config.INSTANCE.discord.token)
.enableIntents(List.of(GatewayIntent.MESSAGE_CONTENT))
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
.addEventListeners(ChannelListener.INSTANCE, CommandUtils.INSTANCE)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class ServerPlayerMixin implements PlayerWebHook {
() -> {
ServerPlayer self = (ServerPlayer) (Object) this;
if (Config.INSTANCE.avatars.useTextureId) {
MinecraftProfileTexture skin = self.getServer().getSessionService().getTextures(self.getGameProfile(), true).get(MinecraftProfileTexture.Type.SKIN);
MinecraftProfileTexture skin = self.getServer().getSessionService().getTextures(self.getGameProfile(), false).get(MinecraftProfileTexture.Type.SKIN);
if (skin != null) return Config.INSTANCE.avatars.avatarUrl.formatted(skin.getHash());
}
return Config.INSTANCE.avatars.avatarUrl.formatted(self.getStringUUID());
Expand Down

0 comments on commit 1b107fc

Please sign in to comment.