Skip to content

Commit

Permalink
cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
maximumpower55 committed May 21, 2024
1 parent 9ea46c6 commit dad8609
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.MinecraftServer;
import one.devos.nautical.teabridge.PlatformUtil;
import one.devos.nautical.teabridge.TeaBridge;
import one.devos.nautical.teabridge.util.FormattingUtils;
import org.jetbrains.annotations.NotNull;

public class ChannelListener extends ListenerAdapter {
public static final ChannelListener INSTANCE = new ChannelListener();
Expand All @@ -25,7 +27,7 @@ void setChannel(long channel) {
}

@Override
public void onMessageReceived(MessageReceivedEvent receivedEvent) {
public void onMessageReceived(@NotNull MessageReceivedEvent receivedEvent) {
PKCompat.await(receivedEvent, (event, proxied) -> {
if (server == null) return;

Expand All @@ -43,10 +45,10 @@ public void onMessageReceived(MessageReceivedEvent receivedEvent) {
try {
formattedMessage = FormattingUtils.formatMessage(event.getMessage());
} catch (Exception e) {
e.printStackTrace();
TeaBridge.LOGGER.error("Exception when handling message : ", e);
formattedMessage = Optional.of(PlatformUtil.literal("Exception when handling message, check log for details!").withStyle(ChatFormatting.RED, ChatFormatting.BOLD));
}
if (playerList != null && formattedMessage.isPresent()) playerList.broadcastSystemMessage(formattedMessage.get(), false);
formattedMessage.ifPresent(mutableComponent -> playerList.broadcastSystemMessage(mutableComponent, false));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class Discord {
() -> selfMember.get().getEffectiveAvatarUrl()
);

private static Thread messageThread;
private static final LinkedBlockingQueue<ScheduledMessage> scheduledMessages = new LinkedBlockingQueue<>();

public static void start() {
Expand Down Expand Up @@ -74,11 +73,11 @@ public static void start() {
return;
}

messageThread = new Thread(() -> {
Thread messageThread = new Thread(() -> {
while (true) {
try {
Discord.scheduledSend(scheduledMessages.take());
} catch (InterruptedException e) { }
} catch (InterruptedException ignored) { }
}
}, "TeaBridge Discord Message Scheduler");
messageThread.setDaemon(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.jetbrains.annotations.Nullable;

public record ProtoWebHook(Supplier<String> username, Supplier<String> avatar) {
public Message createMessage(String content, @Nullable String displayName) throws Exception {
public Message createMessage(String content, @Nullable String displayName) {
return new Message(content, AllowedMentions.INSTANCE, displayName != null ? displayName : this.username.get(), this.avatar.get());
}

Expand All @@ -34,9 +34,5 @@ public record AllowedMentions(List<String> parse) {
public static final Codec<AllowedMentions> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.listOf().fieldOf("parse").forGetter(AllowedMentions::parse)
).apply(instance, AllowedMentions::new));

public DataResult<String> toJson() {
return CODEC.encodeStart(JsonOps.INSTANCE, this).map(JsonUtils.GSON::toJson);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Mixin(CrashReport.class)
public abstract class CrashReportMixin {
@Inject(method = "saveToFile", at = @At("HEAD"))
private void teabridge$uploadCrash(File file, CallbackInfoReturnable<Boolean> cir) {
private void uploadCrash(File file, CallbackInfoReturnable<Boolean> cir) {
CrashHandler.CRASH_VALUE.crash(() -> {
if (Config.INSTANCE.crashes().uploadToMclogs()) CrashHandler.uploadAndSend((CrashReport) (Object) this);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Mixin(PlayerAdvancements.class)
public abstract class PlayerAdvancementsMixin {
@ModifyArg(method = "method_53637", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V"), index = 0)
private Component teabridge$mirrorAwardMessage(Component awardMessage) {
private Component mirrorAwardMessage(Component awardMessage) {
if (Config.INSTANCE.game().mirrorAdvancements()) Discord.send(awardMessage.getString());
return awardMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Mixin(PlayerList.class)
public abstract class PlayerListMixin {
@ModifyArg(method = "placeNewPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V"), index = 0)
private Component teabridge$mirrorJoinMessage(Component joinMessage) {
private Component mirrorJoinMessage(Component joinMessage) {
if (Config.INSTANCE.game().mirrorJoin()) Discord.send(joinMessage.getString());
return joinMessage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package one.devos.nautical.teabridge.mixin;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -17,15 +16,16 @@

@Mixin(ServerGamePacketListenerImpl.class)
public abstract class ServerGamePacketListenerImplMixin {
@Shadow @Final private ServerPlayer player;
@Shadow
public ServerPlayer player;

@Inject(method = "<init>", at = @At("RETURN"))
private void teabridge$makePlayerWebhookOnline(CallbackInfo ci) {
private void makePlayerWebhookOnline(CallbackInfo ci) {
PlayerWebHook.ONLINE.add((PlayerWebHook) player);
}

@ModifyArg(method = "removePlayerFromWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V"), index = 0)
private Component teabridge$mirrorLeaveMessage(Component leaveMessage) {
private Component mirrorLeaveMessage(Component leaveMessage) {
PlayerWebHook.ONLINE.remove((PlayerWebHook) player);
if (Config.INSTANCE.game().mirrorLeave()) Discord.send(leaveMessage.getString());
return leaveMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

Expand All @@ -16,12 +17,13 @@

@Mixin(ServerPlayer.class)
public abstract class ServerPlayerMixin implements PlayerWebHook {
private final ProtoWebHook teabridge$webHook = new ProtoWebHook(
@Unique
private final ProtoWebHook webHook = new ProtoWebHook(
() -> Objects.requireNonNull(((ServerPlayer) (Object) this).getDisplayName()).getString(),
() -> {
ServerPlayer self = (ServerPlayer) (Object) this;
if (Config.INSTANCE.avatars().useTextureId()) {
MinecraftProfileTexture skin = self.getServer().getSessionService().getTextures(self.getGameProfile()).skin();
MinecraftProfileTexture skin = Objects.requireNonNull(self.getServer()).getSessionService().getTextures(self.getGameProfile()).skin();
if (skin != null) return Config.INSTANCE.avatars().avatarUrl().formatted(skin.getHash());
}
return Config.INSTANCE.avatars().avatarUrl().formatted(self.getStringUUID());
Expand All @@ -30,11 +32,11 @@ public abstract class ServerPlayerMixin implements PlayerWebHook {

@Override
public ProtoWebHook getWebHook() {
return teabridge$webHook;
return webHook;
}

@ModifyArg(method = "die", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V"), index = 0)
private Component teabridge$mirrorDeathMessage(Component deathMessage) {
private Component mirrorDeathMessage(Component deathMessage) {
if (Config.INSTANCE.game().mirrorDeath()) Discord.send("**" + deathMessage.getString() + "**");
return deathMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public void crash(Runnable onCrash) {
};

public static void uploadAndSend(final CrashReport crash) {
String crashMessage = null;
String crashMessage;

try {
var response = TeaBridge.CLIENT.send(HttpRequest.newBuilder()
.uri(URI.create("https://api.mclo.gs/1/log"))
.POST(HttpRequest.BodyPublishers.ofString("content=" + URLEncoder.encode(crash.getDetails(), StandardCharsets.UTF_8.toString())))
.POST(HttpRequest.BodyPublishers.ofString("content=" + URLEncoder.encode(crash.getDetails(), StandardCharsets.UTF_8)))
.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
.build(), HttpResponse.BodyHandlers.ofString());
if (response.statusCode() / 100 != 2) throw new Exception("Non-success status code from request " + response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.Optional;

import org.apache.commons.lang3.tuple.Pair;

Expand All @@ -19,8 +18,8 @@ public class StyledChatCompat {
var lookup = MethodHandles.lookup();
var extSignedMessage = lookup.findClass("eu.pb4.styledchat.ducks.ExtSignedMessage");
METHOD = lookup.findVirtual(extSignedMessage, "styledChat_getArg", MethodType.methodType(Component.class, String.class));
} catch (Throwable e) { }
};
} catch (Throwable ignored) { }
}
private static boolean USE_COMPAT = true;

public static Pair<String, @Nullable String> modify(PlayerChatMessage message) {
Expand Down

0 comments on commit dad8609

Please sign in to comment.